From 690f0d4abcb222139a58f5cb1a9ba7d7850a88f8 Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Sun, 6 Jan 2013 17:36:05 +0000 Subject: [PATCH] MIFOSX-9: Audit related work --- ...tch-05-restructure-command-audit-table.sql | 28 + .../accounting/api/GLAccountsApiResource.java | 8 +- .../accounting/api/GLClosuresApiResource.java | 8 +- .../AccountingApiJsonSerializerService.java | 4 +- ...sonAccountingApiJsonSerializerService.java | 4 +- .../mifosplatform/audit/data/AuditData.java | 84 +- .../service/AuditReadPlatformServiceImpl.java | 241 ++- .../commands/api/CommandsApiResource.java | 6 +- .../commands/domain/CommandSource.java | 79 +- .../commands/domain/CommandWrapper.java | 212 ++- .../handler/NewCommandSourceHandler.java | 4 +- .../service/CommandProcessingService.java | 6 +- .../service/CommandWrapperBuilder.java | 385 +++++ ...olioCommandSourceWritePlatformService.java | 10 +- ...CommandSourceWritePlatformServiceImpl.java | 56 +- ...tfolioCommandsReadPlatformServiceImpl.java | 6 +- .../SynchronousCommandProcessingService.java | 64 +- .../codes/api/CodesApiResource.java | 22 +- .../handler/CreateCodeCommandHandler.java | 4 +- .../handler/DeleteCodeCommandHandler.java | 6 +- .../handler/UpdateCodeCommandHandler.java | 6 +- .../service/CodeWritePlatformService.java | 8 +- ...WritePlatformServiceJpaRepositoryImpl.java | 17 +- .../infrastructure/core/api/JsonCommand.java | 71 +- .../core/data/CommandProcessingResult.java | 124 ++ .../data/CommandProcessingResultBuilder.java | 57 + .../core/data/EntityIdentifier.java | 87 - .../dataqueries/api/DataTableApiResource.java | 48 +- .../CreateDatatableEntryCommandHandler.java | 33 +- ...OneToManyDatatableEntryCommandHandler.java | 30 +- ...eOneToOneDatatableEntryCommandHandler.java | 30 +- ...OneToManyDatatableEntryCommandHandler.java | 31 +- ...eOneToOneDatatableEntryCommandHandler.java | 11 +- .../ReadWriteNonCoreDataServiceImpl.java | 1430 +++++++---------- .../api/DocumentManagementApiResource.java | 8 +- .../service/DocumentWritePlatformService.java | 6 +- ...WritePlatformServiceJpaRepositoryImpl.java | 10 +- .../monetary/api/CurrenciesApiResource.java | 10 +- .../handler/UpdateCurrencyCommandHandler.java | 4 +- .../service/CurrencyWritePlatformService.java | 4 +- ...WritePlatformServiceJpaRepositoryImpl.java | 7 +- .../api/OfficeTransactionsApiResource.java | 9 +- .../office/api/OfficesApiResource.java | 16 +- .../handler/CreateOfficeCommandHandler.java | 4 +- ...CreateOfficeTransactionCommandHandler.java | 4 +- .../handler/UpdateOfficeCommandHandler.java | 6 +- .../service/OfficeWritePlatformService.java | 8 +- ...WritePlatformServiceJpaRepositoryImpl.java | 25 +- .../staff/api/StaffApiResource.java | 16 +- .../organisation/staff/domain/Staff.java | 4 + .../handler/CreateStaffCommandHandler.java | 4 +- .../handler/UpdateStaffCommandHandler.java | 6 +- .../service/StaffWritePlatformService.java | 6 +- ...WritePlatformServiceJpaRepositoryImpl.java | 19 +- .../charge/api/ChargesApiResource.java | 22 +- .../CreateChargeDefinitionCommandHandler.java | 4 +- .../DeleteChargeDefinitionCommandHandler.java | 6 +- .../UpdateChargeDefinitionCommandHandler.java | 6 +- .../service/ChargeWritePlatformService.java | 8 +- ...WritePlatformServiceJpaRepositoryImpl.java | 39 +- .../api/ClientIdentifiersApiResource.java | 24 +- .../client/api/ClientImagesApiResource.java | 8 +- .../client/api/ClientNotesApiResource.java | 16 +- .../client/api/ClientsApiResource.java | 28 +- .../portfolio/client/domain/Client.java | 3 +- .../handler/CreateClientCommandHandler.java | 4 +- .../CreateClientIdentifierCommandHandler.java | 6 +- .../CreateClientNoteCommandHandler.java | 6 +- .../handler/DeleteClientCommandHandler.java | 6 +- .../DeleteClientIdentifierCommandHandler.java | 6 +- .../handler/UpdateClientCommandHandler.java | 6 +- .../UpdateClientIdentifierCommandHandler.java | 6 +- .../UpdateClientNoteCommandHandler.java | 6 +- .../service/ClientWritePlatformService.java | 24 +- ...WritePlatformServiceJpaRepositoryImpl.java | 76 +- .../portfolio/fund/api/FundsApiResource.java | 16 +- .../handler/CreateFundCommandHandler.java | 4 +- .../handler/UpdateFundCommandHandler.java | 6 +- .../service/FundWritePlatformService.java | 6 +- ...WritePlatformServiceJpaRepositoryImpl.java | 15 +- .../group/api/GroupsApiResource.java | 8 +- .../portfolio/group/domain/Group.java | 33 +- .../service/GroupWritePlatformService.java | 8 +- ...WritePlatformServiceJpaRepositoryImpl.java | 18 +- .../loanaccount/api/BulkLoansApiResource.java | 10 +- .../api/LoanChargesApiResource.java | 28 +- .../api/LoanTransactionsApiResource.java | 39 +- .../loanaccount/api/LoansApiResource.java | 57 +- .../portfolio/loanaccount/domain/Loan.java | 56 +- .../gaurantor/api/GuarantorsApiResource.java | 8 +- .../handler/AddLoanChargeCommandHandler.java | 6 +- .../BulkUpdateLoanOfficerCommandHandler.java | 4 +- .../CloseLoanAsRescheduledCommandHandler.java | 6 +- .../handler/CloseLoanCommandHandler.java | 6 +- .../DeleteLoanChargeCommandHandler.java | 6 +- .../handler/DisburseLoanCommandHandler.java | 6 +- ...LoanApplicationApprovalCommandHandler.java | 6 +- ...ApplicationApprovalUndoCommandHandler.java | 6 +- ...LoanApplicationDeletionCommandHandler.java | 6 +- ...ApplicationModificationCommandHandler.java | 6 +- ...LoanApplicationRejectedCommandHandler.java | 6 +- ...oanApplicationSubmittalCommandHandler.java | 4 +- ...ionWithdrawnByApplicantCommandHandler.java | 6 +- ...LoanRepaymentAdjustmentCommandHandler.java | 6 +- .../handler/LoanRepaymentCommandHandler.java | 6 +- .../UndoDisbursalLoanCommandHandler.java | 6 +- .../UpdateLoanChargeCommandHandler.java | 6 +- .../UpdateLoanOfficerCommandHandler.java | 6 +- ...veInterestPortionOnLoanCommandHandler.java | 6 +- .../WaiveLoanChargeCommandHandler.java | 6 +- .../handler/WriteOffLoanCommandHandler.java | 6 +- .../LoanApplicationWritePlatformService.java | 16 +- ...WritePlatformServiceJpaRepositoryImpl.java | 110 +- .../service/LoanWritePlatformService.java | 30 +- ...WritePlatformServiceJpaRepositoryImpl.java | 175 +- .../api/LoanProductsApiResource.java | 16 +- .../CreateLoanProductCommandHandler.java | 4 +- .../UpdateLoanProductCommandHandler.java | 6 +- .../LoanProductWritePlatformService.java | 6 +- ...WritePlatformServiceJpaRepositoryImpl.java | 11 +- .../api/SavingsAccountApiResource.java | 6 +- .../SavingAccountWritePlatformService.java | 6 +- ...WritePlatformServiceJpaRepositoryImpl.java | 14 +- .../api/SavingProductsApiResource.java | 8 +- .../SavingProductWritePlatformService.java | 8 +- ...WritePlatformServiceJpaRepositoryImpl.java | 14 +- .../api/DepositAccountsApiResource.java | 24 +- .../DepositAccountWritePlatformService.java | 24 +- ...WritePlatformServiceJpaRepositoryImpl.java | 52 +- .../api/DepositProductsApiResource.java | 8 +- .../DepositProductWritePlatformService.java | 8 +- ...WritePlatformServiceJpaRepositoryImpl.java | 18 +- .../api/PermissionsApiResource.java | 10 +- .../api/RolesApiResource.java | 22 +- .../api/UsersApiResource.java | 22 +- .../handler/CreateRoleCommandHandler.java | 4 +- .../handler/CreateUserCommandHandler.java | 4 +- .../handler/DeleteUserCommandHandler.java | 6 +- ...MakerCheckerPermissionsCommandHandler.java | 4 +- .../handler/UpdateRoleCommandHandler.java | 6 +- .../UpdateRolePermissionsCommandHandler.java | 6 +- .../handler/UpdateUserCommandHandler.java | 8 +- .../service/AppUserWritePlatformService.java | 10 +- ...WritePlatformServiceJpaRepositoryImpl.java | 27 +- .../PermissionWritePlatformService.java | 4 +- ...WritePlatformServiceJpaRepositoryImpl.java | 7 +- .../service/RoleWritePlatformService.java | 8 +- ...WritePlatformServiceJpaRepositoryImpl.java | 15 +- 148 files changed, 2757 insertions(+), 2110 deletions(-) create mode 100644 mifosng-db/patches/patch-05-restructure-command-audit-table.sql create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResult.java create mode 100644 mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResultBuilder.java delete mode 100644 mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/EntityIdentifier.java diff --git a/mifosng-db/patches/patch-05-restructure-command-audit-table.sql b/mifosng-db/patches/patch-05-restructure-command-audit-table.sql new file mode 100644 index 000000000..efca633ec --- /dev/null +++ b/mifosng-db/patches/patch-05-restructure-command-audit-table.sql @@ -0,0 +1,28 @@ +DROP TABLE IF EXISTS `m_portfolio_command_source`; +CREATE TABLE `m_portfolio_command_source` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `action_name` varchar(50) NOT NULL, + `entity_name` varchar(50) NOT NULL, + `office_id` bigint(20) DEFAULT NULL, + `group_id` bigint(20) DEFAULT NULL, + `client_id` bigint(20) DEFAULT NULL, + `loan_id` bigint(20) DEFAULT NULL, + `api_get_url` varchar(100) NOT NULL, + `resource_id` bigint(20) DEFAULT NULL, + `command_as_json` text NOT NULL, + `maker_id` bigint(20) NOT NULL, + `made_on_date` datetime NOT NULL, + `checker_id` bigint(20) DEFAULT NULL, + `checked_on_date` datetime DEFAULT NULL, + `processing_result_enum` smallint(5) NOT NULL, + PRIMARY KEY (`id`), + KEY `FK_m_maker_m_appuser` (`maker_id`), + KEY `FK_m_checker_m_appuser` (`checker_id`), + KEY `action_name` (`action_name`), + KEY `entity_name` (`entity_name`,`resource_id`), + KEY `made_on_date` (`made_on_date`), + KEY `checked_on_date` (`checked_on_date`), + KEY `processing_result_enum` (`processing_result_enum`), + CONSTRAINT `FK_m_checker_m_appuser` FOREIGN KEY (`checker_id`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FK_m_maker_m_appuser` FOREIGN KEY (`maker_id`) REFERENCES `m_appuser` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/GLAccountsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/GLAccountsApiResource.java index 816d2f1d9..1c7926923 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/GLAccountsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/GLAccountsApiResource.java @@ -24,7 +24,7 @@ import org.mifosplatform.accounting.api.infrastructure.AccountingApiJsonSerializ import org.mifosplatform.accounting.service.GLAccountReadPlatformService; import org.mifosplatform.accounting.service.GLAccountWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; @@ -109,7 +109,7 @@ public class GLAccountsApiResource { final Long coaId = glAccountWritePlatformService.createGLAccount(command); - return this.apiJsonSerializerService.serializeEntityIdentifier(new EntityIdentifier(coaId)); + return this.apiJsonSerializerService.serializeEntityIdentifier(new CommandProcessingResult(coaId)); } @PUT @@ -122,7 +122,7 @@ public class GLAccountsApiResource { final Long coaId = glAccountWritePlatformService.updateGLAccount(glAccountId, command); - return this.apiJsonSerializerService.serializeEntityIdentifier(new EntityIdentifier(coaId)); + return this.apiJsonSerializerService.serializeEntityIdentifier(new CommandProcessingResult(coaId)); } @DELETE @@ -133,6 +133,6 @@ public class GLAccountsApiResource { this.glAccountWritePlatformService.deleteGLAccount(glAccountId); - return Response.ok(new EntityIdentifier(glAccountId)).build(); + return Response.ok(new CommandProcessingResult(glAccountId)).build(); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/GLClosuresApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/GLClosuresApiResource.java index b86930a13..82befc445 100755 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/GLClosuresApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/GLClosuresApiResource.java @@ -25,7 +25,7 @@ import org.mifosplatform.accounting.api.infrastructure.AccountingApiJsonSerializ import org.mifosplatform.accounting.service.GLClosureReadPlatformService; import org.mifosplatform.accounting.service.GLClosureWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.office.data.OfficeLookup; import org.mifosplatform.organisation.office.service.OfficeReadPlatformService; @@ -105,7 +105,7 @@ public class GLClosuresApiResource { final Long coaId = glClosureWritePlatformService.createGLClosure(command); - return this.apiJsonSerializerService.serializeEntityIdentifier(new EntityIdentifier(coaId)); + return this.apiJsonSerializerService.serializeEntityIdentifier(new CommandProcessingResult(coaId)); } @PUT @@ -118,7 +118,7 @@ public class GLClosuresApiResource { final Long coaId = glClosureWritePlatformService.updateGLClosure(glClosureId, command); - return this.apiJsonSerializerService.serializeEntityIdentifier(new EntityIdentifier(coaId)); + return this.apiJsonSerializerService.serializeEntityIdentifier(new CommandProcessingResult(coaId)); } @DELETE @@ -129,6 +129,6 @@ public class GLClosuresApiResource { this.glClosureWritePlatformService.deleteGLClosure(glClosureId); - return Response.ok(new EntityIdentifier(glClosureId)).build(); + return Response.ok(new CommandProcessingResult(glClosureId)).build(); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/infrastructure/AccountingApiJsonSerializerService.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/infrastructure/AccountingApiJsonSerializerService.java index 32726cd27..9089c60e2 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/infrastructure/AccountingApiJsonSerializerService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/infrastructure/AccountingApiJsonSerializerService.java @@ -7,12 +7,12 @@ import org.mifosplatform.accounting.api.data.GLAccountData; import org.mifosplatform.accounting.api.data.GLClosureData; import org.mifosplatform.accounting.api.data.GLJournalEntryData; import org.mifosplatform.accounting.api.data.JournalEntryIdentifier; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface AccountingApiJsonSerializerService { - String serializeEntityIdentifier(final EntityIdentifier identifier); + String serializeEntityIdentifier(final CommandProcessingResult identifier); String serializeJournalEntryIdentifier(final JournalEntryIdentifier identifier); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/infrastructure/impl/GoogleGsonAccountingApiJsonSerializerService.java b/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/infrastructure/impl/GoogleGsonAccountingApiJsonSerializerService.java index d537eab15..9b334b3a4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/infrastructure/impl/GoogleGsonAccountingApiJsonSerializerService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/accounting/api/infrastructure/impl/GoogleGsonAccountingApiJsonSerializerService.java @@ -11,7 +11,7 @@ import org.mifosplatform.accounting.api.data.GLJournalEntryData; import org.mifosplatform.accounting.api.data.JournalEntryIdentifier; import org.mifosplatform.accounting.api.infrastructure.AccountingApiJsonSerializerService; import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.GoogleGsonSerializerHelper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -46,7 +46,7 @@ public class GoogleGsonAccountingApiJsonSerializerService implements AccountingA } @Override - public String serializeEntityIdentifier(final EntityIdentifier identifier) { + public String serializeEntityIdentifier(final CommandProcessingResult identifier) { final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(DATA_PARAMETERS, false, DATA_PARAMETERS); return helper.serializedJsonFrom(gsonDeserializer, identifier); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/audit/data/AuditData.java b/mifosng-provider/src/main/java/org/mifosplatform/audit/data/AuditData.java index ff8ea0f52..9587345a4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/audit/data/AuditData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/audit/data/AuditData.java @@ -7,56 +7,40 @@ import org.joda.time.DateTime; */ public final class AuditData { - @SuppressWarnings("unused") - private final Long id; - @SuppressWarnings("unused") - private final String actionName; - @SuppressWarnings("unused") - private final String entityName; - @SuppressWarnings("unused") - private final String apiOperation; - @SuppressWarnings("unused") - private final String resource; - @SuppressWarnings("unused") - private final Long resourceId; - @SuppressWarnings("unused") - private final String subResource; - @SuppressWarnings("unused") - private final Long subResourceId; - @SuppressWarnings("unused") - private final String maker; - @SuppressWarnings("unused") - private final DateTime madeOnDate; - @SuppressWarnings("unused") - private final String checker; - @SuppressWarnings("unused") - private final DateTime checkedOnDate; - @SuppressWarnings("unused") - private final String processingResult; - @SuppressWarnings("unused") - private final String commandAsJson; + @SuppressWarnings("unused") + private final Long id; + @SuppressWarnings("unused") + private final String actionName; + @SuppressWarnings("unused") + private final String entityName; + @SuppressWarnings("unused") + private final Long resourceId; + @SuppressWarnings("unused") + private final String maker; + @SuppressWarnings("unused") + private final DateTime madeOnDate; + @SuppressWarnings("unused") + private final String checker; + @SuppressWarnings("unused") + private final DateTime checkedOnDate; + @SuppressWarnings("unused") + private final String processingResult; + @SuppressWarnings("unused") + private final String commandAsJson; - public AuditData(final Long id, final String actionName, - final String entityName, final String apiOperation, - final String resource, final Long resourceId, - final String subResource, final Long subResourceId, - final String maker, final DateTime madeOnDate, - final String checker, final DateTime checkedOnDate, - final String processingResult, final String commandAsJson) { + public AuditData(final Long id, final String actionName, final String entityName, final Long resourceId, final String maker, + final DateTime madeOnDate, final String checker, final DateTime checkedOnDate, final String processingResult, + final String commandAsJson) { - this.id = id; - this.actionName = actionName; - this.entityName = entityName; - this.apiOperation = apiOperation; - this.resource = resource; - this.resourceId = resourceId; - this.subResource = subResource; - this.subResourceId = subResourceId; - this.maker = maker; - this.madeOnDate = madeOnDate; - this.checker = checker; - this.checkedOnDate = checkedOnDate; - this.commandAsJson = commandAsJson; - this.processingResult = processingResult; - } + this.id = id; + this.actionName = actionName; + this.entityName = entityName; + this.resourceId = resourceId; + this.maker = maker; + this.madeOnDate = madeOnDate; + this.checker = checker; + this.checkedOnDate = checkedOnDate; + this.commandAsJson = commandAsJson; + this.processingResult = processingResult; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/audit/service/AuditReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/audit/service/AuditReadPlatformServiceImpl.java index 94d9d6473..ff1dc256d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/audit/service/AuditReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/audit/service/AuditReadPlatformServiceImpl.java @@ -25,171 +25,142 @@ import org.springframework.stereotype.Service; @Service public class AuditReadPlatformServiceImpl implements AuditReadPlatformService { - private final static Logger logger = LoggerFactory - .getLogger(AuditReadPlatformServiceImpl.class); - private final JdbcTemplate jdbcTemplate; - private final PlatformSecurityContext context; - private final AppUserReadPlatformService appUserReadPlatformService; + private final static Logger logger = LoggerFactory.getLogger(AuditReadPlatformServiceImpl.class); + private final JdbcTemplate jdbcTemplate; + private final PlatformSecurityContext context; + private final AppUserReadPlatformService appUserReadPlatformService; - @Autowired - public AuditReadPlatformServiceImpl(final PlatformSecurityContext context, - final TenantAwareRoutingDataSource dataSource, - final AppUserReadPlatformService appUserReadPlatformService) { - this.context = context; - this.jdbcTemplate = new JdbcTemplate(dataSource); - this.appUserReadPlatformService = appUserReadPlatformService; - } + @Autowired + public AuditReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource, + final AppUserReadPlatformService appUserReadPlatformService) { + this.context = context; + this.jdbcTemplate = new JdbcTemplate(dataSource); + this.appUserReadPlatformService = appUserReadPlatformService; + } - private static final class AuditMapper implements RowMapper { + private static final class AuditMapper implements RowMapper { - public String schema(boolean includeJson) { + public String schema(boolean includeJson) { - String commandAsJsonString = ""; - if (includeJson) - commandAsJsonString = ", aud.command_as_json as commandAsJson "; + String commandAsJsonString = ""; + if (includeJson) commandAsJsonString = ", aud.command_as_json as commandAsJson "; - return " aud.id as id, aud.action_name as actionName, aud.entity_name as entityName, aud.api_operation as apiOperation, " - + " aud.api_resource as resource, aud.resource_id as resourceId, aud.api_subresource as subResource, aud.subresource_id as subResourceId," - + " mk.username as maker, aud.made_on_date as madeOnDate, ck.username as checker, aud.checked_on_date as checkedOnDate, ev.enum_message_property as processingResult " - + commandAsJsonString - + " from m_portfolio_command_source aud " - + " left join m_appuser mk on mk.id = aud.maker_id" - + " left join m_appuser ck on ck.id = aud.checker_id" - + " left join r_enum_value ev on ev.enum_name = 'processing_result_enum' and ev.enum_id = aud.processing_result_enum"; - } + return " aud.id as id, aud.action_name as actionName, aud.entity_name as entityName," + " aud.resource_id as resourceId," + + " mk.username as maker, aud.made_on_date as madeOnDate, " + + "ck.username as checker, aud.checked_on_date as checkedOnDate, ev.enum_message_property as processingResult " + + commandAsJsonString + " from m_portfolio_command_source aud " + " left join m_appuser mk on mk.id = aud.maker_id" + + " left join m_appuser ck on ck.id = aud.checker_id" + + " left join r_enum_value ev on ev.enum_name = 'processing_result_enum' and ev.enum_id = aud.processing_result_enum"; + } - @Override - public AuditData mapRow(final ResultSet rs, - @SuppressWarnings("unused") final int rowNum) - throws SQLException { + @Override + public AuditData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { - final Long id = rs.getLong("id"); - final String actionName = rs.getString("actionName"); - final String entityName = rs.getString("entityName"); - final String apiOperation = rs.getString("apiOperation"); - final String resource = rs.getString("resource"); - final Long resourceId = JdbcSupport.getLong(rs, "resourceId"); - final String subResource = rs.getString("subResource"); - final Long subResourceId = JdbcSupport.getLong(rs, "subResourceId"); - final String maker = rs.getString("maker"); - final DateTime madeOnDate = JdbcSupport.getDateTime(rs, - "madeOnDate"); - final String checker = rs.getString("checker"); - final DateTime checkedOnDate = JdbcSupport.getDateTime(rs, - "checkedOnDate"); - final String processingResult = rs.getString("processingResult"); - String commandAsJson; - // commandAsJson might not be on the select list of columns - try { - commandAsJson = rs.getString("commandAsJson"); - } catch (SQLException e) { - commandAsJson = null; - } - return new AuditData(id, actionName, entityName, apiOperation, - resource, resourceId, subResource, subResourceId, maker, - madeOnDate, checker, checkedOnDate, processingResult, - commandAsJson); - } - } + final Long id = rs.getLong("id"); + final String actionName = rs.getString("actionName"); + final String entityName = rs.getString("entityName"); + final Long resourceId = JdbcSupport.getLong(rs, "resourceId"); + final String maker = rs.getString("maker"); + final DateTime madeOnDate = JdbcSupport.getDateTime(rs, "madeOnDate"); + final String checker = rs.getString("checker"); + final DateTime checkedOnDate = JdbcSupport.getDateTime(rs, "checkedOnDate"); + final String processingResult = rs.getString("processingResult"); + String commandAsJson; + // commandAsJson might not be on the select list of columns + try { + commandAsJson = rs.getString("commandAsJson"); + } catch (SQLException e) { + commandAsJson = null; + } + return new AuditData(id, actionName, entityName, resourceId, maker, madeOnDate, checker, checkedOnDate, processingResult, + commandAsJson); + } + } - @Override - public Collection retrieveAuditEntries(String extraCriteria, - boolean includeJson) { - context.authenticatedUser(); + @Override + public Collection retrieveAuditEntries(String extraCriteria, boolean includeJson) { + context.authenticatedUser(); - final AuditMapper rm = new AuditMapper(); + final AuditMapper rm = new AuditMapper(); - String sql = "select " + rm.schema(includeJson); - if (StringUtils.isNotBlank(extraCriteria)) - sql += " where (" + extraCriteria + ")"; - sql += " order by aud.id DESC"; - logger.info("sql: " + sql); - return this.jdbcTemplate.query(sql, rm, new Object[] {}); - } + String sql = "select " + rm.schema(includeJson); + if (StringUtils.isNotBlank(extraCriteria)) sql += " where (" + extraCriteria + ")"; + sql += " order by aud.id DESC"; + logger.info("sql: " + sql); + return this.jdbcTemplate.query(sql, rm, new Object[] {}); + } - @Override - public AuditData retrieveAuditEntry(Long auditId) { - context.authenticatedUser(); + @Override + public AuditData retrieveAuditEntry(Long auditId) { + context.authenticatedUser(); - final AuditMapper rm = new AuditMapper(); + final AuditMapper rm = new AuditMapper(); - String sql = "select " + rm.schema(true); - sql += " where aud.id = " + auditId; + String sql = "select " + rm.schema(true); + sql += " where aud.id = " + auditId; - return this.jdbcTemplate.queryForObject(sql, rm, new Object[] {}); - } + return this.jdbcTemplate.queryForObject(sql, rm, new Object[] {}); + } - @Override - public AuditSearchData retrieveSearchTemplate() { - Collection appUsers = appUserReadPlatformService - .retrieveSearchTemplate(); + @Override + public AuditSearchData retrieveSearchTemplate() { + Collection appUsers = appUserReadPlatformService.retrieveSearchTemplate(); - ActionNamesMapper mapper = new ActionNamesMapper(); - List actionNames = this.jdbcTemplate.query(mapper.schema(), - mapper, new Object[] {}); + ActionNamesMapper mapper = new ActionNamesMapper(); + List actionNames = this.jdbcTemplate.query(mapper.schema(), mapper, new Object[] {}); - EntityNamesMapper mapper2 = new EntityNamesMapper(); - List entityNames = this.jdbcTemplate.query(mapper2.schema(), - mapper2, new Object[] {}); + EntityNamesMapper mapper2 = new EntityNamesMapper(); + List entityNames = this.jdbcTemplate.query(mapper2.schema(), mapper2, new Object[] {}); - ProcessingResultsMapper mapper3 = new ProcessingResultsMapper(); - Collection processingResults = this.jdbcTemplate - .query(mapper3.schema(), mapper3, new Object[] {}); + ProcessingResultsMapper mapper3 = new ProcessingResultsMapper(); + Collection processingResults = this.jdbcTemplate.query(mapper3.schema(), mapper3, new Object[] {}); - return new AuditSearchData(appUsers, actionNames, entityNames, - processingResults); - } + return new AuditSearchData(appUsers, actionNames, entityNames, processingResults); + } - private static final class ActionNamesMapper implements RowMapper { + private static final class ActionNamesMapper implements RowMapper { - @Override - public String mapRow(final ResultSet rs, - @SuppressWarnings("unused") final int rowNum) - throws SQLException { + @Override + public String mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { - return rs.getString("actionName"); - } + return rs.getString("actionName"); + } - public String schema() { + public String schema() { - return " SELECT distinct(action_name) as actionName FROM m_permission " - + " where action_name is not null and action_name <> 'READ' " - + " order by if(action_name in ('CREATE', 'DELETE', 'UPDATE'), action_name, 'ZZZ'), action_name"; - } + return " SELECT distinct(action_name) as actionName FROM m_permission " + + " where action_name is not null and action_name <> 'READ' " + + " order by if(action_name in ('CREATE', 'DELETE', 'UPDATE'), action_name, 'ZZZ'), action_name"; + } - } + } - private static final class EntityNamesMapper implements RowMapper { + private static final class EntityNamesMapper implements RowMapper { - @Override - public String mapRow(final ResultSet rs, - @SuppressWarnings("unused") final int rowNum) - throws SQLException { - return rs.getString("entityName"); - } + @Override + public String mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + return rs.getString("entityName"); + } - public String schema() { - return " select distinct(entity_name) as entityName from m_permission where action_name is not null and action_name <> 'READ' " - + " order by if(grouping = 'datatable', 'ZZZ', entity_name), entity_name"; - } - } + public String schema() { + return " select distinct(entity_name) as entityName from m_permission where action_name is not null and action_name <> 'READ' " + + " order by if(grouping = 'datatable', 'ZZZ', entity_name), entity_name"; + } + } - private static final class ProcessingResultsMapper implements - RowMapper { + private static final class ProcessingResultsMapper implements RowMapper { - @Override - public ProcessingResultLookup mapRow(final ResultSet rs, - @SuppressWarnings("unused") final int rowNum) - throws SQLException { - Long id = JdbcSupport.getLong(rs, "id"); - String processingResult = rs.getString("processingResult"); + @Override + public ProcessingResultLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { + Long id = JdbcSupport.getLong(rs, "id"); + String processingResult = rs.getString("processingResult"); - return new ProcessingResultLookup(id, processingResult); - } + return new ProcessingResultLookup(id, processingResult); + } - public String schema() { - return " select enum_id as id, enum_message_property as processingResult from r_enum_value where enum_name = 'processing_result_enum' " - + " order by enum_id"; - } - } + public String schema() { + return " select enum_id as id, enum_message_property as processingResult from r_enum_value where enum_name = 'processing_result_enum' " + + " order by enum_id"; + } + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/api/CommandsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/api/CommandsApiResource.java index 091368d1a..bdff8740f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/api/CommandsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/api/CommandsApiResource.java @@ -22,7 +22,7 @@ import org.mifosplatform.commands.data.CommandSourceData; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.commands.service.PortfolioCommandsReadPlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; @@ -76,7 +76,7 @@ public class CommandsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String approveMakerCheckerEntry(@PathParam("commandId") final Long commandId, @QueryParam("command") final String commandParam) { - EntityIdentifier result = null; + CommandProcessingResult result = null; if (is(commandParam, "approve")) { result = this.writePlatformService.approveEntry(commandId); } else { @@ -98,6 +98,6 @@ public class CommandsApiResource { final Long id = this.writePlatformService.deleteEntry(commandId); - return this.toApiJsonSerializer.serialize(EntityIdentifier.commandOnlyResult(id)); + return this.toApiJsonSerializer.serialize(CommandProcessingResult.commandOnlyResult(id)); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandSource.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandSource.java index 5c484b165..6dc520e32 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandSource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/domain/CommandSource.java @@ -25,22 +25,30 @@ public class CommandSource extends AbstractPersistable { @Column(name = "entity_name", nullable = true, length = 100) private String entityName; + + @SuppressWarnings("unused") + @Column(name = "office_id") + private Long officeId; - @Column(name = "api_operation", length = 30) - private String apiOperation; - - @Column(name = "api_resource", length = 100) - private String resource; + @SuppressWarnings("unused") + @Column(name = "group_id") + private Long groupId; + + @SuppressWarnings("unused") + @Column(name = "client_id") + private Long clientId; + + @SuppressWarnings("unused") + @Column(name = "loan_id") + private Long loanId; + + @SuppressWarnings("unused") + @Column(name = "api_get_url", length = 100) + private String resourceGetUrl; @Column(name = "resource_id") private Long resourceId; - @Column(name = "api_subresource", length = 100) - private String subResource; - - @Column(name = "subresource_id") - private Long subResourceId; - @Column(name = "command_as_json", length = 1000) private String commandAsJson; @@ -69,24 +77,22 @@ public class CommandSource extends AbstractPersistable { private Integer processingResult; public static CommandSource fullEntryFrom(final CommandWrapper wrapper, final JsonCommand command, final AppUser maker) { - return new CommandSource(wrapper.actionName(), wrapper.entityName(), wrapper.operation(), wrapper.resourceName(), command.resourceId(), - wrapper.subResourceName(), command.subResourceId(), command.json(), maker, DateTime.now()); + return new CommandSource(wrapper.actionName(), wrapper.entityName(), wrapper.getHref(), command.entityId(), command.json(), maker, DateTime.now()); } protected CommandSource() { // } - private CommandSource(final String actionName, final String entityName, final String apiOperation, final String resource, final Long resourceId, - final String subResource, final Long subResourceId, final String commandSerializedAsJson, final AppUser maker, + private CommandSource( + final String actionName, final String entityName, final String href, + final Long resourceId, + final String commandSerializedAsJson, final AppUser maker, final DateTime madeOnDateTime) { this.actionName = actionName; this.entityName = entityName; - this.apiOperation = StringUtils.defaultIfEmpty(apiOperation, null); - this.resource = StringUtils.defaultIfEmpty(resource, null); + this.resourceGetUrl = href; this.resourceId = resourceId; - this.subResource = StringUtils.defaultIfEmpty(subResource, null); - this.subResourceId = subResourceId; this.commandAsJson = commandSerializedAsJson; this.maker = maker; this.madeOnDate = madeOnDateTime.toDate(); @@ -103,10 +109,6 @@ public class CommandSource extends AbstractPersistable { this.resourceId = resourceId; } - public void updateSubResourceId(final Long subResourceId) { - this.subResourceId = subResourceId; - } - public void updateJsonTo(final String json) { this.commandAsJson = json; } @@ -123,18 +125,6 @@ public class CommandSource extends AbstractPersistable { return this.commandAsJson; } - public String commandName() { - return this.apiOperation + '-' + this.resource; - } - - public String resourceName() { - return this.resource; - } - - public String operation() { - return this.apiOperation; - } - public String getActionName() { return this.actionName; } @@ -147,23 +137,18 @@ public class CommandSource extends AbstractPersistable { return this.actionName + "_" + this.entityName; } - public String getResource() { - return this.resource; - } - public Long getResourceId() { return this.resourceId; } - public String getSubResource() { - return this.subResource; - } - - public Long getSubResourceId() { - return this.subResourceId; - } - public void markAsAwaitingApproval() { this.processingResult = CommandProcessingResultType.AWAITING_APPROVAL.getValue(); } + + public void updateForAudit(final Long officeId, final Long groupId, final Long clientId, final Long loanId) { + this.officeId = officeId; + this.groupId = groupId; + this.clientId = clientId; + this.loanId = loanId; + } } \ 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 861faff74..0d319f91a 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 @@ -3,43 +3,61 @@ package org.mifosplatform.commands.domain; public class CommandWrapper { private final Long commandId; + @SuppressWarnings("unused") + private final Long officeId; + private final Long groupId; + private final Long clientId; + private final Long loanId; private final String actionName; private final String entityName; - private final String apiOperation; - private final String resource; - private final Long resourceId; - private final String subResource; - private final Long subResourceId; + private final String taskPermissionName; + private final Long entityId; + private final String href; + private final String json; + private final Long apptableId; + private final Long datatableId; - public static CommandWrapper wrap(final String actionName, final String enityName, final String apiOperation, final String resource, - final Long resourceId) { - return new CommandWrapper(null, actionName, enityName, apiOperation, resource, resourceId, null, null); - } - - public static CommandWrapper wrap(final String actionName, final String enityName, final String apiOperation, final String resource, - final Long resourceId, final String subResource, final Long subRescourceId) { - return new CommandWrapper(null, actionName, enityName, apiOperation, resource, resourceId, subResource, subRescourceId); + public static CommandWrapper wrap(final String actionName, final String enityName, final Long resourceId) { + return new CommandWrapper(null, actionName, enityName, resourceId); } public static CommandWrapper fromExistingCommand(final Long commandId, final String actionName, final String enityName, - final String apiOperation, final String resource, final Long resourceId, final String subResource, final Long subRescourceId) { - return new CommandWrapper(commandId, actionName, enityName, apiOperation, resource, resourceId, subResource, subRescourceId); + final Long resourceId) { + return new CommandWrapper(commandId, actionName, enityName, resourceId); } - private CommandWrapper(final Long commandId, final String actionName, final String enityName, final String apiOperation, - final String resource, final Long resourceId, final String subResource, final Long subResourceId) { + private CommandWrapper(final Long commandId, final String actionName, final String enityName, final Long resourceId) { this.commandId = commandId; + this.officeId = null; + this.groupId = null; + this.clientId = null; + this.loanId = null; this.actionName = actionName; this.entityName = enityName; - this.apiOperation = apiOperation; - this.resource = resource; - this.resourceId = resourceId; - this.subResource = subResource; - this.subResourceId = subResourceId; + this.taskPermissionName = actionName + "_" + entityName; + this.entityId = resourceId; + this.apptableId = null; + this.datatableId = null; + this.href = null; + this.json = null; } - public String commandName() { - return this.apiOperation + '-' + this.resource; + public CommandWrapper(final Long officeId, final Long groupId, final Long clientId, final Long loanId, final String actionName, + final String entityName, final Long entityId, final Long apptableId, final Long datatableId, final String href, + final String json) { + this.commandId = null; + this.officeId = officeId; + this.groupId = groupId; + this.clientId = clientId; + this.loanId = loanId; + this.actionName = actionName; + this.entityName = entityName; + this.taskPermissionName = actionName + "_" + entityName; + this.entityId = entityId; + this.apptableId = apptableId; + this.datatableId = datatableId; + this.href = href; + this.json = json; } public Long commandId() { @@ -55,117 +73,141 @@ public class CommandWrapper { } public Long resourceId() { - return this.resourceId; - } - - public String resourceName() { - return this.resource; - } - - public Long subResourceId() { - return this.subResourceId; - } - - public String subResourceName() { - return this.subResource; + return this.entityId; } public String taskPermissionName() { return this.actionName + "_" + this.entityName; } - public String operation() { - return this.apiOperation; + public boolean isCreate() { + return this.actionName.equalsIgnoreCase("CREATE"); } - public boolean isCreate() { - return this.apiOperation.equalsIgnoreCase("CREATE"); + public String getTaskPermissionName() { + return this.taskPermissionName; + } + + public String getHref() { + return this.href; + } + + public String getJson() { + return this.json; + } + + public String getEntityName() { + return this.entityName; + } + + public Long getEntityId() { + return this.entityId; + } + + public Long getGroupId() { + return this.groupId; + } + + public Long getClientId() { + return this.clientId; + } + + public Long getLoanId() { + return this.loanId; + } + + public Long getApptableId() { + return this.apptableId; + } + + public Long getDatatableId() { + return this.datatableId; } public boolean isUpdate() { // permissions resource has special update which involves no resource. return (isPermissionResource() && isUpdateOperation()) || (isCurrencyResource() && isUpdateOperation()) - || (isUpdateOperation() && this.resourceId != null); + || (isUpdateOperation() && this.entityId != null); } private boolean isUpdateOperation() { - return this.apiOperation.equalsIgnoreCase("UPDATE"); + return this.actionName.equalsIgnoreCase("UPDATE"); } public boolean isDelete() { - return this.apiOperation.equalsIgnoreCase("DELETE") && this.resourceId != null; + return isDeleteOperation() && this.entityId != null; + } + + private boolean isDeleteOperation() { + return this.actionName.equalsIgnoreCase("DELETE"); } public boolean isUpdateRolePermissions() { - return this.apiOperation.equalsIgnoreCase("UPDATEPERMISSIONS") && this.resourceId != null; + return this.actionName.equalsIgnoreCase("PERMISSIONS") && this.entityId != null; } public boolean isPermissionResource() { - return this.resource.equalsIgnoreCase("PERMISSIONS"); + return this.entityName.equalsIgnoreCase("PERMISSION"); } public boolean isRoleResource() { - return this.resource.equalsIgnoreCase("ROLES"); + return this.entityName.equalsIgnoreCase("ROLE"); } public boolean isUserResource() { - return this.resource.equalsIgnoreCase("USERS"); + return this.entityName.equalsIgnoreCase("USER"); } public boolean isCurrencyResource() { - return this.resource.equalsIgnoreCase("CURRENCIES"); + return this.entityName.equalsIgnoreCase("CURRENCY"); } public boolean isCodeResource() { - return this.resource.equalsIgnoreCase("CODES"); + return this.entityName.equalsIgnoreCase("CODE"); } public boolean isStaffResource() { - return this.resource.equalsIgnoreCase("STAFF"); + return this.entityName.equalsIgnoreCase("STAFF"); } public boolean isFundResource() { - return this.resource.equalsIgnoreCase("FUNDS"); + return this.entityName.equalsIgnoreCase("FUND"); } public boolean isOfficeResource() { - return this.resource.equalsIgnoreCase("OFFICES"); + return this.entityName.equalsIgnoreCase("OFFICE"); } public boolean isOfficeTransactionResource() { - return this.resource.equalsIgnoreCase("OFFICETRANSACTIONS"); + return this.entityName.equalsIgnoreCase("OFFICETRANSACTION"); } public boolean isChargeDefinitionResource() { - return this.resource.equalsIgnoreCase("CHARGES"); + return this.entityName.equalsIgnoreCase("CHARGE"); } public boolean isLoanProductResource() { - return this.resource.equalsIgnoreCase("LOANPRODUCTS"); + return this.entityName.equalsIgnoreCase("LOANPRODUCT"); } public boolean isClientResource() { - return this.resource.equalsIgnoreCase("CLIENTS"); + return this.entityName.equalsIgnoreCase("CLIENT"); } public boolean isClientIdentifierResource() { - return isClientResource() && isIdentifiersSubResource(); + return this.entityName.equals("CLIENTIDENTIFIER"); } public boolean isClientNoteResource() { - return isClientResource() && isNotesSubResource(); - } - - public boolean isNotesSubResource() { - return "NOTES".equalsIgnoreCase(this.subResource); - } - - public boolean isIdentifiersSubResource() { - return "IDENTIFIERS".equalsIgnoreCase(this.subResource); + return this.entityName.equals("CLIENTNOTE"); } public boolean isLoanResource() { - return this.resource.equalsIgnoreCase("LOANS"); + return this.entityName.equalsIgnoreCase("LOAN"); + } + + public boolean isLoanChargeResource() { + return this.entityName.equalsIgnoreCase("LOANCHARGE"); } public boolean isApproveLoanApplication() { @@ -221,9 +263,9 @@ public class CommandWrapper { } public boolean isDeleteLoanCharge() { - return this.actionName.equalsIgnoreCase("DELETE") && this.entityName.equalsIgnoreCase("LOANCHARGE"); + return isDeleteOperation() && this.entityName.equalsIgnoreCase("LOANCHARGE"); } - + public boolean isUpdateLoanCharge() { return this.actionName.equalsIgnoreCase("UPDATE") && this.entityName.equalsIgnoreCase("LOANCHARGE"); } @@ -240,15 +282,27 @@ public class CommandWrapper { return this.actionName.equalsIgnoreCase("BULKREASSIGN") && this.entityName.equalsIgnoreCase("LOAN"); } - public boolean isDatatableResource() { - return this.resource.toUpperCase().startsWith("DATATABLES"); - } + public boolean isDatatableResource() { + return this.apptableId != null; + } - public boolean isDeleteMultiple() { - return isDatatableResource() && this.apiOperation.equalsIgnoreCase("DELETE_MULTIPLE"); - } + public boolean isDeleteOneToOne() { + return isDatatableResource() && isDeleteOperation() && this.apptableId != null; + } + + public boolean isDeleteMultiple() { + return isDatatableResource() && isDeleteOperation() && this.apptableId != null && this.datatableId != null; + } - public boolean isUpdateMultiple() { - return isDatatableResource() && this.apiOperation.equalsIgnoreCase("UPDATE_MULTIPLE"); - } + public boolean isUpdateOneToOne() { + return isDatatableResource() && isUpdateOperation() && this.apptableId != null; + } + + public boolean isUpdateMultiple() { + return isDatatableResource() && isUpdateOperation() && this.apptableId != null && this.datatableId != null; + } + + public String commandName() { + return this.actionName + "_" + this.entityName; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/NewCommandSourceHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/NewCommandSourceHandler.java index c9dd0850e..9b6640371 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/NewCommandSourceHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/NewCommandSourceHandler.java @@ -1,9 +1,9 @@ package org.mifosplatform.commands.handler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface NewCommandSourceHandler { - EntityIdentifier processCommand(JsonCommand command); + CommandProcessingResult processCommand(JsonCommand command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandProcessingService.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandProcessingService.java index f13e6fc19..1a811c235 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandProcessingService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandProcessingService.java @@ -2,12 +2,12 @@ package org.mifosplatform.commands.service; import org.mifosplatform.commands.domain.CommandWrapper; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface CommandProcessingService { - EntityIdentifier processAndLogCommand(CommandWrapper wrapper, JsonCommand command, boolean isApprovedByChecker); + CommandProcessingResult processAndLogCommand(CommandWrapper wrapper, JsonCommand command, boolean isApprovedByChecker); - EntityIdentifier logCommand(CommandWrapper wrapper, JsonCommand command); + CommandProcessingResult logCommand(CommandWrapper wrapper, JsonCommand command); } 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 new file mode 100644 index 000000000..8d9d9db1c --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java @@ -0,0 +1,385 @@ +package org.mifosplatform.commands.service; + +import org.mifosplatform.commands.domain.CommandWrapper; + +public class CommandWrapperBuilder { + + private Long officeId; + private Long groupId; + private Long clientId; + private Long loanId; + private String actionName; + private String entityName; + private Long entityId; + private String href; + private String json; + private Long apptableId; + private Long datatableId; + + public CommandWrapper build() { + return new CommandWrapper(this.officeId, this.groupId, this.clientId, this.loanId, this.actionName, this.entityName, this.entityId, this.apptableId, this.datatableId, + this.href, this.json); + } + + public CommandWrapperBuilder withEntityId(final Long withId) { + this.entityId = withId; + return this; + } + + public CommandWrapperBuilder withLoanId(final Long withLoanId) { + this.loanId = withLoanId; + return this; + } + + public CommandWrapperBuilder withClientId(final Long withClientId) { + this.clientId = withClientId; + return this; + } + + public CommandWrapperBuilder withJson(final String withJson) { + this.json = withJson; + return this; + } + + public CommandWrapperBuilder withUrl(final String withUrl) { + this.href = withUrl; + return this; + } + + public CommandWrapperBuilder updatePermissions() { + this.actionName = "UPDATE"; + this.entityName = "PERMISSION"; + return this; + } + + public CommandWrapperBuilder createRole() { + this.actionName = "CREATE"; + this.entityName = "ROLE"; + return this; + } + + public CommandWrapperBuilder updateRole() { + this.actionName = "UPDATE"; + this.entityName = "ROLE"; + return this; + } + + public CommandWrapperBuilder updateRolePermissions() { + this.actionName = "PERMISSIONS"; + this.entityName = "ROLE"; + return this; + } + + public CommandWrapperBuilder createUser() { + this.actionName = "CREATE"; + this.entityName = "USER"; + return this; + } + + public CommandWrapperBuilder updateUser() { + this.actionName = "UPDATE"; + this.entityName = "USER"; + return this; + } + + public CommandWrapperBuilder deleteUser() { + this.actionName = "DELETE"; + this.entityName = "USER"; + return this; + } + + public CommandWrapperBuilder createOffice() { + this.actionName = "CREATE"; + this.entityName = "OFFICE"; + return this; + } + + public CommandWrapperBuilder updateOffice() { + this.actionName = "UPDATE"; + this.entityName = "OFFICE"; + return this; + } + + public CommandWrapperBuilder createOfficeTransaction() { + this.actionName = "CREATE"; + this.entityName = "OFFICETRANSACTION"; + return this; + } + + public CommandWrapperBuilder createStaff() { + this.actionName = "CREATE"; + this.entityName = "STAFF"; + return this; + } + + public CommandWrapperBuilder updateStaff() { + this.actionName = "UPDATE"; + this.entityName = "STAFF"; + return this; + } + + public CommandWrapperBuilder createFund() { + this.actionName = "CREATE"; + this.entityName = "FUND"; + return this; + } + + public CommandWrapperBuilder updateFund() { + this.actionName = "UPDATE"; + this.entityName = "FUND"; + return this; + } + + public CommandWrapperBuilder updateCurrencies() { + this.actionName = "UPDATE"; + this.entityName = "CURRENCY"; + return this; + } + + public CommandWrapperBuilder createCode() { + this.actionName = "CREATE"; + this.entityName = "CODE"; + return this; + } + + public CommandWrapperBuilder updateCode() { + this.actionName = "UPDATE"; + this.entityName = "CODE"; + return this; + } + + public CommandWrapperBuilder deleteCode() { + this.actionName = "DELETE"; + this.entityName = "CODE"; + return this; + } + + public CommandWrapperBuilder createCharge() { + this.actionName = "CREATE"; + this.entityName = "CHARGE"; + return this; + } + + public CommandWrapperBuilder updateCharge() { + this.actionName = "UPDATE"; + this.entityName = "CHARGE"; + return this; + } + + public CommandWrapperBuilder deleteCharge() { + this.actionName = "DELETE"; + this.entityName = "CHARGE"; + return this; + } + + public CommandWrapperBuilder createLoanProduct() { + this.actionName = "CREATE"; + this.entityName = "LOANPRODUCT"; + return this; + } + + public CommandWrapperBuilder updateLoanProduct() { + this.actionName = "UPDATE"; + this.entityName = "LOANPRODUCT"; + return this; + } + + public CommandWrapperBuilder createClientIdentifier() { + this.actionName = "CREATE"; + this.entityName = "CLIENTIDENTIFIER"; + return this; + } + + public CommandWrapperBuilder updateClientIdentifier() { + this.actionName = "UPDATE"; + this.entityName = "CLIENTIDENTIFIER"; + return this; + } + + public CommandWrapperBuilder deleteClientIdentifier() { + this.actionName = "DELETE"; + this.entityName = "CLIENTIDENTIFIER"; + return this; + } + + public CommandWrapperBuilder createClientNote() { + this.actionName = "CREATE"; + this.entityName = "CLIENTNOTE"; + return this; + } + + public CommandWrapperBuilder updateClientNote() { + this.actionName = "UPDATE"; + this.entityName = "CLIENTNOTE"; + return this; + } + + public CommandWrapperBuilder createClient() { + this.actionName = "CREATE"; + this.entityName = "CLIENT"; + return this; + } + + public CommandWrapperBuilder updateClient() { + this.actionName = "UPDATE"; + this.entityName = "CLIENT"; + return this; + } + + public CommandWrapperBuilder deleteClient() { + this.actionName = "DELETE"; + this.entityName = "CLIENT"; + return this; + } + + public CommandWrapperBuilder createDatatable(final String datatable, final Long apptableId, final Long datatableId) { + this.apptableId = apptableId; + this.datatableId = datatableId; + this.actionName = "CREATE"; + this.entityName = datatable; + return this; + } + + public CommandWrapperBuilder updateDatatable(final String datatable, final Long apptableId, final Long datatableId) { + this.apptableId = apptableId; + this.datatableId = datatableId; + this.actionName = "UPDATE"; + this.entityName = datatable; + return this; + } + + public CommandWrapperBuilder deleteDatatable(final String datatable, final Long apptableId, final Long datatableId) { + this.apptableId = apptableId; + this.datatableId = datatableId; + this.actionName = "DELETE"; + this.entityName = datatable; + return this; + } + + public CommandWrapperBuilder createLoanCharge() { + this.actionName = "CREATE"; + this.entityName = "LOANCHARGE"; + return this; + } + + public CommandWrapperBuilder updateLoanCharge() { + this.actionName = "UPDATE"; + this.entityName = "LOANCHARGE"; + return this; + } + + public CommandWrapperBuilder waiveLoanCharge() { + this.actionName = "WAIVE"; + this.entityName = "LOANCHARGE"; + return this; + + } + + public CommandWrapperBuilder deleteLoanCharge() { + this.actionName = "DELETE"; + this.entityName = "LOANCHARGE"; + return this; + } + + public CommandWrapperBuilder loanRepaymentTransaction() { + this.actionName = "REPAYMENT"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder waiveInterestPortionTransaction() { + this.actionName = "WAIVEINTERESTPORTION"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder writeOffLoanTransaction() { + this.actionName = "WRITEOFF"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder closeLoanAsRescheduledTransaction() { + this.actionName = "CLOSEASRESCHEDULED"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder closeLoanTransaction() { + this.actionName = "CLOSE"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder adjustTransaction() { + this.actionName = "ADJUST"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder createLoanApplication() { + this.actionName = "CREATE"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder updateLoanApplication() { + this.actionName = "UPDATE"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder deleteLoanApplication() { + this.actionName = "DELETE"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder rejectLoanApplication() { + this.actionName = "REJECT"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder withdrawLoanApplication() { + this.actionName = "WITHDRAW"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder approveLoanApplication() { + this.actionName = "APPROVE"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder disburseLoanApplication() { + this.actionName = "DISBURSE"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder undoLoanApplicationApproval() { + this.actionName = "APPROVALUNDO"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder undoLoanApplicationDisbursal() { + this.actionName = "DISBURSALUNDO"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder assignLoanOfficer() { + this.actionName = "UPDATELOANOFFICER"; + this.entityName = "LOAN"; + return this; + } + + public CommandWrapperBuilder assignLoanOfficersInBulk() { + this.actionName = "BULKREASSIGN"; + this.entityName = "LOAN"; + return this; + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandSourceWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandSourceWritePlatformService.java index 982e8ffe7..353e9358f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandSourceWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandSourceWritePlatformService.java @@ -1,15 +1,13 @@ package org.mifosplatform.commands.service; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface PortfolioCommandSourceWritePlatformService { - EntityIdentifier logCommandSource(String actionName, String entityName, String apiOperation, String resource, Long resourceId, String subResource, - Long subRescourceId, String json); + CommandProcessingResult logCommandSource(CommandWrapper commandRequest); - EntityIdentifier logCommandSource(String actionName, String entityName, String apiOperation, String resource, Long resourceId, String json); - - EntityIdentifier approveEntry(Long id); + CommandProcessingResult approveEntry(Long id); Long deleteEntry(Long makerCheckerId); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandSourceWritePlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandSourceWritePlatformServiceImpl.java index d7b00e97e..d3c686e56 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandSourceWritePlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandSourceWritePlatformServiceImpl.java @@ -5,7 +5,7 @@ import org.mifosplatform.commands.domain.CommandSource; import org.mifosplatform.commands.domain.CommandSourceRepository; import org.mifosplatform.commands.domain.CommandWrapper; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.portfolio.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException; @@ -34,46 +34,17 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio } @Override - public EntityIdentifier logCommandSource(final String actionName, final String entityName, final String apiOperation, - final String resource, final Long resourceId, final String subResource, final Long subRescourceId, final String json) { + public CommandProcessingResult logCommandSource(final CommandWrapper wrapper) { - final String taskPermissionName = actionName + "_" + entityName; - context.authenticatedUser().validateHasPermissionTo(taskPermissionName); + context.authenticatedUser().validateHasPermissionTo(wrapper.getTaskPermissionName()); - final CommandWrapper wrapper = CommandWrapper.wrap(actionName, entityName, apiOperation, resource, resourceId, subResource, - subRescourceId); - EntityIdentifier result = null; + final String json = wrapper.getJson(); + CommandProcessingResult result = null; try { final JsonElement parsedCommand = this.fromApiJsonHelper.parse(json); - final JsonCommand command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, entityName, resourceId, subRescourceId); - final boolean isApprovedByChecker = false; - result = this.processAndLogCommandService.processAndLogCommand(wrapper, command, isApprovedByChecker); - } catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) { - - final String jsonToUse = StringUtils.defaultIfEmpty(e.getJsonOfChangesOnly(), json); - - final JsonElement parsedCommand = this.fromApiJsonHelper.parse(jsonToUse); - final JsonCommand command = JsonCommand.from(jsonToUse, parsedCommand, this.fromApiJsonHelper, entityName, resourceId, subRescourceId); - - result = this.processAndLogCommandService.logCommand(wrapper, command); - } - - return result; - } - - @Override - public EntityIdentifier logCommandSource(final String actionName, final String entityName, final String apiOperation, final String resource, - final Long resourceId, final String json) { - - final String taskPermissionName = actionName + "_" + entityName; - context.authenticatedUser().validateHasPermissionTo(taskPermissionName); - - final CommandWrapper wrapper = CommandWrapper.wrap(actionName, entityName, apiOperation, resource, resourceId); - - EntityIdentifier result = null; - try { - final JsonElement parsedCommand = this.fromApiJsonHelper.parse(json); - final JsonCommand command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, entityName, resourceId, null); + final JsonCommand command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(), + wrapper.getEntityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), wrapper.getApptableId(), + wrapper.getDatatableId()); final boolean isApprovedByChecker = false; result = this.processAndLogCommandService.processAndLogCommand(wrapper, command, isApprovedByChecker); @@ -82,7 +53,9 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio final String jsonToUse = StringUtils.defaultIfEmpty(e.getJsonOfChangesOnly(), json); final JsonElement parsedCommand = this.fromApiJsonHelper.parse(jsonToUse); - final JsonCommand command = JsonCommand.from(jsonToUse, parsedCommand, this.fromApiJsonHelper, entityName, resourceId, null); + final JsonCommand command = JsonCommand.from(jsonToUse, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(), + wrapper.getEntityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), wrapper.getApptableId(), + wrapper.getDatatableId()); result = this.processAndLogCommandService.logCommand(wrapper, command); } @@ -91,19 +64,18 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio } @Override - public EntityIdentifier approveEntry(final Long commandId) { + public CommandProcessingResult approveEntry(final Long commandId) { final CommandSource commandSourceInput = this.commandSourceRepository.findOne(commandId); context.authenticatedUser().validateHasCheckerPermissionTo(commandSourceInput.getPermissionCode()); final CommandWrapper wrapper = CommandWrapper.fromExistingCommand(commandId, commandSourceInput.getActionName(), - commandSourceInput.getEntityName(), commandSourceInput.operation(), commandSourceInput.resourceName(), - commandSourceInput.resourceId(), commandSourceInput.getSubResource(), commandSourceInput.getSubResourceId()); + commandSourceInput.getEntityName(), commandSourceInput.resourceId()); final JsonElement parsedCommand = this.fromApiJsonHelper.parse(commandSourceInput.json()); final JsonCommand command = JsonCommand.fromExistingCommand(commandId, commandSourceInput.json(), parsedCommand, - this.fromApiJsonHelper, commandSourceInput.resourceId(), commandSourceInput.getSubResourceId()); + this.fromApiJsonHelper, commandSourceInput.resourceId()); final boolean makerCheckerApproval = true; return this.processAndLogCommandService.processAndLogCommand(wrapper, command, makerCheckerApproval); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandsReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandsReadPlatformServiceImpl.java index 6cb3a7002..82eec36af 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandsReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandsReadPlatformServiceImpl.java @@ -29,7 +29,7 @@ public class PortfolioCommandsReadPlatformServiceImpl implements PortfolioComman private static final class CommandSourceMapper implements RowMapper { public String schema() { - return " mc.id as id, mc.api_operation as taskOperation, mc.api_resource as taskEntity, mc.resource_id as entityId," + return " mc.id as id, mc.action_name as taskOperation, mc.entity_name as taskEntity, mc.resource_id as entityId," + "mc.command_as_json as taskJson, mc.made_on_date as madeOnDate from m_portfolio_command_source mc "; } @@ -54,7 +54,7 @@ public class PortfolioCommandsReadPlatformServiceImpl implements PortfolioComman final CommandSourceMapper rm = new CommandSourceMapper(); final String sql = "select " + rm.schema() - + " where mc.checker_id is null and mc.processing_result_enum = 2 order by mc.made_on_date DESC, mc.api_resource ASC, mc.api_operation ASC"; + + " where mc.checker_id is null and mc.processing_result_enum = 2 order by mc.made_on_date DESC, mc.api_resource ASC, mc.action_name ASC"; return this.jdbcTemplate.query(sql, rm, new Object[] {}); } @@ -74,7 +74,7 @@ public class PortfolioCommandsReadPlatformServiceImpl implements PortfolioComman final CommandSourceMapper rm = new CommandSourceMapper(); final String sql = "select " + rm.schema() - + " where mc.api_resource like ? and mc.resource_id = ? and mc.checker_id is null and mc.processing_result_enum = 2 order by mc.made_on_date DESC, mc.api_operation ASC"; + + " where mc.entity_name like ? and mc.resource_id = ? and mc.checker_id is null and mc.processing_result_enum = 2 order by mc.made_on_date DESC, mc.action_name ASC"; return this.jdbcTemplate.query(sql, rm, new Object[] { apiResource, resourceId }); } 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 150bc3af9..338af9e6b 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 @@ -9,7 +9,8 @@ import org.mifosplatform.commands.domain.CommandWrapper; import org.mifosplatform.commands.exception.UnsupportedCommandException; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.monetary.service.ConfigurationDomainService; @@ -44,13 +45,13 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer @Transactional @Override - public EntityIdentifier processAndLogCommand(final CommandWrapper wrapper, final JsonCommand command, final boolean isApprovedByChecker) { + public CommandProcessingResult processAndLogCommand(final CommandWrapper wrapper, final JsonCommand command, final boolean isApprovedByChecker) { final NewCommandSourceHandler handler = findCommandHandler(wrapper); - final EntityIdentifier result = handler.processCommand(command); + final CommandProcessingResult result = handler.processCommand(command); final AppUser maker = context.authenticatedUser(); - + CommandSource commandSourceResult = null; if (command.commandId() != null) { commandSourceResult = this.commandSourceRepository.findOne(command.commandId()); @@ -59,8 +60,8 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer commandSourceResult = CommandSource.fullEntryFrom(wrapper, command, maker); } commandSourceResult.updateResourceId(result.resourceId()); - commandSourceResult.updateSubResourceId(result.subResourceId()); - + commandSourceResult.updateForAudit(result.getOfficeId(), result.getGroupId(), result.getClientId(), result.getLoanId()); + String changesOnlyJson = null; if (result.hasChanges()) { changesOnlyJson = this.toApiJsonSerializer.serializeResult(result.getChanges()); @@ -75,14 +76,15 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer commandSourceRepository.save(commandSourceResult); } - if (this.configurationDomainService.isMakerCheckerEnabledForTask(wrapper.taskPermissionName()) && !isApprovedByChecker) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(changesOnlyJson); } + if (this.configurationDomainService.isMakerCheckerEnabledForTask(wrapper.taskPermissionName()) && !isApprovedByChecker) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException( + changesOnlyJson); } return result; } @Transactional @Override - public EntityIdentifier logCommand(final CommandWrapper wrapper, final JsonCommand command) { + public CommandProcessingResult logCommand(final CommandWrapper wrapper, final JsonCommand command) { final AppUser maker = context.authenticatedUser(); @@ -92,28 +94,27 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer commandSourceRepository.save(commandSourceResult); } - return EntityIdentifier.resourceResult(commandSourceResult.resourceId(), commandSourceResult.getId()); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(commandSourceResult.resourceId()).build(); } private NewCommandSourceHandler findCommandHandler(final CommandWrapper wrapper) { NewCommandSourceHandler handler = null; if (wrapper.isDatatableResource()) { - if (wrapper.isCreate()) { - handler = applicationContext.getBean("createDatatableEntryCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isUpdateMultiple()) { + if (wrapper.isCreate()) { + handler = applicationContext.getBean("createDatatableEntryCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isUpdateMultiple()) { handler = applicationContext.getBean("updateOneToManyDatatableEntryCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isUpdate()) { - handler = applicationContext.getBean("updateOneToOneDatatableEntryCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isDeleteMultiple()) { - handler = applicationContext.getBean("deleteOneToManyDatatableEntryCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isDelete()) { - handler = applicationContext.getBean("deleteOneToOneDatatableEntryCommandHandler", NewCommandSourceHandler.class); - } else { + } else if (wrapper.isUpdateOneToOne()) { + handler = applicationContext.getBean("updateOneToOneDatatableEntryCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isDeleteMultiple()) { + handler = applicationContext.getBean("deleteOneToManyDatatableEntryCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isDeleteOneToOne()) { + handler = applicationContext.getBean("deleteOneToOneDatatableEntryCommandHandler", NewCommandSourceHandler.class); + } else { throw new UnsupportedCommandException(wrapper.commandName()); } - } - else if (wrapper.isClientNoteResource()) { + } else if (wrapper.isClientNoteResource()) { if (wrapper.isCreate()) { handler = applicationContext.getBean("createClientNoteCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { @@ -132,7 +133,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer } else { throw new UnsupportedCommandException(wrapper.commandName()); } - } else if (wrapper.isClientResource() && !wrapper.isNotesSubResource() && !wrapper.isIdentifiersSubResource()) { + } else if (wrapper.isClientResource() && !wrapper.isClientNoteResource() && !wrapper.isClientIdentifierResource()) { if (wrapper.isCreate()) { handler = applicationContext.getBean("createClientCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdate()) { @@ -226,7 +227,6 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer throw new UnsupportedCommandException(wrapper.commandName()); } } else if (wrapper.isLoanResource()) { - if (wrapper.isApproveLoanApplication()) { handler = applicationContext.getBean("loanApplicationApprovalCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUndoApprovalOfLoanApplication()) { @@ -251,14 +251,6 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer handler = applicationContext.getBean("closeLoanCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isCloseLoanAsRescheduled()) { handler = applicationContext.getBean("closeLoanAsRescheduledCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isAddLoanCharge()) { - handler = applicationContext.getBean("addLoanChargeCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isDeleteLoanCharge()) { - handler = applicationContext.getBean("deleteLoanChargeCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isUpdateLoanCharge()) { - handler = applicationContext.getBean("updateLoanChargeCommandHandler", NewCommandSourceHandler.class); - } else if (wrapper.isWaiveLoanCharge()) { - handler = applicationContext.getBean("waiveLoanChargeCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isUpdateLoanOfficer()) { handler = applicationContext.getBean("updateLoanOfficerCommandHandler", NewCommandSourceHandler.class); } else if (wrapper.isBulkUpdateLoanOfficer()) { @@ -272,6 +264,16 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer } else { throw new UnsupportedCommandException(wrapper.commandName()); } + } else if (wrapper.isLoanChargeResource()) { + if (wrapper.isAddLoanCharge()) { + handler = applicationContext.getBean("addLoanChargeCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isDeleteLoanCharge()) { + handler = applicationContext.getBean("deleteLoanChargeCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isUpdateLoanCharge()) { + handler = applicationContext.getBean("updateLoanChargeCommandHandler", NewCommandSourceHandler.class); + } else if (wrapper.isWaiveLoanCharge()) { + handler = applicationContext.getBean("waiveLoanChargeCommandHandler", NewCommandSourceHandler.class); + } } else { throw new UnsupportedCommandException(wrapper.commandName()); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/api/CodesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/api/CodesApiResource.java index 82f53edcd..d667709d2 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/api/CodesApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/api/CodesApiResource.java @@ -17,11 +17,13 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.codes.data.CodeData; import org.mifosplatform.infrastructure.codes.service.CodeReadPlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -75,9 +77,11 @@ public class CodesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String createCode(final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "CODE", "CREATE", "codes", null, - apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().createCode().withUrl("/codes").withJson(apiRequestBodyAsJson) + .build(); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + return this.toApiJsonSerializer.serialize(result); } @@ -99,9 +103,11 @@ public class CodesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String updateCode(@PathParam("codeId") final Long codeId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "CODE", "UPDATE", "codes", - codeId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateCode().withUrl("/codes").withEntityId(codeId).withJson(apiRequestBodyAsJson) + .build(); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + return this.toApiJsonSerializer.serialize(result); } @@ -111,9 +117,11 @@ public class CodesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String deleteCode(@PathParam("codeId") final Long codeId) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "CODE", "DELETE", "codes", - codeId, "{}"); + final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteCode().withUrl("/codes").withEntityId(codeId).withJson("{}") + .build(); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + return this.toApiJsonSerializer.serialize(result); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/handler/CreateCodeCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/handler/CreateCodeCommandHandler.java index ef2faa1cb..c9e67f3de 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/handler/CreateCodeCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/handler/CreateCodeCommandHandler.java @@ -3,7 +3,7 @@ package org.mifosplatform.infrastructure.codes.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.codes.service.CodeWritePlatformService; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,7 +20,7 @@ public class CreateCodeCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.writePlatformService.createCode(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/handler/DeleteCodeCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/handler/DeleteCodeCommandHandler.java index abd298a3c..6caa714d8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/handler/DeleteCodeCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/handler/DeleteCodeCommandHandler.java @@ -3,7 +3,7 @@ package org.mifosplatform.infrastructure.codes.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.codes.service.CodeWritePlatformService; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,8 +20,8 @@ public class DeleteCodeCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.deleteCode(command.resourceId()); + return this.writePlatformService.deleteCode(command.entityId()); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/handler/UpdateCodeCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/handler/UpdateCodeCommandHandler.java index 2510be4df..877857a9b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/handler/UpdateCodeCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/handler/UpdateCodeCommandHandler.java @@ -3,7 +3,7 @@ package org.mifosplatform.infrastructure.codes.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.codes.service.CodeWritePlatformService; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -20,8 +20,8 @@ public class UpdateCodeCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.updateCode(command.resourceId(), command); + return this.writePlatformService.updateCode(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/service/CodeWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/service/CodeWritePlatformService.java index 1b8e005e9..0cbbe9d90 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/service/CodeWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/service/CodeWritePlatformService.java @@ -1,13 +1,13 @@ package org.mifosplatform.infrastructure.codes.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface CodeWritePlatformService { - EntityIdentifier createCode(JsonCommand command); + CommandProcessingResult createCode(JsonCommand command); - EntityIdentifier updateCode(Long codeId, JsonCommand command); + CommandProcessingResult updateCode(Long codeId, JsonCommand command); - EntityIdentifier deleteCode(Long codeId); + CommandProcessingResult deleteCode(Long codeId); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/service/CodeWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/service/CodeWritePlatformServiceJpaRepositoryImpl.java index c8d70ce26..1d1cf4f62 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/service/CodeWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/codes/service/CodeWritePlatformServiceJpaRepositoryImpl.java @@ -9,7 +9,8 @@ import org.mifosplatform.infrastructure.codes.exception.CodeNotFoundException; import org.mifosplatform.infrastructure.codes.exception.SystemDefinedCodeCannotBeChangedException; import org.mifosplatform.infrastructure.codes.serialization.CodeCommandFromApiJsonDeserializer; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +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.slf4j.Logger; @@ -38,7 +39,7 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf @Transactional @Override - public EntityIdentifier createCode(final JsonCommand command) { + public CommandProcessingResult createCode(final JsonCommand command) { try { context.authenticatedUser(); @@ -49,15 +50,15 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf final Code code = Code.fromJson(command); this.codeRepository.save(code); - return EntityIdentifier.resourceResult(code.getId(), null); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(code.getId()).build(); } catch (DataIntegrityViolationException dve) { - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } } @Transactional @Override - public EntityIdentifier updateCode(final Long codeId, final JsonCommand command) { + public CommandProcessingResult updateCode(final Long codeId, final JsonCommand command) { try { context.authenticatedUser(); @@ -71,7 +72,7 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf this.codeRepository.save(code); } - return EntityIdentifier.withChanges(codeId, changes); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(codeId).with(changes).build(); } catch (DataIntegrityViolationException dve) { handleCodeDataIntegrityIssues(command, dve); return null; @@ -80,7 +81,7 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf @Transactional @Override - public EntityIdentifier deleteCode(final Long codeId) { + public CommandProcessingResult deleteCode(final Long codeId) { context.authenticatedUser(); @@ -89,7 +90,7 @@ public class CodeWritePlatformServiceJpaRepositoryImpl implements CodeWritePlatf this.codeRepository.delete(code); - return new EntityIdentifier(code.getId()); + return new CommandProcessingResultBuilder().withEntityId(codeId).build(); } private Code retrieveCodeBy(final Long codeId) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/JsonCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/JsonCommand.java index 0f3fb7c26..80dfce365 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/JsonCommand.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/api/JsonCommand.java @@ -29,52 +29,79 @@ public final class JsonCommand { private final FromJsonHelper fromApiJsonHelper; private final Long commandId; private final Long resourceId; - private final Long subResourceId; - private final String entityName; + private final Long groupId; + private final Long clientId; + private final Long loanId; + private final String entityName; + private final Long apptableId; + private final Long datatableId; public static JsonCommand from(final String jsonCommand, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper, - final String entityName, final Long resourceId, final Long subResourceId) { - return new JsonCommand(null, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, subResourceId); - } - - public static JsonCommand fromExistingCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper, - final Long resourceId, final Long subResourceId) { - return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, null, resourceId, subResourceId); + final String entityName, final Long resourceId, final Long groupId, final Long clientId, final Long loanId, + final Long apptableId, final Long datatableId) { + return new JsonCommand(null, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, groupId, clientId, loanId, + apptableId, datatableId); } - public JsonCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand, final FromJsonHelper fromApiJsonHelper, - final String entityName, final Long resourceId, final Long subResourceId) { + public static JsonCommand fromExistingCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand, + final FromJsonHelper fromApiJsonHelper, final Long resourceId) { + return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, null, resourceId, null, null, null, null, null); + } + + public JsonCommand(final Long commandId, final String jsonCommand, final JsonElement parsedCommand, + final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId, final Long groupId, + final Long clientId, final Long loanId, final Long apptableId, final Long datatableId) { this.commandId = commandId; this.jsonCommand = jsonCommand; this.parsedCommand = parsedCommand; this.fromApiJsonHelper = fromApiJsonHelper; - this.entityName = entityName; + this.entityName = entityName; this.resourceId = resourceId; - this.subResourceId = subResourceId; + this.groupId = groupId; + this.clientId = clientId; + this.loanId = loanId; + this.apptableId = apptableId; + this.datatableId = datatableId; } public String json() { return this.jsonCommand; } - + public JsonElement parsedJson() { return this.parsedCommand; } - + public Long commandId() { return this.commandId; } - + public String entityName() { - return this.entityName; + return this.entityName; } - - public Long resourceId() { + + public Long entityId() { return this.resourceId; } - - public Long subResourceId() { - return this.subResourceId; + + public Long getGroupId() { + return this.groupId; + } + + public Long getClientId() { + return this.clientId; + } + + public Long getLoanId() { + return this.loanId; + } + + public Long getApptableId() { + return this.apptableId; + } + + public Long getDatatableId() { + return this.datatableId; } private boolean differenceExists(final LocalDate baseValue, final LocalDate workingCopyValue) { 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 new file mode 100644 index 000000000..bf99d3dd2 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResult.java @@ -0,0 +1,124 @@ +package org.mifosplatform.infrastructure.core.data; + +import java.util.HashMap; +import java.util.Map; + +/** + * Represents the successful result of an REST API call that results in + * processing a command. + */ +public class CommandProcessingResult { + + private Long commandId; + private Long officeId; + private final Long groupId; + private final Long clientId; + private final Long loanId; + private Long resourceId; + private Map changes; + + public static CommandProcessingResult fromDetails(final Long commandId, final Long officeId, final Long groupId, final Long clientId, + final Long loanId, final Long entityId, final Map changes) { + return new CommandProcessingResult(commandId, officeId, groupId, clientId, loanId, entityId, changes); + } + + public static CommandProcessingResult commandOnlyResult(final Long commandId) { + return new CommandProcessingResult(null, null, commandId, null); + } + + public static CommandProcessingResult resourceResult(final Long resourceId, final Long commandId) { + return new CommandProcessingResult(resourceId, null, commandId, null); + } + + public static CommandProcessingResult resourceResult(final Long resourceId, final Long commandId, final Map changes) { + return new CommandProcessingResult(resourceId, null, commandId, changes); + } + + public static CommandProcessingResult subResourceResult(final Long resourceId, final Long subResourceId, final Long commandId) { + return new CommandProcessingResult(resourceId, subResourceId, commandId, null); + } + + public static CommandProcessingResult subResourceResult(final Long resourceId, final Long subResourceId, final Long commandId, + final Map changes) { + return new CommandProcessingResult(resourceId, subResourceId, commandId, changes); + } + + public static CommandProcessingResult withChanges(final Long resourceId, final Map changes) { + return new CommandProcessingResult(resourceId, null, null, changes); + } + + public static CommandProcessingResult empty() { + return new CommandProcessingResult(Long.valueOf(-1), Long.valueOf(-1), Long.valueOf(-1), null); + } + + public CommandProcessingResult(final Long entityId) { + this.resourceId = entityId; + this.officeId = null; + this.groupId = null; + this.clientId = null; + this.loanId = null; + this.changes = new HashMap(); + } + + private CommandProcessingResult(final Long commandId, final Long officeId, final Long groupId, final Long clientId, final Long loanId, + final Long resourceId, final Map changesOnly) { + this.commandId = commandId; + this.officeId = officeId; + this.groupId = groupId; + this.clientId = clientId; + this.loanId = loanId; + this.resourceId = resourceId; + this.changes = changesOnly; + } + + private CommandProcessingResult(final Long resourceId, final Long officeId, final Long commandId, final Map changesOnly) { + this.resourceId = resourceId; + this.officeId = officeId; + this.groupId = null; + this.clientId = null; + this.loanId = null; + this.commandId = commandId; + this.changes = changesOnly; + } + + public Long commandId() { + return this.commandId; + } + + public Long resourceId() { + return this.resourceId; + } + + public Long getOfficeId() { + return this.officeId; + } + + public void setOfficeId(Long officeId) { + this.officeId = officeId; + } + + public Long getGroupId() { + return this.groupId; + } + + public Long getClientId() { + return this.clientId; + } + + public Long getLoanId() { + return this.loanId; + } + + public Map getChanges() { + Map checkIfEmpty = null; + if (this.changes != null && !this.changes.isEmpty()) { + checkIfEmpty = this.changes; + } + return checkIfEmpty; + } + + public boolean hasChanges() { + final boolean noChanges = this.changes == null || this.changes.isEmpty(); + return !noChanges; + } +} \ No newline at end of file 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 new file mode 100644 index 000000000..bfc0e11a7 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/CommandProcessingResultBuilder.java @@ -0,0 +1,57 @@ +package org.mifosplatform.infrastructure.core.data; + +import java.util.Map; + +/** + * Represents the successful result of an REST API call that results in + * processing a command. + */ +public class CommandProcessingResultBuilder { + + private Long commandId; + private Long officeId; + private Long groupId; + private Long clientId; + private Long loanId; + private Long entityId; + private Map changes; + + public CommandProcessingResult build() { + return CommandProcessingResult.fromDetails(commandId, officeId, groupId, clientId, loanId, entityId, changes); + } + + public CommandProcessingResultBuilder withCommandId(final Long withCommandId) { + this.commandId = withCommandId; + return this; + } + + public CommandProcessingResultBuilder with(final Map withChanges) { + this.changes = withChanges; + return this; + } + + public CommandProcessingResultBuilder withEntityId(final Long withEntityId) { + this.entityId = withEntityId; + return this; + } + + public CommandProcessingResultBuilder withOfficeId(final Long withOfficeId) { + this.officeId = withOfficeId; + return this; + } + + public CommandProcessingResultBuilder withClientId(final Long withClientId) { + this.clientId = withClientId; + return this; + } + + public CommandProcessingResultBuilder withGroupId(final Long withGroupId) { + this.groupId = withGroupId; + return this; + } + + public CommandProcessingResultBuilder withLoanId(final Long withLoanId) { + this.loanId = withLoanId; + return this; + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/EntityIdentifier.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/EntityIdentifier.java deleted file mode 100644 index b6adda8eb..000000000 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/core/data/EntityIdentifier.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.mifosplatform.infrastructure.core.data; - -import java.util.HashMap; -import java.util.Map; - -/** - * Represents the successful result of an REST API call. - * - * FIXME - KW - Rename to CommandProcessingResult - make immutable - */ -public class EntityIdentifier { - - private Long commandId; - private Long resourceId; - private Long subResourceId; - - private Map changes; - - public static EntityIdentifier commandOnlyResult(final Long commandId) { - return new EntityIdentifier(null, null, commandId, null); - } - - public static EntityIdentifier resourceResult(final Long resourceId, final Long commandId) { - return new EntityIdentifier(resourceId, null, commandId, null); - } - - public static EntityIdentifier resourceResult(final Long resourceId, final Long commandId, final Map changes) { - return new EntityIdentifier(resourceId, null, commandId, changes); - } - - public static EntityIdentifier subResourceResult(final Long resourceId, final Long subResourceId, final Long commandId) { - return new EntityIdentifier(resourceId, subResourceId, commandId, null); - } - - public static EntityIdentifier subResourceResult(final Long resourceId, final Long subResourceId, final Long commandId, final Map changes) { - return new EntityIdentifier(resourceId, subResourceId, commandId, changes); - } - - public static EntityIdentifier withChanges(final Long resourceId, final Map changes) { - return new EntityIdentifier(resourceId, null, null, changes); - } - - public static EntityIdentifier empty() { - return new EntityIdentifier(Long.valueOf(-1), Long.valueOf(-1), Long.valueOf(-1), null); - } - - protected EntityIdentifier() { - // - } - - public EntityIdentifier(final Long entityId) { - this.resourceId = entityId; - this.changes = new HashMap(); - } - - private EntityIdentifier(final Long resourceId, final Long subResourceId, final Long commandId, final Map changesOnly) { - this.resourceId = resourceId; - this.subResourceId = subResourceId; - this.commandId = commandId; - this.changes = changesOnly; - } - - public Long commandId() { - return this.commandId; - } - - public Long resourceId() { - return this.resourceId; - } - - public Long subResourceId() { - return this.subResourceId; - } - - public Map getChanges() { - Map checkIfEmpty = null; - if (this.changes != null && !this.changes.isEmpty()) { - checkIfEmpty = this.changes; - } - return checkIfEmpty; - } - - public boolean hasChanges() { - final boolean noChanges = this.changes == null || this.changes.isEmpty(); - return !noChanges; - } -} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/DataTableApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/DataTableApiResource.java index e24f1a912..7db3999dd 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/DataTableApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/api/DataTableApiResource.java @@ -15,9 +15,11 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer; import org.mifosplatform.infrastructure.dataqueries.data.DatatableData; import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData; @@ -70,7 +72,7 @@ public class DataTableApiResource { this.readWriteNonCoreDataService.registerDatatable(datatable, apptable); - return this.toApiJsonSerializer.serialize(EntityIdentifier.empty()); + return this.toApiJsonSerializer.serialize(CommandProcessingResult.empty()); } @POST @@ -81,7 +83,7 @@ public class DataTableApiResource { this.readWriteNonCoreDataService.deregisterDatatable(datatable); - return this.toApiJsonSerializer.serialize(EntityIdentifier.empty()); + return this.toApiJsonSerializer.serialize(CommandProcessingResult.empty()); } @GET @@ -139,10 +141,12 @@ public class DataTableApiResource { public String newDatatableEntry(@PathParam("datatable") final String datatable, @PathParam("apptableId") final Long apptableId, final String apiRequestBodyAsJson) { - final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("CREATE", datatable, "CREATE", - "datatables/" + datatable, apptableId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().createDatatable(datatable, apptableId, null) + .withUrl("/datatables/" + datatable).withJson(apiRequestBodyAsJson).build(); - return this.toApiJsonSerializer.serialize(entityIdentifier); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + + return this.toApiJsonSerializer.serialize(result); } @PUT @@ -152,10 +156,12 @@ public class DataTableApiResource { public String updateDatatableEntryOnetoOne(@PathParam("datatable") final String datatable, @PathParam("apptableId") final Long apptableId, final String apiRequestBodyAsJson) { - final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", datatable, "UPDATE", - "datatables/" + datatable, apptableId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateDatatable(datatable, apptableId, null) + .withUrl("/datatables/" + datatable).withJson(apiRequestBodyAsJson).build(); - return this.toApiJsonSerializer.serialize(entityIdentifier); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + + return this.toApiJsonSerializer.serialize(result); } @PUT @@ -166,10 +172,12 @@ public class DataTableApiResource { @PathParam("apptableId") final Long apptableId, @PathParam("datatableId") final Long datatableId, final String apiRequestBodyAsJson) { - final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", datatable, - "UPDATE_MULTIPLE", "datatables/" + datatable, apptableId, "datatables/" + datatable, datatableId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateDatatable(datatable, apptableId, datatableId) + .withUrl("/datatables/" + datatable + "/" + apptableId).withJson(apiRequestBodyAsJson).build(); - return this.toApiJsonSerializer.serialize(entityIdentifier); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + + return this.toApiJsonSerializer.serialize(result); } @DELETE @@ -178,10 +186,12 @@ public class DataTableApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String deleteDatatableEntries(@PathParam("datatable") final String datatable, @PathParam("apptableId") final Long apptableId) { - final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("DELETE", datatable, "DELETE", - "datatables/" + datatable, apptableId, "{}"); + final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteDatatable(datatable, apptableId, null) + .withUrl("/datatables/" + datatable).withJson("{}").build(); - return this.toApiJsonSerializer.serialize(entityIdentifier); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + + return this.toApiJsonSerializer.serialize(result); } @DELETE @@ -191,9 +201,11 @@ public class DataTableApiResource { public String deleteDatatableEntries(@PathParam("datatable") final String datatable, @PathParam("apptableId") final Long apptableId, @PathParam("datatableId") final Long datatableId) { - final EntityIdentifier entityIdentifier = this.commandsSourceWritePlatformService.logCommandSource("DELETE", datatable, - "DELETE_MULTIPLE", "datatables/" + datatable, apptableId, "datatables/" + datatable, datatableId, "{}"); + final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteDatatable(datatable, apptableId, datatableId) + .withUrl("/datatables/" + datatable + "/" + apptableId).withJson("{}").build(); - return this.toApiJsonSerializer.serialize(entityIdentifier); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + + return this.toApiJsonSerializer.serialize(result); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/CreateDatatableEntryCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/CreateDatatableEntryCommandHandler.java index 6bbab7b71..9e776b44e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/CreateDatatableEntryCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/CreateDatatableEntryCommandHandler.java @@ -2,32 +2,31 @@ package org.mifosplatform.infrastructure.dataqueries.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class CreateDatatableEntryCommandHandler implements - NewCommandSourceHandler { +public class CreateDatatableEntryCommandHandler implements NewCommandSourceHandler { - private final ReadWriteNonCoreDataService writePlatformService; + private final ReadWriteNonCoreDataService writePlatformService; - @Autowired - public CreateDatatableEntryCommandHandler( - final ReadWriteNonCoreDataService writePlatformService) { - this.writePlatformService = writePlatformService; - } + @Autowired + public CreateDatatableEntryCommandHandler(final ReadWriteNonCoreDataService writePlatformService) { + this.writePlatformService = writePlatformService; + } - @Transactional - @Override - public EntityIdentifier processCommand(final JsonCommand command) { + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { - this.writePlatformService.newDatatableEntry(command.entityName(), - command.resourceId(), command); + this.writePlatformService.newDatatableEntry(command.entityName(), command.getApptableId(), command); - return EntityIdentifier.resourceResult(command.resourceId(), - command.commandId()); - } + // FIXME - kw - need to find office and either group/client/loan that + // this datatable is against. + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(command.getApptableId()).build(); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/DeleteOneToManyDatatableEntryCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/DeleteOneToManyDatatableEntryCommandHandler.java index baa0a079b..e384cefb1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/DeleteOneToManyDatatableEntryCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/DeleteOneToManyDatatableEntryCommandHandler.java @@ -2,31 +2,29 @@ package org.mifosplatform.infrastructure.dataqueries.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class DeleteOneToManyDatatableEntryCommandHandler implements - NewCommandSourceHandler { +public class DeleteOneToManyDatatableEntryCommandHandler implements NewCommandSourceHandler { - private final ReadWriteNonCoreDataService writePlatformService; + private final ReadWriteNonCoreDataService writePlatformService; - @Autowired - public DeleteOneToManyDatatableEntryCommandHandler( - final ReadWriteNonCoreDataService writePlatformService) { - this.writePlatformService = writePlatformService; - } + @Autowired + public DeleteOneToManyDatatableEntryCommandHandler(final ReadWriteNonCoreDataService writePlatformService) { + this.writePlatformService = writePlatformService; + } - @Transactional - @Override - public EntityIdentifier processCommand(final JsonCommand command) { + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { - this.writePlatformService.deleteDatatableEntry(command.entityName(), command.resourceId(), command.subResourceId()); + this.writePlatformService.deleteDatatableEntry(command.entityName(), command.getApptableId(), command.getDatatableId()); - return EntityIdentifier.subResourceResult(command.resourceId(), command.subResourceId(), - command.commandId()); - } + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(command.getDatatableId()).build(); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/DeleteOneToOneDatatableEntryCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/DeleteOneToOneDatatableEntryCommandHandler.java index f307ef82b..6a1a7afd9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/DeleteOneToOneDatatableEntryCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/DeleteOneToOneDatatableEntryCommandHandler.java @@ -2,31 +2,29 @@ package org.mifosplatform.infrastructure.dataqueries.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class DeleteOneToOneDatatableEntryCommandHandler implements - NewCommandSourceHandler { +public class DeleteOneToOneDatatableEntryCommandHandler implements NewCommandSourceHandler { - private final ReadWriteNonCoreDataService writePlatformService; + private final ReadWriteNonCoreDataService writePlatformService; - @Autowired - public DeleteOneToOneDatatableEntryCommandHandler( - final ReadWriteNonCoreDataService writePlatformService) { - this.writePlatformService = writePlatformService; - } + @Autowired + public DeleteOneToOneDatatableEntryCommandHandler(final ReadWriteNonCoreDataService writePlatformService) { + this.writePlatformService = writePlatformService; + } - @Transactional - @Override - public EntityIdentifier processCommand(final JsonCommand command) { + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { - this.writePlatformService.deleteDatatableEntries(command.entityName(), command.resourceId()); + this.writePlatformService.deleteDatatableEntries(command.entityName(), command.getApptableId()); - return EntityIdentifier.resourceResult(command.resourceId(), - command.commandId()); - } + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(command.getApptableId()).build(); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/UpdateOneToManyDatatableEntryCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/UpdateOneToManyDatatableEntryCommandHandler.java index 123cf4776..b88e79184 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/UpdateOneToManyDatatableEntryCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/UpdateOneToManyDatatableEntryCommandHandler.java @@ -4,31 +4,30 @@ import java.util.Map; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service -public class UpdateOneToManyDatatableEntryCommandHandler implements - NewCommandSourceHandler { +public class UpdateOneToManyDatatableEntryCommandHandler implements NewCommandSourceHandler { - private final ReadWriteNonCoreDataService writePlatformService; + private final ReadWriteNonCoreDataService writePlatformService; - @Autowired - public UpdateOneToManyDatatableEntryCommandHandler( - final ReadWriteNonCoreDataService writePlatformService) { - this.writePlatformService = writePlatformService; - } + @Autowired + public UpdateOneToManyDatatableEntryCommandHandler(final ReadWriteNonCoreDataService writePlatformService) { + this.writePlatformService = writePlatformService; + } - @Transactional - @Override - public EntityIdentifier processCommand(final JsonCommand command) { + @Transactional + @Override + public CommandProcessingResult processCommand(final JsonCommand command) { - Map changes = this.writePlatformService.updateDatatableEntryOneToMany(command.entityName(), command.resourceId(), command.subResourceId(), command); + final Map changes = this.writePlatformService.updateDatatableEntryOneToMany(command.entityName(), + command.getApptableId(), command.getDatatableId(), command); - return EntityIdentifier.subResourceResult(command.resourceId(), command.subResourceId(), - command.commandId(), changes); - } + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(command.getDatatableId()).with(changes).build(); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/UpdateOneToOneDatatableEntryCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/UpdateOneToOneDatatableEntryCommandHandler.java index 1db80337d..6fca086a3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/UpdateOneToOneDatatableEntryCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/handler/UpdateOneToOneDatatableEntryCommandHandler.java @@ -4,7 +4,8 @@ import java.util.Map; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.dataqueries.service.ReadWriteNonCoreDataService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,10 +23,12 @@ public class UpdateOneToOneDatatableEntryCommandHandler implements NewCommandSou @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - Map changes = this.writePlatformService.updateDatatableEntryOneToOne(command.entityName(), command.resourceId(), command); + final Map changes = this.writePlatformService.updateDatatableEntryOneToOne(command.entityName(), command.getApptableId(), + command); - return EntityIdentifier.resourceResult(command.resourceId(), command.commandId(), changes); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(command.getApptableId()).with(changes) + .build(); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java index 59541501c..31189d89a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/dataqueries/service/ReadWriteNonCoreDataServiceImpl.java @@ -35,890 +35,666 @@ import org.springframework.stereotype.Service; import com.google.gson.reflect.TypeToken; @Service -public class ReadWriteNonCoreDataServiceImpl implements - ReadWriteNonCoreDataService { - - private final static Logger logger = LoggerFactory - .getLogger(ReadWriteNonCoreDataServiceImpl.class); - - private final PlatformSecurityContext context; - private final FromJsonHelper fromJsonHelper; - - @Autowired - public ReadWriteNonCoreDataServiceImpl( - final PlatformSecurityContext context, - final FromJsonHelper fromJsonHelper) { - this.context = context; - this.fromJsonHelper = fromJsonHelper; - } - - @Autowired - private GenericDataService genericDataService; - - @Override - public List retrieveDatatableNames(final String appTable) { - - String andClause; - if (appTable == null) { - andClause = ""; - } else { - andClause = " and application_table_name = '" + appTable + "'"; - } - // PERMITTED datatables - String sql = "select application_table_name, registered_table_name" - + " from x_registered_table " - + " where exists" - + " (select 'f'" - + " from m_appuser_role ur " - + " join m_role r on r.id = ur.role_id" - + " left join m_role_permission rp on rp.role_id = r.id" - + " left join m_permission p on p.id = rp.permission_id" - + " where ur.appuser_id = " - + context.authenticatedUser().getId() - + " and (p.code in ('ALL_FUNCTIONS', 'ALL_FUNCTIONS_READ') or p.code = concat('READ_', registered_table_name))) " - + andClause - + " order by application_table_name, registered_table_name"; - - String sqlErrorMsg = "Application Table Name: " + appTable + " sql: " - + sql; - CachedRowSet rs = genericDataService.getCachedResultSet(sql, - sqlErrorMsg); - - List datatables = new ArrayList(); - try { - while (rs.next()) { - datatables.add(new DatatableData(rs - .getString("application_table_name"), rs - .getString("registered_table_name"))); - } - - } catch (SQLException e) { - throw new PlatformDataIntegrityException("error.msg.sql.error", - e.getMessage(), sqlErrorMsg); - } - - return datatables; - } - - @Override - public void registerDatatable(final String datatable, final String appTable) { - - // long startTime = System.currentTimeMillis(); - - validateAppTable(appTable); - - String createPermission = "'CREATE_" + datatable + "'"; - String createPermissionChecker = "'CREATE_" + datatable + "_CHECKER'"; - String readPermission = "'READ_" + datatable + "'"; - String updatePermission = "'UPDATE_" + datatable + "'"; - String updatePermissionChecker = "'UPDATE_" + datatable + "_CHECKER'"; - String deletePermission = "'DELETE_" + datatable + "'"; - String deletePermissionChecker = "'DELETE_" + datatable + "_CHECKER'"; - // TODO - put in batch command later - String sql = "insert into x_registered_table (registered_table_name, application_table_name) values ('" - + datatable + "', '" + appTable + "')"; - - genericDataService.updateSQL(sql, "SQL: " + sql); - /* - * add all permissions, including checker permissions for maintenance - * tasks - */ - sql = "insert into m_permission (grouping, code, action_name, entity_name, can_maker_checker) values " - + "('datatable', " - + createPermission - + ", 'CREATE', '" - + datatable - + "', true)," - + "('datatable', " - + createPermissionChecker - + ", 'CREATE', '" - + datatable - + "', false)," - + "('datatable', " - + readPermission - + ", 'READ', '" - + datatable - + "', false)," - + "('datatable', " - + updatePermission - + ", 'UPDATE', '" - + datatable - + "', true)," - + "('datatable', " - + updatePermissionChecker - + ", 'UPDATE', '" - + datatable - + "', false)," - + "('datatable', " - + deletePermission - + ", 'DELETE', '" - + datatable - + "', true)," - + "('datatable', " - + deletePermissionChecker - + ", 'DELETE', '" - + datatable + "', false)"; - - genericDataService.updateSQL(sql, "SQL: " + sql); - - // long elapsed = System.currentTimeMillis() - startTime; - // logger.info("FINISHING registerDatatable: Elapsed Time: " + - // elapsed + " - datatable: " + datatable - // + " application table: " + appTable); - } - - @Override - public void deregisterDatatable(final String datatable) { - // long startTime = System.currentTimeMillis(); - - // TODO - put in batch command later - - String permissionList = "('CREATE_" + datatable + "', 'CREATE_" - + datatable + "_CHECKER', 'READ_" + datatable + "', 'UPDATE_" - + datatable + "', 'UPDATE_" + datatable + "_CHECKER', 'DELETE_" - + datatable + "', 'DELETE_" + datatable + "_CHECKER')"; - - String sql = "delete from m_role_permission where m_role_permission.permission_id in (select id from m_permission where code in " - + permissionList + ")"; - genericDataService.updateSQL(sql, "SQL: " + sql); - - sql = "delete from m_permission where code in " + permissionList; - genericDataService.updateSQL(sql, "SQL: " + sql); - - sql = "delete from x_registered_table where registered_table_name = '" - + datatable + "'"; - genericDataService.updateSQL(sql, "SQL: " + sql); - - // long elapsed = System.currentTimeMillis() - startTime; - // logger.info("FINISHING deregisterDatatable: Elapsed Time: " + - // elapsed + " - datatable: " + datatable); - } - - @Override - public void newDatatableEntry(final String datatable, - final Long appTableId, final JsonCommand command) { - // long startTime = System.currentTimeMillis(); - - String appTable = getWithinScopeApplicationTableName(datatable, - appTableId); - - List columnHeaders = getDatatableResultsetColumnHeaders(datatable); - - final Type typeOfMap = new TypeToken>() { - }.getType(); - Map dataParams = this.fromJsonHelper.extractDataMap( - typeOfMap, command.json()); - - String sql = getAddSql(columnHeaders, datatable, getFKField(appTable), - appTableId, dataParams); - - genericDataService.updateSQL(sql, "SQL: " + sql); - - // long elapsed = System.currentTimeMillis() - startTime; - // logger.info("FINISHING newDatatableEntry: Elapsed Time: " + - // elapsed + " - datatable: " + datatable + " id: " - // + appTableId); - - } - - @Override - public Map updateDatatableEntryOneToOne( - final String datatable, final Long appTableId, - final JsonCommand command) { - - GenericResultsetData grs = retrieveDataTableGenericResultSet(datatable, - appTableId, null, null); - - if (grs.getData().size() == 0) - throw new DataTableNotFoundException(datatable, appTableId); - - if (grs.getData().size() > 1) - throw new PlatformDataIntegrityException( - "error.msg.attempting.multiple.update", - "Application Table: " + datatable + " Foreign Key Id: " - + appTableId); +public class ReadWriteNonCoreDataServiceImpl implements ReadWriteNonCoreDataService { + + private final static Logger logger = LoggerFactory.getLogger(ReadWriteNonCoreDataServiceImpl.class); + + private final PlatformSecurityContext context; + private final FromJsonHelper fromJsonHelper; + + @Autowired + public ReadWriteNonCoreDataServiceImpl(final PlatformSecurityContext context, final FromJsonHelper fromJsonHelper) { + this.context = context; + this.fromJsonHelper = fromJsonHelper; + } + + @Autowired + private GenericDataService genericDataService; + + @Override + public List retrieveDatatableNames(final String appTable) { + + String andClause; + if (appTable == null) { + andClause = ""; + } else { + andClause = " and application_table_name = '" + appTable + "'"; + } + // PERMITTED datatables + String sql = "select application_table_name, registered_table_name" + " from x_registered_table " + " where exists" + + " (select 'f'" + " from m_appuser_role ur " + " join m_role r on r.id = ur.role_id" + + " left join m_role_permission rp on rp.role_id = r.id" + " left join m_permission p on p.id = rp.permission_id" + + " where ur.appuser_id = " + context.authenticatedUser().getId() + + " and (p.code in ('ALL_FUNCTIONS', 'ALL_FUNCTIONS_READ') or p.code = concat('READ_', registered_table_name))) " + + andClause + " order by application_table_name, registered_table_name"; - String fkName = getFKField(getApplicationTableName(datatable)); + String sqlErrorMsg = "Application Table Name: " + appTable + " sql: " + sql; + CachedRowSet rs = genericDataService.getCachedResultSet(sql, sqlErrorMsg); - final Type typeOfMap = new TypeToken>() { - }.getType(); - Map dataParams = this.fromJsonHelper.extractDataMap( - typeOfMap, command.json()); + List datatables = new ArrayList(); + try { + while (rs.next()) { + datatables.add(new DatatableData(rs.getString("application_table_name"), rs.getString("registered_table_name"))); + } - final Map changes = getAffectedAndChangedColumns(grs, - dataParams, fkName); + } catch (SQLException e) { + throw new PlatformDataIntegrityException("error.msg.sql.error", e.getMessage(), sqlErrorMsg); + } - if (changes.size() == 0) - return changes; + return datatables; + } - String sql = getUpdateSql(datatable, fkName, appTableId, changes); + @Override + public void registerDatatable(final String datatable, final String appTable) { - if (sql != null) { - genericDataService.updateSQL(sql, "SQL: " + sql); - } else { - logger.info("No Changes"); - } + validateAppTable(appTable); - return changes; - } + String createPermission = "'CREATE_" + datatable + "'"; + String createPermissionChecker = "'CREATE_" + datatable + "_CHECKER'"; + String readPermission = "'READ_" + datatable + "'"; + String updatePermission = "'UPDATE_" + datatable + "'"; + String updatePermissionChecker = "'UPDATE_" + datatable + "_CHECKER'"; + String deletePermission = "'DELETE_" + datatable + "'"; + String deletePermissionChecker = "'DELETE_" + datatable + "_CHECKER'"; + // TODO - put in batch command later + String sql = "insert into x_registered_table (registered_table_name, application_table_name) values ('" + datatable + "', '" + + appTable + "')"; - @Override - public Map updateDatatableEntryOneToMany( - final String datatable, final Long appTableId, - final Long datatableId, final JsonCommand command) { + genericDataService.updateSQL(sql, "SQL: " + sql); + /* + * add all permissions, including checker permissions for maintenance + * tasks + */ + sql = "insert into m_permission (grouping, code, action_name, entity_name, can_maker_checker) values " + "('datatable', " + + createPermission + ", 'CREATE', '" + datatable + "', true)," + "('datatable', " + createPermissionChecker + + ", 'CREATE', '" + datatable + "', false)," + "('datatable', " + readPermission + ", 'READ', '" + datatable + "', false)," + + "('datatable', " + updatePermission + ", 'UPDATE', '" + datatable + "', true)," + "('datatable', " + + updatePermissionChecker + ", 'UPDATE', '" + datatable + "', false)," + "('datatable', " + deletePermission + + ", 'DELETE', '" + datatable + "', true)," + "('datatable', " + deletePermissionChecker + ", 'DELETE', '" + datatable + + "', false)"; - GenericResultsetData grs = retrieveDataTableGenericResultSet(datatable, - appTableId, null, datatableId); + genericDataService.updateSQL(sql, "SQL: " + sql); + } - if (grs.getData().size() == 0) - throw new DataTableNotFoundException(datatable, appTableId); + @Override + public void deregisterDatatable(final String datatable) { + // TODO - put in batch command later - final Type typeOfMap = new TypeToken>() { - }.getType(); - Map dataParams = this.fromJsonHelper.extractDataMap( - typeOfMap, command.json()); + String permissionList = "('CREATE_" + datatable + "', 'CREATE_" + datatable + "_CHECKER', 'READ_" + datatable + "', 'UPDATE_" + + datatable + "', 'UPDATE_" + datatable + "_CHECKER', 'DELETE_" + datatable + "', 'DELETE_" + datatable + "_CHECKER')"; - final Map changes = getAffectedAndChangedColumns(grs, - dataParams, "id"); + String sql = "delete from m_role_permission where m_role_permission.permission_id in (select id from m_permission where code in " + + permissionList + ")"; + genericDataService.updateSQL(sql, "SQL: " + sql); - if (changes.size() == 0) - return changes; + sql = "delete from m_permission where code in " + permissionList; + genericDataService.updateSQL(sql, "SQL: " + sql); - String sql = getUpdateSql(datatable, "id", datatableId, changes); + sql = "delete from x_registered_table where registered_table_name = '" + datatable + "'"; + genericDataService.updateSQL(sql, "SQL: " + sql); + } - if (sql != null) { - genericDataService.updateSQL(sql, "SQL: " + sql); - } else { - logger.info("No Changes"); - } + @Override + public void newDatatableEntry(final String datatable, final Long appTableId, final JsonCommand command) { + String appTable = getWithinScopeApplicationTableName(datatable, appTableId); - return changes; - } + List columnHeaders = getDatatableResultsetColumnHeaders(datatable); - @Override - public void deleteDatatableEntries(final String datatable, - final Long appTableId) { - // long startTime = System.currentTimeMillis(); + final Type typeOfMap = new TypeToken>() {}.getType(); + Map dataParams = this.fromJsonHelper.extractDataMap(typeOfMap, command.json()); - String appTable = getWithinScopeApplicationTableName(datatable, - appTableId); + String sql = getAddSql(columnHeaders, datatable, getFKField(appTable), appTableId, dataParams); - String sql = getDeleteEntriesSql(datatable, getFKField(appTable), - appTableId); + genericDataService.updateSQL(sql, "SQL: " + sql); + } - genericDataService.updateSQL(sql, "SQL: " + sql); + @Override + public Map updateDatatableEntryOneToOne(final String datatable, final Long appTableId, final JsonCommand command) { - // long elapsed = System.currentTimeMillis() - startTime; - // logger.info("FINISHING deleteDatatableEntries: Elapsed Time: " + - // elapsed + " - datatable: " + datatable - // + " App Table Id: " + appTableId); + GenericResultsetData grs = retrieveDataTableGenericResultSet(datatable, appTableId, null, null); - } + if (grs.getData().size() == 0) throw new DataTableNotFoundException(datatable, appTableId); - @Override - public void deleteDatatableEntry(final String datatable, - final Long appTableId, final Long datatableId) { - // long startTime = System.currentTimeMillis(); + if (grs.getData().size() > 1) + throw new PlatformDataIntegrityException("error.msg.attempting.multiple.update", "Application Table: " + datatable + + " Foreign Key Id: " + appTableId); - getWithinScopeApplicationTableName(datatable, appTableId); + String fkName = getFKField(getApplicationTableName(datatable)); - String sql = getDeleteEntrySql(datatable, datatableId); + final Type typeOfMap = new TypeToken>() {}.getType(); + Map dataParams = this.fromJsonHelper.extractDataMap(typeOfMap, command.json()); - genericDataService.updateSQL(sql, "SQL: " + sql); + final Map changes = getAffectedAndChangedColumns(grs, dataParams, fkName); - // long elapsed = System.currentTimeMillis() - startTime; - // logger.info("FINISHING deleteDatatableEntry: Elapsed Time: " + - // elapsed + " - datatable: " + datatable - // + " App Table Id: " + appTableId + " Data Table Id: " + - // datatableId); + if (changes.size() == 0) return changes; - } + String sql = getUpdateSql(datatable, fkName, appTableId, changes); - @Override - public GenericResultsetData retrieveDataTableGenericResultSet( - final String datatable, final Long appTableId, final String order, - final Long id) { + if (sql != null) { + genericDataService.updateSQL(sql, "SQL: " + sql); + } else { + logger.info("No Changes"); + } - // long startTime = System.currentTimeMillis(); + return changes; + } - String appTable = getWithinScopeApplicationTableName(datatable, - appTableId); + @Override + public Map updateDatatableEntryOneToMany(final String datatable, final Long appTableId, final Long datatableId, + final JsonCommand command) { - List columnHeaders = getDatatableResultsetColumnHeaders(datatable); + GenericResultsetData grs = retrieveDataTableGenericResultSet(datatable, appTableId, null, datatableId); - String sql = ""; + if (grs.getData().size() == 0) throw new DataTableNotFoundException(datatable, appTableId); - // id only used for reading a specific entry in a one to many datatable - // (when updating) - if (id == null) { - sql = sql + "select * from `" + datatable + "` where " - + getFKField(appTable) + " = " + appTableId; - } else { - sql = sql + "select * from `" + datatable + "` where id = " + id; - } + final Type typeOfMap = new TypeToken>() {}.getType(); + Map dataParams = this.fromJsonHelper.extractDataMap(typeOfMap, command.json()); - if (order != null) - sql = sql + " order by " + order; + final Map changes = getAffectedAndChangedColumns(grs, dataParams, "id"); - List result = fillDatatableResultSetDataRows(sql); + if (changes.size() == 0) return changes; - // long elapsed = System.currentTimeMillis() - startTime; - // logger.info("FINISHING DATATABLE: " + datatable + - // " Elapsed Time: " + elapsed + " SQL: " + sql); + String sql = getUpdateSql(datatable, "id", datatableId, changes); - return new GenericResultsetData(columnHeaders, result); + if (sql != null) { + genericDataService.updateSQL(sql, "SQL: " + sql); + } else { + logger.info("No Changes"); + } - } + return changes; + } - private void checkMainResourceExistsWithinScope(final String appTable, - final Long appTableId) { + @Override + public void deleteDatatableEntries(final String datatable, final Long appTableId) { - String unscopedSql = "select t.id from `" + appTable - + "` t ${dataScopeCriteria} where t.id = " + appTableId; + String appTable = getWithinScopeApplicationTableName(datatable, appTableId); - String sql = dataScopedSQL(unscopedSql, appTable); + String sql = getDeleteEntriesSql(datatable, getFKField(appTable), appTableId); - CachedRowSet rs = genericDataService.getCachedResultSet(sql, "SQL : " - + sql); + genericDataService.updateSQL(sql, "SQL: " + sql); + } - if (rs.size() == 0) - throw new DataTableNotFoundException(appTable, appTableId); - } + @Override + public void deleteDatatableEntry(final String datatable, final Long appTableId, final Long datatableId) { - private String dataScopedSQL(final String unscopedSQL, final String appTable) { - String dataScopeCriteria = null; - /* - * unfortunately have to, one way or another, be able to restrict data - * to the users office hierarchy. Here it's hardcoded for client and - * loan. They are the main application tables. But if additional fields - * are needed on other tables like group, loan_transaction or others the - * same applies (hardcoding of some sort) - */ + getWithinScopeApplicationTableName(datatable, appTableId); - AppUser currentUser = context.authenticatedUser(); - if (appTable.equalsIgnoreCase("m_client")) { - dataScopeCriteria = " join m_office o on o.id = t.office_id and o.hierarchy like '" - + currentUser.getOffice().getHierarchy() + "%'"; - } - if (appTable.equalsIgnoreCase("m_loan")) { - dataScopeCriteria = " join m_client c on c.id = t.client_id " - + " join m_office o on o.id = c.office_id and o.hierarchy like '" - + currentUser.getOffice().getHierarchy() + "%'"; - } + String sql = getDeleteEntrySql(datatable, datatableId); - if (dataScopeCriteria == null) { - throw new PlatformDataIntegrityException( - "error.msg.invalid.dataScopeCriteria", - "Application Table: " + appTable - + " not catered for in data Scoping"); - } + genericDataService.updateSQL(sql, "SQL: " + sql); + } - return genericDataService.replace(unscopedSQL, "${dataScopeCriteria}", - dataScopeCriteria); - - } + @Override + public GenericResultsetData retrieveDataTableGenericResultSet(final String datatable, final Long appTableId, final String order, + final Long id) { - private void validateAppTable(final String appTable) { + String appTable = getWithinScopeApplicationTableName(datatable, appTableId); - if (appTable.equalsIgnoreCase("m_client")) - return; - if (appTable.equalsIgnoreCase("m_loan")) - return; - - throw new PlatformDataIntegrityException( - "error.msg.invalid.application.table", - "Invalid Application Table: " + appTable); - } - - private List fillDatatableResultSetDataRows( - final String sql) { - - String sqlErrorMsg = "Sql: " + sql; - CachedRowSet rs = genericDataService.getCachedResultSet(sql, - sqlErrorMsg); + List columnHeaders = getDatatableResultsetColumnHeaders(datatable); - List resultsetDataRows = new ArrayList(); + String sql = ""; - try { + // id only used for reading a specific entry in a one to many datatable + // (when updating) + if (id == null) { + sql = sql + "select * from `" + datatable + "` where " + getFKField(appTable) + " = " + appTableId; + } else { + sql = sql + "select * from `" + datatable + "` where id = " + id; + } - ResultSetMetaData rsmd = rs.getMetaData(); - int columnCount = rsmd.getColumnCount(); + if (order != null) sql = sql + " order by " + order; - ResultsetDataRow resultsetDataRow; - String columnName = null; - String columnValue = null; - while (rs.next()) { - resultsetDataRow = new ResultsetDataRow(); - List columnValues = new ArrayList(); - for (int i = 0; i < columnCount; i++) { - columnName = rsmd.getColumnName(i + 1); - columnValue = rs.getString(columnName); - columnValues.add(columnValue); - } - resultsetDataRow.setRow(columnValues); - resultsetDataRows.add(resultsetDataRow); - } + List result = fillDatatableResultSetDataRows(sql); - return resultsetDataRows; - } catch (SQLException e) { - throw new PlatformDataIntegrityException("error.msg.sql.error", - e.getMessage(), sqlErrorMsg); - } - } + return new GenericResultsetData(columnHeaders, result); + } - private String getWithinScopeApplicationTableName(final String datatable, - final Long appTableId) { - String sql = "SELECT application_table_name FROM x_registered_table where registered_table_name = '" - + datatable + "'"; - - CachedRowSet rs = genericDataService.getCachedResultSet(sql, "SQL : " - + sql); - - if (rs.size() == 0) - throw new DataTableNotFoundException(datatable); - - try { - rs.next(); - String appTable = rs.getString("application_table_name"); - - checkMainResourceExistsWithinScope(appTable, appTableId); - - return appTable; - } catch (SQLException e) { - throw new PlatformDataIntegrityException("error.msg.sql.error", - e.getMessage()); - } - } - - private String getApplicationTableName(final String datatable) { - // TODO - only used for update... can probably remove this after as its - // a reread - String sql = "SELECT application_table_name FROM x_registered_table where registered_table_name = '" - + datatable + "'"; - - CachedRowSet rs = genericDataService.getCachedResultSet(sql, "SQL : " - + sql); - - if (rs.size() == 0) - throw new DataTableNotFoundException(datatable); + private void checkMainResourceExistsWithinScope(final String appTable, final Long appTableId) { - try { - rs.next(); - return rs.getString("application_table_name"); - } catch (SQLException e) { - throw new PlatformDataIntegrityException("error.msg.sql.error", - e.getMessage()); - } - } - - private String getFKField(final String applicationTableName) { + String unscopedSql = "select t.id from `" + appTable + "` t ${dataScopeCriteria} where t.id = " + appTableId; - return applicationTableName.substring(2) + "_id"; - } + String sql = dataScopedSQL(unscopedSql, appTable); - private CachedRowSet getDatatableMetaData(final String datatable) { - - String sql = "select COLUMN_NAME, IS_NULLABLE, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, COLUMN_KEY" - + " from INFORMATION_SCHEMA.COLUMNS " - + " where TABLE_SCHEMA = schema() and TABLE_NAME = '" - + datatable + "'order by ORDINAL_POSITION"; - - CachedRowSet columnDefinitions = genericDataService.getCachedResultSet( - sql, "SQL: " + sql); - - if (columnDefinitions.size() > 0) - return columnDefinitions; - - throw new DataTableNotFoundException(datatable); - } - - private List getDatatableResultsetColumnHeaders( - final String datatable) { - - CachedRowSet columnDefinitions = getDatatableMetaData(datatable); - - List columnHeaders = new ArrayList(); - - try { - - while (columnDefinitions.next()) { - ResultsetColumnHeader rsch = new ResultsetColumnHeader(); - - rsch.setColumnName(columnDefinitions.getString("COLUMN_NAME")); - - String isNullable = columnDefinitions.getString("IS_NULLABLE"); - if (isNullable.equalsIgnoreCase("YES")) - rsch.setColumnNullable(true); - else - rsch.setColumnNullable(false); - - String isPrimaryKey = columnDefinitions.getString("COLUMN_KEY"); - if (isPrimaryKey.equalsIgnoreCase("PRI")) - rsch.setColumnPrimaryKey(true); - else - rsch.setColumnPrimaryKey(false); - - Long columnLength = columnDefinitions - .getLong("CHARACTER_MAXIMUM_LENGTH"); - if (columnLength > 0) - rsch.setColumnLength(columnDefinitions - .getLong("CHARACTER_MAXIMUM_LENGTH")); - - rsch.setColumnType(columnDefinitions.getString("DATA_TYPE")); - - /* look for codes */ - if (rsch.getColumnType().equalsIgnoreCase("varchar")) - addCodesValueIfNecessary(rsch, "_cv"); - - if (rsch.getColumnType().equalsIgnoreCase("int")) - addCodesValueIfNecessary(rsch, "_cd"); - - rsch.setColumnDisplayType(); - - columnHeaders.add(rsch); - } - ; - return columnHeaders; - - } catch (SQLException e) { - throw new PlatformDataIntegrityException("error.msg.sql.error", - e.getMessage()); - } - - } - - private void addCodesValueIfNecessary(final ResultsetColumnHeader rsch, - final String code_suffix) { - int codePosition = rsch.getColumnName().indexOf(code_suffix); - if (codePosition > 0) { - String codeName = rsch.getColumnName().substring(0, codePosition); - - String sql = "select v.id, v.code_value from m_code m " - + " join m_code_value v on v.code_id = m.id " - + " where m.code_name = '" + codeName - + "' order by v.order_position, v.id"; - - CachedRowSet rsValues = genericDataService.getCachedResultSet(sql, - "SQL: " + sql); - - try { - while (rsValues.next()) { - rsch.getColumnValues().add( - new ResultsetColumnValue(rsValues.getInt("id"), - rsValues.getString("code_value"))); - } - } catch (SQLException e) { - throw new PlatformDataIntegrityException("error.msg.sql.error", - e.getMessage()); - } - } - - } - - private String getAddSql(final List columnHeaders, - final String datatable, final String fkName, final Long appTableId, - final Map queryParams) { - - final Map affectedColumns = getAffectedColumns( - columnHeaders, queryParams, fkName); - - String pValueWrite = ""; - String addSql = ""; - String singleQuote = "'"; - - String insertColumns = ""; - String selectColumns = ""; - String columnName = ""; - String pValue = null; - for (String key : affectedColumns.keySet()) { - pValue = affectedColumns.get(key); - - if (StringUtils.isEmpty(pValue)) { - pValueWrite = "null"; - } else { - pValueWrite = singleQuote - + genericDataService.replace(pValue, singleQuote, - singleQuote + singleQuote) + singleQuote; - } - columnName = "`" + key + "`"; - insertColumns += ", " + columnName; - selectColumns += "," + pValueWrite + " as " + columnName; - } - - addSql = "insert into `" + datatable + "` (`" + fkName + "` " - + insertColumns + ")" + " select " + appTableId + " as id" - + selectColumns; - - return addSql; - } - - private String getUpdateSql(final String datatable, - final String keyFieldName, final Long keyFieldValue, - final Map changedColumns) { - - // just updating fields that have changed since pre-update read - though - // its possible these values are different from the page the user was - // looking at and even different from the current db values (if some - // other update got in quick) - would need a version field for - // completeness but its okay to take this risk with additional fields - // data - - if (changedColumns.size() == 0) - return null; - - String pValue = null; - String pValueWrite = ""; - String singleQuote = "'"; - boolean firstColumn = true; - String sql = "update `" + datatable + "` "; - - for (String key : changedColumns.keySet()) { - if (firstColumn) { - sql += " set "; - firstColumn = false; - } else { - sql += ", "; - } - - pValue = (String) changedColumns.get(key); - if (StringUtils.isEmpty(pValue)) { - pValueWrite = "null"; - } else { - pValueWrite = singleQuote - + genericDataService.replace(pValue, singleQuote, - singleQuote + singleQuote) + singleQuote; - } - sql += "`" + key + "` = " + pValueWrite; - } - - sql += " where " + keyFieldName + " = " + keyFieldValue; - - return sql; - } - - private Map getAffectedAndChangedColumns( - final GenericResultsetData grs, - final Map queryParams, final String fkName) { - - Map affectedColumns = getAffectedColumns( - grs.getColumnHeaders(), queryParams, fkName); - Map affectedAndChangedColumns = new HashMap(); - String columnValue; - - for (String key : affectedColumns.keySet()) { - columnValue = affectedColumns.get(key); - if (columnChanged(key, columnValue, grs)) { - affectedAndChangedColumns.put(key, columnValue); - } - } - - return affectedAndChangedColumns; - } - - private boolean columnChanged(final String key, final String keyValue, - final GenericResultsetData grs) { - - List columnValues = grs.getData().get(0).getRow(); - - String columnValue = null; - for (int i = 0; i < grs.getColumnHeaders().size(); i++) { - - if (key.equals(grs.getColumnHeaders().get(i).getColumnName())) { - columnValue = columnValues.get(i); - - if (notTheSame(columnValue, keyValue)) { - logger.info("Difference - Column: " + key - + "- Current Value: " + columnValue - + " New Value: " + keyValue); - return true; - - } - return false; - } - } - - throw new PlatformDataIntegrityException( - "error.msg.invalid.columnName", "Parameter Column Name: " + key - + " not found"); - } - - private Map getAffectedColumns( - final List columnHeaders, - final Map queryParams, final String keyFieldName) { - - String dateFormat = queryParams.get("dateFormat"); - Locale clientApplicationLocale = null; - String localeQueryParam = queryParams.get("locale"); - if (!(StringUtils.isBlank(localeQueryParam))) - clientApplicationLocale = new Locale(queryParams.get("locale")); - - String underscore = "_"; - String space = " "; - String pValue = null; - String queryParamColumnUnderscored; - String columnHeaderUnderscored; - boolean notFound; - - Map affectedColumns = new HashMap(); - Set keys = queryParams.keySet(); - for (String key : keys) { - // ignores id and foreign key fields - // also ignores locale and dateformat fields that are used for - // validating numeric and date data - if (!((key.equalsIgnoreCase("id")) - || (key.equalsIgnoreCase(keyFieldName)) - || (key.equals("locale")) || (key.equals("dateFormat")))) { - notFound = true; - // matches incoming fields with and without underscores (spaces - // and underscores considered the same) - queryParamColumnUnderscored = genericDataService.replace(key, - space, underscore); - for (ResultsetColumnHeader columnHeader : columnHeaders) { - if (notFound) { - columnHeaderUnderscored = genericDataService - .replace(columnHeader.getColumnName(), space, - underscore); - if (queryParamColumnUnderscored - .equalsIgnoreCase(columnHeaderUnderscored)) { - pValue = queryParams.get(key); - pValue = validateColumn(columnHeader, pValue, - dateFormat, clientApplicationLocale); - affectedColumns.put(columnHeader.getColumnName(), - pValue); - notFound = false; - } - } - - } - if (notFound) { - throw new PlatformDataIntegrityException( - "error.msg.column.not.found", "Column: " + key - + " Not Found"); - } - } - } - return affectedColumns; - } - - private String validateColumn(final ResultsetColumnHeader columnHeader, - final String pValue, final String dateFormat, - final Locale clientApplicationLocale) { - - String paramValue = pValue; - - if ((StringUtils.isEmpty(paramValue)) - && (!(columnHeader.isColumnNullable()))) { - - List dataValidationErrors = new ArrayList(); - ApiParameterError error = ApiParameterError.parameterError( - "error.msg.column.mandatory", "Mandatory", - columnHeader.getColumnName()); - dataValidationErrors.add(error); - throw new PlatformApiDataValidationException( - "validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); - } - - if (!StringUtils.isEmpty(paramValue)) { - - if (columnHeader.getColumnValues().size() > 0) { - // match code value or id - List allowedValues = columnHeader - .getColumnValues(); - if (columnHeader.getColumnDisplayType().equals("CODEVALUE")) { - for (ResultsetColumnValue allowedValue : allowedValues) { - if (paramValue - .equalsIgnoreCase(allowedValue.getValue())) - return paramValue; - } - List dataValidationErrors = new ArrayList(); - ApiParameterError error = ApiParameterError.parameterError( - "error.msg.invalid.columnValue", - "Value not found in Allowed Value list", - columnHeader.getColumnName(), paramValue); - dataValidationErrors.add(error); - throw new PlatformApiDataValidationException( - "validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); - } - - if (columnHeader.getColumnDisplayType().equals("CODELOOKUP")) { - for (ResultsetColumnValue allowedValue : allowedValues) { - if (paramValue.equals(Integer.toString(allowedValue - .getId()))) - return paramValue; - } - List dataValidationErrors = new ArrayList(); - ApiParameterError error = ApiParameterError.parameterError( - "error.msg.invalid.columnValue", - "Value not found in Allowed Value list", - columnHeader.getColumnName(), paramValue); - dataValidationErrors.add(error); - throw new PlatformApiDataValidationException( - "validation.msg.validation.errors.exist", - "Validation errors exist.", dataValidationErrors); - } - - throw new PlatformDataIntegrityException( - "error.msg.invalid.columnType.", "Code: " - + columnHeader.getColumnName() - + " - Invalid Type " - + columnHeader.getColumnType() - + " (neither varchar nor int)"); - } - - JsonParserHelper helper = new JsonParserHelper(); - - if (columnHeader.getColumnDisplayType().equals("DATE")) - paramValue = helper.convertFrom(paramValue, - columnHeader.getColumnName(), dateFormat, - clientApplicationLocale).toString(); - - if (columnHeader.getColumnDisplayType().equals("INTEGER")) - paramValue = helper.convertToInteger(paramValue, - columnHeader.getColumnName(), clientApplicationLocale) - .toString(); - - if (columnHeader.getColumnDisplayType().equals("DECIMAL")) - paramValue = helper.convertFrom(paramValue, - columnHeader.getColumnName(), clientApplicationLocale) - .toString(); - // logger.info("Converted Value: " + paramValue + " - was: " + - // pValue); - - } - - return paramValue; - } - - private String getDeleteEntriesSql(final String datatable, - final String FKField, final Long appTableId) { - - return "delete from `" + datatable + "` where `" + FKField + "` = " - + appTableId; - - } - - private String getDeleteEntrySql(final String datatable, - final Long datatableId) { - - return "delete from `" + datatable + "` where `id` = " + datatableId; - - } - - private boolean notTheSame(final String currValue, final String pValue) { - if (StringUtils.isEmpty(currValue) && StringUtils.isEmpty(pValue)) - return false; - - if (StringUtils.isEmpty(currValue)) - return true; - - if (StringUtils.isEmpty(pValue)) - return true; - - if (currValue.equals(pValue)) - return false; - - return true; - } + CachedRowSet rs = genericDataService.getCachedResultSet(sql, "SQL : " + sql); + + if (rs.size() == 0) throw new DataTableNotFoundException(appTable, appTableId); + } + + private String dataScopedSQL(final String unscopedSQL, final String appTable) { + String dataScopeCriteria = null; + /* + * unfortunately have to, one way or another, be able to restrict data + * to the users office hierarchy. Here it's hardcoded for client and + * loan. They are the main application tables. But if additional fields + * are needed on other tables like group, loan_transaction or others the + * same applies (hardcoding of some sort) + */ + + AppUser currentUser = context.authenticatedUser(); + if (appTable.equalsIgnoreCase("m_client")) { + dataScopeCriteria = " join m_office o on o.id = t.office_id and o.hierarchy like '" + currentUser.getOffice().getHierarchy() + + "%'"; + } + if (appTable.equalsIgnoreCase("m_loan")) { + dataScopeCriteria = " join m_client c on c.id = t.client_id " + " join m_office o on o.id = c.office_id and o.hierarchy like '" + + currentUser.getOffice().getHierarchy() + "%'"; + } + + if (dataScopeCriteria == null) { throw new PlatformDataIntegrityException("error.msg.invalid.dataScopeCriteria", + "Application Table: " + appTable + " not catered for in data Scoping"); } + + return genericDataService.replace(unscopedSQL, "${dataScopeCriteria}", dataScopeCriteria); + + } + + private void validateAppTable(final String appTable) { + + if (appTable.equalsIgnoreCase("m_client")) return; + if (appTable.equalsIgnoreCase("m_loan")) return; + + throw new PlatformDataIntegrityException("error.msg.invalid.application.table", "Invalid Application Table: " + appTable); + } + + private List fillDatatableResultSetDataRows(final String sql) { + + String sqlErrorMsg = "Sql: " + sql; + CachedRowSet rs = genericDataService.getCachedResultSet(sql, sqlErrorMsg); + + List resultsetDataRows = new ArrayList(); + + try { + + ResultSetMetaData rsmd = rs.getMetaData(); + int columnCount = rsmd.getColumnCount(); + + ResultsetDataRow resultsetDataRow; + String columnName = null; + String columnValue = null; + while (rs.next()) { + resultsetDataRow = new ResultsetDataRow(); + List columnValues = new ArrayList(); + for (int i = 0; i < columnCount; i++) { + columnName = rsmd.getColumnName(i + 1); + columnValue = rs.getString(columnName); + columnValues.add(columnValue); + } + resultsetDataRow.setRow(columnValues); + resultsetDataRows.add(resultsetDataRow); + } + + return resultsetDataRows; + } catch (SQLException e) { + throw new PlatformDataIntegrityException("error.msg.sql.error", e.getMessage(), sqlErrorMsg); + } + } + + private String getWithinScopeApplicationTableName(final String datatable, final Long appTableId) { + String sql = "SELECT application_table_name FROM x_registered_table where registered_table_name = '" + datatable + "'"; + + CachedRowSet rs = genericDataService.getCachedResultSet(sql, "SQL : " + sql); + + if (rs.size() == 0) throw new DataTableNotFoundException(datatable); + + try { + rs.next(); + String appTable = rs.getString("application_table_name"); + + checkMainResourceExistsWithinScope(appTable, appTableId); + + return appTable; + } catch (SQLException e) { + throw new PlatformDataIntegrityException("error.msg.sql.error", e.getMessage()); + } + } + + private String getApplicationTableName(final String datatable) { + // TODO - only used for update... can probably remove this after as its + // a reread + String sql = "SELECT application_table_name FROM x_registered_table where registered_table_name = '" + datatable + "'"; + + CachedRowSet rs = genericDataService.getCachedResultSet(sql, "SQL : " + sql); + + if (rs.size() == 0) throw new DataTableNotFoundException(datatable); + + try { + rs.next(); + return rs.getString("application_table_name"); + } catch (SQLException e) { + throw new PlatformDataIntegrityException("error.msg.sql.error", e.getMessage()); + } + } + + private String getFKField(final String applicationTableName) { + + return applicationTableName.substring(2) + "_id"; + } + + private CachedRowSet getDatatableMetaData(final String datatable) { + + String sql = "select COLUMN_NAME, IS_NULLABLE, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, COLUMN_KEY" + + " from INFORMATION_SCHEMA.COLUMNS " + " where TABLE_SCHEMA = schema() and TABLE_NAME = '" + datatable + + "'order by ORDINAL_POSITION"; + + CachedRowSet columnDefinitions = genericDataService.getCachedResultSet(sql, "SQL: " + sql); + + if (columnDefinitions.size() > 0) return columnDefinitions; + + throw new DataTableNotFoundException(datatable); + } + + private List getDatatableResultsetColumnHeaders(final String datatable) { + + CachedRowSet columnDefinitions = getDatatableMetaData(datatable); + + List columnHeaders = new ArrayList(); + + try { + + while (columnDefinitions.next()) { + ResultsetColumnHeader rsch = new ResultsetColumnHeader(); + + rsch.setColumnName(columnDefinitions.getString("COLUMN_NAME")); + + String isNullable = columnDefinitions.getString("IS_NULLABLE"); + if (isNullable.equalsIgnoreCase("YES")) + rsch.setColumnNullable(true); + else + rsch.setColumnNullable(false); + + String isPrimaryKey = columnDefinitions.getString("COLUMN_KEY"); + if (isPrimaryKey.equalsIgnoreCase("PRI")) + rsch.setColumnPrimaryKey(true); + else + rsch.setColumnPrimaryKey(false); + + Long columnLength = columnDefinitions.getLong("CHARACTER_MAXIMUM_LENGTH"); + if (columnLength > 0) rsch.setColumnLength(columnDefinitions.getLong("CHARACTER_MAXIMUM_LENGTH")); + + rsch.setColumnType(columnDefinitions.getString("DATA_TYPE")); + + /* look for codes */ + if (rsch.getColumnType().equalsIgnoreCase("varchar")) addCodesValueIfNecessary(rsch, "_cv"); + + if (rsch.getColumnType().equalsIgnoreCase("int")) addCodesValueIfNecessary(rsch, "_cd"); + + rsch.setColumnDisplayType(); + + columnHeaders.add(rsch); + } + ; + return columnHeaders; + + } catch (SQLException e) { + throw new PlatformDataIntegrityException("error.msg.sql.error", e.getMessage()); + } + + } + + private void addCodesValueIfNecessary(final ResultsetColumnHeader rsch, final String code_suffix) { + int codePosition = rsch.getColumnName().indexOf(code_suffix); + if (codePosition > 0) { + String codeName = rsch.getColumnName().substring(0, codePosition); + + String sql = "select v.id, v.code_value from m_code m " + " join m_code_value v on v.code_id = m.id " + + " where m.code_name = '" + codeName + "' order by v.order_position, v.id"; + + CachedRowSet rsValues = genericDataService.getCachedResultSet(sql, "SQL: " + sql); + + try { + while (rsValues.next()) { + rsch.getColumnValues().add(new ResultsetColumnValue(rsValues.getInt("id"), rsValues.getString("code_value"))); + } + } catch (SQLException e) { + throw new PlatformDataIntegrityException("error.msg.sql.error", e.getMessage()); + } + } + + } + + private String getAddSql(final List columnHeaders, final String datatable, final String fkName, + final Long appTableId, final Map queryParams) { + + final Map affectedColumns = getAffectedColumns(columnHeaders, queryParams, fkName); + + String pValueWrite = ""; + String addSql = ""; + String singleQuote = "'"; + + String insertColumns = ""; + String selectColumns = ""; + String columnName = ""; + String pValue = null; + for (String key : affectedColumns.keySet()) { + pValue = affectedColumns.get(key); + + if (StringUtils.isEmpty(pValue)) { + pValueWrite = "null"; + } else { + pValueWrite = singleQuote + genericDataService.replace(pValue, singleQuote, singleQuote + singleQuote) + singleQuote; + } + columnName = "`" + key + "`"; + insertColumns += ", " + columnName; + selectColumns += "," + pValueWrite + " as " + columnName; + } + + addSql = "insert into `" + datatable + "` (`" + fkName + "` " + insertColumns + ")" + " select " + appTableId + " as id" + + selectColumns; + + return addSql; + } + + private String getUpdateSql(final String datatable, final String keyFieldName, final Long keyFieldValue, + final Map changedColumns) { + + // just updating fields that have changed since pre-update read - though + // its possible these values are different from the page the user was + // looking at and even different from the current db values (if some + // other update got in quick) - would need a version field for + // completeness but its okay to take this risk with additional fields + // data + + if (changedColumns.size() == 0) return null; + + String pValue = null; + String pValueWrite = ""; + String singleQuote = "'"; + boolean firstColumn = true; + String sql = "update `" + datatable + "` "; + + for (String key : changedColumns.keySet()) { + if (firstColumn) { + sql += " set "; + firstColumn = false; + } else { + sql += ", "; + } + + pValue = (String) changedColumns.get(key); + if (StringUtils.isEmpty(pValue)) { + pValueWrite = "null"; + } else { + pValueWrite = singleQuote + genericDataService.replace(pValue, singleQuote, singleQuote + singleQuote) + singleQuote; + } + sql += "`" + key + "` = " + pValueWrite; + } + + sql += " where " + keyFieldName + " = " + keyFieldValue; + + return sql; + } + + private Map getAffectedAndChangedColumns(final GenericResultsetData grs, final Map queryParams, + final String fkName) { + + Map affectedColumns = getAffectedColumns(grs.getColumnHeaders(), queryParams, fkName); + Map affectedAndChangedColumns = new HashMap(); + String columnValue; + + for (String key : affectedColumns.keySet()) { + columnValue = affectedColumns.get(key); + if (columnChanged(key, columnValue, grs)) { + affectedAndChangedColumns.put(key, columnValue); + } + } + + return affectedAndChangedColumns; + } + + private boolean columnChanged(final String key, final String keyValue, final GenericResultsetData grs) { + + List columnValues = grs.getData().get(0).getRow(); + + String columnValue = null; + for (int i = 0; i < grs.getColumnHeaders().size(); i++) { + + if (key.equals(grs.getColumnHeaders().get(i).getColumnName())) { + columnValue = columnValues.get(i); + + if (notTheSame(columnValue, keyValue)) { + logger.info("Difference - Column: " + key + "- Current Value: " + columnValue + " New Value: " + keyValue); + return true; + + } + return false; + } + } + + throw new PlatformDataIntegrityException("error.msg.invalid.columnName", "Parameter Column Name: " + key + " not found"); + } + + private Map getAffectedColumns(final List columnHeaders, final Map queryParams, + final String keyFieldName) { + + String dateFormat = queryParams.get("dateFormat"); + Locale clientApplicationLocale = null; + String localeQueryParam = queryParams.get("locale"); + if (!(StringUtils.isBlank(localeQueryParam))) clientApplicationLocale = new Locale(queryParams.get("locale")); + + String underscore = "_"; + String space = " "; + String pValue = null; + String queryParamColumnUnderscored; + String columnHeaderUnderscored; + boolean notFound; + + Map affectedColumns = new HashMap(); + Set keys = queryParams.keySet(); + for (String key : keys) { + // ignores id and foreign key fields + // also ignores locale and dateformat fields that are used for + // validating numeric and date data + if (!((key.equalsIgnoreCase("id")) || (key.equalsIgnoreCase(keyFieldName)) || (key.equals("locale")) || (key + .equals("dateFormat")))) { + notFound = true; + // matches incoming fields with and without underscores (spaces + // and underscores considered the same) + queryParamColumnUnderscored = genericDataService.replace(key, space, underscore); + for (ResultsetColumnHeader columnHeader : columnHeaders) { + if (notFound) { + columnHeaderUnderscored = genericDataService.replace(columnHeader.getColumnName(), space, underscore); + if (queryParamColumnUnderscored.equalsIgnoreCase(columnHeaderUnderscored)) { + pValue = queryParams.get(key); + pValue = validateColumn(columnHeader, pValue, dateFormat, clientApplicationLocale); + affectedColumns.put(columnHeader.getColumnName(), pValue); + notFound = false; + } + } + + } + if (notFound) { throw new PlatformDataIntegrityException("error.msg.column.not.found", "Column: " + key + " Not Found"); } + } + } + return affectedColumns; + } + + private String validateColumn(final ResultsetColumnHeader columnHeader, final String pValue, final String dateFormat, + final Locale clientApplicationLocale) { + + String paramValue = pValue; + + if ((StringUtils.isEmpty(paramValue)) && (!(columnHeader.isColumnNullable()))) { + + List dataValidationErrors = new ArrayList(); + ApiParameterError error = ApiParameterError.parameterError("error.msg.column.mandatory", "Mandatory", + columnHeader.getColumnName()); + dataValidationErrors.add(error); + throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", + dataValidationErrors); + } + + if (!StringUtils.isEmpty(paramValue)) { + + if (columnHeader.getColumnValues().size() > 0) { + // match code value or id + List allowedValues = columnHeader.getColumnValues(); + if (columnHeader.getColumnDisplayType().equals("CODEVALUE")) { + for (ResultsetColumnValue allowedValue : allowedValues) { + if (paramValue.equalsIgnoreCase(allowedValue.getValue())) return paramValue; + } + List dataValidationErrors = new ArrayList(); + ApiParameterError error = ApiParameterError.parameterError("error.msg.invalid.columnValue", + "Value not found in Allowed Value list", columnHeader.getColumnName(), paramValue); + dataValidationErrors.add(error); + throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", + dataValidationErrors); + } + + if (columnHeader.getColumnDisplayType().equals("CODELOOKUP")) { + for (ResultsetColumnValue allowedValue : allowedValues) { + if (paramValue.equals(Integer.toString(allowedValue.getId()))) return paramValue; + } + List dataValidationErrors = new ArrayList(); + ApiParameterError error = ApiParameterError.parameterError("error.msg.invalid.columnValue", + "Value not found in Allowed Value list", columnHeader.getColumnName(), paramValue); + dataValidationErrors.add(error); + throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", + dataValidationErrors); + } + + throw new PlatformDataIntegrityException("error.msg.invalid.columnType.", "Code: " + columnHeader.getColumnName() + + " - Invalid Type " + columnHeader.getColumnType() + " (neither varchar nor int)"); + } + + JsonParserHelper helper = new JsonParserHelper(); + + if (columnHeader.getColumnDisplayType().equals("DATE")) + paramValue = helper.convertFrom(paramValue, columnHeader.getColumnName(), dateFormat, clientApplicationLocale).toString(); + + if (columnHeader.getColumnDisplayType().equals("INTEGER")) + paramValue = helper.convertToInteger(paramValue, columnHeader.getColumnName(), clientApplicationLocale).toString(); + + if (columnHeader.getColumnDisplayType().equals("DECIMAL")) + paramValue = helper.convertFrom(paramValue, columnHeader.getColumnName(), clientApplicationLocale).toString(); + // logger.info("Converted Value: " + paramValue + " - was: " + + // pValue); + + } + + return paramValue; + } + + private String getDeleteEntriesSql(final String datatable, final String FKField, final Long appTableId) { + + return "delete from `" + datatable + "` where `" + FKField + "` = " + appTableId; + + } + + private String getDeleteEntrySql(final String datatable, final Long datatableId) { + + return "delete from `" + datatable + "` where `id` = " + datatableId; + + } + + private boolean notTheSame(final String currValue, final String pValue) { + if (StringUtils.isEmpty(currValue) && StringUtils.isEmpty(pValue)) return false; + + if (StringUtils.isEmpty(currValue)) return true; + + if (StringUtils.isEmpty(pValue)) return true; + + if (currValue.equals(pValue)) return false; + + return true; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/api/DocumentManagementApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/api/DocumentManagementApiResource.java index 194737d82..3305c77de 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/api/DocumentManagementApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/api/DocumentManagementApiResource.java @@ -24,7 +24,7 @@ import javax.ws.rs.core.UriInfo; import org.mifosplatform.infrastructure.core.api.ApiConstants; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer; import org.mifosplatform.infrastructure.core.service.FileUtils; @@ -106,7 +106,7 @@ public class DocumentManagementApiResource { Long documentId = this.documentWritePlatformService.createDocument(documentCommand, inputStream); - return this.toApiJsonSerializer.serialize(EntityIdentifier.resourceResult(documentId, null)); + return this.toApiJsonSerializer.serialize(CommandProcessingResult.resourceResult(documentId, null)); } @PUT @@ -141,7 +141,7 @@ public class DocumentManagementApiResource { documentCommand = new DocumentCommand(modifiedParams, documentId, entityType, entityId, name, null, null, null, description, null); } - EntityIdentifier identifier = this.documentWritePlatformService.updateDocument(documentCommand, inputStream); + CommandProcessingResult identifier = this.documentWritePlatformService.updateDocument(documentCommand, inputStream); return this.toApiJsonSerializer.serialize(identifier); } @@ -189,7 +189,7 @@ public class DocumentManagementApiResource { final DocumentCommand documentCommand = new DocumentCommand(null, documentId, entityType, entityId, null, null, null, null, null, null); - final EntityIdentifier documentIdentifier = this.documentWritePlatformService.deleteDocument(documentCommand); + final CommandProcessingResult documentIdentifier = this.documentWritePlatformService.deleteDocument(documentCommand); return this.toApiJsonSerializer.serialize(documentIdentifier); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentWritePlatformService.java index 8d94dbac0..371e37a67 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentWritePlatformService.java @@ -2,7 +2,7 @@ package org.mifosplatform.infrastructure.documentmanagement.service; import java.io.InputStream; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.documentmanagement.command.DocumentCommand; import org.springframework.security.access.prepost.PreAuthorize; @@ -12,9 +12,9 @@ public interface DocumentWritePlatformService { Long createDocument(DocumentCommand documentCommand, InputStream inputStream); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'UPDATE_m_guarantor_external')") - EntityIdentifier updateDocument(DocumentCommand documentCommand, InputStream inputStream); + CommandProcessingResult updateDocument(DocumentCommand documentCommand, InputStream inputStream); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'DELETE_m_guarantor_external')") - EntityIdentifier deleteDocument(DocumentCommand documentCommand); + CommandProcessingResult deleteDocument(DocumentCommand documentCommand); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java index fb46a6804..7428df18c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/documentmanagement/service/DocumentWritePlatformServiceJpaRepositoryImpl.java @@ -4,7 +4,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException; import org.mifosplatform.infrastructure.core.service.FileUtils; import org.mifosplatform.infrastructure.documentmanagement.command.DocumentCommand; @@ -77,7 +77,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr @Transactional @Override - public EntityIdentifier updateDocument(final DocumentCommand documentCommand, final InputStream inputStream) { + public CommandProcessingResult updateDocument(final DocumentCommand documentCommand, final InputStream inputStream) { try { context.authenticatedUser(); @@ -114,7 +114,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr this.documentRepository.saveAndFlush(documentForUpdate); - return new EntityIdentifier(documentForUpdate.getId()); + return new CommandProcessingResult(documentForUpdate.getId()); } catch (DataIntegrityViolationException dve) { logger.error(dve.getMessage(), dve); throw new PlatformDataIntegrityException("error.msg.document.unknown.data.integrity.issue", @@ -127,7 +127,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr @Transactional @Override - public EntityIdentifier deleteDocument(final DocumentCommand documentCommand) { + public CommandProcessingResult deleteDocument(final DocumentCommand documentCommand) { context.authenticatedUser(); validateParentEntityType(documentCommand); @@ -138,7 +138,7 @@ public class DocumentWritePlatformServiceJpaRepositoryImpl implements DocumentWr this.documentRepository.delete(document); deleteFile(document.getName(), document.getLocation()); - return new EntityIdentifier(document.getId()); + return new CommandProcessingResult(document.getId()); } private void deleteFile(String documentName, String location) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/api/CurrenciesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/api/CurrenciesApiResource.java index c6981d4da..01d0822ad 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/api/CurrenciesApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/api/CurrenciesApiResource.java @@ -13,9 +13,11 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -70,9 +72,11 @@ public class CurrenciesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String updateCurrencies(final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "CURRENCY", "UPDATE", "currencies", - null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateCurrencies().withUrl("/currencies").withJson(apiRequestBodyAsJson) + .build(); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + return this.toApiJsonSerializer.serialize(result); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/handler/UpdateCurrencyCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/handler/UpdateCurrencyCommandHandler.java index 45eaec31a..550ac8833 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/handler/UpdateCurrencyCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/handler/UpdateCurrencyCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.organisation.monetary.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.organisation.monetary.service.CurrencyWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class UpdateCurrencyCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.writePlatformService.updateAllowedCurrencies(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/service/CurrencyWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/service/CurrencyWritePlatformService.java index cc9601b08..d994dc191 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/service/CurrencyWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/service/CurrencyWritePlatformService.java @@ -1,10 +1,10 @@ package org.mifosplatform.organisation.monetary.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface CurrencyWritePlatformService { - EntityIdentifier updateAllowedCurrencies(JsonCommand command); + CommandProcessingResult updateAllowedCurrencies(JsonCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/service/CurrencyWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/service/CurrencyWritePlatformServiceJpaRepositoryImpl.java index 0733a06da..f8d546b6f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/service/CurrencyWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/monetary/service/CurrencyWritePlatformServiceJpaRepositoryImpl.java @@ -8,7 +8,8 @@ import java.util.Map; import java.util.Set; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.monetary.command.CurrencyCommand; import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency; @@ -42,7 +43,7 @@ public class CurrencyWritePlatformServiceJpaRepositoryImpl implements CurrencyWr @Transactional @Override - public EntityIdentifier updateAllowedCurrencies(final JsonCommand command) { + public CommandProcessingResult updateAllowedCurrencies(final JsonCommand command) { context.authenticatedUser(); @@ -69,6 +70,6 @@ public class CurrencyWritePlatformServiceJpaRepositoryImpl implements CurrencyWr this.organisationCurrencyRepository.deleteAll(); this.organisationCurrencyRepository.save(allowedCurrencies); - return EntityIdentifier.withChanges(null, changes); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).with(changes).build(); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/api/OfficeTransactionsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/api/OfficeTransactionsApiResource.java index 66b18e32f..644dc3339 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/api/OfficeTransactionsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/api/OfficeTransactionsApiResource.java @@ -14,9 +14,11 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -86,9 +88,10 @@ public class OfficeTransactionsApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String transferMoneyFrom(final String apiRequestBodyAsJson) { + + final CommandWrapper commandRequest = new CommandWrapperBuilder().createOfficeTransaction().withUrl("/officetransactions").withJson(apiRequestBodyAsJson).build(); - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "OFFICETRANSACTION", "CREATE", - "officetransactions", null, apiRequestBodyAsJson); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/api/OfficesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/api/OfficesApiResource.java index 398dfebb9..c7a8811a7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/api/OfficesApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/api/OfficesApiResource.java @@ -18,10 +18,12 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.codes.data.CodeData; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -97,8 +99,10 @@ public class OfficesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String createOffice(final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "OFFICE", "CREATE", "offices", - null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().createOffice().withUrl("/offices").withJson(apiRequestBodyAsJson) + .build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -128,8 +132,10 @@ public class OfficesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String updateOffice(@PathParam("officeId") final Long officeId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "OFFICE", "UPDATE", "offices", - officeId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateOffice().withUrl("/offices").withEntityId(officeId) + .withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/handler/CreateOfficeCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/handler/CreateOfficeCommandHandler.java index 60c9c97af..f7b142fa9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/handler/CreateOfficeCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/handler/CreateOfficeCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.organisation.office.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.organisation.office.service.OfficeWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class CreateOfficeCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.writePlatformService.createOffice(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/handler/CreateOfficeTransactionCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/handler/CreateOfficeTransactionCommandHandler.java index 786edd6cc..78769004d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/handler/CreateOfficeTransactionCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/handler/CreateOfficeTransactionCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.organisation.office.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.organisation.office.service.OfficeWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class CreateOfficeTransactionCommandHandler implements NewCommandSourceHa @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.writePlatformService.externalBranchMoneyTransfer(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/handler/UpdateOfficeCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/handler/UpdateOfficeCommandHandler.java index 6e36b8d35..aa962ae8a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/handler/UpdateOfficeCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/handler/UpdateOfficeCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.organisation.office.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.organisation.office.service.OfficeWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class UpdateOfficeCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.updateOffice(command.resourceId(), command); + return this.writePlatformService.updateOffice(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeWritePlatformService.java index 16712569e..30b670b20 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeWritePlatformService.java @@ -1,13 +1,13 @@ package org.mifosplatform.organisation.office.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface OfficeWritePlatformService { - EntityIdentifier createOffice(JsonCommand command); + CommandProcessingResult createOffice(JsonCommand command); - EntityIdentifier updateOffice(Long officeId, JsonCommand command); + CommandProcessingResult updateOffice(Long officeId, JsonCommand command); - EntityIdentifier externalBranchMoneyTransfer(JsonCommand command); + CommandProcessingResult externalBranchMoneyTransfer(JsonCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java index f70a64e08..6501336e1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/office/service/OfficeWritePlatformServiceJpaRepositoryImpl.java @@ -3,7 +3,8 @@ package org.mifosplatform.organisation.office.service; import java.util.Map; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +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.exception.NoAuthorizationException; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -57,7 +58,7 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP @Transactional @Override - public EntityIdentifier createOffice(final JsonCommand command) { + public CommandProcessingResult createOffice(final JsonCommand command) { try { final AppUser currentUser = context.authenticatedUser(); @@ -76,16 +77,17 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP this.officeRepository.save(office); - return EntityIdentifier.resourceResult(office.getId(), null); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(office.getId()) + .withOfficeId(office.getId()).build(); } catch (DataIntegrityViolationException dve) { handleOfficeDataIntegrityIssues(command, dve); - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } } @Transactional @Override - public EntityIdentifier updateOffice(final Long officeId, final JsonCommand command) { + public CommandProcessingResult updateOffice(final Long officeId, final JsonCommand command) { try { final AppUser currentUser = context.authenticatedUser(); @@ -106,16 +108,17 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP this.officeRepository.saveAndFlush(office); } - return EntityIdentifier.withChanges(office.getId(), changes); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(office.getId()) + .withOfficeId(office.getId()).with(changes).build(); } catch (DataIntegrityViolationException dve) { handleOfficeDataIntegrityIssues(command, dve); - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } } @Transactional @Override - public EntityIdentifier externalBranchMoneyTransfer(final JsonCommand command) { + public CommandProcessingResult externalBranchMoneyTransfer(final JsonCommand command) { context.authenticatedUser(); @@ -123,13 +126,16 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP .json()); moneyTransferCommand.validateBranchTransfer(); + Long officeId = null; Office fromOffice = null; if (moneyTransferCommand.getFromOfficeId() != null) { fromOffice = this.officeRepository.findOne(moneyTransferCommand.getFromOfficeId()); + officeId = fromOffice.getId(); } Office toOffice = null; if (moneyTransferCommand.getToOfficeId() != null) { toOffice = this.officeRepository.findOne(moneyTransferCommand.getToOfficeId()); + officeId = toOffice.getId(); } if (fromOffice == null && toOffice == null) { throw new OfficeNotFoundException(moneyTransferCommand.getToOfficeId()); } @@ -145,7 +151,8 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP this.officeMonetaryTransferRepository.save(entity); - return EntityIdentifier.resourceResult(entity.getId(), null); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(entity.getId()).withOfficeId(officeId) + .build(); } /* diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/api/StaffApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/api/StaffApiResource.java index 2b48ce614..083225194 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/api/StaffApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/api/StaffApiResource.java @@ -18,9 +18,11 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; import org.apache.commons.lang.StringUtils; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -85,9 +87,11 @@ public class StaffApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String createStaff(final String apiRequestBodyAsJson) { + + final CommandWrapper commandRequest = new CommandWrapperBuilder().createStaff().withUrl("/staff").withJson(apiRequestBodyAsJson) + .build(); - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "STAFF", "CREATE", "staff", - null, apiRequestBodyAsJson); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -117,9 +121,11 @@ public class StaffApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String updateStaff(@PathParam("staffId") final Long staffId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "STAFF", "UPDATE", "staff", - staffId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateStaff().withUrl("/staff").withEntityId(staffId).withJson(apiRequestBodyAsJson) + .build(); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/domain/Staff.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/domain/Staff.java index 6072e6a90..96ac16446 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/domain/Staff.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/domain/Staff.java @@ -134,4 +134,8 @@ public class Staff extends AbstractAuditableCustom { public boolean identifiedBy(final Staff staff) { return getId().equals(staff.getId()); } + + public Long officeId() { + return this.office.getId(); + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/handler/CreateStaffCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/handler/CreateStaffCommandHandler.java index c87f6a33a..6bd2e8244 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/handler/CreateStaffCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/handler/CreateStaffCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.organisation.staff.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.organisation.staff.service.StaffWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class CreateStaffCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.writePlatformService.createStaff(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/handler/UpdateStaffCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/handler/UpdateStaffCommandHandler.java index ded418cba..d6052150a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/handler/UpdateStaffCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/handler/UpdateStaffCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.organisation.staff.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.organisation.staff.service.StaffWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class UpdateStaffCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.updateStaff(command.resourceId(), command); + return this.writePlatformService.updateStaff(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffWritePlatformService.java index 29432c6e9..fbc24c44f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffWritePlatformService.java @@ -1,11 +1,11 @@ package org.mifosplatform.organisation.staff.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface StaffWritePlatformService { - EntityIdentifier createStaff(final JsonCommand command); + CommandProcessingResult createStaff(final JsonCommand command); - EntityIdentifier updateStaff(final Long staffId, final JsonCommand command); + CommandProcessingResult updateStaff(final Long staffId, final JsonCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java index c10b6f943..7e50c8e4a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/organisation/staff/service/StaffWritePlatformServiceJpaRepositoryImpl.java @@ -4,7 +4,8 @@ import java.util.Map; import org.apache.commons.lang.StringUtils; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +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.organisation.office.domain.Office; @@ -44,7 +45,7 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla @Transactional @Override - public EntityIdentifier createStaff(final JsonCommand command) { + public CommandProcessingResult createStaff(final JsonCommand command) { try { context.authenticatedUser(); @@ -61,16 +62,17 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla this.staffRepository.save(staff); - return EntityIdentifier.resourceResult(staff.getId(), null); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(staff.getId()) + .withOfficeId(officeId).build(); } catch (DataIntegrityViolationException dve) { handleStaffDataIntegrityIssues(command, dve); - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } } @Transactional @Override - public EntityIdentifier updateStaff(final Long staffId, final JsonCommand command) { + public CommandProcessingResult updateStaff(final Long staffId, final JsonCommand command) { try { context.authenticatedUser(); @@ -78,7 +80,7 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla final StaffCommand staffCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json()); staffCommand.validateForUpdate(); - Staff staffForUpdate = this.staffRepository.findOne(staffId); + final Staff staffForUpdate = this.staffRepository.findOne(staffId); if (staffForUpdate == null) { throw new StaffNotFoundException(staffId); } final Map changesOnly = staffForUpdate.update(command); @@ -95,10 +97,11 @@ public class StaffWritePlatformServiceJpaRepositoryImpl implements StaffWritePla this.staffRepository.save(staffForUpdate); } - return EntityIdentifier.withChanges(staffForUpdate.getId(), changesOnly); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(staffId) + .withOfficeId(staffForUpdate.officeId()).with(changesOnly).build(); } catch (DataIntegrityViolationException dve) { handleStaffDataIntegrityIssues(command, dve); - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/api/ChargesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/api/ChargesApiResource.java index 7d766527d..1f34bb721 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/api/ChargesApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/api/ChargesApiResource.java @@ -17,9 +17,11 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -108,8 +110,10 @@ public class ChargesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String createCharge(final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "CHARGE", "CREATE", "charges", - null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().createCharge().withUrl("/charges").withJson(apiRequestBodyAsJson) + .build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -120,8 +124,10 @@ public class ChargesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String updateCharge(@PathParam("chargeId") final Long chargeId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "CHARGE", "UPDATE", "charges", - chargeId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateCharge().withUrl("/charges").withEntityId(chargeId) + .withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -132,8 +138,10 @@ public class ChargesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String deleteCharge(@PathParam("chargeId") final Long chargeId) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "CHARGE", "DELETE", "charges", - chargeId, "{}"); + final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteCharge().withUrl("/charges").withEntityId(chargeId) + .withJson("{}").build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/handler/CreateChargeDefinitionCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/handler/CreateChargeDefinitionCommandHandler.java index 2d41f75aa..c70d93427 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/handler/CreateChargeDefinitionCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/handler/CreateChargeDefinitionCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.charge.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.charge.service.ChargeWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class CreateChargeDefinitionCommandHandler implements NewCommandSourceHan @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.clientWritePlatformService.createCharge(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/handler/DeleteChargeDefinitionCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/handler/DeleteChargeDefinitionCommandHandler.java index 7679a4026..8201d0243 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/handler/DeleteChargeDefinitionCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/handler/DeleteChargeDefinitionCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.charge.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.charge.service.ChargeWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class DeleteChargeDefinitionCommandHandler implements NewCommandSourceHan @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.clientWritePlatformService.deleteCharge(command.resourceId()); + return this.clientWritePlatformService.deleteCharge(command.entityId()); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/handler/UpdateChargeDefinitionCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/handler/UpdateChargeDefinitionCommandHandler.java index c53109b38..a1d225179 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/handler/UpdateChargeDefinitionCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/handler/UpdateChargeDefinitionCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.charge.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.charge.service.ChargeWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class UpdateChargeDefinitionCommandHandler implements NewCommandSourceHan @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.clientWritePlatformService.updateCharge(command.resourceId(), command); + return this.clientWritePlatformService.updateCharge(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeWritePlatformService.java index 2b1220bec..411bbca03 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeWritePlatformService.java @@ -1,13 +1,13 @@ package org.mifosplatform.portfolio.charge.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface ChargeWritePlatformService { - EntityIdentifier createCharge(JsonCommand command); + CommandProcessingResult createCharge(JsonCommand command); - EntityIdentifier updateCharge(Long chargeId, JsonCommand command); + CommandProcessingResult updateCharge(Long chargeId, JsonCommand command); - EntityIdentifier deleteCharge(Long chargeId); + CommandProcessingResult deleteCharge(Long chargeId); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeWritePlatformServiceJpaRepositoryImpl.java index 714d34a43..6c3138a9b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/charge/service/ChargeWritePlatformServiceJpaRepositoryImpl.java @@ -3,7 +3,8 @@ package org.mifosplatform.portfolio.charge.service; import java.util.Map; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +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.charge.command.ChargeDefinitionCommand; @@ -28,9 +29,8 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP private final ChargeRepository chargeRepository; @Autowired - public ChargeWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, - final ChargeDefinitionCommandFromApiJsonDeserializer fromApiJsonDeserializer, - final ChargeRepository chargeRepository) { + public ChargeWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, + final ChargeDefinitionCommandFromApiJsonDeserializer fromApiJsonDeserializer, final ChargeRepository chargeRepository) { this.context = context; this.fromApiJsonDeserializer = fromApiJsonDeserializer; this.chargeRepository = chargeRepository; @@ -38,63 +38,63 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP @Transactional @Override - public EntityIdentifier createCharge(final JsonCommand command) { + public CommandProcessingResult createCharge(final JsonCommand command) { try { this.context.authenticatedUser(); - + final ChargeDefinitionCommand chargeDefinitionCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json()); chargeDefinitionCommand.validateForCreate(); final Charge charge = Charge.fromJson(command); this.chargeRepository.save(charge); - return EntityIdentifier.resourceResult(charge.getId(), null); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(charge.getId()).build(); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } } @Transactional @Override - public EntityIdentifier updateCharge(final Long chargeId, final JsonCommand command) { + public CommandProcessingResult updateCharge(final Long chargeId, final JsonCommand command) { try { this.context.authenticatedUser(); - + final ChargeDefinitionCommand chargeDefinitionCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json()); chargeDefinitionCommand.validateForUpdate(); final Charge chargeForUpdate = this.chargeRepository.findOne(chargeId); if (chargeForUpdate == null) { throw new ChargeNotFoundException(chargeId); } - + final Map changes = chargeForUpdate.update(command); if (!changes.isEmpty()) { this.chargeRepository.save(chargeForUpdate); } - return EntityIdentifier.withChanges(chargeForUpdate.getId(), changes); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(chargeId).with(changes).build(); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } } @Transactional @Override - public EntityIdentifier deleteCharge(final Long chargeId) { + public CommandProcessingResult deleteCharge(final Long chargeId) { this.context.authenticatedUser(); final Charge chargeForDelete = this.chargeRepository.findOne(chargeId); if (chargeForDelete == null || chargeForDelete.isDeleted()) { throw new ChargeNotFoundException(chargeId); } - + chargeForDelete.delete(); chargeRepository.save(chargeForDelete); - return EntityIdentifier.resourceResult(chargeForDelete.getId(), null); + return new CommandProcessingResultBuilder().withEntityId(chargeForDelete.getId()).build(); } /* @@ -104,10 +104,11 @@ public class ChargeWritePlatformServiceJpaRepositoryImpl implements ChargeWriteP private void handleDataIntegrityIssues(final JsonCommand command, final DataIntegrityViolationException dve) { Throwable realCause = dve.getMostSpecificCause(); - if (realCause.getMessage().contains("name")) { + if (realCause.getMessage().contains("name")) { final String name = command.stringValueOfParameterNamed("name"); - throw new PlatformDataIntegrityException("error.msg.charge.duplicate.name", - "Charge with name `" + name +"` already exists", "name", name); } + throw new PlatformDataIntegrityException("error.msg.charge.duplicate.name", "Charge with name `" + name + "` already exists", + "name", name); + } logger.error(dve.getMessage(), dve); throw new PlatformDataIntegrityException("error.msg.charge.unknown.data.integrity.issue", diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientIdentifiersApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientIdentifiersApiResource.java index b264d4869..96ceab855 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientIdentifiersApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientIdentifiersApiResource.java @@ -17,11 +17,13 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.codes.data.CodeValueData; import org.mifosplatform.infrastructure.codes.service.CodeValueReadPlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -98,8 +100,10 @@ public class ClientIdentifiersApiResource { public String createClientIdentifier(@PathParam("clientId") final Long clientId, final String apiRequestBodyAsJson) { try { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "CLIENTIDENTIFIER", "CREATE", - "clients", clientId, "identifiers", null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().createClientIdentifier().withClientId(clientId) + .withUrl("/clients/" + clientId + "/identifiers").withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } catch (DuplicateClientIdentifierException e) { @@ -143,8 +147,11 @@ public class ClientIdentifiersApiResource { @PathParam("identifierId") final Long clientIdentifierId, final String apiRequestBodyAsJson) { try { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "CLIENTIDENTIFIER", "UPDATE", - "clients", clientId, "identifiers", clientIdentifierId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateClientIdentifier() + .withUrl("/clients/" + clientId + "/identifiers").withClientId(clientId).withEntityId(clientIdentifierId) + .withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } catch (DuplicateClientIdentifierException e) { @@ -166,8 +173,11 @@ public class ClientIdentifiersApiResource { public String deleteClientIdentifier(@PathParam("clientId") final Long clientId, @PathParam("identifierId") final Long clientIdentifierId) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "CLIENTIDENTIFIER", "DELETE", - "clients", clientId, "identifiers", clientIdentifierId, "{}"); + final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteClientIdentifier() + .withUrl("/clients/" + clientId + "/identifiers").withClientId(clientId).withEntityId(clientIdentifierId).withJson("{}") + .build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientImagesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientImagesApiResource.java index 970e9ab22..74f6f1b12 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientImagesApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientImagesApiResource.java @@ -14,7 +14,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.mifosplatform.infrastructure.core.api.ApiConstants; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.domain.Base64EncodedImage; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.core.service.FileUtils; @@ -69,7 +69,7 @@ public class ClientImagesApiResource { FileUtils.validateImageMimeType(bodyPart.getMediaType().toString()); FileUtils.validateFileSizeWithinPermissibleRange(fileSize, fileDetails.getFileName(), ApiConstants.MAX_FILE_UPLOAD_SIZE_IN_MB); - final EntityIdentifier result = this.clientWritePlatformService.saveOrUpdateClientImage(clientId, fileDetails.getFileName(), + final CommandProcessingResult result = this.clientWritePlatformService.saveOrUpdateClientImage(clientId, fileDetails.getFileName(), inputStream); return this.toApiJsonSerializer.serialize(result); @@ -85,7 +85,7 @@ public class ClientImagesApiResource { final Base64EncodedImage base64EncodedImage = FileUtils.extractImageFromDataURL(jsonRequestBody); - final EntityIdentifier result = this.clientWritePlatformService.saveOrUpdateClientImage(clientId, base64EncodedImage); + final CommandProcessingResult result = this.clientWritePlatformService.saveOrUpdateClientImage(clientId, base64EncodedImage); return this.toApiJsonSerializer.serialize(result); } @@ -127,7 +127,7 @@ public class ClientImagesApiResource { public String deleteClientImage(@PathParam("clientId") final Long clientId) { this.clientWritePlatformService.deleteClientImage(clientId); - return this.toApiJsonSerializer.serialize(new EntityIdentifier(clientId)); + return this.toApiJsonSerializer.serialize(new CommandProcessingResult(clientId)); } /** diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientNotesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientNotesApiResource.java index 8d0bacabd..ed73f3109 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientNotesApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientNotesApiResource.java @@ -16,9 +16,11 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -71,8 +73,10 @@ public class ClientNotesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String addNewClientNote(@PathParam("clientId") final Long clientId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "CLIENTNOTE", "CREATE", - "clients", clientId, "notes", null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().createClientNote().withUrl("/clients/" + clientId + "/notes") + .withClientId(clientId).withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -99,8 +103,10 @@ public class ClientNotesApiResource { public String updateClientNote(@PathParam("clientId") final Long clientId, @PathParam("noteId") final Long noteId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "CLIENTNOTE", "UPDATE", - "clients", clientId, "notes", noteId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateClientNote().withUrl("/clients/" + clientId + "/notes") + .withClientId(clientId).withEntityId(noteId).withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientsApiResource.java index d264edccd..a73e9c0a6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientsApiResource.java @@ -22,12 +22,14 @@ import javax.ws.rs.core.UriInfo; import org.apache.commons.lang.StringUtils; import org.mifosplatform.commands.data.CommandSourceData; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.commands.service.PortfolioCommandsReadPlatformService; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -89,7 +91,8 @@ public class ClientsApiResource { // FIXME - kw - rather than exposing SQL through the api can we not just // pass parameter we want to search by and build up sql like is done for // other parameters? - final String extraCriteria = buildSqlStringFromClientCriteria(sqlSearch, officeId, externalId, displayName, firstName, lastName, hierarchy); + final String extraCriteria = buildSqlStringFromClientCriteria(sqlSearch, officeId, externalId, displayName, firstName, lastName, + hierarchy); final Collection clients = this.clientReadPlatformService.retrieveAllIndividualClients(extraCriteria); @@ -150,7 +153,8 @@ public class ClientsApiResource { ClientData clientData = this.clientReadPlatformService.retrieveIndividualClient(clientId); if (settings.isTemplate()) { - // FIXME - KW - no need for special OfficeLookup object, just use OfficeData and only populate with id, name, nameDecorated + // FIXME - KW - no need for special OfficeLookup object, just use + // OfficeData and only populate with id, name, nameDecorated final List allowedOffices = new ArrayList(officeReadPlatformService.retrieveAllOfficesForLookup()); clientData = ClientData.templateOnTop(clientData, allowedOffices); } @@ -216,8 +220,10 @@ public class ClientsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String createClient(final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "CLIENT", "CREATE", "clients", - null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().createClient().withUrl("/clients").withJson(apiRequestBodyAsJson) + .build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -228,8 +234,10 @@ public class ClientsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String updateClient(@PathParam("clientId") final Long clientId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "CLIENT", "UPDATE", "clients", - clientId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateClient().withUrl("/clients").withEntityId(clientId) + .withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -240,8 +248,10 @@ public class ClientsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String deleteClient(@PathParam("clientId") final Long clientId) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "CLIENT", "DELETE", "clients", - clientId, "{}"); + final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteClient().withUrl("/clients").withEntityId(clientId) + .withJson("{}").build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java index 01b9e27c2..07a656509 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/domain/Client.java @@ -23,6 +23,7 @@ import org.springframework.data.jpa.domain.AbstractPersistable; @Table(name = "m_client") public class Client extends AbstractPersistable { + @SuppressWarnings("unused") @Column(name = "account_no", length=40, unique=true, nullable=false) private String accountNumber; @@ -81,7 +82,7 @@ public class Client extends AbstractPersistable { } private Client(final Office office, final String firstName, final String lastName, final LocalDate openingDate, final String externalId) { - this.accountNumber = new RandomPasswordGenerator(25).generate(); + this.accountNumber = new RandomPasswordGenerator(19).generate(); this.office = office; if (StringUtils.isNotBlank(externalId)) { this.externalId = externalId.trim(); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/CreateClientCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/CreateClientCommandHandler.java index e79135f26..a4c757991 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/CreateClientCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/CreateClientCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.client.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.client.service.ClientWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class CreateClientCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.clientWritePlatformService.createClient(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/CreateClientIdentifierCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/CreateClientIdentifierCommandHandler.java index b6683e5e0..4a13bdf57 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/CreateClientIdentifierCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/CreateClientIdentifierCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.client.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.client.service.ClientWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class CreateClientIdentifierCommandHandler implements NewCommandSourceHan @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.clientWritePlatformService.addClientIdentifier(command.resourceId(), command); + return this.clientWritePlatformService.addClientIdentifier(command.getClientId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/CreateClientNoteCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/CreateClientNoteCommandHandler.java index 10c5297ad..9e3e7126e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/CreateClientNoteCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/CreateClientNoteCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.client.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.client.service.ClientWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class CreateClientNoteCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.clientWritePlatformService.addClientNote(command.resourceId(), command); + return this.clientWritePlatformService.addClientNote(command.getClientId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/DeleteClientCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/DeleteClientCommandHandler.java index 654d8d777..efd27cae5 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/DeleteClientCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/DeleteClientCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.client.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.client.service.ClientWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class DeleteClientCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.clientWritePlatformService.deleteClient(command.resourceId()); + return this.clientWritePlatformService.deleteClient(command.entityId()); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/DeleteClientIdentifierCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/DeleteClientIdentifierCommandHandler.java index 9dccab29b..56744db57 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/DeleteClientIdentifierCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/DeleteClientIdentifierCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.client.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.client.service.ClientWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class DeleteClientIdentifierCommandHandler implements NewCommandSourceHan @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.clientWritePlatformService.deleteClientIdentifier(command.resourceId(), command.subResourceId(), command.commandId()); + return this.clientWritePlatformService.deleteClientIdentifier(command.getClientId(), command.entityId(), command.commandId()); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/UpdateClientCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/UpdateClientCommandHandler.java index 1c9712d09..0b75b56bd 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/UpdateClientCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/UpdateClientCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.client.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.client.service.ClientWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class UpdateClientCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.clientWritePlatformService.updateClient(command.resourceId(), command); + return this.clientWritePlatformService.updateClient(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/UpdateClientIdentifierCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/UpdateClientIdentifierCommandHandler.java index 3495d0bc9..2f7c91166 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/UpdateClientIdentifierCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/UpdateClientIdentifierCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.client.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.client.service.ClientWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class UpdateClientIdentifierCommandHandler implements NewCommandSourceHan @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.clientWritePlatformService.updateClientIdentifier(command.resourceId(), command.subResourceId(), command); + return this.clientWritePlatformService.updateClientIdentifier(command.getClientId(), command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/UpdateClientNoteCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/UpdateClientNoteCommandHandler.java index da0787837..f3b32a993 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/UpdateClientNoteCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/handler/UpdateClientNoteCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.client.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.client.service.ClientWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class UpdateClientNoteCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.clientWritePlatformService.updateClientNote(command.resourceId(), command.subResourceId(), command); + return this.clientWritePlatformService.updateClientNote(command.getClientId(), command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformService.java index d76ece0d8..3aa44b907 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformService.java @@ -3,34 +3,34 @@ package org.mifosplatform.portfolio.client.service; import java.io.InputStream; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.domain.Base64EncodedImage; import org.springframework.security.access.prepost.PreAuthorize; public interface ClientWritePlatformService { - EntityIdentifier createClient(JsonCommand command); + CommandProcessingResult createClient(JsonCommand command); - EntityIdentifier updateClient(Long clientId, JsonCommand command); + CommandProcessingResult updateClient(Long clientId, JsonCommand command); - EntityIdentifier deleteClient(Long clientId); + CommandProcessingResult deleteClient(Long clientId); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_CLIENTIMAGE')") - EntityIdentifier saveOrUpdateClientImage(Long clientId, String imageName, InputStream inputStream); + CommandProcessingResult saveOrUpdateClientImage(Long clientId, String imageName, InputStream inputStream); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_CLIENTIMAGE')") - EntityIdentifier saveOrUpdateClientImage(Long clientId, Base64EncodedImage encodedImage); + CommandProcessingResult saveOrUpdateClientImage(Long clientId, Base64EncodedImage encodedImage); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'DELETE_CLIENTIMAGE')") - EntityIdentifier deleteClientImage(Long clientId); + CommandProcessingResult deleteClientImage(Long clientId); - EntityIdentifier addClientNote(Long clientId, JsonCommand command); + CommandProcessingResult addClientNote(Long clientId, JsonCommand command); - EntityIdentifier updateClientNote(Long clientId, Long noteId, JsonCommand command); + CommandProcessingResult updateClientNote(Long clientId, Long noteId, JsonCommand command); - EntityIdentifier addClientIdentifier(Long clientId, JsonCommand command); + CommandProcessingResult addClientIdentifier(Long clientId, JsonCommand command); - EntityIdentifier updateClientIdentifier(Long clientId, Long clientIdentifierId, JsonCommand command); + CommandProcessingResult updateClientIdentifier(Long clientId, Long clientIdentifierId, JsonCommand command); - EntityIdentifier deleteClientIdentifier(Long clientId, Long clientIdentifierId, Long commandId); + CommandProcessingResult deleteClientIdentifier(Long clientId, Long clientIdentifierId, Long commandId); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java index e11ad7710..4b7267755 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java @@ -10,7 +10,8 @@ import org.mifosplatform.infrastructure.codes.domain.CodeValue; import org.mifosplatform.infrastructure.codes.domain.CodeValueRepository; import org.mifosplatform.infrastructure.codes.exception.CodeValueNotFoundException; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.core.domain.Base64EncodedImage; import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException; import org.mifosplatform.infrastructure.core.service.FileUtils; @@ -79,15 +80,17 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP @Transactional @Override - public EntityIdentifier deleteClient(final Long clientId) { + public CommandProcessingResult deleteClient(final Long clientId) { final Client client = this.clientRepository.findOne(clientId); if (client == null || client.isDeleted()) { throw new ClientNotFoundException(clientId); } + final Long officeId = client.getOffice().getId(); + client.delete(); this.clientRepository.save(client); - return EntityIdentifier.resourceResult(clientId, null); + return new CommandProcessingResultBuilder().withOfficeId(officeId).withClientId(clientId).withEntityId(clientId).build(); } /* @@ -111,7 +114,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP @Transactional @Override - public EntityIdentifier createClient(final JsonCommand command) { + public CommandProcessingResult createClient(final JsonCommand command) { try { context.authenticatedUser(); @@ -127,22 +130,24 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP final Client newClient = Client.fromJson(clientOffice, command); this.clientRepository.save(newClient); - - // now use client account identifier generator to generate proper account number + + // now use client account identifier generator to generate proper + // account number AccountIdentifierGenerator generator = new ClientAccountIdentifierGenerator(newClient.getId(), 9); newClient.updateAccountIdentifier(generator.generate()); this.clientRepository.save(newClient); - - return EntityIdentifier.resourceResult(newClient.getId(), null); + + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(clientOffice.getId()) + .withClientId(newClient.getId()).withEntityId(newClient.getId()).build(); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } } @Transactional @Override - public EntityIdentifier updateClient(final Long clientId, final JsonCommand command) { + public CommandProcessingResult updateClient(final Long clientId, final JsonCommand command) { try { context.authenticatedUser(); @@ -167,22 +172,23 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP this.clientRepository.save(clientForUpdate); } - return EntityIdentifier.withChanges(clientId, changes); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()) + .withOfficeId(clientForUpdate.getOffice().getId()).withClientId(clientId).withEntityId(clientId).with(changes).build(); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); - return new EntityIdentifier(Long.valueOf(-1)); + return new CommandProcessingResult(Long.valueOf(-1)); } } @Transactional @Override - public EntityIdentifier addClientNote(final Long clientId, final JsonCommand command) { + public CommandProcessingResult addClientNote(final Long clientId, final JsonCommand command) { context.authenticatedUser(); final ClientNoteCommand clientNoteCommand = this.clientNoteFromApiJsonDeserializer.commandFromApiJson(command.json()); clientNoteCommand.validate(); - + final Client clientForUpdate = this.clientRepository.findOne(clientId); if (clientForUpdate == null) { throw new ClientNotFoundException(clientId); } @@ -190,12 +196,13 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP this.noteRepository.save(note); - return EntityIdentifier.subResourceResult(clientId, note.getId(), command.commandId()); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(clientForUpdate.getOffice().getId()) + .withClientId(clientId).withEntityId(note.getId()).build(); } @Transactional @Override - public EntityIdentifier updateClientNote(final Long clientId, final Long noteId, final JsonCommand command) { + public CommandProcessingResult updateClientNote(final Long clientId, final Long noteId, final JsonCommand command) { context.authenticatedUser(); @@ -206,18 +213,21 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP if (noteForUpdate == null || noteForUpdate.isNotAgainstClientWithIdOf(clientId)) { throw new NoteNotFoundException(noteId, clientId, "client"); } + final Client client = this.clientRepository.findOne(clientId); + final Map changes = noteForUpdate.update(command); if (!changes.isEmpty()) { this.noteRepository.save(noteForUpdate); } - return EntityIdentifier.subResourceResult(clientId, noteId, command.commandId(), changes); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(client.getOffice().getId()) + .withClientId(clientId).withEntityId(noteId).with(changes).build(); } @Transactional @Override - public EntityIdentifier addClientIdentifier(final Long clientId, final JsonCommand command) { + public CommandProcessingResult addClientIdentifier(final Long clientId, final JsonCommand command) { context.authenticatedUser(); final ClientIdentifierCommand clientIdentifierCommand = this.clientIdentifierCommandFromApiJsonDeserializer @@ -241,16 +251,17 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP this.clientIdentifierRepository.save(clientIdentifier); - return EntityIdentifier.subResourceResult(clientId, clientIdentifier.getId(), command.commandId()); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(client.getOffice().getId()) + .withClientId(clientId).withEntityId(clientIdentifier.getId()).build(); } catch (DataIntegrityViolationException dve) { handleClientIdentifierDataIntegrityViolation(documentTypeLabel, documentTypeId, documentKey, dve); - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } } @Transactional @Override - public EntityIdentifier updateClientIdentifier(final Long clientId, final Long identifierId, final JsonCommand command) { + public CommandProcessingResult updateClientIdentifier(final Long clientId, final Long identifierId, final JsonCommand command) { context.authenticatedUser(); final ClientIdentifierCommand clientIdentifierCommand = this.clientIdentifierCommandFromApiJsonDeserializer @@ -291,10 +302,13 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP if (!changes.isEmpty()) { this.clientIdentifierRepository.saveAndFlush(clientIdentifierForUpdate); } - return EntityIdentifier.subResourceResult(clientId, identifierId, command.commandId(), changes); + + final Client client = this.clientRepository.findOne(clientId); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withOfficeId(client.getOffice().getId()) + .withClientId(clientId).withEntityId(identifierId).with(changes).build(); } catch (DataIntegrityViolationException dve) { handleClientIdentifierDataIntegrityViolation(documentTypeLabel, documentTypeId, documentKey, dve); - return new EntityIdentifier(Long.valueOf(-1)); + return new CommandProcessingResult(Long.valueOf(-1)); } } @@ -317,17 +331,19 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP @Transactional @Override - public EntityIdentifier deleteClientIdentifier(final Long clientId, final Long identifierId, final Long commandId) { + public CommandProcessingResult deleteClientIdentifier(final Long clientId, final Long identifierId, final Long commandId) { final ClientIdentifier clientIdentifier = this.clientIdentifierRepository.findOne(identifierId); if (clientIdentifier == null) { throw new ClientIdentifierNotFoundException(identifierId); } this.clientIdentifierRepository.delete(clientIdentifier); - return EntityIdentifier.subResourceResult(clientId, identifierId, commandId); + final Client client = this.clientRepository.findOne(clientId); + return new CommandProcessingResultBuilder().withCommandId(commandId).withOfficeId(client.getOffice().getId()) + .withClientId(clientId).withEntityId(identifierId).build(); } @Transactional @Override - public EntityIdentifier saveOrUpdateClientImage(Long clientId, String imageName, InputStream inputStream) { + public CommandProcessingResult saveOrUpdateClientImage(Long clientId, String imageName, InputStream inputStream) { try { final Client client = this.clientRepository.findOne(clientId); String imageUploadLocation = setupForClientImageUpdate(clientId, client); @@ -343,7 +359,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP @Transactional @Override - public EntityIdentifier deleteClientImage(final Long clientId) { + public CommandProcessingResult deleteClientImage(final Long clientId) { final Client client = this.clientRepository.findOne(clientId); if (client == null || client.isDeleted()) { throw new ClientNotFoundException(clientId); } @@ -356,7 +372,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP } @Override - public EntityIdentifier saveOrUpdateClientImage(final Long clientId, final Base64EncodedImage encodedImage) { + public CommandProcessingResult saveOrUpdateClientImage(final Long clientId, final Base64EncodedImage encodedImage) { try { final Client client = this.clientRepository.findOne(clientId); final String imageUploadLocation = setupForClientImageUpdate(clientId, client); @@ -386,10 +402,10 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP return imageUploadLocation; } - private EntityIdentifier updateClientImage(final Long clientId, final Client client, final String imageLocation) { + private CommandProcessingResult updateClientImage(final Long clientId, final Client client, final String imageLocation) { client.setImageKey(imageLocation); this.clientRepository.save(client); - return new EntityIdentifier(clientId); + return new CommandProcessingResult(clientId); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/api/FundsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/api/FundsApiResource.java index 2926902b1..f20c4e866 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/api/FundsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/api/FundsApiResource.java @@ -16,10 +16,12 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.codes.data.CodeData; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -76,8 +78,10 @@ public class FundsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String createFund(final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "FUND", "CREATE", "funds", null, - apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().createFund().withUrl("/funds").withJson(apiRequestBodyAsJson) + .build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -102,8 +106,10 @@ public class FundsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String updateFund(@PathParam("fundId") final Long fundId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "FUND", "UPDATE", "funds", - fundId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateFund().withUrl("/funds").withEntityId(fundId) + .withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/handler/CreateFundCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/handler/CreateFundCommandHandler.java index 8385a9f79..fbd8d8dfe 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/handler/CreateFundCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/handler/CreateFundCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.fund.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.fund.service.FundWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class CreateFundCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.writePlatformService.createFund(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/handler/UpdateFundCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/handler/UpdateFundCommandHandler.java index 639aff739..b62849997 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/handler/UpdateFundCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/handler/UpdateFundCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.fund.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.fund.service.FundWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class UpdateFundCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.updateFund(command.resourceId(), command); + return this.writePlatformService.updateFund(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/service/FundWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/service/FundWritePlatformService.java index 1b75f790c..7cb67002d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/service/FundWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/service/FundWritePlatformService.java @@ -1,11 +1,11 @@ package org.mifosplatform.portfolio.fund.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface FundWritePlatformService { - EntityIdentifier createFund(JsonCommand command); + CommandProcessingResult createFund(JsonCommand command); - EntityIdentifier updateFund(Long fundId, JsonCommand command); + CommandProcessingResult updateFund(Long fundId, JsonCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/service/FundWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/service/FundWritePlatformServiceJpaRepositoryImpl.java index 1e19a92e3..2e43baea5 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/service/FundWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/fund/service/FundWritePlatformServiceJpaRepositoryImpl.java @@ -3,7 +3,8 @@ package org.mifosplatform.portfolio.fund.service; import java.util.Map; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +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.fund.command.FundCommand; @@ -38,7 +39,7 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf @Transactional @Override - public EntityIdentifier createFund(final JsonCommand command) { + public CommandProcessingResult createFund(final JsonCommand command) { try { context.authenticatedUser(); @@ -50,16 +51,16 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf this.fundRepository.save(fund); - return EntityIdentifier.resourceResult(fund.getId(), null); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(fund.getId()).build(); } catch (DataIntegrityViolationException dve) { handleFundDataIntegrityIssues(command, dve); - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } } @Transactional @Override - public EntityIdentifier updateFund(final Long fundId, final JsonCommand command) { + public CommandProcessingResult updateFund(final Long fundId, final JsonCommand command) { try { context.authenticatedUser(); @@ -75,10 +76,10 @@ public class FundWritePlatformServiceJpaRepositoryImpl implements FundWritePlatf this.fundRepository.saveAndFlush(fund); } - return EntityIdentifier.withChanges(fund.getId(), changes); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(fund.getId()).with(changes).build(); } catch (DataIntegrityViolationException dve) { handleFundDataIntegrityIssues(command, dve); - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } } 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 271b084bd..41fca7776 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 @@ -22,7 +22,7 @@ import org.apache.commons.lang.StringUtils; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -156,7 +156,7 @@ public class GroupsApiResource { final GroupCommand command = this.apiDataConversionService.convertJsonToGroupCommand(null, jsonRequestBody); - EntityIdentifier entityIdentifier = this.groupWritePlatformService.createGroup(command); + CommandProcessingResult entityIdentifier = this.groupWritePlatformService.createGroup(command); return this.toApiJsonSerializer.serialize(entityIdentifier); } @@ -169,7 +169,7 @@ public class GroupsApiResource { final GroupCommand command = this.apiDataConversionService.convertJsonToGroupCommand(groupId, jsonRequestBody); - EntityIdentifier entityIdentifier = this.groupWritePlatformService.updateGroup(command); + CommandProcessingResult entityIdentifier = this.groupWritePlatformService.updateGroup(command); return this.toApiJsonSerializer.serialize(entityIdentifier); } @@ -180,7 +180,7 @@ public class GroupsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String deleteGroup(@PathParam("groupId") final Long groupId) { - EntityIdentifier entityIdentifier = this.groupWritePlatformService.deleteGroup(groupId); + CommandProcessingResult entityIdentifier = this.groupWritePlatformService.deleteGroup(groupId); return this.toApiJsonSerializer.serialize(entityIdentifier); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java index 3f3ed1450..7f0d73a81 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java @@ -23,7 +23,7 @@ import org.mifosplatform.useradministration.domain.AppUser; public class Group extends AbstractAuditableCustom { @SuppressWarnings("unused") - @ManyToOne + @ManyToOne @JoinColumn(name = "office_id", nullable = false) private Office office; @@ -33,13 +33,11 @@ public class Group extends AbstractAuditableCustom { @Column(name = "external_id", length = 100, unique = true) private String externalId; - @Column(name = "is_deleted", nullable=false) + @Column(name = "is_deleted", nullable = false) private boolean deleted = false; - + @ManyToMany - @JoinTable(name = "m_group_client", - joinColumns = @JoinColumn(name = "group_id"), - inverseJoinColumns = @JoinColumn(name = "client_id")) + @JoinTable(name = "m_group_client", joinColumns = @JoinColumn(name = "group_id"), inverseJoinColumns = @JoinColumn(name = "client_id")) private Set clientMembers; public Group() { @@ -48,10 +46,10 @@ public class Group extends AbstractAuditableCustom { this.clientMembers = new HashSet(); } - public static Group newGroup(Office office, String name, String externalId, Set clientMembers){ + public static Group newGroup(Office office, String name, String externalId, Set clientMembers) { return new Group(office, name, externalId, clientMembers); } - + public Group(Office office, String name, String externalId, Set clientMembers) { this.office = office; if (StringUtils.isNotBlank(name)) { @@ -64,11 +62,11 @@ public class Group extends AbstractAuditableCustom { } else { this.externalId = null; } - if (clientMembers != null){ + if (clientMembers != null) { this.clientMembers = clientMembers; } } - + public void update(final GroupCommand command, final Office groupOffice, final Set clientMembers) { if (command.isExternalIdChanged()) { this.externalId = command.getExternalId(); @@ -81,22 +79,23 @@ public class Group extends AbstractAuditableCustom { if (command.isNameChanged()) { this.name = command.getName(); } - - if (clientMembers != null && command.isClientMembersChanged()){ + + if (clientMembers != null && command.isClientMembersChanged()) { this.clientMembers = clientMembers; } } - - public void addClientMember(final Client member){ + + public void addClientMember(final Client member) { this.clientMembers.add(member); } - public boolean hasClientAsMember(final Client client){ + public boolean hasClientAsMember(final Client client) { return this.clientMembers.contains(client); } - + /** - * Delete is a soft delete. Updates flag on group so it wont appear in query/report results. + * Delete is a soft delete. Updates flag on group so it wont appear + * in query/report results. * * Any fields with unique constraints and prepended with id of record. */ diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformService.java index a6d07c2f0..8954c7812 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformService.java @@ -1,18 +1,18 @@ package org.mifosplatform.portfolio.group.service; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.group.command.GroupCommand; import org.springframework.security.access.prepost.PreAuthorize; public interface GroupWritePlatformService { @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_GROUP')") - EntityIdentifier createGroup(GroupCommand command); + CommandProcessingResult createGroup(GroupCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'UPDATE_GROUP')") - EntityIdentifier updateGroup(GroupCommand command); + CommandProcessingResult updateGroup(GroupCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'DELETE_GROUP')") - EntityIdentifier deleteGroup(Long groupId); + CommandProcessingResult deleteGroup(Long groupId); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformServiceJpaRepositoryImpl.java index 84ae0c1be..b86796d5d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupWritePlatformServiceJpaRepositoryImpl.java @@ -3,7 +3,7 @@ package org.mifosplatform.portfolio.group.service; import java.util.HashSet; import java.util.Set; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.office.domain.Office; @@ -50,7 +50,7 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla @Transactional @Override - public EntityIdentifier createGroup(GroupCommand command) { + public CommandProcessingResult createGroup(GroupCommand command) { try { this.context.authenticatedUser(); @@ -68,16 +68,16 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla this.groupRepository.saveAndFlush(newGroup); - return new EntityIdentifier(newGroup.getId()); + return new CommandProcessingResult(newGroup.getId()); } catch (DataIntegrityViolationException dve) { handleGroupDataIntegrityIssues(command, dve); - return new EntityIdentifier(Long.valueOf(-1)); + return new CommandProcessingResult(Long.valueOf(-1)); } } @Transactional @Override - public EntityIdentifier updateGroup(GroupCommand command) { + public CommandProcessingResult updateGroup(GroupCommand command) { try { context.authenticatedUser(); @@ -105,16 +105,16 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla groupRepository.saveAndFlush(groupForUpdate); - return new EntityIdentifier(groupForUpdate.getId()); + return new CommandProcessingResult(groupForUpdate.getId()); } catch (DataIntegrityViolationException dve) { handleGroupDataIntegrityIssues(command, dve); - return new EntityIdentifier(Long.valueOf(-1)); + return new CommandProcessingResult(Long.valueOf(-1)); } } @Transactional @Override - public EntityIdentifier deleteGroup(Long groupId) { + public CommandProcessingResult deleteGroup(Long groupId) { context.authenticatedUser(); @@ -125,7 +125,7 @@ public class GroupWritePlatformServiceJpaRepositoryImpl implements GroupWritePla groupForDelete.delete(); this.groupRepository.save(groupForDelete); - return new EntityIdentifier(groupId); + return new CommandProcessingResult(groupId); } private Set assembleSetOfClients(final GroupCommand command) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/BulkLoansApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/BulkLoansApiResource.java index d49660683..a3f28a0dc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/BulkLoansApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/BulkLoansApiResource.java @@ -16,9 +16,11 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; import org.joda.time.LocalDate; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -97,8 +99,10 @@ public class BulkLoansApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String loanReassignment(final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("BULKREASSIGN", "LOAN", "N/A", "loans", - null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().assignLoanOfficersInBulk().withUrl("/loans/loanreassignment") + .withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoanChargesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoanChargesApiResource.java index 68364b15b..4877d690d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoanChargesApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoanChargesApiResource.java @@ -19,9 +19,11 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; import org.apache.commons.lang.StringUtils; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; @@ -102,8 +104,10 @@ public class LoanChargesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String addLoanCharge(@PathParam("loanId") final Long loanId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "LOANCHARGE", "N/A", "loans", - loanId, "charges", null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().createLoanCharge().withUrl("/loans/" + loanId + "/charges") + .withLoanId(loanId).withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -115,8 +119,10 @@ public class LoanChargesApiResource { public String updateLoanCharge(@PathParam("loanId") final Long loanId, @PathParam("loanChargeId") final Long loanChargeId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "LOANCHARGE", "N/A", "loans", - loanId, "charges", loanChargeId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateLoanCharge().withUrl("/loans/" + loanId + "/charges") + .withLoanId(loanId).withEntityId(loanChargeId).withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -130,8 +136,10 @@ public class LoanChargesApiResource { String json = ""; if (is(commandParam, "waive")) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("WAIVE", "LOANCHARGE", "N/A", "loans", - loanId, "charges", loanChargeId, "{}"); + final CommandWrapper commandRequest = new CommandWrapperBuilder().waiveLoanCharge().withUrl("/loans/" + loanId + "/charges") + .withLoanId(loanId).withEntityId(loanChargeId).withJson("{}").build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); json = this.toApiJsonSerializer.serialize(result); } else { @@ -147,8 +155,10 @@ public class LoanChargesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String deleteLoanCharge(@PathParam("loanId") final Long loanId, @PathParam("chargeId") final Long loanChargeId) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "LOANCHARGE", "N/A", "loans", - loanId, "charges", loanChargeId, "{}"); + final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteLoanCharge().withUrl("/loans/" + loanId + "/charges") + .withLoanId(loanId).withEntityId(loanChargeId).withJson("{}").build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoanTransactionsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoanTransactionsApiResource.java index 44993ccb9..0818e9baf 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoanTransactionsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoanTransactionsApiResource.java @@ -16,9 +16,11 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; import org.apache.commons.lang.StringUtils; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; @@ -115,22 +117,25 @@ public class LoanTransactionsApiResource { public String executeLoanTransaction(@PathParam("loanId") final Long loanId, @QueryParam("command") final String commandParam, final String apiRequestBodyAsJson) { - EntityIdentifier result = null; + CommandWrapperBuilder builder = new CommandWrapperBuilder().withUrl("/loans/" + loanId + "/transactions").withLoanId(loanId) + .withJson(apiRequestBodyAsJson); + + CommandProcessingResult result = null; if (is(commandParam, "repayment")) { - result = this.commandsSourceWritePlatformService.logCommandSource("REPAYMENT", "LOAN", "N/A", "loans", loanId, "transactions", - null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = builder.loanRepaymentTransaction().build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, "waiveinterest")) { - result = this.commandsSourceWritePlatformService.logCommandSource("WAIVEINTERESTPORTION", "LOAN", "N/A", "loans", loanId, - "transactions", null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = builder.waiveInterestPortionTransaction().build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, "writeoff")) { - result = this.commandsSourceWritePlatformService.logCommandSource("WRITEOFF", "LOAN", "N/A", "loans", loanId, "transactions", - null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = builder.writeOffLoanTransaction().build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, "close-rescheduled")) { - result = this.commandsSourceWritePlatformService.logCommandSource("CLOSEASRESCHEDULED", "LOAN", "N/A", "loans", loanId, - "transactions", null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = builder.closeLoanAsRescheduledTransaction().build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, "close")) { - result = this.commandsSourceWritePlatformService - .logCommandSource("CLOSE", "LOAN", "N/A", "loans", loanId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = builder.closeLoanTransaction().build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } if (result == null) { throw new UnrecognizedQueryParamException("command", commandParam); } @@ -145,9 +150,13 @@ public class LoanTransactionsApiResource { public String adjustLoanTransaction(@PathParam("loanId") final Long loanId, @PathParam("transactionId") final Long transactionId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("ADJUST", "LOAN", "N/A", "loans", loanId, - "transactions", transactionId, apiRequestBodyAsJson); - + CommandWrapperBuilder builder = new CommandWrapperBuilder().withUrl("/loans/" + loanId + "/transactions").withLoanId(loanId).withEntityId(transactionId) + .withJson(apiRequestBodyAsJson); + final CommandWrapper commandRequest = builder.adjustTransaction().build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + return this.toApiJsonSerializer.serialize(result); } + } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java index 84add922c..79b8e25bc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java @@ -20,11 +20,13 @@ import javax.ws.rs.core.UriInfo; import org.apache.commons.lang.StringUtils; import org.joda.time.LocalDate; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; import org.mifosplatform.infrastructure.core.api.JsonQuery; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; @@ -331,8 +333,10 @@ public class LoansApiResource { return this.loanScheduleToApiJsonSerializer.serialize(settings, loanSchedule, new HashSet()); } - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "LOAN", "CREATE", "loans", null, - apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().createLoanApplication().withUrl("/loans") + .withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -343,8 +347,10 @@ public class LoansApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String modifyLoanApplication(@PathParam("loanId") final Long loanId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "LOAN", "UPDATE", "loans", - loanId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateLoanApplication().withUrl("/loans").withLoanId(loanId) + .withEntityId(loanId).withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -355,8 +361,10 @@ public class LoansApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String deleteLoanApplication(@PathParam("loanId") final Long loanId) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "LOAN", "DELETE", "loans", - loanId, "{}"); + final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteLoanApplication().withUrl("/loans").withLoanId(loanId) + .withEntityId(loanId).withJson("{}").build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -368,28 +376,31 @@ public class LoansApiResource { public String stateTransitions(@PathParam("loanId") final Long loanId, @QueryParam("command") final String commandParam, final String apiRequestBodyAsJson) { - EntityIdentifier result = null; + final CommandWrapperBuilder builder = new CommandWrapperBuilder().withUrl("/loans").withLoanId(loanId).withEntityId(loanId) + .withJson(apiRequestBodyAsJson); + + CommandProcessingResult result = null; if (is(commandParam, "reject")) { - result = this.commandsSourceWritePlatformService.logCommandSource("REJECT", "LOAN", "N/A", "loans", loanId, - apiRequestBodyAsJson); + final CommandWrapper commandRequest = builder.rejectLoanApplication().build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, "withdrewbyclient")) { - result = this.commandsSourceWritePlatformService.logCommandSource("WITHDRAW", "LOAN", "N/A", "loans", loanId, - apiRequestBodyAsJson); + final CommandWrapper commandRequest = builder.withdrawLoanApplication().build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, "approve")) { - result = this.commandsSourceWritePlatformService.logCommandSource("APPROVE", "LOAN", "N/A", "loans", loanId, - apiRequestBodyAsJson); + final CommandWrapper commandRequest = builder.approveLoanApplication().build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, "disburse")) { - result = this.commandsSourceWritePlatformService.logCommandSource("DISBURSE", "LOAN", "N/A", "loans", loanId, - apiRequestBodyAsJson); + final CommandWrapper commandRequest = builder.disburseLoanApplication().build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } if (is(commandParam, "undoapproval")) { - result = this.commandsSourceWritePlatformService.logCommandSource("APPROVALUNDO", "LOAN", "N/A", "loans", loanId, - apiRequestBodyAsJson); + final CommandWrapper commandRequest = builder.undoLoanApplicationApproval().build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } else if (is(commandParam, "undodisbursal")) { - result = this.commandsSourceWritePlatformService.logCommandSource("DISBURSALUNDO", "LOAN", "N/A", "loans", loanId, - apiRequestBodyAsJson); + final CommandWrapper commandRequest = builder.undoLoanApplicationDisbursal().build(); + result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); } if (result == null) { throw new UnrecognizedQueryParamException("command", commandParam); } @@ -429,8 +440,10 @@ public class LoansApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String assignLoanOfficer(@PathParam("loanId") final Long loanId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATELOANOFFICER", "LOAN", "N/A", - "loans", loanId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().assignLoanOfficer().withUrl("/loans").withLoanId(loanId) + .withEntityId(loanId).withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java index ce429dce5..7c9c6fbb1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java @@ -75,7 +75,6 @@ public class Loan extends AbstractAuditableCustom { @JoinColumn(name = "guarantor_id") private Client guarantor; - @SuppressWarnings("unused") @ManyToOne(optional = true) @JoinColumn(name = "group_id") private Group group; @@ -212,7 +211,8 @@ public class Loan extends AbstractAuditableCustom { final Set loanCharges) { final LoanStatus status = null; LoanProductRelatedDetail loanRepaymentScheduleDetail = loanSchedule.loanProductRelatedDetail(); - return new Loan(client, null, fund, officer, transactionProcessingStrategy, loanProduct, loanRepaymentScheduleDetail, status, loanCharges); + return new Loan(client, null, fund, officer, transactionProcessingStrategy, loanProduct, loanRepaymentScheduleDetail, status, + loanCharges); } public static Loan newGroupLoanApplication(final Group group, final LoanProduct loanProduct, final Fund fund, final Staff officer, @@ -220,12 +220,13 @@ public class Loan extends AbstractAuditableCustom { final Set loanCharges) { final LoanStatus status = null; LoanProductRelatedDetail loanRepaymentScheduleDetail = loanSchedule.loanProductRelatedDetail(); - return new Loan(null, group, fund, officer, transactionProcessingStrategy, loanProduct, loanRepaymentScheduleDetail, status, loanCharges); + return new Loan(null, group, fund, officer, transactionProcessingStrategy, loanProduct, loanRepaymentScheduleDetail, status, + loanCharges); } - public static Loan newIndividualLoanApplicationFromGroup(final Client client, final Group group, final LoanProduct loanProduct, final Fund fund, - final Staff officer, final LoanTransactionProcessingStrategy transactionProcessingStrategy, final LoanSchedule loanSchedule, - final Set loanCharges) { + public static Loan newIndividualLoanApplicationFromGroup(final Client client, final Group group, final LoanProduct loanProduct, + final Fund fund, final Staff officer, final LoanTransactionProcessingStrategy transactionProcessingStrategy, + final LoanSchedule loanSchedule, final Set loanCharges) { final LoanStatus status = null; LoanProductRelatedDetail loanRepaymentScheduleDetail = loanSchedule.loanProductRelatedDetail(); return new Loan(client, group, fund, officer, transactionProcessingStrategy, loanProduct, loanRepaymentScheduleDetail, status, @@ -236,9 +237,9 @@ public class Loan extends AbstractAuditableCustom { // } - private Loan(final Client client, final Group group, Fund fund, Staff loanOfficer, final LoanTransactionProcessingStrategy transactionProcessingStrategy, - final LoanProduct loanProduct, final LoanProductRelatedDetail loanRepaymentScheduleDetail, final LoanStatus loanStatus, - final Set loanCharges) { + private Loan(final Client client, final Group group, Fund fund, Staff loanOfficer, + final LoanTransactionProcessingStrategy transactionProcessingStrategy, final LoanProduct loanProduct, + final LoanProductRelatedDetail loanRepaymentScheduleDetail, final LoanStatus loanStatus, final Set loanCharges) { this.client = client; this.group = group; this.fund = fund; @@ -436,12 +437,13 @@ public class Loan extends AbstractAuditableCustom { return actualChanges; } - public LoanTransaction waiveLoanCharge(final LoanCharge loanCharge, final LoanLifecycleStateMachine loanLifecycleStateMachine, final Map changes) { + public LoanTransaction waiveLoanCharge(final LoanCharge loanCharge, final LoanLifecycleStateMachine loanLifecycleStateMachine, + final Map changes) { validateLoanIsNotClosed(loanCharge); final Money amountWaived = loanCharge.waive(loanCurrency()); - + changes.put("amount", amountWaived.getAmount()); Money feeChargesWaived = Money.of(loanCurrency(), loanCharge.amount()); @@ -665,7 +667,7 @@ public class Loan extends AbstractAuditableCustom { Arrays.sort(newLoanChargeData); return !Arrays.equals(existingLoanChargeData, newLoanChargeData); } - + private Set getNullPointerSafeLoanCharges() { Set loanCharges = this.charges; if (this.charges == null) { @@ -968,8 +970,8 @@ public class Loan extends AbstractAuditableCustom { final LoanSchedule loanSchedule = new LoanSchedule(loanScheduleGenerator, applicationCurrency, principal, interestRatePerPeriod, interestRatePeriodFrequencyType, defaultAnnualNominalInterestRate, interestMethod, interestCalculationPeriodMethod, repaymentEvery, repaymentPeriodFrequencyType, numberOfRepayments, amortizationMethod, loanTermFrequency, - loanTermPeriodFrequencyType, getNullPointerSafeLoanCharges(), this.getDisbursementDate(), this.getExpectedFirstRepaymentOnDate(), - this.getInterestChargedFromDate(), inArrearsTolerance); + loanTermPeriodFrequencyType, getNullPointerSafeLoanCharges(), this.getDisbursementDate(), + this.getExpectedFirstRepaymentOnDate(), this.getInterestChargedFromDate(), inArrearsTolerance); final LoanScheduleData generatedData = loanSchedule.generate(); @@ -1922,4 +1924,30 @@ public class Loan extends AbstractAuditableCustom { public Client getClient() { return client; } + + public Long getClientId() { + Long clientId = null; + if (this.client != null) { + clientId = this.client.getId(); + } + return clientId; + } + + public Long getGroupId() { + Long groupId = null; + if (this.group != null) { + groupId = this.group.getId(); + } + return groupId; + } + + public Long getOfficeId() { + Long officeId = null; + if (this.client != null) { + officeId = this.client.getOffice().getId(); + } else { +// officeId = this.group.getOffice().getId(); + } + return officeId; + } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/api/GuarantorsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/api/GuarantorsApiResource.java index 658476e64..16a5c5a92 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/api/GuarantorsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/gaurantor/api/GuarantorsApiResource.java @@ -20,7 +20,7 @@ import javax.ws.rs.core.UriInfo; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.portfolio.loanaccount.gaurantor.command.GuarantorCommand; import org.mifosplatform.portfolio.loanaccount.gaurantor.data.GuarantorData; @@ -82,7 +82,7 @@ public class GuarantorsApiResource { this.guarantorWritePlatformService.createGuarantor(loanId, command); // returns the loan Identifier for which the guarantor was associated - return Response.ok().entity(new EntityIdentifier(loanId)).build(); + return Response.ok().entity(new CommandProcessingResult(loanId)).build(); } @PUT @@ -93,7 +93,7 @@ public class GuarantorsApiResource { this.guarantorWritePlatformService.updateGuarantor(loanId, command); - return Response.ok().entity(new EntityIdentifier(loanId)).build(); + return Response.ok().entity(new CommandProcessingResult(loanId)).build(); } @DELETE @@ -101,6 +101,6 @@ public class GuarantorsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public Response deleteGuarantor(@PathParam("loanId") final Long loanId) { this.guarantorWritePlatformService.removeGuarantor(loanId); - return Response.ok(new EntityIdentifier(loanId)).build(); + return Response.ok(new CommandProcessingResult(loanId)).build(); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/AddLoanChargeCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/AddLoanChargeCommandHandler.java index d37f88bd2..74d90e590 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/AddLoanChargeCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/AddLoanChargeCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class AddLoanChargeCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.addLoanCharge(command.resourceId(), command); + return this.writePlatformService.addLoanCharge(command.getLoanId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/BulkUpdateLoanOfficerCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/BulkUpdateLoanOfficerCommandHandler.java index c16a94f5e..d6ae80c14 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/BulkUpdateLoanOfficerCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/BulkUpdateLoanOfficerCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class BulkUpdateLoanOfficerCommandHandler implements NewCommandSourceHand @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.writePlatformService.bulkLoanReassignment(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/CloseLoanAsRescheduledCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/CloseLoanAsRescheduledCommandHandler.java index 3586171b1..bbabc983c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/CloseLoanAsRescheduledCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/CloseLoanAsRescheduledCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class CloseLoanAsRescheduledCommandHandler implements NewCommandSourceHan @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.closeAsRescheduled(command.resourceId(), command); + return this.writePlatformService.closeAsRescheduled(command.getLoanId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/CloseLoanCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/CloseLoanCommandHandler.java index a0d0f06b2..f8f4b6ca0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/CloseLoanCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/CloseLoanCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class CloseLoanCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.closeLoan(command.resourceId(), command); + return this.writePlatformService.closeLoan(command.getLoanId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/DeleteLoanChargeCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/DeleteLoanChargeCommandHandler.java index d4b0762a1..81c93124a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/DeleteLoanChargeCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/DeleteLoanChargeCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class DeleteLoanChargeCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.deleteLoanCharge(command.resourceId(), command.subResourceId(), command); + return this.writePlatformService.deleteLoanCharge(command.getLoanId(), command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/DisburseLoanCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/DisburseLoanCommandHandler.java index 0ea2e4797..39a5ea075 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/DisburseLoanCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/DisburseLoanCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class DisburseLoanCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.disburseLoan(command.resourceId(), command); + return this.writePlatformService.disburseLoan(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationApprovalCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationApprovalCommandHandler.java index 0aac7f19a..32e61dc40 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationApprovalCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationApprovalCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanApplicationWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class LoanApplicationApprovalCommandHandler implements NewCommandSourceHa @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.approveLoanApplication(command.resourceId(), command); + return this.writePlatformService.approveLoanApplication(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationApprovalUndoCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationApprovalUndoCommandHandler.java index 91b1804b6..79eb9ed2f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationApprovalUndoCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationApprovalUndoCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanApplicationWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class LoanApplicationApprovalUndoCommandHandler implements NewCommandSour @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.undoLoanApplicationApproval(command.resourceId(), command); + return this.writePlatformService.undoLoanApplicationApproval(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationDeletionCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationDeletionCommandHandler.java index a7a066173..7f007042f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationDeletionCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationDeletionCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanApplicationWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class LoanApplicationDeletionCommandHandler implements NewCommandSourceHa @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.deleteLoanApplication(command.resourceId()); + return this.writePlatformService.deleteLoanApplication(command.entityId()); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationModificationCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationModificationCommandHandler.java index 5bd26b953..7ca46f42f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationModificationCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationModificationCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanApplicationWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class LoanApplicationModificationCommandHandler implements NewCommandSour @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.modifyLoanApplication(command.resourceId(), command); + return this.writePlatformService.modifyLoanApplication(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationRejectedCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationRejectedCommandHandler.java index 8c67f8c08..ef1bda278 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationRejectedCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationRejectedCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanApplicationWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class LoanApplicationRejectedCommandHandler implements NewCommandSourceHa @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.rejectLoanApplication(command.resourceId(), command); + return this.writePlatformService.rejectLoanApplication(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationSubmittalCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationSubmittalCommandHandler.java index 8a141a05b..455bb83b5 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationSubmittalCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationSubmittalCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanApplicationWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class LoanApplicationSubmittalCommandHandler implements NewCommandSourceH @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.writePlatformService.submitLoanApplication(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationWithdrawnByApplicantCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationWithdrawnByApplicantCommandHandler.java index 29d07e03c..ff217b928 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationWithdrawnByApplicantCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanApplicationWithdrawnByApplicantCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanApplicationWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class LoanApplicationWithdrawnByApplicantCommandHandler implements NewCom @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.applicantWithdrawsFromLoanApplication(command.resourceId(), command); + return this.writePlatformService.applicantWithdrawsFromLoanApplication(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanRepaymentAdjustmentCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanRepaymentAdjustmentCommandHandler.java index a1a75342a..0cf28a176 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanRepaymentAdjustmentCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanRepaymentAdjustmentCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class LoanRepaymentAdjustmentCommandHandler implements NewCommandSourceHa @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.adjustLoanTransaction(command.resourceId(), command.subResourceId(), command); + return this.writePlatformService.adjustLoanTransaction(command.getLoanId(), command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanRepaymentCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanRepaymentCommandHandler.java index 00ffe78e6..e4f0431a1 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanRepaymentCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/LoanRepaymentCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class LoanRepaymentCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.makeLoanRepayment(command.resourceId(), command); + return this.writePlatformService.makeLoanRepayment(command.getLoanId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/UndoDisbursalLoanCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/UndoDisbursalLoanCommandHandler.java index 7463bd8c1..991a16d84 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/UndoDisbursalLoanCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/UndoDisbursalLoanCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class UndoDisbursalLoanCommandHandler implements NewCommandSourceHandler @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.undoLoanDisbursal(command.resourceId(), command); + return this.writePlatformService.undoLoanDisbursal(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/UpdateLoanChargeCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/UpdateLoanChargeCommandHandler.java index e3d0624bc..c15cbf4f4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/UpdateLoanChargeCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/UpdateLoanChargeCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class UpdateLoanChargeCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.updateLoanCharge(command.resourceId(), command.subResourceId(), command); + return this.writePlatformService.updateLoanCharge(command.getLoanId(), command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/UpdateLoanOfficerCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/UpdateLoanOfficerCommandHandler.java index 2ee67ff3b..9055d0552 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/UpdateLoanOfficerCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/UpdateLoanOfficerCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class UpdateLoanOfficerCommandHandler implements NewCommandSourceHandler @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.loanReassignment(command.resourceId(), command); + return this.writePlatformService.loanReassignment(command.getLoanId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/WaiveInterestPortionOnLoanCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/WaiveInterestPortionOnLoanCommandHandler.java index 437e99911..ffba1905f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/WaiveInterestPortionOnLoanCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/WaiveInterestPortionOnLoanCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class WaiveInterestPortionOnLoanCommandHandler implements NewCommandSourc @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.waiveInterestOnLoan(command.resourceId(), command); + return this.writePlatformService.waiveInterestOnLoan(command.getLoanId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/WaiveLoanChargeCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/WaiveLoanChargeCommandHandler.java index b26d283b7..edb5eca91 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/WaiveLoanChargeCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/WaiveLoanChargeCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class WaiveLoanChargeCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.waiveLoanCharge(command.resourceId(), command.subResourceId(), command); + return this.writePlatformService.waiveLoanCharge(command.getLoanId(), command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/WriteOffLoanCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/WriteOffLoanCommandHandler.java index 9e5dda106..106207ab9 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/WriteOffLoanCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/handler/WriteOffLoanCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanaccount.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.service.LoanWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class WriteOffLoanCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.writeOff(command.resourceId(), command); + return this.writePlatformService.writeOff(command.getLoanId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformService.java index d641290f0..99293b886 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformService.java @@ -1,21 +1,21 @@ package org.mifosplatform.portfolio.loanaccount.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface LoanApplicationWritePlatformService { - EntityIdentifier submitLoanApplication(JsonCommand command); + CommandProcessingResult submitLoanApplication(JsonCommand command); - EntityIdentifier modifyLoanApplication(Long loanId, JsonCommand command); + CommandProcessingResult modifyLoanApplication(Long loanId, JsonCommand command); - EntityIdentifier deleteLoanApplication(Long loanId); + CommandProcessingResult deleteLoanApplication(Long loanId); - EntityIdentifier approveLoanApplication(Long loanId, JsonCommand command); + CommandProcessingResult approveLoanApplication(Long loanId, JsonCommand command); - EntityIdentifier undoLoanApplicationApproval(Long loanId, JsonCommand command); + CommandProcessingResult undoLoanApplicationApproval(Long loanId, JsonCommand command); - EntityIdentifier rejectLoanApplication(Long loanId, JsonCommand command); + CommandProcessingResult rejectLoanApplication(Long loanId, JsonCommand command); - EntityIdentifier applicantWithdrawsFromLoanApplication(Long loanId, JsonCommand command); + CommandProcessingResult applicantWithdrawsFromLoanApplication(Long loanId, JsonCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java index 3307e3b21..37173c650 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java @@ -11,7 +11,8 @@ import org.joda.time.LocalDate; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.api.JsonQuery; import org.mifosplatform.infrastructure.core.data.ApiParameterError; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper; import org.mifosplatform.infrastructure.security.exception.NoAuthorizationException; @@ -102,22 +103,22 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa @Transactional @Override - public EntityIdentifier submitLoanApplication(final JsonCommand command) { + public CommandProcessingResult submitLoanApplication(final JsonCommand command) { context.authenticatedUser(); - final CalculateLoanScheduleQuery calculateLoanScheduleQuery = this.calculateLoanScheduleQueryFromApiJsonDeserializer.commandFromApiJson(command.json()); + final CalculateLoanScheduleQuery calculateLoanScheduleQuery = this.calculateLoanScheduleQueryFromApiJsonDeserializer + .commandFromApiJson(command.json()); final List loanScheduleErrors = calculateLoanScheduleQuery.validate(); - + final LoanApplicationCommand loanApplicationCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json()); final List loanApplicationErrors = loanApplicationCommand.validate(); - + final List combinedErrors = new ArrayList(loanScheduleErrors); combinedErrors.addAll(loanApplicationErrors); - - if (!combinedErrors.isEmpty()) { - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", combinedErrors); - } + + if (!combinedErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", combinedErrors); } final Loan newLoanApplication = loanAssembler.assembleFrom(command); @@ -129,27 +130,34 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa this.noteRepository.save(note); } - return EntityIdentifier.resourceResult(newLoanApplication.getId(), command.commandId()); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(newLoanApplication.getId()) // + .withOfficeId(newLoanApplication.getOfficeId()) // + .withClientId(newLoanApplication.getClientId()) // + .withGroupId(newLoanApplication.getGroupId()) // + .withLoanId(newLoanApplication.getId()) // + .build(); } @Transactional @Override - public EntityIdentifier modifyLoanApplication(final Long loanId, final JsonCommand command) { + public CommandProcessingResult modifyLoanApplication(final Long loanId, final JsonCommand command) { context.authenticatedUser(); - final CalculateLoanScheduleQuery calculateLoanScheduleQuery = this.calculateLoanScheduleQueryFromApiJsonDeserializer.commandFromApiJson(command.json()); + final CalculateLoanScheduleQuery calculateLoanScheduleQuery = this.calculateLoanScheduleQueryFromApiJsonDeserializer + .commandFromApiJson(command.json()); final List loanScheduleErrors = calculateLoanScheduleQuery.validate(); - + final LoanApplicationCommand loanApplicationCommand = this.fromApiJsonDeserializer.commandFromApiJson(command.json()); final List loanApplicationErrors = loanApplicationCommand.validate(); - + final List combinedErrors = new ArrayList(loanScheduleErrors); combinedErrors.addAll(loanApplicationErrors); - - if (!combinedErrors.isEmpty()) { - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", combinedErrors); - } + + if (!combinedErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", + "Validation errors exist.", combinedErrors); } final Loan existingLoanApplication = retrieveLoanBy(loanId); @@ -215,12 +223,18 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa this.noteRepository.save(note); } - return EntityIdentifier.resourceResult(loanId, command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withEntityId(loanId) // + .withOfficeId(existingLoanApplication.getOfficeId()) // + .withClientId(existingLoanApplication.getClientId()) // + .withGroupId(existingLoanApplication.getGroupId()) // + .withLoanId(existingLoanApplication.getId()) // + .with(changes).build(); } @Transactional @Override - public EntityIdentifier deleteLoanApplication(final Long loanId) { + public CommandProcessingResult deleteLoanApplication(final Long loanId) { context.authenticatedUser(); @@ -233,12 +247,18 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa this.loanRepository.delete(loanId); - return new EntityIdentifier(loanId); + return new CommandProcessingResultBuilder() // + .withEntityId(loanId) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loan.getId()) // + .build(); } @Transactional @Override - public EntityIdentifier approveLoanApplication(final Long loanId, final JsonCommand command) { + public CommandProcessingResult approveLoanApplication(final Long loanId, final JsonCommand command) { AppUser currentUser = context.authenticatedUser(); @@ -262,12 +282,20 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa this.noteRepository.save(note); } - return EntityIdentifier.resourceResult(loanId, command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loan.getId()) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } @Transactional @Override - public EntityIdentifier undoLoanApplicationApproval(final Long loanId, final JsonCommand command) { + public CommandProcessingResult undoLoanApplicationApproval(final Long loanId, final JsonCommand command) { context.authenticatedUser(); @@ -282,12 +310,20 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa this.noteRepository.save(note); } - return EntityIdentifier.resourceResult(loanId, command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loan.getId()) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } @Transactional @Override - public EntityIdentifier rejectLoanApplication(final Long loanId, final JsonCommand command) { + public CommandProcessingResult rejectLoanApplication(final Long loanId, final JsonCommand command) { final AppUser currentUser = context.authenticatedUser(); @@ -310,12 +346,20 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa this.noteRepository.save(note); } - return EntityIdentifier.resourceResult(loanId, command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loan.getId()) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } @Transactional @Override - public EntityIdentifier applicantWithdrawsFromLoanApplication(final Long loanId, final JsonCommand command) { + public CommandProcessingResult applicantWithdrawsFromLoanApplication(final Long loanId, final JsonCommand command) { final AppUser currentUser = context.authenticatedUser(); @@ -338,7 +382,15 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa this.noteRepository.save(note); } - return EntityIdentifier.resourceResult(loanId, command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loan.getId()) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } private Loan retrieveLoanBy(final Long loanId) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformService.java index ebbbb7d2a..9f5ba66b5 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformService.java @@ -1,35 +1,35 @@ package org.mifosplatform.portfolio.loanaccount.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface LoanWritePlatformService { - EntityIdentifier disburseLoan(Long loanId, JsonCommand command); + CommandProcessingResult disburseLoan(Long loanId, JsonCommand command); - EntityIdentifier undoLoanDisbursal(Long loanId, JsonCommand command); + CommandProcessingResult undoLoanDisbursal(Long loanId, JsonCommand command); - EntityIdentifier makeLoanRepayment(Long loanId, JsonCommand command); + CommandProcessingResult makeLoanRepayment(Long loanId, JsonCommand command); - EntityIdentifier adjustLoanTransaction(Long loanId, Long transactionId, JsonCommand command); + CommandProcessingResult adjustLoanTransaction(Long loanId, Long transactionId, JsonCommand command); - EntityIdentifier waiveInterestOnLoan(Long loanId, JsonCommand command); + CommandProcessingResult waiveInterestOnLoan(Long loanId, JsonCommand command); - EntityIdentifier writeOff(Long loanId, JsonCommand command); + CommandProcessingResult writeOff(Long loanId, JsonCommand command); - EntityIdentifier closeLoan(Long loanId, JsonCommand command); + CommandProcessingResult closeLoan(Long loanId, JsonCommand command); - EntityIdentifier closeAsRescheduled(Long loanId, JsonCommand command); + CommandProcessingResult closeAsRescheduled(Long loanId, JsonCommand command); - EntityIdentifier addLoanCharge(Long loanId, JsonCommand command); + CommandProcessingResult addLoanCharge(Long loanId, JsonCommand command); - EntityIdentifier updateLoanCharge(Long loanId, Long loanChargeId, JsonCommand command); + CommandProcessingResult updateLoanCharge(Long loanId, Long loanChargeId, JsonCommand command); - EntityIdentifier deleteLoanCharge(Long loanId, Long loanChargeId, JsonCommand command); + CommandProcessingResult deleteLoanCharge(Long loanId, Long loanChargeId, JsonCommand command); - EntityIdentifier waiveLoanCharge(Long loanId, Long loanChargeId, JsonCommand command); + CommandProcessingResult waiveLoanCharge(Long loanId, Long loanChargeId, JsonCommand command); - EntityIdentifier loanReassignment(Long loanId, JsonCommand command); + CommandProcessingResult loanReassignment(Long loanId, JsonCommand command); - EntityIdentifier bulkLoanReassignment(JsonCommand command); + CommandProcessingResult bulkLoanReassignment(JsonCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java index 87c48fe88..4d5867538 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanWritePlatformServiceJpaRepositoryImpl.java @@ -9,7 +9,8 @@ import java.util.Map; import org.apache.commons.lang.StringUtils; import org.joda.time.LocalDate; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.security.exception.NoAuthorizationException; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.monetary.domain.ApplicationCurrency; @@ -93,7 +94,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Transactional @Override - public EntityIdentifier disburseLoan(final Long loanId, final JsonCommand command) { + public CommandProcessingResult disburseLoan(final Long loanId, final JsonCommand command) { final AppUser currentUser = context.authenticatedUser(); @@ -118,12 +119,20 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf this.noteRepository.save(note); } - return EntityIdentifier.resourceResult(loanId, command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loan.getId()) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } @Transactional @Override - public EntityIdentifier undoLoanDisbursal(final Long loanId, final JsonCommand command) { + public CommandProcessingResult undoLoanDisbursal(final Long loanId, final JsonCommand command) { context.authenticatedUser(); @@ -138,12 +147,20 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf this.noteRepository.save(note); } - return EntityIdentifier.resourceResult(loanId, command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loan.getId()) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } @Transactional @Override - public EntityIdentifier makeLoanRepayment(final Long loanId, final JsonCommand command) { + public CommandProcessingResult makeLoanRepayment(final Long loanId, final JsonCommand command) { final AppUser currentUser = context.authenticatedUser(); @@ -177,12 +194,20 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf changes.put("locale", command.locale()); changes.put("dateFormat", command.dateFormat()); - return EntityIdentifier.subResourceResult(loanId, loanRepayment.getId(), command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loanRepayment.getId()) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } @Transactional @Override - public EntityIdentifier adjustLoanTransaction(final Long loanId, final Long transactionId, final JsonCommand command) { + public CommandProcessingResult adjustLoanTransaction(final Long loanId, final Long transactionId, final JsonCommand command) { context.authenticatedUser(); @@ -220,12 +245,20 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf changes.put("locale", command.locale()); changes.put("dateFormat", command.dateFormat()); - return EntityIdentifier.subResourceResult(loanId, transactionId, command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(transactionId) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } @Transactional @Override - public EntityIdentifier waiveInterestOnLoan(final Long loanId, final JsonCommand command) { + public CommandProcessingResult waiveInterestOnLoan(final Long loanId, final JsonCommand command) { context.authenticatedUser(); @@ -254,12 +287,20 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf changes.put("locale", command.locale()); changes.put("dateFormat", command.dateFormat()); - return EntityIdentifier.subResourceResult(loanId, waiveTransaction.getId(), command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(waiveTransaction.getId()) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } @Transactional @Override - public EntityIdentifier writeOff(final Long loanId, final JsonCommand command) { + public CommandProcessingResult writeOff(final Long loanId, final JsonCommand command) { context.authenticatedUser(); final LoanTransactionCommand loanTransactionCommand = this.loanTransactionCommandFromApiJsonDeserializer.commandFromApiJson(command @@ -286,12 +327,20 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf changes.put("locale", command.locale()); changes.put("dateFormat", command.dateFormat()); - return EntityIdentifier.subResourceResult(loanId, writeoff.getId(), command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(writeoff.getId()) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } @Transactional @Override - public EntityIdentifier closeLoan(final Long loanId, final JsonCommand command) { + public CommandProcessingResult closeLoan(final Long loanId, final JsonCommand command) { context.authenticatedUser(); @@ -320,11 +369,28 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf changes.put("locale", command.locale()); changes.put("dateFormat", command.dateFormat()); - EntityIdentifier result = null; + CommandProcessingResult result = null; if (possibleClosingTransaction != null) { - result = EntityIdentifier.subResourceResult(loanId, possibleClosingTransaction.getId(), command.commandId(), changes); + + result = new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(possibleClosingTransaction.getId()) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } else { - result = EntityIdentifier.resourceResult(loanId, command.commandId(), changes); + result = new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loanId) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } return result; @@ -332,7 +398,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Transactional @Override - public EntityIdentifier closeAsRescheduled(final Long loanId, final JsonCommand command) { + public CommandProcessingResult closeAsRescheduled(final Long loanId, final JsonCommand command) { context.authenticatedUser(); final LoanTransactionCommand loanTransactionCommand = this.loanTransactionCommandFromApiJsonDeserializer.commandFromApiJson(command @@ -358,12 +424,20 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf changes.put("locale", command.locale()); changes.put("dateFormat", command.dateFormat()); - return EntityIdentifier.resourceResult(loanId, command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loanId) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } @Transactional @Override - public EntityIdentifier addLoanCharge(final Long loanId, final JsonCommand command) { + public CommandProcessingResult addLoanCharge(final Long loanId, final JsonCommand command) { this.context.authenticatedUser(); final LoanChargeCommand loanChargeCommand = this.loanChargeCommandFromApiJsonDeserializer.commandFromApiJson(command.json()); @@ -388,12 +462,19 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf loan.addLoanCharge(loanCharge); this.loanRepository.save(loan); - return EntityIdentifier.subResourceResult(loanId, loanCharge.getId(), command.commandId()); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loanCharge.getId()) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .build(); } @Transactional @Override - public EntityIdentifier updateLoanCharge(final Long loanId, final Long loanChargeId, final JsonCommand command) { + public CommandProcessingResult updateLoanCharge(final Long loanId, final Long loanChargeId, final JsonCommand command) { this.context.authenticatedUser(); @@ -407,12 +488,20 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf this.loanRepository.save(loan); - return EntityIdentifier.subResourceResult(loanId, loanChargeId, command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loanChargeId) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } @Transactional @Override - public EntityIdentifier waiveLoanCharge(final Long loanId, final Long loanChargeId, final JsonCommand command) { + public CommandProcessingResult waiveLoanCharge(final Long loanId, final Long loanChargeId, final JsonCommand command) { this.context.authenticatedUser(); @@ -435,12 +524,20 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf this.noteRepository.save(note); } - return EntityIdentifier.subResourceResult(loanId, loanChargeId, command.commandId(), changes); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loanChargeId) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .with(changes) // + .build(); } @Transactional @Override - public EntityIdentifier deleteLoanCharge(final Long loanId, final Long loanChargeId, final JsonCommand command) { + public CommandProcessingResult deleteLoanCharge(final Long loanId, final Long loanChargeId, final JsonCommand command) { this.context.authenticatedUser(); @@ -450,7 +547,14 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf loan.removeLoanCharge(loanCharge); this.loanRepository.save(loan); - return EntityIdentifier.subResourceResult(loanId, loanChargeId, command.commandId()); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loanChargeId) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .build(); } private Loan retrieveLoanBy(final Long loanId) { @@ -469,7 +573,7 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf @Transactional @Override - public EntityIdentifier loanReassignment(final Long loanId, final JsonCommand command) { + public CommandProcessingResult loanReassignment(final Long loanId, final JsonCommand command) { this.context.authenticatedUser(); @@ -488,12 +592,19 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf this.loanRepository.saveAndFlush(loan); - return EntityIdentifier.resourceResult(loanId, command.commandId()); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(loanId) // + .withOfficeId(loan.getOfficeId()) // + .withClientId(loan.getClientId()) // + .withGroupId(loan.getGroupId()) // + .withLoanId(loanId) // + .build(); } @Transactional @Override - public EntityIdentifier bulkLoanReassignment(final JsonCommand command) { + public CommandProcessingResult bulkLoanReassignment(final JsonCommand command) { this.context.authenticatedUser(); @@ -518,6 +629,8 @@ public class LoanWritePlatformServiceJpaRepositoryImpl implements LoanWritePlatf this.loanRepository.flush(); - return EntityIdentifier.resourceResult(null, command.commandId()); + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .build(); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/api/LoanProductsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/api/LoanProductsApiResource.java index 30e71f635..645efbcd0 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/api/LoanProductsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/api/LoanProductsApiResource.java @@ -17,9 +17,11 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; @@ -86,9 +88,11 @@ public class LoanProductsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String createLoanProduct(final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "LOANPRODUCT", "CREATE", - "loanproducts", null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().createLoanProduct().withUrl("/loanproducts") + .withJson(apiRequestBodyAsJson).build(); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + return this.toApiJsonSerializer.serialize(result); } @@ -143,9 +147,11 @@ public class LoanProductsApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) public String updateLoanProduct(@PathParam("productId") final Long productId, final String apiRequestBodyAsJson) { + + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateLoanProduct().withUrl("/loanproducts").withEntityId(productId) + .withJson(apiRequestBodyAsJson).build(); - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "LOANPRODUCT", "UPDATE", - "loanproducts", productId, apiRequestBodyAsJson); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/handler/CreateLoanProductCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/handler/CreateLoanProductCommandHandler.java index d73b5df9f..f3295695d 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/handler/CreateLoanProductCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/handler/CreateLoanProductCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanproduct.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanproduct.service.LoanProductWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class CreateLoanProductCommandHandler implements NewCommandSourceHandler @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.writePlatformService.createLoanProduct(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/handler/UpdateLoanProductCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/handler/UpdateLoanProductCommandHandler.java index 0e66d70c9..7fb04d39c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/handler/UpdateLoanProductCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/handler/UpdateLoanProductCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.loanproduct.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanproduct.service.LoanProductWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class UpdateLoanProductCommandHandler implements NewCommandSourceHandler @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.updateLoanProduct(command.resourceId(), command); + return this.writePlatformService.updateLoanProduct(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductWritePlatformService.java index 7fdee9167..49393b11b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductWritePlatformService.java @@ -1,11 +1,11 @@ package org.mifosplatform.portfolio.loanproduct.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface LoanProductWritePlatformService { - EntityIdentifier createLoanProduct(JsonCommand command); + CommandProcessingResult createLoanProduct(JsonCommand command); - EntityIdentifier updateLoanProduct(Long loanProductId, JsonCommand command); + CommandProcessingResult updateLoanProduct(Long loanProductId, JsonCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java index e9e6dc216..b83596a4f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java @@ -5,7 +5,8 @@ import java.util.Map; import java.util.Set; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.portfolio.charge.domain.Charge; import org.mifosplatform.portfolio.charge.domain.ChargeRepository; @@ -57,7 +58,7 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro @Transactional @Override - public EntityIdentifier createLoanProduct(final JsonCommand command) { + public CommandProcessingResult createLoanProduct(final JsonCommand command) { this.context.authenticatedUser(); @@ -75,7 +76,7 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro this.loanProductRepository.save(loanproduct); - return EntityIdentifier.resourceResult(loanproduct.getId(), null); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(loanproduct.getId()).build(); } private LoanTransactionProcessingStrategy findStrategyByIdIfProvided(final Long transactionProcessingStrategyId) { @@ -98,7 +99,7 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro @Transactional @Override - public EntityIdentifier updateLoanProduct(final Long loanProductId, final JsonCommand command) { + public CommandProcessingResult updateLoanProduct(final Long loanProductId, final JsonCommand command) { this.context.authenticatedUser(); @@ -132,7 +133,7 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro this.loanProductRepository.save(product); } - return EntityIdentifier.withChanges(product.getId(), changes); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(loanProductId).with(changes).build(); } private Set assembleSetOfCharges(final JsonCommand command, final String currencyCode) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/api/SavingsAccountApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/api/SavingsAccountApiResource.java index ad4c64bbd..853569995 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/api/SavingsAccountApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/api/SavingsAccountApiResource.java @@ -23,7 +23,7 @@ import org.apache.commons.lang.StringUtils; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.core.serialization.ToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -104,7 +104,7 @@ public class SavingsAccountApiResource { return calculateSavingSchedule(uriInfo, calculateSavingScheduleCommand); } - EntityIdentifier entityIdentifier = this.savingAccountWritePlatformService.createSavingAccount(command); + CommandProcessingResult entityIdentifier = this.savingAccountWritePlatformService.createSavingAccount(command); return this.toApiJsonSerializer.serialize(entityIdentifier); } @@ -126,7 +126,7 @@ public class SavingsAccountApiResource { final SavingAccountCommand command = this.apiDataConversionService.convertJsonToSavingAccountCommand(accountId, jsonRequestBody); - EntityIdentifier entityIdentifier = this.savingAccountWritePlatformService.updateSavingAccount(command); + CommandProcessingResult entityIdentifier = this.savingAccountWritePlatformService.updateSavingAccount(command); return Response.ok().entity(entityIdentifier).build(); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountWritePlatformService.java index d9b850fe9..d80890007 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountWritePlatformService.java @@ -1,14 +1,14 @@ package org.mifosplatform.portfolio.savingsaccount.service; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.savingsaccount.command.SavingAccountCommand; import org.springframework.security.access.prepost.PreAuthorize; public interface SavingAccountWritePlatformService { @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_SAVINGSACCOUNT')") - EntityIdentifier createSavingAccount(SavingAccountCommand command); + CommandProcessingResult createSavingAccount(SavingAccountCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'UPDATE_SAVINGSACCOUNT')") - EntityIdentifier updateSavingAccount(SavingAccountCommand command); + CommandProcessingResult updateSavingAccount(SavingAccountCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountWritePlatformServiceJpaRepositoryImpl.java index 3b297a7a1..f9ab2915a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccount/service/SavingAccountWritePlatformServiceJpaRepositoryImpl.java @@ -1,6 +1,6 @@ package org.mifosplatform.portfolio.savingsaccount.service; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.portfolio.client.domain.NoteRepository; @@ -39,7 +39,7 @@ public class SavingAccountWritePlatformServiceJpaRepositoryImpl implements Savin @Transactional @Override - public EntityIdentifier createSavingAccount(final SavingAccountCommand command) { + public CommandProcessingResult createSavingAccount(final SavingAccountCommand command) { try { this.context.authenticatedUser(); SavingAccountCommandValidator validator = new SavingAccountCommandValidator(command); @@ -48,16 +48,16 @@ public class SavingAccountWritePlatformServiceJpaRepositoryImpl implements Savin SavingAccount account = this.savingAccountAssembler.assembleFrom(command); this.savingAccountRepository.save(account); - return new EntityIdentifier(account.getId()); + return new CommandProcessingResult(account.getId()); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); - return new EntityIdentifier(Long.valueOf(-1)); + return new CommandProcessingResult(Long.valueOf(-1)); } } @Override - public EntityIdentifier updateSavingAccount(final SavingAccountCommand command) { + public CommandProcessingResult updateSavingAccount(final SavingAccountCommand command) { try { this.context.authenticatedUser(); SavingAccountCommandValidator validator = new SavingAccountCommandValidator(command); @@ -69,10 +69,10 @@ public class SavingAccountWritePlatformServiceJpaRepositoryImpl implements Savin this.savingAccountAssembler.assembleFrom(command, account); this.savingAccountRepository.save(account); } - return new EntityIdentifier(account.getId()); + return new CommandProcessingResult(account.getId()); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); - return new EntityIdentifier(Long.valueOf(-1)); + return new CommandProcessingResult(Long.valueOf(-1)); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/api/SavingProductsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/api/SavingProductsApiResource.java index ef099b29d..57fd0e770 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/api/SavingProductsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/api/SavingProductsApiResource.java @@ -22,7 +22,7 @@ import javax.ws.rs.core.UriInfo; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.monetary.data.CurrencyData; @@ -73,7 +73,7 @@ public class SavingProductsApiResource { final SavingProductCommand command = this.apiDataConversionService.convertJsonToSavingProductCommand(null, jsonRequestBody); - EntityIdentifier entityIdentifier = this.savingProductWritePlatformService.createSavingProduct(command); + CommandProcessingResult entityIdentifier = this.savingProductWritePlatformService.createSavingProduct(command); return Response.ok().entity(entityIdentifier).build(); } @@ -85,7 +85,7 @@ public class SavingProductsApiResource { public Response updateSavingProduct(@PathParam("productId") final Long productId, final String jsonRequestBody) { SavingProductCommand command = this.apiDataConversionService.convertJsonToSavingProductCommand(productId, jsonRequestBody); - EntityIdentifier entityIdentifier = this.savingProductWritePlatformService.updateSavingProduct(command); + CommandProcessingResult entityIdentifier = this.savingProductWritePlatformService.updateSavingProduct(command); return Response.ok().entity(entityIdentifier).build(); } @@ -209,6 +209,6 @@ public class SavingProductsApiResource { this.savingProductWritePlatformService.deleteSavingProduct(productId); - return Response.ok(new EntityIdentifier(productId)).build(); + return Response.ok(new CommandProcessingResult(productId)).build(); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformService.java index cc5e07fb4..d9732c286 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformService.java @@ -1,17 +1,17 @@ package org.mifosplatform.portfolio.savingsaccountproduct.service; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.savingsaccountproduct.command.SavingProductCommand; import org.springframework.security.access.prepost.PreAuthorize; public interface SavingProductWritePlatformService { @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'CREATE_SAVINGSPRODUCT')") - EntityIdentifier createSavingProduct(SavingProductCommand command); + CommandProcessingResult createSavingProduct(SavingProductCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'UPDATE_SAVINGSPRODUCT')") - EntityIdentifier updateSavingProduct(SavingProductCommand command); + CommandProcessingResult updateSavingProduct(SavingProductCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'DELETE_SAVINGSPRODUCT')") - EntityIdentifier deleteSavingProduct(Long productId); + CommandProcessingResult deleteSavingProduct(Long productId); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformServiceJpaRepositoryImpl.java index ae5466864..3460d2d3a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsaccountproduct/service/SavingProductWritePlatformServiceJpaRepositoryImpl.java @@ -1,6 +1,6 @@ package org.mifosplatform.portfolio.savingsaccountproduct.service; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency; import org.mifosplatform.portfolio.loanproduct.domain.PeriodFrequencyType; @@ -33,7 +33,7 @@ public class SavingProductWritePlatformServiceJpaRepositoryImpl implements Savin @Transactional @Override - public EntityIdentifier createSavingProduct(final SavingProductCommand command) { + public CommandProcessingResult createSavingProduct(final SavingProductCommand command) { this.context.authenticatedUser(); SavingProductCommandValidator validator = new SavingProductCommandValidator(command); @@ -55,12 +55,12 @@ public class SavingProductWritePlatformServiceJpaRepositoryImpl implements Savin command.getLockinPeriod(), lockinPeriodType); this.savingProductRepository.save(product); - return new EntityIdentifier(product.getId()); + return new CommandProcessingResult(product.getId()); } @Transactional @Override - public EntityIdentifier updateSavingProduct(final SavingProductCommand command) { + public CommandProcessingResult updateSavingProduct(final SavingProductCommand command) { this.context.authenticatedUser(); SavingProductCommandValidator validator = new SavingProductCommandValidator(command); @@ -70,19 +70,19 @@ public class SavingProductWritePlatformServiceJpaRepositoryImpl implements Savin if (product == null) { throw new SavingProductNotFoundException(command.getId()); } product.update(command); this.savingProductRepository.save(product); - return new EntityIdentifier(Long.valueOf(product.getId())); + return new CommandProcessingResult(Long.valueOf(product.getId())); } @Transactional @Override - public EntityIdentifier deleteSavingProduct(Long productId) { + public CommandProcessingResult deleteSavingProduct(Long productId) { this.context.authenticatedUser(); SavingProduct product = this.savingProductRepository.findOne(productId); if (product == null || product.isDeleted()) { throw new SavingsProductNotFoundException(productId); } product.delete(); this.savingProductRepository.save(product); - return new EntityIdentifier(Long.valueOf(product.getId())); + return new CommandProcessingResult(Long.valueOf(product.getId())); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/api/DepositAccountsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/api/DepositAccountsApiResource.java index 577b03e59..f285d60b7 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/api/DepositAccountsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/api/DepositAccountsApiResource.java @@ -26,7 +26,7 @@ import org.apache.commons.lang.StringUtils; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.core.exception.UnrecognizedQueryParamException; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -89,7 +89,7 @@ public class DepositAccountsApiResource { final DepositAccountCommand command = this.apiDataConversionService.convertJsonToDepositAccountCommand(null, jsonRequestBody); - EntityIdentifier entityIdentifier = this.depositAccountWritePlatformService.createDepositAccount(command); + CommandProcessingResult entityIdentifier = this.depositAccountWritePlatformService.createDepositAccount(command); return Response.ok().entity(entityIdentifier).build(); } @@ -102,7 +102,7 @@ public class DepositAccountsApiResource { final DepositAccountCommand command = this.apiDataConversionService.convertJsonToDepositAccountCommand(accountId, jsonRequestBody); - EntityIdentifier entityIdentifier = this.depositAccountWritePlatformService.updateDepositAccount(command); + CommandProcessingResult entityIdentifier = this.depositAccountWritePlatformService.updateDepositAccount(command); return Response.ok().entity(entityIdentifier).build(); } @@ -193,7 +193,7 @@ public class DepositAccountsApiResource { this.depositAccountWritePlatformService.deleteDepositAccount(accountId); - return Response.ok(new EntityIdentifier(accountId)).build(); + return Response.ok(new CommandProcessingResult(accountId)).build(); } private DepositAccountData handleTemplateRelatedData(final Set responseParameters, final DepositAccountData account) { @@ -220,37 +220,37 @@ public class DepositAccountsApiResource { if (is(commandParam, "approve")) { DepositStateTransitionApprovalCommand command = apiDataConversionService.convertJsonToDepositStateTransitionApprovalCommand( accountId, jsonRequestBody); - EntityIdentifier identifier = this.depositAccountWritePlatformService.approveDepositApplication(command); + CommandProcessingResult identifier = this.depositAccountWritePlatformService.approveDepositApplication(command); response = Response.ok().entity(identifier).build(); } else if (is(commandParam, "withdrawal")) { DepositAccountWithdrawalCommand command = apiDataConversionService.convertJsonToDepositWithdrawalCommand(accountId, jsonRequestBody); - EntityIdentifier identifier = this.depositAccountWritePlatformService.withdrawDepositAccountMoney(command); + CommandProcessingResult identifier = this.depositAccountWritePlatformService.withdrawDepositAccountMoney(command); response = Response.ok().entity(identifier).build(); } else if (is(commandParam, "interestwithdraw")) { DepositAccountWithdrawInterestCommand command = apiDataConversionService.convertJsonToDepositAccountWithdrawInterestCommand( accountId, jsonRequestBody); - EntityIdentifier identifier = this.depositAccountWritePlatformService.withdrawDepositAccountInterestMoney(command); + CommandProcessingResult identifier = this.depositAccountWritePlatformService.withdrawDepositAccountInterestMoney(command); response = Response.ok().entity(identifier).build(); } else if (is(commandParam, "renew")) { DepositAccountCommand command = apiDataConversionService.convertJsonToDepositAccountCommand(accountId, jsonRequestBody); - EntityIdentifier entityIdentifier = this.depositAccountWritePlatformService.renewDepositAccount(command); + CommandProcessingResult entityIdentifier = this.depositAccountWritePlatformService.renewDepositAccount(command); return Response.ok().entity(entityIdentifier).build(); } else { DepositStateTransitionCommand command = apiDataConversionService.convertJsonToDepositStateTransitionCommand(accountId, jsonRequestBody); if (is(commandParam, "reject")) { - EntityIdentifier identifier = this.depositAccountWritePlatformService.rejectDepositApplication(command); + CommandProcessingResult identifier = this.depositAccountWritePlatformService.rejectDepositApplication(command); response = Response.ok().entity(identifier).build(); } else if (is(commandParam, "withdrewbyclient")) { - EntityIdentifier identifier = this.depositAccountWritePlatformService.withdrawDepositApplication(command); + CommandProcessingResult identifier = this.depositAccountWritePlatformService.withdrawDepositApplication(command); response = Response.ok().entity(identifier).build(); } UndoStateTransitionCommand undoCommand = new UndoStateTransitionCommand(accountId, command.getNote()); if (is(commandParam, "undoapproval")) { - EntityIdentifier identifier = this.depositAccountWritePlatformService.undoDepositApproval(undoCommand); + CommandProcessingResult identifier = this.depositAccountWritePlatformService.undoDepositApproval(undoCommand); response = Response.ok().entity(identifier).build(); } } @@ -270,7 +270,7 @@ public class DepositAccountsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public Response postInterest() { Collection accounts = this.depositAccountReadPlatformService.retrieveDepositAccountForLookup(); - EntityIdentifier entityIdentifier = this.depositAccountWritePlatformService.postInterestToDepositAccount(accounts); + CommandProcessingResult entityIdentifier = this.depositAccountWritePlatformService.postInterestToDepositAccount(accounts); return Response.ok().entity(entityIdentifier).build(); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformService.java index 25c8a6210..dedaef4e5 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformService.java @@ -2,7 +2,7 @@ package org.mifosplatform.portfolio.savingsdepositaccount.service; import java.util.Collection; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.loanaccount.command.UndoStateTransitionCommand; import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountCommand; import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountWithdrawInterestCommand; @@ -15,27 +15,27 @@ import org.springframework.security.access.prepost.PreAuthorize; public interface DepositAccountWritePlatformService { @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'CREATE_DEPOSITACCOUNT')") - EntityIdentifier createDepositAccount(DepositAccountCommand command); + CommandProcessingResult createDepositAccount(DepositAccountCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'UPDATE_DEPOSITACCOUNT')") - EntityIdentifier updateDepositAccount(DepositAccountCommand command); + CommandProcessingResult updateDepositAccount(DepositAccountCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'DELETE_DEPOSITACCOUNT')") - EntityIdentifier deleteDepositAccount(Long productId); + CommandProcessingResult deleteDepositAccount(Long productId); // NOTE - took out permissions relating to doing things with deposit // accounts in the past as doesn't appear to be code for it @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'APPROVE_DEPOSITACCOUNT')") - EntityIdentifier approveDepositApplication(DepositStateTransitionApprovalCommand command); + CommandProcessingResult approveDepositApplication(DepositStateTransitionApprovalCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'REJECT_DEPOSITACCOUNT')") - EntityIdentifier rejectDepositApplication(DepositStateTransitionCommand command); + CommandProcessingResult rejectDepositApplication(DepositStateTransitionCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'WITHDRAW_DEPOSITACCOUNT')") - EntityIdentifier withdrawDepositApplication(DepositStateTransitionCommand command); + CommandProcessingResult withdrawDepositApplication(DepositStateTransitionCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'APPROVALUNDO_DEPOSITACCOUNT')") - EntityIdentifier undoDepositApproval(UndoStateTransitionCommand undoCommand); + CommandProcessingResult undoDepositApproval(UndoStateTransitionCommand undoCommand); /* * @PreAuthorize(value = @@ -45,15 +45,15 @@ public interface DepositAccountWritePlatformService { */ @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'WITHDRAWAL_DEPOSITACCOUNT')") - EntityIdentifier withdrawDepositAccountMoney(DepositAccountWithdrawalCommand command); + CommandProcessingResult withdrawDepositAccountMoney(DepositAccountWithdrawalCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER', 'INTEREST_DEPOSITACCOUNT')") - EntityIdentifier withdrawDepositAccountInterestMoney(DepositAccountWithdrawInterestCommand command); + CommandProcessingResult withdrawDepositAccountInterestMoney(DepositAccountWithdrawInterestCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'RENEW_DEPOSITACCOUNT')") - EntityIdentifier renewDepositAccount(DepositAccountCommand command); + CommandProcessingResult renewDepositAccount(DepositAccountCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'PORTFOLIO_MANAGEMENT_SUPER_USER')") - EntityIdentifier postInterestToDepositAccount(Collection accounts); + CommandProcessingResult postInterestToDepositAccount(Collection accounts); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java index 8a980cecb..2f657009e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositaccount/service/DepositAccountWritePlatformServiceJpaRepositoryImpl.java @@ -7,7 +7,7 @@ import java.util.List; import org.apache.commons.lang.StringUtils; import org.joda.time.LocalDate; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.monetary.domain.Money; @@ -81,7 +81,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo @Transactional @Override - public EntityIdentifier createDepositAccount(final DepositAccountCommand command) { + public CommandProcessingResult createDepositAccount(final DepositAccountCommand command) { try { this.context.authenticatedUser(); @@ -92,16 +92,16 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo final DepositAccount account = this.depositAccountAssembler.assembleFrom(command); this.depositAccountRepository.save(account); - return new EntityIdentifier(account.getId()); + return new CommandProcessingResult(account.getId()); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); - return new EntityIdentifier(Long.valueOf(-1)); + return new CommandProcessingResult(Long.valueOf(-1)); } } @Transactional @Override - public EntityIdentifier deleteDepositAccount(final Long accountId) { + public CommandProcessingResult deleteDepositAccount(final Long accountId) { this.context.authenticatedUser(); @@ -111,12 +111,12 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo account.delete(); this.depositAccountRepository.save(account); - return new EntityIdentifier(accountId); + return new CommandProcessingResult(accountId); } @Transactional @Override - public EntityIdentifier approveDepositApplication(final DepositStateTransitionApprovalCommand command) { + public CommandProcessingResult approveDepositApplication(final DepositStateTransitionApprovalCommand command) { // AppUser currentUser = context.authenticatedUser(); @@ -147,7 +147,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo this.noteRepository.save(note); } - return new EntityIdentifier(account.getId()); + return new CommandProcessingResult(account.getId()); } @@ -161,7 +161,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo @Transactional @Override - public EntityIdentifier rejectDepositApplication(DepositStateTransitionCommand command) { + public CommandProcessingResult rejectDepositApplication(DepositStateTransitionCommand command) { // AppUser currentUser = context.authenticatedUser(); @@ -189,12 +189,12 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo this.noteRepository.save(note); } - return new EntityIdentifier(account.getId()); + return new CommandProcessingResult(account.getId()); } @Transactional @Override - public EntityIdentifier withdrawDepositApplication(DepositStateTransitionCommand command) { + public CommandProcessingResult withdrawDepositApplication(DepositStateTransitionCommand command) { // AppUser currentUser = context.authenticatedUser(); @@ -222,12 +222,12 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo this.noteRepository.save(note); } - return new EntityIdentifier(account.getId()); + return new CommandProcessingResult(account.getId()); } @Transactional @Override - public EntityIdentifier undoDepositApproval(UndoStateTransitionCommand command) { + public CommandProcessingResult undoDepositApproval(UndoStateTransitionCommand command) { context.authenticatedUser(); @@ -242,7 +242,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo Note note = Note.depositNote(account, noteText); this.noteRepository.save(note); } - return new EntityIdentifier(account.getId()); + return new CommandProcessingResult(account.getId()); } /* @@ -285,7 +285,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo @Transactional @Override - public EntityIdentifier withdrawDepositAccountMoney(final DepositAccountWithdrawalCommand command) { + public CommandProcessingResult withdrawDepositAccountMoney(final DepositAccountWithdrawalCommand command) { context.authenticatedUser(); @@ -316,12 +316,12 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo this.noteRepository.save(note); } - return new EntityIdentifier(account.getId()); + return new CommandProcessingResult(account.getId()); } @Transactional @Override - public EntityIdentifier withdrawDepositAccountInterestMoney(DepositAccountWithdrawInterestCommand command) { + public CommandProcessingResult withdrawDepositAccountInterestMoney(DepositAccountWithdrawInterestCommand command) { context.authenticatedUser(); @@ -353,7 +353,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo throw new DepositAccountTransactionsException("deposit.transaction.interest.withdrawal.cannot.withdraw", "You can not withdraw interst for this account"); } - return new EntityIdentifier(account.getId()); + return new CommandProcessingResult(account.getId()); } /* private BigDecimal getTotalWithdrawableInterestAvailable(DepositAccount account) { @@ -366,7 +366,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo @Transactional @Override - public EntityIdentifier renewDepositAccount(DepositAccountCommand command) { + public CommandProcessingResult renewDepositAccount(DepositAccountCommand command) { this.context.authenticatedUser(); @@ -386,7 +386,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo this.depositAccountRepository.save(renewedAccount); account.closeDepositAccount(defaultDepositLifecycleStateMachine()); this.depositAccountRepository.save(account); - return new EntityIdentifier(renewedAccount.getId()); + return new CommandProcessingResult(renewedAccount.getId()); } throw new DepositAccountReopenException(account.getMaturityDate()); @@ -396,7 +396,7 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo } @Override - public EntityIdentifier updateDepositAccount(DepositAccountCommand command) { + public CommandProcessingResult updateDepositAccount(DepositAccountCommand command) { try { this.context.authenticatedUser(); @@ -415,16 +415,16 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo this.depositAccountRepository.save(account); - return new EntityIdentifier(account.getId()); + return new CommandProcessingResult(account.getId()); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); - return new EntityIdentifier(Long.valueOf(-1)); + return new CommandProcessingResult(Long.valueOf(-1)); } } @Transactional @Override - public EntityIdentifier postInterestToDepositAccount(Collection accounts) { + public CommandProcessingResult postInterestToDepositAccount(Collection accounts) { try { @@ -434,9 +434,9 @@ public class DepositAccountWritePlatformServiceJpaRepositoryImpl implements Depo this.depositAccountAssembler.postInterest(account); this.depositAccountRepository.save(account); } - return new EntityIdentifier(new Long(accounts.size())); + return new CommandProcessingResult(new Long(accounts.size())); } catch (Exception e) { - return new EntityIdentifier(Long.valueOf(-1)); + return new CommandProcessingResult(Long.valueOf(-1)); } } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/api/DepositProductsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/api/DepositProductsApiResource.java index ab5392e24..c5e0d9ce2 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/api/DepositProductsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/api/DepositProductsApiResource.java @@ -22,7 +22,7 @@ import javax.ws.rs.core.UriInfo; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService; import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.data.EnumOptionData; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.monetary.data.CurrencyData; @@ -69,7 +69,7 @@ public class DepositProductsApiResource { final DepositProductCommand command = this.apiDataConversionService.convertJsonToDepositProductCommand(null, jsonRequestBody); - EntityIdentifier entityIdentifier = this.depositProductWritePlatformService.createDepositProduct(command); + CommandProcessingResult entityIdentifier = this.depositProductWritePlatformService.createDepositProduct(command); return Response.ok().entity(entityIdentifier).build(); } @@ -81,7 +81,7 @@ public class DepositProductsApiResource { public Response updateDepositProduct(@PathParam("productId") final Long productId, final String jsonRequestBody) { final DepositProductCommand command = this.apiDataConversionService.convertJsonToDepositProductCommand(productId, jsonRequestBody); - EntityIdentifier entityIdentifier = this.depositProductWritePlatformService.updateDepositProduct(command); + CommandProcessingResult entityIdentifier = this.depositProductWritePlatformService.updateDepositProduct(command); return Response.ok().entity(entityIdentifier).build(); } @@ -93,7 +93,7 @@ public class DepositProductsApiResource { this.depositProductWritePlatformService.deleteDepositProduct(productId); - return Response.ok(new EntityIdentifier(productId)).build(); + return Response.ok(new CommandProcessingResult(productId)).build(); } @GET diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformService.java index fb60c12b0..a0e755896 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformService.java @@ -1,17 +1,17 @@ package org.mifosplatform.portfolio.savingsdepositproduct.service; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.portfolio.savingsdepositproduct.command.DepositProductCommand; import org.springframework.security.access.prepost.PreAuthorize; public interface DepositProductWritePlatformService { @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'CREATE_DEPOSITPRODUCT')") - EntityIdentifier createDepositProduct(DepositProductCommand command); + CommandProcessingResult createDepositProduct(DepositProductCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'UPDATE_DEPOSITPRODUCT')") - EntityIdentifier updateDepositProduct(DepositProductCommand command); + CommandProcessingResult updateDepositProduct(DepositProductCommand command); @PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'ORGANISATION_ADMINISTRATION_SUPER_USER', 'DELETE_DEPOSITPRODUCT')") - EntityIdentifier deleteDepositProduct(Long productId); + CommandProcessingResult deleteDepositProduct(Long productId); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformServiceJpaRepositoryImpl.java index 57bf0562b..068b3502a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformServiceJpaRepositoryImpl.java @@ -1,6 +1,6 @@ package org.mifosplatform.portfolio.savingsdepositproduct.service; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency; @@ -52,7 +52,7 @@ public class DepositProductWritePlatformServiceJpaRepositoryImpl implements Depo @Transactional @Override - public EntityIdentifier createDepositProduct(final DepositProductCommand command) { + public CommandProcessingResult createDepositProduct(final DepositProductCommand command) { try { this.context.authenticatedUser(); @@ -70,16 +70,16 @@ public class DepositProductWritePlatformServiceJpaRepositoryImpl implements Depo command.isLockinPeriodAllowed(), command.getLockinPeriod(), lockinPeriodType); this.depositProductRepository.save(product); - return new EntityIdentifier(product.getId()); + return new CommandProcessingResult(product.getId()); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); - return new EntityIdentifier(Long.valueOf(-1)); + return new CommandProcessingResult(Long.valueOf(-1)); } } @Transactional @Override - public EntityIdentifier updateDepositProduct(final DepositProductCommand command) { + public CommandProcessingResult updateDepositProduct(final DepositProductCommand command) { try { this.context.authenticatedUser(); @@ -101,22 +101,22 @@ public class DepositProductWritePlatformServiceJpaRepositoryImpl implements Depo product.update(command, interestCompoundingFrequency, lockinPeriodType); this.depositProductRepository.save(product); - return new EntityIdentifier(Long.valueOf(product.getId())); + return new CommandProcessingResult(Long.valueOf(product.getId())); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); - return new EntityIdentifier(Long.valueOf(-1)); + return new CommandProcessingResult(Long.valueOf(-1)); } } @Transactional @Override - public EntityIdentifier deleteDepositProduct(final Long productId) { + public CommandProcessingResult deleteDepositProduct(final Long productId) { this.context.authenticatedUser(); DepositProduct product = this.depositProductRepository.findOne(productId); if (product == null) { throw new DepositProductNotFoundException(productId); } product.delete(); this.depositProductRepository.save(product); - return new EntityIdentifier(Long.valueOf(product.getId())); + return new CommandProcessingResult(Long.valueOf(product.getId())); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/PermissionsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/PermissionsApiResource.java index 1ae4ef9fd..33ccaf902 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/PermissionsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/PermissionsApiResource.java @@ -14,9 +14,11 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -77,8 +79,10 @@ public class PermissionsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String updatePermissionsDetails(final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "PERMISSION", "UPDATE", - "permissions", null, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updatePermissions().withUrl("/permissions") + .withJson(apiRequestBodyAsJson).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/RolesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/RolesApiResource.java index 7b36750fd..fa864fc99 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/RolesApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/RolesApiResource.java @@ -17,11 +17,13 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; import org.mifosplatform.commands.data.CommandSourceData; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.commands.service.PortfolioCommandsReadPlatformService; import org.mifosplatform.infrastructure.codes.data.CodeData; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -103,8 +105,10 @@ public class RolesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String createRole(final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "ROLE", "CREATE", "roles", null, - apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().createRole().withUrl("/roles").withJson(apiRequestBodyAsJson) + .build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -145,8 +149,10 @@ public class RolesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String updateRole(@PathParam("roleId") final Long roleId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "ROLE", "UPDATE", "roles", - roleId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateRole().withUrl("/roles").withJson(apiRequestBodyAsJson) + .withEntityId(roleId).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -175,9 +181,11 @@ public class RolesApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String updateRolePermissions(@PathParam("roleId") final Long roleId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("PERMISSIONS", "ROLE", - "UPDATEPERMISSIONS", "roles", roleId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateRolePermissions().withUrl("/roles/" + roleId + "/permissions").withJson(apiRequestBodyAsJson) + .withEntityId(roleId).build(); + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); + return this.toApiJsonSerializer.serialize(result); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/UsersApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/UsersApiResource.java index 1ff62000a..c33ff554e 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/UsersApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/api/UsersApiResource.java @@ -19,9 +19,11 @@ import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriInfo; +import org.mifosplatform.commands.domain.CommandWrapper; +import org.mifosplatform.commands.service.CommandWrapperBuilder; import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService; import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings; import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; @@ -118,8 +120,10 @@ public class UsersApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String createUser(final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "USER", "CREATE", "users", null, - apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().createUser().withUrl("/users").withJson(apiRequestBodyAsJson) + .build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -130,8 +134,10 @@ public class UsersApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String updateUser(@PathParam("userId") final Long userId, final String apiRequestBodyAsJson) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "USER", "UPDATE", "users", - userId, apiRequestBodyAsJson); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateUser().withUrl("/users").withJson(apiRequestBodyAsJson) + .withEntityId(userId).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } @@ -142,8 +148,10 @@ public class UsersApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String deleteUser(@PathParam("userId") final Long userId) { - final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "USER", "DELETE", "users", - userId, "{}"); + final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteUser().withUrl("/users").withJson("{}") + .withEntityId(userId).build(); + + final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); return this.toApiJsonSerializer.serialize(result); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/CreateRoleCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/CreateRoleCommandHandler.java index 6990dc109..03d43d4f4 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/CreateRoleCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/CreateRoleCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.useradministration.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.useradministration.service.RoleWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class CreateRoleCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.writePlatformService.createRole(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/CreateUserCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/CreateUserCommandHandler.java index 78d2bec50..9d97aadd8 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/CreateUserCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/CreateUserCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.useradministration.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.useradministration.service.AppUserWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class CreateUserCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.writePlatformService.createUser(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/DeleteUserCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/DeleteUserCommandHandler.java index 8c8898302..c86f30acc 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/DeleteUserCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/DeleteUserCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.useradministration.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.useradministration.service.AppUserWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class DeleteUserCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.deleteUser(command.resourceId()); + return this.writePlatformService.deleteUser(command.entityId()); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateMakerCheckerPermissionsCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateMakerCheckerPermissionsCommandHandler.java index 33ed47f49..f8d202074 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateMakerCheckerPermissionsCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateMakerCheckerPermissionsCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.useradministration.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.useradministration.service.PermissionWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,7 +20,7 @@ public class UpdateMakerCheckerPermissionsCommandHandler implements NewCommandSo @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { return this.writePlatformService.updateMakerCheckerPermissions(command); } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateRoleCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateRoleCommandHandler.java index 00d887291..53e5d81a3 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateRoleCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateRoleCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.useradministration.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.useradministration.service.RoleWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class UpdateRoleCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.updateRole(command.resourceId(), command); + return this.writePlatformService.updateRole(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateRolePermissionsCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateRolePermissionsCommandHandler.java index 81d1f8dc9..2aac4d928 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateRolePermissionsCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateRolePermissionsCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.useradministration.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.useradministration.service.RoleWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -20,8 +20,8 @@ public class UpdateRolePermissionsCommandHandler implements NewCommandSourceHand @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { - return this.writePlatformService.updateRolePermissions(command.resourceId(), command); + return this.writePlatformService.updateRolePermissions(command.entityId(), command); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateUserCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateUserCommandHandler.java index dd36a81f5..cdc3c00ce 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateUserCommandHandler.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/handler/UpdateUserCommandHandler.java @@ -2,7 +2,7 @@ package org.mifosplatform.useradministration.handler; import org.mifosplatform.commands.handler.NewCommandSourceHandler; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.useradministration.domain.AppUser; import org.mifosplatform.useradministration.service.AppUserWritePlatformService; @@ -24,12 +24,12 @@ public class UpdateUserCommandHandler implements NewCommandSourceHandler { @Transactional @Override - public EntityIdentifier processCommand(final JsonCommand command) { + public CommandProcessingResult processCommand(final JsonCommand command) { final AppUser loggedInUser = context.authenticatedUser(); - final Long userId = command.resourceId(); - EntityIdentifier result = null; + final Long userId = command.entityId(); + CommandProcessingResult result = null; if (loggedInUser.hasIdOf(userId)) { result = this.writePlatformService.updateUsersOwnAccountDetails(userId, command); } else { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserWritePlatformService.java index 917e1375f..e9ab59307 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserWritePlatformService.java @@ -1,17 +1,17 @@ package org.mifosplatform.useradministration.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface AppUserWritePlatformService { - EntityIdentifier createUser(JsonCommand command); + CommandProcessingResult createUser(JsonCommand command); - EntityIdentifier updateUser(Long userId, JsonCommand command); + CommandProcessingResult updateUser(Long userId, JsonCommand command); - EntityIdentifier deleteUser(Long userId); + CommandProcessingResult deleteUser(Long userId); // we dont put any permissions on this e.g. a user with no admin rights can // change their own details (email, username, password etc). - EntityIdentifier updateUsersOwnAccountDetails(Long userId, JsonCommand command); + CommandProcessingResult updateUsersOwnAccountDetails(Long userId, JsonCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java index 9a457f4ec..1ca777004 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/AppUserWritePlatformServiceJpaRepositoryImpl.java @@ -8,7 +8,8 @@ import java.util.Set; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.ApiParameterError; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException; import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException; import org.mifosplatform.infrastructure.core.service.PlatformEmailSendException; @@ -62,7 +63,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit @Transactional @Override - public EntityIdentifier createUser(final JsonCommand command) { + public CommandProcessingResult createUser(final JsonCommand command) { try { context.authenticatedUser(); @@ -82,10 +83,11 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit final AppUser appUser = AppUser.fromJson(userOffice, allRoles, command); this.userDomainService.create(appUser); - return EntityIdentifier.resourceResult(appUser.getId(), null); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(appUser.getId()) + .withOfficeId(userOffice.getId()).build(); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } catch (PlatformEmailSendException e) { final List dataValidationErrors = new ArrayList(); @@ -101,7 +103,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit @Transactional @Override - public EntityIdentifier updateUser(final Long userId, final JsonCommand command) { + public CommandProcessingResult updateUser(final Long userId, final JsonCommand command) { try { context.authenticatedUser(); @@ -133,10 +135,11 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit this.appUserRepository.save(userToUpdate); } - return EntityIdentifier.withChanges(userId, changes); + return new CommandProcessingResultBuilder().withEntityId(userId).withOfficeId(userToUpdate.getOffice().getId()).with(changes) + .build(); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } } @@ -147,7 +150,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit */ @Transactional @Override - public EntityIdentifier updateUsersOwnAccountDetails(final Long userId, final JsonCommand command) { + public CommandProcessingResult updateUsersOwnAccountDetails(final Long userId, final JsonCommand command) { try { context.authenticatedUser(); @@ -179,10 +182,10 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit this.appUserRepository.saveAndFlush(userToUpdate); } - return EntityIdentifier.withChanges(userId, changes); + return CommandProcessingResult.withChanges(userId, changes); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); - return EntityIdentifier.empty(); + return CommandProcessingResult.empty(); } } @@ -204,7 +207,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit @Transactional @Override - public EntityIdentifier deleteUser(final Long userId) { + public CommandProcessingResult deleteUser(final Long userId) { final AppUser user = this.appUserRepository.findOne(userId); if (user == null || user.isDeleted()) { throw new UserNotFoundException(userId); } @@ -212,7 +215,7 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit user.delete(); this.appUserRepository.save(user); - return EntityIdentifier.resourceResult(userId, null); + return new CommandProcessingResultBuilder().withEntityId(userId).withOfficeId(user.getOffice().getId()).build(); } /* diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/PermissionWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/PermissionWritePlatformService.java index b76169fb0..ab914f48c 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/PermissionWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/PermissionWritePlatformService.java @@ -1,9 +1,9 @@ package org.mifosplatform.useradministration.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface PermissionWritePlatformService { - EntityIdentifier updateMakerCheckerPermissions(JsonCommand command); + CommandProcessingResult updateMakerCheckerPermissions(JsonCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/PermissionWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/PermissionWritePlatformServiceJpaRepositoryImpl.java index 00f101463..134eb46e6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/PermissionWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/PermissionWritePlatformServiceJpaRepositoryImpl.java @@ -5,7 +5,8 @@ import java.util.HashMap; import java.util.Map; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.useradministration.command.PermissionsCommand; import org.mifosplatform.useradministration.domain.Permission; @@ -34,7 +35,7 @@ public class PermissionWritePlatformServiceJpaRepositoryImpl implements Permissi @Transactional @Override - public EntityIdentifier updateMakerCheckerPermissions(final JsonCommand command) { + public CommandProcessingResult updateMakerCheckerPermissions(final JsonCommand command) { context.authenticatedUser(); final Collection allPermissions = this.permissionRepository.findAll(); @@ -63,7 +64,7 @@ public class PermissionWritePlatformServiceJpaRepositoryImpl implements Permissi changes.put("permissions", changedPermissions); } - return EntityIdentifier.withChanges(null, changes); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).with(changes).build(); } private Permission findPermissionInCollectionByCode(final Collection allPermissions, final String permissionCode) { diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleWritePlatformService.java index 2558602ec..80f734b50 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleWritePlatformService.java @@ -1,13 +1,13 @@ package org.mifosplatform.useradministration.service; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface RoleWritePlatformService { - EntityIdentifier createRole(JsonCommand command); + CommandProcessingResult createRole(JsonCommand command); - EntityIdentifier updateRole(Long roleId, JsonCommand command); + CommandProcessingResult updateRole(Long roleId, JsonCommand command); - EntityIdentifier updateRolePermissions(Long roleId, JsonCommand command); + CommandProcessingResult updateRolePermissions(Long roleId, JsonCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java index 382a7e434..dcd4008c6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/useradministration/service/RoleWritePlatformServiceJpaRepositoryImpl.java @@ -5,7 +5,8 @@ import java.util.HashMap; import java.util.Map; import org.mifosplatform.infrastructure.core.api.JsonCommand; -import org.mifosplatform.infrastructure.core.data.EntityIdentifier; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.useradministration.command.PermissionsCommand; import org.mifosplatform.useradministration.command.RoleCommand; @@ -43,7 +44,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf @Transactional @Override - public EntityIdentifier createRole(final JsonCommand command) { + public CommandProcessingResult createRole(final JsonCommand command) { context.authenticatedUser(); @@ -53,12 +54,12 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf final Role entity = Role.fromJson(command); this.roleRepository.save(entity); - return EntityIdentifier.resourceResult(entity.getId(), null); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(entity.getId()).build(); } @Transactional @Override - public EntityIdentifier updateRole(final Long roleId, final JsonCommand command) { + public CommandProcessingResult updateRole(final Long roleId, final JsonCommand command) { context.authenticatedUser(); @@ -73,12 +74,12 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf this.roleRepository.save(role); } - return EntityIdentifier.withChanges(role.getId(), changes); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(roleId).with(changes).build(); } @Transactional @Override - public EntityIdentifier updateRolePermissions(final Long roleId, final JsonCommand command) { + public CommandProcessingResult updateRolePermissions(final Long roleId, final JsonCommand command) { context.authenticatedUser(); final Role role = this.roleRepository.findOne(roleId); @@ -106,7 +107,7 @@ public class RoleWritePlatformServiceJpaRepositoryImpl implements RoleWritePlatf this.roleRepository.save(role); } - return EntityIdentifier.withChanges(role.getId(), changes); + return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(roleId).with(changes).build(); } private Permission findPermissionByCode(Collection allPermissions, String permissionCode) {