List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty
public static String defaultIfEmpty(String str, String defaultStr)
Returns either the passed in String, or if the String is empty or null
, the value of defaultStr
.
From source file:org.mifosplatform.portfolio.client.domain.Client.java
public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(9); if (command.isChangeInIntegerParameterNamed(ClientApiConstants.statusParamName, this.status)) { final Integer newValue = command.integerValueOfParameterNamed(ClientApiConstants.statusParamName); actualChanges.put(ClientApiConstants.statusParamName, ClientEnumerations.status(newValue)); this.status = ClientStatus.fromInt(newValue).getValue(); }/*ww w .j a v a2s . c o m*/ if (command.isChangeInStringParameterNamed(ClientApiConstants.accountNoParamName, this.accountNumber)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.accountNoParamName); actualChanges.put(ClientApiConstants.accountNoParamName, newValue); this.accountNumber = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(ClientApiConstants.externalIdParamName, this.externalId)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.externalIdParamName); actualChanges.put(ClientApiConstants.externalIdParamName, newValue); this.externalId = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(ClientApiConstants.mobileNoParamName, this.mobileNo)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.mobileNoParamName); actualChanges.put(ClientApiConstants.mobileNoParamName, newValue); this.mobileNo = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(ClientApiConstants.firstnameParamName, this.firstname)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.firstnameParamName); actualChanges.put(ClientApiConstants.firstnameParamName, newValue); this.firstname = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(ClientApiConstants.middlenameParamName, this.middlename)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.middlenameParamName); actualChanges.put(ClientApiConstants.middlenameParamName, newValue); this.middlename = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(ClientApiConstants.lastnameParamName, this.lastname)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.lastnameParamName); actualChanges.put(ClientApiConstants.lastnameParamName, newValue); this.lastname = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(ClientApiConstants.fullnameParamName, this.fullname)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.fullnameParamName); actualChanges.put(ClientApiConstants.fullnameParamName, newValue); this.fullname = newValue; } if (command.isChangeInStringParameterNamed(ClientApiConstants.addressParamName, this.address)) { final String newValue = command.stringValueOfParameterNamed(ClientApiConstants.addressParamName); actualChanges.put(ClientApiConstants.addressParamName, newValue); this.address = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInStringParameterNamed(ClientApiConstants.taxIdentificationNumberParamName, this.taxIdentificationNumber)) { final String newValue = command .stringValueOfParameterNamed(ClientApiConstants.taxIdentificationNumberParamName); actualChanges.put(ClientApiConstants.taxIdentificationNumberParamName, newValue); this.taxIdentificationNumber = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInLongParameterNamed(ClientApiConstants.staffIdParamName, staffId())) { final Long newValue = command.longValueOfParameterNamed(ClientApiConstants.staffIdParamName); actualChanges.put(ClientApiConstants.staffIdParamName, newValue); } final String dateFormatAsInput = command.dateFormat(); final String localeAsInput = command.locale(); if (command.isChangeInLocalDateParameterNamed(ClientApiConstants.activationDateParamName, getActivationLocalDate())) { final String valueAsInput = command .stringValueOfParameterNamed(ClientApiConstants.activationDateParamName); actualChanges.put(ClientApiConstants.activationDateParamName, valueAsInput); actualChanges.put(ClientApiConstants.dateFormatParamName, dateFormatAsInput); actualChanges.put(ClientApiConstants.localeParamName, localeAsInput); final LocalDate newValue = command .localDateValueOfParameterNamed(ClientApiConstants.activationDateParamName); this.activationDate = newValue.toDate(); this.officeJoiningDate = this.activationDate; } validate(); deriveDisplayName(); return actualChanges; }
From source file:org.mifosplatform.portfolio.client.domain.ClientAddress.java
private ClientAddress(final Client client, final CodeValue addressType, final String address_line, final String address_line_two, final String landmark, final String city, final String pincode, final Boolean isBoth, final CodeValue stateType) { this.client = client; this.addressType = addressType; this.address_line = StringUtils.defaultIfEmpty(address_line, null); this.address_line_two = StringUtils.defaultIfEmpty(address_line_two, null); this.landmark = StringUtils.defaultIfEmpty(landmark, null); this.city = StringUtils.defaultIfEmpty(city, null); this.pincode = StringUtils.defaultIfEmpty(pincode, null); this.isBoth = Boolean.valueOf(isBoth); this.stateType = stateType; }
From source file:org.mifosplatform.portfolio.client.domain.ClientAddress.java
public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<>(7); final String addressTypeIdParamName = "addressTypeId"; if (command.isChangeInLongParameterNamed(addressTypeIdParamName, this.addressType.getId())) { final Long newValue = command.longValueOfParameterNamed(addressTypeIdParamName); actualChanges.put(addressTypeIdParamName, newValue); }/* w w w. j av a 2 s . c o m*/ final String address_lineParamName = "address_line"; if (command.isChangeInStringParameterNamed(address_lineParamName, this.address_line)) { final String newValue = command.stringValueOfParameterNamed(address_lineParamName); actualChanges.put(address_lineParamName, newValue); this.address_line = StringUtils.defaultIfEmpty(newValue, null); } final String address_line_twoParamName = "address_line_two"; if (command.isChangeInStringParameterNamed(address_line_twoParamName, this.address_line_two)) { final String newValue = command.stringValueOfParameterNamed(address_line_twoParamName); actualChanges.put(address_line_twoParamName, newValue); this.address_line_two = StringUtils.defaultIfEmpty(newValue, null); } final String landmarkParamName = "landmark"; if (command.isChangeInStringParameterNamed(landmarkParamName, this.landmark)) { final String newValue = command.stringValueOfParameterNamed(landmarkParamName); actualChanges.put(landmarkParamName, newValue); this.landmark = StringUtils.defaultIfEmpty(newValue, null); } final String cityParamName = "city"; if (command.isChangeInStringParameterNamed(cityParamName, this.city)) { final String newValue = command.stringValueOfParameterNamed(cityParamName); actualChanges.put(cityParamName, newValue); this.city = StringUtils.defaultIfEmpty(newValue, null); } final String pincodeParamName = "pincode"; if (command.isChangeInStringParameterNamed(pincodeParamName, this.pincode)) { final String newValue = command.stringValueOfParameterNamed(pincodeParamName); actualChanges.put(pincodeParamName, newValue); this.pincode = StringUtils.defaultIfEmpty(pincodeParamName, null); } final String isBothParamName = "isBoth"; if (command.isChangeInBooleanParameterNamed(isBothParamName, this.isBoth)) { final Boolean newValue = command.booleanObjectValueOfParameterNamed(isBothParamName); actualChanges.put(isBothParamName, newValue); this.isBoth = Boolean.valueOf(isBothParamName); } final String stateTypeIdParamName = "stateTypeId"; if (command.isChangeInLongParameterNamed(stateTypeIdParamName, this.stateType.getId())) { final Long newValue = command.longValueOfParameterNamed(stateTypeIdParamName); actualChanges.put(stateTypeIdParamName, newValue); } return actualChanges; }
From source file:org.mifosplatform.portfolio.client.domain.ClientIdentifier.java
public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(7); final String documentTypeIdParamName = "documentTypeId"; if (command.isChangeInLongParameterNamed(documentTypeIdParamName, this.documentType.getId())) { final Long newValue = command.longValueOfParameterNamed(documentTypeIdParamName); actualChanges.put(documentTypeIdParamName, newValue); }//from w ww . java2s .c om final String documentKeyParamName = "documentKey"; if (command.isChangeInStringParameterNamed(documentKeyParamName, this.documentKey)) { final String newValue = command.stringValueOfParameterNamed(documentKeyParamName); actualChanges.put(documentKeyParamName, newValue); this.documentKey = StringUtils.defaultIfEmpty(newValue, null); } final String descriptionParamName = "description"; if (command.isChangeInStringParameterNamed(descriptionParamName, this.description)) { final String newValue = command.stringValueOfParameterNamed(descriptionParamName); actualChanges.put(descriptionParamName, newValue); this.description = StringUtils.defaultIfEmpty(newValue, null); } return actualChanges; }
From source file:org.mifosplatform.portfolio.collateral.domain.LoanCollateral.java
public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(7); final String collateralTypeIdParamName = COLLATERAL_JSON_INPUT_PARAMS.COLLATERAL_TYPE_ID.getValue(); if (command.isChangeInLongParameterNamed(collateralTypeIdParamName, this.type.getId())) { final Long newValue = command.longValueOfParameterNamed(collateralTypeIdParamName); actualChanges.put(collateralTypeIdParamName, newValue); }/* ww w. j a v a2s. co m*/ final String descriptionParamName = COLLATERAL_JSON_INPUT_PARAMS.DESCRIPTION.getValue(); if (command.isChangeInStringParameterNamed(descriptionParamName, this.description)) { final String newValue = command.stringValueOfParameterNamed(descriptionParamName); actualChanges.put(descriptionParamName, newValue); this.description = StringUtils.defaultIfEmpty(newValue, null); } final String valueParamName = COLLATERAL_JSON_INPUT_PARAMS.VALUE.getValue(); if (command.isChangeInBigDecimalParameterNamed(valueParamName, this.value)) { final BigDecimal newValue = command.bigDecimalValueOfParameterNamed(valueParamName); actualChanges.put(valueParamName, newValue); this.value = newValue; } return actualChanges; }
From source file:org.mifosplatform.portfolio.fund.domain.Fund.java
public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(7); final String nameParamName = "name"; if (command.isChangeInStringParameterNamed(nameParamName, this.name)) { final String newValue = command.stringValueOfParameterNamed(nameParamName); actualChanges.put(nameParamName, newValue); this.name = StringUtils.defaultIfEmpty(newValue, null); }/*from ww w . j a va2 s. c o m*/ final String externalIdParamName = "externalId"; if (command.isChangeInStringParameterNamed(externalIdParamName, this.externalId)) { final String newValue = command.stringValueOfParameterNamed(externalIdParamName); actualChanges.put(externalIdParamName, newValue); this.externalId = StringUtils.defaultIfEmpty(newValue, null); } return actualChanges; }
From source file:org.mifosplatform.portfolio.group.domain.Group.java
public Map<String, Object> update(final JsonCommand command) { final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(9); if (command.isChangeInIntegerParameterNamed(GroupingTypesApiConstants.statusParamName, this.status)) { final Integer newValue = command .integerValueOfParameterNamed(GroupingTypesApiConstants.statusParamName); actualChanges.put(GroupingTypesApiConstants.statusParamName, GroupingTypeEnumerations.status(newValue)); this.status = GroupingTypeStatus.fromInt(newValue).getValue(); }/*from w w w . j a va2 s . c o m*/ if (command.isChangeInStringParameterNamed(GroupingTypesApiConstants.externalIdParamName, this.externalId)) { final String newValue = command .stringValueOfParameterNamed(GroupingTypesApiConstants.externalIdParamName); actualChanges.put(GroupingTypesApiConstants.externalIdParamName, newValue); this.externalId = StringUtils.defaultIfEmpty(newValue, null); } if (command.isChangeInLongParameterNamed(GroupingTypesApiConstants.officeIdParamName, this.office.getId())) { final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.officeIdParamName); actualChanges.put(GroupingTypesApiConstants.officeIdParamName, newValue); } if (command.isChangeInLongParameterNamed(GroupingTypesApiConstants.staffIdParamName, staffId())) { final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName); actualChanges.put(GroupingTypesApiConstants.staffIdParamName, newValue); } if (command.isChangeInStringParameterNamed(GroupingTypesApiConstants.nameParamName, this.name)) { final String newValue = command.stringValueOfParameterNamed(GroupingTypesApiConstants.nameParamName); actualChanges.put(GroupingTypesApiConstants.nameParamName, newValue); this.name = StringUtils.defaultIfEmpty(newValue, null); } final String dateFormatAsInput = command.dateFormat(); final String localeAsInput = command.locale(); if (command.isChangeInLocalDateParameterNamed(GroupingTypesApiConstants.activationDateParamName, getActivationLocalDate())) { final String valueAsInput = command .stringValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName); actualChanges.put(GroupingTypesApiConstants.activationDateParamName, valueAsInput); actualChanges.put(GroupingTypesApiConstants.dateFormatParamName, dateFormatAsInput); actualChanges.put(GroupingTypesApiConstants.localeParamName, localeAsInput); final LocalDate newValue = command .localDateValueOfParameterNamed(GroupingTypesApiConstants.activationDateParamName); this.activationDate = newValue.toDate(); } return actualChanges; }
From source file:org.mifosplatform.portfolio.group.service.GroupWritePlatformServiceJpaRepositoryImpl.java
@Transactional @Override//from w w w . j a va2s. c o m public CommandProcessingResult updateGroup(final Long grouptId, final JsonCommand command) { GroupLevel groupLevel = null; try { this.context.authenticatedUser(); final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(9); this.fromApiJsonDeserializer.validateForUpdate(command.json()); final Group groupForUpdate = this.groupRepository.findOne(grouptId); if (groupForUpdate == null || groupForUpdate.isDeleted()) { throw new GroupNotFoundException(grouptId); } final Long officeId = groupForUpdate.getOfficeId(); final String nameParamName = "name"; if (command.isChangeInStringParameterNamed(nameParamName, groupForUpdate.getName())) { final String newValue = command.stringValueOfParameterNamed(nameParamName); actualChanges.put(nameParamName, newValue); groupForUpdate.setName(StringUtils.defaultIfEmpty(newValue, null)); } final String externalIdParamName = "externalId"; if (command.isChangeInStringParameterNamed(externalIdParamName, groupForUpdate.getExternalId())) { final String newValue = command.stringValueOfParameterNamed(externalIdParamName); actualChanges.put(externalIdParamName, newValue); groupForUpdate.setExternalId(StringUtils.defaultIfEmpty(newValue, null)); } final Staff presentStaff = groupForUpdate.getStaff(); Long presentStaffId = null; if (presentStaff != null) { presentStaffId = presentStaff.getId(); } final String staffIdParamName = "staffId"; if (command.isChangeInLongParameterNamed(staffIdParamName, presentStaffId)) { final Long newValue = command.longValueOfParameterNamed(staffIdParamName); actualChanges.put(staffIdParamName, newValue); Staff newStaff = null; if (newValue != null) { newStaff = this.staffRepository.findByOffice(newValue, officeId); if (newStaff == null) { throw new StaffNotFoundException(newValue); } } groupForUpdate.setStaff(newStaff); } groupLevel = this.groupLevelRepository.findOne(groupForUpdate.getGroupLevel().getId()); /* * Ignoring parentId param, if group for update is super parent. * TODO Need to check: Ignoring is correct or need throw unsupported * param */ if (!groupLevel.isSuperParent()) { final String parentIdParamName = "parentId"; Long parentId = null; final Group presentParentGroup = groupForUpdate.getParent(); if (presentParentGroup != null) { parentId = presentParentGroup.getId(); } if (command.isChangeInLongParameterNamed(parentIdParamName, parentId)) { final Long newValue = command.longValueOfParameterNamed(parentIdParamName); actualChanges.put(parentIdParamName, newValue); Group newParentGroup = null; if (newValue != null) { newParentGroup = this.groupRepository.findOne(newValue); if (newParentGroup == null || newParentGroup.isDeleted()) { throw new StaffNotFoundException(newValue); } if (!newParentGroup.isOfficeIdentifiedBy(officeId)) { final String errorMessage = "Group and parent group must have the same office"; throw new InvalidOfficeException("group", "attach.to.parent.group", errorMessage); } /* * If Group is not super parent then validate group * level's parent level is same as group parent's level * this check makes sure new group is added at immediate * next level in hierarchy */ if (!groupForUpdate.getGroupLevel() .isIdentifiedByParentId(newParentGroup.getGroupLevel().getId())) { final String errorMessage = "Parent group's level is not equal to child level's parent level "; throw new InvalidGroupLevelException("add", "invalid.level", errorMessage); } } groupForUpdate.setParent(newParentGroup); // Parent has changed, re-generate 'Hierarchy' as parent is changed groupForUpdate.generateHierarchy(); } } final Set<Client> clientMembers = assembleSetOfClients(officeId, command); final String clientMembersParamName = "clientMembers"; if (!clientMembers.equals(groupForUpdate.getClientMembers())) { Set<Client> diffClients = Sets.symmetricDifference(clientMembers, groupForUpdate.getClientMembers()); final String[] diffClientsIds = getClientIds(diffClients); actualChanges.put(clientMembersParamName, diffClientsIds); groupForUpdate.setClientMembers(clientMembers); } this.groupRepository.saveAndFlush(groupForUpdate); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // .withOfficeId(groupForUpdate.getId()) // .withGroupId(groupForUpdate.getOfficeId()) // .withEntityId(groupForUpdate.getId()) // .with(actualChanges) // .build(); } catch (final DataIntegrityViolationException dve) { handleGroupDataIntegrityIssues(command, dve, groupLevel); return new CommandProcessingResult(Long.valueOf(-1)); } }
From source file:org.mifosplatform.portfolio.loanaccount.domain.Loan.java
public Map<String, Object> loanApplicationModification(final JsonCommand command, final Set<LoanCharge> possiblyModifedLoanCharges, final Set<LoanCollateral> possiblyModifedLoanCollateralItems, final AprCalculator aprCalculator, final Set<LoanFeeMaster> possiblyModifedLoanDeposits) { final Map<String, Object> actualChanges = this.loanRepaymentScheduleDetail .updateLoanApplicationAttributes(command, aprCalculator); if (!actualChanges.isEmpty()) { final boolean recalculateLoanSchedule = !(actualChanges.size() == 1 && actualChanges.containsKey("inArrearsTolerance")); actualChanges.put("recalculateLoanSchedule", recalculateLoanSchedule); }/*from ww w. j ava2s . c o m*/ final String dateFormatAsInput = command.dateFormat(); final String localeAsInput = command.locale(); final String accountNoParamName = "accountNo"; if (command.isChangeInStringParameterNamed(accountNoParamName, this.accountNumber)) { final String newValue = command.stringValueOfParameterNamed(accountNoParamName); actualChanges.put(accountNoParamName, newValue); this.accountNumber = StringUtils.defaultIfEmpty(newValue, null); } final String externalIdParamName = "externalId"; if (command.isChangeInStringParameterNamed(externalIdParamName, this.externalId)) { final String newValue = command.stringValueOfParameterNamed(externalIdParamName); actualChanges.put(externalIdParamName, newValue); this.externalId = StringUtils.defaultIfEmpty(newValue, null); } // add clientId, groupId and loanType changes to actual changes final String clientIdParamName = "clientId"; final Long clientId = this.client == null ? null : this.client.getId(); if (command.isChangeInLongParameterNamed(clientIdParamName, clientId)) { final Long newValue = command.longValueOfParameterNamed(clientIdParamName); actualChanges.put(clientIdParamName, newValue); } // FIXME: AA - We may require separate api command to move loan from one // group to another final String groupIdParamName = "groupId"; final Long groupId = this.group == null ? null : this.group.getId(); if (command.isChangeInLongParameterNamed(groupIdParamName, groupId)) { final Long newValue = command.longValueOfParameterNamed(groupIdParamName); actualChanges.put(groupIdParamName, newValue); } final String productIdParamName = "productId"; if (command.isChangeInLongParameterNamed(productIdParamName, this.loanProduct.getId())) { final Long newValue = command.longValueOfParameterNamed(productIdParamName); actualChanges.put(productIdParamName, newValue); actualChanges.put("recalculateLoanSchedule", true); } Long existingFundId = null; if (this.fund != null) { existingFundId = this.fund.getId(); } final String fundIdParamName = "fundId"; if (command.isChangeInLongParameterNamed(fundIdParamName, existingFundId)) { final Long newValue = command.longValueOfParameterNamed(fundIdParamName); actualChanges.put(fundIdParamName, newValue); } Long existingLoanOfficerId = null; if (this.loanOfficer != null) { existingLoanOfficerId = this.loanOfficer.getId(); } final String loanOfficerIdParamName = "loanOfficerId"; if (command.isChangeInLongParameterNamed(loanOfficerIdParamName, existingLoanOfficerId)) { final Long newValue = command.longValueOfParameterNamed(loanOfficerIdParamName); actualChanges.put(loanOfficerIdParamName, newValue); } Long existingLoanPurposeId = null; if (this.loanPurpose != null) { existingLoanPurposeId = this.loanPurpose.getId(); } final String loanPurposeIdParamName = "loanPurposeId"; if (command.isChangeInLongParameterNamed(loanPurposeIdParamName, existingLoanPurposeId)) { final Long newValue = command.longValueOfParameterNamed(loanPurposeIdParamName); actualChanges.put(loanPurposeIdParamName, newValue); } final String strategyIdParamName = "transactionProcessingStrategyId"; if (command.isChangeInLongParameterNamed(strategyIdParamName, this.transactionProcessingStrategy.getId())) { final Long newValue = command.longValueOfParameterNamed(strategyIdParamName); actualChanges.put(strategyIdParamName, newValue); } final String submittedOnDateParamName = "submittedOnDate"; if (command.isChangeInLocalDateParameterNamed(submittedOnDateParamName, getSubmittedOnDate())) { final String valueAsInput = command.stringValueOfParameterNamed(submittedOnDateParamName); actualChanges.put(submittedOnDateParamName, valueAsInput); actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); final LocalDate newValue = command.localDateValueOfParameterNamed(submittedOnDateParamName); this.submittedOnDate = newValue.toDate(); } final String expectedDisbursementDateParamName = "expectedDisbursementDate"; if (command.isChangeInLocalDateParameterNamed(expectedDisbursementDateParamName, getExpectedDisbursedOnLocalDate())) { final String valueAsInput = command.stringValueOfParameterNamed(expectedDisbursementDateParamName); actualChanges.put(expectedDisbursementDateParamName, valueAsInput); actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); actualChanges.put("recalculateLoanSchedule", true); final LocalDate newValue = command.localDateValueOfParameterNamed(expectedDisbursementDateParamName); this.expectedDisbursementDate = newValue.toDate(); removeFirstDisbursementTransaction(); } final String repaymentsStartingFromDateParamName = "repaymentsStartingFromDate"; if (command.isChangeInLocalDateParameterNamed(repaymentsStartingFromDateParamName, getExpectedFirstRepaymentOnDate())) { final String valueAsInput = command.stringValueOfParameterNamed(repaymentsStartingFromDateParamName); actualChanges.put(repaymentsStartingFromDateParamName, valueAsInput); actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); actualChanges.put("recalculateLoanSchedule", true); final LocalDate newValue = command.localDateValueOfParameterNamed(repaymentsStartingFromDateParamName); if (newValue != null) { this.expectedFirstRepaymentOnDate = newValue.toDate(); } else { this.expectedFirstRepaymentOnDate = null; } } final String syncDisbursementParameterName = "syncDisbursementWithMeeting"; if (command.isChangeInBooleanParameterNamed(syncDisbursementParameterName, isSyncDisbursementWithMeeting())) { final Boolean valueAsInput = command.booleanObjectValueOfParameterNamed(syncDisbursementParameterName); actualChanges.put(syncDisbursementParameterName, valueAsInput); this.syncDisbursementWithMeeting = valueAsInput; } final String interestChargedFromDateParamName = "interestChargedFromDate"; if (command.isChangeInLocalDateParameterNamed(interestChargedFromDateParamName, getInterestChargedFromDate())) { final String valueAsInput = command.stringValueOfParameterNamed(interestChargedFromDateParamName); actualChanges.put(interestChargedFromDateParamName, valueAsInput); actualChanges.put("dateFormat", dateFormatAsInput); actualChanges.put("locale", localeAsInput); actualChanges.put("recalculateLoanSchedule", true); final LocalDate newValue = command.localDateValueOfParameterNamed(interestChargedFromDateParamName); if (newValue != null) { this.interestChargedFromDate = newValue.toDate(); } else { this.interestChargedFromDate = null; } } if (getSubmittedOnDate().isAfter(new LocalDate())) { final String errorMessage = "The date on which a loan is submitted cannot be in the future."; throw new InvalidLoanStateTransitionException("submittal", "cannot.be.a.future.date", errorMessage, getSubmittedOnDate()); } if (!(this.client == null)) { if (getSubmittedOnDate().isBefore(this.client.getActivationLocalDate())) { final String errorMessage = "The date on which a loan is submitted cannot be earlier than client's activation date."; throw new InvalidLoanStateTransitionException("submittal", "cannot.be.before.client.activation.date", errorMessage, getSubmittedOnDate()); } } else if (!(this.group == null)) { if (getSubmittedOnDate().isBefore(this.group.getActivationLocalDate())) { final String errorMessage = "The date on which a loan is submitted cannot be earlier than groups's activation date."; throw new InvalidLoanStateTransitionException("submittal", "cannot.be.before.group.activation.date", errorMessage, getSubmittedOnDate()); } } if (getSubmittedOnDate().isAfter(getExpectedDisbursedOnLocalDate())) { final String errorMessage = "The date on which a loan is submitted cannot be after its expected disbursement date: " + getExpectedDisbursedOnLocalDate().toString(); throw new InvalidLoanStateTransitionException("submittal", "cannot.be.after.expected.disbursement.date", errorMessage, getSubmittedOnDate(), getExpectedDisbursedOnLocalDate()); } final String chargesParamName = "charges"; if (command.parameterExists(chargesParamName)) { final Set<LoanCharge> existingLoanCharges = setOfLoanCharges(); if (!possiblyModifedLoanCharges.equals(existingLoanCharges)) { actualChanges.put(chargesParamName, getLoanCharges(possiblyModifedLoanCharges)); actualChanges.put("recalculateLoanSchedule", true); for (final LoanCharge loanCharge : possiblyModifedLoanCharges) { final BigDecimal amount = calculateAmountPercentageAppliedTo(loanCharge); BigDecimal chargeAmt = BigDecimal.ZERO; BigDecimal totalChargeAmt = BigDecimal.ZERO; if (loanCharge.getChargeCalculation().isPercentageBased()) { chargeAmt = loanCharge.getPercentage(); if (loanCharge.isInstalmentFee()) { totalChargeAmt = calculatePerInstallmentChargeAmount(loanCharge); } } else { chargeAmt = loanCharge.amount(); if (loanCharge.isInstalmentFee()) { chargeAmt = chargeAmt .divide(BigDecimal.valueOf(repaymentScheduleDetail().getNumberOfRepayments())); } } loanCharge.update(chargeAmt, loanCharge.getDueLocalDate(), amount, repaymentScheduleDetail().getNumberOfRepayments(), totalChargeAmt); validateChargeHasValidSpecifiedDateIfApplicable(loanCharge, getDisbursementDate(), getLastRepaymentPeriodDueDate()); } } } final String collateralParamName = "collateral"; if (command.parameterExists(collateralParamName)) { if (!possiblyModifedLoanCollateralItems.equals(this.collateral)) { actualChanges.put(collateralParamName, listOfLoanCollateralData(possiblyModifedLoanCollateralItems)); } } final String loanTermFrequencyParamName = "loanTermFrequency"; if (command.isChangeInIntegerParameterNamed(loanTermFrequencyParamName, this.termFrequency)) { final Integer newValue = command.integerValueOfParameterNamed(loanTermFrequencyParamName); actualChanges.put(externalIdParamName, newValue); this.termFrequency = newValue; } final String loanTermFrequencyTypeParamName = "loanTermFrequencyType"; if (command.isChangeInIntegerParameterNamed(loanTermFrequencyTypeParamName, this.termPeriodFrequencyType)) { final Integer newValue = command.integerValueOfParameterNamed(loanTermFrequencyTypeParamName); final PeriodFrequencyType newTermPeriodFrequencyType = PeriodFrequencyType.fromInt(newValue); actualChanges.put(loanTermFrequencyTypeParamName, newTermPeriodFrequencyType.getValue()); this.termPeriodFrequencyType = newValue; } final String depositsParamName = "depositArray"; if (command.parameterExists(depositsParamName)) { final Set<LoanFeeMaster> existingLoanDeposits = setOfLoanDeposits(); if (!possiblyModifedLoanDeposits.equals(existingLoanDeposits)) { actualChanges.put(depositsParamName, getLoanDeposit(possiblyModifedLoanDeposits)); actualChanges.put("recalculateLoanSchedule", true); for (final LoanFeeMaster loanDeposit : possiblyModifedLoanDeposits) { final BigDecimal amount = calculateAmountPercentageAppliedTo(loanDeposit); BigDecimal depositAmt = BigDecimal.ZERO; if (loanDeposit.getDepositCalculation().isPercentageBased()) { depositAmt = loanDeposit.getPercentage(); } else { depositAmt = loanDeposit.getAmount(); } loanDeposit.update(depositAmt, amount, BigDecimal.ZERO); } } } return actualChanges; }