diff --git a/mifosng-db/migrations/core_db/V58__add_group_roles_schema_and_permissions.sql b/mifosng-db/migrations/core_db/V58__add_group_roles_schema_and_permissions.sql new file mode 100644 index 000000000..16ad5f065 --- /dev/null +++ b/mifosng-db/migrations/core_db/V58__add_group_roles_schema_and_permissions.sql @@ -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; \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java index dc7b6a09c..a2535a778 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandWrapper.java @@ -109,18 +109,15 @@ public class CommandWrapper { } public boolean isCreateDatatable() { - return (this.actionName.equalsIgnoreCase("CREATE") && this.href.startsWith("/datatables/") - && this.entityId == null); + return (this.actionName.equalsIgnoreCase("CREATE") && this.href.startsWith("/datatables/") && this.entityId == null); } public boolean isDeleteDatatable() { - return (this.actionName.equalsIgnoreCase("DELETE") && this.href.startsWith("/datatables/") - && this.entityId == null); + return (this.actionName.equalsIgnoreCase("DELETE") && this.href.startsWith("/datatables/") && this.entityId == null); } public boolean isUpdateDatatable() { - return (this.actionName.equalsIgnoreCase("UPDATE") && this.href.startsWith("/datatables/") - && this.entityId == null); + return (this.actionName.equalsIgnoreCase("UPDATE") && this.href.startsWith("/datatables/") && this.entityId == null); } public String getTaskPermissionName() { @@ -415,7 +412,7 @@ public class CommandWrapper { } public boolean isUpdateOfOwnUserDetails(final Long loggedInUserId) { - return this.isUserResource() && isUpdate() && loggedInUserId.equals(this.entityId); + return isUserResource() && isUpdate() && loggedInUserId.equals(this.entityId); } public boolean isDepositProductResource() { @@ -499,8 +496,8 @@ public class CommandWrapper { public boolean isGroupResource() { return this.entityName.equalsIgnoreCase("GROUP"); } - - public boolean isSaveGroupCollectionSheet(){ + + public boolean isSaveGroupCollectionSheet() { return this.entityName.equalsIgnoreCase("GROUP") && this.actionName.equalsIgnoreCase("SAVECOLLECTIONSHEET"); } @@ -512,10 +509,10 @@ public class CommandWrapper { return this.entityName.equalsIgnoreCase("CENTER"); } - public boolean isSaveCenterCollectionSheet(){ + public boolean isSaveCenterCollectionSheet() { return this.entityName.equalsIgnoreCase("CENTER") && this.actionName.equalsIgnoreCase("SAVECOLLECTIONSHEET"); } - + public boolean isReportResource() { return this.entityName.equalsIgnoreCase("REPORT"); } @@ -528,11 +525,23 @@ public class CommandWrapper { return this.actionName.equalsIgnoreCase("DISASSOCIATECLIENTS"); } - public boolean isAccountingRuleResource() { - return this.entityName.equalsIgnoreCase("ACCOUNTINGRULE"); - } - - public boolean isHolidayResource() { - return this.entityName.equalsIgnoreCase("HOLIDAY"); - } + public boolean isHolidayResource() { + return this.entityName.equalsIgnoreCase("HOLIDAY"); + } + + public boolean isAccountingRuleResource() { + 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"); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java index 132a79d8e..71f5c6df0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java @@ -1026,4 +1026,31 @@ public class CommandWrapperBuilder { this.href = "/holidays/template"; 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; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java index 692c12bcf..cc652c3dc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/SynchronousCommandProcessingService.java @@ -59,7 +59,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer final NewCommandSourceHandler handler = findCommandHandler(wrapper); final CommandProcessingResult result = handler.processCommand(command); - final AppUser maker = context.authenticatedUser(); + final AppUser maker = this.context.authenticatedUser(); CommandSource commandSourceResult = null; if (command.commandId() != null) { @@ -83,7 +83,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer } if (commandSourceResult.hasJson()) { - commandSourceRepository.save(commandSourceResult); + this.commandSourceRepository.save(commandSourceResult); } if (rollbackTransaction) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(commandSourceResult); } @@ -96,7 +96,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer public CommandProcessingResult logCommand(final CommandSource commandSourceResult) { commandSourceResult.markAsAwaitingApproval(); - commandSourceRepository.save(commandSourceResult); + this.commandSourceRepository.save(commandSourceResult); return new CommandProcessingResultBuilder().withCommandId(commandSourceResult.getId()) .withEntityId(commandSourceResult.getResourceId()).build(); @@ -106,333 +106,340 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer NewCommandSourceHandler handler = null; if (wrapper.isConfigurationResource()) { - handler = applicationContext.getBean("updateGlobalConfigurationCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateGlobalConfigurationCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDatatableResource()) { - if (wrapper.isCreateDatatable()) { - handler = applicationContext.getBean("createDatatableCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isDeleteDatatable()) { - handler = applicationContext.getBean("deleteDatatableCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isUpdateDatatable()) { - handler = applicationContext.getBean("updateDatatableCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isCreate()) { - handler = applicationContext.getBean("createDatatableEntryCommandHandler", NewCommandSourceHandler.class); + if (wrapper.isCreateDatatable()) { + handler = this.applicationContext.getBean("createDatatableCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isDeleteDatatable()) { + handler = this.applicationContext.getBean("deleteDatatableCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isUpdateDatatable()) { + handler = this.applicationContext.getBean("updateDatatableCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isCreate()) { + handler = this.applicationContext.getBean("createDatatableEntryCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdateMultiple()) { - handler = applicationContext.getBean("updateOneToManyDatatableEntryCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateOneToManyDatatableEntryCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdateOneToOne()) { - handler = applicationContext.getBean("updateOneToOneDatatableEntryCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateOneToOneDatatableEntryCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDeleteMultiple()) { - handler = applicationContext.getBean("deleteOneToManyDatatableEntryCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteOneToManyDatatableEntryCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDeleteOneToOne()) { - handler = applicationContext.getBean("deleteOneToOneDatatableEntryCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteOneToOneDatatableEntryCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isNoteResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createNoteCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createNoteCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateNoteCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateNoteCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteNoteCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteNoteCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isClientIdentifierResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createClientIdentifierCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createClientIdentifierCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateClientIdentifierCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateClientIdentifierCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteClientIdentifierCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteClientIdentifierCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isClientResource() && !wrapper.isClientNoteResource() && !wrapper.isClientIdentifierResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createClientCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createClientCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateClientCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateClientCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteClientCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteClientCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isClientActivation()) { - handler = applicationContext.getBean("activateClientCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("activateClientCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } // end of client } else if (wrapper.isUpdateRolePermissions()) { - handler = applicationContext.getBean("updateRolePermissionsCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateRolePermissionsCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isPermissionResource()) { - handler = applicationContext.getBean("updateMakerCheckerPermissionsCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateMakerCheckerPermissionsCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isRoleResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createRoleCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createRoleCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateRoleCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateRoleCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isUserResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createUserCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createUserCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateUserCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateUserCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteUserCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteUserCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isStaffResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createStaffCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createStaffCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateStaffCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateStaffCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isGuarantorResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createGuarantorCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createGuarantorCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateGuarantorCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateGuarantorCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteGuarantorCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteGuarantorCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isCollateralResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createCollateralCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createCollateralCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateCollateralCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateCollateralCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteCollateralCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteCollateralCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isCodeResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createCodeCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createCodeCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateCodeCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateCodeCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteCodeCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteCodeCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isCodeValueResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createCodeValueCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createCodeValueCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateCodeValueCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateCodeValueCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteCodeValueCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteCodeValueCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isCurrencyResource()) { - handler = applicationContext.getBean("updateCurrencyCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateCurrencyCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isFundResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createFundCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createFundCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateFundCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateFundCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isOfficeResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createOfficeCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createOfficeCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateOfficeCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateOfficeCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isOfficeTransactionResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createOfficeTransactionCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createOfficeTransactionCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteOfficeTransactionCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteOfficeTransactionCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isChargeDefinitionResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createChargeDefinitionCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createChargeDefinitionCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateChargeDefinitionCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateChargeDefinitionCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteChargeDefinitionCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteChargeDefinitionCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isLoanProductResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createLoanProductCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createLoanProductCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateLoanProductCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateLoanProductCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isLoanResource()) { if (wrapper.isApproveLoanApplication()) { - handler = applicationContext.getBean("loanApplicationApprovalCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("loanApplicationApprovalCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUndoApprovalOfLoanApplication()) { - handler = applicationContext.getBean("loanApplicationApprovalUndoCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("loanApplicationApprovalUndoCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isApplicantWithdrawalFromLoanApplication()) { - handler = applicationContext.getBean("loanApplicationWithdrawnByApplicantCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("loanApplicationWithdrawnByApplicantCommandHandler", + NewCommandSourceHandler.class); } else if (wrapper.isRejectionOfLoanApplication()) { - handler = applicationContext.getBean("loanApplicationRejectedCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("loanApplicationRejectedCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDisbursementOfLoan()) { - handler = applicationContext.getBean("disburseLoanCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("disburseLoanCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUndoDisbursementOfLoan()) { - handler = applicationContext.getBean("undoDisbursalLoanCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("undoDisbursalLoanCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isLoanRepayment()) { - handler = applicationContext.getBean("loanRepaymentCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("loanRepaymentCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isLoanRepaymentAdjustment()) { - handler = applicationContext.getBean("loanRepaymentAdjustmentCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("loanRepaymentAdjustmentCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isWaiveInterestPortionOnLoan()) { - handler = applicationContext.getBean("waiveInterestPortionOnLoanCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("waiveInterestPortionOnLoanCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isLoanWriteOff()) { - handler = applicationContext.getBean("writeOffLoanCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("writeOffLoanCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isCloseLoanAsObligationsMet()) { - handler = applicationContext.getBean("closeLoanCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("closeLoanCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isCloseLoanAsRescheduled()) { - handler = applicationContext.getBean("closeLoanAsRescheduledCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("closeLoanAsRescheduledCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdateLoanOfficer()) { - handler = applicationContext.getBean("updateLoanOfficerCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateLoanOfficerCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isRemoveLoanOfficer()) { - handler = applicationContext.getBean("removeLoanOfficerCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("removeLoanOfficerCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isBulkUpdateLoanOfficer()) { - handler = applicationContext.getBean("bulkUpdateLoanOfficerCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("bulkUpdateLoanOfficerCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isCreate()) { - handler = applicationContext.getBean("loanApplicationSubmittalCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("loanApplicationSubmittalCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("loanApplicationModificationCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("loanApplicationModificationCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("loanApplicationDeletionCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("loanApplicationDeletionCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isLoanChargeResource()) { if (wrapper.isAddLoanCharge()) { - handler = applicationContext.getBean("addLoanChargeCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("addLoanChargeCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDeleteLoanCharge()) { - handler = applicationContext.getBean("deleteLoanChargeCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteLoanChargeCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdateLoanCharge()) { - handler = applicationContext.getBean("updateLoanChargeCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateLoanChargeCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isWaiveLoanCharge()) { - handler = applicationContext.getBean("waiveLoanChargeCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("waiveLoanChargeCommandHandler", NewCommandSourceHandler.class); } } else if (wrapper.isGLAccountResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createGLAccountCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createGLAccountCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateGLAccountCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateGLAccountCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteGLAccountCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteGLAccountCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isGLClosureResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createGLClosureCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createGLClosureCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateGLClosureCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateGLClosureCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteGLClosureCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteGLClosureCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isJournalEntryResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createJournalEntryCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createJournalEntryCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isRevertJournalEntry()) { - handler = applicationContext.getBean("reverseJournalEntryCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("reverseJournalEntryCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isSavingsProductResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createSavingsProductCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createSavingsProductCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateSavingsProductCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateSavingsProductCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteSavingsProductCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteSavingsProductCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isSavingsAccountResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createSavingsAccountCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createSavingsAccountCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateSavingsAccountCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateSavingsAccountCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteSavingsAccountCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteSavingsAccountCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isSavingsAccountDeposit()) { - handler = applicationContext.getBean("depositSavingsAccountCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("depositSavingsAccountCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isSavingsAccountWithdrawal()) { - handler = applicationContext.getBean("withdrawSavingsAccountCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("withdrawSavingsAccountCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isSavingsAccountActivation()) { - handler = applicationContext.getBean("activateSavingsAccountCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("activateSavingsAccountCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isSavingsAccountInterestCalculation()) { - handler = applicationContext.getBean("calculateInterestSavingsAccountCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("calculateInterestSavingsAccountCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isSavingsAccountInterestPosting()) { - handler = applicationContext.getBean("postInterestSavingsAccountCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("postInterestSavingsAccountCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isCalendarResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createCalendarCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createCalendarCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateCalendarCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateCalendarCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteCalendarCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteCalendarCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isGroupResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createGroupCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createGroupCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateGroupCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateGroupCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUnassignStaff()) { - handler = applicationContext.getBean("unassignGroupStaffCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("unassignGroupStaffCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteGroupCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteGroupCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isGroupActivation()) { - handler = applicationContext.getBean("activateGroupCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("activateGroupCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isAssociateClients()) { - handler = applicationContext.getBean("associateClientsToGroupCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("associateClientsToGroupCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDisassociateClients()) { - handler = applicationContext.getBean("disassociateClientsFromGroupCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("disassociateClientsFromGroupCommandHandler", NewCommandSourceHandler.class); } 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 { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isCenterResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createCenterCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createCenterCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateCenterCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateCenterCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteCenterCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteCenterCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isCenterActivation()) { - handler = applicationContext.getBean("activateCenterCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("activateCenterCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isSaveCenterCollectionSheet()) { - handler = applicationContext.getBean("saveCenterCollectionSheetCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("saveCenterCollectionSheetCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isCollectionSheetResource()) { if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateCollectionSheetCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateCollectionSheetCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } @@ -440,11 +447,11 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer } else if (wrapper.isReportResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createReportCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createReportCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateReportCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateReportCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteReportCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteReportCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } @@ -452,11 +459,11 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer } else if (wrapper.isAccountingRuleResource()) { if (wrapper.isCreate()) { - handler = applicationContext.getBean("createAccountingRuleCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("createAccountingRuleCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateAccountingRuleCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("updateAccountingRuleCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteAccountingRuleCommandHandler", NewCommandSourceHandler.class); + handler = this.applicationContext.getBean("deleteAccountingRuleCommandHandler", NewCommandSourceHandler.class); } else { throw new UnsupportedCommandException(wrapper.commandName()); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResult.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResult.java index d1c23560f..c0a1bcc60 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResult.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResult.java @@ -22,16 +22,15 @@ public class CommandProcessingResult { private final Long savingsId; private final Long resourceId; private final String transactionId; - private final Long holidayId; private final Map changes; @SuppressWarnings("unused") private final String resourceIdentifier; 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 holidayId, final Map changes) { + final Map changes) { return new CommandProcessingResult(commandId, officeId, groupId, clientId, loanId, savingsId, resourceIdentifier, entityId, - transactionId, holidayId, changes); + transactionId, changes); } public static CommandProcessingResult commandOnlyResult(final Long commandId) { @@ -79,12 +78,11 @@ public class CommandProcessingResult { this.loanId = null; this.savingsId = null; this.transactionId = null; - this.holidayId = null; this.changes = new HashMap(); } 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 changesOnly) { this.commandId = commandId; this.officeId = officeId; @@ -96,7 +94,6 @@ public class CommandProcessingResult { this.resourceId = resourceId; this.changes = changesOnly; this.transactionId = transactionId; - this.holidayId = holidayId; } private CommandProcessingResult(final Long resourceId, final Long officeId, final Long commandId, final Map changesOnly) { @@ -112,7 +109,6 @@ public class CommandProcessingResult { this.loanId = null; this.savingsId = null; this.transactionId = null; - this.holidayId = null; this.commandId = commandId; this.changes = changesOnly; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResultBuilder.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResultBuilder.java index 20d977079..6045306f6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResultBuilder.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResultBuilder.java @@ -22,12 +22,11 @@ public class CommandProcessingResultBuilder { private String resourceIdentifier; private Long entityId; private String transactionId; - private Long holidayId; private Map changes; public CommandProcessingResult build() { return CommandProcessingResult.fromDetails(commandId, officeId, groupId, clientId, loanId, savingsId, resourceIdentifier, entityId, - transactionId, holidayId, changes); + transactionId, changes); } public CommandProcessingResultBuilder withCommandId(final Long withCommandId) { @@ -79,9 +78,5 @@ public class CommandProcessingResultBuilder { this.transactionId = withTransactionId; return this; } - - public CommandProcessingResultBuilder withHolidayId(final Long withHolidayId) { - this.holidayId = withHolidayId; - return this; - } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/holiday/service/HolidayWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/holiday/service/HolidayWritePlatformServiceJpaRepositoryImpl.java index 18fe2b2de..b4157e47a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/holiday/service/HolidayWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/holiday/service/HolidayWritePlatformServiceJpaRepositoryImpl.java @@ -82,8 +82,7 @@ public class HolidayWritePlatformServiceJpaRepositoryImpl implements HolidayWrit this.holidayRepository.save(holiday); - return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(holiday.getId()) - .withHolidayId(holiday.getId()).build(); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(holiday.getId()).build(); } catch (final DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); return CommandProcessingResult.empty(); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java index 155e28d52..03bbec3ee 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/CentersApiResource.java @@ -210,8 +210,8 @@ public class CentersApiResource { final CommandWrapper commandRequest = builder.saveCenterCollectionSheet(centerId).build(); result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); - } else { // - throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "generateCollectionSheet" }); + } else { + throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "generateCollectionSheet", "createRole" }); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupingTypesApiConstants.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupingTypesApiConstants.java index d322c1976..9151d270d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupingTypesApiConstants.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupingTypesApiConstants.java @@ -16,6 +16,15 @@ public class GroupingTypesApiConstants { public static final String CENTER_RESOURCE_NAME = "center"; public static final String GROUP_RESOURCE_NAME = "group"; 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 public static final String localeParamName = "locale"; @@ -51,6 +60,8 @@ public class GroupingTypesApiConstants { public static final Set GROUP_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(localeParamName, dateFormatParamName, idParamName, nameParamName, externalIdParamName, centerIdParamName, officeIdParamName, staffIdParamName, activeParamName, activationDateParamName, clientMembersParamName)); + + public static final Set GROUP_ROLES_REQUEST_DATA_PARAMETERS = new HashSet(Arrays.asList(roleParamName, clientIdParamName)); /** * These parameters will match the class level parameters of @@ -74,4 +85,5 @@ public class GroupingTypesApiConstants { public static final Set COLLECTIONSHEET_DATA_PARAMETERS = new HashSet(Arrays.asList("dueDate", "loanProducts", "groups")); + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java index 7b2507582..465507b64 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/api/GroupsApiResource.java @@ -44,8 +44,10 @@ import org.mifosplatform.portfolio.collectionsheet.data.JLGCollectionSheetData; import org.mifosplatform.portfolio.collectionsheet.service.CollectionSheetReadPlatformService; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData; 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.GroupReadPlatformService; +import org.mifosplatform.portfolio.group.service.GroupRolesReadPlatformService; import org.mifosplatform.portfolio.group.service.SearchParameters; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -70,6 +72,7 @@ public class GroupsApiResource { private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; private final CollectionSheetReadPlatformService collectionSheetReadPlatformService; private final FromJsonHelper fromJsonHelper; + private final GroupRolesReadPlatformService groupRolesReadPlatformService; @Autowired public GroupsApiResource(final PlatformSecurityContext context, final GroupReadPlatformService groupReadPlatformService, @@ -79,7 +82,8 @@ public class GroupsApiResource { final ToApiJsonSerializer groupSummaryToApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper, final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService, - final CollectionSheetReadPlatformService collectionSheetReadPlatformService, final FromJsonHelper fromJsonHelper) { + final CollectionSheetReadPlatformService collectionSheetReadPlatformService, final FromJsonHelper fromJsonHelper, + final GroupRolesReadPlatformService groupRolesReadPlatformService) { this.context = context; this.groupReadPlatformService = groupReadPlatformService; this.centerReadPlatformService = centerReadPlatformService; @@ -91,6 +95,7 @@ public class GroupsApiResource { this.commandsSourceWritePlatformService = commandsSourceWritePlatformService; this.collectionSheetReadPlatformService = collectionSheetReadPlatformService; this.fromJsonHelper = fromJsonHelper; + this.groupRolesReadPlatformService = groupRolesReadPlatformService; } @GET @@ -132,7 +137,7 @@ public class GroupsApiResource { limit, orderBy, sortOrder); final Page 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); } @@ -141,7 +146,8 @@ public class GroupsApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) 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); final Set associationParameters = ApiParameterHelper.extractAssociationsForResponseIfProvided(uriInfo.getQueryParameters()); @@ -150,22 +156,39 @@ public class GroupsApiResource { // associations Collection membersOfGroup = null; + Collection groupRoles = null; + GroupRoleData selectedRole = null; if (!associationParameters.isEmpty()) { + if (associationParameters.contains("all")) { + associationParameters.addAll(Arrays.asList("clientMembers", "groupRoles")); + } if (associationParameters.contains("clientMembers")) { membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId); if (CollectionUtils.isEmpty(membersOfGroup)) { 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()); if (template) { final GroupGeneralData templateGroup = this.groupReadPlatformService.retrieveTemplate(group.officeId(), false, staffInSelectedOfficeOnly); - group = GroupGeneralData.withTemplateAndAssociations(templateGroup, group, membersOfGroup); + group = GroupGeneralData.withTemplateAndAssociations(templateGroup, group, membersOfGroup, groupRoles); } else { - group = GroupGeneralData.withAssocations(group, membersOfGroup); + group = GroupGeneralData.withAssocations(group, membersOfGroup, groupRoles); } final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); @@ -232,8 +255,8 @@ public class GroupsApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) 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); CommandProcessingResult result = null; @@ -264,9 +287,21 @@ public class GroupsApiResource { final CommandWrapper commandRequest = builder.unassignGroupStaff(groupId).build(); result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); 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 { throw new UnrecognizedQueryParamException("command", commandParam, new Object[] { "activate", "generateCollectionSheet", - "saveCollectionSheet", "unassignStaff" }); + "saveCollectionSheet", "unassignStaff", "assignRole", "unassignRole", "updateassignRole" }); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupGeneralData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupGeneralData.java index 36b50da77..63d037eb8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupGeneralData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupGeneralData.java @@ -8,6 +8,7 @@ package org.mifosplatform.portfolio.group.data; import java.util.Collection; import org.joda.time.LocalDate; +import org.mifosplatform.infrastructure.codes.data.CodeValueData; import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.organisation.office.data.OfficeData; import org.mifosplatform.organisation.staff.data.StaffData; @@ -38,50 +39,59 @@ public class GroupGeneralData { // associations private final Collection clientMembers; + private final Collection groupRoles; // template private final Collection centerOptions; private final Collection officeOptions; private final Collection staffOptions; private final Collection clientOptions; + private final Collection availableRoles; + private final GroupRoleData selectedRole; public static GroupGeneralData lookup(final Long groupId, final String groupName) { final Collection clientMembers = null; + final Collection groupRoles = 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, final String staffName, final Collection centerOptions, final Collection officeOptions, - final Collection staffOptions, final Collection clientOptions) { + final Collection staffOptions, final Collection clientOptions, + final Collection availableRoles) { final Collection clientMembers = null; + final Collection groupRoles = 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) { 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, 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, - final Collection membersOfGroup) { + final Collection membersOfGroup, final Collection groupRoles) { 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, 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 membersOfGroup) { + public static GroupGeneralData withAssocations(final GroupGeneralData grouping, final Collection membersOfGroup, + final Collection groupRoles) { 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, 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, @@ -93,16 +103,21 @@ public class GroupGeneralData { final Collection officeOptions = null; final Collection staffOptions = null; final Collection clientOptions = null; + final Collection groupRoles = null; + final Collection availableRoles = null; + final GroupRoleData role = null; 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, 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 clientMembers, final Collection centerOptions, final Collection officeOptions, - final Collection staffOptions, final Collection clientOptions) { + final Collection staffOptions, final Collection clientOptions, + final Collection groupRoles, final Collection availableRoles, final GroupRoleData role) { this.id = id; this.name = name; this.externalId = externalId; @@ -134,6 +149,9 @@ public class GroupGeneralData { clientOptions.removeAll(clientMembers); } this.clientOptions = clientOptions; + this.groupRoles = groupRoles; + this.availableRoles = availableRoles; + this.selectedRole = role; } public Long getId() { @@ -147,9 +165,16 @@ public class GroupGeneralData { public Long officeId() { return this.officeId; } - + public String getHierarchy() { 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); + } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupRoleData.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupRoleData.java new file mode 100644 index 000000000..1de03a0ba --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/data/GroupRoleData.java @@ -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; + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupRole.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupRole.java new file mode 100644 index 000000000..07a68e612 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupRole.java @@ -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 { + + @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 update(final JsonCommand command) { + + final Map actualChanges = new LinkedHashMap(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; + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupRoleRepository.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupRoleRepository.java new file mode 100644 index 000000000..f0dd7ae32 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupRoleRepository.java @@ -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, JpaSpecificationExecutor { + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupRoleRepositoryWrapper.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupRoleRepositoryWrapper.java new file mode 100644 index 000000000..5cfd1122d --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/GroupRoleRepositoryWrapper.java @@ -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); + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/exception/GroupRoleNotFoundException.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/exception/GroupRoleNotFoundException.java new file mode 100644 index 000000000..5ab112047 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/exception/GroupRoleNotFoundException.java @@ -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); + } +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/AssignRoleCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/AssignRoleCommandHandler.java new file mode 100644 index 000000000..8a91b6ac1 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/AssignRoleCommandHandler.java @@ -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); + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UnassignRoleCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UnassignRoleCommandHandler.java new file mode 100644 index 000000000..94662f1bd --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UnassignRoleCommandHandler.java @@ -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()); + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UpdateGroupRoleCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UpdateGroupRoleCommandHandler.java new file mode 100644 index 000000000..5671cb633 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/handler/UpdateGroupRoleCommandHandler.java @@ -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); + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/serialization/GroupRolesDataValidator.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/serialization/GroupRolesDataValidator.java new file mode 100644 index 000000000..fdaa183a7 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/serialization/GroupRolesDataValidator.java @@ -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 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>() {}.getType(); + this.fromApiJsonHelper + .checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.GROUP_ROLES_REQUEST_DATA_PARAMETERS); + + final List dataValidationErrors = new ArrayList(); + + 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>() {}.getType(); + this.fromApiJsonHelper + .checkForUnsupportedParameters(typeOfMap, json, GroupingTypesApiConstants.GROUP_ROLES_REQUEST_DATA_PARAMETERS); + + final List dataValidationErrors = new ArrayList(); + + 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); + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformServiceImpl.java index 6d5ff3f6a..5673e0c8d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/CenterReadPlatformServiceImpl.java @@ -323,7 +323,7 @@ public class CenterReadPlatformServiceImpl implements CenterReadPlatformService } return GroupGeneralData.template(centerOfficeId, center.getId(), center.getName(), staffId, staffName, centerOptions, - officeOptions, staffOptions, clientOptions); + officeOptions, staffOptions, clientOptions, null); } @Override diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java index 53207d039..99f643bea 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupReadPlatformServiceImpl.java @@ -12,6 +12,8 @@ import java.util.Collection; import java.util.List; 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.domain.JdbcSupport; 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.service.ClientReadPlatformService; 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.GroupAccountSummaryCollectionData; import org.mifosplatform.portfolio.group.data.GroupAccountSummaryData; @@ -48,6 +51,7 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { private final OfficeReadPlatformService officeReadPlatformService; private final StaffReadPlatformService staffReadPlatformService; private final CenterReadPlatformService centerReadPlatformService; + private final CodeValueReadPlatformService codeValueReadPlatformService; private final AllGroupTypesDataMapper allGroupTypesDataMapper = new AllGroupTypesDataMapper(); private final PaginationHelper paginationHelper = new PaginationHelper(); @@ -55,13 +59,15 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { @Autowired public GroupReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource, 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.jdbcTemplate = new JdbcTemplate(dataSource); this.centerReadPlatformService = centerReadPlatformService; this.clientReadPlatformService = clientReadPlatformService; this.officeReadPlatformService = officeReadPlatformService; this.staffReadPlatformService = staffReadPlatformService; + this.codeValueReadPlatformService = codeValueReadPlatformService; } @Override @@ -94,13 +100,16 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { clientOptions = null; } + final Collection availableRoles = this.codeValueReadPlatformService + .retrieveCodeValuesByCode(GroupingTypesApiConstants.GROUP_ROLE_NAME); + final Long centerId = null; final String centerName = null; final Long staffId = null; final String staffName = null; return GroupGeneralData.template(defaultOfficeId, centerId, centerName, staffId, staffName, centerOptions, officeOptions, - staffOptions, clientOptions); + staffOptions, clientOptions, availableRoles); } private Long defaultToUsersOfficeIfNull(final Long officeId) { @@ -114,11 +123,11 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { @Override public Page retrieveAll(final SearchParameters searchParameters) { - final AppUser currentUser = context.authenticatedUser(); + final AppUser currentUser = this.context.authenticatedUser(); final String hierarchy = currentUser.getOffice().getHierarchy(); final String hierarchySearchString = hierarchy + "%"; - StringBuilder sqlBuilder = new StringBuilder(200); + final StringBuilder sqlBuilder = new StringBuilder(200); sqlBuilder.append("select SQL_CALC_FOUND_ROWS "); sqlBuilder.append(this.allGroupTypesDataMapper.schema()); sqlBuilder.append(" where o.hierarchy like ?"); @@ -190,13 +199,13 @@ public class GroupReadPlatformServiceImpl implements GroupReadPlatformService { public GroupGeneralData retrieveOne(final Long groupId) { try { - final AppUser currentUser = context.authenticatedUser(); + final AppUser currentUser = this.context.authenticatedUser(); final String hierarchy = currentUser.getOffice().getHierarchy(); 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 }); - } catch (EmptyResultDataAccessException e) { + } catch (final EmptyResultDataAccessException e) { 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,"); 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(); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupRolesReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupRolesReadPlatformService.java new file mode 100644 index 000000000..c5703d06b --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupRolesReadPlatformService.java @@ -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 retrieveGroupRoles(Long groupId); + + GroupRoleData retrieveGroupRole(Long groupId, Long roleId); +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupRolesReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupRolesReadPlatformServiceImpl.java new file mode 100644 index 000000000..d08be9cbf --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupRolesReadPlatformServiceImpl.java @@ -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 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 { + + 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); + } + + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupRolesWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupRolesWritePlatformService.java new file mode 100644 index 000000000..eb0e0aba8 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupRolesWritePlatformService.java @@ -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); + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupRolesWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupRolesWritePlatformServiceJpaRepositoryImpl.java new file mode 100644 index 000000000..691f8528d --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupRolesWritePlatformServiceJpaRepositoryImpl.java @@ -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 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(); + } + +} diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java index be244bd87..a0fc10ec1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanReadPlatformServiceImpl.java @@ -279,7 +279,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { // get group associations Collection membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId); if (!CollectionUtils.isEmpty(membersOfGroup)) { - groupAccount = GroupGeneralData.withAssocations(groupAccount, membersOfGroup); + groupAccount = GroupGeneralData.withAssocations(groupAccount, membersOfGroup, null); } final LocalDate expectedDisbursementDate = DateUtils.getLocalDateOfTenant(); @@ -938,7 +938,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { // get group associations Collection membersOfGroup = this.clientReadPlatformService.retrieveClientMembersOfGroup(groupId); if (!CollectionUtils.isEmpty(membersOfGroup)) { - groupAccount = GroupGeneralData.withAssocations(groupAccount, membersOfGroup); + groupAccount = GroupGeneralData.withAssocations(groupAccount, membersOfGroup, null); } return LoanAccountData.groupDefaults(groupAccount, expectedDisbursementDate);