From 2d405a14abad6374ec94916355a28bd6ac07987b Mon Sep 17 00:00:00 2001 From: John Woodlock Date: Tue, 26 Mar 2013 11:31:58 +0000 Subject: [PATCH] mifosx-276 Support audit 'ids' when in maker-checker mode --- ...ommandIsNotApprovedByCheckerException.java | 36 ++++++++++++------- .../service/CommandProcessingService.java | 6 ++-- ...CommandSourceWritePlatformServiceImpl.java | 12 +------ .../SynchronousCommandProcessingService.java | 17 ++++----- 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/exception/RollbackTransactionAsCommandIsNotApprovedByCheckerException.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/exception/RollbackTransactionAsCommandIsNotApprovedByCheckerException.java index 8b97d1285..25b5a0390 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/exception/RollbackTransactionAsCommandIsNotApprovedByCheckerException.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/exception/RollbackTransactionAsCommandIsNotApprovedByCheckerException.java @@ -5,18 +5,30 @@ */ package org.mifosplatform.commands.exception; -public class RollbackTransactionAsCommandIsNotApprovedByCheckerException extends RuntimeException { +import org.mifosplatform.commands.domain.CommandSource; - /** - * Used to pass back the changes detected when updating a resource so the command json can be changed to only the changes. - */ - private final String jsonOfChangesOnly; +public class RollbackTransactionAsCommandIsNotApprovedByCheckerException extends + RuntimeException { - public RollbackTransactionAsCommandIsNotApprovedByCheckerException(final String jsonOfChangesOnly) { - this.jsonOfChangesOnly = jsonOfChangesOnly; - } - - public String getJsonOfChangesOnly() { - return this.jsonOfChangesOnly; - } + /** + * When maker-checker is configured globally and also for the current + * transaction. + * + * An initial save determines if there are any integrity rule or data + * problems. + * + * If there isn't... and the transaction is from a maker... then this roll + * back is issued and the commandSourceResult is used to write the audit + * entry. + */ + private final CommandSource commandSourceResult; + + public RollbackTransactionAsCommandIsNotApprovedByCheckerException( + final CommandSource commandSourceResult) { + this.commandSourceResult = commandSourceResult; + } + + public CommandSource getCommandSourceResult() { + return this.commandSourceResult; + } } 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 3bc1e45d5..8d61f2b26 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 @@ -5,14 +5,16 @@ */ package org.mifosplatform.commands.service; +import org.mifosplatform.commands.domain.CommandSource; import org.mifosplatform.commands.domain.CommandWrapper; import org.mifosplatform.infrastructure.core.api.JsonCommand; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; public interface CommandProcessingService { - CommandProcessingResult processAndLogCommand(CommandWrapper wrapper, JsonCommand command, boolean isApprovedByChecker); + CommandProcessingResult processAndLogCommand(CommandWrapper wrapper, + JsonCommand command, boolean isApprovedByChecker); - CommandProcessingResult logCommand(CommandWrapper wrapper, JsonCommand command); + CommandProcessingResult logCommand(CommandSource commandSourceResult); } 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 53e428e53..da9532b9b 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,6 @@ */ package org.mifosplatform.commands.service; -import org.apache.commons.lang.StringUtils; import org.mifosplatform.commands.domain.CommandSource; import org.mifosplatform.commands.domain.CommandSourceRepository; import org.mifosplatform.commands.domain.CommandWrapper; @@ -68,16 +67,7 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio 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, wrapper.getEntityName(), - wrapper.getEntityId(), wrapper.getSubentityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), - wrapper.getSavingsId(), wrapper.getCodeId(), wrapper.getSupportedEntityType(), wrapper.getSupportedEntityId(), - wrapper.getTransactionId()); - - result = this.processAndLogCommandService.logCommand(wrapper, command); + result = this.processAndLogCommandService.logCommand(e.getCommandSourceResult()); } return result; 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 c06b689b3..14331db03 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 @@ -85,24 +85,19 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer commandSourceRepository.save(commandSourceResult); } - if (rollbackTransaction) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(changesOnlyJson); } + if (rollbackTransaction) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(commandSourceResult); } return result; } @Transactional @Override - public CommandProcessingResult logCommand(final CommandWrapper wrapper, final JsonCommand command) { + public CommandProcessingResult logCommand(final CommandSource commandSourceResult) { - final AppUser maker = context.authenticatedUser(); - - final CommandSource commandSourceResult = CommandSource.fullEntryFrom(wrapper, command, maker); - if (commandSourceResult.hasJson()) { - commandSourceResult.markAsAwaitingApproval(); - commandSourceRepository.save(commandSourceResult); - } - - return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(commandSourceResult.resourceId()) + commandSourceResult.markAsAwaitingApproval(); + commandSourceRepository.save(commandSourceResult); + + return new CommandProcessingResultBuilder().withCommandId(commandSourceResult.getId()).withEntityId(commandSourceResult.getResourceId()) .build(); }