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:org.apache.fineract.portfolio.calendar.domain.Calendar.java

License:Apache License

@SuppressWarnings("null")
public Map<String, Object> updateRepeatingCalendar(final LocalDate calendarStartDate,
        final CalendarFrequencyType frequencyType, final Integer interval, final Integer repeatsOnDay) {
    final Map<String, Object> actualChanges = new LinkedHashMap<>(9);

    if (calendarStartDate != null & this.startDate != null) {
        if (!calendarStartDate.equals(this.getStartDateLocalDate())) {
            actualChanges.put("startDate", calendarStartDate);
            this.startDate = calendarStartDate.toDate();
        }/*from  w w w.ja  v a2  s . c  o  m*/
    }

    final String newRecurrence = Calendar.constructRecurrence(frequencyType, interval, repeatsOnDay);
    if (!StringUtils.isBlank(this.recurrence) && !newRecurrence.equalsIgnoreCase(this.recurrence)) {
        actualChanges.put("recurrence", newRecurrence);
        this.recurrence = newRecurrence;
    }
    return actualChanges;
}

From source file:org.apache.fineract.portfolio.calendar.domain.Calendar.java

License:Apache License

public void updateStartAndEndDate(final LocalDate startDate, final LocalDate endDate) {

    final CalendarFrequencyType frequencyType = CalendarUtils.getFrequency(this.recurrence);
    final Integer interval = new Integer(CalendarUtils.getInterval(this.recurrence));
    final String newRecurrence = Calendar.constructRecurrence(frequencyType, interval,
            startDate.getDayOfWeek());/*from w ww  . j a va2 s.c om*/

    this.recurrence = newRecurrence;
    this.startDate = startDate.toDate();
    this.endDate = endDate.toDate();
}

From source file:org.apache.fineract.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) {
    if (recur == null) {
        return null;
    }/*from w w  w  . jav  a  2s .  com*/
    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));
}

From source file:org.apache.fineract.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 SavingsProduct savingsProduct,
        final SavingsAccount savingsAccount, 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  va  2  s.  c o m
        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.savingsProduct = savingsProduct;
    this.savingsAccount = savingsAccount;

    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:org.apache.fineract.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);
    }/* ww  w.java 2 s. c o  m*/

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

    validate();
}

From source file:org.apache.fineract.portfolio.client.domain.ClientIdentifier.java

License:Apache License

private ClientIdentifier(final Client client, final CodeValue documentType, final CodeValue proofType,
        final String documentKey, final LocalDate validity, final Boolean isLifeTime, final String statusName,
        String description) {/*from  ww  w.jav  a 2 s  . c om*/
    this.client = client;
    this.documentType = documentType;
    this.proofType = proofType;
    this.documentKey = StringUtils.defaultIfEmpty(documentKey, null);
    if (validity == null) {
        this.validity = null;
    } else {
        this.validity = validity.toDate();
    }
    this.isLifeTime = isLifeTime;
    this.description = StringUtils.defaultIfEmpty(description, null);
    ClientIdentifierStatus statusEnum = ClientIdentifierStatus.valueOf(statusName.toUpperCase());
    this.active = null;
    if (statusEnum.isActive()) {
        this.active = statusEnum.getValue();
    }
    this.status = statusEnum.getValue();
}

From source file:org.apache.fineract.portfolio.client.service.ClientWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

@Transactional
@Override//from w w  w .  j  a  v a2 s. co m
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());
        }

        final List<Loan> clientLoans = this.loanRepository.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.savingsRepository
                .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);
        return CommandProcessingResult.empty();
    }
}

From source file:org.apache.fineract.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());
    }/*from w  w w.ja va 2s  .  c o m*/
    client.reject(currentUser, rejectionReason, rejectionDate.toDate());
    this.clientRepository.saveAndFlush(client);

    return new CommandProcessingResultBuilder() //
            .withCommandId(command.commandId()) //
            .withClientId(entityId) //
            .withEntityId(entityId) //
            .build();
}

From source file:org.apache.fineract.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());
    }/* w w w . j  a v  a  2 s  . 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:org.apache.fineract.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());
    }/*from w  w  w. java 2s. co m*/
    client.reActivate(currentUser, reactivateDate.toDate());
    this.clientRepository.saveAndFlush(client);

    return new CommandProcessingResultBuilder() //
            .withCommandId(command.commandId()) //
            .withClientId(entityId) //
            .withEntityId(entityId) //
            .build();
}