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.client.service.ClientWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

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

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

    if (!client.isRejected()) {
        final String errorMessage = "only rejected clients may be reactivated.";
        throw new InvalidClientStateTransitionException("undorejection", "on.nonrejected.account",
                errorMessage);// ww  w . java  2 s  .c  om
    } else if (client.getRejectedDate().isAfter(undoRejectDate)) {
        final String errorMessage = "The client reactivation date cannot be before the client rejected date.";
        throw new InvalidClientStateTransitionException("reopened", "date.cannot.before.client.rejected.date",
                errorMessage, undoRejectDate, client.getRejectedDate());
    }

    client.reOpened(currentUser, undoRejectDate.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 undoWithdrawal(Long entityId, JsonCommand command) {
    final AppUser currentUser = this.context.authenticatedUser();
    this.fromApiJsonDeserializer.validateUndoWithDrawn(command);

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

    if (!client.isWithdrawn()) {
        final String errorMessage = "only withdrawal clients may be reactivated.";
        throw new InvalidClientStateTransitionException("undoWithdrawal", "on.nonwithdrawal.account",
                errorMessage);/*from  ww  w.  j  a  v  a  2  s . co m*/
    } else if (client.getWithdrawalDate().isAfter(undoWithdrawalDate)) {
        final String errorMessage = "The client reactivation date cannot be before the client withdrawal date.";
        throw new InvalidClientStateTransitionException("reopened", "date.cannot.before.client.withdrawal.date",
                errorMessage, undoWithdrawalDate, client.getWithdrawalDate());
    }
    client.reOpened(currentUser, undoWithdrawalDate.toDate());
    this.clientRepository.saveAndFlush(client);

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

From source file:com.gst.portfolio.collectionsheet.service.CollectionSheetReadPlatformServiceImpl.java

License:Apache License

@Override
public JLGCollectionSheetData generateGroupCollectionSheet(final Long groupId, final JsonQuery query) {

    this.collectionSheetGenerateCommandFromApiJsonDeserializer.validateForGenerateCollectionSheet(query.json());

    final Long calendarId = query.longValueOfParameterNamed(calendarIdParamName);
    final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName);
    final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    final String transactionDateStr = df.format(transactionDate.toDate());

    final Calendar calendar = this.calendarRepositoryWrapper.findOneWithNotFoundDetection(calendarId);
    // check if transaction against calendar effective from date

    final GroupGeneralData group = this.groupReadPlatformService.retrieveOne(groupId);

    // entityType should be center if it's within a center
    final CalendarEntityType entityType = (group.isChildGroup()) ? CalendarEntityType.CENTERS
            : CalendarEntityType.GROUPS;

    Long entityId = null;//from w w w.java 2s.  co  m
    if (group.isChildGroup()) {
        entityId = group.getParentId();
    } else {
        entityId = group.getId();
    }

    Boolean isSkipMeetingOnFirstDay = false;
    Integer numberOfDays = 0;
    boolean isSkipRepaymentOnFirstMonthEnabled = this.configurationDomainService
            .isSkippingMeetingOnFirstDayOfMonthEnabled();
    if (isSkipRepaymentOnFirstMonthEnabled) {
        numberOfDays = this.configurationDomainService.retreivePeroidInNumberOfDaysForSkipMeetingDate()
                .intValue();
        isSkipMeetingOnFirstDay = this.calendarReadPlatformService.isCalendarAssociatedWithEntity(entityId,
                calendar.getId(), entityType.getValue().longValue());
    }

    if (!calendar.isValidRecurringDate(transactionDate, isSkipMeetingOnFirstDay, numberOfDays)) {
        throw new NotValidRecurringDateException("collectionsheet",
                "The date '" + transactionDate + "' is not a valid meeting date.", transactionDate);
    }

    final AppUser currentUser = this.context.authenticatedUser();
    final String hierarchy = currentUser.getOffice().getHierarchy();
    final String officeHierarchy = hierarchy + "%";

    final JLGCollectionSheetFaltDataMapper mapper = new JLGCollectionSheetFaltDataMapper();

    final SqlParameterSource namedParameters = new MapSqlParameterSource()
            .addValue("dueDate", transactionDateStr).addValue("groupId", group.getId())
            .addValue("officeHierarchy", officeHierarchy).addValue("entityTypeId", entityType.getValue());

    final Collection<JLGCollectionSheetFlatData> collectionSheetFlatDatas = this.namedParameterjdbcTemplate
            .query(mapper.collectionSheetSchema(false), namedParameters, mapper);

    // loan data for collection sheet
    JLGCollectionSheetData collectionSheetData = buildJLGCollectionSheet(transactionDate,
            collectionSheetFlatDatas);

    // mandatory savings data for collection sheet
    Collection<JLGGroupData> groupsWithSavingsData = this.namedParameterjdbcTemplate.query(
            mandatorySavingsExtractor.collectionSheetSchema(false), namedParameters, mandatorySavingsExtractor);

    // merge savings data into loan data
    mergeSavingsGroupDataIntoCollectionsheetData(groupsWithSavingsData, collectionSheetData);

    collectionSheetData = JLGCollectionSheetData.withSavingsProducts(collectionSheetData,
            retrieveSavingsProducts(groupsWithSavingsData));

    return collectionSheetData;
}

From source file:com.gst.portfolio.collectionsheet.service.CollectionSheetReadPlatformServiceImpl.java

License:Apache License

@Override
public JLGCollectionSheetData generateCenterCollectionSheet(final Long centerId, final JsonQuery query) {

    this.collectionSheetGenerateCommandFromApiJsonDeserializer.validateForGenerateCollectionSheet(query.json());

    final AppUser currentUser = this.context.authenticatedUser();
    final String hierarchy = currentUser.getOffice().getHierarchy();
    final String officeHierarchy = hierarchy + "%";

    final CenterData center = this.centerReadPlatformService.retrieveOne(centerId);

    final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName);
    final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    final String dueDateStr = df.format(transactionDate.toDate());

    final JLGCollectionSheetFaltDataMapper mapper = new JLGCollectionSheetFaltDataMapper();

    StringBuilder sql = new StringBuilder(mapper.collectionSheetSchema(true));

    final SqlParameterSource namedParameters = new MapSqlParameterSource().addValue("dueDate", dueDateStr)
            .addValue("centerId", center.getId()).addValue("officeHierarchy", officeHierarchy)
            .addValue("entityTypeId", CalendarEntityType.CENTERS.getValue());

    final Collection<JLGCollectionSheetFlatData> collectionSheetFlatDatas = this.namedParameterjdbcTemplate
            .query(sql.toString(), namedParameters, mapper);

    // loan data for collection sheet
    JLGCollectionSheetData collectionSheetData = buildJLGCollectionSheet(transactionDate,
            collectionSheetFlatDatas);/*from w ww.j  a  va  2  s  .c  o  m*/

    // mandatory savings data for collection sheet
    Collection<JLGGroupData> groupsWithSavingsData = this.namedParameterjdbcTemplate.query(
            mandatorySavingsExtractor.collectionSheetSchema(true), namedParameters, mandatorySavingsExtractor);

    // merge savings data into loan data
    mergeSavingsGroupDataIntoCollectionsheetData(groupsWithSavingsData, collectionSheetData);

    collectionSheetData = JLGCollectionSheetData.withSavingsProducts(collectionSheetData,
            retrieveSavingsProducts(groupsWithSavingsData));

    return collectionSheetData;
}

From source file:com.gst.portfolio.collectionsheet.service.CollectionSheetReadPlatformServiceImpl.java

License:Apache License

@Override
public IndividualCollectionSheetData generateIndividualCollectionSheet(final JsonQuery query) {

    this.collectionSheetGenerateCommandFromApiJsonDeserializer
            .validateForGenerateCollectionSheetOfIndividuals(query.json());

    final LocalDate transactionDate = query.localDateValueOfParameterNamed(transactionDateParamName);
    final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    final String transactionDateStr = df.format(transactionDate.toDate());

    final AppUser currentUser = this.context.authenticatedUser();
    final String hierarchy = currentUser.getOffice().getHierarchy();
    final String officeHierarchy = hierarchy + "%";

    final Long officeId = query.longValueOfParameterNamed(officeIdParamName);
    final Long staffId = query.longValueOfParameterNamed(staffIdParamName);
    final boolean checkForOfficeId = officeId != null;
    final boolean checkForStaffId = staffId != null;

    final IndividualCollectionSheetFaltDataMapper mapper = new IndividualCollectionSheetFaltDataMapper(
            checkForOfficeId, checkForStaffId);

    final SqlParameterSource namedParameters = new MapSqlParameterSource()
            .addValue("dueDate", transactionDateStr).addValue("officeHierarchy", officeHierarchy);

    if (checkForOfficeId) {
        ((MapSqlParameterSource) namedParameters).addValue("officeId", officeId);
    }//w  w w.  j a  va 2 s. c  o m
    if (checkForStaffId) {
        ((MapSqlParameterSource) namedParameters).addValue("staffId", staffId);
    }

    final Collection<IndividualCollectionSheetLoanFlatData> collectionSheetFlatDatas = this.namedParameterjdbcTemplate
            .query(mapper.sqlSchema(), namedParameters, mapper);

    IndividualMandatorySavingsCollectionsheetExtractor mandatorySavingsExtractor = new IndividualMandatorySavingsCollectionsheetExtractor(
            checkForOfficeId, checkForStaffId);
    // mandatory savings data for collection sheet
    Collection<IndividualClientData> clientData = this.namedParameterjdbcTemplate.query(
            mandatorySavingsExtractor.collectionSheetSchema(), namedParameters, mandatorySavingsExtractor);

    // merge savings data into loan data
    mergeLoanData(collectionSheetFlatDatas, (List<IndividualClientData>) clientData);

    final Collection<PaymentTypeData> paymentOptions = this.paymentTypeReadPlatformService
            .retrieveAllPaymentTypes();

    return IndividualCollectionSheetData.instance(transactionDate, clientData, paymentOptions);

}

From source file:com.gst.portfolio.floatingrates.domain.FloatingRate.java

License:Apache License

public static FloatingRate createNew(AppUser currentUser, JsonCommand command) {

    final String name = command.stringValueOfParameterNamed("name");
    final boolean isBaseLendingRate = command.parameterExists("isBaseLendingRate")
            ? command.booleanPrimitiveValueOfParameterNamed("isBaseLendingRate")
            : false;/*from  www  . ja va2 s  .c om*/
    final boolean isActive = command.parameterExists("isActive")
            ? command.booleanPrimitiveValueOfParameterNamed("isActive")
            : true;
    final List<FloatingRatePeriod> floatingRatePeriods = getRatePeriods(currentUser, command);
    final LocalDate currentDate = DateUtils.getLocalDateOfTenant();

    return new FloatingRate(name, isBaseLendingRate, isActive, floatingRatePeriods, currentUser, currentUser,
            currentDate.toDate(), currentDate.toDate());
}

From source file:com.gst.portfolio.floatingrates.domain.FloatingRate.java

License:Apache License

private void updateRatePeriods(final List<FloatingRatePeriod> newRatePeriods, final AppUser appUser) {
    final LocalDate today = DateUtils.getLocalDateOfTenant();
    if (this.floatingRatePeriods != null) {
        for (FloatingRatePeriod ratePeriod : this.floatingRatePeriods) {
            LocalDate fromDate = LocalDate.fromDateFields(ratePeriod.getFromDate());
            if (fromDate.isAfter(today)) {
                ratePeriod.setActive(false);
                ratePeriod.setModifiedBy(appUser);
                ratePeriod.setModifiedOn(today.toDate());
            }/*w  w w.jav a2  s.c o m*/
        }
    }
    for (FloatingRatePeriod newRatePeriod : newRatePeriods) {
        newRatePeriod.updateFloatingRate(this);
        this.floatingRatePeriods.add(newRatePeriod);
    }
}

From source file:com.gst.portfolio.group.domain.Group.java

License:Apache License

private Group(final Office office, final Staff staff, final Group parent, final GroupLevel groupLevel,
        final String name, final String externalId, final GroupingTypeStatus status,
        final LocalDate activationDate, final Set<Client> clientMembers, final Set<Group> groupMembers,
        final LocalDate submittedOnDate, final AppUser currentUser, final String accountNo) {

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

    this.office = office;
    this.staff = staff;
    this.groupLevel = groupLevel;
    this.parent = parent;

    if (parent != null) {
        this.parent.addChild(this);
    }// ww  w  .  j  a v  a2 s  .  com

    if (StringUtils.isBlank(accountNo)) {
        this.accountNumber = new RandomPasswordGenerator(19).generate();
        this.accountNumberRequiresAutoGeneration = true;
    } else {
        this.accountNumber = accountNo;
    }

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

    if (groupMembers != null) {
        this.groupMembers.addAll(groupMembers);
    }

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

    associateClients(clientMembers);

    /*
     * Always keep status change at the bottom, as status change rule
     * depends on the attribute's value
     */

    setStatus(activationDate, currentUser, status, dataValidationErrors);

    throwExceptionIfErrors(dataValidationErrors);
}

From source file:com.gst.portfolio.group.domain.Group.java

License:Apache License

private void activate(final AppUser currentUser, final LocalDate activationLocalDate,
        final List<ApiParameterError> dataValidationErrors) {

    validateStatusNotEqualToActiveAndLogError(dataValidationErrors);
    if (dataValidationErrors.isEmpty()) {
        this.status = GroupingTypeStatus.ACTIVE.getValue();
        setActivationDate(activationLocalDate.toDate(), currentUser, dataValidationErrors);
    }//  w w  w  . j  a  va 2  s  .c  om

}

From source file:com.gst.portfolio.group.domain.Group.java

License:Apache License

public void close(final AppUser currentUser, final CodeValue closureReason, final LocalDate closureDate) {

    if (isClosed()) {
        final String errorMessage = "Group with identifier " + getId() + " is alread closed.";
        throw new InvalidGroupStateTransitionException(this.groupLevel.getLevelName(), "close",
                "already.closed", errorMessage, getId());
    }/*from  ww  w .j av a 2  s.c  o  m*/

    if (isNotPending() && getActivationLocalDate().isAfter(closureDate)) {
        final String errorMessage = "The Group closure Date " + closureDate
                + " cannot be before the group Activation Date " + getActivationLocalDate() + ".";
        throw new InvalidGroupStateTransitionException(this.groupLevel.getLevelName(), "close",
                "date.cannot.before.group.actvation.date", errorMessage, closureDate, getActivationLocalDate());
    }

    this.closureReason = closureReason;
    this.closureDate = closureDate.toDate();
    this.status = GroupingTypeStatus.CLOSED.getValue();
    this.closedBy = currentUser;
}