merging group role changes and removing holiday id from Commandwrapper and related classes

This commit is contained in:
Vishwas Babu AJ
2013-06-14 18:07:48 +05:30
27 changed files with 896 additions and 190 deletions
@@ -0,0 +1,22 @@
INSERT INTO `m_code` (`code_name`, `is_system_defined`) VALUES ('GROUPROLE', 1);
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'ASSIGNROLE_GROUP', 'GROUP', 'ASSIGNROLE', 0);
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'UNASSIGNROLE_GROUP', 'GROUP', 'UNASSIGNROLE', 0);
INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES ('portfolio', 'UPDATEROLE_GROUP', 'GROUP', 'UPDATEROLE', 0);
CREATE TABLE `m_group_roles` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`client_id` BIGINT(20) NULL DEFAULT NULL,
`group_id` BIGINT(20) NULL DEFAULT NULL,
`role_cv_id` INT(11) NULL DEFAULT NULL,
PRIMARY KEY (`id`),
INDEX `FKGroupRoleClientId` (`client_id`),
INDEX `FKGroupRoleGroupId` (`group_id`),
INDEX `FK_grouprole_m_codevalue` (`role_cv_id`),
UNIQUE INDEX `UNIQUE_GROUP_ROLES` (`client_id`, `group_id`, `role_cv_id`),
CONSTRAINT `FKGroupRoleClientId` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`),
CONSTRAINT `FKGroupRoleGroupId` FOREIGN KEY (`group_id`) REFERENCES `m_group` (`id`),
CONSTRAINT `FK_grouprole_m_codevalue` FOREIGN KEY (`role_cv_id`) REFERENCES `m_code_value` (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
@@ -109,18 +109,15 @@ public class CommandWrapper {
} }
public boolean isCreateDatatable() { public boolean isCreateDatatable() {
return (this.actionName.equalsIgnoreCase("CREATE") && this.href.startsWith("/datatables/") return (this.actionName.equalsIgnoreCase("CREATE") && this.href.startsWith("/datatables/") && this.entityId == null);
&& this.entityId == null);
} }
public boolean isDeleteDatatable() { public boolean isDeleteDatatable() {
return (this.actionName.equalsIgnoreCase("DELETE") && this.href.startsWith("/datatables/") return (this.actionName.equalsIgnoreCase("DELETE") && this.href.startsWith("/datatables/") && this.entityId == null);
&& this.entityId == null);
} }
public boolean isUpdateDatatable() { public boolean isUpdateDatatable() {
return (this.actionName.equalsIgnoreCase("UPDATE") && this.href.startsWith("/datatables/") return (this.actionName.equalsIgnoreCase("UPDATE") && this.href.startsWith("/datatables/") && this.entityId == null);
&& this.entityId == null);
} }
public String getTaskPermissionName() { public String getTaskPermissionName() {
@@ -415,7 +412,7 @@ public class CommandWrapper {
} }
public boolean isUpdateOfOwnUserDetails(final Long loggedInUserId) { public boolean isUpdateOfOwnUserDetails(final Long loggedInUserId) {
return this.isUserResource() && isUpdate() && loggedInUserId.equals(this.entityId); return isUserResource() && isUpdate() && loggedInUserId.equals(this.entityId);
} }
public boolean isDepositProductResource() { public boolean isDepositProductResource() {
@@ -500,7 +497,7 @@ public class CommandWrapper {
return this.entityName.equalsIgnoreCase("GROUP"); return this.entityName.equalsIgnoreCase("GROUP");
} }
public boolean isSaveGroupCollectionSheet(){ public boolean isSaveGroupCollectionSheet() {
return this.entityName.equalsIgnoreCase("GROUP") && this.actionName.equalsIgnoreCase("SAVECOLLECTIONSHEET"); return this.entityName.equalsIgnoreCase("GROUP") && this.actionName.equalsIgnoreCase("SAVECOLLECTIONSHEET");
} }
@@ -512,7 +509,7 @@ public class CommandWrapper {
return this.entityName.equalsIgnoreCase("CENTER"); return this.entityName.equalsIgnoreCase("CENTER");
} }
public boolean isSaveCenterCollectionSheet(){ public boolean isSaveCenterCollectionSheet() {
return this.entityName.equalsIgnoreCase("CENTER") && this.actionName.equalsIgnoreCase("SAVECOLLECTIONSHEET"); return this.entityName.equalsIgnoreCase("CENTER") && this.actionName.equalsIgnoreCase("SAVECOLLECTIONSHEET");
} }
@@ -528,11 +525,23 @@ public class CommandWrapper {
return this.actionName.equalsIgnoreCase("DISASSOCIATECLIENTS"); return this.actionName.equalsIgnoreCase("DISASSOCIATECLIENTS");
} }
public boolean isAccountingRuleResource() { public boolean isHolidayResource() {
return this.entityName.equalsIgnoreCase("ACCOUNTINGRULE"); return this.entityName.equalsIgnoreCase("HOLIDAY");
} }
public boolean isHolidayResource() { public boolean isAccountingRuleResource() {
return this.entityName.equalsIgnoreCase("HOLIDAY"); return this.entityName.equalsIgnoreCase("ACCOUNTINGRULE");
} }
public boolean isAssignRole() {
return this.entityName.equalsIgnoreCase("GROUP") && this.actionName.equalsIgnoreCase("ASSIGNROLE");
}
public boolean isUnAssignRole() {
return this.entityName.equalsIgnoreCase("GROUP") && this.actionName.equalsIgnoreCase("UNASSIGNROLE");
}
public boolean isUpdateRole() {
return this.entityName.equalsIgnoreCase("GROUP") && this.actionName.equalsIgnoreCase("UPDATEROLE");
}
} }
@@ -1026,4 +1026,31 @@ public class CommandWrapperBuilder {
this.href = "/holidays/template"; this.href = "/holidays/template";
return this; return this;
} }
public CommandWrapperBuilder assignRole(Long groupId) {
this.actionName = "ASSIGNROLE";
this.entityName = "GROUP";
this.groupId = groupId;
this.entityId = null;
this.href = "/groups/"+groupId+"?command=assignRole";
return this;
}
public CommandWrapperBuilder unassignRole(Long groupId, Long roleId) {
this.actionName = "UNASSIGNROLE";
this.entityName = "GROUP";
this.groupId = groupId;
this.entityId = roleId;
this.href = "/groups/"+groupId+"?command=unassignRole";
return this;
}
public CommandWrapperBuilder updateRole(Long groupId, Long roleId) {
this.actionName = "UPDATEROLE";
this.entityName = "GROUP";
this.groupId = groupId;
this.entityId = roleId;
this.href = "/groups/"+groupId+"?command=updateRole";
return this;
}
} }
@@ -59,7 +59,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
final NewCommandSourceHandler handler = findCommandHandler(wrapper); final NewCommandSourceHandler handler = findCommandHandler(wrapper);
final CommandProcessingResult result = handler.processCommand(command); final CommandProcessingResult result = handler.processCommand(command);
final AppUser maker = context.authenticatedUser(); final AppUser maker = this.context.authenticatedUser();
CommandSource commandSourceResult = null; CommandSource commandSourceResult = null;
if (command.commandId() != null) { if (command.commandId() != null) {
@@ -83,7 +83,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
} }
if (commandSourceResult.hasJson()) { if (commandSourceResult.hasJson()) {
commandSourceRepository.save(commandSourceResult); this.commandSourceRepository.save(commandSourceResult);
} }
if (rollbackTransaction) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(commandSourceResult); } if (rollbackTransaction) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(commandSourceResult); }
@@ -96,7 +96,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
public CommandProcessingResult logCommand(final CommandSource commandSourceResult) { public CommandProcessingResult logCommand(final CommandSource commandSourceResult) {
commandSourceResult.markAsAwaitingApproval(); commandSourceResult.markAsAwaitingApproval();
commandSourceRepository.save(commandSourceResult); this.commandSourceRepository.save(commandSourceResult);
return new CommandProcessingResultBuilder().withCommandId(commandSourceResult.getId()) return new CommandProcessingResultBuilder().withCommandId(commandSourceResult.getId())
.withEntityId(commandSourceResult.getResourceId()).build(); .withEntityId(commandSourceResult.getResourceId()).build();
@@ -106,333 +106,340 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
NewCommandSourceHandler handler = null; NewCommandSourceHandler handler = null;
if (wrapper.isConfigurationResource()) { if (wrapper.isConfigurationResource()) {
handler = applicationContext.getBean("updateGlobalConfigurationCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateGlobalConfigurationCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDatatableResource()) { } else if (wrapper.isDatatableResource()) {
if (wrapper.isCreateDatatable()) { if (wrapper.isCreateDatatable()) {
handler = applicationContext.getBean("createDatatableCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createDatatableCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDeleteDatatable()) { } else if (wrapper.isDeleteDatatable()) {
handler = applicationContext.getBean("deleteDatatableCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteDatatableCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdateDatatable()) { } else if (wrapper.isUpdateDatatable()) {
handler = applicationContext.getBean("updateDatatableCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateDatatableCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isCreate()) { } else if (wrapper.isCreate()) {
handler = applicationContext.getBean("createDatatableEntryCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createDatatableEntryCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdateMultiple()) { } else if (wrapper.isUpdateMultiple()) {
handler = applicationContext.getBean("updateOneToManyDatatableEntryCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateOneToManyDatatableEntryCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdateOneToOne()) { } else if (wrapper.isUpdateOneToOne()) {
handler = applicationContext.getBean("updateOneToOneDatatableEntryCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateOneToOneDatatableEntryCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDeleteMultiple()) { } else if (wrapper.isDeleteMultiple()) {
handler = applicationContext.getBean("deleteOneToManyDatatableEntryCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteOneToManyDatatableEntryCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDeleteOneToOne()) { } else if (wrapper.isDeleteOneToOne()) {
handler = applicationContext.getBean("deleteOneToOneDatatableEntryCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteOneToOneDatatableEntryCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isNoteResource()) { } else if (wrapper.isNoteResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createNoteCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createNoteCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateNoteCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateNoteCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteNoteCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteNoteCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isClientIdentifierResource()) { } else if (wrapper.isClientIdentifierResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createClientIdentifierCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createClientIdentifierCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateClientIdentifierCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateClientIdentifierCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteClientIdentifierCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteClientIdentifierCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isClientResource() && !wrapper.isClientNoteResource() && !wrapper.isClientIdentifierResource()) { } else if (wrapper.isClientResource() && !wrapper.isClientNoteResource() && !wrapper.isClientIdentifierResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createClientCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createClientCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateClientCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateClientCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteClientCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteClientCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isClientActivation()) { } else if (wrapper.isClientActivation()) {
handler = applicationContext.getBean("activateClientCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("activateClientCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
// end of client // end of client
} else if (wrapper.isUpdateRolePermissions()) { } else if (wrapper.isUpdateRolePermissions()) {
handler = applicationContext.getBean("updateRolePermissionsCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateRolePermissionsCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isPermissionResource()) { } else if (wrapper.isPermissionResource()) {
handler = applicationContext.getBean("updateMakerCheckerPermissionsCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateMakerCheckerPermissionsCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isRoleResource()) { } else if (wrapper.isRoleResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createRoleCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createRoleCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateRoleCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateRoleCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isUserResource()) { } else if (wrapper.isUserResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createUserCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createUserCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateUserCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateUserCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteUserCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteUserCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isStaffResource()) { } else if (wrapper.isStaffResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createStaffCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createStaffCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateStaffCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateStaffCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isGuarantorResource()) { } else if (wrapper.isGuarantorResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createGuarantorCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createGuarantorCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateGuarantorCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateGuarantorCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteGuarantorCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteGuarantorCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isCollateralResource()) { } else if (wrapper.isCollateralResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createCollateralCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createCollateralCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateCollateralCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateCollateralCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteCollateralCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteCollateralCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isCodeResource()) { } else if (wrapper.isCodeResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createCodeCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createCodeCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateCodeCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateCodeCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteCodeCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteCodeCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isCodeValueResource()) { } else if (wrapper.isCodeValueResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createCodeValueCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createCodeValueCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateCodeValueCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateCodeValueCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteCodeValueCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteCodeValueCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isCurrencyResource()) { } else if (wrapper.isCurrencyResource()) {
handler = applicationContext.getBean("updateCurrencyCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateCurrencyCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isFundResource()) { } else if (wrapper.isFundResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createFundCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createFundCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateFundCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateFundCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isOfficeResource()) { } else if (wrapper.isOfficeResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createOfficeCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createOfficeCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateOfficeCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateOfficeCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isOfficeTransactionResource()) { } else if (wrapper.isOfficeTransactionResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createOfficeTransactionCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createOfficeTransactionCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteOfficeTransactionCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteOfficeTransactionCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isChargeDefinitionResource()) { } else if (wrapper.isChargeDefinitionResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createChargeDefinitionCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createChargeDefinitionCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateChargeDefinitionCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateChargeDefinitionCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteChargeDefinitionCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteChargeDefinitionCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isLoanProductResource()) { } else if (wrapper.isLoanProductResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createLoanProductCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createLoanProductCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateLoanProductCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateLoanProductCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isLoanResource()) { } else if (wrapper.isLoanResource()) {
if (wrapper.isApproveLoanApplication()) { if (wrapper.isApproveLoanApplication()) {
handler = applicationContext.getBean("loanApplicationApprovalCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("loanApplicationApprovalCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUndoApprovalOfLoanApplication()) { } else if (wrapper.isUndoApprovalOfLoanApplication()) {
handler = applicationContext.getBean("loanApplicationApprovalUndoCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("loanApplicationApprovalUndoCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isApplicantWithdrawalFromLoanApplication()) { } else if (wrapper.isApplicantWithdrawalFromLoanApplication()) {
handler = applicationContext.getBean("loanApplicationWithdrawnByApplicantCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("loanApplicationWithdrawnByApplicantCommandHandler",
NewCommandSourceHandler.class);
} else if (wrapper.isRejectionOfLoanApplication()) { } else if (wrapper.isRejectionOfLoanApplication()) {
handler = applicationContext.getBean("loanApplicationRejectedCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("loanApplicationRejectedCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDisbursementOfLoan()) { } else if (wrapper.isDisbursementOfLoan()) {
handler = applicationContext.getBean("disburseLoanCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("disburseLoanCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUndoDisbursementOfLoan()) { } else if (wrapper.isUndoDisbursementOfLoan()) {
handler = applicationContext.getBean("undoDisbursalLoanCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("undoDisbursalLoanCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isLoanRepayment()) { } else if (wrapper.isLoanRepayment()) {
handler = applicationContext.getBean("loanRepaymentCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("loanRepaymentCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isLoanRepaymentAdjustment()) { } else if (wrapper.isLoanRepaymentAdjustment()) {
handler = applicationContext.getBean("loanRepaymentAdjustmentCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("loanRepaymentAdjustmentCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isWaiveInterestPortionOnLoan()) { } else if (wrapper.isWaiveInterestPortionOnLoan()) {
handler = applicationContext.getBean("waiveInterestPortionOnLoanCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("waiveInterestPortionOnLoanCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isLoanWriteOff()) { } else if (wrapper.isLoanWriteOff()) {
handler = applicationContext.getBean("writeOffLoanCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("writeOffLoanCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isCloseLoanAsObligationsMet()) { } else if (wrapper.isCloseLoanAsObligationsMet()) {
handler = applicationContext.getBean("closeLoanCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("closeLoanCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isCloseLoanAsRescheduled()) { } else if (wrapper.isCloseLoanAsRescheduled()) {
handler = applicationContext.getBean("closeLoanAsRescheduledCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("closeLoanAsRescheduledCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdateLoanOfficer()) { } else if (wrapper.isUpdateLoanOfficer()) {
handler = applicationContext.getBean("updateLoanOfficerCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateLoanOfficerCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isRemoveLoanOfficer()) { } else if (wrapper.isRemoveLoanOfficer()) {
handler = applicationContext.getBean("removeLoanOfficerCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("removeLoanOfficerCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isBulkUpdateLoanOfficer()) { } else if (wrapper.isBulkUpdateLoanOfficer()) {
handler = applicationContext.getBean("bulkUpdateLoanOfficerCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("bulkUpdateLoanOfficerCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isCreate()) { } else if (wrapper.isCreate()) {
handler = applicationContext.getBean("loanApplicationSubmittalCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("loanApplicationSubmittalCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("loanApplicationModificationCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("loanApplicationModificationCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("loanApplicationDeletionCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("loanApplicationDeletionCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isLoanChargeResource()) { } else if (wrapper.isLoanChargeResource()) {
if (wrapper.isAddLoanCharge()) { if (wrapper.isAddLoanCharge()) {
handler = applicationContext.getBean("addLoanChargeCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("addLoanChargeCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDeleteLoanCharge()) { } else if (wrapper.isDeleteLoanCharge()) {
handler = applicationContext.getBean("deleteLoanChargeCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteLoanChargeCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdateLoanCharge()) { } else if (wrapper.isUpdateLoanCharge()) {
handler = applicationContext.getBean("updateLoanChargeCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateLoanChargeCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isWaiveLoanCharge()) { } else if (wrapper.isWaiveLoanCharge()) {
handler = applicationContext.getBean("waiveLoanChargeCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("waiveLoanChargeCommandHandler", NewCommandSourceHandler.class);
} }
} else if (wrapper.isGLAccountResource()) { } else if (wrapper.isGLAccountResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createGLAccountCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createGLAccountCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateGLAccountCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateGLAccountCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteGLAccountCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteGLAccountCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isGLClosureResource()) { } else if (wrapper.isGLClosureResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createGLClosureCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createGLClosureCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateGLClosureCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateGLClosureCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteGLClosureCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteGLClosureCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isJournalEntryResource()) { } else if (wrapper.isJournalEntryResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createJournalEntryCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createJournalEntryCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isRevertJournalEntry()) { } else if (wrapper.isRevertJournalEntry()) {
handler = applicationContext.getBean("reverseJournalEntryCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("reverseJournalEntryCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isSavingsProductResource()) { } else if (wrapper.isSavingsProductResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createSavingsProductCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createSavingsProductCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateSavingsProductCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateSavingsProductCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteSavingsProductCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteSavingsProductCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isSavingsAccountResource()) { } else if (wrapper.isSavingsAccountResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createSavingsAccountCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createSavingsAccountCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateSavingsAccountCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateSavingsAccountCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteSavingsAccountCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteSavingsAccountCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isSavingsAccountDeposit()) { } else if (wrapper.isSavingsAccountDeposit()) {
handler = applicationContext.getBean("depositSavingsAccountCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("depositSavingsAccountCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isSavingsAccountWithdrawal()) { } else if (wrapper.isSavingsAccountWithdrawal()) {
handler = applicationContext.getBean("withdrawSavingsAccountCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("withdrawSavingsAccountCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isSavingsAccountActivation()) { } else if (wrapper.isSavingsAccountActivation()) {
handler = applicationContext.getBean("activateSavingsAccountCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("activateSavingsAccountCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isSavingsAccountInterestCalculation()) { } else if (wrapper.isSavingsAccountInterestCalculation()) {
handler = applicationContext.getBean("calculateInterestSavingsAccountCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("calculateInterestSavingsAccountCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isSavingsAccountInterestPosting()) { } else if (wrapper.isSavingsAccountInterestPosting()) {
handler = applicationContext.getBean("postInterestSavingsAccountCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("postInterestSavingsAccountCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isCalendarResource()) { } else if (wrapper.isCalendarResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createCalendarCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createCalendarCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateCalendarCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateCalendarCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteCalendarCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteCalendarCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isGroupResource()) { } else if (wrapper.isGroupResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createGroupCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createGroupCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateGroupCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateGroupCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUnassignStaff()) { } else if (wrapper.isUnassignStaff()) {
handler = applicationContext.getBean("unassignGroupStaffCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("unassignGroupStaffCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteGroupCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteGroupCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isGroupActivation()) { } else if (wrapper.isGroupActivation()) {
handler = applicationContext.getBean("activateGroupCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("activateGroupCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isAssociateClients()) { } else if (wrapper.isAssociateClients()) {
handler = applicationContext.getBean("associateClientsToGroupCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("associateClientsToGroupCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDisassociateClients()) { } else if (wrapper.isDisassociateClients()) {
handler = applicationContext.getBean("disassociateClientsFromGroupCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("disassociateClientsFromGroupCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isSaveGroupCollectionSheet()) { } else if (wrapper.isSaveGroupCollectionSheet()) {
handler = applicationContext.getBean("saveGroupCollectionSheetCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("saveGroupCollectionSheetCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isAssignRole()) {
handler = this.applicationContext.getBean("assignRoleCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUnAssignRole()) {
handler = this.applicationContext.getBean("unassignRoleCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdateRole()) {
handler = this.applicationContext.getBean("updateGroupRoleCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isCenterResource()) { } else if (wrapper.isCenterResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createCenterCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createCenterCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateCenterCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateCenterCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteCenterCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteCenterCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isCenterActivation()) { } else if (wrapper.isCenterActivation()) {
handler = applicationContext.getBean("activateCenterCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("activateCenterCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isSaveCenterCollectionSheet()) { } else if (wrapper.isSaveCenterCollectionSheet()) {
handler = applicationContext.getBean("saveCenterCollectionSheetCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("saveCenterCollectionSheetCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
} else if (wrapper.isCollectionSheetResource()) { } else if (wrapper.isCollectionSheetResource()) {
if (wrapper.isUpdate()) { if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateCollectionSheetCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateCollectionSheetCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
@@ -440,11 +447,11 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
} else if (wrapper.isReportResource()) { } else if (wrapper.isReportResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createReportCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createReportCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateReportCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateReportCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteReportCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteReportCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
@@ -452,11 +459,11 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
} else if (wrapper.isAccountingRuleResource()) { } else if (wrapper.isAccountingRuleResource()) {
if (wrapper.isCreate()) { if (wrapper.isCreate()) {
handler = applicationContext.getBean("createAccountingRuleCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("createAccountingRuleCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isUpdate()) { } else if (wrapper.isUpdate()) {
handler = applicationContext.getBean("updateAccountingRuleCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("updateAccountingRuleCommandHandler", NewCommandSourceHandler.class);
} else if (wrapper.isDelete()) { } else if (wrapper.isDelete()) {
handler = applicationContext.getBean("deleteAccountingRuleCommandHandler", NewCommandSourceHandler.class); handler = this.applicationContext.getBean("deleteAccountingRuleCommandHandler", NewCommandSourceHandler.class);
} else { } else {
throw new UnsupportedCommandException(wrapper.commandName()); throw new UnsupportedCommandException(wrapper.commandName());
} }
@@ -22,16 +22,15 @@ public class CommandProcessingResult {
private final Long savingsId; private final Long savingsId;
private final Long resourceId; private final Long resourceId;
private final String transactionId; private final String transactionId;
private final Long holidayId;
private final Map<String, Object> changes; private final Map<String, Object> changes;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final String resourceIdentifier; private final String resourceIdentifier;
public static CommandProcessingResult fromDetails(final Long commandId, final Long officeId, final Long groupId, final Long clientId, public static CommandProcessingResult fromDetails(final Long commandId, final Long officeId, final Long groupId, final Long clientId,
final Long loanId, final Long savingsId, final String resourceIdentifier, final Long entityId, final String transactionId, final Long loanId, final Long savingsId, final String resourceIdentifier, final Long entityId, final String transactionId,
final Long holidayId, final Map<String, Object> changes) { final Map<String, Object> changes) {
return new CommandProcessingResult(commandId, officeId, groupId, clientId, loanId, savingsId, resourceIdentifier, entityId, return new CommandProcessingResult(commandId, officeId, groupId, clientId, loanId, savingsId, resourceIdentifier, entityId,
transactionId, holidayId, changes); transactionId, changes);
} }
public static CommandProcessingResult commandOnlyResult(final Long commandId) { public static CommandProcessingResult commandOnlyResult(final Long commandId) {
@@ -79,12 +78,11 @@ public class CommandProcessingResult {
this.loanId = null; this.loanId = null;
this.savingsId = null; this.savingsId = null;
this.transactionId = null; this.transactionId = null;
this.holidayId = null;
this.changes = new HashMap<String, Object>(); this.changes = new HashMap<String, Object>();
} }
private CommandProcessingResult(final Long commandId, final Long officeId, final Long groupId, final Long clientId, final Long loanId, private CommandProcessingResult(final Long commandId, final Long officeId, final Long groupId, final Long clientId, final Long loanId,
final Long savingsId, final String resourceIdentifier, final Long resourceId, final String transactionId, final Long holidayId, final Long savingsId, final String resourceIdentifier, final Long resourceId, final String transactionId,
final Map<String, Object> changesOnly) { final Map<String, Object> changesOnly) {
this.commandId = commandId; this.commandId = commandId;
this.officeId = officeId; this.officeId = officeId;
@@ -96,7 +94,6 @@ public class CommandProcessingResult {
this.resourceId = resourceId; this.resourceId = resourceId;
this.changes = changesOnly; this.changes = changesOnly;
this.transactionId = transactionId; this.transactionId = transactionId;
this.holidayId = holidayId;
} }
private CommandProcessingResult(final Long resourceId, final Long officeId, final Long commandId, final Map<String, Object> changesOnly) { private CommandProcessingResult(final Long resourceId, final Long officeId, final Long commandId, final Map<String, Object> changesOnly) {
@@ -112,7 +109,6 @@ public class CommandProcessingResult {
this.loanId = null; this.loanId = null;
this.savingsId = null; this.savingsId = null;
this.transactionId = null; this.transactionId = null;
this.holidayId = null;
this.commandId = commandId; this.commandId = commandId;
this.changes = changesOnly; this.changes = changesOnly;
} }
@@ -22,12 +22,11 @@ public class CommandProcessingResultBuilder {
private String resourceIdentifier; private String resourceIdentifier;
private Long entityId; private Long entityId;
private String transactionId; private String transactionId;
private Long holidayId;
private Map<String, Object> changes; private Map<String, Object> changes;
public CommandProcessingResult build() { public CommandProcessingResult build() {
return CommandProcessingResult.fromDetails(commandId, officeId, groupId, clientId, loanId, savingsId, resourceIdentifier, entityId, return CommandProcessingResult.fromDetails(commandId, officeId, groupId, clientId, loanId, savingsId, resourceIdentifier, entityId,
transactionId, holidayId, changes); transactionId, changes);
} }
public CommandProcessingResultBuilder withCommandId(final Long withCommandId) { public CommandProcessingResultBuilder withCommandId(final Long withCommandId) {
@@ -80,8 +79,4 @@ public class CommandProcessingResultBuilder {
return this; return this;
} }
public CommandProcessingResultBuilder withHolidayId(final Long withHolidayId) {
this.holidayId = withHolidayId;
return this;
}
} }
@@ -82,8 +82,7 @@ public class HolidayWritePlatformServiceJpaRepositoryImpl implements HolidayWrit
this.holidayRepository.save(holiday); this.holidayRepository.save(holiday);
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(holiday.getId()) return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(holiday.getId()).build();
.withHolidayId(holiday.getId()).build();
} catch (final DataIntegrityViolationException dve) { } catch (final DataIntegrityViolationException dve) {
handleDataIntegrityIssues(command, dve); handleDataIntegrityIssues(command, dve);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
@@ -210,8 +210,8 @@ public class CentersApiResource {
final CommandWrapper commandRequest = builder.saveCenterCollectionSheet(centerId).build(); final CommandWrapper commandRequest = builder.saveCenterCollectionSheet(centerId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result); return this.toApiJsonSerializer.serialize(result);
} else { // } else {
throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "generateCollectionSheet" }); throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "generateCollectionSheet", "createRole" });
} }
} }
@@ -17,6 +17,15 @@ public class GroupingTypesApiConstants {
public static final String GROUP_RESOURCE_NAME = "group"; public static final String GROUP_RESOURCE_NAME = "group";
public static final String COMMUNAL_BANK_RESOURCE_NAME = "communalbank"; public static final String COMMUNAL_BANK_RESOURCE_NAME = "communalbank";
//group roles
public static final String GROUP_ROLE_RESOURCE_NAME = "grouprole";
public static final String GROUP_ROLE_NAME = "GROUPROLE";
public static final String roleParamName = "role";
public static final String groupIdParamName = "groupId";
public static final String clientIdParamName = "clientId";
public static final String groupRolesParamName = "groupRoles";
// general // general
public static final String localeParamName = "locale"; public static final String localeParamName = "locale";
public static final String dateFormatParamName = "dateFormat"; public static final String dateFormatParamName = "dateFormat";
@@ -52,6 +61,8 @@ public class GroupingTypesApiConstants {
idParamName, nameParamName, externalIdParamName, centerIdParamName, officeIdParamName, staffIdParamName, activeParamName, idParamName, nameParamName, externalIdParamName, centerIdParamName, officeIdParamName, staffIdParamName, activeParamName,
activationDateParamName, clientMembersParamName)); activationDateParamName, clientMembersParamName));
public static final Set<String> GROUP_ROLES_REQUEST_DATA_PARAMETERS = new HashSet<String>(Arrays.asList(roleParamName, clientIdParamName));
/** /**
* These parameters will match the class level parameters of * These parameters will match the class level parameters of
* {@link CenterData}. Where possible, we try to get response parameters to * {@link CenterData}. Where possible, we try to get response parameters to
@@ -74,4 +85,5 @@ public class GroupingTypesApiConstants {
public static final Set<String> COLLECTIONSHEET_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("dueDate", "loanProducts", "groups")); public static final Set<String> COLLECTIONSHEET_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("dueDate", "loanProducts", "groups"));
} }
@@ -44,8 +44,10 @@ import org.mifosplatform.portfolio.collectionsheet.data.JLGCollectionSheetData;
import org.mifosplatform.portfolio.collectionsheet.service.CollectionSheetReadPlatformService; import org.mifosplatform.portfolio.collectionsheet.service.CollectionSheetReadPlatformService;
import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData;
import org.mifosplatform.portfolio.group.data.GroupGeneralData; import org.mifosplatform.portfolio.group.data.GroupGeneralData;
import org.mifosplatform.portfolio.group.data.GroupRoleData;
import org.mifosplatform.portfolio.group.service.CenterReadPlatformService; import org.mifosplatform.portfolio.group.service.CenterReadPlatformService;
import org.mifosplatform.portfolio.group.service.GroupReadPlatformService; import org.mifosplatform.portfolio.group.service.GroupReadPlatformService;
import org.mifosplatform.portfolio.group.service.GroupRolesReadPlatformService;
import org.mifosplatform.portfolio.group.service.SearchParameters; import org.mifosplatform.portfolio.group.service.SearchParameters;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
@@ -70,6 +72,7 @@ public class GroupsApiResource {
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final CollectionSheetReadPlatformService collectionSheetReadPlatformService; private final CollectionSheetReadPlatformService collectionSheetReadPlatformService;
private final FromJsonHelper fromJsonHelper; private final FromJsonHelper fromJsonHelper;
private final GroupRolesReadPlatformService groupRolesReadPlatformService;
@Autowired @Autowired
public GroupsApiResource(final PlatformSecurityContext context, final GroupReadPlatformService groupReadPlatformService, public GroupsApiResource(final PlatformSecurityContext context, final GroupReadPlatformService groupReadPlatformService,
@@ -79,7 +82,8 @@ public class GroupsApiResource {
final ToApiJsonSerializer<GroupAccountSummaryCollectionData> groupSummaryToApiJsonSerializer, final ToApiJsonSerializer<GroupAccountSummaryCollectionData> groupSummaryToApiJsonSerializer,
final ApiRequestParameterHelper apiRequestParameterHelper, final ApiRequestParameterHelper apiRequestParameterHelper,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
final CollectionSheetReadPlatformService collectionSheetReadPlatformService, final FromJsonHelper fromJsonHelper) { final CollectionSheetReadPlatformService collectionSheetReadPlatformService, final FromJsonHelper fromJsonHelper,
final GroupRolesReadPlatformService groupRolesReadPlatformService) {
this.context = context; this.context = context;
this.groupReadPlatformService = groupReadPlatformService; this.groupReadPlatformService = groupReadPlatformService;
this.centerReadPlatformService = centerReadPlatformService; this.centerReadPlatformService = centerReadPlatformService;
@@ -91,6 +95,7 @@ public class GroupsApiResource {
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
this.collectionSheetReadPlatformService = collectionSheetReadPlatformService; this.collectionSheetReadPlatformService = collectionSheetReadPlatformService;
this.fromJsonHelper = fromJsonHelper; this.fromJsonHelper = fromJsonHelper;
this.groupRolesReadPlatformService = groupRolesReadPlatformService;
} }
@GET @GET
@@ -132,7 +137,7 @@ public class GroupsApiResource {
limit, orderBy, sortOrder); limit, orderBy, sortOrder);
final Page<GroupGeneralData> groups = this.groupReadPlatformService.retrieveAll(searchParameters); final Page<GroupGeneralData> groups = this.groupReadPlatformService.retrieveAll(searchParameters);
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, groups, GroupingTypesApiConstants.GROUP_RESPONSE_DATA_PARAMETERS); return this.toApiJsonSerializer.serialize(settings, groups, GroupingTypesApiConstants.GROUP_RESPONSE_DATA_PARAMETERS);
} }
@@ -141,7 +146,8 @@ public class GroupsApiResource {
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String retrieveOne(@Context final UriInfo uriInfo, @PathParam("groupId") final Long groupId, public String retrieveOne(@Context final UriInfo uriInfo, @PathParam("groupId") final Long groupId,
@DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly) { @DefaultValue("false") @QueryParam("staffInSelectedOfficeOnly") final boolean staffInSelectedOfficeOnly,
@QueryParam("roleId") final Long roleId) {
this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.GROUP_RESOURCE_NAME); this.context.authenticatedUser().validateHasReadPermission(GroupingTypesApiConstants.GROUP_RESOURCE_NAME);
final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters()); final Set<String> associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters());
@@ -150,22 +156,39 @@ public class GroupsApiResource {
// associations // associations
Collection<ClientData> membersOfGroup = null; Collection<ClientData> membersOfGroup = null;
Collection<GroupRoleData> groupRoles = null;
GroupRoleData selectedRole = null;
if (!associationParameters.isEmpty()) { if (!associationParameters.isEmpty()) {
if (associationParameters.contains("all")) {
associationParameters.addAll(Arrays.asList("clientMembers", "groupRoles"));
}
if (associationParameters.contains("clientMembers")) { if (associationParameters.contains("clientMembers")) {
membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId); membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId);
if (CollectionUtils.isEmpty(membersOfGroup)) { if (CollectionUtils.isEmpty(membersOfGroup)) {
membersOfGroup = null; membersOfGroup = null;
} }
} }
if (associationParameters.contains("groupRoles")) {
groupRoles = this.groupRolesReadPlatformService.retrieveGroupRoles(groupId);
if (CollectionUtils.isEmpty(membersOfGroup)) {
groupRoles = null;
}
}
if (roleId != null) {
selectedRole = this.groupRolesReadPlatformService.retrieveGroupRole(groupId, roleId);
if (selectedRole != null) {
group = GroupGeneralData.updateSelectedRole(group, selectedRole);
}
}
} }
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters()); final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
if (template) { if (template) {
final GroupGeneralData templateGroup = this.groupReadPlatformService.retrieveTemplate(group.officeId(), false, final GroupGeneralData templateGroup = this.groupReadPlatformService.retrieveTemplate(group.officeId(), false,
staffInSelectedOfficeOnly); staffInSelectedOfficeOnly);
group = GroupGeneralData.withTemplateAndAssociations(templateGroup, group, membersOfGroup); group = GroupGeneralData.withTemplateAndAssociations(templateGroup, group, membersOfGroup, groupRoles);
} else { } else {
group = GroupGeneralData.withAssocations(group, membersOfGroup); group = GroupGeneralData.withAssocations(group, membersOfGroup, groupRoles);
} }
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
@@ -232,8 +255,8 @@ public class GroupsApiResource {
@Consumes({ MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String activateOrGenerateCollectionSheet(@PathParam("groupId") final Long groupId, public String activateOrGenerateCollectionSheet(@PathParam("groupId") final Long groupId,
@QueryParam("command") final String commandParam, final String apiRequestBodyAsJson, @Context final UriInfo uriInfo) { @QueryParam("command") final String commandParam, @QueryParam("roleId") final Long roleId, final String apiRequestBodyAsJson,
@Context final UriInfo uriInfo) {
final CommandWrapperBuilder builder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson); final CommandWrapperBuilder builder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson);
CommandProcessingResult result = null; CommandProcessingResult result = null;
@@ -264,9 +287,21 @@ public class GroupsApiResource {
final CommandWrapper commandRequest = builder.unassignGroupStaff(groupId).build(); final CommandWrapper commandRequest = builder.unassignGroupStaff(groupId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result); return this.toApiJsonSerializer.serialize(result);
} else if (is(commandParam, "assignRole")) {
final CommandWrapper commandRequest = builder.assignRole(groupId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
} else if (is(commandParam, "unassignRole")) {
final CommandWrapper commandRequest = builder.unassignRole(groupId, roleId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
} else if (is(commandParam, "updateRole")) {
final CommandWrapper commandRequest = builder.updateRole(groupId, roleId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
} else { } else {
throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "generateCollectionSheet", throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "generateCollectionSheet",
"saveCollectionSheet", "unassignStaff" }); "saveCollectionSheet", "unassignStaff", "assignRole", "unassignRole", "updateassignRole" });
} }
} }
@@ -8,6 +8,7 @@ package org.mifosplatform.portfolio.group.data;
import java.util.Collection; import java.util.Collection;
import org.joda.time.LocalDate; import org.joda.time.LocalDate;
import org.mifosplatform.infrastructure.codes.data.CodeValueData;
import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.core.data.EnumOptionData;
import org.mifosplatform.organisation.office.data.OfficeData; import org.mifosplatform.organisation.office.data.OfficeData;
import org.mifosplatform.organisation.staff.data.StaffData; import org.mifosplatform.organisation.staff.data.StaffData;
@@ -38,50 +39,59 @@ public class GroupGeneralData {
// associations // associations
private final Collection<ClientData> clientMembers; private final Collection<ClientData> clientMembers;
private final Collection<GroupRoleData> groupRoles;
// template // template
private final Collection<CenterData> centerOptions; private final Collection<CenterData> centerOptions;
private final Collection<OfficeData> officeOptions; private final Collection<OfficeData> officeOptions;
private final Collection<StaffData> staffOptions; private final Collection<StaffData> staffOptions;
private final Collection<ClientData> clientOptions; private final Collection<ClientData> clientOptions;
private final Collection<CodeValueData> availableRoles;
private final GroupRoleData selectedRole;
public static GroupGeneralData lookup(final Long groupId, final String groupName) { public static GroupGeneralData lookup(final Long groupId, final String groupName) {
final Collection<ClientData> clientMembers = null; final Collection<ClientData> clientMembers = null;
final Collection<GroupRoleData> groupRoles = null;
return new GroupGeneralData(groupId, groupName, null, null, null, null, null, null, null, null, null, null, clientMembers, null, return new GroupGeneralData(groupId, groupName, null, null, null, null, null, null, null, null, null, null, clientMembers, null,
null, null, null); null, null, null, groupRoles, null, null);
} }
public static GroupGeneralData template(final Long officeId, final Long centerId, final String centerName, final Long staffId, public static GroupGeneralData template(final Long officeId, final Long centerId, final String centerName, final Long staffId,
final String staffName, final Collection<CenterData> centerOptions, final Collection<OfficeData> officeOptions, final String staffName, final Collection<CenterData> centerOptions, final Collection<OfficeData> officeOptions,
final Collection<StaffData> staffOptions, final Collection<ClientData> clientOptions) { final Collection<StaffData> staffOptions, final Collection<ClientData> clientOptions,
final Collection<CodeValueData> availableRoles) {
final Collection<ClientData> clientMembers = null; final Collection<ClientData> clientMembers = null;
final Collection<GroupRoleData> groupRoles = null;
return new GroupGeneralData(null, null, null, null, null, officeId, null, centerId, centerName, staffId, staffName, null, return new GroupGeneralData(null, null, null, null, null, officeId, null, centerId, centerName, staffId, staffName, null,
clientMembers, centerOptions, officeOptions, staffOptions, clientOptions); clientMembers, centerOptions, officeOptions, staffOptions, clientOptions, groupRoles, availableRoles, null);
} }
public static GroupGeneralData withTemplate(final GroupGeneralData templatedGrouping, final GroupGeneralData grouping) { public static GroupGeneralData withTemplate(final GroupGeneralData templatedGrouping, final GroupGeneralData grouping) {
return new GroupGeneralData(grouping.id, grouping.name, grouping.externalId, grouping.status, grouping.activationDate, return new GroupGeneralData(grouping.id, grouping.name, grouping.externalId, grouping.status, grouping.activationDate,
grouping.officeId, grouping.officeName, grouping.centerId, grouping.centerName, grouping.staffId, grouping.staffName, grouping.officeId, grouping.officeName, grouping.centerId, grouping.centerName, grouping.staffId, grouping.staffName,
grouping.hierarchy, grouping.clientMembers, templatedGrouping.centerOptions, templatedGrouping.officeOptions, grouping.hierarchy, grouping.clientMembers, templatedGrouping.centerOptions, templatedGrouping.officeOptions,
templatedGrouping.staffOptions, templatedGrouping.clientOptions); templatedGrouping.staffOptions, templatedGrouping.clientOptions, grouping.groupRoles, templatedGrouping.availableRoles,
grouping.selectedRole);
} }
public static GroupGeneralData withTemplateAndAssociations(final GroupGeneralData templatedGrouping, final GroupGeneralData grouping, public static GroupGeneralData withTemplateAndAssociations(final GroupGeneralData templatedGrouping, final GroupGeneralData grouping,
final Collection<ClientData> membersOfGroup) { final Collection<ClientData> membersOfGroup, final Collection<GroupRoleData> groupRoles) {
return new GroupGeneralData(grouping.id, grouping.name, grouping.externalId, grouping.status, grouping.activationDate, return new GroupGeneralData(grouping.id, grouping.name, grouping.externalId, grouping.status, grouping.activationDate,
grouping.officeId, grouping.officeName, grouping.centerId, grouping.centerName, grouping.staffId, grouping.staffName, grouping.officeId, grouping.officeName, grouping.centerId, grouping.centerName, grouping.staffId, grouping.staffName,
grouping.hierarchy, membersOfGroup, templatedGrouping.centerOptions, templatedGrouping.officeOptions, grouping.hierarchy, membersOfGroup, templatedGrouping.centerOptions, templatedGrouping.officeOptions,
templatedGrouping.staffOptions, templatedGrouping.clientOptions); templatedGrouping.staffOptions, templatedGrouping.clientOptions, groupRoles, templatedGrouping.availableRoles,
grouping.selectedRole);
} }
public static GroupGeneralData withAssocations(final GroupGeneralData grouping, final Collection<ClientData> membersOfGroup) { public static GroupGeneralData withAssocations(final GroupGeneralData grouping, final Collection<ClientData> membersOfGroup,
final Collection<GroupRoleData> groupRoles) {
return new GroupGeneralData(grouping.id, grouping.name, grouping.externalId, grouping.status, grouping.activationDate, return new GroupGeneralData(grouping.id, grouping.name, grouping.externalId, grouping.status, grouping.activationDate,
grouping.officeId, grouping.officeName, grouping.centerId, grouping.centerName, grouping.staffId, grouping.staffName, grouping.officeId, grouping.officeName, grouping.centerId, grouping.centerName, grouping.staffId, grouping.staffName,
grouping.hierarchy, membersOfGroup, grouping.centerOptions, grouping.officeOptions, grouping.staffOptions, grouping.hierarchy, membersOfGroup, grouping.centerOptions, grouping.officeOptions, grouping.staffOptions,
grouping.clientOptions); grouping.clientOptions, groupRoles, grouping.availableRoles, grouping.selectedRole);
} }
public static GroupGeneralData instance(final Long id, final String name, final String externalId, final EnumOptionData status, public static GroupGeneralData instance(final Long id, final String name, final String externalId, final EnumOptionData status,
@@ -93,16 +103,21 @@ public class GroupGeneralData {
final Collection<OfficeData> officeOptions = null; final Collection<OfficeData> officeOptions = null;
final Collection<StaffData> staffOptions = null; final Collection<StaffData> staffOptions = null;
final Collection<ClientData> clientOptions = null; final Collection<ClientData> clientOptions = null;
final Collection<GroupRoleData> groupRoles = null;
final Collection<CodeValueData> availableRoles = null;
final GroupRoleData role = null;
return new GroupGeneralData(id, name, externalId, status, activationDate, officeId, officeName, centerId, centerName, staffId, return new GroupGeneralData(id, name, externalId, status, activationDate, officeId, officeName, centerId, centerName, staffId,
staffName, hierarchy, clientMembers, centerOptions, officeOptions, staffOptions, clientOptions); staffName, hierarchy, clientMembers, centerOptions, officeOptions, staffOptions, clientOptions, groupRoles, availableRoles,
role);
} }
private GroupGeneralData(final Long id, final String name, final String externalId, final EnumOptionData status, private GroupGeneralData(final Long id, final String name, final String externalId, final EnumOptionData status,
final LocalDate activationDate, final Long officeId, final String officeName, final Long centerId, final String centerName, final LocalDate activationDate, final Long officeId, final String officeName, final Long centerId, final String centerName,
final Long staffId, final String staffName, final String hierarchy, final Collection<ClientData> clientMembers, final Long staffId, final String staffName, final String hierarchy, final Collection<ClientData> clientMembers,
final Collection<CenterData> centerOptions, final Collection<OfficeData> officeOptions, final Collection<CenterData> centerOptions, final Collection<OfficeData> officeOptions,
final Collection<StaffData> staffOptions, final Collection<ClientData> clientOptions) { final Collection<StaffData> staffOptions, final Collection<ClientData> clientOptions,
final Collection<GroupRoleData> groupRoles, final Collection<CodeValueData> availableRoles, final GroupRoleData role) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.externalId = externalId; this.externalId = externalId;
@@ -134,6 +149,9 @@ public class GroupGeneralData {
clientOptions.removeAll(clientMembers); clientOptions.removeAll(clientMembers);
} }
this.clientOptions = clientOptions; this.clientOptions = clientOptions;
this.groupRoles = groupRoles;
this.availableRoles = availableRoles;
this.selectedRole = role;
} }
public Long getId() { public Long getId() {
@@ -152,4 +170,11 @@ public class GroupGeneralData {
return this.hierarchy; return this.hierarchy;
} }
public static GroupGeneralData updateSelectedRole(final GroupGeneralData grouping, final GroupRoleData selectedRole) {
return new GroupGeneralData(grouping.id, grouping.name, grouping.externalId, grouping.status, grouping.activationDate,
grouping.officeId, grouping.officeName, grouping.centerId, grouping.centerName, grouping.staffId, grouping.staffName,
grouping.hierarchy, grouping.clientMembers, grouping.centerOptions, grouping.officeOptions, grouping.staffOptions,
grouping.clientOptions, grouping.groupRoles, grouping.availableRoles, selectedRole);
}
} }
@@ -0,0 +1,27 @@
package org.mifosplatform.portfolio.group.data;
import org.mifosplatform.infrastructure.codes.data.CodeValueData;
public class GroupRoleData {
@SuppressWarnings("unused")
private final Long id;
@SuppressWarnings("unused")
private final CodeValueData role;
@SuppressWarnings("unused")
private final Long clientId;
@SuppressWarnings("unused")
private final String clientName;
public static final GroupRoleData template() {
return new GroupRoleData(null, null, null, null);
}
public GroupRoleData(final Long id, final CodeValueData role, final Long clientId, final String clientName) {
this.id = id;
this.role = role;
this.clientId = clientId;
this.clientName = clientName;
}
}
@@ -0,0 +1,74 @@
package org.mifosplatform.portfolio.group.domain;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.mifosplatform.infrastructure.codes.domain.CodeValue;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.portfolio.client.domain.Client;
import org.mifosplatform.portfolio.group.api.GroupingTypesApiConstants;
import org.springframework.data.jpa.domain.AbstractPersistable;
@Entity
@Table(name = "m_group_roles")
public class GroupRole extends AbstractPersistable<Long> {
@SuppressWarnings("unused")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "group_id")
private Group group;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "client_id")
private Client client;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "role_cv_id")
private CodeValue role;
public GroupRole() {
// TODO Auto-generated constructor stub
}
public static final GroupRole createGroupRole(final Group group, final Client client, final CodeValue role) {
return new GroupRole(group, client, role);
}
public GroupRole(final Group group, final Client client, final CodeValue role) {
this.group = group;
this.client = client;
this.role = role;
}
public Map<String, Object> update(final JsonCommand command) {
final Map<String, Object> actualChanges = new LinkedHashMap<String, Object>(2);
if (command.isChangeInLongParameterNamed(GroupingTypesApiConstants.clientIdParamName, this.client.getId())) {
final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.clientIdParamName);
actualChanges.put(GroupingTypesApiConstants.clientIdParamName, newValue);
}
if (command.isChangeInLongParameterNamed(GroupingTypesApiConstants.roleParamName, this.role.getId())) {
final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.roleParamName);
actualChanges.put(GroupingTypesApiConstants.roleParamName, newValue);
}
return actualChanges;
}
public void updateRole(final CodeValue role) {
this.role = role;
}
public void updateClient(final Client client) {
this.client = client;
}
}
@@ -0,0 +1,8 @@
package org.mifosplatform.portfolio.group.domain;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface GroupRoleRepository extends JpaRepository<GroupRole, Long>, JpaSpecificationExecutor<GroupRole> {
}
@@ -0,0 +1,35 @@
package org.mifosplatform.portfolio.group.domain;
import org.mifosplatform.portfolio.group.exception.GroupRoleNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class GroupRoleRepositoryWrapper {
private final GroupRoleRepository repository;
@Autowired
public GroupRoleRepositoryWrapper(final GroupRoleRepository rRepository) {
this.repository = rRepository;
}
public GroupRole findOneWithNotFoundDetection(final Long id) {
final GroupRole entity = this.repository.findOne(id);
if (entity == null) { throw new GroupRoleNotFoundException(id); }
return entity;
}
public void save(final GroupRole entity) {
this.repository.save(entity);
}
public void saveAndFlush(final GroupRole entity) {
this.repository.saveAndFlush(entity);
}
public void delete(final GroupRole entity) {
this.repository.delete(entity);
}
}
@@ -0,0 +1,10 @@
package org.mifosplatform.portfolio.group.exception;
import org.mifosplatform.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
public class GroupRoleNotFoundException extends AbstractPlatformResourceNotFoundException {
public GroupRoleNotFoundException(final Long id) {
super("error.msg.group.role.id.invalid", "Group Role with identifier " + id + " does not exist", id);
}
}
@@ -0,0 +1,27 @@
package org.mifosplatform.portfolio.group.handler;
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.portfolio.group.service.GroupRolesWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class AssignRoleCommandHandler implements NewCommandSourceHandler {
private final GroupRolesWritePlatformService groupRolesWritePlatformService;
@Autowired
public AssignRoleCommandHandler(final GroupRolesWritePlatformService groupRolesWritePlatformService) {
this.groupRolesWritePlatformService = groupRolesWritePlatformService;
}
@Override
@Transactional
public CommandProcessingResult processCommand(final JsonCommand command) {
return this.groupRolesWritePlatformService.createRole(command);
}
}
@@ -0,0 +1,27 @@
package org.mifosplatform.portfolio.group.handler;
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.portfolio.group.service.GroupRolesWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class UnassignRoleCommandHandler implements NewCommandSourceHandler {
private final GroupRolesWritePlatformService groupRolesWritePlatformService;
@Autowired
public UnassignRoleCommandHandler(final GroupRolesWritePlatformService groupRolesWritePlatformService) {
this.groupRolesWritePlatformService = groupRolesWritePlatformService;
}
@Override
@Transactional
public CommandProcessingResult processCommand(JsonCommand command) {
return this.groupRolesWritePlatformService.deleteRole(command.entityId());
}
}
@@ -0,0 +1,27 @@
package org.mifosplatform.portfolio.group.handler;
import org.mifosplatform.commands.handler.NewCommandSourceHandler;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.portfolio.group.service.GroupRolesWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class UpdateGroupRoleCommandHandler implements NewCommandSourceHandler {
private final GroupRolesWritePlatformService groupRolesWritePlatformService;
@Autowired
public UpdateGroupRoleCommandHandler(final GroupRolesWritePlatformService groupRolesWritePlatformService) {
this.groupRolesWritePlatformService = groupRolesWritePlatformService;
}
@Override
@Transactional
public CommandProcessingResult processCommand(JsonCommand command) {
return this.groupRolesWritePlatformService.updateRole(command);
}
}
@@ -0,0 +1,89 @@
package org.mifosplatform.portfolio.group.serialization;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
import org.mifosplatform.portfolio.group.api.GroupingTypesApiConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;
@Component
public class GroupRolesDataValidator {
private final FromJsonHelper fromApiJsonHelper;
@Autowired
public GroupRolesDataValidator(final FromJsonHelper fromApiJsonHelper) {
this.fromApiJsonHelper = fromApiJsonHelper;
}
private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
}
public void validateForCreateGroupRole(final JsonCommand command) {
final String json = command.json();
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
this.fromApiJsonHelper
.checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.GROUP_ROLES_REQUEST_DATA_PARAMETERS);
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
.resource(GroupingTypesApiConstants.GROUP_ROLE_RESOURCE_NAME);
final JsonElement element = command.parsedJson();
final Long roleId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.roleParamName, element);
baseDataValidator.reset().parameter(GroupingTypesApiConstants.roleParamName).value(roleId).notNull().longGreaterThanZero();
final Long clientId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.clientIdParamName, element);
baseDataValidator.reset().parameter(GroupingTypesApiConstants.clientIdParamName).value(clientId).notNull().longGreaterThanZero();
throwExceptionIfValidationWarningsExist(dataValidationErrors);
}
public void validateForUpdateRole(final JsonCommand command) {
final String json = command.json();
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
this.fromApiJsonHelper
.checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.GROUP_ROLES_REQUEST_DATA_PARAMETERS);
final List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
.resource(GroupingTypesApiConstants.GROUP_ROLE_RESOURCE_NAME);
final JsonElement element = command.parsedJson();
final Long roleId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.roleParamName, element);
baseDataValidator.reset().parameter(GroupingTypesApiConstants.roleParamName).value(roleId).ignoreIfNull().notBlank()
.longGreaterThanZero();
final Long clientId = this.fromApiJsonHelper.extractLongNamed(GroupingTypesApiConstants.clientIdParamName, element);
baseDataValidator.reset().parameter(GroupingTypesApiConstants.clientIdParamName).value(clientId).ignoreIfNull().notBlank()
.longGreaterThanZero();
throwExceptionIfValidationWarningsExist(dataValidationErrors);
}
}
@@ -323,7 +323,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService
} }
return GroupGeneralData.template(centerOfficeId, center.getId(), center.getName(), staffId, staffName, centerOptions, return GroupGeneralData.template(centerOfficeId, center.getId(), center.getName(), staffId, staffName, centerOptions,
officeOptions, staffOptions, clientOptions); officeOptions, staffOptions, clientOptions, null);
} }
@Override @Override
@@ -12,6 +12,8 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.mifosplatform.infrastructure.codes.data.CodeValueData;
import org.mifosplatform.infrastructure.codes.service.CodeValueReadPlatformService;
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport; import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.service.Page; import org.mifosplatform.infrastructure.core.service.Page;
@@ -25,6 +27,7 @@ import org.mifosplatform.organisation.staff.service.StaffReadPlatformService;
import org.mifosplatform.portfolio.client.data.ClientData; import org.mifosplatform.portfolio.client.data.ClientData;
import org.mifosplatform.portfolio.client.service.ClientReadPlatformService; import org.mifosplatform.portfolio.client.service.ClientReadPlatformService;
import org.mifosplatform.portfolio.client.service.LoanStatusMapper; import org.mifosplatform.portfolio.client.service.LoanStatusMapper;
import org.mifosplatform.portfolio.group.api.GroupingTypesApiConstants;
import org.mifosplatform.portfolio.group.data.CenterData; import org.mifosplatform.portfolio.group.data.CenterData;
import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData;
import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData;
@@ -48,6 +51,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
private final OfficeReadPlatformService officeReadPlatformService; private final OfficeReadPlatformService officeReadPlatformService;
private final StaffReadPlatformService staffReadPlatformService; private final StaffReadPlatformService staffReadPlatformService;
private final CenterReadPlatformService centerReadPlatformService; private final CenterReadPlatformService centerReadPlatformService;
private final CodeValueReadPlatformService codeValueReadPlatformService;
private final AllGroupTypesDataMapper allGroupTypesDataMapper = new AllGroupTypesDataMapper(); private final AllGroupTypesDataMapper allGroupTypesDataMapper = new AllGroupTypesDataMapper();
private final PaginationHelper<GroupGeneralData> paginationHelper = new PaginationHelper<GroupGeneralData>(); private final PaginationHelper<GroupGeneralData> paginationHelper = new PaginationHelper<GroupGeneralData>();
@@ -55,13 +59,15 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
@Autowired @Autowired
public GroupReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource, public GroupReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource,
final CenterReadPlatformService centerReadPlatformService, final ClientReadPlatformService clientReadPlatformService, final CenterReadPlatformService centerReadPlatformService, final ClientReadPlatformService clientReadPlatformService,
final OfficeReadPlatformService officeReadPlatformService, final StaffReadPlatformService staffReadPlatformService) { final OfficeReadPlatformService officeReadPlatformService, final StaffReadPlatformService staffReadPlatformService,
final CodeValueReadPlatformService codeValueReadPlatformService) {
this.context = context; this.context = context;
this.jdbcTemplate = new JdbcTemplate(dataSource); this.jdbcTemplate = new JdbcTemplate(dataSource);
this.centerReadPlatformService = centerReadPlatformService; this.centerReadPlatformService = centerReadPlatformService;
this.clientReadPlatformService = clientReadPlatformService; this.clientReadPlatformService = clientReadPlatformService;
this.officeReadPlatformService = officeReadPlatformService; this.officeReadPlatformService = officeReadPlatformService;
this.staffReadPlatformService = staffReadPlatformService; this.staffReadPlatformService = staffReadPlatformService;
this.codeValueReadPlatformService = codeValueReadPlatformService;
} }
@Override @Override
@@ -94,13 +100,16 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
clientOptions = null; clientOptions = null;
} }
final Collection<CodeValueData> availableRoles = this.codeValueReadPlatformService
.retrieveCodeValuesByCode(GroupingTypesApiConstants.GROUP_ROLE_NAME);
final Long centerId = null; final Long centerId = null;
final String centerName = null; final String centerName = null;
final Long staffId = null; final Long staffId = null;
final String staffName = null; final String staffName = null;
return GroupGeneralData.template(defaultOfficeId, centerId, centerName, staffId, staffName, centerOptions, officeOptions, return GroupGeneralData.template(defaultOfficeId, centerId, centerName, staffId, staffName, centerOptions, officeOptions,
staffOptions, clientOptions); staffOptions, clientOptions, availableRoles);
} }
private Long defaultToUsersOfficeIfNull(final Long officeId) { private Long defaultToUsersOfficeIfNull(final Long officeId) {
@@ -114,11 +123,11 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
@Override @Override
public Page<GroupGeneralData> retrieveAll(final SearchParameters searchParameters) { public Page<GroupGeneralData> retrieveAll(final SearchParameters searchParameters) {
final AppUser currentUser = context.authenticatedUser(); final AppUser currentUser = this.context.authenticatedUser();
final String hierarchy = currentUser.getOffice().getHierarchy(); final String hierarchy = currentUser.getOffice().getHierarchy();
final String hierarchySearchString = hierarchy + "%"; final String hierarchySearchString = hierarchy + "%";
StringBuilder sqlBuilder = new StringBuilder(200); final StringBuilder sqlBuilder = new StringBuilder(200);
sqlBuilder.append("select SQL_CALC_FOUND_ROWS "); sqlBuilder.append("select SQL_CALC_FOUND_ROWS ");
sqlBuilder.append(this.allGroupTypesDataMapper.schema()); sqlBuilder.append(this.allGroupTypesDataMapper.schema());
sqlBuilder.append(" where o.hierarchy like ?"); sqlBuilder.append(" where o.hierarchy like ?");
@@ -190,13 +199,13 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
public GroupGeneralData retrieveOne(final Long groupId) { public GroupGeneralData retrieveOne(final Long groupId) {
try { try {
final AppUser currentUser = context.authenticatedUser(); final AppUser currentUser = this.context.authenticatedUser();
final String hierarchy = currentUser.getOffice().getHierarchy(); final String hierarchy = currentUser.getOffice().getHierarchy();
final String hierarchySearchString = hierarchy + "%"; final String hierarchySearchString = hierarchy + "%";
String sql = "select " + this.allGroupTypesDataMapper.schema() + " where g.id = ? and o.hierarchy like ?"; final String sql = "select " + this.allGroupTypesDataMapper.schema() + " where g.id = ? and o.hierarchy like ?";
return this.jdbcTemplate.queryForObject(sql, this.allGroupTypesDataMapper, new Object[] { groupId, hierarchySearchString }); return this.jdbcTemplate.queryForObject(sql, this.allGroupTypesDataMapper, new Object[] { groupId, hierarchySearchString });
} catch (EmptyResultDataAccessException e) { } catch (final EmptyResultDataAccessException e) {
throw new GroupNotFoundException(groupId); throw new GroupNotFoundException(groupId);
} }
} }
@@ -292,7 +301,8 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService {
final StringBuilder accountsSummary = new StringBuilder("l.id as id, l.external_id as externalId,"); final StringBuilder accountsSummary = new StringBuilder("l.id as id, l.external_id as externalId,");
accountsSummary.append("l.product_id as productId, lp.name as productName,").append("l.loan_status_id as statusId, ") accountsSummary.append("l.product_id as productId, lp.name as productName,").append("l.loan_status_id as statusId, ")
.append("l.account_no as accountNo ").append("from m_loan l ").append("LEFT JOIN m_product_loan AS lp ON lp.id = l.product_id "); .append("l.account_no as accountNo ").append("from m_loan l ")
.append("LEFT JOIN m_product_loan AS lp ON lp.id = l.product_id ");
return accountsSummary.toString(); return accountsSummary.toString();
} }
@@ -0,0 +1,12 @@
package org.mifosplatform.portfolio.group.service;
import java.util.Collection;
import org.mifosplatform.portfolio.group.data.GroupRoleData;
public interface GroupRolesReadPlatformService {
Collection<GroupRoleData> retrieveGroupRoles(Long groupId);
GroupRoleData retrieveGroupRole(Long groupId, Long roleId);
}
@@ -0,0 +1,71 @@
package org.mifosplatform.portfolio.group.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import org.mifosplatform.infrastructure.codes.data.CodeValueData;
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.group.data.GroupRoleData;
import org.mifosplatform.portfolio.group.exception.GroupRoleNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
@Service
public class GroupRolesReadPlatformServiceImpl implements GroupRolesReadPlatformService {
private final JdbcTemplate jdbcTemplate;
private final PlatformSecurityContext context;
@Autowired
public GroupRolesReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource) {
this.context = context;
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
@Override
public Collection<GroupRoleData> retrieveGroupRoles(final Long groupId) {
this.context.authenticatedUser();
final GroupRolesDataMapper mapper = new GroupRolesDataMapper();
final String sql = "Select " + mapper.schema() + " where role.group_id=?";
return this.jdbcTemplate.query(sql, mapper, new Object[] { groupId });
}
@Override
public GroupRoleData retrieveGroupRole(final Long groupId, final Long roleId) {
try {
this.context.authenticatedUser();
final GroupRolesDataMapper mapper = new GroupRolesDataMapper();
final String sql = "Select " + mapper.schema() + " where role.group_id=? and role.id=?";
return this.jdbcTemplate.queryForObject(sql, mapper, new Object[] { groupId, roleId });
} catch (final EmptyResultDataAccessException e) {
throw new GroupRoleNotFoundException(roleId);
}
}
private static final class GroupRolesDataMapper implements RowMapper<GroupRoleData> {
public final String schema() {
return " role.id AS id, role.client_id AS clientId, c.display_name as clientName, role.role_cv_id AS roleId, cv.code_value AS roleName"
+ " from m_code_value cv join m_group_roles role on role.role_cv_id = cv.id left join m_client c on c.id = role.client_id ";
}
@Override
public GroupRoleData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
final Long id = JdbcSupport.getLong(rs, "id");
final Long clientId = JdbcSupport.getLong(rs, "clientId");
final String clientName = rs.getString("clientName");
final Long roleId = JdbcSupport.getLong(rs, "roleId");
final String roleName = rs.getString("roleName");
final CodeValueData role = CodeValueData.instance(roleId, roleName);
return new GroupRoleData(id, role, clientId, clientName);
}
}
}
@@ -0,0 +1,15 @@
package org.mifosplatform.portfolio.group.service;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
public interface GroupRolesWritePlatformService {
CommandProcessingResult createRole(JsonCommand command);
CommandProcessingResult updateRole(JsonCommand command);
CommandProcessingResult deleteRole(Long ruleId);
}
@@ -0,0 +1,147 @@
package org.mifosplatform.portfolio.group.service;
import java.util.Map;
import org.mifosplatform.infrastructure.codes.domain.CodeValue;
import org.mifosplatform.infrastructure.codes.domain.CodeValueRepositoryWrapper;
import org.mifosplatform.infrastructure.core.api.JsonCommand;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder;
import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.portfolio.client.domain.Client;
import org.mifosplatform.portfolio.client.domain.ClientRepositoryWrapper;
import org.mifosplatform.portfolio.group.api.GroupingTypesApiConstants;
import org.mifosplatform.portfolio.group.domain.Group;
import org.mifosplatform.portfolio.group.domain.GroupRepositoryWrapper;
import org.mifosplatform.portfolio.group.domain.GroupRole;
import org.mifosplatform.portfolio.group.domain.GroupRoleRepositoryWrapper;
import org.mifosplatform.portfolio.group.exception.ClientNotInGroupException;
import org.mifosplatform.portfolio.group.serialization.GroupRolesDataValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
@Service
public class GroupRolesWritePlatformServiceJpaRepositoryImpl implements GroupRolesWritePlatformService {
private final static Logger logger = LoggerFactory.getLogger(GroupRolesWritePlatformServiceJpaRepositoryImpl.class);
private final PlatformSecurityContext context;
private final GroupRepositoryWrapper groupRepository;
private final GroupRolesDataValidator fromApiJsonDeserializer;
private final CodeValueRepositoryWrapper codeValueRepository;
private final ClientRepositoryWrapper clientRepository;
private final GroupRoleRepositoryWrapper groupRoleRepository;
@Autowired
public GroupRolesWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
final GroupRepositoryWrapper groupRepository, final GroupRolesDataValidator fromApiJsonDeserializer,
final CodeValueRepositoryWrapper codeValueRepository, final ClientRepositoryWrapper clientRepository,
final GroupRoleRepositoryWrapper groupRoleRepository) {
this.context = context;
this.groupRepository = groupRepository;
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
this.codeValueRepository = codeValueRepository;
this.clientRepository = clientRepository;
this.groupRoleRepository = groupRoleRepository;
}
@Override
public CommandProcessingResult createRole(final JsonCommand command) {
try {
this.context.authenticatedUser();
this.fromApiJsonDeserializer.validateForCreateGroupRole(command);
final Long roleId = command.longValueOfParameterNamed(GroupingTypesApiConstants.roleParamName);
final CodeValue role = this.codeValueRepository.findOneWithNotFoundDetection(roleId);
final Long clientId = command.longValueOfParameterNamed(GroupingTypesApiConstants.clientIdParamName);
final Client client = this.clientRepository.findOneWithNotFoundDetection(clientId);
final Group group = this.groupRepository.findOneWithNotFoundDetection(command.getGroupId());
if (!group.hasClientAsMember(client)) { throw new ClientNotInGroupException(clientId, command.getGroupId()); }
final GroupRole groupRole = GroupRole.createGroupRole(group, client, role);
this.groupRoleRepository.save(groupRole);
return new CommandProcessingResultBuilder().withClientId(client.getId()).withGroupId(group.getId())
.withEntityId(groupRole.getId()).build();
} catch (final DataIntegrityViolationException dve) {
handleGroupDataIntegrityIssues(command, dve);
return CommandProcessingResult.empty();
}
}
private void handleGroupDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) {
final Throwable realCause = dve.getMostSpecificCause();
if (realCause.getMessage().contains("UNIQUE_GROUP_ROLES")) {
final String clientId = command.stringValueOfParameterNamed(GroupingTypesApiConstants.clientIdParamName);
final String roleId = command.stringValueOfParameterNamed(GroupingTypesApiConstants.roleParamName);
final String errorMessageForUser = "Group Role with roleId `" + roleId + "`, clientId `" + clientId + "`, groupId `"
+ command.getGroupId() + "` already exists.";
final String errorMessageForMachine = "error.msg.group.role.already.exists";
throw new PlatformDataIntegrityException(errorMessageForMachine, errorMessageForUser,
GroupingTypesApiConstants.clientIdParamName, roleId, clientId, command.getGroupId());
}
logger.error(dve.getMessage(), dve);
throw new PlatformDataIntegrityException("error.msg.group.unknown.data.integrity.issue",
"Unknown data integrity issue with resource.");
}
@Override
public CommandProcessingResult updateRole(final JsonCommand command) {
try {
this.context.authenticatedUser();
this.fromApiJsonDeserializer.validateForUpdateRole(command);
final Group group = this.groupRepository.findOneWithNotFoundDetection(command.getGroupId());
final GroupRole groupRole = this.groupRoleRepository.findOneWithNotFoundDetection(command.entityId());
final Map<String, Object> actualChanges = groupRole.update(command);
if (actualChanges.containsKey(GroupingTypesApiConstants.roleParamName)) {
final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.roleParamName);
CodeValue role = null;
if (newValue != null) {
role = this.codeValueRepository.findOneWithNotFoundDetection(newValue);
}
groupRole.updateRole(role);
}
if (actualChanges.containsKey(GroupingTypesApiConstants.clientIdParamName)) {
final Long newValue = command.longValueOfParameterNamed(GroupingTypesApiConstants.clientIdParamName);
Client client = null;
if (newValue != null) {
client = this.clientRepository.findOneWithNotFoundDetection(newValue);
if (!group.hasClientAsMember(client)) { throw new ClientNotInGroupException(newValue, command.getGroupId()); }
}
groupRole.updateClient(client);
}
this.groupRoleRepository.saveAndFlush(groupRole);
return new CommandProcessingResultBuilder().with(actualChanges).withGroupId(group.getId()).withEntityId(groupRole.getId())
.build();
} catch (final DataIntegrityViolationException dve) {
handleGroupDataIntegrityIssues(command, dve);
return CommandProcessingResult.empty();
}
}
@Override
public CommandProcessingResult deleteRole(final Long ruleId) {
this.context.authenticatedUser();
final GroupRole groupRole = this.groupRoleRepository.findOneWithNotFoundDetection(ruleId);
this.groupRoleRepository.delete(groupRole);
return new CommandProcessingResultBuilder().withEntityId(groupRole.getId()).build();
}
}
@@ -279,7 +279,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
// get group associations // get group associations
Collection<ClientData> membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId); Collection<ClientData> membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId);
if (!CollectionUtils.isEmpty(membersOfGroup)) { if (!CollectionUtils.isEmpty(membersOfGroup)) {
groupAccount = GroupGeneralData.withAssocations(groupAccount, membersOfGroup); groupAccount = GroupGeneralData.withAssocations(groupAccount, membersOfGroup, null);
} }
final LocalDate expectedDisbursementDate = DateUtils.getLocalDateOfTenant(); final LocalDate expectedDisbursementDate = DateUtils.getLocalDateOfTenant();
@@ -938,7 +938,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService {
// get group associations // get group associations
Collection<ClientData> membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId); Collection<ClientData> membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId);
if (!CollectionUtils.isEmpty(membersOfGroup)) { if (!CollectionUtils.isEmpty(membersOfGroup)) {
groupAccount = GroupGeneralData.withAssocations(groupAccount, membersOfGroup); groupAccount = GroupGeneralData.withAssocations(groupAccount, membersOfGroup, null);
} }
return LoanAccountData.groupDefaults(groupAccount, expectedDisbursementDate); return LoanAccountData.groupDefaults(groupAccount, expectedDisbursementDate);