Example usage for org.joda.time LocalDate toDate

List of usage examples for org.joda.time LocalDate toDate

Introduction

In this page you can find the example usage for org.joda.time LocalDate toDate.

Prototype

@SuppressWarnings("deprecation")
public Date toDate() 

Source Link

Document

Get the date time as a java.util.Date.

Usage

From source file:com.gst.portfolio.calendar.service.CalendarUtils.java

License:Apache License

private static Collection<LocalDate> getRecurringDates(final Recur recur, final LocalDate seedDate,
        final LocalDate periodStartDate, final LocalDate periodEndDate, final int maxCount,
        boolean isSkippMeetingOnFirstDay, final Integer numberOfDays) {
    if (recur == null) {
        return null;
    }//w  w w. ja v  a  2 s . c  o m
    final Date seed = convertToiCal4JCompatibleDate(seedDate);
    final DateTime periodStart = new DateTime(periodStartDate.toDate());
    final DateTime periodEnd = new DateTime(periodEndDate.toDate());

    final Value value = new Value(Value.DATE.getValue());
    final DateList recurringDates = recur.getDates(seed, periodStart, periodEnd, value, maxCount);
    return convertToLocalDateList(recurringDates, seedDate, getMeetingPeriodFrequencyType(recur),
            isSkippMeetingOnFirstDay, numberOfDays);
}

From source file:com.gst.portfolio.client.domain.Client.java

License:Apache License

private Client(final AppUser currentUser, final ClientStatus status, final Office office,
        final Group clientParentGroup, final String accountNo, final String firstname, final String middlename,
        final String lastname, final String fullname, final LocalDate activationDate,
        final LocalDate officeJoiningDate, final String externalId, final String mobileNo, final Staff staff,
        final LocalDate submittedOnDate, final Long savingsProductId, final Long savingsAccountId,
        final LocalDate dateOfBirth, final CodeValue gender, final CodeValue clientType,
        final CodeValue clientClassification, final Integer legalForm) {

    if (StringUtils.isBlank(accountNo)) {
        this.accountNumber = new RandomPasswordGenerator(19).generate();
        this.accountNumberRequiresAutoGeneration = true;
    } else {/*from  w w w. j  a v  a2 s. c om*/
        this.accountNumber = accountNo;
    }

    this.submittedOnDate = submittedOnDate.toDate();
    this.submittedBy = currentUser;

    this.status = status.getValue();
    this.office = office;
    if (StringUtils.isNotBlank(externalId)) {
        this.externalId = externalId.trim();
    } else {
        this.externalId = null;
    }

    if (StringUtils.isNotBlank(mobileNo)) {
        this.mobileNo = mobileNo.trim();
    } else {
        this.mobileNo = null;
    }

    if (activationDate != null) {
        this.activationDate = activationDate.toDateTimeAtStartOfDay().toDate();
        this.activatedBy = currentUser;
    }
    if (officeJoiningDate != null) {
        this.officeJoiningDate = officeJoiningDate.toDateTimeAtStartOfDay().toDate();
    }
    if (StringUtils.isNotBlank(firstname)) {
        this.firstname = firstname.trim();
    } else {
        this.firstname = null;
    }

    if (StringUtils.isNotBlank(middlename)) {
        this.middlename = middlename.trim();
    } else {
        this.middlename = null;
    }

    if (StringUtils.isNotBlank(lastname)) {
        this.lastname = lastname.trim();
    } else {
        this.lastname = null;
    }

    if (StringUtils.isNotBlank(fullname)) {
        this.fullname = fullname.trim();
    } else {
        this.fullname = null;
    }

    if (clientParentGroup != null) {
        this.groups = new HashSet<>();
        this.groups.add(clientParentGroup);
    }

    this.staff = staff;
    this.savingsProductId = savingsProductId;
    this.savingsAccountId = savingsAccountId;

    if (gender != null) {
        this.gender = gender;
    }
    if (dateOfBirth != null) {
        this.dateOfBirth = dateOfBirth.toDateTimeAtStartOfDay().toDate();
    }
    this.clientType = clientType;
    this.clientClassification = clientClassification;
    this.setLegalForm(legalForm);
    deriveDisplayName();
    validate();
}

From source file:com.gst.portfolio.client.domain.Client.java

License:Apache License

public void activate(final AppUser currentUser, final DateTimeFormatter formatter,
        final LocalDate activationLocalDate) {

    if (isActive()) {
        final String defaultUserMessage = "Cannot activate client. Client is already active.";
        final ApiParameterError error = ApiParameterError.parameterError("error.msg.clients.already.active",
                defaultUserMessage, ClientApiConstants.activationDateParamName,
                activationLocalDate.toString(formatter));

        final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
        dataValidationErrors.add(error);

        throw new PlatformApiDataValidationException(dataValidationErrors);
    }//from  ww w .j  a  v a  2s .  c o m

    this.activationDate = activationLocalDate.toDate();
    this.activatedBy = currentUser;
    this.officeJoiningDate = this.activationDate;
    this.status = ClientStatus.ACTIVE.getValue();

    // in case a closed client is being re open
    this.closureDate = null;
    this.closureReason = null;
    this.closedBy = null;

    validate();
}

From source file:com.gst.portfolio.client.domain.ClientCharge.java

License:Apache License

private ClientCharge(final Client client, final Charge charge, final BigDecimal amount, final LocalDate dueDate,
        final boolean status) {

    this.client = client;
    this.charge = charge;
    this.penaltyCharge = charge.isPenalty();
    this.chargeTime = charge.getChargeTimeType();
    this.dueDate = (dueDate == null) ? null : dueDate.toDate();
    this.chargeCalculation = charge.getChargeCalculation();

    BigDecimal chargeAmount = charge.getAmount();
    if (amount != null) {
        chargeAmount = amount;//w w  w .ja v  a 2  s.  com
    }

    populateDerivedFields(chargeAmount);

    this.paid = determineIfFullyPaid();
    this.status = status;
}

From source file:com.gst.portfolio.client.domain.ClientNonPerson.java

License:Apache License

private ClientNonPerson(final Client client, final CodeValue constitution, final CodeValue mainBusinessLine,
        final String incorpNumber, final LocalDate incorpValidityTill, final String remarks) {
    if (client != null)
        this.client = client;

    if (constitution != null)
        this.constitution = constitution;

    if (mainBusinessLine != null)
        this.mainBusinessLine = mainBusinessLine;

    if (StringUtils.isNotBlank(incorpNumber)) {
        this.incorpNumber = incorpNumber.trim();
    } else {//  www .  j  ava  2 s .  com
        this.incorpNumber = null;
    }

    if (incorpValidityTill != null) {
        this.incorpValidityTill = incorpValidityTill.toDateTimeAtStartOfDay().toDate();
    }

    if (StringUtils.isNotBlank(remarks)) {
        this.remarks = remarks.trim();
    } else {
        this.remarks = null;
    }

    validate(client);
}

From source file:com.gst.portfolio.client.domain.ClientTransaction.java

License:Apache License

public ClientTransaction(Client client, Office office, PaymentDetail paymentDetail, Integer typeOf,
        LocalDate transactionLocalDate, Money amount, boolean reversed, String externalId, Date createdDate,
        String currencyCode, AppUser appUser) {
    super();/*  w  w  w .  j  a  va 2s. com*/
    this.client = client;
    this.office = office;
    this.paymentDetail = paymentDetail;
    this.typeOf = typeOf;
    this.dateOf = transactionLocalDate.toDate();
    this.amount = amount.getAmount();
    this.reversed = reversed;
    this.externalId = externalId;
    this.createdDate = createdDate;
    this.currencyCode = currencyCode;
    this.appUser = appUser;
}

From source file:com.gst.portfolio.client.service.ClientWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

@Transactional
@Override//from   ww w .j a  v a 2s  . com
public CommandProcessingResult closeClient(final Long clientId, final JsonCommand command) {
    try {

        final AppUser currentUser = this.context.authenticatedUser();
        this.fromApiJsonDeserializer.validateClose(command);

        final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId);
        final LocalDate closureDate = command
                .localDateValueOfParameterNamed(ClientApiConstants.closureDateParamName);
        final Long closureReasonId = command
                .longValueOfParameterNamed(ClientApiConstants.closureReasonIdParamName);

        final CodeValue closureReason = this.codeValueRepository.findOneByCodeNameAndIdWithNotFoundDetection(
                ClientApiConstants.CLIENT_CLOSURE_REASON, closureReasonId);

        if (ClientStatus.fromInt(client.getStatus()).isClosed()) {
            final String errorMessage = "Client is already closed.";
            throw new InvalidClientStateTransitionException("close", "is.already.closed", errorMessage);
        } else if (ClientStatus.fromInt(client.getStatus()).isUnderTransfer()) {
            final String errorMessage = "Cannot Close a Client under Transfer";
            throw new InvalidClientStateTransitionException("close", "is.under.transfer", errorMessage);
        }

        if (client.isNotPending() && client.getActivationLocalDate().isAfter(closureDate)) {
            final String errorMessage = "The client closureDate cannot be before the client ActivationDate.";
            throw new InvalidClientStateTransitionException("close", "date.cannot.before.client.actvation.date",
                    errorMessage, closureDate, client.getActivationLocalDate());
        }
        entityDatatableChecksWritePlatformService.runTheCheck(clientId, EntityTables.CLIENT.getName(),
                StatusEnum.CLOSE.getCode().longValue(),
                EntityTables.CLIENT.getForeignKeyColumnNameOnDatatable());

        final List<Loan> clientLoans = this.loanRepositoryWrapper.findLoanByClientId(clientId);
        for (final Loan loan : clientLoans) {
            final LoanStatusMapper loanStatus = new LoanStatusMapper(loan.status().getValue());
            if (loanStatus.isOpen() || loanStatus.isPendingApproval() || loanStatus.isAwaitingDisbursal()) {
                final String errorMessage = "Client cannot be closed because of non-closed loans.";
                throw new InvalidClientStateTransitionException("close", "loan.non-closed", errorMessage);
            } else if (loanStatus.isClosed() && loan.getClosedOnDate().after(closureDate.toDate())) {
                final String errorMessage = "The client closureDate cannot be before the loan closedOnDate.";
                throw new InvalidClientStateTransitionException("close", "date.cannot.before.loan.closed.date",
                        errorMessage, closureDate, loan.getClosedOnDate());
            } else if (loanStatus.isOverpaid()) {
                final String errorMessage = "Client cannot be closed because of overpaid loans.";
                throw new InvalidClientStateTransitionException("close", "loan.overpaid", errorMessage);
            }
        }
        final List<SavingsAccount> clientSavingAccounts = this.savingsRepositoryWrapper
                .findSavingAccountByClientId(clientId);

        for (final SavingsAccount saving : clientSavingAccounts) {
            if (saving.isActive() || saving.isSubmittedAndPendingApproval() || saving.isApproved()) {
                final String errorMessage = "Client cannot be closed because of non-closed savings account.";
                throw new InvalidClientStateTransitionException("close", "non-closed.savings.account",
                        errorMessage);
            }
        }

        client.close(currentUser, closureReason, closureDate.toDate());
        this.clientRepository.saveAndFlush(client);
        return new CommandProcessingResultBuilder() //
                .withCommandId(command.commandId()) //
                .withClientId(clientId) //
                .withEntityId(clientId) //
                .build();
    } catch (final DataIntegrityViolationException dve) {
        handleDataIntegrityIssues(command, dve.getMostSpecificCause(), dve);
        return CommandProcessingResult.empty();
    }
}

From source file:com.gst.portfolio.client.service.ClientWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

@Override
public CommandProcessingResult rejectClient(final Long entityId, final JsonCommand command) {
    final AppUser currentUser = this.context.authenticatedUser();
    this.fromApiJsonDeserializer.validateRejection(command);

    final Client client = this.clientRepository.findOneWithNotFoundDetection(entityId);
    final LocalDate rejectionDate = command
            .localDateValueOfParameterNamed(ClientApiConstants.rejectionDateParamName);
    final Long rejectionReasonId = command
            .longValueOfParameterNamed(ClientApiConstants.rejectionReasonIdParamName);

    final CodeValue rejectionReason = this.codeValueRepository.findOneByCodeNameAndIdWithNotFoundDetection(
            ClientApiConstants.CLIENT_REJECT_REASON, rejectionReasonId);

    if (client.isNotPending()) {
        final String errorMessage = "Only clients pending activation may be withdrawn.";
        throw new InvalidClientStateTransitionException("rejection",
                "on.account.not.in.pending.activation.status", errorMessage, rejectionDate,
                client.getSubmittedOnDate());
    } else if (client.getSubmittedOnDate().isAfter(rejectionDate)) {
        final String errorMessage = "The client rejection date cannot be before the client submitted date.";
        throw new InvalidClientStateTransitionException("rejection", "date.cannot.before.client.submitted.date",
                errorMessage, rejectionDate, client.getSubmittedOnDate());
    }// w  ww . j av a2 s . co  m
    client.reject(currentUser, rejectionReason, rejectionDate.toDate());
    this.clientRepository.saveAndFlush(client);
    this.businessEventNotifierService.notifyBusinessEventWasExecuted(BUSINESS_EVENTS.CLIENTS_REJECT,
            constructEntityMap(BUSINESS_ENTITY.CLIENT, client));
    return new CommandProcessingResultBuilder() //
            .withCommandId(command.commandId()) //
            .withClientId(entityId) //
            .withEntityId(entityId) //
            .build();
}

From source file:com.gst.portfolio.client.service.ClientWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

@Override
public CommandProcessingResult withdrawClient(Long entityId, JsonCommand command) {
    final AppUser currentUser = this.context.authenticatedUser();
    this.fromApiJsonDeserializer.validateWithdrawn(command);

    final Client client = this.clientRepository.findOneWithNotFoundDetection(entityId);
    final LocalDate withdrawalDate = command
            .localDateValueOfParameterNamed(ClientApiConstants.withdrawalDateParamName);
    final Long withdrawalReasonId = command
            .longValueOfParameterNamed(ClientApiConstants.withdrawalReasonIdParamName);

    final CodeValue withdrawalReason = this.codeValueRepository.findOneByCodeNameAndIdWithNotFoundDetection(
            ClientApiConstants.CLIENT_WITHDRAW_REASON, withdrawalReasonId);

    if (client.isNotPending()) {
        final String errorMessage = "Only clients pending activation may be withdrawn.";
        throw new InvalidClientStateTransitionException("withdrawal",
                "on.account.not.in.pending.activation.status", errorMessage, withdrawalDate,
                client.getSubmittedOnDate());
    } else if (client.getSubmittedOnDate().isAfter(withdrawalDate)) {
        final String errorMessage = "The client withdrawal date cannot be before the client submitted date.";
        throw new InvalidClientStateTransitionException("withdrawal",
                "date.cannot.before.client.submitted.date", errorMessage, withdrawalDate,
                client.getSubmittedOnDate());
    }//from  ww w  . j  a  va 2s  . c  o m
    client.withdraw(currentUser, withdrawalReason, withdrawalDate.toDate());
    this.clientRepository.saveAndFlush(client);
    return new CommandProcessingResultBuilder() //
            .withCommandId(command.commandId()) //
            .withClientId(entityId) //
            .withEntityId(entityId) //
            .build();
}

From source file:com.gst.portfolio.client.service.ClientWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

@Override
public CommandProcessingResult reActivateClient(Long entityId, JsonCommand command) {
    final AppUser currentUser = this.context.authenticatedUser();
    this.fromApiJsonDeserializer.validateReactivate(command);

    final Client client = this.clientRepository.findOneWithNotFoundDetection(entityId);
    final LocalDate reactivateDate = command
            .localDateValueOfParameterNamed(ClientApiConstants.reactivationDateParamName);

    if (!client.isClosed()) {
        final String errorMessage = "only closed clients may be reactivated.";
        throw new InvalidClientStateTransitionException("reactivation", "on.nonclosed.account", errorMessage);
    } else if (client.getClosureDate().isAfter(reactivateDate)) {
        final String errorMessage = "The client reactivation date cannot be before the client closed date.";
        throw new InvalidClientStateTransitionException("reactivation", "date.cannot.before.client.closed.date",
                errorMessage, reactivateDate, client.getClosureDate());
    }// w  ww.  j a va2s .  c  o  m
    client.reActivate(currentUser, reactivateDate.toDate());
    this.clientRepository.saveAndFlush(client);
    return new CommandProcessingResultBuilder() //
            .withCommandId(command.commandId()) //
            .withClientId(entityId) //
            .withEntityId(entityId) //
            .build();
}