Example usage for org.joda.time LocalDate LocalDate

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

Introduction

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

Prototype

public LocalDate() 

Source Link

Document

Constructs an instance set to the current local time evaluated using ISO chronology in the default zone.

Usage

From source file:com.gst.infrastructure.core.service.DateUtils.java

License:Apache License

public static LocalDate getLocalDateOfTenant() {

    LocalDate today = new LocalDate();

    final DateTimeZone zone = getDateTimeZoneOfTenant();
    if (zone != null) {
        today = new LocalDate(zone);
    }/*w w  w .j  a  va  2s.  co  m*/

    return today;
}

From source file:com.gst.integrationtests.common.Utils.java

License:Apache License

public static LocalDate getLocalDateOfTenant() {
    LocalDate today = new LocalDate();
    final DateTimeZone zone = DateTimeZone.forID(TENANT_TIME_ZONE);
    if (zone != null) {
        today = new LocalDate(zone);
    }//from  w w w .j av a2s  .  com
    return today;
}

From source file:com.gst.organisation.office.service.OfficeReadPlatformServiceImpl.java

License:Apache License

@Override
public OfficeData retrieveNewOfficeTemplate() {

    this.context.authenticatedUser();

    return OfficeData.template(null, new LocalDate());
}

From source file:com.gst.organisation.office.service.OfficeReadPlatformServiceImpl.java

License:Apache License

@Override
public OfficeTransactionData retrieveNewOfficeTransactionDetails() {
    this.context.authenticatedUser();

    final Collection<OfficeData> parentLookups = retrieveAllOfficesForDropdown();
    final Collection<CurrencyData> currencyOptions = this.currencyReadPlatformService
            .retrieveAllowedCurrencies();

    return OfficeTransactionData.template(new LocalDate(), parentLookups, currencyOptions);
}

From source file:com.gst.portfolio.account.service.StandingInstructionWritePlatformServiceImpl.java

License:Apache License

@Override
@CronTarget(jobName = JobName.EXECUTE_STANDING_INSTRUCTIONS)
public void executeStandingInstructions() throws JobExecutionException {
    Collection<StandingInstructionData> instructionDatas = this.standingInstructionReadPlatformService
            .retrieveAll(StandingInstructionStatus.ACTIVE.getValue());
    final StringBuilder sb = new StringBuilder();
    for (StandingInstructionData data : instructionDatas) {
        boolean isDueForTransfer = false;
        AccountTransferRecurrenceType recurrenceType = data.recurrenceType();
        StandingInstructionType instructionType = data.instructionType();
        LocalDate transactionDate = new LocalDate();
        if (recurrenceType.isPeriodicRecurrence()) {
            final ScheduledDateGenerator scheduledDateGenerator = new DefaultScheduledDateGenerator();
            PeriodFrequencyType frequencyType = data.recurrenceFrequency();
            LocalDate startDate = data.validFrom();
            if (frequencyType.isMonthly()) {
                startDate = startDate.withDayOfMonth(data.recurrenceOnDay());
                if (startDate.isBefore(data.validFrom())) {
                    startDate = startDate.plusMonths(1);
                }//from w w w  .ja v a2  s .  com
            } else if (frequencyType.isYearly()) {
                startDate = startDate.withDayOfMonth(data.recurrenceOnDay())
                        .withMonthOfYear(data.recurrenceOnMonth());
                if (startDate.isBefore(data.validFrom())) {
                    startDate = startDate.plusYears(1);
                }
            }
            isDueForTransfer = scheduledDateGenerator.isDateFallsInSchedule(frequencyType,
                    data.recurrenceInterval(), startDate, transactionDate);

        }
        BigDecimal transactionAmount = data.amount();
        if (data.toAccountType().isLoanAccount() && (recurrenceType.isDuesRecurrence()
                || (isDueForTransfer && instructionType.isDuesAmoutTransfer()))) {
            StandingInstructionDuesData standingInstructionDuesData = this.standingInstructionReadPlatformService
                    .retriveLoanDuesData(data.toAccount().accountId());
            if (data.instructionType().isDuesAmoutTransfer()) {
                transactionAmount = standingInstructionDuesData.totalDueAmount();
            }
            if (recurrenceType.isDuesRecurrence()) {
                isDueForTransfer = new LocalDate().equals(standingInstructionDuesData.dueDate());
            }
        }

        if (isDueForTransfer && transactionAmount != null && transactionAmount.compareTo(BigDecimal.ZERO) > 0) {
            final SavingsAccount fromSavingsAccount = null;
            final boolean isRegularTransaction = true;
            final boolean isExceptionForBalanceCheck = false;
            AccountTransferDTO accountTransferDTO = new AccountTransferDTO(transactionDate, transactionAmount,
                    data.fromAccountType(), data.toAccountType(), data.fromAccount().accountId(),
                    data.toAccount().accountId(), data.name() + " Standing instruction trasfer ", null, null,
                    null, null, data.toTransferType(), null, null, data.transferType().getValue(), null, null,
                    null, null, null, fromSavingsAccount, isRegularTransaction, isExceptionForBalanceCheck);
            final boolean transferCompleted = transferAmount(sb, accountTransferDTO, data.getId());

            if (transferCompleted) {
                final String updateQuery = "UPDATE m_account_transfer_standing_instructions SET last_run_date = ? where id = ?";
                this.jdbcTemplate.update(updateQuery, transactionDate.toDate(), data.getId());
            }

        }
    }
    if (sb.length() > 0) {
        throw new JobExecutionException(sb.toString());
    }

}

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

License:Apache License

public static Client createNew(final AppUser currentUser, final Office clientOffice,
        final Group clientParentGroup, final Staff staff, final Long savingsProductId, final CodeValue gender,
        final CodeValue clientType, final CodeValue clientClassification, final Integer legalForm,
        final JsonCommand command) {

    final String accountNo = command.stringValueOfParameterNamed(ClientApiConstants.accountNoParamName);
    final String externalId = command.stringValueOfParameterNamed(ClientApiConstants.externalIdParamName);
    final String mobileNo = command.stringValueOfParameterNamed(ClientApiConstants.mobileNoParamName);

    final String firstname = command.stringValueOfParameterNamed(ClientApiConstants.firstnameParamName);
    final String middlename = command.stringValueOfParameterNamed(ClientApiConstants.middlenameParamName);
    final String lastname = command.stringValueOfParameterNamed(ClientApiConstants.lastnameParamName);
    final String fullname = command.stringValueOfParameterNamed(ClientApiConstants.fullnameParamName);

    final LocalDate dataOfBirth = command
            .localDateValueOfParameterNamed(ClientApiConstants.dateOfBirthParamName);

    ClientStatus status = ClientStatus.PENDING;
    boolean active = false;
    if (command.hasParameter("active")) {
        active = command.booleanPrimitiveValueOfParameterNamed(ClientApiConstants.activeParamName);
    }/*w  w w.j av a2s.co m*/

    LocalDate activationDate = null;
    LocalDate officeJoiningDate = null;
    if (active) {
        status = ClientStatus.ACTIVE;
        activationDate = command.localDateValueOfParameterNamed(ClientApiConstants.activationDateParamName);
        officeJoiningDate = activationDate;
    }

    LocalDate submittedOnDate = new LocalDate();
    if (active && submittedOnDate.isAfter(activationDate)) {
        submittedOnDate = activationDate;
    }
    if (command.hasParameter(ClientApiConstants.submittedOnDateParamName)) {
        submittedOnDate = command.localDateValueOfParameterNamed(ClientApiConstants.submittedOnDateParamName);
    }
    final Long savingsAccountId = null;
    return new Client(currentUser, status, clientOffice, clientParentGroup, accountNo, firstname, middlename,
            lastname, fullname, activationDate, officeJoiningDate, externalId, mobileNo, staff, submittedOnDate,
            savingsProductId, savingsAccountId, dataOfBirth, gender, clientType, clientClassification,
            legalForm);
}

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

License:Apache License

@Override
public ClientData retrieveTemplate(final Long officeId, final boolean staffInSelectedOfficeOnly) {
    this.context.authenticatedUser();

    final Long defaultOfficeId = defaultToUsersOfficeIfNull(officeId);
    AddressData address = null;/* w  w w . ja v a  2 s.  c om*/

    final Collection<OfficeData> offices = this.officeReadPlatformService.retrieveAllOfficesForDropdown();

    final Collection<SavingsProductData> savingsProductDatas = this.savingsProductReadPlatformService
            .retrieveAllForLookupByType(null);

    final GlobalConfigurationPropertyData configuration = this.configurationReadPlatformService
            .retrieveGlobalConfiguration("Enable-Address");

    final Boolean isAddressEnabled = configuration.isEnabled();
    if (isAddressEnabled) {
        address = this.addressReadPlatformService.retrieveTemplate();
    }

    Collection<StaffData> staffOptions = null;

    final boolean loanOfficersOnly = false;
    if (staffInSelectedOfficeOnly) {
        staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(defaultOfficeId);
    } else {
        staffOptions = this.staffReadPlatformService
                .retrieveAllStaffInOfficeAndItsParentOfficeHierarchy(defaultOfficeId, loanOfficersOnly);
    }
    if (CollectionUtils.isEmpty(staffOptions)) {
        staffOptions = null;
    }
    final List<CodeValueData> genderOptions = new ArrayList<>(
            this.codeValueReadPlatformService.retrieveCodeValuesByCode(ClientApiConstants.GENDER));

    final List<CodeValueData> clientTypeOptions = new ArrayList<>(
            this.codeValueReadPlatformService.retrieveCodeValuesByCode(ClientApiConstants.CLIENT_TYPE));

    final List<CodeValueData> clientClassificationOptions = new ArrayList<>(this.codeValueReadPlatformService
            .retrieveCodeValuesByCode(ClientApiConstants.CLIENT_CLASSIFICATION));

    final List<CodeValueData> clientNonPersonConstitutionOptions = new ArrayList<>(
            this.codeValueReadPlatformService
                    .retrieveCodeValuesByCode(ClientApiConstants.CLIENT_NON_PERSON_CONSTITUTION));

    final List<CodeValueData> clientNonPersonMainBusinessLineOptions = new ArrayList<>(
            this.codeValueReadPlatformService
                    .retrieveCodeValuesByCode(ClientApiConstants.CLIENT_NON_PERSON_MAIN_BUSINESS_LINE));

    final List<EnumOptionData> clientLegalFormOptions = ClientEnumerations.legalForm(LegalForm.values());

    final List<DatatableData> datatableTemplates = this.entityDatatableChecksReadService
            .retrieveTemplates(StatusEnum.CREATE.getCode().longValue(), EntityTables.CLIENT.getName(), null);

    return ClientData.template(defaultOfficeId, new LocalDate(), offices, staffOptions, null, genderOptions,
            savingsProductDatas, clientTypeOptions, clientClassificationOptions,
            clientNonPersonConstitutionOptions, clientNonPersonMainBusinessLineOptions, clientLegalFormOptions,
            address, isAddressEnabled, datatableTemplates);
}

From source file:com.gst.portfolio.group.service.CenterReadPlatformServiceImpl.java

License:Apache License

@Override
public CenterData retrieveTemplate(final Long officeId, final boolean staffInSelectedOfficeOnly) {

    final Long officeIdDefaulted = defaultToUsersOfficeIfNull(officeId);

    final Collection<OfficeData> officeOptions = this.officeReadPlatformService.retrieveAllOfficesForDropdown();

    final boolean loanOfficersOnly = false;
    Collection<StaffData> staffOptions = null;
    if (staffInSelectedOfficeOnly) {
        staffOptions = this.staffReadPlatformService.retrieveAllStaffForDropdown(officeIdDefaulted);
    } else {/*from   w  w  w  . j a  va2s  .co  m*/
        staffOptions = this.staffReadPlatformService
                .retrieveAllStaffInOfficeAndItsParentOfficeHierarchy(officeIdDefaulted, loanOfficersOnly);
    }

    if (CollectionUtils.isEmpty(staffOptions)) {
        staffOptions = null;
    }
    final Collection<GroupGeneralData> groupMembersOptions = null;
    final String accountNo = null;
    final BigDecimal totalCollected = null;
    final BigDecimal totalOverdue = null;
    final BigDecimal totaldue = null;
    final BigDecimal installmentDue = null;

    // final boolean clientPendingApprovalAllowed =
    // this.configurationDomainService.isClientPendingApprovalAllowedEnabled();

    return CenterData.template(officeIdDefaulted, accountNo, new LocalDate(), officeOptions, staffOptions,
            groupMembersOptions, totalCollected, totalOverdue, totaldue, installmentDue);
}

From source file:com.gst.portfolio.group.service.GroupingTypesWritePlatformServiceJpaRepositoryImpl.java

License:Apache License

private CommandProcessingResult createGroupingType(final JsonCommand command, final GroupTypes groupingType,
        final Long centerId) {
    try {/*from   www.j a  v  a 2 s  . co  m*/
        final String accountNo = command
                .stringValueOfParameterNamed(GroupingTypesApiConstants.accountNoParamName);
        final String name = command.stringValueOfParameterNamed(GroupingTypesApiConstants.nameParamName);
        final String externalId = command
                .stringValueOfParameterNamed(GroupingTypesApiConstants.externalIdParamName);

        final AppUser currentUser = this.context.authenticatedUser();
        Long officeId = null;
        Group parentGroup = null;

        if (centerId == null) {
            officeId = command.longValueOfParameterNamed(GroupingTypesApiConstants.officeIdParamName);
        } else {
            parentGroup = this.groupRepository.findOneWithNotFoundDetection(centerId);
            officeId = parentGroup.officeId();
        }

        final Office groupOffice = this.officeRepositoryWrapper.findOneWithNotFoundDetection(officeId);

        final LocalDate activationDate = command
                .localDateValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName);
        final GroupLevel groupLevel = this.groupLevelRepository.findOne(groupingType.getId());

        validateOfficeOpeningDateisAfterGroupOrCenterOpeningDate(groupOffice, groupLevel, activationDate);

        Staff staff = null;
        final Long staffId = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName);
        if (staffId != null) {
            staff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(staffId,
                    groupOffice.getHierarchy());
        }

        final Set<Client> clientMembers = assembleSetOfClients(officeId, command);

        final Set<Group> groupMembers = assembleSetOfChildGroups(officeId, command);

        final boolean active = command
                .booleanPrimitiveValueOfParameterNamed(GroupingTypesApiConstants.activeParamName);
        LocalDate submittedOnDate = new LocalDate();
        if (active && submittedOnDate.isAfter(activationDate)) {
            submittedOnDate = activationDate;
        }
        if (command.hasParameter(GroupingTypesApiConstants.submittedOnDateParamName)) {
            submittedOnDate = command
                    .localDateValueOfParameterNamed(GroupingTypesApiConstants.submittedOnDateParamName);
        }

        final Group newGroup = Group.newGroup(groupOffice, staff, parentGroup, groupLevel, name, externalId,
                active, activationDate, clientMembers, groupMembers, submittedOnDate, currentUser, accountNo);

        boolean rollbackTransaction = false;
        if (newGroup.isActive()) {
            this.groupRepository.save(newGroup);
            // validate Group creation rules for Group
            if (newGroup.isGroup()) {
                validateGroupRulesBeforeActivation(newGroup);
            }

            if (newGroup.isCenter()) {
                final CommandWrapper commandWrapper = new CommandWrapperBuilder().activateCenter(null).build();
                rollbackTransaction = this.commandProcessingService.validateCommand(commandWrapper,
                        currentUser);
            } else {
                final CommandWrapper commandWrapper = new CommandWrapperBuilder().activateGroup(null).build();
                rollbackTransaction = this.commandProcessingService.validateCommand(commandWrapper,
                        currentUser);
            }
        }

        if (!newGroup.isCenter() && newGroup.hasActiveClients()) {
            final CommandWrapper commandWrapper = new CommandWrapperBuilder()
                    .associateClientsToGroup(newGroup.getId()).build();
            rollbackTransaction = this.commandProcessingService.validateCommand(commandWrapper, currentUser);
        }

        // pre-save to generate id for use in group hierarchy
        this.groupRepository.save(newGroup);

        /*
         * Generate hierarchy for a new center/group and all the child
         * groups if they exist
         */
        newGroup.generateHierarchy();

        /* Generate account number if required */
        generateAccountNumberIfRequired(newGroup);

        this.groupRepository.saveAndFlush(newGroup);
        newGroup.captureStaffHistoryDuringCenterCreation(staff, activationDate);

        if (newGroup.isGroup()) {
            if (command.parameterExists(GroupingTypesApiConstants.datatables)) {
                this.entityDatatableChecksWritePlatformService.saveDatatables(
                        StatusEnum.CREATE.getCode().longValue(), EntityTables.GROUP.getName(), newGroup.getId(),
                        null, command.arrayOfParameterNamed(GroupingTypesApiConstants.datatables));
            }

            this.entityDatatableChecksWritePlatformService.runTheCheck(newGroup.getId(),
                    EntityTables.GROUP.getName(), StatusEnum.CREATE.getCode().longValue(),
                    EntityTables.GROUP.getForeignKeyColumnNameOnDatatable());
        }

        return new CommandProcessingResultBuilder() //
                .withCommandId(command.commandId()) //
                .withOfficeId(groupOffice.getId()) //
                .withGroupId(newGroup.getId()) //
                .withEntityId(newGroup.getId()) //
                .setRollbackTransaction(rollbackTransaction)//
                .build();

    } catch (final DataIntegrityViolationException dve) {
        handleGroupDataIntegrityIssues(command, dve.getMostSpecificCause(), dve, groupingType);
        return CommandProcessingResult.empty();
    } catch (final PersistenceException dve) {
        Throwable throwable = ExceptionUtils.getRootCause(dve.getCause());
        handleGroupDataIntegrityIssues(command, throwable, dve, groupingType);
        return CommandProcessingResult.empty();
    }
}

From source file:com.gst.portfolio.loanaccount.api.BulkLoansApiResource.java

License:Apache License

@GET
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String loanReassignmentTemplate(@QueryParam("officeId") final Long officeId,
        @QueryParam("fromLoanOfficerId") final Long loanOfficerId, @Context final UriInfo uriInfo) {

    this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);

    final Collection<OfficeData> offices = this.officeReadPlatformService.retrieveAllOfficesForDropdown();

    Collection<StaffData> loanOfficers = null;
    StaffAccountSummaryCollectionData staffAccountSummaryCollectionData = null;

    if (officeId != null) {
        loanOfficers = this.staffReadPlatformService.retrieveAllLoanOfficersInOfficeById(officeId);
    }/*w  w w .j a v  a2s.  com*/

    if (loanOfficerId != null) {
        staffAccountSummaryCollectionData = this.bulkLoansReadPlatformService
                .retrieveLoanOfficerAccountSummary(loanOfficerId);
    }

    final BulkTransferLoanOfficerData loanReassignmentData = BulkTransferLoanOfficerData.templateForBulk(
            officeId, loanOfficerId, new LocalDate(), offices, loanOfficers, staffAccountSummaryCollectionData);

    final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper
            .process(uriInfo.getQueryParameters());
    return this.toApiJsonSerializer.serialize(settings, loanReassignmentData, this.RESPONSE_DATA_PARAMETERS);
}