List of usage examples for org.apache.commons.lang StringUtils lowerCase
public static String lowerCase(String str)
Converts a String to lower case as per String#toLowerCase() .
From source file:org.apache.fineract.infrastructure.dataexport.helper.FileHelper.java
/** * Creates a data export XLS file/* w w w . ja v a 2s . c o m*/ * * @param sqlRowSet * @param fileName * @return {@link DataExportFileData} object */ public static DataExportFileData createDataExportXlsFile(final SqlRowSet sqlRowSet, final String fileName, final HashMap<Long, CodeValueData> codeValueMap, final HashMap<Long, AppUserData> appUserMap, final DataExportCoreTable coreTable) { DataExportFileData dataExportFileData = null; try { final String fileNamePlusExtension = fileName + "." + StringUtils.lowerCase(DataExportApiConstants.XLS_FILE_FORMAT); final File parentDirectoryPath = FileHelper.getDataExportDirectoryPath(); final File file = new File(parentDirectoryPath, fileNamePlusExtension); // create a new xls file on the server XlsFileHelper.createFile(sqlRowSet, file, codeValueMap, appUserMap, coreTable); dataExportFileData = new DataExportFileData(file, fileNamePlusExtension, DataExportApiConstants.XLS_FILE_CONTENT_TYPE); } catch (Exception exception) { logger.error(exception.getMessage(), exception); } return dataExportFileData; }
From source file:org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobValidator.java
/** * validate the request to create a new report mailing job * // w w w . j a v a2 s . c o m * @param jsonCommand -- the JSON command object (instance of the JsonCommand class) * @return None **/ public void validateCreateRequest(final JsonCommand jsonCommand) { final String jsonString = jsonCommand.json(); final JsonElement jsonElement = jsonCommand.parsedJson(); if (StringUtils.isBlank(jsonString)) { throw new InvalidJsonException(); } final Type typeToken = new TypeToken<Map<String, Object>>() { }.getType(); this.fromJsonHelper.checkForUnsupportedParameters(typeToken, jsonString, ReportMailingJobConstants.CREATE_REQUEST_PARAMETERS); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors) .resource(StringUtils.lowerCase(ReportMailingJobConstants.REPORT_MAILING_JOB_ENTITY_NAME)); final String name = this.fromJsonHelper.extractStringNamed(ReportMailingJobConstants.NAME_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.NAME_PARAM_NAME).value(name).notBlank() .notExceedingLengthOf(100); final String startDateTime = this.fromJsonHelper .extractStringNamed(ReportMailingJobConstants.START_DATE_TIME_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.START_DATE_TIME_PARAM_NAME) .value(startDateTime).notBlank(); final Integer stretchyReportId = this.fromJsonHelper.extractIntegerWithLocaleNamed( ReportMailingJobConstants.STRETCHY_REPORT_ID_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.STRETCHY_REPORT_ID_PARAM_NAME) .value(stretchyReportId).notNull().integerGreaterThanZero(); final String emailRecipients = this.fromJsonHelper .extractStringNamed(ReportMailingJobConstants.EMAIL_RECIPIENTS_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.EMAIL_RECIPIENTS_PARAM_NAME) .value(emailRecipients).notBlank(); final String emailSubject = this.fromJsonHelper .extractStringNamed(ReportMailingJobConstants.EMAIL_SUBJECT_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.EMAIL_SUBJECT_PARAM_NAME) .value(emailSubject).notBlank().notExceedingLengthOf(100); final String emailMessage = this.fromJsonHelper .extractStringNamed(ReportMailingJobConstants.EMAIL_MESSAGE_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.EMAIL_MESSAGE_PARAM_NAME) .value(emailMessage).notBlank(); if (this.fromJsonHelper.parameterExists(ReportMailingJobConstants.IS_ACTIVE_PARAM_NAME, jsonElement)) { final Boolean isActive = this.fromJsonHelper .extractBooleanNamed(ReportMailingJobConstants.IS_ACTIVE_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.IS_ACTIVE_PARAM_NAME).value(isActive) .notNull(); } final Integer emailAttachmentFileFormatId = this.fromJsonHelper.extractIntegerSansLocaleNamed( ReportMailingJobConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME) .value(emailAttachmentFileFormatId).notNull(); if (emailAttachmentFileFormatId != null) { dataValidatorBuilder.reset() .parameter(ReportMailingJobConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME) .value(emailAttachmentFileFormatId) .isOneOfTheseValues(ReportMailingJobEmailAttachmentFileFormat.validValues()); } final String dateFormat = jsonCommand.dateFormat(); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.DATE_FORMAT_PARAM_NAME).value(dateFormat) .notBlank(); if (StringUtils.isNotEmpty(dateFormat)) { try { final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(dateFormat) .withLocale(jsonCommand.extractLocale()); // try to parse the date time string LocalDateTime.parse(startDateTime, dateTimeFormatter); } catch (IllegalArgumentException ex) { dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.DATE_FORMAT_PARAM_NAME) .value(dateFormat).failWithCode("invalid.date.format"); } } throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:org.apache.fineract.infrastructure.reportmailingjob.data.ReportMailingJobValidator.java
/** * validate the request to update a report mailing job * /*from w w w.jav a 2s. co m*/ * @param jsonCommand -- the JSON command object (instance of the JsonCommand class) * @return None **/ public void validateUpdateRequest(final JsonCommand jsonCommand) { final String jsonString = jsonCommand.json(); final JsonElement jsonElement = jsonCommand.parsedJson(); if (StringUtils.isBlank(jsonString)) { throw new InvalidJsonException(); } final Type typeToken = new TypeToken<Map<String, Object>>() { }.getType(); this.fromJsonHelper.checkForUnsupportedParameters(typeToken, jsonString, ReportMailingJobConstants.UPDATE_REQUEST_PARAMETERS); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors) .resource(StringUtils.lowerCase(ReportMailingJobConstants.REPORT_MAILING_JOB_ENTITY_NAME)); if (this.fromJsonHelper.parameterExists(ReportMailingJobConstants.NAME_PARAM_NAME, jsonElement)) { final String name = this.fromJsonHelper.extractStringNamed(ReportMailingJobConstants.NAME_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.NAME_PARAM_NAME).value(name).notBlank() .notExceedingLengthOf(100); } if (this.fromJsonHelper.parameterExists(ReportMailingJobConstants.STRETCHY_REPORT_ID_PARAM_NAME, jsonElement)) { final Integer stretchyReportId = this.fromJsonHelper.extractIntegerWithLocaleNamed( ReportMailingJobConstants.STRETCHY_REPORT_ID_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.STRETCHY_REPORT_ID_PARAM_NAME) .value(stretchyReportId).notNull().integerGreaterThanZero(); } if (this.fromJsonHelper.parameterExists(ReportMailingJobConstants.EMAIL_RECIPIENTS_PARAM_NAME, jsonElement)) { final String emailRecipients = this.fromJsonHelper .extractStringNamed(ReportMailingJobConstants.EMAIL_RECIPIENTS_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.EMAIL_RECIPIENTS_PARAM_NAME) .value(emailRecipients).notBlank(); } if (this.fromJsonHelper.parameterExists(ReportMailingJobConstants.EMAIL_SUBJECT_PARAM_NAME, jsonElement)) { final String emailSubject = this.fromJsonHelper .extractStringNamed(ReportMailingJobConstants.EMAIL_SUBJECT_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.EMAIL_SUBJECT_PARAM_NAME) .value(emailSubject).notBlank().notExceedingLengthOf(100); } if (this.fromJsonHelper.parameterExists(ReportMailingJobConstants.EMAIL_MESSAGE_PARAM_NAME, jsonElement)) { final String emailMessage = this.fromJsonHelper .extractStringNamed(ReportMailingJobConstants.EMAIL_MESSAGE_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.EMAIL_MESSAGE_PARAM_NAME) .value(emailMessage).notBlank(); } if (this.fromJsonHelper.parameterExists(ReportMailingJobConstants.IS_ACTIVE_PARAM_NAME, jsonElement)) { final Boolean isActive = this.fromJsonHelper .extractBooleanNamed(ReportMailingJobConstants.IS_ACTIVE_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.IS_ACTIVE_PARAM_NAME).value(isActive) .notNull(); } if (this.fromJsonHelper.parameterExists( ReportMailingJobConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME, jsonElement)) { final Integer emailAttachmentFileFormatId = this.fromJsonHelper.extractIntegerSansLocaleNamed( ReportMailingJobConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME, jsonElement); dataValidatorBuilder.reset() .parameter(ReportMailingJobConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME) .value(emailAttachmentFileFormatId).notNull(); if (emailAttachmentFileFormatId != null) { dataValidatorBuilder.reset() .parameter(ReportMailingJobConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME) .value(emailAttachmentFileFormatId) .isOneOfTheseValues(ReportMailingJobEmailAttachmentFileFormat.validValues()); } } if (this.fromJsonHelper.parameterExists(ReportMailingJobConstants.START_DATE_TIME_PARAM_NAME, jsonElement)) { final String dateFormat = jsonCommand.dateFormat(); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.DATE_FORMAT_PARAM_NAME) .value(dateFormat).notBlank(); final String startDateTime = this.fromJsonHelper .extractStringNamed(ReportMailingJobConstants.START_DATE_TIME_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.START_DATE_TIME_PARAM_NAME) .value(startDateTime).notBlank(); if (StringUtils.isNotEmpty(dateFormat)) { try { final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(dateFormat) .withLocale(jsonCommand.extractLocale()); // try to parse the date time string LocalDateTime.parse(startDateTime, dateTimeFormatter); } catch (IllegalArgumentException ex) { dataValidatorBuilder.reset().parameter(ReportMailingJobConstants.DATE_FORMAT_PARAM_NAME) .value(dateFormat).failWithCode("invalid.date.format"); } } } throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:org.apache.fineract.infrastructure.scheduledemail.data.EmailDataValidator.java
/** * validate the request to create a new report mailing job * * @param jsonCommand -- the JSON command object (instance of the JsonCommand class) * @return None// w w w . j a va 2 s. co m **/ public void validateCreateRequest(final JsonCommand jsonCommand) { final String jsonString = jsonCommand.json(); final JsonElement jsonElement = jsonCommand.parsedJson(); if (StringUtils.isBlank(jsonString)) { throw new InvalidJsonException(); } final Type typeToken = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeToken, jsonString, ScheduledEmailConstants.CREATE_REQUEST_PARAMETERS); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors) .resource(StringUtils.lowerCase(ScheduledEmailConstants.SCHEDULED_EMAIL_ENTITY_NAME)); final String name = this.fromApiJsonHelper.extractStringNamed(ScheduledEmailConstants.NAME_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.NAME_PARAM_NAME).value(name).notBlank() .notExceedingLengthOf(100); final String startDateTime = this.fromApiJsonHelper .extractStringNamed(ScheduledEmailConstants.START_DATE_TIME_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.START_DATE_TIME_PARAM_NAME) .value(startDateTime).notBlank(); final Integer stretchyReportId = this.fromApiJsonHelper .extractIntegerWithLocaleNamed(ScheduledEmailConstants.STRETCHY_REPORT_ID_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.STRETCHY_REPORT_ID_PARAM_NAME) .value(stretchyReportId).notNull().integerGreaterThanZero(); final String emailRecipients = this.fromApiJsonHelper .extractStringNamed(ScheduledEmailConstants.EMAIL_RECIPIENTS_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.EMAIL_RECIPIENTS_PARAM_NAME) .value(emailRecipients).notBlank(); final String emailSubject = this.fromApiJsonHelper .extractStringNamed(ScheduledEmailConstants.EMAIL_SUBJECT_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.EMAIL_SUBJECT_PARAM_NAME).value(emailSubject) .notBlank().notExceedingLengthOf(100); final String emailMessage = this.fromApiJsonHelper .extractStringNamed(ScheduledEmailConstants.EMAIL_MESSAGE_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.EMAIL_MESSAGE_PARAM_NAME).value(emailMessage) .notBlank(); if (this.fromApiJsonHelper.parameterExists(ScheduledEmailConstants.IS_ACTIVE_PARAM_NAME, jsonElement)) { final Boolean isActive = this.fromApiJsonHelper .extractBooleanNamed(ScheduledEmailConstants.IS_ACTIVE_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.IS_ACTIVE_PARAM_NAME).value(isActive) .notNull(); } final Integer emailAttachmentFileFormatId = this.fromApiJsonHelper.extractIntegerSansLocaleNamed( ScheduledEmailConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME) .value(emailAttachmentFileFormatId).notNull(); if (emailAttachmentFileFormatId != null) { dataValidatorBuilder.reset() .parameter(ScheduledEmailConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME) .value(emailAttachmentFileFormatId) .isOneOfTheseValues(ScheduledEmailAttachmentFileFormat.validValues()); } final String dateFormat = jsonCommand.dateFormat(); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.DATE_FORMAT_PARAM_NAME).value(dateFormat) .notBlank(); if (StringUtils.isNotEmpty(dateFormat)) { try { final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(dateFormat) .withLocale(jsonCommand.extractLocale()); // try to parse the date time string LocalDateTime.parse(startDateTime, dateTimeFormatter); } catch (IllegalArgumentException ex) { dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.DATE_FORMAT_PARAM_NAME) .value(dateFormat).failWithCode("invalid.date.format"); } } throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:org.apache.fineract.infrastructure.scheduledemail.data.EmailDataValidator.java
/** * validate the request to update a report mailing job * * @param jsonCommand -- the JSON command object (instance of the JsonCommand class) * @return None//from w ww . j av a2 s. c om **/ public void validateUpdateRequest(final JsonCommand jsonCommand) { final String jsonString = jsonCommand.json(); final JsonElement jsonElement = jsonCommand.parsedJson(); if (StringUtils.isBlank(jsonString)) { throw new InvalidJsonException(); } final Type typeToken = new TypeToken<Map<String, Object>>() { }.getType(); this.fromApiJsonHelper.checkForUnsupportedParameters(typeToken, jsonString, ScheduledEmailConstants.UPDATE_REQUEST_PARAMETERS); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors) .resource(StringUtils.lowerCase(ScheduledEmailConstants.SCHEDULED_EMAIL_ENTITY_NAME)); if (this.fromApiJsonHelper.parameterExists(ScheduledEmailConstants.NAME_PARAM_NAME, jsonElement)) { final String name = this.fromApiJsonHelper.extractStringNamed(ScheduledEmailConstants.NAME_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.NAME_PARAM_NAME).value(name).notBlank() .notExceedingLengthOf(100); } if (this.fromApiJsonHelper.parameterExists(ScheduledEmailConstants.STRETCHY_REPORT_ID_PARAM_NAME, jsonElement)) { final Integer stretchyReportId = this.fromApiJsonHelper.extractIntegerWithLocaleNamed( ScheduledEmailConstants.STRETCHY_REPORT_ID_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.STRETCHY_REPORT_ID_PARAM_NAME) .value(stretchyReportId).notNull().integerGreaterThanZero(); } if (this.fromApiJsonHelper.parameterExists(ScheduledEmailConstants.EMAIL_RECIPIENTS_PARAM_NAME, jsonElement)) { final String emailRecipients = this.fromApiJsonHelper .extractStringNamed(ScheduledEmailConstants.EMAIL_RECIPIENTS_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.EMAIL_RECIPIENTS_PARAM_NAME) .value(emailRecipients).notBlank(); } if (this.fromApiJsonHelper.parameterExists(ScheduledEmailConstants.EMAIL_SUBJECT_PARAM_NAME, jsonElement)) { final String emailSubject = this.fromApiJsonHelper .extractStringNamed(ScheduledEmailConstants.EMAIL_SUBJECT_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.EMAIL_SUBJECT_PARAM_NAME) .value(emailSubject).notBlank().notExceedingLengthOf(100); } if (this.fromApiJsonHelper.parameterExists(ScheduledEmailConstants.EMAIL_MESSAGE_PARAM_NAME, jsonElement)) { final String emailMessage = this.fromApiJsonHelper .extractStringNamed(ScheduledEmailConstants.EMAIL_MESSAGE_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.EMAIL_MESSAGE_PARAM_NAME) .value(emailMessage).notBlank(); } if (this.fromApiJsonHelper.parameterExists(ScheduledEmailConstants.IS_ACTIVE_PARAM_NAME, jsonElement)) { final Boolean isActive = this.fromApiJsonHelper .extractBooleanNamed(ScheduledEmailConstants.IS_ACTIVE_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.IS_ACTIVE_PARAM_NAME).value(isActive) .notNull(); } if (this.fromApiJsonHelper .parameterExists(ScheduledEmailConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME, jsonElement)) { final Integer emailAttachmentFileFormatId = this.fromApiJsonHelper.extractIntegerSansLocaleNamed( ScheduledEmailConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME, jsonElement); dataValidatorBuilder.reset() .parameter(ScheduledEmailConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME) .value(emailAttachmentFileFormatId).notNull(); if (emailAttachmentFileFormatId != null) { dataValidatorBuilder.reset() .parameter(ScheduledEmailConstants.EMAIL_ATTACHMENT_FILE_FORMAT_ID_PARAM_NAME) .value(emailAttachmentFileFormatId) .isOneOfTheseValues(ScheduledEmailAttachmentFileFormat.validValues()); } } if (this.fromApiJsonHelper.parameterExists(ScheduledEmailConstants.START_DATE_TIME_PARAM_NAME, jsonElement)) { final String dateFormat = jsonCommand.dateFormat(); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.DATE_FORMAT_PARAM_NAME).value(dateFormat) .notBlank(); final String startDateTime = this.fromApiJsonHelper .extractStringNamed(ScheduledEmailConstants.START_DATE_TIME_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.START_DATE_TIME_PARAM_NAME) .value(startDateTime).notBlank(); if (StringUtils.isNotEmpty(dateFormat)) { try { final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(dateFormat) .withLocale(jsonCommand.extractLocale()); // try to parse the date time string LocalDateTime.parse(startDateTime, dateTimeFormatter); } catch (IllegalArgumentException ex) { dataValidatorBuilder.reset().parameter(ScheduledEmailConstants.DATE_FORMAT_PARAM_NAME) .value(dateFormat).failWithCode("invalid.date.format"); } } } throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:org.apache.fineract.portfolio.creditcheck.data.CreditCheckDataValidator.java
/** * validate the request to create a new credit check * //from www.ja v a 2 s .com * @param jsonCommand -- the JSON command object (instance of the JsonCommand class) * @return None **/ public void validateForCreateAction(final JsonCommand jsonCommand) { final String jsonString = jsonCommand.json(); final JsonElement jsonElement = jsonCommand.parsedJson(); if (StringUtils.isBlank(jsonString)) { throw new InvalidJsonException(); } final Type typeToken = new TypeToken<Map<String, Object>>() { }.getType(); this.fromJsonHelper.checkForUnsupportedParameters(typeToken, jsonString, CreditCheckConstants.CREATE_REQUEST_PARAMETERS); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors) .resource(StringUtils.lowerCase(CreditCheckConstants.CREDIT_CHECK_ENTITY_NAME)); final String name = this.fromJsonHelper.extractStringNamed(CreditCheckConstants.NAME_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(CreditCheckConstants.NAME_PARAM_NAME).value(name).notBlank() .notExceedingLengthOf(100); final Integer creditCheckRelatedEntity = this.fromJsonHelper .extractIntegerSansLocaleNamed(CreditCheckConstants.RELATED_ENTITY_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(CreditCheckConstants.RELATED_ENTITY_PARAM_NAME) .value(creditCheckRelatedEntity).notNull(); if (creditCheckRelatedEntity != null) { dataValidatorBuilder.reset().parameter(CreditCheckConstants.RELATED_ENTITY_PARAM_NAME) .value(creditCheckRelatedEntity).isOneOfTheseValues(CreditCheckRelatedEntity.validValues()); } if (this.fromJsonHelper.parameterExists(CreditCheckConstants.IS_ACTIVE_PARAM_NAME, jsonElement)) { final Boolean isActive = this.fromJsonHelper .extractBooleanNamed(CreditCheckConstants.IS_ACTIVE_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(CreditCheckConstants.IS_ACTIVE_PARAM_NAME).value(isActive) .notNull(); } final String expectedResult = this.fromJsonHelper .extractStringNamed(CreditCheckConstants.EXPECTED_RESULT_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(CreditCheckConstants.EXPECTED_RESULT_PARAM_NAME) .value(expectedResult).notBlank().notExceedingLengthOf(20); final Integer severityLevel = this.fromJsonHelper .extractIntegerSansLocaleNamed(CreditCheckConstants.SEVERITY_LEVEL_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(CreditCheckConstants.SEVERITY_LEVEL_PARAM_NAME).value(severityLevel) .notNull(); if (severityLevel != null) { dataValidatorBuilder.reset().parameter(CreditCheckConstants.SEVERITY_LEVEL_PARAM_NAME) .value(severityLevel).isOneOfTheseValues(CreditCheckSeverityLevel.validValues()); } final Integer stretchyReportId = this.fromJsonHelper .extractIntegerWithLocaleNamed(CreditCheckConstants.STRETCHY_REPORT_ID_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(CreditCheckConstants.STRETCHY_REPORT_ID_PARAM_NAME) .value(stretchyReportId).notNull(); final String message = this.fromJsonHelper.extractStringNamed(CreditCheckConstants.MESSAGE_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(CreditCheckConstants.MESSAGE_PARAM_NAME).value(message).notBlank() .notExceedingLengthOf(500); throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:org.apache.fineract.portfolio.creditcheck.data.CreditCheckDataValidator.java
/** * validate the request to update a credit check * // w w w.j a v a 2 s .c o m * @param jsonCommand -- the JSON command object (instance of the JsonCommand class) * @return None **/ public void validateForUpdateAction(final JsonCommand jsonCommand) { final String jsonString = jsonCommand.json(); final JsonElement jsonElement = jsonCommand.parsedJson(); if (StringUtils.isBlank(jsonString)) { throw new InvalidJsonException(); } final Type typeToken = new TypeToken<Map<String, Object>>() { }.getType(); this.fromJsonHelper.checkForUnsupportedParameters(typeToken, jsonString, CreditCheckConstants.UPDATE_REQUEST_PARAMETERS); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors) .resource(StringUtils.lowerCase(CreditCheckConstants.CREDIT_CHECK_ENTITY_NAME)); if (this.fromJsonHelper.parameterExists(CreditCheckConstants.NAME_PARAM_NAME, jsonElement)) { final String name = this.fromJsonHelper.extractStringNamed(CreditCheckConstants.NAME_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(CreditCheckConstants.NAME_PARAM_NAME).value(name).notBlank() .notExceedingLengthOf(100); } if (this.fromJsonHelper.parameterExists(CreditCheckConstants.IS_ACTIVE_PARAM_NAME, jsonElement)) { final Boolean isActive = this.fromJsonHelper .extractBooleanNamed(CreditCheckConstants.IS_ACTIVE_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(CreditCheckConstants.IS_ACTIVE_PARAM_NAME).value(isActive) .notNull(); } if (this.fromJsonHelper.parameterExists(CreditCheckConstants.EXPECTED_RESULT_PARAM_NAME, jsonElement)) { final String expectedResult = this.fromJsonHelper .extractStringNamed(CreditCheckConstants.EXPECTED_RESULT_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(CreditCheckConstants.EXPECTED_RESULT_PARAM_NAME) .value(expectedResult).notBlank().notExceedingLengthOf(20); } if (this.fromJsonHelper.parameterExists(CreditCheckConstants.SEVERITY_LEVEL_PARAM_NAME, jsonElement)) { final Integer severityLevel = this.fromJsonHelper .extractIntegerSansLocaleNamed(CreditCheckConstants.SEVERITY_LEVEL_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(CreditCheckConstants.SEVERITY_LEVEL_PARAM_NAME) .value(severityLevel).notNull().isOneOfTheseValues(CreditCheckSeverityLevel.validValues()); } if (this.fromJsonHelper.parameterExists(CreditCheckConstants.STRETCHY_REPORT_ID_PARAM_NAME, jsonElement)) { final Integer stretchyReportId = this.fromJsonHelper .extractIntegerWithLocaleNamed(CreditCheckConstants.STRETCHY_REPORT_ID_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(CreditCheckConstants.STRETCHY_REPORT_ID_PARAM_NAME) .value(stretchyReportId).notNull(); } if (this.fromJsonHelper.parameterExists(CreditCheckConstants.MESSAGE_PARAM_NAME, jsonElement)) { final String message = this.fromJsonHelper.extractStringNamed(CreditCheckConstants.MESSAGE_PARAM_NAME, jsonElement); dataValidatorBuilder.reset().parameter(CreditCheckConstants.MESSAGE_PARAM_NAME).value(message) .notBlank().notExceedingLengthOf(500); } throwExceptionIfValidationWarningsExist(dataValidationErrors); }
From source file:org.apache.fineract.portfolio.loanaccount.rescheduleloan.data.LoanRescheduleRequestDataValidator.java
/** * Validates the request to create a new loan reschedule entry * /* ww w .j a va2 s . c om*/ * @param jsonCommand * the JSON command object (instance of the JsonCommand class) * @return void **/ public void validateForCreateAction(final JsonCommand jsonCommand, final Loan loan) { final String jsonString = jsonCommand.json(); if (StringUtils.isBlank(jsonString)) { throw new InvalidJsonException(); } final Type typeToken = new TypeToken<Map<String, Object>>() { }.getType(); this.fromJsonHelper.checkForUnsupportedParameters(typeToken, jsonString, RescheduleLoansApiConstants.CREATE_REQUEST_DATA_PARAMETERS); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors) .resource(StringUtils.lowerCase(RescheduleLoansApiConstants.ENTITY_NAME)); final JsonElement jsonElement = jsonCommand.parsedJson(); if (!loan.status().isActive()) { dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode("loan.is.not.active", "Loan is not active"); } final Long loanId = this.fromJsonHelper.extractLongNamed(RescheduleLoansApiConstants.loanIdParamName, jsonElement); dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.loanIdParamName).value(loanId).notNull() .integerGreaterThanZero(); final LocalDate submittedOnDate = this.fromJsonHelper .extractLocalDateNamed(RescheduleLoansApiConstants.submittedOnDateParamName, jsonElement); dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.submittedOnDateParamName) .value(submittedOnDate).notNull(); if (submittedOnDate != null && loan.getDisbursementDate().isAfter(submittedOnDate)) { dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.submittedOnDateParamName) .failWithCode("before.loan.disbursement.date", "Submission date cannot be before the loan disbursement date"); } final LocalDate rescheduleFromDate = this.fromJsonHelper .extractLocalDateNamed(RescheduleLoansApiConstants.rescheduleFromDateParamName, jsonElement); dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName) .value(rescheduleFromDate).notNull(); final Integer graceOnPrincipal = this.fromJsonHelper .extractIntegerWithLocaleNamed(RescheduleLoansApiConstants.graceOnPrincipalParamName, jsonElement); dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.graceOnPrincipalParamName) .value(graceOnPrincipal).ignoreIfNull().integerGreaterThanZero(); final Integer graceOnInterest = this.fromJsonHelper .extractIntegerWithLocaleNamed(RescheduleLoansApiConstants.graceOnInterestParamName, jsonElement); dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.graceOnInterestParamName) .value(graceOnInterest).ignoreIfNull().integerGreaterThanZero(); final Integer extraTerms = this.fromJsonHelper .extractIntegerWithLocaleNamed(RescheduleLoansApiConstants.extraTermsParamName, jsonElement); dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.extraTermsParamName).value(extraTerms) .ignoreIfNull().integerGreaterThanZero(); final Long rescheduleReasonId = this.fromJsonHelper .extractLongNamed(RescheduleLoansApiConstants.rescheduleReasonIdParamName, jsonElement); dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleReasonIdParamName) .value(rescheduleReasonId).notNull().integerGreaterThanZero(); final String rescheduleReasonComment = this.fromJsonHelper .extractStringNamed(RescheduleLoansApiConstants.rescheduleReasonCommentParamName, jsonElement); dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleReasonCommentParamName) .value(rescheduleReasonComment).ignoreIfNull().notExceedingLengthOf(500); final LocalDate adjustedDueDate = this.fromJsonHelper .extractLocalDateNamed(RescheduleLoansApiConstants.adjustedDueDateParamName, jsonElement); if (adjustedDueDate != null && rescheduleFromDate != null && adjustedDueDate.isBefore(rescheduleFromDate)) { dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName) .failWithCode("adjustedDueDate.before.rescheduleFromDate", "Adjusted due date cannot be before the reschedule from date"); } // at least one of the following must be provided => graceOnPrincipal, // graceOnInterest, extraTerms, newInterestRate if (!this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.graceOnPrincipalParamName, jsonElement) && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.graceOnInterestParamName, jsonElement) && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.extraTermsParamName, jsonElement) && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.newInterestRateParamName, jsonElement) && !this.fromJsonHelper.parameterExists(RescheduleLoansApiConstants.adjustedDueDateParamName, jsonElement)) { dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.graceOnPrincipalParamName).notNull(); } if (rescheduleFromDate != null) { LoanRepaymentScheduleInstallment installment = loan.getRepaymentScheduleInstallment(rescheduleFromDate); if (installment == null) { dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName) .failWithCode("repayment.schedule.installment.does.not.exist", "Repayment schedule installment does not exist"); } if (installment != null && installment.isObligationsMet()) { dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName) .failWithCode("repayment.schedule.installment.obligation.met", "Repayment schedule installment obligation met"); } if (installment != null && installment.isPartlyPaid()) { dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.rescheduleFromDateParamName) .failWithCode("repayment.schedule.installment.partly.paid", "Repayment schedule installment is partly paid"); } } if (loanId != null) { List<LoanRescheduleRequestData> loanRescheduleRequestData = this.loanRescheduleRequestReadPlatformService .readLoanRescheduleRequests(loanId, LoanStatus.APPROVED.getValue()); if (loanRescheduleRequestData.size() > 0) { dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode("loan.already.rescheduled", "The loan can only be rescheduled once."); } } if (loan.isMultiDisburmentLoan()) { dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode( RescheduleLoansApiConstants.resheduleForMultiDisbursementNotSupportedErrorCode, "Loan rescheduling is not supported for multidisbursement loans"); } if (loan.isInterestRecalculationEnabledForProduct()) { dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode( RescheduleLoansApiConstants.resheduleWithInterestRecalculationNotSupportedErrorCode, "Loan rescheduling is not supported for the loan product with interest recalculation enabled"); } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } }
From source file:org.apache.fineract.portfolio.loanaccount.rescheduleloan.data.LoanRescheduleRequestDataValidator.java
/** * Validates a user request to approve a loan reschedule request * //from w ww . j av a 2s.com * @param jsonCommand * the JSON command object (instance of the JsonCommand class) * @return void **/ public void validateForApproveAction(final JsonCommand jsonCommand, LoanRescheduleRequest loanRescheduleRequest) { final String jsonString = jsonCommand.json(); if (StringUtils.isBlank(jsonString)) { throw new InvalidJsonException(); } final Type typeToken = new TypeToken<Map<String, Object>>() { }.getType(); this.fromJsonHelper.checkForUnsupportedParameters(typeToken, jsonString, RescheduleLoansApiConstants.APPROVE_REQUEST_DATA_PARAMETERS); final List<ApiParameterError> dataValidationErrors = new ArrayList<>(); final DataValidatorBuilder dataValidatorBuilder = new DataValidatorBuilder(dataValidationErrors) .resource(StringUtils.lowerCase(RescheduleLoansApiConstants.ENTITY_NAME)); final JsonElement jsonElement = jsonCommand.parsedJson(); final LocalDate approvedOnDate = this.fromJsonHelper .extractLocalDateNamed(RescheduleLoansApiConstants.approvedOnDateParam, jsonElement); dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.approvedOnDateParam) .value(approvedOnDate).notNull(); if (approvedOnDate != null && loanRescheduleRequest.getSubmittedOnDate().isAfter(approvedOnDate)) { dataValidatorBuilder.reset().parameter(RescheduleLoansApiConstants.approvedOnDateParam).failWithCode( "before.submission.date", "Approval date cannot be before the request submission date."); } LoanRescheduleRequestStatusEnumData loanRescheduleRequestStatusEnumData = LoanRescheduleRequestEnumerations .status(loanRescheduleRequest.getStatusEnum()); if (!loanRescheduleRequestStatusEnumData.isPendingApproval()) { dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode( "request.is.not.in.submitted.and.pending.state", "Loan reschedule request approval is not allowed. " + "Loan reschedule request is not in submitted and pending approval state."); } LocalDate rescheduleFromDate = loanRescheduleRequest.getRescheduleFromDate(); final Loan loan = loanRescheduleRequest.getLoan(); if (loan != null) { Long loanId = loan.getId(); if (!loan.status().isActive()) { dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode("loan.is.not.active", "Loan is not active"); } if (rescheduleFromDate != null) { LoanRepaymentScheduleInstallment installment = loan .getRepaymentScheduleInstallment(rescheduleFromDate); if (installment == null) { dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode( "loan.repayment.schedule.installment.does.not.exist", "Repayment schedule installment does not exist"); } if (installment != null && installment.isObligationsMet()) { dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode( "loan.repayment.schedule.installment." + "obligation.met", "Repayment schedule installment obligation met"); } } if (loanId != null) { List<LoanRescheduleRequestData> loanRescheduleRequestData = this.loanRescheduleRequestReadPlatformService .readLoanRescheduleRequests(loanId, LoanStatus.APPROVED.getValue()); if (loanRescheduleRequestData.size() > 0) { dataValidatorBuilder.reset().failWithCodeNoParameterAddedToErrorCode("loan.already.rescheduled", "The loan can only be rescheduled once."); } } } if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); } }
From source file:org.apache.myfaces.custom.convertStringUtils.StringUtilsConverter.java
private String format(String val, boolean duringOutput) throws ConverterException { String str;/* w w w. ja v a2 s .c om*/ if (BooleanUtils.isTrue(trim)) { str = val.trim(); } else { str = val; } // Any decorations first if (StringUtils.isNotEmpty(format)) { if ("uppercase".equalsIgnoreCase(format)) { str = StringUtils.upperCase(str); } else if ("lowercase".equalsIgnoreCase(format)) { str = StringUtils.lowerCase(str); } else if ("capitalize".equalsIgnoreCase(format)) { str = WordUtils.capitalizeFully(str); } else { throw new ConverterException("Invalid format '" + format + "'"); } } boolean appendEllipses = ((duringOutput) && ((null != appendEllipsesDuringOutput) && (appendEllipsesDuringOutput.booleanValue()))) || ((false == duringOutput) && ((null != appendEllipsesDuringInput) && (appendEllipsesDuringInput.booleanValue()))); if (appendEllipses) { // See if we need to abbreviate/truncate this string if (null != maxLength && maxLength.intValue() > 4) { str = StringUtils.abbreviate(str, maxLength.intValue()); } } else { // See if we need to truncate this string if (null != maxLength) { str = str.substring(0, maxLength.intValue()); } } return str; }