List of usage examples for org.joda.time LocalDate toString
@ToString
public String toString()
From source file:com.gst.infrastructure.dataqueries.service.ReadWriteNonCoreDataServiceImpl.java
License:Apache License
private String validateColumn(final ResultsetColumnHeaderData columnHeader, final String pValue, final String dateFormat, final Locale clientApplicationLocale) { String paramValue = pValue;/*from w ww . j a v a2s . c o m*/ if (columnHeader.isDateDisplayType() || columnHeader.isDateTimeDisplayType() || columnHeader.isIntegerDisplayType() || columnHeader.isDecimalDisplayType() || columnHeader.isBooleanDisplayType()) { // only trim if string is not empty and is not null. // throws a NULL pointer exception if the check below is not applied paramValue = StringUtils.isNotEmpty(paramValue) ? paramValue.trim() : paramValue; } if (StringUtils.isEmpty(paramValue) && columnHeader.isMandatory()) { final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final ApiParameterError error = ApiParameterError.parameterError("error.msg.column.mandatory", "Mandatory", columnHeader.getColumnName()); dataValidationErrors.add(error); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } if (StringUtils.isNotEmpty(paramValue)) { if (columnHeader.hasColumnValues()) { if (columnHeader.isCodeValueDisplayType()) { if (columnHeader.isColumnValueNotAllowed(paramValue)) { final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final ApiParameterError error = ApiParameterError.parameterError( "error.msg.invalid.columnValue", "Value not found in Allowed Value list", columnHeader.getColumnName(), paramValue); dataValidationErrors.add(error); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } return paramValue; } else if (columnHeader.isCodeLookupDisplayType()) { final Integer codeLookup = Integer.valueOf(paramValue); if (columnHeader.isColumnCodeNotAllowed(codeLookup)) { final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final ApiParameterError error = ApiParameterError.parameterError( "error.msg.invalid.columnValue", "Value not found in Allowed Value list", columnHeader.getColumnName(), paramValue); dataValidationErrors.add(error); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } return paramValue; } else { throw new PlatformDataIntegrityException("error.msg.invalid.columnType.", "Code: " + columnHeader.getColumnName() + " - Invalid Type " + columnHeader.getColumnType() + " (neither varchar nor int)"); } } if (columnHeader.isDateDisplayType()) { final LocalDate tmpDate = JsonParserHelper.convertFrom(paramValue, columnHeader.getColumnName(), dateFormat, clientApplicationLocale); if (tmpDate == null) { paramValue = null; } else { paramValue = tmpDate.toString(); } } else if (columnHeader.isDateTimeDisplayType()) { final LocalDateTime tmpDateTime = JsonParserHelper.convertDateTimeFrom(paramValue, columnHeader.getColumnName(), dateFormat, clientApplicationLocale); if (tmpDateTime == null) { paramValue = null; } else { paramValue = tmpDateTime.toString(); } } else if (columnHeader.isIntegerDisplayType()) { final Integer tmpInt = this.helper.convertToInteger(paramValue, columnHeader.getColumnName(), clientApplicationLocale); if (tmpInt == null) { paramValue = null; } else { paramValue = tmpInt.toString(); } } else if (columnHeader.isDecimalDisplayType()) { final BigDecimal tmpDecimal = this.helper.convertFrom(paramValue, columnHeader.getColumnName(), clientApplicationLocale); if (tmpDecimal == null) { paramValue = null; } else { paramValue = tmpDecimal.toString(); } } else if (columnHeader.isBooleanDisplayType()) { final Boolean tmpBoolean = BooleanUtils.toBooleanObject(paramValue); if (tmpBoolean == null) { final ApiParameterError error = ApiParameterError.parameterError( "validation.msg.invalid.boolean.format", "The parameter " + columnHeader.getColumnName() + " has value: " + paramValue + " which is invalid boolean value.", columnHeader.getColumnName(), paramValue); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); dataValidationErrors.add(error); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } paramValue = tmpBoolean.toString(); } else if (columnHeader.isString()) { if (paramValue.length() > columnHeader.getColumnLength()) { final ApiParameterError error = ApiParameterError.parameterError( "validation.msg.datatable.entry.column.exceeds.maxlength", "The column `" + columnHeader.getColumnName() + "` exceeds its defined max-length ", columnHeader.getColumnName(), paramValue); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); dataValidationErrors.add(error); throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); } } } return paramValue; }
From source file:com.gst.organisation.holiday.service.HolidayWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
private void validateInputDates(final LocalDate fromDate, final LocalDate toDate, final LocalDate repaymentsRescheduledTo) { String defaultUserMessage = ""; if (toDate.isBefore(fromDate)) { defaultUserMessage = "To Date date cannot be before the From Date."; throw new HolidayDateException("to.date.cannot.be.before.from.date", defaultUserMessage, fromDate.toString(), toDate.toString()); }/*from ww w. j a v a 2 s.c o m*/ if (repaymentsRescheduledTo.isEqual(fromDate) || repaymentsRescheduledTo.isEqual(toDate) || (repaymentsRescheduledTo.isAfter(fromDate) && repaymentsRescheduledTo.isBefore(toDate))) { defaultUserMessage = "Repayments rescheduled date should be before from date or after to date."; throw new HolidayDateException( "repayments.rescheduled.date.should.be.before.from.date.or.after.to.date", defaultUserMessage, repaymentsRescheduledTo.toString()); } final WorkingDays workingDays = this.daysRepositoryWrapper.findOne(); final Boolean isRepaymentOnWorkingDay = WorkingDaysUtil.isWorkingDay(workingDays, repaymentsRescheduledTo); if (!isRepaymentOnWorkingDay) { defaultUserMessage = "Repayments rescheduled date should not fall on non working days"; throw new HolidayDateException("repayments.rescheduled.date.should.not.fall.on.non.working.day", defaultUserMessage, repaymentsRescheduledTo.toString()); } // validate repaymentsRescheduledTo date // 1. should be within a 7 days date range. // 2. Alternative date should not be an exist holiday.//TBD // 3. Holiday should not be on an repaymentsRescheduledTo date of // another holiday.//TBD // restricting repaymentsRescheduledTo date to be within 7 days range // before or after from date and to date. if (repaymentsRescheduledTo.isBefore(fromDate.minusDays(7)) || repaymentsRescheduledTo.isAfter(toDate.plusDays(7))) { defaultUserMessage = "Repayments Rescheduled to date must be within 7 days before or after from and to dates"; throw new HolidayDateException("repayments.rescheduled.to.must.be.within.range", defaultUserMessage, fromDate.toString(), toDate.toString(), repaymentsRescheduledTo.toString()); } }
From source file:com.gst.organisation.teller.serialization.TellerCommandFromApiJsonDeserializer.java
License:Apache License
public void validateForCreateAndUpdateTeller(final String json) { if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }//from w ww.j a va 2s.c o m final Type typeOfMap = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, this.supportedParameters); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors) .resource("teller"); final JsonElement element = this.fromApiJsonHelper.parse(json); final Long officeId = this.fromApiJsonHelper.extractLongNamed("officeId", element); baseDataValidator.reset().parameter("officeId").value(officeId).notNull().integerGreaterThanZero(); final String name = this.fromApiJsonHelper.extractStringNamed("name", element); baseDataValidator.reset().parameter("name").value(name).notBlank().notExceedingLengthOf(50); final String description = this.fromApiJsonHelper.extractStringNamed("description", element); baseDataValidator.reset().parameter("description").value(description).notExceedingLengthOf(100); final LocalDate startDate = this.fromApiJsonHelper.extractLocalDateNamed("startDate", element); baseDataValidator.reset().parameter("startDate").value(startDate).notNull(); final LocalDate endDate = this.fromApiJsonHelper.extractLocalDateNamed("endDate", element); baseDataValidator.reset().parameter("endDate").value(endDate).ignoreIfNull(); final String status = this.fromApiJsonHelper.extractStringNamed("status", element); baseDataValidator.reset().parameter("status").value(status).notBlank().notExceedingLengthOf(50); if (endDate != null) { if (endDate.isBefore(startDate)) { throw new InvalidDateInputException(startDate.toString(), endDate.toString()); } } throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:com.gst.portfolio.calendar.domain.Calendar.java
License:Apache License
public Map<String, Object> updateStartDateAndDerivedFeilds(final LocalDate newMeetingStartDate) { final Map<String, Object> actualChanges = new LinkedHashMap<>(9); final LocalDate currentDate = DateUtils.getLocalDateOfTenant(); if (newMeetingStartDate.isBefore(currentDate)) { final String defaultUserMessage = "New meeting effective from date cannot be in past"; throw new CalendarDateException("new.start.date.cannot.be.in.past", defaultUserMessage, newMeetingStartDate, getStartDateLocalDate()); } else if (isStartDateAfter(newMeetingStartDate) && isStartDateBeforeOrEqual(currentDate)) { // new meeting date should be on or after start date or current // date/*from ww w. j a v a2s . c o m*/ final String defaultUserMessage = "New meeting effective from date cannot be a date before existing meeting start date"; throw new CalendarDateException("new.start.date.before.existing.date", defaultUserMessage, newMeetingStartDate, getStartDateLocalDate()); } else { actualChanges.put(CALENDAR_SUPPORTED_PARAMETERS.START_DATE.getValue(), newMeetingStartDate.toString()); this.startDate = newMeetingStartDate.toDate(); /* * If meeting start date is changed then there is possibilities of * recurring day may change, so derive the recurring day and update * it if it is changed. For weekly type is weekday and for monthly * type it is day of the month */ CalendarFrequencyType calendarFrequencyType = CalendarUtils.getFrequency(this.recurrence); Integer interval = CalendarUtils.getInterval(this.recurrence); Integer repeatsOnDay = null; /* * Repeats on day, need to derive based on the start date */ if (calendarFrequencyType.isWeekly()) { repeatsOnDay = newMeetingStartDate.getDayOfWeek(); } else if (calendarFrequencyType.isMonthly()) { repeatsOnDay = newMeetingStartDate.getDayOfMonth(); } // TODO cover other recurrence also this.recurrence = constructRecurrence(calendarFrequencyType, interval, repeatsOnDay, null); } return actualChanges; }
From source file:com.gst.portfolio.group.service.GroupingTypesWritePlatformServiceJpaRepositoryImpl.java
License:Apache License
public void validateOfficeOpeningDateisAfterGroupOrCenterOpeningDate(final Office groupOffice, final GroupLevel groupLevel, final LocalDate activationDate) { if (activationDate != null && groupOffice.getOpeningLocalDate().isAfter(activationDate)) { final String levelName = groupLevel.getLevelName(); final String errorMessage = levelName + " activation date should be greater than or equal to the parent Office's creation date " + activationDate.toString(); throw new InvalidGroupStateTransitionException(levelName.toLowerCase(), "activate.date", "cannot.be.before.office.activation.date", errorMessage, activationDate, groupOffice.getOpeningLocalDate()); }// w ww. j a va 2s. com }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
public Map<String, Object> loanApplicationApproval(final AppUser currentUser, final JsonCommand command, final JsonArray disbursementDataArray, final LoanLifecycleStateMachine loanLifecycleStateMachine) { validateAccountStatus(LoanEvent.LOAN_APPROVED); final Map<String, Object> actualChanges = new LinkedHashMap<>(); /*/*from w ww . j a v a 2 s. c om*/ * statusEnum is holding the possible new status derived from * loanLifecycleStateMachine.transition. */ final LoanStatus newStatusEnum = loanLifecycleStateMachine.transition(LoanEvent.LOAN_APPROVED, LoanStatus.fromInt(this.loanStatus)); /* * FIXME: There is no need to check below condition, if * loanLifecycleStateMachine.transition is doing it's responsibility * properly. Better implementation approach is, if code passes invalid * combination of states (fromState and toState), state machine should * return invalidate state and below if condition should check for not * equal to invalidateState, instead of check new value is same as * present value. */ if (!newStatusEnum.hasStateOf(LoanStatus.fromInt(this.loanStatus))) { this.loanStatus = newStatusEnum.getValue(); actualChanges.put("status", LoanEnumerations.status(this.loanStatus)); // only do below if status has changed in the 'approval' case LocalDate approvedOn = command.localDateValueOfParameterNamed("approvedOnDate"); String approvedOnDateChange = command.stringValueOfParameterNamed("approvedOnDate"); if (approvedOn == null) { approvedOn = command.localDateValueOfParameterNamed("eventDate"); approvedOnDateChange = command.stringValueOfParameterNamed("eventDate"); } LocalDate expecteddisbursementDate = command.localDateValueOfParameterNamed("expectedDisbursementDate"); BigDecimal approvedLoanAmount = command .bigDecimalValueOfParameterNamed(LoanApiConstants.approvedLoanAmountParameterName); if (approvedLoanAmount != null) { // Approved amount has to be less than or equal to principal // amount demanded if (approvedLoanAmount.compareTo(this.proposedPrincipal) == -1) { this.approvedPrincipal = approvedLoanAmount; /* * All the calculations are done based on the principal * amount, so it is necessary to set principal amount to * approved amount */ this.loanRepaymentScheduleDetail.setPrincipal(approvedLoanAmount); actualChanges.put(LoanApiConstants.approvedLoanAmountParameterName, approvedLoanAmount); actualChanges.put(LoanApiConstants.disbursementPrincipalParameterName, approvedLoanAmount); } else if (approvedLoanAmount.compareTo(this.proposedPrincipal) == 1) { final String errorMessage = "Loan approved amount can't be greater than loan amount demanded."; throw new InvalidLoanStateTransitionException("approval", "amount.can't.be.greater.than.loan.amount.demanded", errorMessage, this.proposedPrincipal, approvedLoanAmount); } /* Update disbursement details */ if (disbursementDataArray != null) { updateDisbursementDetails(command, actualChanges); } } if (loanProduct.isMultiDisburseLoan()) { recalculateAllCharges(); if (this.disbursementDetails.isEmpty()) { final String errorMessage = "For this loan product, disbursement details must be provided"; throw new MultiDisbursementDataRequiredException(LoanApiConstants.disbursementDataParameterName, errorMessage); } if (this.disbursementDetails.size() > loanProduct.maxTrancheCount()) { final String errorMessage = "Number of tranche shouldn't be greter than " + loanProduct.maxTrancheCount(); throw new ExceedingTrancheCountException(LoanApiConstants.disbursementDataParameterName, errorMessage, loanProduct.maxTrancheCount(), disbursementDetails.size()); } } this.approvedOnDate = approvedOn.toDate(); this.approvedBy = currentUser; actualChanges.put("locale", command.locale()); actualChanges.put("dateFormat", command.dateFormat()); actualChanges.put("approvedOnDate", approvedOnDateChange); final LocalDate submittalDate = new LocalDate(this.submittedOnDate); if (approvedOn.isBefore(submittalDate)) { final String errorMessage = "The date on which a loan is approved cannot be before its submittal date: " + submittalDate.toString(); throw new InvalidLoanStateTransitionException("approval", "cannot.be.before.submittal.date", errorMessage, getApprovedOnDate(), submittalDate); } if (expecteddisbursementDate != null) { this.expectedDisbursementDate = expecteddisbursementDate.toDate(); actualChanges.put("expectedDisbursementDate", expectedDisbursementDate); if (expecteddisbursementDate.isBefore(approvedOn)) { final String errorMessage = "The expected disbursement date should be either on or after the approval date: " + approvedOn.toString(); throw new InvalidLoanStateTransitionException("expecteddisbursal", "should.be.on.or.after.approval.date", errorMessage, getApprovedOnDate(), expecteddisbursementDate); } } validateActivityNotBeforeClientOrGroupTransferDate(LoanEvent.LOAN_APPROVED, approvedOn); if (approvedOn.isAfter(DateUtils.getLocalDateOfTenant())) { final String errorMessage = "The date on which a loan is approved cannot be in the future."; throw new InvalidLoanStateTransitionException("approval", "cannot.be.a.future.date", errorMessage, getApprovedOnDate()); } if (this.loanOfficer != null) { final LoanOfficerAssignmentHistory loanOfficerAssignmentHistory = LoanOfficerAssignmentHistory .createNew(this, this.loanOfficer, approvedOn); this.loanOfficerHistory.add(loanOfficerAssignmentHistory); } } return actualChanges; }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
public void reassignLoanOfficer(final Staff newLoanOfficer, final LocalDate assignmentDate) { final LoanOfficerAssignmentHistory latestHistoryRecord = findLatestIncompleteHistoryRecord(); final LoanOfficerAssignmentHistory lastAssignmentRecord = findLastAssignmentHistoryRecord(newLoanOfficer); // assignment date should not be less than loan submitted date if (isSubmittedOnDateAfter(assignmentDate)) { final String errorMessage = "The Loan Officer assignment date (" + assignmentDate.toString() + ") cannot be before loan submitted date (" + getSubmittedOnDate().toString() + ")."; throw new LoanOfficerAssignmentDateException("cannot.be.before.loan.submittal.date", errorMessage, assignmentDate, getSubmittedOnDate()); } else if (lastAssignmentRecord != null && lastAssignmentRecord.isEndDateAfter(assignmentDate)) { final String errorMessage = "The Loan Officer assignment date (" + assignmentDate + ") cannot be before previous Loan Officer unassigned date (" + lastAssignmentRecord.getEndDate() + ")."; throw new LoanOfficerAssignmentDateException("cannot.be.before.previous.unassignement.date", errorMessage, assignmentDate, lastAssignmentRecord.getEndDate()); } else if (DateUtils.getLocalDateOfTenant().isBefore(assignmentDate)) { final String errorMessage = "The Loan Officer assignment date (" + assignmentDate + ") cannot be in the future."; throw new LoanOfficerAssignmentDateException("cannot.be.a.future.date", errorMessage, assignmentDate); } else if (latestHistoryRecord != null && this.loanOfficer.identifiedBy(newLoanOfficer)) { latestHistoryRecord.updateStartDate(assignmentDate); } else if (latestHistoryRecord != null && latestHistoryRecord.matchesStartDateOf(assignmentDate)) { latestHistoryRecord.updateLoanOfficer(newLoanOfficer); this.loanOfficer = newLoanOfficer; } else if (latestHistoryRecord != null && latestHistoryRecord.hasStartDateBefore(assignmentDate)) { final String errorMessage = "Loan with identifier " + getId() + " was already assigned before date " + assignmentDate;/*from ww w.jav a2s . c o m*/ throw new LoanOfficerAssignmentDateException("is.before.last.assignment.date", errorMessage, getId(), assignmentDate); } else { if (latestHistoryRecord != null) { // loan officer correctly changed from previous loan officer to // new loan officer latestHistoryRecord.updateEndDate(assignmentDate); } this.loanOfficer = newLoanOfficer; if (isNotSubmittedAndPendingApproval()) { final LoanOfficerAssignmentHistory loanOfficerAssignmentHistory = LoanOfficerAssignmentHistory .createNew(this, this.loanOfficer, assignmentDate); this.loanOfficerHistory.add(loanOfficerAssignmentHistory); } } }
From source file:com.gst.portfolio.loanaccount.domain.Loan.java
License:Apache License
private void validateRefundDateIsAfterLastRepayment(final LocalDate refundTransactionDate) { final LocalDate possibleNextRefundDate = possibleNextRefundDate(); if (possibleNextRefundDate == null || refundTransactionDate.isBefore(possibleNextRefundDate)) { throw new InvalidRefundDateException(refundTransactionDate.toString()); }// w ww. j a va2 s. co m }
From source file:com.gst.portfolio.loanaccount.exception.LoanOfficerAssignmentException.java
License:Apache License
public LoanOfficerAssignmentException(final Long loanId, final LocalDate date) { super("error.msg.loan.assignment.date.is.before.last.assignment.date", "Loan with identifier " + loanId + " was already assigned before date " + date.toString()); }
From source file:com.gst.portfolio.loanaccount.serialization.LoanEventApiJsonValidator.java
License:Apache License
public void validateDisbursementDateWithMeetingDate(final LocalDate actualDisbursementDate, final CalendarInstance calendarInstance, Boolean isSkipRepaymentOnFirstMonth, Integer numberOfDays) { if (null != calendarInstance) { final Calendar calendar = calendarInstance.getCalendar(); if (!calendar.isValidRecurringDate(actualDisbursementDate, isSkipRepaymentOnFirstMonth, numberOfDays)) { // Disbursement date should fall on a meeting date final String errorMessage = "Expected disbursement date '" + actualDisbursementDate.toString() + "' does not fall on a meeting date."; throw new NotValidRecurringDateException("loan.actual.disbursement.date", errorMessage, actualDisbursementDate.toString(), calendar.getTitle()); }/*from ww w . j a v a 2 s . c om*/ } }