diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/PortfolioCommandSerializerService.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/PortfolioCommandSerializerService.java
index dde64bf76..c1314b396 100644
--- a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/PortfolioCommandSerializerService.java
+++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/PortfolioCommandSerializerService.java
@@ -1,43 +1,15 @@
package org.mifosng.platform.api.infrastructure;
-import org.mifosplatform.infrastructure.codes.command.CodeCommand;
-import org.mifosplatform.infrastructure.configuration.command.CurrencyCommand;
-import org.mifosplatform.infrastructure.office.command.BranchMoneyTransferCommand;
-import org.mifosplatform.infrastructure.office.command.OfficeCommand;
-import org.mifosplatform.infrastructure.staff.command.StaffCommand;
-import org.mifosplatform.infrastructure.user.command.PermissionsCommand;
-import org.mifosplatform.infrastructure.user.command.RoleCommand;
-import org.mifosplatform.infrastructure.user.command.RolePermissionCommand;
-import org.mifosplatform.infrastructure.user.command.UserCommand;
-import org.mifosplatform.portfolio.fund.command.FundCommand;
-
/**
* Service for serializing commands into another format.
*
- *
Known implementations:
- * @see PortfolioCommandSerializerServiceJson
+ *
+ * Known implementations:
+ *
+ *
+ * @see PortfolioCommandSerializerServiceJson
*/
public interface PortfolioCommandSerializerService {
- String serializeRoleCommandToJson(RoleCommand command);
-
- String serializeRolePermissionCommandToJson(RolePermissionCommand command);
-
- String serializePermissionsCommandToJson(PermissionsCommand command);
-
- String serializeUserCommandToJson(UserCommand command);
-
- String serializeCodeCommandToJson(CodeCommand command);
-
- String serializeStaffCommandToJson(StaffCommand command);
-
- String serializeFundCommandToJson(FundCommand command);
-
- String serializeOfficeCommandToJson(OfficeCommand command);
-
- String serializeOfficeTransactionCommandToJson(BranchMoneyTransferCommand command);
-
- String serializeCurrencyCommandToJson(CurrencyCommand command);
-
String serializeCommandToJson(Object command);
}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/PortfolioCommandSerializerServiceJson.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/PortfolioCommandSerializerServiceJson.java
index ba0624cba..3a6ed6ce2 100644
--- a/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/PortfolioCommandSerializerServiceJson.java
+++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/infrastructure/PortfolioCommandSerializerServiceJson.java
@@ -3,16 +3,6 @@ package org.mifosng.platform.api.infrastructure;
import java.util.HashSet;
import org.mifosng.platform.infrastructure.api.GoogleGsonSerializerHelper;
-import org.mifosplatform.infrastructure.codes.command.CodeCommand;
-import org.mifosplatform.infrastructure.configuration.command.CurrencyCommand;
-import org.mifosplatform.infrastructure.office.command.BranchMoneyTransferCommand;
-import org.mifosplatform.infrastructure.office.command.OfficeCommand;
-import org.mifosplatform.infrastructure.staff.command.StaffCommand;
-import org.mifosplatform.infrastructure.user.command.PermissionsCommand;
-import org.mifosplatform.infrastructure.user.command.RoleCommand;
-import org.mifosplatform.infrastructure.user.command.RolePermissionCommand;
-import org.mifosplatform.infrastructure.user.command.UserCommand;
-import org.mifosplatform.portfolio.fund.command.FundCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -33,69 +23,9 @@ public class PortfolioCommandSerializerServiceJson implements PortfolioCommandSe
}
@Override
- public String serializeRoleCommandToJson(final RoleCommand command) {
+ public String serializeCommandToJson(Object command) {
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet(), false,
new HashSet());
return helper.serializedJsonFrom(gsonDeserializer, command);
}
-
- @Override
- public String serializeRolePermissionCommandToJson(final RolePermissionCommand command) {
- final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet(), false, new HashSet());
- return helper.serializedJsonFrom(gsonDeserializer, command);
- }
-
- @Override
- public String serializePermissionsCommandToJson(final PermissionsCommand command) {
- final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet(), false, new HashSet());
- return helper.serializedJsonFrom(gsonDeserializer, command);
- }
-
- @Override
- public String serializeUserCommandToJson(final UserCommand command) {
- final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet(), false, new HashSet());
- return helper.serializedJsonFrom(gsonDeserializer, command);
- }
-
- @Override
- public String serializeCodeCommandToJson(final CodeCommand command) {
- final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet(), false, new HashSet());
- return helper.serializedJsonFrom(gsonDeserializer, command);
- }
-
- @Override
- public String serializeStaffCommandToJson(final StaffCommand command) {
- final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet(), false, new HashSet());
- return helper.serializedJsonFrom(gsonDeserializer, command);
- }
-
- @Override
- public String serializeFundCommandToJson(final FundCommand command) {
- final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet(), false, new HashSet());
- return helper.serializedJsonFrom(gsonDeserializer, command);
- }
-
- @Override
- public String serializeOfficeCommandToJson(final OfficeCommand command) {
- final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet(), false, new HashSet());
- return helper.serializedJsonFrom(gsonDeserializer, command);
- }
-
- @Override
- public String serializeOfficeTransactionCommandToJson(final BranchMoneyTransferCommand command) {
- final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet(), false, new HashSet());
- return helper.serializedJsonFrom(gsonDeserializer, command);
- }
-
- @Override
- public String serializeCurrencyCommandToJson(final CurrencyCommand command) {
- final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet(), false, new HashSet());
- return helper.serializedJsonFrom(gsonDeserializer, command);
- }
-
- @Override
- public String serializeCommandToJson(Object command) {
- final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(new HashSet(), false, new HashSet());
- return helper.serializedJsonFrom(gsonDeserializer, command);
- }
}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/ChargeDefinitionCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/ChargeDefinitionCommandHandler.java
index 155934181..1850bd90f 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/ChargeDefinitionCommandHandler.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/ChargeDefinitionCommandHandler.java
@@ -33,12 +33,8 @@ public class ChargeDefinitionCommandHandler implements CommandSourceHandler {
this.writePlatformService = writePlatformService;
}
- /*
- * Used when users with 'create' capability create a command. If 'maker-checker' is not
- * enabled for this specific command then the 'creator' is also marked 'as the checker' and command
- * automatically is processed and changes state of system.
- */
- public CommandSource handle(final CommandSource commandSource, final String commandSerializedAsJson) {
+ @Override
+ public CommandSource handleCommandWithSupportForRollback(final CommandSource commandSource) {
final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate();
@@ -81,10 +77,8 @@ public class ChargeDefinitionCommandHandler implements CommandSourceHandler {
return commandSourceResult;
}
- /*
- * Used when users with 'checker' capability approve a command.
- */
- public CommandSource handle(final CommandSource commandSourceResult) {
+ @Override
+ public CommandSource handleCommandForCheckerApproval(final CommandSource commandSourceResult) {
final AppUser checker = context.authenticatedUser();
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/ClientCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/ClientCommandHandler.java
index 751066a6c..2a6a310c9 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/ClientCommandHandler.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/ClientCommandHandler.java
@@ -34,7 +34,8 @@ public class ClientCommandHandler implements CommandSourceHandler {
this.clientWritePlatformService = clientWritePlatformService;
}
- public CommandSource handle(final CommandSource commandSource, final String commandSerializedAsJson) {
+ @Override
+ public CommandSource handleCommandWithSupportForRollback(final CommandSource commandSource) {
final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate();
@@ -82,7 +83,8 @@ public class ClientCommandHandler implements CommandSourceHandler {
return commandSourceResult;
}
- public CommandSource handle(final CommandSource commandSourceResult) {
+ @Override
+ public CommandSource handleCommandForCheckerApproval(final CommandSource commandSourceResult) {
final AppUser checker = context.authenticatedUser();
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CodeCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CodeCommandHandler.java
index 7f64a4efc..68dc08eb2 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CodeCommandHandler.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CodeCommandHandler.java
@@ -4,9 +4,7 @@ import java.util.Arrays;
import java.util.List;
import org.joda.time.LocalDate;
-import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService;
-import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosplatform.commands.domain.CommandSource;
import org.mifosplatform.commands.service.ChangeDetectionService;
@@ -22,42 +20,29 @@ public class CodeCommandHandler implements CommandSourceHandler {
private final PlatformSecurityContext context;
private final ChangeDetectionService changeDetectionService;
- private final PortfolioApiDataConversionService apiDataConversionService;
- private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandDeserializerService commandDeserializerService;
private final CodeWritePlatformService writePlatformService;
-
+
@Autowired
public CodeCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
- final PortfolioApiDataConversionService apiDataConversionService,
- final PortfolioCommandSerializerService commandSerializerService,
- final PortfolioCommandDeserializerService commandDeserializerService,
- final CodeWritePlatformService writePlatformService) {
+ final PortfolioCommandDeserializerService commandDeserializerService, final CodeWritePlatformService writePlatformService) {
this.context = context;
this.changeDetectionService = changeDetectionService;
- this.apiDataConversionService = apiDataConversionService;
- this.commandSerializerService = commandSerializerService;
this.commandDeserializerService = commandDeserializerService;
this.writePlatformService = writePlatformService;
}
- /*
- * Used when users with 'create' capability create a command. If 'maker-checker' is not
- * enabled for this specific command then the 'creator' is also marked 'as the checker' and command
- * automatically is processed and changes state of system.
- */
- public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) {
+ @Override
+ public CommandSource handleCommandWithSupportForRollback(final CommandSource commandSource) {
final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate();
+ final Long resourceId = commandSource.resourceId();
+ final CodeCommand command = this.commandDeserializerService.deserializeCodeCommand(resourceId, commandSource.json(), false);
+
CommandSource commandSourceResult = commandSource.copy();
- final Long resourceId = commandSource.resourceId();
- final CodeCommand command = this.apiDataConversionService.convertApiRequestJsonToCodeCommand(resourceId, apiRequestBodyInJson);
- final String commandSerializedAsJson = this.commandSerializerService.serializeCodeCommandToJson(command);
- commandSourceResult.updateJsonTo(commandSerializedAsJson);
-
if (commandSource.isCreate()) {
try {
Long newResourceId = this.writePlatformService.createCode(command);
@@ -68,12 +53,14 @@ public class CodeCommandHandler implements CommandSourceHandler {
}
} else if (commandSource.isUpdate()) {
try {
- final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(), commandSource.resourceId(), commandSerializedAsJson);
+ final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(),
+ commandSource.resourceId(), commandSource.json());
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
- final CodeCommand changesOnly = this.commandDeserializerService.deserializeCodeCommand(resourceId, jsonOfChangesOnly, false);
+ final CodeCommand changesOnly = this.commandDeserializerService
+ .deserializeCodeCommand(resourceId, jsonOfChangesOnly, false);
this.writePlatformService.updateCode(changesOnly);
-
+
commandSourceResult.markAsChecked(maker, asToday);
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
// swallow this rollback transaction by design
@@ -90,36 +77,34 @@ public class CodeCommandHandler implements CommandSourceHandler {
return commandSourceResult;
}
- /*
- * Used when users with 'checker' capability approve a command.
- */
- public CommandSource handle(final CommandSource commandSourceResult) {
+ @Override
+ public CommandSource handleCommandForCheckerApproval(final CommandSource commandSourceResult) {
final AppUser checker = context.authenticatedUser();
-
+
Long resourceId = commandSourceResult.resourceId();
final CodeCommand command = this.commandDeserializerService.deserializeCodeCommand(resourceId, commandSourceResult.json(), true);
-
- if (commandSourceResult.isCreate()) {
- final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "CREATE_CODE_MAKER");
- context.authenticatedUser().validateHasPermissionTo("CREATE_USER_MAKER", allowedPermissions);
-
- resourceId = this.writePlatformService.createCode(command);
- commandSourceResult.updateResourceId(resourceId);
- commandSourceResult.markAsChecked(checker, new LocalDate());
- } else if (commandSourceResult.isUpdate()) {
- final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "UPDATE_CODE_MAKER");
- context.authenticatedUser().validateHasPermissionTo("UPDATE_USER_MAKER", allowedPermissions);
-
- this.writePlatformService.updateCode(command);
- commandSourceResult.markAsChecked(checker, new LocalDate());
- } else if (commandSourceResult.isDelete()) {
- final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "DELETE_CODE_MAKER");
- context.authenticatedUser().validateHasPermissionTo("DELETE_USER_MAKER", allowedPermissions);
-
- this.writePlatformService.deleteCode(command);
- commandSourceResult.markAsChecked(checker, new LocalDate());
- }
+
+ if (commandSourceResult.isCreate()) {
+ final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "CREATE_CODE_MAKER");
+ context.authenticatedUser().validateHasPermissionTo("CREATE_USER_MAKER", allowedPermissions);
+
+ resourceId = this.writePlatformService.createCode(command);
+ commandSourceResult.updateResourceId(resourceId);
+ commandSourceResult.markAsChecked(checker, new LocalDate());
+ } else if (commandSourceResult.isUpdate()) {
+ final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "UPDATE_CODE_MAKER");
+ context.authenticatedUser().validateHasPermissionTo("UPDATE_USER_MAKER", allowedPermissions);
+
+ this.writePlatformService.updateCode(command);
+ commandSourceResult.markAsChecked(checker, new LocalDate());
+ } else if (commandSourceResult.isDelete()) {
+ final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "DELETE_CODE_MAKER");
+ context.authenticatedUser().validateHasPermissionTo("DELETE_USER_MAKER", allowedPermissions);
+
+ this.writePlatformService.deleteCode(command);
+ commandSourceResult.markAsChecked(checker, new LocalDate());
+ }
return commandSourceResult;
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CommandSourceHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CommandSourceHandler.java
index b02cca555..3f529654f 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CommandSourceHandler.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CommandSourceHandler.java
@@ -1,5 +1,19 @@
package org.mifosplatform.commands.handler;
+import org.mifosplatform.commands.domain.CommandSource;
+
public interface CommandSourceHandler {
+ /*
+ * Used when users with 'create' capability create a command. If
+ * 'maker-checker' is not enabled for this specific command then the
+ * 'creator' is also marked 'as the checker' and command automatically is
+ * processed and changes state of system.
+ */
+ CommandSource handleCommandWithSupportForRollback(CommandSource commandSource);
+
+ /*
+ * Used when users with 'checker' capability approve a command.
+ */
+ CommandSource handleCommandForCheckerApproval(CommandSource commandSourceResult);
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CommandSourceHandlerDelegator.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CommandSourceHandlerDelegator.java
index f27e00f5d..95c6e85d3 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CommandSourceHandlerDelegator.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CommandSourceHandlerDelegator.java
@@ -52,32 +52,32 @@ public class CommandSourceHandlerDelegator {
this.chargeDefinitionCommandHandler = chargeDefinitionCommandHandler;
}
- public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) {
+ public CommandSource handleCommandWithSupportForRollback(final CommandSource commandSource) {
context.authenticatedUser();
CommandSource commandSourceResult = null;
if (commandSource.isClientResource()) {
- commandSourceResult = clientCommandHandler.handle(commandSource, apiRequestBodyInJson);
+ commandSourceResult = clientCommandHandler.handleCommandWithSupportForRollback(commandSource);
} else if (commandSource.isRoleResource()) {
- commandSourceResult = roleCommandHandler.handle(commandSource, apiRequestBodyInJson);
+ commandSourceResult = roleCommandHandler.handleCommandWithSupportForRollback(commandSource);
} else if (commandSource.isPermissionResource()) {
- commandSourceResult = permissionCommandHandler.handle(commandSource, apiRequestBodyInJson);
+ commandSourceResult = permissionCommandHandler.handleCommandWithSupportForRollback(commandSource);
} else if (commandSource.isUserResource()) {
- commandSourceResult = userCommandHandler.handle(commandSource, apiRequestBodyInJson);
+ commandSourceResult = userCommandHandler.handleCommandWithSupportForRollback(commandSource);
} else if (commandSource.isCodeResource()) {
- commandSourceResult = codeCommandHandler.handle(commandSource, apiRequestBodyInJson);
+ commandSourceResult = codeCommandHandler.handleCommandWithSupportForRollback(commandSource);
} else if (commandSource.isStaffResource()) {
- commandSourceResult = staffCommandHandler.handle(commandSource, apiRequestBodyInJson);
+ commandSourceResult = staffCommandHandler.handleCommandWithSupportForRollback(commandSource);
} else if (commandSource.isFundResource()) {
- commandSourceResult = fundCommandHandler.handle(commandSource, apiRequestBodyInJson);
+ commandSourceResult = fundCommandHandler.handleCommandWithSupportForRollback(commandSource);
} else if (commandSource.isOfficeResource()) {
- commandSourceResult = officeCommandHandler.handle(commandSource, apiRequestBodyInJson);
+ commandSourceResult = officeCommandHandler.handleCommandWithSupportForRollback(commandSource);
} else if (commandSource.isOfficeTransactionResource()) {
- commandSourceResult = officeTransactionCommandHandler.handle(commandSource, apiRequestBodyInJson);
+ commandSourceResult = officeTransactionCommandHandler.handleCommandWithSupportForRollback(commandSource);
} else if (commandSource.isCurrencyResource()) {
- commandSourceResult = currencyCommandHandler.handle(commandSource, apiRequestBodyInJson);
+ commandSourceResult = currencyCommandHandler.handleCommandWithSupportForRollback(commandSource);
} else if (commandSource.isChargeDefinitionResource()) {
- commandSourceResult = chargeDefinitionCommandHandler.handle(commandSource, apiRequestBodyInJson);
+ commandSourceResult = chargeDefinitionCommandHandler.handleCommandWithSupportForRollback(commandSource);
} else {
throw new UnsupportedCommandException(commandSource.commandName());
}
@@ -85,31 +85,31 @@ public class CommandSourceHandlerDelegator {
return commandSourceResult;
}
- public CommandSource handleExistingCommand(final CommandSource existingCommandSource) {
+ public CommandSource handleCommandForCheckerApproval(final CommandSource existingCommandSource) {
CommandSource commandSourceResult = null;
if (existingCommandSource.isClientResource()) {
- commandSourceResult = clientCommandHandler.handle(existingCommandSource);
+ commandSourceResult = clientCommandHandler.handleCommandForCheckerApproval(existingCommandSource);
} else if (existingCommandSource.isRoleResource()) {
- commandSourceResult = roleCommandHandler.handle(existingCommandSource);
+ commandSourceResult = roleCommandHandler.handleCommandForCheckerApproval(existingCommandSource);
} else if (existingCommandSource.isPermissionResource()) {
- commandSourceResult = permissionCommandHandler.handle(existingCommandSource);
+ commandSourceResult = permissionCommandHandler.handleCommandForCheckerApproval(existingCommandSource);
} else if (existingCommandSource.isUserResource()) {
- commandSourceResult = userCommandHandler.handle(existingCommandSource);
+ commandSourceResult = userCommandHandler.handleCommandForCheckerApproval(existingCommandSource);
} else if (existingCommandSource.isCodeResource()) {
- commandSourceResult = codeCommandHandler.handle(existingCommandSource);
+ commandSourceResult = codeCommandHandler.handleCommandForCheckerApproval(existingCommandSource);
} else if (existingCommandSource.isStaffResource()) {
- commandSourceResult = staffCommandHandler.handle(existingCommandSource);
+ commandSourceResult = staffCommandHandler.handleCommandForCheckerApproval(existingCommandSource);
} else if (existingCommandSource.isFundResource()) {
- commandSourceResult = fundCommandHandler.handle(existingCommandSource);
+ commandSourceResult = fundCommandHandler.handleCommandForCheckerApproval(existingCommandSource);
} else if (existingCommandSource.isOfficeResource()) {
- commandSourceResult = officeCommandHandler.handle(existingCommandSource);
+ commandSourceResult = officeCommandHandler.handleCommandForCheckerApproval(existingCommandSource);
} else if (existingCommandSource.isOfficeTransactionResource()) {
- commandSourceResult = officeTransactionCommandHandler.handle(existingCommandSource);
+ commandSourceResult = officeTransactionCommandHandler.handleCommandForCheckerApproval(existingCommandSource);
} else if (existingCommandSource.isCurrencyResource()) {
- commandSourceResult = currencyCommandHandler.handle(existingCommandSource);
+ commandSourceResult = currencyCommandHandler.handleCommandForCheckerApproval(existingCommandSource);
} else if (existingCommandSource.isChargeDefinitionResource()) {
- commandSourceResult = chargeDefinitionCommandHandler.handle(existingCommandSource);
+ commandSourceResult = chargeDefinitionCommandHandler.handleCommandForCheckerApproval(existingCommandSource);
} else {
throw new UnsupportedCommandException(existingCommandSource.commandName());
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CurrencyCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CurrencyCommandHandler.java
index 9de2e8440..7d9ec364a 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CurrencyCommandHandler.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/CurrencyCommandHandler.java
@@ -4,9 +4,7 @@ import java.util.Arrays;
import java.util.List;
import org.joda.time.LocalDate;
-import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService;
-import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosng.platform.infrastructure.errorhandling.UnsupportedCommandException;
import org.mifosplatform.commands.domain.CommandSource;
@@ -23,52 +21,36 @@ public class CurrencyCommandHandler implements CommandSourceHandler {
private final PlatformSecurityContext context;
private final ChangeDetectionService changeDetectionService;
- private final PortfolioApiDataConversionService apiDataConversionService;
- private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandDeserializerService commandDeserializerService;
private final CurrencyWritePlatformService writePlatformService;
@Autowired
- public CurrencyCommandHandler(final PlatformSecurityContext context,
- final ChangeDetectionService changeDetectionService,
- final PortfolioApiDataConversionService apiDataConversionService,
- final PortfolioCommandSerializerService commandSerializerService,
+ public CurrencyCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
final PortfolioCommandDeserializerService commandDeserializerService, final CurrencyWritePlatformService writePlatformService) {
this.context = context;
this.changeDetectionService = changeDetectionService;
- this.apiDataConversionService = apiDataConversionService;
- this.commandSerializerService = commandSerializerService;
this.commandDeserializerService = commandDeserializerService;
this.writePlatformService = writePlatformService;
}
- /*
- * Used when users with 'create' capability create a command. If
- * 'maker-checker' is not enabled for this specific command then the
- * 'creator' is also marked 'as the checker' and command automatically is
- * processed and changes state of system.
- */
- public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) {
+ @Override
+ public CommandSource handleCommandWithSupportForRollback(final CommandSource commandSource) {
final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate();
CommandSource commandSourceResult = commandSource.copy();
- final CurrencyCommand command = this.apiDataConversionService.convertApiRequestJsonToCurrencyCommand(apiRequestBodyInJson);
- final String commandSerializedAsJson = this.commandSerializerService.serializeCurrencyCommandToJson(command);
- commandSourceResult.updateJsonTo(commandSerializedAsJson);
-
if (commandSource.isCreate()) {
throw new UnsupportedCommandException(commandSource.commandName());
} else if (commandSource.isUpdate()) {
try {
final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(),
- commandSource.resourceId(), commandSerializedAsJson);
+ commandSource.resourceId(), commandSource.json());
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
-
+
final CurrencyCommand changesOnly = this.commandDeserializerService.deserializeCurrencyCommand(jsonOfChangesOnly, false);
-
+
this.writePlatformService.updateAllowedCurrencies(changesOnly);
commandSourceResult.markAsChecked(maker, asToday);
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
@@ -79,10 +61,8 @@ public class CurrencyCommandHandler implements CommandSourceHandler {
return commandSourceResult;
}
- /*
- * Used when users with 'checker' capability approve a command.
- */
- public CommandSource handle(final CommandSource commandSourceResult) {
+ @Override
+ public CommandSource handleCommandForCheckerApproval(final CommandSource commandSourceResult) {
final AppUser checker = context.authenticatedUser();
@@ -96,7 +76,7 @@ public class CurrencyCommandHandler implements CommandSourceHandler {
context.authenticatedUser().validateHasPermissionTo("UPDATE_CURRENCY_CHECKER", allowedPermissions);
this.writePlatformService.updateAllowedCurrencies(command);
-
+
commandSourceResult.markAsChecked(checker, new LocalDate());
} else if (commandSourceResult.isDelete()) { throw new UnsupportedCommandException(commandSourceResult.commandName()); }
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/FundCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/FundCommandHandler.java
index 082f0e7f5..889f4ccfd 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/FundCommandHandler.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/FundCommandHandler.java
@@ -4,9 +4,7 @@ import java.util.Arrays;
import java.util.List;
import org.joda.time.LocalDate;
-import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService;
-import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosng.platform.infrastructure.errorhandling.UnsupportedCommandException;
import org.mifosplatform.commands.domain.CommandSource;
@@ -23,42 +21,28 @@ public class FundCommandHandler implements CommandSourceHandler {
private final PlatformSecurityContext context;
private final ChangeDetectionService changeDetectionService;
- private final PortfolioApiDataConversionService apiDataConversionService;
- private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandDeserializerService commandDeserializerService;
private final FundWritePlatformService writePlatformService;
@Autowired
public FundCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
- final PortfolioApiDataConversionService apiDataConversionService,
- final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandDeserializerService commandDeserializerService, final FundWritePlatformService writePlatformService) {
this.context = context;
this.changeDetectionService = changeDetectionService;
- this.apiDataConversionService = apiDataConversionService;
- this.commandSerializerService = commandSerializerService;
this.commandDeserializerService = commandDeserializerService;
this.writePlatformService = writePlatformService;
}
- /*
- * Used when users with 'create' capability create a command. If
- * 'maker-checker' is not enabled for this specific command then the
- * 'creator' is also marked 'as the checker' and command automatically is
- * processed and changes state of system.
- */
- public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) {
+ @Override
+ public CommandSource handleCommandWithSupportForRollback(final CommandSource commandSource) {
final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate();
- CommandSource commandSourceResult = commandSource.copy();
-
final Long resourceId = commandSource.resourceId();
+ final FundCommand command = this.commandDeserializerService.deserializeFundCommand(resourceId, commandSource.json(), false);
- final FundCommand command = this.apiDataConversionService.convertApiRequestJsonToFundCommand(resourceId, apiRequestBodyInJson);
- final String commandSerializedAsJson = this.commandSerializerService.serializeFundCommandToJson(command);
- commandSourceResult.updateJsonTo(commandSerializedAsJson);
+ CommandSource commandSourceResult = commandSource.copy();
Long newResourceId = null;
@@ -73,10 +57,11 @@ public class FundCommandHandler implements CommandSourceHandler {
} else if (commandSource.isUpdate()) {
try {
final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(),
- commandSource.resourceId(), commandSerializedAsJson);
+ commandSource.resourceId(), commandSource.json());
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
- final FundCommand changesOnly = this.commandDeserializerService.deserializeFundCommand(resourceId, jsonOfChangesOnly,false);
+ final FundCommand changesOnly = this.commandDeserializerService
+ .deserializeFundCommand(resourceId, jsonOfChangesOnly, false);
this.writePlatformService.updateFund(changesOnly);
@@ -89,25 +74,25 @@ public class FundCommandHandler implements CommandSourceHandler {
return commandSourceResult;
}
- /*
- * Used when users with 'checker' capability approve a command.
- */
- public CommandSource handle(final CommandSource commandSourceResult) {
+ @Override
+ public CommandSource handleCommandForCheckerApproval(final CommandSource commandSourceResult) {
final AppUser checker = context.authenticatedUser();
Long resourceId = commandSourceResult.resourceId();
final FundCommand command = this.commandDeserializerService.deserializeFundCommand(resourceId, commandSourceResult.json(), true);
-
+
if (commandSourceResult.isCreate()) {
- final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "CREATE_FUND_CHECKER");
+ final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER",
+ "CREATE_FUND_CHECKER");
context.authenticatedUser().validateHasPermissionTo("CREATE_FUND_CHECKER", allowedPermissions);
resourceId = this.writePlatformService.createFund(command);
commandSourceResult.updateResourceId(resourceId);
commandSourceResult.markAsChecked(checker, new LocalDate());
} else if (commandSourceResult.isUpdate()) {
- final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "UPDATE_FUND_CHECKER");
+ final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER",
+ "UPDATE_FUND_CHECKER");
context.authenticatedUser().validateHasPermissionTo("UPDATE_FUND_CHECKER", allowedPermissions);
resourceId = this.writePlatformService.updateFund(command);
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/OfficeCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/OfficeCommandHandler.java
index 6fa4a22d5..ac421c19c 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/OfficeCommandHandler.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/OfficeCommandHandler.java
@@ -4,9 +4,7 @@ import java.util.Arrays;
import java.util.List;
import org.joda.time.LocalDate;
-import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService;
-import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosng.platform.infrastructure.errorhandling.UnsupportedCommandException;
import org.mifosplatform.commands.domain.CommandSource;
@@ -23,43 +21,28 @@ public class OfficeCommandHandler implements CommandSourceHandler {
private final PlatformSecurityContext context;
private final ChangeDetectionService changeDetectionService;
- private final PortfolioApiDataConversionService apiDataConversionService;
- private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandDeserializerService commandDeserializerService;
private final OfficeWritePlatformService writePlatformService;
@Autowired
public OfficeCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
- final PortfolioApiDataConversionService apiDataConversionService,
- final PortfolioCommandSerializerService commandSerializerService,
- final PortfolioCommandDeserializerService commandDeserializerService,
- final OfficeWritePlatformService writePlatformService) {
+ final PortfolioCommandDeserializerService commandDeserializerService, final OfficeWritePlatformService writePlatformService) {
this.context = context;
this.changeDetectionService = changeDetectionService;
- this.apiDataConversionService = apiDataConversionService;
- this.commandSerializerService = commandSerializerService;
this.commandDeserializerService = commandDeserializerService;
this.writePlatformService = writePlatformService;
}
- /*
- * Used when users with 'create' capability create a command. If
- * 'maker-checker' is not enabled for this specific command then the
- * 'creator' is also marked 'as the checker' and command automatically is
- * processed and changes state of system.
- */
- public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) {
+ @Override
+ public CommandSource handleCommandWithSupportForRollback(final CommandSource commandSource) {
final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate();
- CommandSource commandSourceResult = commandSource.copy();
-
final Long resourceId = commandSource.resourceId();
+ final OfficeCommand command = this.commandDeserializerService.deserializeOfficeCommand(resourceId, commandSource.json(), false);
- final OfficeCommand command = this.apiDataConversionService.convertApiRequestJsonToOfficeCommand(resourceId, apiRequestBodyInJson);
- final String commandSerializedAsJson = this.commandSerializerService.serializeOfficeCommandToJson(command);
- commandSourceResult.updateJsonTo(commandSerializedAsJson);
+ CommandSource commandSourceResult = commandSource.copy();
Long newResourceId = null;
@@ -74,10 +57,11 @@ public class OfficeCommandHandler implements CommandSourceHandler {
} else if (commandSource.isUpdate()) {
try {
final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(),
- commandSource.resourceId(), commandSerializedAsJson);
+ commandSource.resourceId(), commandSource.json());
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
- final OfficeCommand changesOnly = this.commandDeserializerService.deserializeOfficeCommand(resourceId, jsonOfChangesOnly, false);
+ final OfficeCommand changesOnly = this.commandDeserializerService.deserializeOfficeCommand(resourceId, jsonOfChangesOnly,
+ false);
this.writePlatformService.updateOffice(changesOnly);
@@ -90,25 +74,26 @@ public class OfficeCommandHandler implements CommandSourceHandler {
return commandSourceResult;
}
- /*
- * Used when users with 'checker' capability approve a command.
- */
- public CommandSource handle(final CommandSource commandSourceResult) {
+ @Override
+ public CommandSource handleCommandForCheckerApproval(final CommandSource commandSourceResult) {
final AppUser checker = context.authenticatedUser();
Long resourceId = commandSourceResult.resourceId();
- final OfficeCommand command = this.commandDeserializerService.deserializeOfficeCommand(resourceId, commandSourceResult.json(), true);
-
+ final OfficeCommand command = this.commandDeserializerService
+ .deserializeOfficeCommand(resourceId, commandSourceResult.json(), true);
+
if (commandSourceResult.isCreate()) {
- final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "CREATE_OFFICE_CHECKER");
+ final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER",
+ "CREATE_OFFICE_CHECKER");
context.authenticatedUser().validateHasPermissionTo("CREATE_OFFICE_CHECKER", allowedPermissions);
resourceId = this.writePlatformService.createOffice(command);
commandSourceResult.updateResourceId(resourceId);
commandSourceResult.markAsChecked(checker, new LocalDate());
} else if (commandSourceResult.isUpdate()) {
- final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "UPDATE_OFFICE_CHECKER");
+ final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER",
+ "UPDATE_OFFICE_CHECKER");
context.authenticatedUser().validateHasPermissionTo("UPDATE_OFFICE_CHECKER", allowedPermissions);
resourceId = this.writePlatformService.updateOffice(command);
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/OfficeTransactionCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/OfficeTransactionCommandHandler.java
index 1116aae19..72337cabe 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/OfficeTransactionCommandHandler.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/OfficeTransactionCommandHandler.java
@@ -4,9 +4,7 @@ import java.util.Arrays;
import java.util.List;
import org.joda.time.LocalDate;
-import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService;
-import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosng.platform.infrastructure.errorhandling.UnsupportedCommandException;
import org.mifosplatform.commands.domain.CommandSource;
@@ -21,40 +19,27 @@ import org.springframework.stereotype.Service;
public class OfficeTransactionCommandHandler implements CommandSourceHandler {
private final PlatformSecurityContext context;
- private final PortfolioApiDataConversionService apiDataConversionService;
- private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandDeserializerService commandDeserializerService;
private final OfficeWritePlatformService writePlatformService;
@Autowired
public OfficeTransactionCommandHandler(final PlatformSecurityContext context,
- final PortfolioApiDataConversionService apiDataConversionService,
- final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandDeserializerService commandDeserializerService, final OfficeWritePlatformService writePlatformService) {
this.context = context;
- this.apiDataConversionService = apiDataConversionService;
- this.commandSerializerService = commandSerializerService;
this.commandDeserializerService = commandDeserializerService;
this.writePlatformService = writePlatformService;
}
- /*
- * Used when users with 'create' capability create a command. If
- * 'maker-checker' is not enabled for this specific command then the
- * 'creator' is also marked 'as the checker' and command automatically is
- * processed and changes state of system.
- */
- public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) {
+ @Override
+ public CommandSource handleCommandWithSupportForRollback(final CommandSource commandSource) {
final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate();
- CommandSource commandSourceResult = commandSource.copy();
+ final BranchMoneyTransferCommand command = this.commandDeserializerService.deserializeOfficeTransactionCommand(
+ commandSource.json(), false);
- final BranchMoneyTransferCommand command = this.apiDataConversionService
- .convertApiRequestJsonToBranchMoneyTransferCommand(apiRequestBodyInJson);
- final String commandSerializedAsJson = this.commandSerializerService.serializeOfficeTransactionCommandToJson(command);
- commandSourceResult.updateJsonTo(commandSerializedAsJson);
+ CommandSource commandSourceResult = commandSource.copy();
Long newResourceId = null;
@@ -73,10 +58,8 @@ public class OfficeTransactionCommandHandler implements CommandSourceHandler {
return commandSourceResult;
}
- /*
- * Used when users with 'checker' capability approve a command.
- */
- public CommandSource handle(final CommandSource commandSourceResult) {
+ @Override
+ public CommandSource handleCommandForCheckerApproval(final CommandSource commandSourceResult) {
final AppUser checker = context.authenticatedUser();
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/PermissionsCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/PermissionsCommandHandler.java
index 38d1eb4da..a2c0f887e 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/PermissionsCommandHandler.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/PermissionsCommandHandler.java
@@ -4,9 +4,7 @@ import java.util.Arrays;
import java.util.List;
import org.joda.time.LocalDate;
-import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService;
-import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosng.platform.infrastructure.errorhandling.UnsupportedCommandException;
import org.mifosplatform.commands.domain.CommandSource;
@@ -23,32 +21,21 @@ public class PermissionsCommandHandler implements CommandSourceHandler {
private final PlatformSecurityContext context;
private final ChangeDetectionService changeDetectionService;
- private final PortfolioApiDataConversionService apiDataConversionService;
- private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandDeserializerService commandDeserializerService;
private final PermissionWritePlatformService permissionWritePlatformService;
@Autowired
public PermissionsCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
- final PortfolioApiDataConversionService apiDataConversionService,
- final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandDeserializerService commandDeserializerService,
final PermissionWritePlatformService permissionWritePlatformService) {
this.context = context;
this.changeDetectionService = changeDetectionService;
- this.apiDataConversionService = apiDataConversionService;
- this.commandSerializerService = commandSerializerService;
this.commandDeserializerService = commandDeserializerService;
this.permissionWritePlatformService = permissionWritePlatformService;
}
- /*
- * Used when users with 'create' capability create a command. If
- * 'maker-checker' is not enabled for this specific command then the
- * 'creator' is also marked 'as the checker' and command automatically is
- * processed and changes state of system.
- */
- public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) {
+ @Override
+ public CommandSource handleCommandWithSupportForRollback(final CommandSource commandSource) {
final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate();
@@ -57,14 +44,12 @@ public class PermissionsCommandHandler implements CommandSourceHandler {
if (commandSource.isUpdate()) {
try {
- final PermissionsCommand command = this.apiDataConversionService.convertApiRequestJsonToPermissionsCommand(apiRequestBodyInJson);
- final String commandSerializedAsJson = this.commandSerializerService.serializePermissionsCommandToJson(command);
- commandSourceResult.updateJsonTo(commandSerializedAsJson);
-
- final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(), commandSource.resourceId(), commandSerializedAsJson);
+ final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(),
+ commandSource.resourceId(), commandSource.json());
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
- final PermissionsCommand changesOnly = this.commandDeserializerService.deserializePermissionsCommand(jsonOfChangesOnly, false);
+ final PermissionsCommand changesOnly = this.commandDeserializerService.deserializePermissionsCommand(jsonOfChangesOnly,
+ false);
this.permissionWritePlatformService.updateMakerCheckerPermissions(changesOnly);
@@ -79,21 +64,20 @@ public class PermissionsCommandHandler implements CommandSourceHandler {
return commandSourceResult;
}
- /*
- * Used when users with 'checker' capability approve a command.
- */
- public CommandSource handle(final CommandSource commandSourceResult) {
+ @Override
+ public CommandSource handleCommandForCheckerApproval(final CommandSource commandSourceResult) {
final AppUser checker = context.authenticatedUser();
if (commandSourceResult.isUpdate()) {
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "PERMISSIONS_ROLE");
context.authenticatedUser().validateHasPermissionTo("PERMISSIONS_ROLE", allowedPermissions);
-
- final PermissionsCommand command = this.commandDeserializerService.deserializePermissionsCommand(commandSourceResult.json(), true);
+
+ final PermissionsCommand command = this.commandDeserializerService.deserializePermissionsCommand(commandSourceResult.json(),
+ true);
this.permissionWritePlatformService.updateMakerCheckerPermissions(command);
commandSourceResult.markAsChecked(checker, new LocalDate());
- } else {
+ } else {
throw new UnsupportedCommandException(commandSourceResult.commandName());
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/RoleCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/RoleCommandHandler.java
index c8db22b1a..39827ea4d 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/RoleCommandHandler.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/RoleCommandHandler.java
@@ -34,13 +34,8 @@ public class RoleCommandHandler implements CommandSourceHandler {
this.writePlatformService = writePlatformService;
}
- /*
- * Used when users with 'create' capability create a command. If
- * 'maker-checker' is not enabled for this specific command then the
- * 'creator' is also marked 'as the checker' and command automatically is
- * processed and changes state of system.
- */
- public CommandSource handle(final CommandSource commandSource, final String commandSerializedAsJson) {
+ @Override
+ public CommandSource handleCommandWithSupportForRollback(final CommandSource commandSource) {
final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate();
@@ -96,10 +91,8 @@ public class RoleCommandHandler implements CommandSourceHandler {
return commandSourceResult;
}
- /*
- * Used when users with 'checker' capability approve a command.
- */
- public CommandSource handle(final CommandSource commandSourceResult) {
+ @Override
+ public CommandSource handleCommandForCheckerApproval(final CommandSource commandSourceResult) {
final AppUser checker = context.authenticatedUser();
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/StaffCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/StaffCommandHandler.java
index 66f56d583..c9be9561f 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/StaffCommandHandler.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/StaffCommandHandler.java
@@ -4,9 +4,7 @@ import java.util.Arrays;
import java.util.List;
import org.joda.time.LocalDate;
-import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService;
-import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosng.platform.infrastructure.errorhandling.UnsupportedCommandException;
import org.mifosplatform.commands.domain.CommandSource;
@@ -23,45 +21,29 @@ public class StaffCommandHandler implements CommandSourceHandler {
private final PlatformSecurityContext context;
private final ChangeDetectionService changeDetectionService;
- private final PortfolioApiDataConversionService apiDataConversionService;
- private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandDeserializerService commandDeserializerService;
private final StaffWritePlatformService writePlatformService;
@Autowired
public StaffCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
- final PortfolioApiDataConversionService apiDataConversionService,
- final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandDeserializerService commandDeserializerService, final StaffWritePlatformService writePlatformService) {
this.context = context;
this.changeDetectionService = changeDetectionService;
- this.apiDataConversionService = apiDataConversionService;
- this.commandSerializerService = commandSerializerService;
this.commandDeserializerService = commandDeserializerService;
this.writePlatformService = writePlatformService;
}
- /*
- * Used when users with 'create' capability create a command. If
- * 'maker-checker' is not enabled for this specific command then the
- * 'creator' is also marked 'as the checker' and command automatically is
- * processed and changes state of system.
- */
- public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) {
+ @Override
+ public CommandSource handleCommandWithSupportForRollback(final CommandSource commandSource) {
final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate();
+ final Long resourceId = commandSource.resourceId();
+ final StaffCommand command = this.commandDeserializerService.deserializeStaffCommand(resourceId, commandSource.json(), false);
CommandSource commandSourceResult = commandSource.copy();
- final Long resourceId = commandSource.resourceId();
-
- final StaffCommand command = this.apiDataConversionService.convertApiRequestJsonToStaffCommand(resourceId, apiRequestBodyInJson);
- final String commandSerializedAsJson = this.commandSerializerService.serializeStaffCommandToJson(command);
- commandSourceResult.updateJsonTo(commandSerializedAsJson);
-
Long newResourceId = null;
-
if (commandSource.isCreate()) {
try {
newResourceId = this.writePlatformService.createStaff(command);
@@ -73,10 +55,11 @@ public class StaffCommandHandler implements CommandSourceHandler {
} else if (commandSource.isUpdate()) {
try {
final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(),
- commandSource.resourceId(), commandSerializedAsJson);
+ commandSource.resourceId(), commandSource.json());
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
- final StaffCommand changesOnly = this.commandDeserializerService.deserializeStaffCommand(resourceId, jsonOfChangesOnly,false);
+ final StaffCommand changesOnly = this.commandDeserializerService.deserializeStaffCommand(resourceId, jsonOfChangesOnly,
+ false);
this.writePlatformService.updateStaff(changesOnly);
@@ -89,25 +72,25 @@ public class StaffCommandHandler implements CommandSourceHandler {
return commandSourceResult;
}
- /*
- * Used when users with 'checker' capability approve a command.
- */
- public CommandSource handle(final CommandSource commandSourceResult) {
+ @Override
+ public CommandSource handleCommandForCheckerApproval(final CommandSource commandSourceResult) {
final AppUser checker = context.authenticatedUser();
Long resourceId = commandSourceResult.resourceId();
final StaffCommand command = this.commandDeserializerService.deserializeStaffCommand(resourceId, commandSourceResult.json(), true);
-
+
if (commandSourceResult.isCreate()) {
- final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "CREATE_STAFF_CHECKER");
+ final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER",
+ "CREATE_STAFF_CHECKER");
context.authenticatedUser().validateHasPermissionTo("CREATE_STAFF_CHECKER", allowedPermissions);
resourceId = this.writePlatformService.createStaff(command);
commandSourceResult.updateResourceId(resourceId);
commandSourceResult.markAsChecked(checker, new LocalDate());
} else if (commandSourceResult.isUpdate()) {
- final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "UPDATE_STAFF_CHECKER");
+ final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER",
+ "UPDATE_STAFF_CHECKER");
context.authenticatedUser().validateHasPermissionTo("UPDATE_STAFF_CHECKER", allowedPermissions);
resourceId = this.writePlatformService.updateStaff(command);
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/UserCommandHandler.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/UserCommandHandler.java
index 205fb234c..4bf9d891c 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/UserCommandHandler.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/handler/UserCommandHandler.java
@@ -4,9 +4,7 @@ import java.util.Arrays;
import java.util.List;
import org.joda.time.LocalDate;
-import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioCommandDeserializerService;
-import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
import org.mifosplatform.commands.domain.CommandSource;
import org.mifosplatform.commands.service.ChangeDetectionService;
@@ -22,45 +20,32 @@ public class UserCommandHandler implements CommandSourceHandler {
private final PlatformSecurityContext context;
private final ChangeDetectionService changeDetectionService;
- private final PortfolioApiDataConversionService apiDataConversionService;
- private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandDeserializerService commandDeserializerService;
private final AppUserWritePlatformService writePlatformService;
-
+
@Autowired
public UserCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
- final PortfolioApiDataConversionService apiDataConversionService,
- final PortfolioCommandSerializerService commandSerializerService,
- final PortfolioCommandDeserializerService commandDeserializerService,
- final AppUserWritePlatformService writePlatformService) {
+ final PortfolioCommandDeserializerService commandDeserializerService, final AppUserWritePlatformService writePlatformService) {
this.context = context;
this.changeDetectionService = changeDetectionService;
- this.apiDataConversionService = apiDataConversionService;
- this.commandSerializerService = commandSerializerService;
this.commandDeserializerService = commandDeserializerService;
this.writePlatformService = writePlatformService;
}
- /*
- * Used when users with 'create' capability create a command. If 'maker-checker' is not
- * enabled for this specific command then the 'creator' is also marked 'as the checker' and command
- * automatically is processed and changes state of system.
- */
- public CommandSource handle(final CommandSource commandSource, final String apiRequestBodyInJson) {
+ @Override
+ public CommandSource handleCommandWithSupportForRollback(final CommandSource commandSource) {
final AppUser maker = context.authenticatedUser();
final LocalDate asToday = new LocalDate();
- CommandSource commandSourceResult = commandSource.copy();
-
final Long resourceId = commandSource.resourceId();
+ final UserCommand command = this.commandDeserializerService.deserializeUserCommand(resourceId, commandSource.json(), false);
+
+ CommandSource commandSourceResult = commandSource.copy();
if (commandSource.isCreate()) {
try {
- final UserCommand command = this.apiDataConversionService.convertApiRequestJsonToUserCommand(null, apiRequestBodyInJson);
- final String commandSerializedAsJson = this.commandSerializerService.serializeUserCommandToJson(command);
- commandSourceResult.updateJsonTo(commandSerializedAsJson);
-
Long newResourceId = this.writePlatformService.createUser(command);
+
commandSourceResult.markAsChecked(maker, asToday);
commandSourceResult.updateResourceId(newResourceId);
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
@@ -68,31 +53,25 @@ public class UserCommandHandler implements CommandSourceHandler {
}
} else if (commandSource.isUpdate()) {
try {
- final UserCommand command = this.apiDataConversionService.convertApiRequestJsonToUserCommand(resourceId, apiRequestBodyInJson);
- final String commandSerializedAsJson = this.commandSerializerService.serializeUserCommandToJson(command);
- commandSourceResult.updateJsonTo(commandSerializedAsJson);
-
- final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(), commandSource.resourceId(), commandSerializedAsJson);
+ final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(),
+ commandSource.resourceId(), commandSource.json());
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
- final UserCommand changesOnly = this.commandDeserializerService.deserializeUserCommand(resourceId, jsonOfChangesOnly, false);
+ final UserCommand changesOnly = this.commandDeserializerService
+ .deserializeUserCommand(resourceId, jsonOfChangesOnly, false);
if (maker.hasIdOf(command.getId())) {
this.writePlatformService.updateUsersOwnAccountDetails(changesOnly);
} else {
this.writePlatformService.updateUser(changesOnly);
}
-
+
commandSourceResult.markAsChecked(maker, asToday);
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
// swallow this rollback transaction by design
}
} else if (commandSource.isDelete()) {
try {
- final UserCommand command = this.apiDataConversionService.convertApiRequestJsonToUserCommand(resourceId, apiRequestBodyInJson);
- final String commandSerializedAsJson = this.commandSerializerService.serializeUserCommandToJson(command);
- commandSourceResult.updateJsonTo(commandSerializedAsJson);
-
this.writePlatformService.deleteUser(command);
commandSourceResult.markAsChecked(maker, asToday);
} catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
@@ -103,40 +82,39 @@ public class UserCommandHandler implements CommandSourceHandler {
return commandSourceResult;
}
- /*
- * Used when users with 'checker' capability approve a command.
- */
- public CommandSource handle(final CommandSource commandSourceResult) {
+ @Override
+ public CommandSource handleCommandForCheckerApproval(final CommandSource commandSourceResult) {
final AppUser checker = context.authenticatedUser();
-
+
Long resourceId = commandSourceResult.resourceId();
+ final UserCommand command = this.commandDeserializerService.deserializeUserCommand(resourceId, commandSourceResult.json(), true);
if (commandSourceResult.isUserResource()) {
if (commandSourceResult.isCreate()) {
- final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "CREATE_USER_MAKER");
+ final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER",
+ "CREATE_USER_MAKER");
context.authenticatedUser().validateHasPermissionTo("CREATE_USER_MAKER", allowedPermissions);
-
- final UserCommand command = this.commandDeserializerService.deserializeUserCommand(resourceId, commandSourceResult.json(), true);
+
resourceId = this.writePlatformService.createUser(command);
commandSourceResult.updateResourceId(resourceId);
commandSourceResult.markAsChecked(checker, new LocalDate());
} else if (commandSourceResult.isUpdate()) {
- final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "UPDATE_USER_MAKER");
+ final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER",
+ "UPDATE_USER_MAKER");
context.authenticatedUser().validateHasPermissionTo("UPDATE_USER_MAKER", allowedPermissions);
-
- final UserCommand command = this.commandDeserializerService.deserializeUserCommand(resourceId, commandSourceResult.json(), true);
+
if (checker.hasIdOf(command.getId())) {
this.writePlatformService.updateUsersOwnAccountDetails(command);
} else {
this.writePlatformService.updateUser(command);
}
-
+
commandSourceResult.markAsChecked(checker, new LocalDate());
} else if (commandSourceResult.isDelete()) {
- final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "DELETE_USER_MAKER");
+ final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER",
+ "DELETE_USER_MAKER");
context.authenticatedUser().validateHasPermissionTo("DELETE_USER_MAKER", allowedPermissions);
-
- final UserCommand command = this.commandDeserializerService.deserializeUserCommand(resourceId, commandSourceResult.json(), true);
+
this.writePlatformService.deleteUser(command);
commandSourceResult.markAsChecked(checker, new LocalDate());
}
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 6e9f4ffc9..13a3cc72a 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
@@ -35,7 +35,7 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
final LocalDate asToday = new LocalDate();
final CommandSource commandSourceInput = CommandSource.createdBy(apiOperation, resource, resourceId, commandSerializedAsJson, maker, asToday);
- final CommandSource commandSourceResult = this.commandSourceHandlerDelegator.handle(commandSourceInput, commandSerializedAsJson);
+ final CommandSource commandSourceResult = this.commandSourceHandlerDelegator.handleCommandWithSupportForRollback(commandSourceInput);
commandSourceRepository.save(commandSourceResult);
return EntityIdentifier.makerChecker(commandSourceResult.resourceId(), commandSourceResult.getId());
@@ -48,7 +48,7 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
context.authenticatedUser();
final CommandSource commandSourceInput = this.commandSourceRepository.findOne(id);
- final CommandSource commandSourceResult = this.commandSourceHandlerDelegator.handleExistingCommand(commandSourceInput);
+ final CommandSource commandSourceResult = this.commandSourceHandlerDelegator.handleCommandForCheckerApproval(commandSourceInput);
commandSourceRepository.save(commandSourceResult);
return EntityIdentifier.makerChecker(commandSourceResult.resourceId(), commandSourceResult.getId());
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 bb528fc43..aa580b3cd 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
@@ -18,9 +18,12 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.data.EntityIdentifier;
+import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
+import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.mifosplatform.infrastructure.codes.command.CodeCommand;
import org.mifosplatform.infrastructure.codes.data.CodeData;
import org.mifosplatform.infrastructure.codes.service.CodeReadPlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
@@ -33,20 +36,26 @@ import org.springframework.stereotype.Component;
@Scope("singleton")
public class CodesApiResource {
- private CodeReadPlatformService readPlatformService;
- private PortfolioApiJsonSerializerService apiJsonSerializerService;
- private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
- private final PlatformSecurityContext context;
-
private final String resourceNameForPermissions = "CODE";
+ private final PlatformSecurityContext context;
+ private final CodeReadPlatformService readPlatformService;
+ private final PortfolioApiJsonSerializerService apiJsonSerializerService;
+ private final PortfolioApiDataConversionService apiDataConversionService;
+ private final PortfolioCommandSerializerService commandSerializerService;
+ private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
+
@Autowired
public CodesApiResource(final PlatformSecurityContext context, final CodeReadPlatformService readPlatformService,
final PortfolioApiJsonSerializerService apiJsonSerializerService,
+ final PortfolioApiDataConversionService apiDataConversionService,
+ final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context;
this.readPlatformService = readPlatformService;
this.apiJsonSerializerService = apiJsonSerializerService;
+ this.apiDataConversionService = apiDataConversionService;
+ this.commandSerializerService = commandSerializerService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@@ -73,8 +82,11 @@ public class CodesApiResource {
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "CREATE_CODE");
context.authenticatedUser().validateHasPermissionTo("CREATE_CODE", allowedPermissions);
+ final CodeCommand command = this.apiDataConversionService.convertApiRequestJsonToCodeCommand(null, apiRequestBodyAsJson);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
+
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "codes", null,
- apiRequestBodyAsJson);
+ commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}
@@ -102,8 +114,11 @@ public class CodesApiResource {
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "UPDATE_CODE");
context.authenticatedUser().validateHasPermissionTo("UPDATE_CODE", allowedPermissions);
+ final CodeCommand command = this.apiDataConversionService.convertApiRequestJsonToCodeCommand(codeId, apiRequestBodyAsJson);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
+
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "codes", codeId,
- apiRequestBodyAsJson);
+ commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/api/CurrenciesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/api/CurrenciesApiResource.java
index aa704574c..c97f574d7 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/api/CurrenciesApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/configuration/api/CurrenciesApiResource.java
@@ -14,9 +14,12 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.data.EntityIdentifier;
+import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
+import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.mifosplatform.infrastructure.configuration.command.CurrencyCommand;
import org.mifosplatform.infrastructure.configuration.data.ConfigurationData;
import org.mifosplatform.infrastructure.configuration.service.OrganisationCurrencyReadPlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
@@ -34,16 +37,22 @@ public class CurrenciesApiResource {
private final PlatformSecurityContext context;
private final OrganisationCurrencyReadPlatformService readPlatformService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
+ private final PortfolioApiDataConversionService apiDataConversionService;
+ private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public CurrenciesApiResource(final PlatformSecurityContext context,
final OrganisationCurrencyReadPlatformService readPlatformService,
final PortfolioApiJsonSerializerService apiJsonSerializerService,
+ final PortfolioApiDataConversionService apiDataConversionService,
+ final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context;
this.readPlatformService = readPlatformService;
this.apiJsonSerializerService = apiJsonSerializerService;
+ this.apiDataConversionService = apiDataConversionService;
+ this.commandSerializerService = commandSerializerService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@@ -70,8 +79,11 @@ public class CurrenciesApiResource {
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "UPDATE_CURRENCY");
context.authenticatedUser().validateHasPermissionTo("UPDATE_CURRENCY", allowedPermissions);
+ final CurrencyCommand command = this.apiDataConversionService.convertApiRequestJsonToCurrencyCommand(apiRequestBodyAsJson);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
+
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "currencies", null,
- apiRequestBodyAsJson);
+ commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/office/api/OfficeTransactionsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/office/api/OfficeTransactionsApiResource.java
index bd30780c5..798d5946f 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/office/api/OfficeTransactionsApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/office/api/OfficeTransactionsApiResource.java
@@ -15,9 +15,12 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.data.EntityIdentifier;
+import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
+import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.mifosplatform.infrastructure.office.command.BranchMoneyTransferCommand;
import org.mifosplatform.infrastructure.office.data.OfficeTransactionData;
import org.mifosplatform.infrastructure.office.service.OfficeReadPlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
@@ -36,16 +39,22 @@ public class OfficeTransactionsApiResource {
private final PlatformSecurityContext context;
private final OfficeReadPlatformService readPlatformService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
+ private final PortfolioApiDataConversionService apiDataConversionService;
+ private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public OfficeTransactionsApiResource(final PlatformSecurityContext context,
final OfficeReadPlatformService readPlatformService,
final PortfolioApiJsonSerializerService apiJsonSerializerService,
+ final PortfolioApiDataConversionService apiDataConversionService,
+ final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context;
this.readPlatformService = readPlatformService;
this.apiJsonSerializerService = apiJsonSerializerService;
+ this.apiDataConversionService = apiDataConversionService;
+ this.commandSerializerService = commandSerializerService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@@ -92,8 +101,11 @@ public class OfficeTransactionsApiResource {
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "CREATE_OFFICETRANSACTION");
context.authenticatedUser().validateHasPermissionTo("CREATE_OFFICETRANSACTION", allowedPermissions);
+ final BranchMoneyTransferCommand command = this.apiDataConversionService.convertApiRequestJsonToBranchMoneyTransferCommand(apiRequestBodyAsJson);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
+
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "officetransactions", null,
- apiRequestBodyAsJson);
+ commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/office/api/OfficesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/office/api/OfficesApiResource.java
index 45b22f6e5..540831ba3 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/office/api/OfficesApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/office/api/OfficesApiResource.java
@@ -18,9 +18,12 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.data.EntityIdentifier;
+import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
+import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.mifosplatform.infrastructure.office.command.OfficeCommand;
import org.mifosplatform.infrastructure.office.data.OfficeData;
import org.mifosplatform.infrastructure.office.data.OfficeLookup;
import org.mifosplatform.infrastructure.office.service.OfficeReadPlatformService;
@@ -39,16 +42,22 @@ public class OfficesApiResource {
private final PlatformSecurityContext context;
private final OfficeReadPlatformService readPlatformService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
+ private final PortfolioApiDataConversionService apiDataConversionService;
+ private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@Autowired
public OfficesApiResource(final PlatformSecurityContext context,
final OfficeReadPlatformService readPlatformService,
final PortfolioApiJsonSerializerService apiJsonSerializerService,
+ final PortfolioApiDataConversionService apiDataConversionService,
+ final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context;
this.readPlatformService = readPlatformService;
this.apiJsonSerializerService = apiJsonSerializerService;
+ this.apiDataConversionService = apiDataConversionService;
+ this.commandSerializerService = commandSerializerService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@@ -94,8 +103,11 @@ public class OfficesApiResource {
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "CREATE_OFFICE");
context.authenticatedUser().validateHasPermissionTo("CREATE_OFFICE", allowedPermissions);
+ final OfficeCommand command = this.apiDataConversionService.convertApiRequestJsonToOfficeCommand(null, apiRequestBodyAsJson);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
+
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "offices", null,
- apiRequestBodyAsJson);
+ commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}
@@ -130,8 +142,11 @@ public class OfficesApiResource {
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "UPDATE_OFFICE");
context.authenticatedUser().validateHasPermissionTo("UPDATE_OFFICE", allowedPermissions);
+ final OfficeCommand command = this.apiDataConversionService.convertApiRequestJsonToOfficeCommand(officeId, apiRequestBodyAsJson);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
+
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "offices", officeId,
- apiRequestBodyAsJson);
+ commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/staff/api/StaffApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/staff/api/StaffApiResource.java
index ffb2ac3a3..9984737f8 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/staff/api/StaffApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/staff/api/StaffApiResource.java
@@ -19,12 +19,15 @@ import javax.ws.rs.core.UriInfo;
import org.apache.commons.lang.StringUtils;
import org.mifosng.platform.api.data.EntityIdentifier;
+import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
+import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
import org.mifosplatform.infrastructure.office.data.OfficeLookup;
import org.mifosplatform.infrastructure.office.service.OfficeReadPlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
+import org.mifosplatform.infrastructure.staff.command.StaffCommand;
import org.mifosplatform.infrastructure.staff.data.StaffData;
import org.mifosplatform.infrastructure.staff.service.StaffReadPlatformService;
import org.slf4j.Logger;
@@ -40,22 +43,30 @@ public class StaffApiResource {
private final static Logger logger = LoggerFactory.getLogger(StaffApiResource.class);
+ private final String resourceNameForPermissions = "STAFF";
+
private final PlatformSecurityContext context;
private final StaffReadPlatformService readPlatformService;
private final OfficeReadPlatformService officeReadPlatformService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
- private final String resourceNameForPermissions = "STAFF";
+ private final PortfolioApiDataConversionService apiDataConversionService;
+
+ private final PortfolioCommandSerializerService commandSerializerService;
@Autowired
public StaffApiResource(final PlatformSecurityContext context, final StaffReadPlatformService readPlatformService,
final OfficeReadPlatformService officeReadPlatformService, final PortfolioApiJsonSerializerService apiJsonSerializerService,
+ final PortfolioApiDataConversionService apiDataConversionService,
+ final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context;
this.readPlatformService = readPlatformService;
this.officeReadPlatformService = officeReadPlatformService;
this.apiJsonSerializerService = apiJsonSerializerService;
+ this.apiDataConversionService = apiDataConversionService;
+ this.commandSerializerService = commandSerializerService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@@ -84,8 +95,11 @@ public class StaffApiResource {
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "CREATE_STAFF");
context.authenticatedUser().validateHasPermissionTo("CREATE_STAFF", allowedPermissions);
+ final StaffCommand command = this.apiDataConversionService.convertApiRequestJsonToStaffCommand(null, apiRequestBodyAsJson);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
+
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "staff", null,
- apiRequestBodyAsJson);
+ commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}
@@ -120,8 +134,11 @@ public class StaffApiResource {
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "UPDATE_STAFF");
context.authenticatedUser().validateHasPermissionTo("UPDATE_STAFF", allowedPermissions);
+ final StaffCommand command = this.apiDataConversionService.convertApiRequestJsonToStaffCommand(staffId, apiRequestBodyAsJson);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
+
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "staff", staffId,
- apiRequestBodyAsJson);
+ commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/user/api/PermissionsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/user/api/PermissionsApiResource.java
index 47a525065..19a151e9f 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/user/api/PermissionsApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/user/api/PermissionsApiResource.java
@@ -15,11 +15,14 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.data.EntityIdentifier;
+import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
+import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.infrastructure.user.api.data.PermissionUsageData;
+import org.mifosplatform.infrastructure.user.command.PermissionsCommand;
import org.mifosplatform.infrastructure.user.service.PermissionReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@@ -30,22 +33,28 @@ import org.springframework.stereotype.Component;
@Scope("singleton")
public class PermissionsApiResource {
+ private final String resourceNameForPermissions = "PERMISSION";
+
private final PlatformSecurityContext context;
private final PermissionReadPlatformService permissionReadPlatformService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
+ private final PortfolioApiDataConversionService apiDataConversionService;
+ private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
- private final String resourceNameForPermissions = "PERMISSION";
-
@Autowired
public PermissionsApiResource(
final PlatformSecurityContext context,
final PermissionReadPlatformService readPlatformService,
final PortfolioApiJsonSerializerService apiJsonSerializerService,
+ final PortfolioApiDataConversionService apiDataConversionService,
+ final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context;
this.permissionReadPlatformService = readPlatformService;
this.apiJsonSerializerService = apiJsonSerializerService;
+ this.apiDataConversionService = apiDataConversionService;
+ this.commandSerializerService = commandSerializerService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@@ -80,8 +89,11 @@ public class PermissionsApiResource {
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "PERMISSIONS_ROLE");
context.authenticatedUser().validateHasPermissionTo("PERMISSIONS_ROLE", allowedPermissions);
+ final PermissionsCommand command = this.apiDataConversionService.convertApiRequestJsonToPermissionsCommand(apiRequestBodyAsJson);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
+
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "permissions", null,
- apiRequestBodyAsJson);
+ commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/user/api/RolesApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/user/api/RolesApiResource.java
index aff346c04..23cf05e66 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/user/api/RolesApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/user/api/RolesApiResource.java
@@ -43,6 +43,8 @@ import org.springframework.stereotype.Component;
@Scope("singleton")
public class RolesApiResource {
+ private final String resourceNameForPermissions = "ROLE";
+
private final PlatformSecurityContext context;
private final RoleReadPlatformService roleReadPlatformService;
private final PermissionReadPlatformService permissionReadPlatformService;
@@ -53,8 +55,6 @@ public class RolesApiResource {
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final PortfolioCommandDeserializerService commandDeserializerService;
- private final String resourceNameForPermissions = "ROLE";
-
@Autowired
public RolesApiResource(
final PlatformSecurityContext context,
@@ -101,7 +101,7 @@ public class RolesApiResource {
context.authenticatedUser().validateHasPermissionTo("CREATE_ROLE", allowedPermissions);
final RoleCommand command = this.apiDataConversionService.convertApiRequestJsonToRoleCommand(null,apiRequestBodyAsJson);
- final String commandSerializedAsJson = this.commandSerializerService.serializeRoleCommandToJson(command);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "roles", null,
commandSerializedAsJson);
@@ -152,7 +152,7 @@ public class RolesApiResource {
context.authenticatedUser().validateHasPermissionTo("UPDATE_ROLE", allowedPermissions);
final RoleCommand command = this.apiDataConversionService.convertApiRequestJsonToRoleCommand(roleId, apiRequestBodyAsJson);
- final String commandSerializedAsJson = this.commandSerializerService.serializeRoleCommandToJson(command);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "roles", roleId,
commandSerializedAsJson);
@@ -215,7 +215,7 @@ public class RolesApiResource {
context.authenticatedUser().validateHasPermissionTo("PERMISSIONS_ROLE", allowedPermissions);
final RolePermissionCommand command = this.apiDataConversionService.convertApiRequestJsonToRolePermissionCommand(roleId, apiRequestBodyAsJson);
- final String commandSerializedAsJson = this.commandSerializerService.serializeRolePermissionCommandToJson(command);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATEPERMISSIONS", "roles", roleId,
commandSerializedAsJson);
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/user/api/UsersApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/user/api/UsersApiResource.java
index 63f1c836c..c361f6ab3 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/user/api/UsersApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/infrastructure/user/api/UsersApiResource.java
@@ -19,13 +19,16 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.data.EntityIdentifier;
+import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
+import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
import org.mifosplatform.infrastructure.office.data.OfficeLookup;
import org.mifosplatform.infrastructure.office.service.OfficeReadPlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.infrastructure.user.api.data.AppUserData;
+import org.mifosplatform.infrastructure.user.command.UserCommand;
import org.mifosplatform.infrastructure.user.service.AppUserReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
@@ -36,26 +39,34 @@ import org.springframework.stereotype.Component;
@Scope("singleton")
public class UsersApiResource {
- @Autowired
- private AppUserReadPlatformService appUserReadPlatformService;
-
- @Autowired
- private OfficeReadPlatformService officeReadPlatformService;
-
- @Autowired
- private PortfolioApiJsonSerializerService apiJsonSerializerService;
-
- @Autowired
- private PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
-
- @Autowired
- private PlatformSecurityContext context;
-
private final String resourceNameForPermissions = "USER";
+ private final PlatformSecurityContext context;
+ private final AppUserReadPlatformService readPlatformService;
+ private final OfficeReadPlatformService officeReadPlatformService;
+ private final PortfolioApiJsonSerializerService apiJsonSerializerService;
+ private final PortfolioApiDataConversionService apiDataConversionService;
+ private final PortfolioCommandSerializerService commandSerializerService;
+ private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
+
+ @Autowired
+ public UsersApiResource(final PlatformSecurityContext context, final AppUserReadPlatformService readPlatformService,
+ final OfficeReadPlatformService officeReadPlatformService, final PortfolioApiJsonSerializerService apiJsonSerializerService,
+ final PortfolioApiDataConversionService apiDataConversionService,
+ final PortfolioCommandSerializerService commandSerializerService,
+ final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
+ this.context = context;
+ this.readPlatformService = readPlatformService;
+ this.officeReadPlatformService = officeReadPlatformService;
+ this.apiJsonSerializerService = apiJsonSerializerService;
+ this.apiDataConversionService = apiDataConversionService;
+ this.commandSerializerService = commandSerializerService;
+ this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
+ }
+
@GET
- @Consumes({MediaType.APPLICATION_JSON})
- @Produces({MediaType.APPLICATION_JSON})
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
public String retrieveUsers(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
@@ -63,15 +74,15 @@ public class UsersApiResource {
final Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
- final Collection users = this.appUserReadPlatformService.retrieveAllUsers();
+ final Collection users = this.readPlatformService.retrieveAllUsers();
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, users);
}
@GET
@Path("{userId}")
- @Consumes({MediaType.APPLICATION_JSON})
- @Produces({MediaType.APPLICATION_JSON})
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
public String retrieveUser(@PathParam("userId") final Long userId, @Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
@@ -80,7 +91,7 @@ public class UsersApiResource {
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
- AppUserData user = this.appUserReadPlatformService.retrieveUser(userId);
+ AppUserData user = this.readPlatformService.retrieveUser(userId);
if (template) {
List offices = new ArrayList(this.officeReadPlatformService.retrieveAllOfficesForLookup());
user = new AppUserData(user, offices);
@@ -91,8 +102,8 @@ public class UsersApiResource {
@GET
@Path("template")
- @Consumes({MediaType.APPLICATION_JSON})
- @Produces({MediaType.APPLICATION_JSON})
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
public String newUserDetails(@Context final UriInfo uriInfo) {
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
@@ -100,48 +111,56 @@ public class UsersApiResource {
final Set responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
- final AppUserData user = this.appUserReadPlatformService.retrieveNewUserDetails();
+ final AppUserData user = this.readPlatformService.retrieveNewUserDetails();
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, user);
}
@POST
- @Consumes({MediaType.APPLICATION_JSON})
- @Produces({MediaType.APPLICATION_JSON})
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
public String createUser(final String apiRequestBodyAsJson) {
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "CREATE_USER");
context.authenticatedUser().validateHasPermissionTo("CREATE_USER", allowedPermissions);
-
- final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "users", null, apiRequestBodyAsJson);
- return this.apiJsonSerializerService.serializeEntityIdentifier(result);
- }
+ final UserCommand command = this.apiDataConversionService.convertApiRequestJsonToUserCommand(null, apiRequestBodyAsJson);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
- @DELETE
- @Path("{userId}")
- @Consumes({MediaType.APPLICATION_JSON})
- @Produces({MediaType.APPLICATION_JSON})
- public String deleteUser(@PathParam("userId") final Long userId) {
-
- final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "DELETE_USER");
- context.authenticatedUser().validateHasPermissionTo("DELETE_USER", allowedPermissions);
-
- final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "users", userId, "{}");
+ final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "users", null,
+ commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}
@PUT
@Path("{userId}")
- @Consumes({MediaType.APPLICATION_JSON})
- @Produces({MediaType.APPLICATION_JSON})
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
public String updateUser(@PathParam("userId") final Long userId, final String apiRequestBodyAsJson) {
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "UPDATE_USER");
context.authenticatedUser().validateHasPermissionTo("UPDATE_USER", allowedPermissions);
-
- final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "users", userId, apiRequestBodyAsJson);
+
+ final UserCommand command = this.apiDataConversionService.convertApiRequestJsonToUserCommand(null, apiRequestBodyAsJson);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
+
+ final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "users", userId,
+ commandSerializedAsJson);
+
+ return this.apiJsonSerializerService.serializeEntityIdentifier(result);
+ }
+
+ @DELETE
+ @Path("{userId}")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ public String deleteUser(@PathParam("userId") final Long userId) {
+
+ final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "DELETE_USER");
+ context.authenticatedUser().validateHasPermissionTo("DELETE_USER", allowedPermissions);
+
+ final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "users", userId, "{}");
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}
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 7d1fc6fb2..03940c5ec 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
@@ -17,10 +17,13 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.data.EntityIdentifier;
+import org.mifosng.platform.api.infrastructure.PortfolioApiDataConversionService;
import org.mifosng.platform.api.infrastructure.PortfolioApiJsonSerializerService;
+import org.mifosng.platform.api.infrastructure.PortfolioCommandSerializerService;
import org.mifosng.platform.infrastructure.api.ApiParameterHelper;
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
+import org.mifosplatform.portfolio.fund.command.FundCommand;
import org.mifosplatform.portfolio.fund.data.FundData;
import org.mifosplatform.portfolio.fund.service.FundReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,22 +34,27 @@ import org.springframework.stereotype.Component;
@Component
@Scope("singleton")
public class FundsApiResource {
-
+
private final String resourceNameForPermissions = "FUND";
-
+
private final PlatformSecurityContext context;
private final FundReadPlatformService readPlatformService;
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
+ private final PortfolioApiDataConversionService apiDataConversionService;
+ private final PortfolioCommandSerializerService commandSerializerService;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
-
+
@Autowired
- public FundsApiResource(final PlatformSecurityContext context,
- final FundReadPlatformService readPlatformService,
+ public FundsApiResource(final PlatformSecurityContext context, final FundReadPlatformService readPlatformService,
final PortfolioApiJsonSerializerService apiJsonSerializerService,
+ final PortfolioApiDataConversionService apiDataConversionService,
+ final PortfolioCommandSerializerService commandSerializerService,
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
this.context = context;
this.readPlatformService = readPlatformService;
this.apiJsonSerializerService = apiJsonSerializerService;
+ this.apiDataConversionService = apiDataConversionService;
+ this.commandSerializerService = commandSerializerService;
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
}
@@ -69,13 +77,16 @@ public class FundsApiResource {
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String createFund(final String apiRequestBodyAsJson) {
-
+
// FIXME - permissions - is funds a portfolio concept?
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "CREATE_FUND");
context.authenticatedUser().validateHasPermissionTo("CREATE_FUND", allowedPermissions);
+ final FundCommand command = this.apiDataConversionService.convertApiRequestJsonToFundCommand(null, apiRequestBodyAsJson);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
+
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "funds", null,
- apiRequestBodyAsJson);
+ commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}
@@ -105,8 +116,11 @@ public class FundsApiResource {
final List allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "UPDATE_FUND");
context.authenticatedUser().validateHasPermissionTo("UPDATE_FUND", allowedPermissions);
+ final FundCommand command = this.apiDataConversionService.convertApiRequestJsonToFundCommand(fundId, apiRequestBodyAsJson);
+ final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
+
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "funds", fundId,
- apiRequestBodyAsJson);
+ commandSerializedAsJson);
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
}