List of usage examples for org.joda.time.format DateTimeFormat forPattern
public static DateTimeFormatter forPattern(String pattern)
From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
@Override public CommandProcessingResult close(final Long savingsId, final JsonCommand command) { final AppUser user = this.context.authenticatedUser(); this.savingsAccountTransactionDataValidator.validateClosing(command); final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsId); final boolean isLinkedWithAnyActiveLoan = this.accountAssociationsReadPlatformService .isLinkedWithAnyActiveAccount(savingsId); if (isLinkedWithAnyActiveLoan) { final String defaultUserMessage = "Closing savings account with id:" + savingsId + " is not allowed, since it is linked with one of the active accounts"; throw new SavingsAccountClosingNotAllowedException("linked", defaultUserMessage, savingsId); }// ww w .j a v a2s . com entityDatatableChecksWritePlatformService.runTheCheckForProduct(savingsId, EntityTables.SAVING.getName(), StatusEnum.CLOSE.getCode().longValue(), EntityTables.SAVING.getForeignKeyColumnNameOnDatatable(), account.productId()); final boolean isWithdrawBalance = command.booleanPrimitiveValueOfParameterNamed(withdrawBalanceParamName); final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); final LocalDate closedDate = command .localDateValueOfParameterNamed(SavingsApiConstants.closedOnDateParamName); final boolean isPostInterest = command .booleanPrimitiveValueOfParameterNamed(SavingsApiConstants.postInterestValidationOnClosure); // postInterest(account,closedDate,flag); if (isPostInterest) { boolean postInterestOnClosingDate = false; List<SavingsAccountTransaction> savingTransactions = account.getTransactions(); for (SavingsAccountTransaction savingTransaction : savingTransactions) { if (savingTransaction.isInterestPosting() && savingTransaction.isNotReversed() && closedDate.isEqual(savingTransaction.getTransactionLocalDate())) { postInterestOnClosingDate = true; break; } } if (postInterestOnClosingDate == false) { throw new PostInterestClosingDateException(); } } final Map<String, Object> changes = new LinkedHashMap<>(); if (isWithdrawBalance && account.getSummary().getAccountBalance(account.getCurrency()).isGreaterThanZero()) { final BigDecimal transactionAmount = account.getSummary().getAccountBalance(); final PaymentDetail paymentDetail = this.paymentDetailWritePlatformService .createAndPersistPaymentDetail(command, changes); final boolean isAccountTransfer = false; final boolean isRegularTransaction = true; final boolean isApplyWithdrawFee = false; final boolean isInterestTransfer = false; final SavingsTransactionBooleanValues transactionBooleanValues = new SavingsTransactionBooleanValues( isAccountTransfer, isRegularTransaction, isApplyWithdrawFee, isInterestTransfer, isWithdrawBalance); this.savingsAccountDomainService.handleWithdrawal(account, fmt, closedDate, transactionAmount, paymentDetail, transactionBooleanValues); } final Map<String, Object> accountChanges = account.close(user, command, DateUtils.getLocalDateOfTenant()); changes.putAll(accountChanges); if (!changes.isEmpty()) { this.savingAccountRepositoryWrapper.save(account); final String noteText = command.stringValueOfParameterNamed("note"); if (StringUtils.isNotBlank(noteText)) { final Note note = Note.savingNote(account, noteText); changes.put("note", noteText); this.noteRepository.save(note); } } // disable all standing orders linked to the savings account this.disableStandingInstructionsLinkedToClosedSavings(account); return new CommandProcessingResultBuilder() // .withEntityId(savingsId) // .withOfficeId(account.officeId()) // .withClientId(account.clientId()) // .withGroupId(account.groupId()) // .withSavingsId(savingsId) // .with(changes) // .build(); }
From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
@Transactional @Override/* w w w. j a v a2 s . co m*/ public CommandProcessingResult addSavingsAccountCharge(final JsonCommand command) { this.context.authenticatedUser(); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(SAVINGS_ACCOUNT_RESOURCE_NAME); final Long savingsAccountId = command.getSavingsId(); this.savingsAccountChargeDataValidator.validateAdd(command.json()); final SavingsAccount savingsAccount = this.savingAccountAssembler.assembleFrom(savingsAccountId); checkClientOrGroupActive(savingsAccount); final Locale locale = command.extractLocale(); final String format = command.dateFormat(); final DateTimeFormatter fmt = StringUtils.isNotBlank(format) ? DateTimeFormat.forPattern(format).withLocale(locale) : DateTimeFormat.forPattern("dd MM yyyy"); final Long chargeDefinitionId = command.longValueOfParameterNamed(chargeIdParamName); final Charge chargeDefinition = this.chargeRepository.findOneWithNotFoundDetection(chargeDefinitionId); Integer chargeTimeType = chargeDefinition.getChargeTimeType(); LocalDate dueAsOfDateParam = command.localDateValueOfParameterNamed(dueAsOfDateParamName); if ((chargeTimeType.equals(ChargeTimeType.WITHDRAWAL_FEE.getValue()) || chargeTimeType.equals(ChargeTimeType.SAVINGS_NOACTIVITY_FEE.getValue())) && dueAsOfDateParam != null) { baseDataValidator.reset().parameter(dueAsOfDateParamName).value(dueAsOfDateParam.toString(fmt)) .failWithCodeNoParameterAddedToErrorCode( "charge.due.date.is.invalid.for." + ChargeTimeType.fromInt(chargeTimeType).getCode()); } final SavingsAccountCharge savingsAccountCharge = SavingsAccountCharge.createNewFromJson(savingsAccount, chargeDefinition, command); if (savingsAccountCharge.getDueLocalDate() != null) { // transaction date should not be on a holiday or non working day if (!this.configurationDomainService.allowTransactionsOnHolidayEnabled() && this.holidayRepository .isHoliday(savingsAccount.officeId(), savingsAccountCharge.getDueLocalDate())) { baseDataValidator.reset().parameter(dueAsOfDateParamName) .value(savingsAccountCharge.getDueLocalDate().toString(fmt)) .failWithCodeNoParameterAddedToErrorCode("charge.due.date.is.on.holiday"); } if (!this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled() && !this.workingDaysRepository.isWorkingDay(savingsAccountCharge.getDueLocalDate())) { baseDataValidator.reset().parameter(dueAsOfDateParamName) .value(savingsAccountCharge.getDueLocalDate().toString(fmt)) .failWithCodeNoParameterAddedToErrorCode("charge.due.date.is.a.nonworking.day"); } } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } savingsAccount.addCharge(fmt, savingsAccountCharge, chargeDefinition); this.savingsAccountChargeRepository.save(savingsAccountCharge); this.savingAccountRepositoryWrapper.saveAndFlush(savingsAccount); return new CommandProcessingResultBuilder() // .withEntityId(savingsAccountCharge.getId()) // .withOfficeId(savingsAccount.officeId()) // .withClientId(savingsAccount.clientId()) // .withGroupId(savingsAccount.groupId()) // .withSavingsId(savingsAccountId) // .build(); }
From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
@Transactional @Override//from w ww . j ava 2 s . c om public CommandProcessingResult updateSavingsAccountCharge(final JsonCommand command) { this.context.authenticatedUser(); this.savingsAccountChargeDataValidator.validateUpdate(command.json()); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(SAVINGS_ACCOUNT_RESOURCE_NAME); final Long savingsAccountId = command.getSavingsId(); // SavingsAccount Charge entity final Long savingsChargeId = command.entityId(); final SavingsAccount savingsAccount = this.savingAccountAssembler.assembleFrom(savingsAccountId); checkClientOrGroupActive(savingsAccount); final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository .findOneWithNotFoundDetection(savingsChargeId, savingsAccountId); final Map<String, Object> changes = savingsAccountCharge.update(command); if (savingsAccountCharge.getDueLocalDate() != null) { final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); // transaction date should not be on a holiday or non working day if (!this.configurationDomainService.allowTransactionsOnHolidayEnabled() && this.holidayRepository .isHoliday(savingsAccount.officeId(), savingsAccountCharge.getDueLocalDate())) { baseDataValidator.reset().parameter(dueAsOfDateParamName) .value(savingsAccountCharge.getDueLocalDate().toString(fmt)) .failWithCodeNoParameterAddedToErrorCode("charge.due.date.is.on.holiday"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } if (!this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled() && !this.workingDaysRepository.isWorkingDay(savingsAccountCharge.getDueLocalDate())) { baseDataValidator.reset().parameter(dueAsOfDateParamName) .value(savingsAccountCharge.getDueLocalDate().toString(fmt)) .failWithCodeNoParameterAddedToErrorCode("charge.due.date.is.a.nonworking.day"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } } this.savingsAccountChargeRepository.saveAndFlush(savingsAccountCharge); return new CommandProcessingResultBuilder() // .withEntityId(savingsAccountCharge.getId()) // .withOfficeId(savingsAccountCharge.savingsAccount().officeId()) // .withClientId(savingsAccountCharge.savingsAccount().clientId()) // .withGroupId(savingsAccountCharge.savingsAccount().groupId()) // .withSavingsId(savingsAccountCharge.savingsAccount().getId()) // .with(changes) // .build(); }
From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
@Override public CommandProcessingResult payCharge(final Long savingsAccountId, final Long savingsAccountChargeId, final JsonCommand command) { AppUser user = getAppUserIfPresent(); this.savingsAccountChargeDataValidator.validatePayCharge(command.json()); final Locale locale = command.extractLocale(); final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale); final BigDecimal amountPaid = command.bigDecimalValueOfParameterNamed(amountParamName); final LocalDate transactionDate = command.localDateValueOfParameterNamed(dueAsOfDateParamName); final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository .findOneWithNotFoundDetection(savingsAccountChargeId, savingsAccountId); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource(SAVINGS_ACCOUNT_RESOURCE_NAME); // transaction date should not be on a holiday or non working day if (!this.configurationDomainService.allowTransactionsOnHolidayEnabled() && this.holidayRepository .isHoliday(savingsAccountCharge.savingsAccount().officeId(), transactionDate)) { baseDataValidator.reset().parameter(dueAsOfDateParamName).value(transactionDate.toString(fmt)) .failWithCodeNoParameterAddedToErrorCode( "transaction.not.allowed.transaction.date.is.on.holiday"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }/*from w w w.j a va 2s. co m*/ } if (!this.configurationDomainService.allowTransactionsOnNonWorkingDayEnabled() && !this.workingDaysRepository.isWorkingDay(transactionDate)) { baseDataValidator.reset().parameter(dueAsOfDateParamName).value(transactionDate.toString(fmt)) .failWithCodeNoParameterAddedToErrorCode( "transaction.not.allowed.transaction.date.is.a.nonworking.day"); if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } } this.payCharge(savingsAccountCharge, transactionDate, amountPaid, fmt, user); return new CommandProcessingResultBuilder() // .withEntityId(savingsAccountCharge.getId()) // .withOfficeId(savingsAccountCharge.savingsAccount().officeId()) // .withClientId(savingsAccountCharge.savingsAccount().clientId()) // .withGroupId(savingsAccountCharge.savingsAccount().groupId()) // .withSavingsId(savingsAccountCharge.savingsAccount().getId()) // .build(); }
From source file:com.gst.portfolio.savings.service.SavingsAccountWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
@Transactional @Override/*from w w w.j av a 2 s . c om*/ public void applyChargeDue(final Long savingsAccountChargeId, final Long accountId) { // always use current date as transaction date for batch job AppUser user = null; final LocalDate transactionDate = DateUtils.getLocalDateOfTenant(); final SavingsAccountCharge savingsAccountCharge = this.savingsAccountChargeRepository .findOneWithNotFoundDetection(savingsAccountChargeId, accountId); final DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MM yyyy"); fmt.withZone(DateUtils.getDateTimeZoneOfTenant()); while (transactionDate.isAfter(savingsAccountCharge.getDueLocalDate()) && savingsAccountCharge.isNotFullyPaid()) { payCharge(savingsAccountCharge, transactionDate, savingsAccountCharge.amoutOutstanding(), fmt, user); } }
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 va2 s .co m*/ 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 va 2s . c om 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.hack23.cia.service.component.agent.impl.riksdagen.workgenerator.RiksdagenDocumentListWorkGeneratorImpl.java
License:Apache License
@Override public void generateWorkOrders() { try {//w ww.j ava 2 s . co m 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.hamdikavak.humanmobility.modeling.test.DataHelper.java
License:Open Source License
private static ExtendedLocationTrace convertLineToAExtendedLocationTraceObject(String line) { String[] columnValues;/*from w w w . j av a 2s. c o m*/ ExtendedLocationTrace trace = new ExtendedLocationTrace(); // a line in the csv file {user_id,utc_time,latitude,longitude} columnValues = line.split(","); String dtString = columnValues[1].replace("\"", "") + "00"; // 00 added to conform time zone format DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ssZ"); String userId = columnValues[0]; DateTime dt = DateTime.parse(dtString, formatter); Double latitude = Double.parseDouble(columnValues[2]); Double longitude = Double.parseDouble(columnValues[3]); trace.setUserId(userId); trace.setUTCTime(dt); trace.setLocalTime(dt.toLocalDateTime()); trace.setCoordinate(new GeoCoordinate(latitude, longitude)); return trace; }
From source file:com.hangum.tadpole.engine.utils.TimeZoneUtil.java
License:Open Source License
/** * prettyDate/*w ww .j ava2 s . co m*/ * @param date * @return */ public static DateTimeFormatter prettyDateTimeFormater() { DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); return dtf; }