mifosx-276 Support audit 'ids' when in maker-checker mode
This commit is contained in:
+24
-12
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
+1
-11
@@ -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;
|
||||
|
||||
+6
-11
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user