List of usage examples for org.joda.time.format DateTimeFormatter print
public String print(ReadablePartial partial)
From source file:com.gst.portfolio.savings.domain.RecurringDepositAccount.java
License:Apache License
@Override public Map<String, Object> activate(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate) { final Map<String, Object> actualChanges = super.activate(currentUser, command, tenantsTodayDate); if (accountTermAndPreClosure.isAfterExpectedFirstDepositDate(getActivationLocalDate())) { final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(RECURRING_DEPOSIT_ACCOUNT_RESOURCE_NAME); final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat()) .withLocale(command.extractLocale()); final String dateAsString = formatter .print(this.accountTermAndPreClosure.getExpectedFirstDepositOnDate()); baseDataValidator.reset().parameter(DepositsApiConstants.activatedOnDateParamName).value(dateAsString) .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.expected.first.deposit.date"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }// w w w . j a v a2 s . com } return actualChanges; }
From source file:com.gst.portfolio.savings.domain.SavingsAccount.java
License:Apache License
public Map<String, Object> approveApplication(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate) { final Map<String, Object> actualChanges = new LinkedHashMap<>(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(SAVINGS_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.approvalAction); final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status); if (!SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.hasStateOf(currentStatus)) { baseDataValidator.reset().parameter(SavingsApiConstants.approvedOnDateParamName) .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }/* w w w. j a v a2 s. co m*/ } this.status = SavingsAccountStatusType.APPROVED.getValue(); actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status)); // only do below if status has changed in the 'approval' case final LocalDate approvedOn = command .localDateValueOfParameterNamed(SavingsApiConstants.approvedOnDateParamName); final String approvedOnDateChange = command .stringValueOfParameterNamed(SavingsApiConstants.approvedOnDateParamName); this.approvedOnDate = approvedOn.toDate(); this.approvedBy = currentUser; actualChanges.put(SavingsApiConstants.localeParamName, command.locale()); actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat()); actualChanges.put(SavingsApiConstants.approvedOnDateParamName, approvedOnDateChange); final LocalDate submittalDate = getSubmittedOnLocalDate(); if (approvedOn.isBefore(submittalDate)) { final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat()) .withLocale(command.extractLocale()); final String submittalDateAsString = formatter.print(submittalDate); baseDataValidator.reset().parameter(SavingsApiConstants.approvedOnDateParamName) .value(submittalDateAsString) .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.submittal.date"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } if (approvedOn.isAfter(tenantsTodayDate)) { baseDataValidator.reset().parameter(SavingsApiConstants.approvedOnDateParamName) .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_APPLICATION_APPROVED, approvedOn); // FIXME - kw - support field officer history for savings accounts // if (this.fieldOfficer != null) { // final LoanOfficerAssignmentHistory loanOfficerAssignmentHistory = // LoanOfficerAssignmentHistory.createNew(this, // this.fieldOfficer, approvedOn); // this.loanOfficerHistory.add(loanOfficerAssignmentHistory); // } if (this.savingsOfficer != null) { final SavingsOfficerAssignmentHistory savingsOfficerAssignmentHistory = SavingsOfficerAssignmentHistory .createNew(this, this.savingsOfficer, approvedOn); this.savingsOfficerHistory.add(savingsOfficerAssignmentHistory); } return actualChanges; }
From source file:com.gst.portfolio.savings.domain.SavingsAccount.java
License:Apache License
public Map<String, Object> rejectApplication(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate) { final Map<String, Object> actualChanges = new LinkedHashMap<>(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(SAVINGS_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.rejectAction); final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status); if (!SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.hasStateOf(currentStatus)) { baseDataValidator.reset().parameter(SavingsApiConstants.rejectedOnDateParamName) .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }/* w w w.ja v a2 s . c o m*/ } this.status = SavingsAccountStatusType.REJECTED.getValue(); actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status)); final LocalDate rejectedOn = command .localDateValueOfParameterNamed(SavingsApiConstants.rejectedOnDateParamName); final String rejectedOnAsString = command .stringValueOfParameterNamed(SavingsApiConstants.rejectedOnDateParamName); this.rejectedOnDate = rejectedOn.toDate(); this.rejectedBy = currentUser; this.withdrawnOnDate = null; this.withdrawnBy = null; this.closedOnDate = rejectedOn.toDate(); this.closedBy = currentUser; actualChanges.put(SavingsApiConstants.localeParamName, command.locale()); actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat()); actualChanges.put(SavingsApiConstants.rejectedOnDateParamName, rejectedOnAsString); actualChanges.put(SavingsApiConstants.closedOnDateParamName, rejectedOnAsString); final LocalDate submittalDate = getSubmittedOnLocalDate(); if (rejectedOn.isBefore(submittalDate)) { final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat()) .withLocale(command.extractLocale()); final String submittalDateAsString = formatter.print(submittalDate); baseDataValidator.reset().parameter(SavingsApiConstants.rejectedOnDateParamName) .value(submittalDateAsString) .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.submittal.date"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } if (rejectedOn.isAfter(tenantsTodayDate)) { baseDataValidator.reset().parameter(SavingsApiConstants.rejectedOnDateParamName).value(rejectedOn) .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_APPLICATION_REJECTED, rejectedOn); return actualChanges; }
From source file:com.gst.portfolio.savings.domain.SavingsAccount.java
License:Apache License
public Map<String, Object> applicantWithdrawsFromApplication(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate) { final Map<String, Object> actualChanges = new LinkedHashMap<>(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(SAVINGS_ACCOUNT_RESOURCE_NAME + SavingsApiConstants.withdrawnByApplicantAction); final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status); if (!SavingsAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.hasStateOf(currentStatus)) { baseDataValidator.reset().parameter(SavingsApiConstants.withdrawnOnDateParamName) .failWithCodeNoParameterAddedToErrorCode("not.in.submittedandpendingapproval.state"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }// w w w .j a v a2 s. c om } this.status = SavingsAccountStatusType.WITHDRAWN_BY_APPLICANT.getValue(); actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status)); final LocalDate withdrawnOn = command .localDateValueOfParameterNamed(SavingsApiConstants.withdrawnOnDateParamName); final String withdrawnOnAsString = command .stringValueOfParameterNamed(SavingsApiConstants.withdrawnOnDateParamName); this.rejectedOnDate = null; this.rejectedBy = null; this.withdrawnOnDate = withdrawnOn.toDate(); this.withdrawnBy = currentUser; this.closedOnDate = withdrawnOn.toDate(); this.closedBy = currentUser; actualChanges.put(SavingsApiConstants.localeParamName, command.locale()); actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat()); actualChanges.put(SavingsApiConstants.withdrawnOnDateParamName, withdrawnOnAsString); actualChanges.put(SavingsApiConstants.closedOnDateParamName, withdrawnOnAsString); final LocalDate submittalDate = getSubmittedOnLocalDate(); if (withdrawnOn.isBefore(submittalDate)) { final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat()) .withLocale(command.extractLocale()); final String submittalDateAsString = formatter.print(submittalDate); baseDataValidator.reset().parameter(SavingsApiConstants.withdrawnOnDateParamName) .value(submittalDateAsString) .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.submittal.date"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } if (withdrawnOn.isAfter(tenantsTodayDate)) { baseDataValidator.reset().parameter(SavingsApiConstants.withdrawnOnDateParamName).value(withdrawnOn) .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_APPLICATION_WITHDRAWAL_BY_CUSTOMER, withdrawnOn); return actualChanges; }
From source file:com.gst.portfolio.savings.domain.SavingsAccount.java
License:Apache License
public Map<String, Object> activate(final AppUser currentUser, final JsonCommand command, final LocalDate tenantsTodayDate) { final Map<String, Object> actualChanges = new LinkedHashMap<>(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(depositAccountType().resourceName() + SavingsApiConstants.activateAction); final SavingsAccountStatusType currentStatus = SavingsAccountStatusType.fromInt(this.status); if (!SavingsAccountStatusType.APPROVED.hasStateOf(currentStatus)) { baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName) .failWithCodeNoParameterAddedToErrorCode("not.in.approved.state"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }/*from www. ja v a2s . com*/ } final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); final LocalDate activationDate = command .localDateValueOfParameterNamed(SavingsApiConstants.activatedOnDateParamName); this.status = SavingsAccountStatusType.ACTIVE.getValue(); actualChanges.put(SavingsApiConstants.statusParamName, SavingsEnumerations.status(this.status)); actualChanges.put(SavingsApiConstants.localeParamName, command.locale()); actualChanges.put(SavingsApiConstants.dateFormatParamName, command.dateFormat()); actualChanges.put(SavingsApiConstants.activatedOnDateParamName, activationDate.toString(fmt)); this.rejectedOnDate = null; this.rejectedBy = null; this.withdrawnOnDate = null; this.withdrawnBy = null; this.closedOnDate = null; this.closedBy = null; this.activatedOnDate = activationDate.toDate(); this.activatedBy = currentUser; this.lockedInUntilDate = calculateDateAccountIsLockedUntil(getActivationLocalDate()); /* * if (annualFeeSettingsSet()) { * updateToNextAnnualFeeDueDateFrom(getActivationLocalDate()); } */ if (this.client != null && this.client.isActivatedAfter(activationDate)) { final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat()) .withLocale(command.extractLocale()); final String dateAsString = formatter.print(this.client.getActivationLocalDate()); baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(dateAsString) .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.client.activation.date"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } if (this.group != null && this.group.isActivatedAfter(activationDate)) { final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat()) .withLocale(command.extractLocale()); final String dateAsString = formatter.print(this.client.getActivationLocalDate()); baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(dateAsString) .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.group.activation.date"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } final LocalDate approvalDate = getApprovedOnLocalDate(); if (activationDate.isBefore(approvalDate)) { final DateTimeFormatter formatter = DateTimeFormat.forPattern(command.dateFormat()) .withLocale(command.extractLocale()); final String dateAsString = formatter.print(approvalDate); baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(dateAsString) .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.approval.date"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } if (activationDate.isAfter(tenantsTodayDate)) { baseDataValidator.reset().parameter(SavingsApiConstants.activatedOnDateParamName).value(activationDate) .failWithCodeNoParameterAddedToErrorCode("cannot.be.a.future.date"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } validateActivityNotBeforeClientOrGroupTransferDate(SavingsEvent.SAVINGS_ACTIVATE, activationDate); return actualChanges; }
From source file:com.gst.portfolio.shareaccounts.serialization.ShareAccountDataSerializer.java
License:Apache License
@SuppressWarnings("null") public Map<String, Object> validateAndApprove(JsonCommand jsonCommand, ShareAccount account) { Map<String, Object> actualChanges = new HashMap<>(); if (StringUtils.isBlank(jsonCommand.json())) { throw new InvalidJsonException(); }/*w w w. j a v a 2s.c om*/ final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(), ShareAccountApiConstants.approvalParameters); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("sharesaccount"); JsonElement element = jsonCommand.parsedJson(); if (!account.status().equals(ShareAccountStatusType.SUBMITTED_AND_PENDING_APPROVAL.getValue())) { baseDataValidator.failWithCodeNoParameterAddedToErrorCode("is.not.pending.for.approval"); } LocalDate approvedDate = this.fromApiJsonHelper .extractLocalDateNamed(ShareAccountApiConstants.approveddate_paramname, element); final LocalDate submittalDate = new LocalDate(account.getSubmittedDate()); if (approvedDate != null && approvedDate.isBefore(submittalDate)) { final DateTimeFormatter formatter = DateTimeFormat.forPattern(jsonCommand.dateFormat()) .withLocale(jsonCommand.extractLocale()); final String submittalDateAsString = formatter.print(submittalDate); baseDataValidator.reset().parameter(ShareAccountApiConstants.approveddate_paramname) .value(submittalDateAsString) .failWithCodeNoParameterAddedToErrorCode("approved.date.cannot.be.before.submitted.date"); } Set<ShareAccountTransaction> transactions = account.getShareAccountTransactions(); for (ShareAccountTransaction transaction : transactions) { if (transaction.isActive() && transaction.isPendingForApprovalTransaction()) { validateTotalSubsribedShares(account, transaction, baseDataValidator); } } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } AppUser approvedUser = this.platformSecurityContext.authenticatedUser(); account.approve(approvedDate.toDate(), approvedUser); actualChanges.put(ShareAccountApiConstants.id_paramname, account.getId()); updateTotalChargeDerived(account); return actualChanges; }
From source file:com.gst.portfolio.shareaccounts.serialization.ShareAccountDataSerializer.java
License:Apache License
@SuppressWarnings("null") public Map<String, Object> validateAndActivate(JsonCommand jsonCommand, ShareAccount account) { Map<String, Object> actualChanges = new HashMap<>(); if (StringUtils.isBlank(jsonCommand.json())) { throw new InvalidJsonException(); }//from w w w . ja v a 2 s. c o m final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, jsonCommand.json(), ShareAccountApiConstants.activateParameters); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("sharesaccount"); JsonElement element = jsonCommand.parsedJson(); if (!account.status().equals(ShareAccountStatusType.APPROVED.getValue())) { baseDataValidator.failWithCodeNoParameterAddedToErrorCode("is.not.in.approved.status"); } LocalDate activatedDate = this.fromApiJsonHelper .extractLocalDateNamed(ShareAccountApiConstants.activatedate_paramname, element); baseDataValidator.reset().parameter(ShareAccountApiConstants.activatedate_paramname).value(activatedDate) .notNull(); final LocalDate approvedDate = new LocalDate(account.getApprovedDate()); if (activatedDate != null && activatedDate.isBefore(approvedDate)) { final DateTimeFormatter formatter = DateTimeFormat.forPattern(jsonCommand.dateFormat()) .withLocale(jsonCommand.extractLocale()); final String submittalDateAsString = formatter.print(approvedDate); baseDataValidator.reset().parameter(ShareAccountApiConstants.activatedate_paramname) .value(submittalDateAsString) .failWithCodeNoParameterAddedToErrorCode("cannot.be.before.approved.date"); } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } AppUser approvedUser = this.platformSecurityContext.authenticatedUser(); account.activate(activatedDate.toDate(), approvedUser); handlechargesOnActivation(account); actualChanges.put(ShareAccountApiConstants.charges_paramname, activatedDate.toDate()); return actualChanges; }
From source file:com.guavabot.alarmpreference.AlarmPreference.java
License:Apache License
@Override public CharSequence getSummary() { if (mAlarm == null) { return null; }/* w w w . java 2 s . com*/ if (!mAlarm.isAlarmOn()) { return getContext().getResources().getText(R.string.alarm_disabled); } String[] dayNames = getContext().getResources().getStringArray(R.array.alarm_days_summary); StringBuilder builder = new StringBuilder(); int weeklyAlarms = mAlarm.getWeeklyAlarms(); for (int i = 0; i < 7; i++) { if ((weeklyAlarms & (1 << i)) != 0) builder.append(dayNames[i]); } DateTimeFormatter timeFmt = DateTimeFormat.shortTime(); builder.append(getContext().getString(R.string.alarm_at, timeFmt.print(mAlarm.getTime()))); return builder.toString(); }
From source file:com.hack23.cia.service.component.agent.impl.riksdagen.workgenerator.RiksdagenDocumentListWorkGeneratorImpl.java
License:Apache License
@Override public void generateWorkOrders() { try {/*from ww w. java2 s. c om*/ final int startYearForDocumentElement = getImportService().getStartYearForDocumentElement(); final org.joda.time.format.DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd"); DateTime fromDateTime = fmt.parseDateTime(startYearForDocumentElement + "-01-01"); DateTime loadedWeekDate = fmt.parseDateTime(startYearForDocumentElement + "-01-01"); final DateTime toDate = new DateTime(); while (loadedWeekDate.isBefore(toDate)) { loadedWeekDate = loadedWeekDate.plusWeeks(1); sendMessage(loadDocumentWorkdestination, new LoadDocumentWork(fmt.print(fromDateTime), fmt.print(loadedWeekDate))); fromDateTime = fromDateTime.plusWeeks(1); } } catch (final Exception e) { LOGGER.warn("error generating work for loading documents", e); } }
From source file:com.hmsinc.epicenter.velocity.DateTimeFormatTool.java
License:Open Source License
/** * Converts the specified object to a date and returns a formatted string * representing that date in the locale returned by {@link #getLocale()}. * //from ww w .j a va 2s . co m * @param format * the formatting instructions * @param obj * the date object to be formatted * @return a formatted string for this locale representing the specified * date or <code>null</code> if the parameters are invalid */ public String format(String format, ReadableInstant date) { final String ret; if (date == null) { ret = null; } else { final DateTimeFormatter formatter = getDateTimeStyle(format, format, Locale.getDefault(), DateTimeZone.getDefault()); ret = formatter == null ? null : formatter.print(date); } return ret; }