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 4a9ae0da6..a64a9d697 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 @@ -47,7 +47,6 @@ public class CommandSource extends AbstractPersistable { @Column(name = "loan_id") private Long loanId; - @SuppressWarnings("unused") @Column(name = "api_get_url", length = 100) private String resourceGetUrl; @@ -156,4 +155,8 @@ public class CommandSource extends AbstractPersistable { this.clientId = clientId; this.loanId = loanId; } + + public String getResourceGetUrl() { + return this.resourceGetUrl; + } } \ 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 552e68575..73f3db897 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 @@ -27,15 +27,16 @@ public class CommandWrapper { private final Long supportedEntityId; public static CommandWrapper wrap(final String actionName, final String enityName, final Long resourceId) { - return new CommandWrapper(null, actionName, enityName, resourceId); + return new CommandWrapper(null, actionName, enityName, resourceId, null); } public static CommandWrapper fromExistingCommand(final Long commandId, final String actionName, final String enityName, - final Long resourceId) { - return new CommandWrapper(commandId, actionName, enityName, resourceId); + final Long resourceId, final String resourceGetUrl) { + return new CommandWrapper(commandId, actionName, enityName, resourceId, resourceGetUrl); } - private CommandWrapper(final Long commandId, final String actionName, final String enityName, final Long resourceId) { + private CommandWrapper(final Long commandId, final String actionName, final String enityName, final Long resourceId, + final String resourceGetUrl) { this.commandId = commandId; this.officeId = null; this.groupId = null; @@ -45,14 +46,19 @@ public class CommandWrapper { this.entityName = enityName; this.taskPermissionName = actionName + "_" + entityName; this.entityId = resourceId; - this.apptableId = null; this.datatableId = null; this.codeId = null; this.supportedEntityType = null; this.supportedEntityId = null; - this.href = null; + this.href = resourceGetUrl; this.json = null; this.transactionId = null; + + if (this.href.contains("datatables")) { + this.apptableId = resourceId; + } else { + this.apptableId = null; + } } public CommandWrapper(final Long officeId, final Long groupId, final Long clientId, final Long loanId, final String actionName, 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 2b52ba4c1..b46567386 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 @@ -66,8 +66,15 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio final String jsonToUse = StringUtils.defaultIfEmpty(e.getJsonOfChangesOnly(), json); final JsonElement parsedCommand = this.fromApiJsonHelper.parse(jsonToUse); + + // for datatables + Long entityId = wrapper.getEntityId(); + if (entityId == null && wrapper.isDatatableResource()) { + entityId = wrapper.getApptableId(); + } + final JsonCommand command = JsonCommand.from(jsonToUse, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(), - wrapper.getEntityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), wrapper.getApptableId(), + entityId, wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), wrapper.getApptableId(), wrapper.getDatatableId(), wrapper.getCodeId(), wrapper.getSupportedEntityType(), wrapper.getSupportedEntityId(), wrapper.getTransactionId()); result = this.processAndLogCommandService.logCommand(wrapper, command); @@ -84,11 +91,11 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio context.authenticatedUser().validateHasCheckerPermissionTo(commandSourceInput.getPermissionCode()); final CommandWrapper wrapper = CommandWrapper.fromExistingCommand(commandId, commandSourceInput.getActionName(), - commandSourceInput.getEntityName(), commandSourceInput.resourceId()); + commandSourceInput.getEntityName(), commandSourceInput.resourceId(), commandSourceInput.getResourceGetUrl()); final JsonElement parsedCommand = this.fromApiJsonHelper.parse(commandSourceInput.json()); final JsonCommand command = JsonCommand.fromExistingCommand(commandId, commandSourceInput.json(), parsedCommand, - this.fromApiJsonHelper, commandSourceInput.resourceId()); + this.fromApiJsonHelper, commandSourceInput.getEntityName(), commandSourceInput.resourceId()); final boolean makerCheckerApproval = true; return this.processAndLogCommandService.processAndLogCommand(wrapper, command, makerCheckerApproval); 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 3f46cab56..78a953c1c 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 @@ -46,21 +46,21 @@ public final class JsonCommand { public static JsonCommand from(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, final Long codeId, final String supportedEntityType, final Long supportedEntityId, - final String transactionId) { + final Long apptableId, final Long datatableId, final Long codeId, final String supportedEntityType, + final Long supportedEntityId, final String transactionId) { return new JsonCommand(null, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, groupId, clientId, loanId, apptableId, datatableId, codeId, supportedEntityType, supportedEntityId, transactionId); } 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, - null, null, null, null); + final FromJsonHelper fromApiJsonHelper, final String entityName, final Long resourceId) { + return new JsonCommand(commandId, jsonCommand, parsedCommand, fromApiJsonHelper, entityName, resourceId, null, null, null, null, + 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, final Long codeId, + final Long clientId, final Long loanId, final Long apptableId, final Long datatableId, final Long codeId, final String supportedEntityType, final Long supportedEntityId, final String transactionId) { this.commandId = commandId; this.jsonCommand = jsonCommand; @@ -135,15 +135,14 @@ public final class JsonCommand { public Long getSupportedEntityId() { return this.supportedEntityId; } - + public String getSupportedEntityType() { return this.supportedEntityType; } - public String getTransactionId(){ + public String getTransactionId() { return this.transactionId; } - private boolean differenceExists(final LocalDate baseValue, final LocalDate workingCopyValue) { boolean differenceExists = false; 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 2920b21a7..792c023cb 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 @@ -28,11 +28,16 @@ public class CreateDatatableEntryCommandHandler implements NewCommandSourceHandl @Override public CommandProcessingResult processCommand(final JsonCommand command) { - this.writePlatformService.createNewDatatableEntry(command.entityName(), command.getApptableId(), command); + Long appTableId = command.getApptableId(); + if (appTableId == null) { + appTableId = command.entityId(); + } + + this.writePlatformService.createNewDatatableEntry(command.entityName(), appTableId, command); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // - .withEntityId(command.getApptableId()) // + .withEntityId(appTableId) // .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 b3801a3ea..e5e3df0de 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 @@ -28,11 +28,16 @@ public class DeleteOneToOneDatatableEntryCommandHandler implements NewCommandSou @Override public CommandProcessingResult processCommand(final JsonCommand command) { - this.writePlatformService.deleteDatatableEntries(command.entityName(), command.getApptableId()); + Long appTableId = command.getApptableId(); + if (appTableId == null) { + appTableId = command.entityId(); + } + + this.writePlatformService.deleteDatatableEntries(command.entityName(), appTableId); return new CommandProcessingResultBuilder() // .withCommandId(command.commandId()) // - .withEntityId(command.getApptableId()) // + .withEntityId(appTableId) // .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 adf1956d2..6068fcfb1 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 @@ -30,10 +30,18 @@ public class UpdateOneToOneDatatableEntryCommandHandler implements NewCommandSou @Override public CommandProcessingResult processCommand(final JsonCommand command) { - final Map changes = this.writePlatformService.updateDatatableEntryOneToOne(command.entityName(), command.getApptableId(), + Long appTableId = command.getApptableId(); + if (appTableId == null) { + appTableId = command.entityId(); + } + + final Map changes = this.writePlatformService.updateDatatableEntryOneToOne(command.entityName(), appTableId, command); - return new CommandProcessingResultBuilder().withCommandId(command.commandId()).withEntityId(command.getApptableId()).with(changes) + return new CommandProcessingResultBuilder() // + .withCommandId(command.commandId()) // + .withEntityId(appTableId) // + .with(changes) // .build(); } } \ No newline at end of file