mifosx-276 Support audit 'ids' when in maker-checker mode
This commit is contained in:
+23
-11
@@ -5,18 +5,30 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.commands.exception;
|
package org.mifosplatform.commands.exception;
|
||||||
|
|
||||||
public class RollbackTransactionAsCommandIsNotApprovedByCheckerException extends RuntimeException {
|
import org.mifosplatform.commands.domain.CommandSource;
|
||||||
|
|
||||||
/**
|
public class RollbackTransactionAsCommandIsNotApprovedByCheckerException extends
|
||||||
* Used to pass back the changes detected when updating a resource so the command json can be changed to only the changes.
|
RuntimeException {
|
||||||
*/
|
|
||||||
private final String jsonOfChangesOnly;
|
|
||||||
|
|
||||||
public RollbackTransactionAsCommandIsNotApprovedByCheckerException(final String jsonOfChangesOnly) {
|
/**
|
||||||
this.jsonOfChangesOnly = 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 String getJsonOfChangesOnly() {
|
public RollbackTransactionAsCommandIsNotApprovedByCheckerException(
|
||||||
return this.jsonOfChangesOnly;
|
final CommandSource commandSourceResult) {
|
||||||
}
|
this.commandSourceResult = commandSourceResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommandSource getCommandSourceResult() {
|
||||||
|
return this.commandSourceResult;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -5,14 +5,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.commands.service;
|
package org.mifosplatform.commands.service;
|
||||||
|
|
||||||
|
import org.mifosplatform.commands.domain.CommandSource;
|
||||||
import org.mifosplatform.commands.domain.CommandWrapper;
|
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||||
|
|
||||||
public interface CommandProcessingService {
|
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;
|
package org.mifosplatform.commands.service;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.mifosplatform.commands.domain.CommandSource;
|
import org.mifosplatform.commands.domain.CommandSource;
|
||||||
import org.mifosplatform.commands.domain.CommandSourceRepository;
|
import org.mifosplatform.commands.domain.CommandSourceRepository;
|
||||||
import org.mifosplatform.commands.domain.CommandWrapper;
|
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||||
@@ -68,16 +67,7 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
|
|||||||
result = this.processAndLogCommandService.processAndLogCommand(wrapper, command, isApprovedByChecker);
|
result = this.processAndLogCommandService.processAndLogCommand(wrapper, command, isApprovedByChecker);
|
||||||
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
|
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
|
||||||
|
|
||||||
final String jsonToUse = StringUtils.defaultIfEmpty(e.getJsonOfChangesOnly(), json);
|
result = this.processAndLogCommandService.logCommand(e.getCommandSourceResult());
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+5
-10
@@ -85,24 +85,19 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
|||||||
commandSourceRepository.save(commandSourceResult);
|
commandSourceRepository.save(commandSourceResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rollbackTransaction) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(changesOnlyJson); }
|
if (rollbackTransaction) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(commandSourceResult); }
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public CommandProcessingResult logCommand(final CommandWrapper wrapper, final JsonCommand command) {
|
public CommandProcessingResult logCommand(final CommandSource commandSourceResult) {
|
||||||
|
|
||||||
final AppUser maker = context.authenticatedUser();
|
commandSourceResult.markAsAwaitingApproval();
|
||||||
|
commandSourceRepository.save(commandSourceResult);
|
||||||
|
|
||||||
final CommandSource commandSourceResult = CommandSource.fullEntryFrom(wrapper, command, maker);
|
return new CommandProcessingResultBuilder().withCommandId(commandSourceResult.getId()).withEntityId(commandSourceResult.getResourceId())
|
||||||
if (commandSourceResult.hasJson()) {
|
|
||||||
commandSourceResult.markAsAwaitingApproval();
|
|
||||||
commandSourceRepository.save(commandSourceResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(commandSourceResult.resourceId())
|
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user