MIFOSX-97: tidy up serialization approach for currencies, offices, staff.
This commit is contained in:
+8
-7
@@ -7,9 +7,9 @@ import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.commands.domain.CommandSource;
|
||||
import org.mifosplatform.commands.exception.UnsupportedCommandException;
|
||||
import org.mifosplatform.commands.service.ChangeDetectionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioCommandDeserializerService;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.monetary.command.CurrencyCommand;
|
||||
import org.mifosplatform.organisation.monetary.serialization.CurrencyCommandFromCommandJsonDeserializer;
|
||||
import org.mifosplatform.organisation.monetary.service.CurrencyWritePlatformService;
|
||||
import org.mifosplatform.portfolio.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
@@ -21,15 +21,16 @@ public class CurrencyCommandHandler implements CommandSourceHandler {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ChangeDetectionService changeDetectionService;
|
||||
private final PortfolioCommandDeserializerService commandDeserializerService;
|
||||
private final CurrencyCommandFromCommandJsonDeserializer fromApiJsonDeserializer;
|
||||
private final CurrencyWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public CurrencyCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
|
||||
final PortfolioCommandDeserializerService commandDeserializerService, final CurrencyWritePlatformService writePlatformService) {
|
||||
final CurrencyCommandFromCommandJsonDeserializer fromApiJsonDeserializer,
|
||||
final CurrencyWritePlatformService writePlatformService) {
|
||||
this.context = context;
|
||||
this.changeDetectionService = changeDetectionService;
|
||||
this.commandDeserializerService = commandDeserializerService;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@@ -49,7 +50,7 @@ public class CurrencyCommandHandler implements CommandSourceHandler {
|
||||
commandSource.resourceId(), commandSource.json());
|
||||
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
|
||||
|
||||
final CurrencyCommand changesOnly = this.commandDeserializerService.deserializeCurrencyCommand(jsonOfChangesOnly, false);
|
||||
final CurrencyCommand changesOnly = this.fromApiJsonDeserializer.commandFromCommandJson(jsonOfChangesOnly);
|
||||
|
||||
this.writePlatformService.updateAllowedCurrencies(changesOnly);
|
||||
commandSourceResult.markAsChecked(maker, asToday);
|
||||
@@ -66,8 +67,8 @@ public class CurrencyCommandHandler implements CommandSourceHandler {
|
||||
|
||||
final AppUser checker = context.authenticatedUser();
|
||||
|
||||
final CurrencyCommand command = this.commandDeserializerService.deserializeCurrencyCommand(commandSourceResult.json(), true);
|
||||
|
||||
final CurrencyCommand command = this.fromApiJsonDeserializer.commandFromCommandJson(commandSourceResult.resourceId(),
|
||||
commandSourceResult.json(), true);
|
||||
if (commandSourceResult.isCreate()) {
|
||||
throw new UnsupportedCommandException(commandSourceResult.commandName());
|
||||
} else if (commandSourceResult.isUpdate()) {
|
||||
|
||||
+7
-8
@@ -7,10 +7,10 @@ import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.commands.domain.CommandSource;
|
||||
import org.mifosplatform.commands.exception.UnsupportedCommandException;
|
||||
import org.mifosplatform.commands.service.ChangeDetectionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioCommandDeserializerService;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.portfolio.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
|
||||
import org.mifosplatform.portfolio.fund.command.FundCommand;
|
||||
import org.mifosplatform.portfolio.fund.serialization.FundCommandFromCommandJsonDeserializer;
|
||||
import org.mifosplatform.portfolio.fund.service.FundWritePlatformService;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -21,15 +21,15 @@ public class FundCommandHandler implements CommandSourceHandler {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ChangeDetectionService changeDetectionService;
|
||||
private final PortfolioCommandDeserializerService commandDeserializerService;
|
||||
private final FundCommandFromCommandJsonDeserializer fromCommandJsonDeserializer;
|
||||
private final FundWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public FundCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
|
||||
final PortfolioCommandDeserializerService commandDeserializerService, final FundWritePlatformService writePlatformService) {
|
||||
final FundCommandFromCommandJsonDeserializer fromCommandJsonDeserializer, final FundWritePlatformService writePlatformService) {
|
||||
this.context = context;
|
||||
this.changeDetectionService = changeDetectionService;
|
||||
this.commandDeserializerService = commandDeserializerService;
|
||||
this.fromCommandJsonDeserializer = fromCommandJsonDeserializer;
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class FundCommandHandler implements CommandSourceHandler {
|
||||
final LocalDate asToday = new LocalDate();
|
||||
|
||||
final Long resourceId = commandSource.resourceId();
|
||||
final FundCommand command = this.commandDeserializerService.deserializeFundCommand(resourceId, commandSource.json(), false);
|
||||
final FundCommand command = this.fromCommandJsonDeserializer.commandFromCommandJson(resourceId, commandSource.json());
|
||||
|
||||
CommandSource commandSourceResult = commandSource.copy();
|
||||
|
||||
@@ -60,8 +60,7 @@ public class FundCommandHandler implements CommandSourceHandler {
|
||||
commandSource.resourceId(), commandSource.json());
|
||||
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
|
||||
|
||||
final FundCommand changesOnly = this.commandDeserializerService
|
||||
.deserializeFundCommand(resourceId, jsonOfChangesOnly, false);
|
||||
final FundCommand changesOnly = this.fromCommandJsonDeserializer.commandFromCommandJson(resourceId, jsonOfChangesOnly);
|
||||
|
||||
this.writePlatformService.updateFund(changesOnly);
|
||||
|
||||
@@ -80,7 +79,7 @@ public class FundCommandHandler implements CommandSourceHandler {
|
||||
final AppUser checker = context.authenticatedUser();
|
||||
|
||||
Long resourceId = commandSourceResult.resourceId();
|
||||
final FundCommand command = this.commandDeserializerService.deserializeFundCommand(resourceId, commandSourceResult.json(), true);
|
||||
final FundCommand command = this.fromCommandJsonDeserializer.commandFromCommandJson(resourceId, commandSourceResult.json(), true);
|
||||
|
||||
if (commandSourceResult.isCreate()) {
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER",
|
||||
|
||||
+10
-11
@@ -7,9 +7,9 @@ import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.commands.domain.CommandSource;
|
||||
import org.mifosplatform.commands.exception.UnsupportedCommandException;
|
||||
import org.mifosplatform.commands.service.ChangeDetectionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioCommandDeserializerService;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.office.command.OfficeCommand;
|
||||
import org.mifosplatform.organisation.office.serialization.OfficeCommandFromCommandJsonDeserializer;
|
||||
import org.mifosplatform.organisation.office.service.OfficeWritePlatformService;
|
||||
import org.mifosplatform.portfolio.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
@@ -21,15 +21,16 @@ public class OfficeCommandHandler implements CommandSourceHandler {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ChangeDetectionService changeDetectionService;
|
||||
private final PortfolioCommandDeserializerService commandDeserializerService;
|
||||
private final OfficeCommandFromCommandJsonDeserializer commandFromCommandJsonDeserializer;
|
||||
private final OfficeWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public OfficeCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
|
||||
final PortfolioCommandDeserializerService commandDeserializerService, final OfficeWritePlatformService writePlatformService) {
|
||||
final OfficeCommandFromCommandJsonDeserializer commandFromCommandJsonDeserializer,
|
||||
final OfficeWritePlatformService writePlatformService) {
|
||||
this.context = context;
|
||||
this.changeDetectionService = changeDetectionService;
|
||||
this.commandDeserializerService = commandDeserializerService;
|
||||
this.commandFromCommandJsonDeserializer = commandFromCommandJsonDeserializer;
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@@ -40,7 +41,7 @@ public class OfficeCommandHandler implements CommandSourceHandler {
|
||||
final LocalDate asToday = new LocalDate();
|
||||
|
||||
final Long resourceId = commandSource.resourceId();
|
||||
final OfficeCommand command = this.commandDeserializerService.deserializeOfficeCommand(resourceId, commandSource.json(), false);
|
||||
final OfficeCommand command = this.commandFromCommandJsonDeserializer.commandFromCommandJson(resourceId, commandSource.json());
|
||||
|
||||
CommandSource commandSourceResult = commandSource.copy();
|
||||
|
||||
@@ -60,9 +61,8 @@ public class OfficeCommandHandler implements CommandSourceHandler {
|
||||
commandSource.resourceId(), commandSource.json());
|
||||
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
|
||||
|
||||
final OfficeCommand changesOnly = this.commandDeserializerService.deserializeOfficeCommand(resourceId, jsonOfChangesOnly,
|
||||
false);
|
||||
|
||||
final OfficeCommand changesOnly = this.commandFromCommandJsonDeserializer.commandFromCommandJson(resourceId,
|
||||
jsonOfChangesOnly);
|
||||
this.writePlatformService.updateOffice(changesOnly);
|
||||
|
||||
commandSourceResult.markAsChecked(maker, asToday);
|
||||
@@ -80,9 +80,8 @@ public class OfficeCommandHandler implements CommandSourceHandler {
|
||||
final AppUser checker = context.authenticatedUser();
|
||||
|
||||
Long resourceId = commandSourceResult.resourceId();
|
||||
final OfficeCommand command = this.commandDeserializerService
|
||||
.deserializeOfficeCommand(resourceId, commandSourceResult.json(), true);
|
||||
|
||||
final OfficeCommand command = this.commandFromCommandJsonDeserializer.commandFromCommandJson(resourceId,
|
||||
commandSourceResult.json(), true);
|
||||
if (commandSourceResult.isCreate()) {
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER",
|
||||
"CREATE_OFFICE_CHECKER");
|
||||
|
||||
+9
-9
@@ -6,9 +6,9 @@ import java.util.List;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.commands.domain.CommandSource;
|
||||
import org.mifosplatform.commands.exception.UnsupportedCommandException;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioCommandDeserializerService;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.office.command.BranchMoneyTransferCommand;
|
||||
import org.mifosplatform.organisation.office.serialization.BranchMoneyTransferCommandFromCommandJsonDeserializer;
|
||||
import org.mifosplatform.organisation.office.service.OfficeWritePlatformService;
|
||||
import org.mifosplatform.portfolio.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
@@ -19,14 +19,15 @@ import org.springframework.stereotype.Service;
|
||||
public class OfficeTransactionCommandHandler implements CommandSourceHandler {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final PortfolioCommandDeserializerService commandDeserializerService;
|
||||
private final BranchMoneyTransferCommandFromCommandJsonDeserializer commandFromCommandJsonDeserializer;
|
||||
private final OfficeWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public OfficeTransactionCommandHandler(final PlatformSecurityContext context,
|
||||
final PortfolioCommandDeserializerService commandDeserializerService, final OfficeWritePlatformService writePlatformService) {
|
||||
final BranchMoneyTransferCommandFromCommandJsonDeserializer commandFromCommandJsonDeserializer,
|
||||
final OfficeWritePlatformService writePlatformService) {
|
||||
this.context = context;
|
||||
this.commandDeserializerService = commandDeserializerService;
|
||||
this.commandFromCommandJsonDeserializer = commandFromCommandJsonDeserializer;
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@@ -36,13 +37,12 @@ public class OfficeTransactionCommandHandler implements CommandSourceHandler {
|
||||
final AppUser maker = context.authenticatedUser();
|
||||
final LocalDate asToday = new LocalDate();
|
||||
|
||||
final BranchMoneyTransferCommand command = this.commandDeserializerService.deserializeOfficeTransactionCommand(
|
||||
commandSource.json(), false);
|
||||
|
||||
Long resourceId = commandSource.resourceId();
|
||||
final BranchMoneyTransferCommand command = this.commandFromCommandJsonDeserializer.commandFromCommandJson(resourceId,
|
||||
commandSource.json());
|
||||
CommandSource commandSourceResult = commandSource.copy();
|
||||
|
||||
Long newResourceId = null;
|
||||
|
||||
if (commandSource.isCreate()) {
|
||||
try {
|
||||
newResourceId = this.writePlatformService.externalBranchMoneyTransfer(command);
|
||||
@@ -64,7 +64,7 @@ public class OfficeTransactionCommandHandler implements CommandSourceHandler {
|
||||
final AppUser checker = context.authenticatedUser();
|
||||
|
||||
Long resourceId = commandSourceResult.resourceId();
|
||||
final BranchMoneyTransferCommand command = this.commandDeserializerService.deserializeOfficeTransactionCommand(
|
||||
final BranchMoneyTransferCommand command = this.commandFromCommandJsonDeserializer.commandFromCommandJson(resourceId,
|
||||
commandSourceResult.json(), true);
|
||||
|
||||
if (commandSourceResult.isCreate()) {
|
||||
|
||||
+12
-10
@@ -7,11 +7,11 @@ import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.commands.domain.CommandSource;
|
||||
import org.mifosplatform.commands.exception.UnsupportedCommandException;
|
||||
import org.mifosplatform.commands.service.ChangeDetectionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioCommandDeserializerService;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.portfolio.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
|
||||
import org.mifosplatform.useradministration.command.PermissionsCommand;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.mifosplatform.useradministration.serialization.PermissionsCommandFromCommandJsonDeserializer;
|
||||
import org.mifosplatform.useradministration.service.PermissionWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -21,16 +21,16 @@ public class PermissionsCommandHandler implements CommandSourceHandler {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ChangeDetectionService changeDetectionService;
|
||||
private final PortfolioCommandDeserializerService commandDeserializerService;
|
||||
private final PermissionsCommandFromCommandJsonDeserializer commandFromCommandJsonDeserializer;
|
||||
private final PermissionWritePlatformService permissionWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public PermissionsCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
|
||||
final PortfolioCommandDeserializerService commandDeserializerService,
|
||||
final PermissionsCommandFromCommandJsonDeserializer commandFromCommandJsonDeserializer,
|
||||
final PermissionWritePlatformService permissionWritePlatformService) {
|
||||
this.context = context;
|
||||
this.changeDetectionService = changeDetectionService;
|
||||
this.commandDeserializerService = commandDeserializerService;
|
||||
this.commandFromCommandJsonDeserializer = commandFromCommandJsonDeserializer;
|
||||
this.permissionWritePlatformService = permissionWritePlatformService;
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ public class PermissionsCommandHandler implements CommandSourceHandler {
|
||||
commandSource.resourceId(), commandSource.json());
|
||||
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
|
||||
|
||||
final PermissionsCommand changesOnly = this.commandDeserializerService.deserializePermissionsCommand(jsonOfChangesOnly,
|
||||
false);
|
||||
final PermissionsCommand changesOnly = this.commandFromCommandJsonDeserializer.commandFromCommandJson(
|
||||
commandSource.resourceId(), jsonOfChangesOnly);
|
||||
|
||||
this.permissionWritePlatformService.updateMakerCheckerPermissions(changesOnly);
|
||||
|
||||
@@ -70,11 +70,13 @@ public class PermissionsCommandHandler implements CommandSourceHandler {
|
||||
final AppUser checker = context.authenticatedUser();
|
||||
|
||||
if (commandSourceResult.isUpdate()) {
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "PERMISSIONS_ROLE");
|
||||
context.authenticatedUser().validateHasPermissionTo("PERMISSIONS_ROLE", allowedPermissions);
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER",
|
||||
"UPDATE_PERMISSION_CHECKER");
|
||||
context.authenticatedUser().validateHasPermissionTo("UPDATE_PERMISSION_CHECKER", allowedPermissions);
|
||||
|
||||
final PermissionsCommand command = this.commandFromCommandJsonDeserializer.commandFromCommandJson(
|
||||
commandSourceResult.resourceId(), commandSourceResult.json(), true);
|
||||
|
||||
final PermissionsCommand command = this.commandDeserializerService.deserializePermissionsCommand(commandSourceResult.json(),
|
||||
true);
|
||||
this.permissionWritePlatformService.updateMakerCheckerPermissions(command);
|
||||
commandSourceResult.markAsChecked(checker, new LocalDate());
|
||||
} else {
|
||||
|
||||
+24
-15
@@ -7,12 +7,13 @@ import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.commands.domain.CommandSource;
|
||||
import org.mifosplatform.commands.exception.UnsupportedCommandException;
|
||||
import org.mifosplatform.commands.service.ChangeDetectionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioCommandDeserializerService;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.portfolio.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
|
||||
import org.mifosplatform.useradministration.command.RoleCommand;
|
||||
import org.mifosplatform.useradministration.command.RolePermissionCommand;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.mifosplatform.useradministration.serialization.RoleCommandFromCommandJsonDeserializer;
|
||||
import org.mifosplatform.useradministration.serialization.RolePermissionsCommandFromCommandJsonDeserializer;
|
||||
import org.mifosplatform.useradministration.service.RoleWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -22,15 +23,19 @@ public class RoleCommandHandler implements CommandSourceHandler {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ChangeDetectionService changeDetectionService;
|
||||
private final PortfolioCommandDeserializerService commandDeserializerService;
|
||||
private final RoleWritePlatformService writePlatformService;
|
||||
private final RoleCommandFromCommandJsonDeserializer commandFromCommandJsonDeserializer;
|
||||
private final RolePermissionsCommandFromCommandJsonDeserializer permissionsCommandFromCommandJsonDeserializer;
|
||||
|
||||
@Autowired
|
||||
public RoleCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
|
||||
final PortfolioCommandDeserializerService commandDeserializerService, final RoleWritePlatformService writePlatformService) {
|
||||
final RoleCommandFromCommandJsonDeserializer commandFromCommandJsonDeserializer,
|
||||
final RolePermissionsCommandFromCommandJsonDeserializer permissionsCommandFromCommandJsonDeserializer,
|
||||
final RoleWritePlatformService writePlatformService) {
|
||||
this.context = context;
|
||||
this.changeDetectionService = changeDetectionService;
|
||||
this.commandDeserializerService = commandDeserializerService;
|
||||
this.commandFromCommandJsonDeserializer = commandFromCommandJsonDeserializer;
|
||||
this.permissionsCommandFromCommandJsonDeserializer = permissionsCommandFromCommandJsonDeserializer;
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@@ -47,7 +52,8 @@ public class RoleCommandHandler implements CommandSourceHandler {
|
||||
|
||||
if (commandSource.isCreate()) {
|
||||
try {
|
||||
final RoleCommand command = this.commandDeserializerService.deserializeRoleCommand(resourceId, commandSource.json(), false);
|
||||
final RoleCommand command = this.commandFromCommandJsonDeserializer
|
||||
.commandFromCommandJson(resourceId, commandSource.json());
|
||||
|
||||
newResourceId = this.writePlatformService.createRole(command);
|
||||
|
||||
@@ -62,8 +68,8 @@ public class RoleCommandHandler implements CommandSourceHandler {
|
||||
commandSource.resourceId(), commandSource.json());
|
||||
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
|
||||
|
||||
final RoleCommand changesOnly = this.commandDeserializerService
|
||||
.deserializeRoleCommand(resourceId, jsonOfChangesOnly, false);
|
||||
final RoleCommand changesOnly = this.commandFromCommandJsonDeserializer.commandFromCommandJson(resourceId,
|
||||
jsonOfChangesOnly);
|
||||
|
||||
newResourceId = this.writePlatformService.updateRole(changesOnly);
|
||||
|
||||
@@ -77,8 +83,8 @@ public class RoleCommandHandler implements CommandSourceHandler {
|
||||
commandSource.resourceId(), commandSource.json());
|
||||
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
|
||||
|
||||
final RolePermissionCommand changesOnly = this.commandDeserializerService.deserializeRolePermissionCommand(resourceId,
|
||||
jsonOfChangesOnly, false);
|
||||
final RolePermissionCommand changesOnly = this.permissionsCommandFromCommandJsonDeserializer.commandFromCommandJson(
|
||||
resourceId, jsonOfChangesOnly);
|
||||
|
||||
newResourceId = this.writePlatformService.updateRolePermissions(changesOnly);
|
||||
|
||||
@@ -101,8 +107,9 @@ public class RoleCommandHandler implements CommandSourceHandler {
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "CREATE_ROLE_CHECKER");
|
||||
context.authenticatedUser().validateHasPermissionTo("CREATE_ROLE_CHECKER", allowedPermissions);
|
||||
|
||||
final RoleCommand command = this.commandDeserializerService
|
||||
.deserializeRoleCommand(resourceId, commandSourceResult.json(), true);
|
||||
final RoleCommand command = this.commandFromCommandJsonDeserializer.commandFromCommandJson(resourceId,
|
||||
commandSourceResult.json(), true);
|
||||
|
||||
resourceId = this.writePlatformService.createRole(command);
|
||||
commandSourceResult.updateResourceId(resourceId);
|
||||
commandSourceResult.markAsChecked(checker, new LocalDate());
|
||||
@@ -111,8 +118,9 @@ public class RoleCommandHandler implements CommandSourceHandler {
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "UPDATE_ROLE_CHECKER");
|
||||
context.authenticatedUser().validateHasPermissionTo("UPDATE_ROLE_CHECKER", allowedPermissions);
|
||||
|
||||
final RoleCommand command = this.commandDeserializerService
|
||||
.deserializeRoleCommand(resourceId, commandSourceResult.json(), true);
|
||||
final RoleCommand command = this.commandFromCommandJsonDeserializer.commandFromCommandJson(resourceId,
|
||||
commandSourceResult.json(), true);
|
||||
|
||||
resourceId = this.writePlatformService.updateRole(command);
|
||||
commandSourceResult.markAsChecked(checker, new LocalDate());
|
||||
} else if (commandSourceResult.isUpdateRolePermissions()) {
|
||||
@@ -120,8 +128,9 @@ public class RoleCommandHandler implements CommandSourceHandler {
|
||||
"PERMISSIONS_ROLE_CHECKER");
|
||||
context.authenticatedUser().validateHasPermissionTo("PERMISSIONS_ROLE_CHECKER", allowedPermissions);
|
||||
|
||||
final RolePermissionCommand command = this.commandDeserializerService.deserializeRolePermissionCommand(resourceId,
|
||||
commandSourceResult.json(), true);
|
||||
final RolePermissionCommand command = this.permissionsCommandFromCommandJsonDeserializer.commandFromCommandJson(resourceId,
|
||||
commandSourceResult.json());
|
||||
|
||||
resourceId = this.writePlatformService.updateRolePermissions(command);
|
||||
commandSourceResult.markAsChecked(checker, new LocalDate());
|
||||
} else if (commandSourceResult.isDelete()) { throw new UnsupportedCommandException(commandSourceResult.commandName()); }
|
||||
|
||||
+11
-10
@@ -7,9 +7,9 @@ import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.commands.domain.CommandSource;
|
||||
import org.mifosplatform.commands.exception.UnsupportedCommandException;
|
||||
import org.mifosplatform.commands.service.ChangeDetectionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioCommandDeserializerService;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.staff.command.StaffCommand;
|
||||
import org.mifosplatform.organisation.staff.serialization.StaffCommandFromCommandJsonDeserializer;
|
||||
import org.mifosplatform.organisation.staff.service.StaffWritePlatformService;
|
||||
import org.mifosplatform.portfolio.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
@@ -21,15 +21,17 @@ public class StaffCommandHandler implements CommandSourceHandler {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ChangeDetectionService changeDetectionService;
|
||||
private final PortfolioCommandDeserializerService commandDeserializerService;
|
||||
private final StaffCommandFromCommandJsonDeserializer fromCommandJsonDeserializer;
|
||||
private final StaffWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public StaffCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
|
||||
final PortfolioCommandDeserializerService commandDeserializerService, final StaffWritePlatformService writePlatformService) {
|
||||
public StaffCommandHandler(final PlatformSecurityContext context,
|
||||
final ChangeDetectionService changeDetectionService,
|
||||
final StaffCommandFromCommandJsonDeserializer fromCommandJsonDeserializer,
|
||||
final StaffWritePlatformService writePlatformService) {
|
||||
this.context = context;
|
||||
this.changeDetectionService = changeDetectionService;
|
||||
this.commandDeserializerService = commandDeserializerService;
|
||||
this.fromCommandJsonDeserializer = fromCommandJsonDeserializer;
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@@ -40,7 +42,7 @@ public class StaffCommandHandler implements CommandSourceHandler {
|
||||
final LocalDate asToday = new LocalDate();
|
||||
|
||||
final Long resourceId = commandSource.resourceId();
|
||||
final StaffCommand command = this.commandDeserializerService.deserializeStaffCommand(resourceId, commandSource.json(), false);
|
||||
final StaffCommand command = this.fromCommandJsonDeserializer.commandFromCommandJson(resourceId, commandSource.json());
|
||||
CommandSource commandSourceResult = commandSource.copy();
|
||||
|
||||
Long newResourceId = null;
|
||||
@@ -58,8 +60,7 @@ public class StaffCommandHandler implements CommandSourceHandler {
|
||||
commandSource.resourceId(), commandSource.json());
|
||||
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
|
||||
|
||||
final StaffCommand changesOnly = this.commandDeserializerService.deserializeStaffCommand(resourceId, jsonOfChangesOnly,
|
||||
false);
|
||||
final StaffCommand changesOnly = this.fromCommandJsonDeserializer.commandFromCommandJson(resourceId, jsonOfChangesOnly);
|
||||
|
||||
this.writePlatformService.updateStaff(changesOnly);
|
||||
|
||||
@@ -78,8 +79,8 @@ public class StaffCommandHandler implements CommandSourceHandler {
|
||||
final AppUser checker = context.authenticatedUser();
|
||||
|
||||
Long resourceId = commandSourceResult.resourceId();
|
||||
final StaffCommand command = this.commandDeserializerService.deserializeStaffCommand(resourceId, commandSourceResult.json(), true);
|
||||
|
||||
final StaffCommand command = this.fromCommandJsonDeserializer.commandFromCommandJson(resourceId, commandSourceResult.json(), true);
|
||||
|
||||
if (commandSourceResult.isCreate()) {
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER",
|
||||
"CREATE_STAFF_CHECKER");
|
||||
|
||||
+10
-12
@@ -6,11 +6,11 @@ import java.util.List;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.commands.domain.CommandSource;
|
||||
import org.mifosplatform.commands.service.ChangeDetectionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioCommandDeserializerService;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.portfolio.client.service.RollbackTransactionAsCommandIsNotApprovedByCheckerException;
|
||||
import org.mifosplatform.useradministration.command.UserCommand;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.mifosplatform.useradministration.serialization.UserCommandFromCommandJsonDeserializer;
|
||||
import org.mifosplatform.useradministration.service.AppUserWritePlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -20,15 +20,15 @@ public class UserCommandHandler implements CommandSourceHandler {
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final ChangeDetectionService changeDetectionService;
|
||||
private final PortfolioCommandDeserializerService commandDeserializerService;
|
||||
private final UserCommandFromCommandJsonDeserializer fromCommandJsonDeserializer;
|
||||
private final AppUserWritePlatformService writePlatformService;
|
||||
|
||||
@Autowired
|
||||
public UserCommandHandler(final PlatformSecurityContext context, final ChangeDetectionService changeDetectionService,
|
||||
final PortfolioCommandDeserializerService commandDeserializerService, final AppUserWritePlatformService writePlatformService) {
|
||||
final UserCommandFromCommandJsonDeserializer fromCommandJsonDeserializer, final AppUserWritePlatformService writePlatformService) {
|
||||
this.context = context;
|
||||
this.changeDetectionService = changeDetectionService;
|
||||
this.commandDeserializerService = commandDeserializerService;
|
||||
this.fromCommandJsonDeserializer = fromCommandJsonDeserializer;
|
||||
this.writePlatformService = writePlatformService;
|
||||
}
|
||||
|
||||
@@ -39,8 +39,7 @@ public class UserCommandHandler implements CommandSourceHandler {
|
||||
final LocalDate asToday = new LocalDate();
|
||||
|
||||
final Long resourceId = commandSource.resourceId();
|
||||
final UserCommand command = this.commandDeserializerService.deserializeUserCommand(resourceId, commandSource.json(), false);
|
||||
|
||||
final UserCommand command = this.fromCommandJsonDeserializer.commandFromCommandJson(resourceId, commandSource.json());
|
||||
CommandSource commandSourceResult = commandSource.copy();
|
||||
if (commandSource.isCreate()) {
|
||||
try {
|
||||
@@ -57,9 +56,7 @@ public class UserCommandHandler implements CommandSourceHandler {
|
||||
commandSource.resourceId(), commandSource.json());
|
||||
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
|
||||
|
||||
final UserCommand changesOnly = this.commandDeserializerService
|
||||
.deserializeUserCommand(resourceId, jsonOfChangesOnly, false);
|
||||
|
||||
final UserCommand changesOnly = this.fromCommandJsonDeserializer.commandFromCommandJson(resourceId, jsonOfChangesOnly);
|
||||
if (maker.hasIdOf(command.getId())) {
|
||||
this.writePlatformService.updateUsersOwnAccountDetails(changesOnly);
|
||||
} else {
|
||||
@@ -88,7 +85,7 @@ public class UserCommandHandler implements CommandSourceHandler {
|
||||
final AppUser checker = context.authenticatedUser();
|
||||
|
||||
Long resourceId = commandSourceResult.resourceId();
|
||||
final UserCommand command = this.commandDeserializerService.deserializeUserCommand(resourceId, commandSourceResult.json(), true);
|
||||
final UserCommand command = this.fromCommandJsonDeserializer.commandFromCommandJson(resourceId, commandSourceResult.json(), true);
|
||||
if (commandSourceResult.isUserResource()) {
|
||||
if (commandSourceResult.isCreate()) {
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER",
|
||||
@@ -102,9 +99,10 @@ public class UserCommandHandler implements CommandSourceHandler {
|
||||
if (checker.hasIdOf(command.getId())) {
|
||||
this.writePlatformService.updateUsersOwnAccountDetails(command);
|
||||
} else {
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER","UPDATE_USER_MAKER");
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER",
|
||||
"UPDATE_USER_MAKER");
|
||||
context.authenticatedUser().validateHasPermissionTo("UPDATE_USER_MAKER", allowedPermissions);
|
||||
|
||||
|
||||
this.writePlatformService.updateUser(command);
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -38,7 +38,6 @@ public class CodesApiResource {
|
||||
|
||||
/**
|
||||
* The set of parameters that are supported in response for {@link CodeData}
|
||||
* .
|
||||
*/
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "systemDefined"));
|
||||
private final String resourceNameForPermissions = "CODE";
|
||||
@@ -52,8 +51,8 @@ public class CodesApiResource {
|
||||
|
||||
@Autowired
|
||||
public CodesApiResource(final PlatformSecurityContext context, final CodeReadPlatformService readPlatformService,
|
||||
final CodeCommandFromApiJsonDeserializer fromApiJsonDeserializer, final DefaultToApiJsonSerializer<CodeData> toApiJsonSerializer,
|
||||
final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final CodeCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||
final DefaultToApiJsonSerializer<CodeData> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.context = context;
|
||||
this.readPlatformService = readPlatformService;
|
||||
|
||||
+5
-2
@@ -25,7 +25,10 @@ public class ApiRequestParameterHelper {
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(queryParameters);
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(queryParameters);
|
||||
|
||||
return ApiRequestJsonSerializationSettings.from(prettyPrint, responseParameters);
|
||||
final boolean template = ApiParameterHelper.template(queryParameters);
|
||||
final Long commandId = ApiParameterHelper.commandId(queryParameters);
|
||||
final boolean makerCheckerable = ApiParameterHelper.makerCheckerable(queryParameters);
|
||||
|
||||
return ApiRequestJsonSerializationSettings.from(prettyPrint, responseParameters, template, commandId, makerCheckerable);
|
||||
}
|
||||
}
|
||||
+1
-123
@@ -11,9 +11,7 @@ import org.mifosplatform.infrastructure.core.serialization.GoogleGsonSerializerH
|
||||
import org.mifosplatform.infrastructure.dataqueries.data.DatatableData;
|
||||
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
|
||||
import org.mifosplatform.infrastructure.documentmanagement.data.DocumentData;
|
||||
import org.mifosplatform.organisation.monetary.data.ConfigurationData;
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
import org.mifosplatform.organisation.office.data.OfficeTransactionData;
|
||||
import org.mifosplatform.infrastructure.security.data.AuthenticatedUserData;
|
||||
import org.mifosplatform.organisation.staff.data.BulkTransferLoanOfficerData;
|
||||
import org.mifosplatform.organisation.staff.data.StaffData;
|
||||
import org.mifosplatform.portfolio.charge.data.ChargeData;
|
||||
@@ -21,7 +19,6 @@ import org.mifosplatform.portfolio.client.data.ClientAccountSummaryCollectionDat
|
||||
import org.mifosplatform.portfolio.client.data.ClientData;
|
||||
import org.mifosplatform.portfolio.client.data.ClientIdentifierData;
|
||||
import org.mifosplatform.portfolio.client.data.NoteData;
|
||||
import org.mifosplatform.portfolio.fund.data.FundData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupData;
|
||||
import org.mifosplatform.portfolio.loanaccount.data.LoanAccountData;
|
||||
@@ -35,11 +32,6 @@ import org.mifosplatform.portfolio.savingsaccount.data.SavingScheduleData;
|
||||
import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductData;
|
||||
import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositAccountData;
|
||||
import org.mifosplatform.portfolio.savingsdepositproduct.data.DepositProductData;
|
||||
import org.mifosplatform.useradministration.data.AppUserData;
|
||||
import org.mifosplatform.useradministration.data.AuthenticatedUserData;
|
||||
import org.mifosplatform.useradministration.data.PermissionUsageData;
|
||||
import org.mifosplatform.useradministration.data.RoleData;
|
||||
import org.mifosplatform.useradministration.data.RolePermissionsData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -52,22 +44,6 @@ import com.google.gson.Gson;
|
||||
@Service
|
||||
public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApiJsonSerializerService {
|
||||
|
||||
private static final Set<String> PERMISSION_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("grouping", "code", "entityName",
|
||||
"actionName", "selected", "isMakerChecker"));
|
||||
private static final Set<String> ROLE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description",
|
||||
"availablePermissions", "selectedPermissions"));
|
||||
private static final Set<String> ROLE_PERMISSION_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description",
|
||||
"permissionUsageData"));
|
||||
private static final Set<String> APP_USER_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "officeId", "officeName",
|
||||
"username", "firstname", "lastname", "email", "allowedOffices", "availableRoles", "selectedRoles"));
|
||||
private static final Set<String> OFFICE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "nameDecorated",
|
||||
"externalId", "openingDate", "hierarchy", "parentId", "parentName", "allowedParents"));
|
||||
private static final Set<String> OFFICE_TRANSACTIONS_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "transactionDate",
|
||||
"fromOfficeId", "fromOfficeName", "toOfficeId", "toOfficeIdName", "currencyCode", "digitsAfterDecimal", "transactionAmount",
|
||||
"description", "allowedOffices", "currencyOptions"));
|
||||
private static final Set<String> CONFIGURATION_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("selectedCurrencyOptions",
|
||||
"currencyOptions"));
|
||||
private static final Set<String> FUND_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "externalId"));
|
||||
private static final Set<String> STAFF_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "firstname", "lastname",
|
||||
"displayName", "officeId", "officeName", "loanOfficerFlag", "allowedOffices"));
|
||||
private static final Set<String> LOAN_PRODUCT_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description",
|
||||
@@ -196,104 +172,6 @@ public class GoogleGsonPortfolioApiJsonSerializerService implements PortfolioApi
|
||||
return helper.serializedJsonFrom(gsonDeserializer, datatables.toArray(new DatatableData[datatables.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializePermissionDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
|
||||
final Collection<PermissionUsageData> permissions) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(PERMISSION_DATA_PARAMETERS,
|
||||
prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, permissions.toArray(new PermissionUsageData[permissions.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeRoleDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final Collection<RoleData> roles) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(ROLE_DATA_PARAMETERS,
|
||||
prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, roles.toArray(new RoleData[roles.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeRoleDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final RoleData role) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(ROLE_DATA_PARAMETERS,
|
||||
prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeRolePermissionDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
|
||||
final RolePermissionsData rolePermissionData) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(ROLE_PERMISSION_DATA_PARAMETERS,
|
||||
prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, rolePermissionData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeAppUserDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
|
||||
final Collection<AppUserData> users) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(APP_USER_DATA_PARAMETERS,
|
||||
prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, users.toArray(new AppUserData[users.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeAppUserDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final AppUserData user) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(APP_USER_DATA_PARAMETERS,
|
||||
prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeOfficeDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
|
||||
final Collection<OfficeData> offices) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(OFFICE_DATA_PARAMETERS,
|
||||
prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, offices.toArray(new OfficeData[offices.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeOfficeDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final OfficeData office) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(OFFICE_DATA_PARAMETERS,
|
||||
prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, office);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeOfficeTransactionDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
|
||||
final Collection<OfficeTransactionData> officeTransactions) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(
|
||||
OFFICE_TRANSACTIONS_DATA_PARAMETERS, prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, officeTransactions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeOfficeTransactionDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
|
||||
final OfficeTransactionData officeTransaction) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(
|
||||
OFFICE_TRANSACTIONS_DATA_PARAMETERS, prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, officeTransaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeConfigurationDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
|
||||
final ConfigurationData configuration) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(CONFIGURATION_DATA_PARAMETERS,
|
||||
prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeFundDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final Collection<FundData> funds) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(FUND_DATA_PARAMETERS,
|
||||
prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, funds.toArray(new FundData[funds.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeFundDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final FundData fund) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(FUND_DATA_PARAMETERS,
|
||||
prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, fund);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeLoanProductDataToJson(final boolean prettyPrint, final Set<String> responseParameters,
|
||||
final Collection<LoanProductData> products) {
|
||||
|
||||
-27
@@ -1,16 +1,11 @@
|
||||
package org.mifosplatform.infrastructure.core.api;
|
||||
|
||||
import org.mifosplatform.organisation.monetary.command.CurrencyCommand;
|
||||
import org.mifosplatform.organisation.office.command.BranchMoneyTransferCommand;
|
||||
import org.mifosplatform.organisation.office.command.OfficeCommand;
|
||||
import org.mifosplatform.organisation.staff.command.BulkTransferLoanOfficerCommand;
|
||||
import org.mifosplatform.organisation.staff.command.StaffCommand;
|
||||
import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
|
||||
import org.mifosplatform.portfolio.client.command.ClientCommand;
|
||||
import org.mifosplatform.portfolio.client.command.ClientIdentifierCommand;
|
||||
import org.mifosplatform.portfolio.client.command.NoteCommand;
|
||||
import org.mifosplatform.portfolio.client.data.ClientData;
|
||||
import org.mifosplatform.portfolio.fund.command.FundCommand;
|
||||
import org.mifosplatform.portfolio.group.command.GroupCommand;
|
||||
import org.mifosplatform.portfolio.loanaccount.command.AdjustLoanTransactionCommand;
|
||||
import org.mifosplatform.portfolio.loanaccount.command.LoanApplicationCommand;
|
||||
@@ -27,29 +22,11 @@ import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountW
|
||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionApprovalCommand;
|
||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionCommand;
|
||||
import org.mifosplatform.portfolio.savingsdepositproduct.command.DepositProductCommand;
|
||||
import org.mifosplatform.useradministration.command.PermissionsCommand;
|
||||
import org.mifosplatform.useradministration.command.RoleCommand;
|
||||
import org.mifosplatform.useradministration.command.RolePermissionCommand;
|
||||
import org.mifosplatform.useradministration.command.UserCommand;
|
||||
|
||||
public interface PortfolioApiDataConversionService {
|
||||
|
||||
ChargeDefinitionCommand convertApiRequestJsonToChargeDefinitionCommand(Long resourceIdentifier, String json);
|
||||
|
||||
FundCommand convertApiRequestJsonToFundCommand(Long resourceIdentifier, String json);
|
||||
|
||||
OfficeCommand convertApiRequestJsonToOfficeCommand(Long resourceIdentifier, String json);
|
||||
|
||||
RoleCommand convertApiRequestJsonToRoleCommand(Long resourceIdentifier, String json);
|
||||
|
||||
PermissionsCommand convertApiRequestJsonToPermissionsCommand(String jsonRequestBody);
|
||||
|
||||
RolePermissionCommand convertApiRequestJsonToRolePermissionCommand(Long roleId, String jsonRequestBody);
|
||||
|
||||
UserCommand convertApiRequestJsonToUserCommand(Long resourceIdentifier, String json);
|
||||
|
||||
BranchMoneyTransferCommand convertApiRequestJsonToBranchMoneyTransferCommand(String json);
|
||||
|
||||
LoanProductCommand convertApiRequestJsonToLoanProductCommand(Long resourceIdentifier, String json);
|
||||
|
||||
SavingProductCommand convertJsonToSavingProductCommand(Long resourceIdentifier, String json);
|
||||
@@ -74,8 +51,6 @@ public interface PortfolioApiDataConversionService {
|
||||
|
||||
AdjustLoanTransactionCommand convertJsonToAdjustLoanTransactionCommand(Long loanId, Long transactionId, String json);
|
||||
|
||||
CurrencyCommand convertApiRequestJsonToCurrencyCommand(String json);
|
||||
|
||||
NoteCommand convertJsonToNoteCommand(Long resourceIdentifier, Long clientId, String json);
|
||||
|
||||
DepositAccountCommand convertJsonToDepositAccountCommand(Long resourceIdentifier, String json);
|
||||
@@ -84,8 +59,6 @@ public interface PortfolioApiDataConversionService {
|
||||
|
||||
DepositStateTransitionApprovalCommand convertJsonToDepositStateTransitionApprovalCommand(Long resourceIdentifier, String json);
|
||||
|
||||
StaffCommand convertApiRequestJsonToStaffCommand(Long resourceIdentifier, String json);
|
||||
|
||||
BulkTransferLoanOfficerCommand convertJsonToLoanReassignmentCommand(Long resourceIdentifier, String json);
|
||||
|
||||
BulkTransferLoanOfficerCommand convertJsonToBulkLoanReassignmentCommand(String json);
|
||||
|
||||
-163
@@ -22,17 +22,12 @@ import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
|
||||
import org.mifosplatform.infrastructure.core.exception.UnsupportedParameterException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.JsonParserHelper;
|
||||
import org.mifosplatform.organisation.monetary.command.CurrencyCommand;
|
||||
import org.mifosplatform.organisation.office.command.BranchMoneyTransferCommand;
|
||||
import org.mifosplatform.organisation.office.command.OfficeCommand;
|
||||
import org.mifosplatform.organisation.staff.command.BulkTransferLoanOfficerCommand;
|
||||
import org.mifosplatform.organisation.staff.command.StaffCommand;
|
||||
import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
|
||||
import org.mifosplatform.portfolio.client.command.ClientCommand;
|
||||
import org.mifosplatform.portfolio.client.command.ClientIdentifierCommand;
|
||||
import org.mifosplatform.portfolio.client.command.NoteCommand;
|
||||
import org.mifosplatform.portfolio.client.data.ClientData;
|
||||
import org.mifosplatform.portfolio.fund.command.FundCommand;
|
||||
import org.mifosplatform.portfolio.group.command.GroupCommand;
|
||||
import org.mifosplatform.portfolio.loanaccount.command.AdjustLoanTransactionCommand;
|
||||
import org.mifosplatform.portfolio.loanaccount.command.LoanApplicationCommand;
|
||||
@@ -49,10 +44,6 @@ import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositAccountW
|
||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionApprovalCommand;
|
||||
import org.mifosplatform.portfolio.savingsdepositaccount.command.DepositStateTransitionCommand;
|
||||
import org.mifosplatform.portfolio.savingsdepositproduct.command.DepositProductCommand;
|
||||
import org.mifosplatform.useradministration.command.PermissionsCommand;
|
||||
import org.mifosplatform.useradministration.command.RoleCommand;
|
||||
import org.mifosplatform.useradministration.command.RolePermissionCommand;
|
||||
import org.mifosplatform.useradministration.command.UserCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.format.number.NumberFormatter;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -125,36 +116,6 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
chargeTimeType, chargeAppliesTo, chargeCalculationType, penalty, active);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FundCommand convertApiRequestJsonToFundCommand(final Long resourceIdentifier, final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType();
|
||||
final Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
final Set<String> supportedParams = new HashSet<String>(Arrays.asList("name", "externalId"));
|
||||
|
||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||
|
||||
return this.portfolioCommandDeserializerService.deserializeFundCommand(resourceIdentifier, json, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaffCommand convertApiRequestJsonToStaffCommand(final Long resourceIdentifier, final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType();
|
||||
final Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
final Set<String> supportedParams = new HashSet<String>(Arrays.asList("firstname", "lastname", "officeId", "isLoanOfficer"));
|
||||
|
||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||
|
||||
return this.portfolioCommandDeserializerService.deserializeStaffCommand(resourceIdentifier, json, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BulkTransferLoanOfficerCommand convertJsonToLoanReassignmentCommand(Long resourceIdentifier, String json) {
|
||||
|
||||
@@ -217,116 +178,6 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
return new BulkTransferLoanOfficerCommand(fromLoanOfficerId, toLoanOfficerId, assignmentDate, loans);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeCommand convertApiRequestJsonToOfficeCommand(final Long resourceIdentifier, final String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType();
|
||||
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
Set<String> supportedParams = new HashSet<String>(Arrays.asList("name", "externalId", "parentId", "openingDate", "locale",
|
||||
"dateFormat"));
|
||||
|
||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final JsonParser parser = new JsonParser();
|
||||
final JsonElement element = parser.parse(json);
|
||||
final JsonParserHelper helper = new JsonParserHelper();
|
||||
|
||||
final String name = helper.extractStringNamed("name", element, parametersPassedInRequest);
|
||||
final String externalId = helper.extractStringNamed("externalId", element, parametersPassedInRequest);
|
||||
final Long parentId = helper.extractLongNamed("parentId", element, parametersPassedInRequest);
|
||||
final LocalDate openingLocalDate = helper.extractLocalDateNamed("openingDate", element, parametersPassedInRequest);
|
||||
|
||||
return new OfficeCommand(parametersPassedInRequest, false, resourceIdentifier, name, externalId, parentId, openingLocalDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleCommand convertApiRequestJsonToRoleCommand(final Long resourceIdentifier, final String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
final Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
final Set<String> supportedParams = new HashSet<String>(Arrays.asList("id", "name", "description"));
|
||||
|
||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||
|
||||
// no difference between the api json and internal command
|
||||
// representation of json so reuse this code to de-serialize into
|
||||
// command object
|
||||
return this.portfolioCommandDeserializerService.deserializeRoleCommand(resourceIdentifier, json, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsCommand convertApiRequestJsonToPermissionsCommand(final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Boolean>>() {}.getType();
|
||||
final Map<String, Boolean> permissionsMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
return new PermissionsCommand(permissionsMap, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolePermissionCommand convertApiRequestJsonToRolePermissionCommand(final Long resourceIdentifier, final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Boolean>>() {}.getType();
|
||||
final Map<String, Boolean> permissionsMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
return new RolePermissionCommand(resourceIdentifier, permissionsMap, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserCommand convertApiRequestJsonToUserCommand(final Long resourceIdentifier, final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
final Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
final Set<String> supportedParams = new HashSet<String>(Arrays.asList("username", "firstname", "lastname", "password",
|
||||
"repeatPassword", "email", "officeId", "notSelectedRoles", "roles"));
|
||||
|
||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||
|
||||
// no difference between the api json and internal command
|
||||
// representation of json so reuse this code to de-serialize into
|
||||
// command object
|
||||
return this.portfolioCommandDeserializerService.deserializeUserCommand(resourceIdentifier, json, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchMoneyTransferCommand convertApiRequestJsonToBranchMoneyTransferCommand(final String json) {
|
||||
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType();
|
||||
Map<String, String> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
Set<String> supportedParams = new HashSet<String>(Arrays.asList("fromOfficeId", "toOfficeId", "transactionDate", "currencyCode",
|
||||
"transactionAmount", "description", "locale", "dateFormat"));
|
||||
|
||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||
|
||||
Set<String> modifiedParameters = new HashSet<String>();
|
||||
|
||||
Long fromOfficeId = extractLongParameter("fromOfficeId", requestMap, modifiedParameters);
|
||||
Long toOfficeId = extractLongParameter("toOfficeId", requestMap, modifiedParameters);
|
||||
LocalDate transactionLocalDate = extractLocalDateParameter("transactionDate", requestMap, modifiedParameters);
|
||||
String currencyCode = extractStringParameter("currencyCode", requestMap, modifiedParameters);
|
||||
BigDecimal transactionAmountValue = extractBigDecimalParameter("transactionAmount", requestMap, modifiedParameters);
|
||||
String description = extractStringParameter("description", requestMap, modifiedParameters);
|
||||
|
||||
return new BranchMoneyTransferCommand(modifiedParameters, false, fromOfficeId, toOfficeId, transactionLocalDate, currencyCode,
|
||||
transactionAmountValue, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientCommand detectChanges(final Long resourceIdentifier, final String baseJson, final String workingJson) {
|
||||
|
||||
@@ -794,20 +645,6 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
return new NoteCommand(noteId, clientId, note);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrencyCommand convertApiRequestJsonToCurrencyCommand(final String json) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
Set<String> supportedParams = new HashSet<String>(Arrays.asList("currencies"));
|
||||
|
||||
checkForUnsupportedParameters(requestMap, supportedParams);
|
||||
|
||||
return this.portfolioCommandDeserializerService.deserializeCurrencyCommand(json, false);
|
||||
}
|
||||
|
||||
private void checkForUnsupportedParameters(Map<String, ?> requestMap, Set<String> supportedParams) {
|
||||
List<String> unsupportedParameterList = new ArrayList<String>();
|
||||
for (String providedParameter : requestMap.keySet()) {
|
||||
|
||||
+1
-36
@@ -9,9 +9,7 @@ import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
|
||||
import org.mifosplatform.infrastructure.dataqueries.data.DatatableData;
|
||||
import org.mifosplatform.infrastructure.dataqueries.data.GenericResultsetData;
|
||||
import org.mifosplatform.infrastructure.documentmanagement.data.DocumentData;
|
||||
import org.mifosplatform.organisation.monetary.data.ConfigurationData;
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
import org.mifosplatform.organisation.office.data.OfficeTransactionData;
|
||||
import org.mifosplatform.infrastructure.security.data.AuthenticatedUserData;
|
||||
import org.mifosplatform.organisation.staff.data.BulkTransferLoanOfficerData;
|
||||
import org.mifosplatform.organisation.staff.data.StaffData;
|
||||
import org.mifosplatform.portfolio.charge.data.ChargeData;
|
||||
@@ -19,7 +17,6 @@ import org.mifosplatform.portfolio.client.data.ClientAccountSummaryCollectionDat
|
||||
import org.mifosplatform.portfolio.client.data.ClientData;
|
||||
import org.mifosplatform.portfolio.client.data.ClientIdentifierData;
|
||||
import org.mifosplatform.portfolio.client.data.NoteData;
|
||||
import org.mifosplatform.portfolio.fund.data.FundData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupAccountSummaryCollectionData;
|
||||
import org.mifosplatform.portfolio.group.data.GroupData;
|
||||
import org.mifosplatform.portfolio.loanaccount.data.LoanAccountData;
|
||||
@@ -33,11 +30,6 @@ import org.mifosplatform.portfolio.savingsaccount.data.SavingScheduleData;
|
||||
import org.mifosplatform.portfolio.savingsaccountproduct.data.SavingProductData;
|
||||
import org.mifosplatform.portfolio.savingsdepositaccount.data.DepositAccountData;
|
||||
import org.mifosplatform.portfolio.savingsdepositproduct.data.DepositProductData;
|
||||
import org.mifosplatform.useradministration.data.AppUserData;
|
||||
import org.mifosplatform.useradministration.data.AuthenticatedUserData;
|
||||
import org.mifosplatform.useradministration.data.PermissionUsageData;
|
||||
import org.mifosplatform.useradministration.data.RoleData;
|
||||
import org.mifosplatform.useradministration.data.RolePermissionsData;
|
||||
|
||||
public interface PortfolioApiJsonSerializerService {
|
||||
|
||||
@@ -47,33 +39,6 @@ public interface PortfolioApiJsonSerializerService {
|
||||
|
||||
String serializeDatatableDataToJson(boolean prettyPrint, Collection<DatatableData> result);
|
||||
|
||||
String serializePermissionDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<PermissionUsageData> permissions);
|
||||
|
||||
String serializeRoleDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<RoleData> roles);
|
||||
|
||||
String serializeRoleDataToJson(boolean prettyPrint, Set<String> responseParameters, RoleData role);
|
||||
|
||||
String serializeRolePermissionDataToJson(boolean prettyPrint, Set<String> responseParameters, RolePermissionsData rolePermissionData);
|
||||
|
||||
String serializeAppUserDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<AppUserData> users);
|
||||
|
||||
String serializeAppUserDataToJson(boolean prettyPrint, Set<String> responseParameters, AppUserData user);
|
||||
|
||||
String serializeOfficeDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<OfficeData> offices);
|
||||
|
||||
String serializeOfficeDataToJson(boolean prettyPrint, Set<String> responseParameters, OfficeData office);
|
||||
|
||||
String serializeOfficeTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters,
|
||||
Collection<OfficeTransactionData> officeTransactions);
|
||||
|
||||
String serializeOfficeTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, OfficeTransactionData officeTransaction);
|
||||
|
||||
String serializeConfigurationDataToJson(boolean prettyPrint, Set<String> responseParameters, ConfigurationData configuration);
|
||||
|
||||
String serializeFundDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<FundData> funds);
|
||||
|
||||
String serializeFundDataToJson(boolean prettyPrint, Set<String> responseParameters, FundData fund);
|
||||
|
||||
String serializeLoanProductDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<LoanProductData> products);
|
||||
|
||||
String serializeLoanProductDataToJson(boolean prettyPrint, Set<String> responseParameters, LoanProductData loanProduct);
|
||||
|
||||
-180
@@ -9,22 +9,12 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.JsonParserHelper;
|
||||
import org.mifosplatform.organisation.monetary.command.CurrencyCommand;
|
||||
import org.mifosplatform.organisation.office.command.BranchMoneyTransferCommand;
|
||||
import org.mifosplatform.organisation.office.command.OfficeCommand;
|
||||
import org.mifosplatform.organisation.staff.command.StaffCommand;
|
||||
import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
|
||||
import org.mifosplatform.portfolio.client.command.ClientCommand;
|
||||
import org.mifosplatform.portfolio.client.command.ClientIdentifierCommand;
|
||||
import org.mifosplatform.portfolio.fund.command.FundCommand;
|
||||
import org.mifosplatform.portfolio.loanproduct.command.LoanProductCommand;
|
||||
import org.mifosplatform.useradministration.command.PermissionsCommand;
|
||||
import org.mifosplatform.useradministration.command.RoleCommand;
|
||||
import org.mifosplatform.useradministration.command.RolePermissionCommand;
|
||||
import org.mifosplatform.useradministration.command.UserCommand;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -39,179 +29,9 @@ import com.google.gson.JsonParser;
|
||||
public class PortfolioCommandDeerializerServiceGoogleGson implements PortfolioCommandDeserializerService {
|
||||
|
||||
private final JsonParser parser;
|
||||
private final Gson gsonConverter;
|
||||
|
||||
public PortfolioCommandDeerializerServiceGoogleGson() {
|
||||
parser = new JsonParser();
|
||||
gsonConverter = new Gson();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleCommand deserializeRoleCommand(final Long roleId, final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final JsonParserHelper helper = new JsonParserHelper();
|
||||
final JsonElement element = parser.parse(commandAsJson);
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final String name = helper.extractStringNamed("name", element, parametersPassedInRequest);
|
||||
final String description = helper.extractStringNamed("description", element, parametersPassedInRequest);
|
||||
|
||||
return new RoleCommand(parametersPassedInRequest, makerCheckerApproval, roleId, name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolePermissionCommand deserializeRolePermissionCommand(final Long roleId, final String commandAsJson,
|
||||
final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final RolePermissionCommand command = gsonConverter.fromJson(commandAsJson, RolePermissionCommand.class);
|
||||
|
||||
return new RolePermissionCommand(roleId, command.getPermissions(), makerCheckerApproval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsCommand deserializePermissionsCommand(final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final PermissionsCommand command = gsonConverter.fromJson(commandAsJson, PermissionsCommand.class);
|
||||
|
||||
return new PermissionsCommand(command.getPermissions(), makerCheckerApproval);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserCommand deserializeUserCommand(final Long userId, final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final JsonParserHelper helper = new JsonParserHelper();
|
||||
final JsonElement element = parser.parse(commandAsJson);
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final String username = helper.extractStringNamed("username", element, parametersPassedInRequest);
|
||||
final String firstname = helper.extractStringNamed("firstname", element, parametersPassedInRequest);
|
||||
|
||||
final String lastname = helper.extractStringNamed("lastname", element, parametersPassedInRequest);
|
||||
final String password = helper.extractStringNamed("password", element, parametersPassedInRequest);
|
||||
final String repeatPassword = helper.extractStringNamed("repeatPassword", element, parametersPassedInRequest);
|
||||
final String email = helper.extractStringNamed("email", element, parametersPassedInRequest);
|
||||
final Long officeId = helper.extractLongNamed("officeId", element, parametersPassedInRequest);
|
||||
|
||||
// check array
|
||||
String[] notSelectedRoles = null;
|
||||
String[] roles = null;
|
||||
if (element.isJsonObject()) {
|
||||
JsonObject object = element.getAsJsonObject();
|
||||
if (object.has("notSelectedRoles")) {
|
||||
parametersPassedInRequest.add("notSelectedRoles");
|
||||
JsonArray array = object.get("notSelectedRoles").getAsJsonArray();
|
||||
notSelectedRoles = new String[array.size()];
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
notSelectedRoles[i] = array.get(i).getAsString();
|
||||
}
|
||||
}
|
||||
|
||||
if (object.has("roles")) {
|
||||
parametersPassedInRequest.add("roles");
|
||||
JsonArray array = object.get("roles").getAsJsonArray();
|
||||
roles = new String[array.size()];
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
roles[i] = array.get(i).getAsString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new UserCommand(parametersPassedInRequest, makerCheckerApproval, userId, username, firstname, lastname, password,
|
||||
repeatPassword, email, officeId, notSelectedRoles, roles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaffCommand deserializeStaffCommand(final Long staffId, final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final JsonParserHelper helper = new JsonParserHelper();
|
||||
final JsonElement element = parser.parse(commandAsJson);
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final String firstname = helper.extractStringNamed("firstname", element, parametersPassedInRequest);
|
||||
final String lastname = helper.extractStringNamed("lastname", element, parametersPassedInRequest);
|
||||
final Boolean isLoanOfficer = helper.extractBooleanNamed("isLoanOfficer", element, parametersPassedInRequest);
|
||||
final Long officeId = helper.extractLongNamed("officeId", element, parametersPassedInRequest);
|
||||
|
||||
return new StaffCommand(parametersPassedInRequest, makerCheckerApproval, staffId, officeId, firstname, lastname, isLoanOfficer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FundCommand deserializeFundCommand(final Long fundId, final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final JsonParserHelper helper = new JsonParserHelper();
|
||||
final JsonElement element = parser.parse(commandAsJson);
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final String name = helper.extractStringNamed("name", element, parametersPassedInRequest);
|
||||
final String externalId = helper.extractStringNamed("externalId", element, parametersPassedInRequest);
|
||||
|
||||
return new FundCommand(parametersPassedInRequest, makerCheckerApproval, fundId, name, externalId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeCommand deserializeOfficeCommand(final Long officeId, final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final JsonParserHelper helper = new JsonParserHelper();
|
||||
final JsonElement element = parser.parse(commandAsJson);
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final String name = helper.extractStringNamed("name", element, parametersPassedInRequest);
|
||||
final String externalId = helper.extractStringNamed("externalId", element, parametersPassedInRequest);
|
||||
final Long parentId = helper.extractLongNamed("parentId", element, parametersPassedInRequest);
|
||||
final LocalDate openingLocalDate = helper.extractLocalDateAsArrayNamed("openingDate", element, parametersPassedInRequest);
|
||||
|
||||
return new OfficeCommand(parametersPassedInRequest, makerCheckerApproval, officeId, name, externalId, parentId, openingLocalDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchMoneyTransferCommand deserializeOfficeTransactionCommand(final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final JsonParserHelper helper = new JsonParserHelper();
|
||||
final JsonElement element = parser.parse(commandAsJson);
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final Long fromOfficeId = helper.extractLongNamed("fromOfficeId", element, parametersPassedInRequest);
|
||||
final Long toOfficeId = helper.extractLongNamed("toOfficeId", element, parametersPassedInRequest);
|
||||
final LocalDate transactionLocalDate = helper.extractLocalDateAsArrayNamed("transactionDate", element, parametersPassedInRequest);
|
||||
final String currencyCode = helper.extractStringNamed("currencyCode", element, parametersPassedInRequest);
|
||||
final BigDecimal transactionAmount = helper.extractBigDecimalNamed("transactionAmount", element.getAsJsonObject(), Locale.US,
|
||||
parametersPassedInRequest);
|
||||
final String description = helper.extractStringNamed("description", element, parametersPassedInRequest);
|
||||
|
||||
return new BranchMoneyTransferCommand(parametersPassedInRequest, makerCheckerApproval, fromOfficeId, toOfficeId,
|
||||
transactionLocalDate, currencyCode, transactionAmount, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrencyCommand deserializeCurrencyCommand(final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final JsonParserHelper helper = new JsonParserHelper();
|
||||
final JsonElement element = parser.parse(commandAsJson);
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final String[] currencies = helper.extractArrayNamed("currencies", element, parametersPassedInRequest);
|
||||
|
||||
return new CurrencyCommand(makerCheckerApproval, currencies);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-27
@@ -1,18 +1,9 @@
|
||||
package org.mifosplatform.infrastructure.core.api;
|
||||
|
||||
import org.mifosplatform.organisation.monetary.command.CurrencyCommand;
|
||||
import org.mifosplatform.organisation.office.command.BranchMoneyTransferCommand;
|
||||
import org.mifosplatform.organisation.office.command.OfficeCommand;
|
||||
import org.mifosplatform.organisation.staff.command.StaffCommand;
|
||||
import org.mifosplatform.portfolio.charge.command.ChargeDefinitionCommand;
|
||||
import org.mifosplatform.portfolio.client.command.ClientCommand;
|
||||
import org.mifosplatform.portfolio.client.command.ClientIdentifierCommand;
|
||||
import org.mifosplatform.portfolio.fund.command.FundCommand;
|
||||
import org.mifosplatform.portfolio.loanproduct.command.LoanProductCommand;
|
||||
import org.mifosplatform.useradministration.command.PermissionsCommand;
|
||||
import org.mifosplatform.useradministration.command.RoleCommand;
|
||||
import org.mifosplatform.useradministration.command.RolePermissionCommand;
|
||||
import org.mifosplatform.useradministration.command.UserCommand;
|
||||
|
||||
/**
|
||||
* Service for de-serializing JSON for a command into the platforms internal
|
||||
@@ -26,24 +17,6 @@ import org.mifosplatform.useradministration.command.UserCommand;
|
||||
*/
|
||||
public interface PortfolioCommandDeserializerService {
|
||||
|
||||
RoleCommand deserializeRoleCommand(Long roleId, String commandAsJson, boolean makerCheckerApproval);
|
||||
|
||||
RolePermissionCommand deserializeRolePermissionCommand(Long roleId, String commandAsJson, boolean makerCheckerApproval);
|
||||
|
||||
PermissionsCommand deserializePermissionsCommand(String commandAsJson, boolean makerCheckerApproval);
|
||||
|
||||
UserCommand deserializeUserCommand(Long userId, String commandAsJson, boolean makerCheckerApproval);
|
||||
|
||||
StaffCommand deserializeStaffCommand(Long staffId, String commandAsJson, boolean makerCheckerApproval);
|
||||
|
||||
FundCommand deserializeFundCommand(Long fundId, String commandAsJson, boolean makerCheckerApproval);
|
||||
|
||||
OfficeCommand deserializeOfficeCommand(Long officeId, String commandAsJson, boolean makerCheckerApproval);
|
||||
|
||||
BranchMoneyTransferCommand deserializeOfficeTransactionCommand(String commandAsJson, boolean makerCheckerApproval);
|
||||
|
||||
CurrencyCommand deserializeCurrencyCommand(String commandAsJson, boolean makerCheckerApproval);
|
||||
|
||||
ChargeDefinitionCommand deserializeChargeDefinitionCommand(Long chargeDefinitionId, String commandAsJson, boolean makerCheckerApproval);
|
||||
|
||||
ClientCommand deserializeClientCommand(Long clientId, String commandAsJson, boolean makerCheckerApproval);
|
||||
|
||||
+27
-3
@@ -10,24 +10,44 @@ public class ApiRequestJsonSerializationSettings {
|
||||
|
||||
private final boolean prettyPrint;
|
||||
private final Set<String> parametersForPartialResponse;
|
||||
private final boolean template;
|
||||
private final Long commandId;
|
||||
private final boolean makerCheckerable;
|
||||
|
||||
public ApiRequestJsonSerializationSettings(final boolean prettyPrint, final Set<String> parametersForPartialResponse) {
|
||||
public ApiRequestJsonSerializationSettings(final boolean prettyPrint, final Set<String> parametersForPartialResponse,
|
||||
final boolean template, final Long commandId, final boolean makerCheckerable) {
|
||||
this.prettyPrint = prettyPrint;
|
||||
this.parametersForPartialResponse = parametersForPartialResponse;
|
||||
this.template = template;
|
||||
this.commandId = commandId;
|
||||
this.makerCheckerable = makerCheckerable;
|
||||
}
|
||||
|
||||
public static ApiRequestJsonSerializationSettings from(final boolean prettyPrint, final Set<String> parametersForPartialResponse) {
|
||||
public static ApiRequestJsonSerializationSettings from(final boolean prettyPrint, final Set<String> parametersForPartialResponse,
|
||||
final boolean template, final Long commandId, final boolean makerCheckerable) {
|
||||
|
||||
// FIXME - kw - rather than always creating new objects for this could
|
||||
// just send by common ones like, prettyprint=false, empty response
|
||||
// parameters
|
||||
return new ApiRequestJsonSerializationSettings(prettyPrint, parametersForPartialResponse);
|
||||
return new ApiRequestJsonSerializationSettings(prettyPrint, parametersForPartialResponse, template, commandId, makerCheckerable);
|
||||
}
|
||||
|
||||
public boolean isPrettyPrint() {
|
||||
return this.prettyPrint;
|
||||
}
|
||||
|
||||
public boolean isTemplate() {
|
||||
return this.template;
|
||||
}
|
||||
|
||||
public boolean isMakerCheckerable() {
|
||||
return this.makerCheckerable;
|
||||
}
|
||||
|
||||
public Long getCommandId() {
|
||||
return this.commandId;
|
||||
}
|
||||
|
||||
public Set<String> getParametersForPartialResponse() {
|
||||
return this.parametersForPartialResponse;
|
||||
}
|
||||
@@ -35,4 +55,8 @@ public class ApiRequestJsonSerializationSettings {
|
||||
public boolean isPartialResponseRequired() {
|
||||
return !this.parametersForPartialResponse.isEmpty();
|
||||
}
|
||||
|
||||
public boolean isCommandIdPassed() {
|
||||
return this.commandId != null;
|
||||
}
|
||||
}
|
||||
+15
-1
@@ -48,7 +48,21 @@ public final class DefaultToApiJsonSerializer<T> implements ToApiJsonSerializer<
|
||||
return serializeWithSettings(delegatedSerializer, settings, singleObject);
|
||||
}
|
||||
|
||||
private String serializeWithSettings(final Gson gson, final ApiRequestJsonSerializationSettings settings, final Object... dataObject) {
|
||||
private String serializeWithSettings(final Gson gson, final ApiRequestJsonSerializationSettings settings, final Object[] dataObject) {
|
||||
String json = null;
|
||||
if (gson != null) {
|
||||
json = helper.serializedJsonFrom(gson, dataObject);
|
||||
} else {
|
||||
if (settings.isPrettyPrint()) {
|
||||
json = this.excludeNothingWithPrettyPrintingOn.serialize(dataObject);
|
||||
} else {
|
||||
json = serialize(dataObject);
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
private String serializeWithSettings(final Gson gson, final ApiRequestJsonSerializationSettings settings, final Object dataObject) {
|
||||
String json = null;
|
||||
if (gson != null) {
|
||||
json = helper.serializedJsonFrom(gson, dataObject);
|
||||
|
||||
+46
-3
@@ -1,12 +1,15 @@
|
||||
package org.mifosplatform.infrastructure.core.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.exception.UnsupportedParameterException;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -21,18 +24,26 @@ public class FromJsonHelper {
|
||||
private final Gson gsonConverter;
|
||||
private final JsonParserHelper helperDelegator;
|
||||
private final JsonParser parser;
|
||||
|
||||
|
||||
public FromJsonHelper() {
|
||||
this.gsonConverter = new Gson();
|
||||
helperDelegator = new JsonParserHelper();
|
||||
parser = new JsonParser();
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Boolean> extractMap(final Type typeOfMap, final String json) {
|
||||
return this.gsonConverter.fromJson(json, typeOfMap);
|
||||
}
|
||||
|
||||
public <T> T fromJson(final String json, Class<T> classOfT) {
|
||||
return this.gsonConverter.fromJson(json, classOfT);
|
||||
}
|
||||
|
||||
public void checkForUnsupportedParameters(final Type typeOfMap, final String json, final Set<String> supportedParams) {
|
||||
if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
|
||||
|
||||
|
||||
List<String> unsupportedParameterList = new ArrayList<String>();
|
||||
for (String providedParameter : requestMap.keySet()) {
|
||||
if (!supportedParams.contains(providedParameter)) {
|
||||
@@ -50,4 +61,36 @@ public class FromJsonHelper {
|
||||
public String extractStringNamed(final String parameterName, final JsonElement element, final Set<String> parametersPassedInRequest) {
|
||||
return helperDelegator.extractStringNamed(parameterName, element, parametersPassedInRequest);
|
||||
}
|
||||
|
||||
public Long extractLongNamed(final String parameterName, final JsonElement element, final Set<String> parametersPassedInRequest) {
|
||||
return helperDelegator.extractLongNamed(parameterName, element, parametersPassedInRequest);
|
||||
}
|
||||
|
||||
public String[] extractArrayNamed(final String parameterName, final JsonElement element, final Set<String> parametersPassedInRequest) {
|
||||
return helperDelegator.extractArrayNamed(parameterName, element, parametersPassedInRequest);
|
||||
}
|
||||
|
||||
public Boolean extractBooleanNamed(final String parameterName, final JsonElement element, final Set<String> parametersPassedInRequest) {
|
||||
return helperDelegator.extractBooleanNamed(parameterName, element, parametersPassedInRequest);
|
||||
}
|
||||
|
||||
public LocalDate extractLocalDateNamed(final String parameterName, final JsonElement element,
|
||||
final Set<String> parametersPassedInRequest) {
|
||||
return helperDelegator.extractLocalDateNamed(parameterName, element, parametersPassedInRequest);
|
||||
}
|
||||
|
||||
public LocalDate extractLocalDateAsArrayNamed(final String parameterName, final JsonElement element,
|
||||
final Set<String> parametersPassedInRequest) {
|
||||
return helperDelegator.extractLocalDateAsArrayNamed(parameterName, element, parametersPassedInRequest);
|
||||
}
|
||||
|
||||
public BigDecimal extractBigDecimalWithLocaleNamed(final String parameterName, final JsonElement element,
|
||||
final Set<String> parametersPassedInRequest) {
|
||||
return helperDelegator.extractBigDecimalWithLocaleNamed(parameterName, element, parametersPassedInRequest);
|
||||
}
|
||||
|
||||
public BigDecimal extractBigDecimalNamed(final String parameterName, final JsonElement element,
|
||||
final Set<String> parametersPassedInRequest) {
|
||||
return helperDelegator.extractBigDecimalNamed(parameterName, element.getAsJsonObject(), Locale.US, parametersPassedInRequest);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.useradministration.api;
|
||||
package org.mifosplatform.infrastructure.security.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -11,7 +11,7 @@ import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
|
||||
import org.mifosplatform.useradministration.data.AuthenticatedUserData;
|
||||
import org.mifosplatform.infrastructure.security.data.AuthenticatedUserData;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.mifosplatform.useradministration.data;
|
||||
package org.mifosplatform.infrastructure.security.data;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
+24
-26
@@ -1,6 +1,7 @@
|
||||
package org.mifosplatform.organisation.monetary.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -14,14 +15,13 @@ import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.monetary.command.CurrencyCommand;
|
||||
import org.mifosplatform.organisation.monetary.data.ConfigurationData;
|
||||
import org.mifosplatform.organisation.monetary.serialization.CurrencyCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.organisation.monetary.service.OrganisationCurrencyReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -31,28 +31,29 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class CurrenciesApiResource {
|
||||
|
||||
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("selectedCurrencyOptions", "currencyOptions"));
|
||||
|
||||
private final String resourceNameForPermissions = "CURRENCY";
|
||||
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final OrganisationCurrencyReadPlatformService readPlatformService;
|
||||
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
private final PortfolioApiDataConversionService apiDataConversionService;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
private final CurrencyCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||
private final DefaultToApiJsonSerializer<ConfigurationData> toApiJsonSerializer;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public CurrenciesApiResource(final PlatformSecurityContext context,
|
||||
final OrganisationCurrencyReadPlatformService readPlatformService,
|
||||
final PortfolioApiJsonSerializerService apiJsonSerializerService,
|
||||
final PortfolioApiDataConversionService apiDataConversionService,
|
||||
final CommandSerializer commandSerializerService,
|
||||
public CurrenciesApiResource(final PlatformSecurityContext context, final OrganisationCurrencyReadPlatformService readPlatformService,
|
||||
final CurrencyCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||
final DefaultToApiJsonSerializer<ConfigurationData> toApiJsonSerializer,
|
||||
final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.context = context;
|
||||
this.readPlatformService = readPlatformService;
|
||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||
this.apiDataConversionService = apiDataConversionService;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||
}
|
||||
|
||||
@@ -63,12 +64,10 @@ public class CurrenciesApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final ConfigurationData configurationData = this.readPlatformService.retrieveCurrencyConfiguration();
|
||||
|
||||
return this.apiJsonSerializerService.serializeConfigurationDataToJson(prettyPrint, responseParameters, configurationData);
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, configurationData, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@@ -79,12 +78,11 @@ public class CurrenciesApiResource {
|
||||
final List<String> 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 String commandSerializedAsJson = this.fromApiJsonDeserializer.serializedCommandJsonFromApiJson(apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "currencies", null,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package org.mifosplatform.organisation.monetary.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.organisation.monetary.command.CurrencyCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for {@link CurrencyCommand}
|
||||
* 's.
|
||||
*/
|
||||
@Component
|
||||
public final class CurrencyCommandFromApiJsonDeserializer implements FromApiJsonDeserializer<CurrencyCommand> {
|
||||
|
||||
/**
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("currencies"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
private final CurrencyCommandFromCommandJsonDeserializer commandFromCommandJsonDeserializer;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
|
||||
@Autowired
|
||||
public CurrencyCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper,
|
||||
final CurrencyCommandFromCommandJsonDeserializer commandFromCommandJsonDeserializer,
|
||||
final CommandSerializer commandSerializerService) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
this.commandFromCommandJsonDeserializer = commandFromCommandJsonDeserializer;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrencyCommand commandFromApiJson(final String json) {
|
||||
return commandFromApiJson(null, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrencyCommand commandFromApiJson(final Long resourceId, final String json) {
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
return this.commandFromCommandJsonDeserializer.commandFromCommandJson(resourceId, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final String json) {
|
||||
final CurrencyCommand command = commandFromApiJson(json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final Long roleId, final String json) {
|
||||
final CurrencyCommand command = commandFromApiJson(roleId, json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package org.mifosplatform.organisation.monetary.serialization;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromCommandJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.organisation.monetary.command.CurrencyCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
@Component
|
||||
public final class CurrencyCommandFromCommandJsonDeserializer implements FromCommandJsonDeserializer<CurrencyCommand> {
|
||||
|
||||
private final FromJsonHelper fromJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public CurrencyCommandFromCommandJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrencyCommand commandFromCommandJson(final String commandAsJson) {
|
||||
return commandFromCommandJson(null, commandAsJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrencyCommand commandFromCommandJson(final Long resourceId, final String commandAsJson) {
|
||||
return commandFromCommandJson(resourceId, commandAsJson, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrencyCommand commandFromCommandJson(@SuppressWarnings("unused") final Long resourceId, final String commandAsJson,
|
||||
final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final JsonElement element = fromJsonHelper.parse(commandAsJson);
|
||||
final String[] currencies = fromJsonHelper.extractArrayNamed("currencies", element, parametersPassedInRequest);
|
||||
return new CurrencyCommand(makerCheckerApproval, currencies);
|
||||
}
|
||||
}
|
||||
+33
-33
@@ -2,6 +2,7 @@ package org.mifosplatform.organisation.office.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -15,14 +16,13 @@ import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.office.command.BranchMoneyTransferCommand;
|
||||
import org.mifosplatform.organisation.office.data.OfficeTransactionData;
|
||||
import org.mifosplatform.organisation.office.serialization.BranchMoneyTransferCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -32,29 +32,32 @@ import org.springframework.stereotype.Component;
|
||||
@Component
|
||||
@Scope("singleton")
|
||||
public class OfficeTransactionsApiResource {
|
||||
|
||||
|
||||
private static final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "transactionDate", "fromOfficeId",
|
||||
"fromOfficeName", "toOfficeId", "toOfficeIdName", "currencyCode", "digitsAfterDecimal", "transactionAmount", "description",
|
||||
"allowedOffices", "currencyOptions"));
|
||||
|
||||
private final String resourceNameForReadPermissions = "OFFICE";
|
||||
private final String resourceNameForPermissions = "OFFICETRANSACTION";
|
||||
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final OfficeReadPlatformService readPlatformService;
|
||||
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
private final PortfolioApiDataConversionService apiDataConversionService;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
private final BranchMoneyTransferCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||
private final DefaultToApiJsonSerializer<OfficeTransactionData> toApiJsonSerializer;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public OfficeTransactionsApiResource(final PlatformSecurityContext context,
|
||||
final OfficeReadPlatformService readPlatformService,
|
||||
final PortfolioApiJsonSerializerService apiJsonSerializerService,
|
||||
final PortfolioApiDataConversionService apiDataConversionService,
|
||||
final CommandSerializer commandSerializerService,
|
||||
public OfficeTransactionsApiResource(final PlatformSecurityContext context, final OfficeReadPlatformService readPlatformService,
|
||||
final BranchMoneyTransferCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||
final DefaultToApiJsonSerializer<OfficeTransactionData> toApiJsonSerializer,
|
||||
final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.context = context;
|
||||
this.readPlatformService = readPlatformService;
|
||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||
this.apiDataConversionService = apiDataConversionService;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||
}
|
||||
|
||||
@@ -65,12 +68,10 @@ public class OfficeTransactionsApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForReadPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final Collection<OfficeTransactionData> officeTransactions = this.readPlatformService.retrieveAllOfficeTransactions();
|
||||
|
||||
return this.apiJsonSerializerService.serializeOfficeTransactionDataToJson(prettyPrint, responseParameters, officeTransactions);
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, officeTransactions, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -81,12 +82,10 @@ public class OfficeTransactionsApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForReadPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final OfficeTransactionData officeTransactionData = this.readPlatformService.retrieveNewOfficeTransactionDetails();
|
||||
|
||||
return this.apiJsonSerializerService.serializeOfficeTransactionDataToJson(prettyPrint, responseParameters, officeTransactionData);
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, officeTransactionData, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -95,18 +94,19 @@ public class OfficeTransactionsApiResource {
|
||||
public String transferMoneyFrom(final String apiRequestBodyAsJson) {
|
||||
|
||||
// TODO - complete permissions for office transactions when more
|
||||
// functionality add or it is replaced by simple accounting equivalent (JPW)
|
||||
// functionality add or it is replaced by simple accounting equivalent
|
||||
// (JPW)
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "ORGANISATION_ADMINISTRATION_SUPER_USER", "CREATE_OFFICETRANSACTION");
|
||||
|
||||
final List<String> 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 String commandSerializedAsJson = this.fromApiJsonDeserializer.serializedCommandJsonFromApiJson(apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "officetransactions", null,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
}
|
||||
+36
-39
@@ -3,6 +3,7 @@ package org.mifosplatform.organisation.office.api;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -18,15 +19,15 @@ import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
|
||||
import org.mifosplatform.infrastructure.codes.data.CodeData;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.office.command.OfficeCommand;
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
import org.mifosplatform.organisation.office.data.OfficeLookup;
|
||||
import org.mifosplatform.organisation.office.serialization.OfficeCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -37,27 +38,31 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("singleton")
|
||||
public class OfficesApiResource {
|
||||
|
||||
/**
|
||||
* The set of parameters that are supported in response for {@link CodeData}
|
||||
*/
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "nameDecorated", "externalId",
|
||||
"openingDate", "hierarchy", "parentId", "parentName", "allowedParents"));
|
||||
|
||||
private final String resourceNameForPermissions = "OFFICE";
|
||||
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final OfficeReadPlatformService readPlatformService;
|
||||
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
private final PortfolioApiDataConversionService apiDataConversionService;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
private final OfficeCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||
private final DefaultToApiJsonSerializer<OfficeData> toApiJsonSerializer;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public OfficesApiResource(final PlatformSecurityContext context,
|
||||
final OfficeReadPlatformService readPlatformService,
|
||||
final PortfolioApiJsonSerializerService apiJsonSerializerService,
|
||||
final PortfolioApiDataConversionService apiDataConversionService,
|
||||
final CommandSerializer commandSerializerService,
|
||||
public OfficesApiResource(final PlatformSecurityContext context, final OfficeReadPlatformService readPlatformService,
|
||||
final OfficeCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||
final DefaultToApiJsonSerializer<OfficeData> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.context = context;
|
||||
this.readPlatformService = readPlatformService;
|
||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||
this.apiDataConversionService = apiDataConversionService;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||
}
|
||||
|
||||
@@ -68,12 +73,10 @@ public class OfficesApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final Collection<OfficeData> offices = this.readPlatformService.retrieveAllOffices();
|
||||
|
||||
return this.apiJsonSerializerService.serializeOfficeDataToJson(prettyPrint, responseParameters, offices);
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, offices, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -83,16 +86,14 @@ public class OfficesApiResource {
|
||||
public String retrieveOfficeTemplate(@Context final UriInfo uriInfo) {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
OfficeData office = this.readPlatformService.retrieveNewOfficeTemplate();
|
||||
|
||||
|
||||
final List<OfficeLookup> allowedParents = new ArrayList<OfficeLookup>(this.readPlatformService.retrieveAllOfficesForLookup());
|
||||
office = OfficeData.appendedTemplate(office, allowedParents);
|
||||
|
||||
return this.apiJsonSerializerService.serializeOfficeDataToJson(prettyPrint, responseParameters, office);
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, office, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -103,13 +104,12 @@ public class OfficesApiResource {
|
||||
final List<String> 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 String commandSerializedAsJson = this.fromApiJsonDeserializer.serializedCommandJsonFromApiJson(apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "offices", null,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -120,17 +120,15 @@ public class OfficesApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
OfficeData office = this.readPlatformService.retrieveOffice(officeId);
|
||||
if (template) {
|
||||
if (settings.isTemplate()) {
|
||||
List<OfficeLookup> allowedParents = this.readPlatformService.retrieveAllowedParents(officeId);
|
||||
office = OfficeData.appendedTemplate(office, allowedParents);
|
||||
}
|
||||
|
||||
return this.apiJsonSerializerService.serializeOfficeDataToJson(prettyPrint, responseParameters, office);
|
||||
return this.toApiJsonSerializer.serialize(settings, office, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@@ -142,12 +140,11 @@ public class OfficesApiResource {
|
||||
final List<String> 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 String commandSerializedAsJson = this.fromApiJsonDeserializer.serializedCommandJsonFromApiJson(apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "offices", officeId,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
package org.mifosplatform.organisation.office.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.organisation.office.command.BranchMoneyTransferCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for
|
||||
* {@link BranchMoneyTransferCommand} 's.
|
||||
*/
|
||||
@Component
|
||||
public final class BranchMoneyTransferCommandFromApiJsonDeserializer implements FromApiJsonDeserializer<BranchMoneyTransferCommand> {
|
||||
|
||||
/**
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("fromOfficeId", "toOfficeId", "transactionDate",
|
||||
"currencyCode", "transactionAmount", "description", "locale", "dateFormat"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
|
||||
@Autowired
|
||||
public BranchMoneyTransferCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper,
|
||||
final CommandSerializer commandSerializerService) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchMoneyTransferCommand commandFromApiJson(final String json) {
|
||||
return commandFromApiJson(null, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchMoneyTransferCommand commandFromApiJson(@SuppressWarnings("unused") final Long resourceId, final String json) {
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||
final Long fromOfficeId = fromApiJsonHelper.extractLongNamed("fromOfficeId", element, parametersPassedInRequest);
|
||||
final Long toOfficeId = fromApiJsonHelper.extractLongNamed("toOfficeId", element, parametersPassedInRequest);
|
||||
final LocalDate transactionLocalDate = fromApiJsonHelper.extractLocalDateNamed("transactionDate", element,
|
||||
parametersPassedInRequest);
|
||||
|
||||
final String currencyCode = fromApiJsonHelper.extractStringNamed("currencyCode", element, parametersPassedInRequest);
|
||||
final BigDecimal transactionAmountValue = fromApiJsonHelper.extractBigDecimalWithLocaleNamed("transactionAmount", element,
|
||||
parametersPassedInRequest);
|
||||
final String description = fromApiJsonHelper.extractStringNamed("description", element, parametersPassedInRequest);
|
||||
|
||||
return new BranchMoneyTransferCommand(parametersPassedInRequest, false, fromOfficeId, toOfficeId, transactionLocalDate,
|
||||
currencyCode, transactionAmountValue, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final String json) {
|
||||
final BranchMoneyTransferCommand command = commandFromApiJson(json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final Long roleId, final String json) {
|
||||
final BranchMoneyTransferCommand command = commandFromApiJson(roleId, json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package org.mifosplatform.organisation.office.serialization;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromCommandJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.organisation.office.command.BranchMoneyTransferCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
@Component
|
||||
public final class BranchMoneyTransferCommandFromCommandJsonDeserializer implements FromCommandJsonDeserializer<BranchMoneyTransferCommand> {
|
||||
|
||||
private final FromJsonHelper fromJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public BranchMoneyTransferCommandFromCommandJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchMoneyTransferCommand commandFromCommandJson(final String commandAsJson) {
|
||||
return commandFromCommandJson(null, commandAsJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchMoneyTransferCommand commandFromCommandJson(final Long resourceId, final String commandAsJson) {
|
||||
return commandFromCommandJson(resourceId, commandAsJson, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BranchMoneyTransferCommand commandFromCommandJson(@SuppressWarnings("unused") final Long resourceId, final String commandAsJson,
|
||||
final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final JsonElement element = fromJsonHelper.parse(commandAsJson);
|
||||
final Long fromOfficeId = fromJsonHelper.extractLongNamed("fromOfficeId", element, parametersPassedInRequest);
|
||||
final Long toOfficeId = fromJsonHelper.extractLongNamed("toOfficeId", element, parametersPassedInRequest);
|
||||
final LocalDate transactionLocalDate = fromJsonHelper.extractLocalDateAsArrayNamed("transactionDate", element, parametersPassedInRequest);
|
||||
final String currencyCode = fromJsonHelper.extractStringNamed("currencyCode", element, parametersPassedInRequest);
|
||||
final BigDecimal transactionAmountValue = fromJsonHelper.extractBigDecimalNamed("transactionAmount", element,
|
||||
parametersPassedInRequest);
|
||||
final String description = fromJsonHelper.extractStringNamed("description", element, parametersPassedInRequest);
|
||||
|
||||
return new BranchMoneyTransferCommand(parametersPassedInRequest, makerCheckerApproval, fromOfficeId, toOfficeId,
|
||||
transactionLocalDate, currencyCode, transactionAmountValue, description);
|
||||
}
|
||||
}
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package org.mifosplatform.organisation.office.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.organisation.office.command.OfficeCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for {@link OfficeCommand}
|
||||
* 's.
|
||||
*/
|
||||
@Component
|
||||
public final class OfficeCommandFromApiJsonDeserializer implements FromApiJsonDeserializer<OfficeCommand> {
|
||||
|
||||
/**
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("transactionDate", "fromOfficeId",
|
||||
"toOfficeId", "currencyCode", "transactionAmount", "description",
|
||||
"locale", "dateFormat"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
|
||||
@Autowired
|
||||
public OfficeCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper, final CommandSerializer commandSerializerService) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeCommand commandFromApiJson(final String json) {
|
||||
return commandFromApiJson(null, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeCommand commandFromApiJson(final Long officeId, final String json) {
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final JsonElement element = fromApiJsonHelper.parse(json);
|
||||
final String name = fromApiJsonHelper.extractStringNamed("name", element, parametersPassedInRequest);
|
||||
final String externalId = fromApiJsonHelper.extractStringNamed("externalId", element, parametersPassedInRequest);
|
||||
final Long parentId = fromApiJsonHelper.extractLongNamed("parentId", element, parametersPassedInRequest);
|
||||
final LocalDate openingLocalDate = fromApiJsonHelper.extractLocalDateNamed("openingDate", element, parametersPassedInRequest);
|
||||
|
||||
return new OfficeCommand(parametersPassedInRequest, false, officeId, name, externalId, parentId, openingLocalDate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final String json) {
|
||||
final OfficeCommand command = commandFromApiJson(json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final Long roleId, final String json) {
|
||||
final OfficeCommand command = commandFromApiJson(roleId, json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package org.mifosplatform.organisation.office.serialization;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromCommandJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.organisation.office.command.OfficeCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
@Component
|
||||
public final class OfficeCommandFromCommandJsonDeserializer implements FromCommandJsonDeserializer<OfficeCommand> {
|
||||
|
||||
private final FromJsonHelper fromJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public OfficeCommandFromCommandJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeCommand commandFromCommandJson(final String commandAsJson) {
|
||||
return commandFromCommandJson(null, commandAsJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeCommand commandFromCommandJson(final Long officeId, final String commandAsJson) {
|
||||
return commandFromCommandJson(officeId, commandAsJson, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeCommand commandFromCommandJson(final Long officeId, final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final JsonElement element = fromJsonHelper.parse(commandAsJson);
|
||||
|
||||
final String name = fromJsonHelper.extractStringNamed("name", element, parametersPassedInRequest);
|
||||
final String externalId = fromJsonHelper.extractStringNamed("externalId", element, parametersPassedInRequest);
|
||||
final Long parentId = fromJsonHelper.extractLongNamed("parentId", element, parametersPassedInRequest);
|
||||
final LocalDate openingLocalDate = fromJsonHelper.extractLocalDateAsArrayNamed("openingDate", element, parametersPassedInRequest);
|
||||
|
||||
return new OfficeCommand(parametersPassedInRequest, makerCheckerApproval, officeId, name, externalId, parentId, openingLocalDate);
|
||||
}
|
||||
}
|
||||
+29
-31
@@ -2,6 +2,7 @@ package org.mifosplatform.organisation.staff.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -19,16 +20,16 @@ import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
|
||||
import org.mifosplatform.infrastructure.codes.data.CodeData;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.office.data.OfficeLookup;
|
||||
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
|
||||
import org.mifosplatform.organisation.staff.command.StaffCommand;
|
||||
import org.mifosplatform.organisation.staff.data.StaffData;
|
||||
import org.mifosplatform.organisation.staff.serialization.StaffCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.organisation.staff.service.StaffReadPlatformService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -43,30 +44,33 @@ public class StaffApiResource {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(StaffApiResource.class);
|
||||
|
||||
/**
|
||||
* The set of parameters that are supported in response for {@link CodeData}
|
||||
*/
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "firstname", "lastname", "displayName",
|
||||
"officeId", "officeName", "loanOfficerFlag", "allowedOffices"));
|
||||
|
||||
private final String resourceNameForPermissions = "STAFF";
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final StaffReadPlatformService readPlatformService;
|
||||
private final OfficeReadPlatformService officeReadPlatformService;
|
||||
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
private final StaffCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||
private final DefaultToApiJsonSerializer<StaffData> toApiJsonSerializer;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
|
||||
private final PortfolioApiDataConversionService apiDataConversionService;
|
||||
|
||||
private final CommandSerializer commandSerializerService;
|
||||
|
||||
@Autowired
|
||||
public StaffApiResource(final PlatformSecurityContext context, final StaffReadPlatformService readPlatformService,
|
||||
final OfficeReadPlatformService officeReadPlatformService, final PortfolioApiJsonSerializerService apiJsonSerializerService,
|
||||
final PortfolioApiDataConversionService apiDataConversionService,
|
||||
final CommandSerializer commandSerializerService,
|
||||
final OfficeReadPlatformService officeReadPlatformService, final StaffCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||
final DefaultToApiJsonSerializer<StaffData> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.context = context;
|
||||
this.readPlatformService = readPlatformService;
|
||||
this.officeReadPlatformService = officeReadPlatformService;
|
||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||
this.apiDataConversionService = apiDataConversionService;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||
}
|
||||
|
||||
@@ -78,13 +82,11 @@ public class StaffApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final String extraCriteria = getStaffCriteria(sqlSearch, officeId);
|
||||
final Collection<StaffData> staff = this.readPlatformService.retrieveAllStaff(extraCriteria);
|
||||
|
||||
return this.apiJsonSerializerService.serializeStaffDataToJson(prettyPrint, responseParameters, staff);
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, staff, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -95,13 +97,12 @@ public class StaffApiResource {
|
||||
final List<String> 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 String commandSerializedAsJson = this.fromApiJsonDeserializer.serializedCommandJsonFromApiJson(apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "staff", null,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -112,17 +113,15 @@ public class StaffApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
StaffData staff = this.readPlatformService.retrieveStaff(staffId);
|
||||
if (template) {
|
||||
if (settings.isTemplate()) {
|
||||
final Collection<OfficeLookup> allowedOffices = officeReadPlatformService.retrieveAllOfficesForLookup();
|
||||
staff = StaffData.templateData(staff, allowedOffices);
|
||||
}
|
||||
|
||||
return this.apiJsonSerializerService.serializeStaffDataToJson(prettyPrint, responseParameters, staff);
|
||||
return this.toApiJsonSerializer.serialize(settings, staff, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@@ -134,13 +133,12 @@ public class StaffApiResource {
|
||||
final List<String> 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 String commandSerializedAsJson = this.fromApiJsonDeserializer.serializedCommandJsonFromApiJson(staffId, apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "staff", staffId,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
private String getStaffCriteria(final String sqlSearch, final Integer officeId) {
|
||||
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package org.mifosplatform.organisation.staff.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.organisation.staff.command.StaffCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for {@link StaffCommand}'s.
|
||||
*/
|
||||
@Component
|
||||
public final class StaffCommandFromApiJsonDeserializer implements FromApiJsonDeserializer<StaffCommand> {
|
||||
|
||||
/**
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("firstname", "lastname", "officeId", "isLoanOfficer"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
private final StaffCommandFromCommandJsonDeserializer fromCommandJsonDeserializer;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
|
||||
@Autowired
|
||||
public StaffCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper,
|
||||
final StaffCommandFromCommandJsonDeserializer fromCommandJsonDeserializer,
|
||||
final CommandSerializer commandSerializerService) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
this.fromCommandJsonDeserializer = fromCommandJsonDeserializer;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaffCommand commandFromApiJson(final String json) {
|
||||
return commandFromApiJson(null, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaffCommand commandFromApiJson(final Long roleId, final String json) {
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
return this.fromCommandJsonDeserializer.commandFromCommandJson(roleId, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final String json) {
|
||||
final StaffCommand command = commandFromApiJson(json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final Long roleId, final String json) {
|
||||
final StaffCommand command = commandFromApiJson(roleId, json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package org.mifosplatform.organisation.staff.serialization;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromCommandJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.organisation.staff.command.StaffCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
@Component
|
||||
public final class StaffCommandFromCommandJsonDeserializer implements FromCommandJsonDeserializer<StaffCommand> {
|
||||
|
||||
private final FromJsonHelper fromJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public StaffCommandFromCommandJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaffCommand commandFromCommandJson(final String commandAsJson) {
|
||||
return commandFromCommandJson(null, commandAsJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaffCommand commandFromCommandJson(final Long staffId, final String commandAsJson) {
|
||||
return commandFromCommandJson(staffId, commandAsJson, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StaffCommand commandFromCommandJson(final Long staffId, final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final JsonElement element = fromJsonHelper.parse(commandAsJson);
|
||||
|
||||
final String firstname = fromJsonHelper.extractStringNamed("firstname", element, parametersPassedInRequest);
|
||||
final String lastname = fromJsonHelper.extractStringNamed("lastname", element, parametersPassedInRequest);
|
||||
final Boolean isLoanOfficer = fromJsonHelper.extractBooleanNamed("isLoanOfficer", element, parametersPassedInRequest);
|
||||
final Long officeId = fromJsonHelper.extractLongNamed("officeId", element, parametersPassedInRequest);
|
||||
|
||||
return new StaffCommand(parametersPassedInRequest, makerCheckerApproval, staffId, officeId, firstname, lastname, isLoanOfficer);
|
||||
}
|
||||
}
|
||||
+27
-29
@@ -2,6 +2,7 @@ package org.mifosplatform.portfolio.fund.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -17,14 +18,14 @@ import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
|
||||
import org.mifosplatform.infrastructure.codes.data.CodeData;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
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.serialization.FundCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.portfolio.fund.service.FundReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -35,26 +36,30 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("singleton")
|
||||
public class FundsApiResource {
|
||||
|
||||
/**
|
||||
* The set of parameters that are supported in response for {@link CodeData}
|
||||
*/
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "externalId"));
|
||||
|
||||
private final String resourceNameForPermissions = "FUND";
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final FundReadPlatformService readPlatformService;
|
||||
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
private final PortfolioApiDataConversionService apiDataConversionService;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
private final FundCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||
private final DefaultToApiJsonSerializer<FundData> toApiJsonSerializer;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public FundsApiResource(final PlatformSecurityContext context, final FundReadPlatformService readPlatformService,
|
||||
final PortfolioApiJsonSerializerService apiJsonSerializerService,
|
||||
final PortfolioApiDataConversionService apiDataConversionService,
|
||||
final CommandSerializer commandSerializerService,
|
||||
final FundCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||
final DefaultToApiJsonSerializer<FundData> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.context = context;
|
||||
this.readPlatformService = readPlatformService;
|
||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||
this.apiDataConversionService = apiDataConversionService;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||
}
|
||||
|
||||
@@ -65,12 +70,10 @@ public class FundsApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final Collection<FundData> funds = this.readPlatformService.retrieveAllFunds();
|
||||
|
||||
return this.apiJsonSerializerService.serializeFundDataToJson(prettyPrint, responseParameters, funds);
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, funds, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -78,17 +81,15 @@ public class FundsApiResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String createFund(final String apiRequestBodyAsJson) {
|
||||
|
||||
// FIXME - permissions - is funds a portfolio concept?
|
||||
final List<String> 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 String commandSerializedAsJson = this.fromApiJsonDeserializer.serializedCommandJsonFromApiJson(apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "funds", null,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -99,12 +100,10 @@ public class FundsApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final FundData fund = this.readPlatformService.retrieveFund(fundId);
|
||||
|
||||
return this.apiJsonSerializerService.serializeFundDataToJson(prettyPrint, responseParameters, fund);
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, fund, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@@ -116,12 +115,11 @@ public class FundsApiResource {
|
||||
final List<String> 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 String commandSerializedAsJson = this.fromApiJsonDeserializer.serializedCommandJsonFromApiJson(apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "funds", fundId,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package org.mifosplatform.portfolio.fund.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.portfolio.fund.command.FundCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for {@link FundCommand}'s.
|
||||
*/
|
||||
@Component
|
||||
public final class FundCommandFromApiJsonDeserializer implements FromApiJsonDeserializer<FundCommand> {
|
||||
|
||||
/**
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("name", "externalId"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
private final FundCommandFromCommandJsonDeserializer fromCommandJsonDeserializer;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
|
||||
@Autowired
|
||||
public FundCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper,
|
||||
final FundCommandFromCommandJsonDeserializer fromCommandJsonDeserializer, final CommandSerializer commandSerializerService) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
this.fromCommandJsonDeserializer = fromCommandJsonDeserializer;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FundCommand commandFromApiJson(final String json) {
|
||||
return commandFromApiJson(null, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FundCommand commandFromApiJson(final Long roleId, final String json) {
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
return this.fromCommandJsonDeserializer.commandFromCommandJson(roleId, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final String json) {
|
||||
final FundCommand command = commandFromApiJson(json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final Long roleId, final String json) {
|
||||
final FundCommand command = commandFromApiJson(roleId, json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
package org.mifosplatform.portfolio.fund.serialization;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromCommandJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.portfolio.fund.command.FundCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
@Component
|
||||
public final class FundCommandFromCommandJsonDeserializer implements FromCommandJsonDeserializer<FundCommand> {
|
||||
|
||||
private final FromJsonHelper fromJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public FundCommandFromCommandJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FundCommand commandFromCommandJson(final String commandAsJson) {
|
||||
return commandFromCommandJson(null, commandAsJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FundCommand commandFromCommandJson(final Long fundId, final String commandAsJson) {
|
||||
return commandFromCommandJson(fundId, commandAsJson, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FundCommand commandFromCommandJson(final Long fundId, final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final JsonElement element = fromJsonHelper.parse(commandAsJson);
|
||||
|
||||
final String name = fromJsonHelper.extractStringNamed("name", element, parametersPassedInRequest);
|
||||
final String externalId = fromJsonHelper.extractStringNamed("externalId", element, parametersPassedInRequest);
|
||||
|
||||
return new FundCommand(parametersPassedInRequest, makerCheckerApproval, fundId, name, externalId);
|
||||
}
|
||||
}
|
||||
+27
-32
@@ -2,6 +2,7 @@ package org.mifosplatform.useradministration.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -15,14 +16,13 @@ import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.useradministration.command.PermissionsCommand;
|
||||
import org.mifosplatform.useradministration.data.PermissionUsageData;
|
||||
import org.mifosplatform.useradministration.serialization.PermissionsCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.useradministration.service.PermissionReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -33,28 +33,28 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("singleton")
|
||||
public class PermissionsApiResource {
|
||||
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("grouping", "code", "entityName", "actionName",
|
||||
"selected", "isMakerChecker"));
|
||||
private final String resourceNameForPermissions = "PERMISSION";
|
||||
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final PermissionReadPlatformService permissionReadPlatformService;
|
||||
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
private final PortfolioApiDataConversionService apiDataConversionService;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
private final PermissionsCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||
private final DefaultToApiJsonSerializer<PermissionUsageData> toApiJsonSerializer;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public PermissionsApiResource(
|
||||
final PlatformSecurityContext context,
|
||||
final PermissionReadPlatformService readPlatformService,
|
||||
final PortfolioApiJsonSerializerService apiJsonSerializerService,
|
||||
final PortfolioApiDataConversionService apiDataConversionService,
|
||||
final CommandSerializer commandSerializerService,
|
||||
public PermissionsApiResource(final PlatformSecurityContext context, final PermissionReadPlatformService readPlatformService,
|
||||
final PermissionsCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||
final DefaultToApiJsonSerializer<PermissionUsageData> toApiJsonSerializer,
|
||||
final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.context = context;
|
||||
this.permissionReadPlatformService = readPlatformService;
|
||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||
this.apiDataConversionService = apiDataConversionService;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||
}
|
||||
|
||||
@@ -65,19 +65,16 @@ public class PermissionsApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final boolean makerCheckerable = ApiParameterHelper.makerCheckerable(uriInfo.getQueryParameters());
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
Collection<PermissionUsageData> permissions = null;
|
||||
if (makerCheckerable) {
|
||||
if (settings.isMakerCheckerable()) {
|
||||
permissions = this.permissionReadPlatformService.retrieveAllMakerCheckerablePermissions();
|
||||
} else {
|
||||
permissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||
}
|
||||
|
||||
return this.apiJsonSerializerService.serializePermissionDataToJson(prettyPrint, responseParameters, permissions);
|
||||
return this.toApiJsonSerializer.serialize(settings, permissions, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@@ -85,16 +82,14 @@ public class PermissionsApiResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String updatePermissionsDetails(final String apiRequestBodyAsJson) {
|
||||
|
||||
// FIXME - kw/jw - reuse 'PERMISSIONS_ROLE' permission for now
|
||||
final List<String> 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 List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "UPDATE_PERMISSION");
|
||||
context.authenticatedUser().validateHasPermissionTo("UPDATE_PERMISSION", allowedPermissions);
|
||||
|
||||
final String commandSerializedAsJson = this.fromApiJsonDeserializer.serializedCommandJsonFromApiJson(apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "permissions", null,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
}
|
||||
+68
-62
@@ -3,6 +3,7 @@ package org.mifosplatform.useradministration.api;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -20,18 +21,19 @@ import javax.ws.rs.core.UriInfo;
|
||||
import org.mifosplatform.commands.data.CommandSourceData;
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
import org.mifosplatform.commands.service.PortfolioCommandsReadPlatformService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioCommandDeserializerService;
|
||||
import org.mifosplatform.infrastructure.codes.data.CodeData;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.useradministration.command.RoleCommand;
|
||||
import org.mifosplatform.useradministration.command.RolePermissionCommand;
|
||||
import org.mifosplatform.useradministration.data.PermissionUsageData;
|
||||
import org.mifosplatform.useradministration.data.RoleData;
|
||||
import org.mifosplatform.useradministration.data.RolePermissionsData;
|
||||
import org.mifosplatform.useradministration.serialization.RoleCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.useradministration.serialization.RolePermissionsCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.useradministration.service.PermissionReadPlatformService;
|
||||
import org.mifosplatform.useradministration.service.RoleReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -43,38 +45,52 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("singleton")
|
||||
public class RolesApiResource {
|
||||
|
||||
/**
|
||||
* The set of parameters that are supported in response for {@link CodeData}
|
||||
*/
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description",
|
||||
"availablePermissions", "selectedPermissions"));
|
||||
|
||||
/**
|
||||
* The set of parameters that are supported in response for {@link CodeData}
|
||||
*/
|
||||
private final Set<String> PERMISSIONS_RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description",
|
||||
"permissionUsageData"));
|
||||
|
||||
private final String resourceNameForPermissions = "ROLE";
|
||||
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final RoleReadPlatformService roleReadPlatformService;
|
||||
private final PermissionReadPlatformService permissionReadPlatformService;
|
||||
private final PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
private final PortfolioApiDataConversionService apiDataConversionService;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
|
||||
private final RoleCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||
private final DefaultToApiJsonSerializer<RoleData> toApiJsonSerializer;
|
||||
private final RolePermissionsCommandFromApiJsonDeserializer permissionsfromApiJsonDeserializer;
|
||||
private final DefaultToApiJsonSerializer<RolePermissionsData> permissionsToApiJsonSerializer;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final PortfolioCommandsReadPlatformService commandSourceReadPlatformService;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
private final PortfolioCommandDeserializerService commandDeserializerService;
|
||||
|
||||
|
||||
@Autowired
|
||||
public RolesApiResource(
|
||||
final PlatformSecurityContext context,
|
||||
final RoleReadPlatformService readPlatformService,
|
||||
public RolesApiResource(final PlatformSecurityContext context, final RoleReadPlatformService readPlatformService,
|
||||
final PermissionReadPlatformService permissionReadPlatformService,
|
||||
final PortfolioApiJsonSerializerService apiJsonSerializerService,
|
||||
final PortfolioApiDataConversionService apiDataConversionService,
|
||||
final CommandSerializer commandSerializerService,
|
||||
final RoleCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||
final RolePermissionsCommandFromApiJsonDeserializer permissionsfromApiJsonDeserializer,
|
||||
final DefaultToApiJsonSerializer<RoleData> toApiJsonSerializer,
|
||||
final DefaultToApiJsonSerializer<RolePermissionsData> permissionsToApiJsonSerializer,
|
||||
final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final PortfolioCommandsReadPlatformService commandSourceReadPlatformService,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService,
|
||||
final PortfolioCommandDeserializerService commandDeserializerService) {
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.context = context;
|
||||
this.roleReadPlatformService = readPlatformService;
|
||||
this.permissionReadPlatformService = permissionReadPlatformService;
|
||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||
this.apiDataConversionService = apiDataConversionService;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.permissionsfromApiJsonDeserializer = permissionsfromApiJsonDeserializer;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
this.permissionsToApiJsonSerializer = permissionsToApiJsonSerializer;
|
||||
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||
this.commandSourceReadPlatformService = commandSourceReadPlatformService;
|
||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||
this.commandDeserializerService = commandDeserializerService;
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -84,29 +100,26 @@ public class RolesApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final Collection<RoleData> roles = this.roleReadPlatformService.retrieveAllRoles();
|
||||
|
||||
return this.apiJsonSerializerService.serializeRoleDataToJson(prettyPrint, responseParameters, roles);
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, roles, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
public String createRole(final String apiRequestBodyAsJson) {
|
||||
|
||||
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "CREATE_ROLE");
|
||||
context.authenticatedUser().validateHasPermissionTo("CREATE_ROLE", allowedPermissions);
|
||||
|
||||
final RoleCommand command = this.apiDataConversionService.convertApiRequestJsonToRoleCommand(null,apiRequestBodyAsJson);
|
||||
final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
|
||||
|
||||
final String commandSerializedAsJson = this.fromApiJsonDeserializer.serializedCommandJsonFromApiJson(apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "roles", null,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -117,28 +130,25 @@ public class RolesApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final Long commandId = ApiParameterHelper.commandId(uriInfo.getQueryParameters());
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
|
||||
if (commandId != null) {
|
||||
RoleData currentChanges = handleRequestToIntegrateProposedChangesFromRoleCommand(roleId, commandId);
|
||||
|
||||
role = RoleData.integrateChanges(role, currentChanges);
|
||||
if (settings.isCommandIdPassed()) {
|
||||
RoleData currentChanges = handleRequestToIntegrateProposedChangesFromRoleCommand(roleId, settings.getCommandId());
|
||||
|
||||
role = RoleData.integrateChanges(role, currentChanges);
|
||||
}
|
||||
|
||||
return this.apiJsonSerializerService.serializeRoleDataToJson(prettyPrint, responseParameters, role);
|
||||
return this.toApiJsonSerializer.serialize(settings, role, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
|
||||
private RoleData handleRequestToIntegrateProposedChangesFromRoleCommand(final Long roleId, final Long commandId) {
|
||||
final CommandSourceData entry = this.commandSourceReadPlatformService.retrieveById(commandId);
|
||||
return assembleRoleChanges(roleId, entry);
|
||||
}
|
||||
|
||||
private RoleData assembleRoleChanges(final Long roleId, final CommandSourceData entry) {
|
||||
final RoleCommand changesOnly = this.commandDeserializerService.deserializeRoleCommand(roleId, entry.json(), false);
|
||||
final RoleCommand changesOnly = this.fromApiJsonDeserializer.commandFromApiJson(roleId, entry.json());
|
||||
return RoleData.changes(changesOnly.getName(), changesOnly.getDescription());
|
||||
}
|
||||
|
||||
@@ -150,14 +160,13 @@ public class RolesApiResource {
|
||||
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "UPDATE_ROLE");
|
||||
context.authenticatedUser().validateHasPermissionTo("UPDATE_ROLE", allowedPermissions);
|
||||
|
||||
final RoleCommand command = this.apiDataConversionService.convertApiRequestJsonToRoleCommand(roleId, apiRequestBodyAsJson);
|
||||
final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
|
||||
|
||||
|
||||
final String commandSerializedAsJson = this.fromApiJsonDeserializer.serializedCommandJsonFromApiJson(apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "roles", roleId,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -168,20 +177,17 @@ public class RolesApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
final Long commandId = ApiParameterHelper.commandId(uriInfo.getQueryParameters());
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
final RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
|
||||
final Collection<PermissionUsageData> permissionUsageData = this.permissionReadPlatformService.retrieveAllRolePermissions(roleId);
|
||||
Collection<PermissionUsageData> currentChanges = null;
|
||||
if (commandId != null) {
|
||||
currentChanges = handleRequestToIntegrateProposedChangesFromCommand(roleId, commandId);
|
||||
if (settings.isCommandIdPassed()) {
|
||||
currentChanges = handleRequestToIntegrateProposedChangesFromCommand(roleId, settings.getCommandId());
|
||||
}
|
||||
|
||||
final RolePermissionsData permissionsData = role.toRolePermissionData(permissionUsageData, currentChanges);
|
||||
|
||||
return this.apiJsonSerializerService.serializeRolePermissionDataToJson(prettyPrint, responseParameters, permissionsData);
|
||||
return this.permissionsToApiJsonSerializer.serialize(settings, permissionsData, PERMISSIONS_RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
private Collection<PermissionUsageData> handleRequestToIntegrateProposedChangesFromCommand(final Long roleId, final Long commandId) {
|
||||
@@ -190,8 +196,8 @@ public class RolesApiResource {
|
||||
}
|
||||
|
||||
private Collection<PermissionUsageData> assemblePermissionChanges(final Long roleId, final CommandSourceData entry) {
|
||||
final RolePermissionCommand changesOnly = this.commandDeserializerService.deserializeRolePermissionCommand(roleId, entry.json(),
|
||||
false);
|
||||
|
||||
final RolePermissionCommand changesOnly = this.permissionsfromApiJsonDeserializer.commandFromApiJson(roleId, entry.json());
|
||||
|
||||
// assemble map of string/booleans into PermissionUsageData
|
||||
Collection<PermissionUsageData> proposedChanges = new ArrayList<PermissionUsageData>();
|
||||
@@ -213,13 +219,13 @@ public class RolesApiResource {
|
||||
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "PERMISSIONS_ROLE");
|
||||
context.authenticatedUser().validateHasPermissionTo("PERMISSIONS_ROLE", allowedPermissions);
|
||||
|
||||
final RolePermissionCommand command = this.apiDataConversionService.convertApiRequestJsonToRolePermissionCommand(roleId, apiRequestBodyAsJson);
|
||||
final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
|
||||
|
||||
|
||||
final String commandSerializedAsJson = this.permissionsfromApiJsonDeserializer
|
||||
.serializedCommandJsonFromApiJson(apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATEPERMISSIONS", "roles", roleId,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
}
|
||||
+32
-34
@@ -3,6 +3,7 @@ package org.mifosplatform.useradministration.api;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -19,16 +20,16 @@ import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiDataConversionService;
|
||||
import org.mifosplatform.infrastructure.core.api.PortfolioApiJsonSerializerService;
|
||||
import org.mifosplatform.infrastructure.codes.data.CodeData;
|
||||
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||
import org.mifosplatform.infrastructure.core.data.EntityIdentifier;
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
import org.mifosplatform.organisation.office.data.OfficeLookup;
|
||||
import org.mifosplatform.organisation.office.service.OfficeReadPlatformService;
|
||||
import org.mifosplatform.useradministration.command.UserCommand;
|
||||
import org.mifosplatform.useradministration.data.AppUserData;
|
||||
import org.mifosplatform.useradministration.serialization.UserCommandFromApiJsonDeserializer;
|
||||
import org.mifosplatform.useradministration.service.AppUserReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -39,28 +40,33 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("singleton")
|
||||
public class UsersApiResource {
|
||||
|
||||
/**
|
||||
* The set of parameters that are supported in response for {@link CodeData}
|
||||
*/
|
||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "officeId", "officeName", "username",
|
||||
"firstname", "lastname", "email", "allowedOffices", "availableRoles", "selectedRoles"));
|
||||
|
||||
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 CommandSerializer commandSerializerService;
|
||||
private final UserCommandFromApiJsonDeserializer fromApiJsonDeserializer;
|
||||
private final DefaultToApiJsonSerializer<AppUserData> toApiJsonSerializer;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
|
||||
@Autowired
|
||||
public UsersApiResource(final PlatformSecurityContext context, final AppUserReadPlatformService readPlatformService,
|
||||
final OfficeReadPlatformService officeReadPlatformService, final PortfolioApiJsonSerializerService apiJsonSerializerService,
|
||||
final PortfolioApiDataConversionService apiDataConversionService,
|
||||
final CommandSerializer commandSerializerService,
|
||||
final OfficeReadPlatformService officeReadPlatformService, final UserCommandFromApiJsonDeserializer fromApiJsonDeserializer,
|
||||
final DefaultToApiJsonSerializer<AppUserData> toApiJsonSerializer, final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||
final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
|
||||
this.context = context;
|
||||
this.readPlatformService = readPlatformService;
|
||||
this.officeReadPlatformService = officeReadPlatformService;
|
||||
this.apiJsonSerializerService = apiJsonSerializerService;
|
||||
this.apiDataConversionService = apiDataConversionService;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
this.fromApiJsonDeserializer = fromApiJsonDeserializer;
|
||||
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||
this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
|
||||
}
|
||||
|
||||
@@ -71,12 +77,10 @@ public class UsersApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final Collection<AppUserData> users = this.readPlatformService.retrieveAllUsers();
|
||||
|
||||
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, users);
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, users, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -87,17 +91,15 @@ public class UsersApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
|
||||
AppUserData user = this.readPlatformService.retrieveUser(userId);
|
||||
if (template) {
|
||||
if (settings.isTemplate()) {
|
||||
List<OfficeLookup> offices = new ArrayList<OfficeLookup>(this.officeReadPlatformService.retrieveAllOfficesForLookup());
|
||||
user = new AppUserData(user, offices);
|
||||
}
|
||||
|
||||
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, user);
|
||||
return this.toApiJsonSerializer.serialize(settings, user, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -108,12 +110,10 @@ public class UsersApiResource {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final AppUserData user = this.readPlatformService.retrieveNewUserDetails();
|
||||
|
||||
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, user);
|
||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, user, RESPONSE_DATA_PARAMETERS);
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -124,13 +124,12 @@ public class UsersApiResource {
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "CREATE_USER");
|
||||
context.authenticatedUser().validateHasPermissionTo("CREATE_USER", allowedPermissions);
|
||||
|
||||
final UserCommand command = this.apiDataConversionService.convertApiRequestJsonToUserCommand(null, apiRequestBodyAsJson);
|
||||
final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
|
||||
final String commandSerializedAsJson = this.fromApiJsonDeserializer.serializedCommandJsonFromApiJson(apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("CREATE", "users", null,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@@ -142,13 +141,12 @@ public class UsersApiResource {
|
||||
final List<String> allowedPermissions = Arrays.asList("ALL_FUNCTIONS", "USER_ADMINISTRATION_SUPER_USER", "UPDATE_USER");
|
||||
context.authenticatedUser().validateHasPermissionTo("UPDATE_USER", allowedPermissions);
|
||||
|
||||
final UserCommand command = this.apiDataConversionService.convertApiRequestJsonToUserCommand(null, apiRequestBodyAsJson);
|
||||
final String commandSerializedAsJson = this.commandSerializerService.serializeCommandToJson(command);
|
||||
final String commandSerializedAsJson = this.fromApiJsonDeserializer.serializedCommandJsonFromApiJson(apiRequestBodyAsJson);
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("UPDATE", "users", userId,
|
||||
commandSerializedAsJson);
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@@ -162,6 +160,6 @@ public class UsersApiResource {
|
||||
|
||||
final EntityIdentifier result = this.commandsSourceWritePlatformService.logCommandSource("DELETE", "users", userId, "{}");
|
||||
|
||||
return this.apiJsonSerializerService.serializeEntityIdentifier(result);
|
||||
return this.toApiJsonSerializer.serialize(result);
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package org.mifosplatform.useradministration.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.useradministration.command.PermissionsCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for
|
||||
* {@link PermissionsCommand}'s.
|
||||
*/
|
||||
@Component
|
||||
public final class PermissionsCommandFromApiJsonDeserializer implements FromApiJsonDeserializer<PermissionsCommand> {
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
|
||||
@Autowired
|
||||
public PermissionsCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper,
|
||||
final CommandSerializer commandSerializerService) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsCommand commandFromApiJson(final String json) {
|
||||
return commandFromApiJson(null, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsCommand commandFromApiJson(@SuppressWarnings("unused") final Long resourceId, final String json) {
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Boolean>>() {}.getType();
|
||||
final Map<String, Boolean> permissionsMap = fromApiJsonHelper.extractMap(typeOfMap, json);
|
||||
|
||||
return new PermissionsCommand(permissionsMap, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final String json) {
|
||||
final PermissionsCommand command = commandFromApiJson(json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final Long roleId, final String json) {
|
||||
final PermissionsCommand command = commandFromApiJson(roleId, json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package org.mifosplatform.useradministration.serialization;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromCommandJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.useradministration.command.PermissionsCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public final class PermissionsCommandFromCommandJsonDeserializer implements FromCommandJsonDeserializer<PermissionsCommand> {
|
||||
|
||||
private final FromJsonHelper fromJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public PermissionsCommandFromCommandJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsCommand commandFromCommandJson(final String commandAsJson) {
|
||||
return commandFromCommandJson(null, commandAsJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsCommand commandFromCommandJson(final Long roleId, final String commandAsJson) {
|
||||
return commandFromCommandJson(roleId, commandAsJson, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionsCommand commandFromCommandJson(@SuppressWarnings("unused") final Long resourceId, final String commandAsJson,
|
||||
final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final PermissionsCommand command = fromJsonHelper.fromJson(commandAsJson, PermissionsCommand.class);
|
||||
|
||||
return new PermissionsCommand(command.getPermissions(), makerCheckerApproval);
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package org.mifosplatform.useradministration.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.useradministration.command.RoleCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for {@link RoleCommand}'s.
|
||||
*/
|
||||
@Component
|
||||
public final class RoleCommandFromApiJsonDeserializer implements FromApiJsonDeserializer<RoleCommand> {
|
||||
|
||||
/**
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("id", "name", "description"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
private final RoleCommandFromCommandJsonDeserializer fromCommandJsonDeserializer;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
|
||||
@Autowired
|
||||
public RoleCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper,
|
||||
final RoleCommandFromCommandJsonDeserializer fromCommandJsonDeserializer, final CommandSerializer commandSerializerService) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
this.fromCommandJsonDeserializer = fromCommandJsonDeserializer;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleCommand commandFromApiJson(final String json) {
|
||||
return commandFromApiJson(null, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleCommand commandFromApiJson(final Long roleId, final String json) {
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
return this.fromCommandJsonDeserializer.commandFromCommandJson(roleId, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final String json) {
|
||||
final RoleCommand command = commandFromApiJson(json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final Long roleId, final String json) {
|
||||
final RoleCommand command = commandFromApiJson(roleId, json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
package org.mifosplatform.useradministration.serialization;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromCommandJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.useradministration.command.RoleCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public final class RoleCommandFromCommandJsonDeserializer implements FromCommandJsonDeserializer<RoleCommand> {
|
||||
|
||||
private final FromJsonHelper fromJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public RoleCommandFromCommandJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleCommand commandFromCommandJson(final String commandAsJson) {
|
||||
return commandFromCommandJson(null, commandAsJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleCommand commandFromCommandJson(final Long roleId, final String commandAsJson) {
|
||||
return commandFromCommandJson(roleId, commandAsJson, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleCommand commandFromCommandJson(final Long roleId, final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final JsonElement element = fromJsonHelper.parse(commandAsJson);
|
||||
|
||||
final String name = fromJsonHelper.extractStringNamed("name", element, parametersPassedInRequest);
|
||||
final String description = fromJsonHelper.extractStringNamed("description", element, parametersPassedInRequest);
|
||||
|
||||
return new RoleCommand(parametersPassedInRequest, makerCheckerApproval, roleId, name, description);
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package org.mifosplatform.useradministration.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.useradministration.command.RoleCommand;
|
||||
import org.mifosplatform.useradministration.command.RolePermissionCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for {@link RoleCommand}'s.
|
||||
*/
|
||||
@Component
|
||||
public final class RolePermissionsCommandFromApiJsonDeserializer implements FromApiJsonDeserializer<RolePermissionCommand> {
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
|
||||
@Autowired
|
||||
public RolePermissionsCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper,
|
||||
final CommandSerializer commandSerializerService) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolePermissionCommand commandFromApiJson(final String json) {
|
||||
return commandFromApiJson(null, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolePermissionCommand commandFromApiJson(final Long roleId, final String json) {
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Boolean>>() {}.getType();
|
||||
|
||||
final Map<String, Boolean> permissionsMap = fromApiJsonHelper.extractMap(typeOfMap, json);
|
||||
|
||||
return new RolePermissionCommand(roleId, permissionsMap, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final String json) {
|
||||
final RolePermissionCommand command = commandFromApiJson(json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final Long roleId, final String json) {
|
||||
final RolePermissionCommand command = commandFromApiJson(roleId, json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package org.mifosplatform.useradministration.serialization;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromCommandJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.useradministration.command.RolePermissionCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public final class RolePermissionsCommandFromCommandJsonDeserializer implements FromCommandJsonDeserializer<RolePermissionCommand> {
|
||||
|
||||
private final FromJsonHelper fromJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public RolePermissionsCommandFromCommandJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolePermissionCommand commandFromCommandJson(final String commandAsJson) {
|
||||
return commandFromCommandJson(null, commandAsJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolePermissionCommand commandFromCommandJson(final Long roleId, final String commandAsJson) {
|
||||
return commandFromCommandJson(roleId, commandAsJson, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RolePermissionCommand commandFromCommandJson(final Long roleId, final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final RolePermissionCommand command = fromJsonHelper.fromJson(commandAsJson, RolePermissionCommand.class);
|
||||
|
||||
return new RolePermissionCommand(roleId, command.getPermissions(), makerCheckerApproval);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package org.mifosplatform.useradministration.serialization;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.serialization.CommandSerializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromApiJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.useradministration.command.UserCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Implementation of {@link FromApiJsonDeserializer} for {@link UserCommand}'s.
|
||||
*/
|
||||
@Component
|
||||
public final class UserCommandFromApiJsonDeserializer implements FromApiJsonDeserializer<UserCommand> {
|
||||
|
||||
/**
|
||||
* The parameters supported for this command.
|
||||
*/
|
||||
private final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("username", "firstname", "lastname", "password",
|
||||
"repeatPassword", "email", "officeId", "notSelectedRoles", "roles"));
|
||||
|
||||
private final FromJsonHelper fromApiJsonHelper;
|
||||
private final UserCommandFromCommandJsonDeserializer fromCommandJsonDeserializer;
|
||||
private final CommandSerializer commandSerializerService;
|
||||
|
||||
@Autowired
|
||||
public UserCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper,
|
||||
final UserCommandFromCommandJsonDeserializer fromCommandJsonDeserializer, final CommandSerializer commandSerializerService) {
|
||||
this.fromApiJsonHelper = fromApiJsonHelper;
|
||||
this.fromCommandJsonDeserializer = fromCommandJsonDeserializer;
|
||||
this.commandSerializerService = commandSerializerService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserCommand commandFromApiJson(final String json) {
|
||||
return commandFromApiJson(null, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserCommand commandFromApiJson(final Long userId, final String json) {
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
|
||||
|
||||
return this.fromCommandJsonDeserializer.commandFromCommandJson(userId, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final String json) {
|
||||
final UserCommand command = commandFromApiJson(json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializedCommandJsonFromApiJson(final Long userId, final String json) {
|
||||
final UserCommand command = commandFromApiJson(userId, json);
|
||||
return this.commandSerializerService.serializeCommandToJson(command);
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
package org.mifosplatform.useradministration.serialization;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.mifosplatform.infrastructure.core.exception.InvalidJsonException;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromCommandJsonDeserializer;
|
||||
import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
|
||||
import org.mifosplatform.useradministration.command.UserCommand;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
public final class UserCommandFromCommandJsonDeserializer implements FromCommandJsonDeserializer<UserCommand> {
|
||||
|
||||
private final FromJsonHelper fromJsonHelper;
|
||||
|
||||
@Autowired
|
||||
public UserCommandFromCommandJsonDeserializer(final FromJsonHelper fromApiJsonHelper) {
|
||||
this.fromJsonHelper = fromApiJsonHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserCommand commandFromCommandJson(final String commandAsJson) {
|
||||
return commandFromCommandJson(null, commandAsJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserCommand commandFromCommandJson(final Long userId, final String commandAsJson) {
|
||||
return commandFromCommandJson(userId, commandAsJson, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserCommand commandFromCommandJson(final Long userId, final String commandAsJson, final boolean makerCheckerApproval) {
|
||||
if (StringUtils.isBlank(commandAsJson)) { throw new InvalidJsonException(); }
|
||||
|
||||
final Set<String> parametersPassedInRequest = new HashSet<String>();
|
||||
|
||||
final JsonElement element = fromJsonHelper.parse(commandAsJson);
|
||||
|
||||
final String username = fromJsonHelper.extractStringNamed("username", element, parametersPassedInRequest);
|
||||
final String firstname = fromJsonHelper.extractStringNamed("firstname", element, parametersPassedInRequest);
|
||||
final String lastname = fromJsonHelper.extractStringNamed("lastname", element, parametersPassedInRequest);
|
||||
final String password = fromJsonHelper.extractStringNamed("password", element, parametersPassedInRequest);
|
||||
final String repeatPassword = fromJsonHelper.extractStringNamed("repeatPassword", element, parametersPassedInRequest);
|
||||
final String email = fromJsonHelper.extractStringNamed("email", element, parametersPassedInRequest);
|
||||
final Long officeId = fromJsonHelper.extractLongNamed("officeId", element, parametersPassedInRequest);
|
||||
|
||||
final String[] notSelectedRoles = fromJsonHelper.extractArrayNamed("notSelectedRoles", element, parametersPassedInRequest);
|
||||
final String[] roles = fromJsonHelper.extractArrayNamed("roles", element, parametersPassedInRequest);
|
||||
|
||||
return new UserCommand(parametersPassedInRequest, makerCheckerApproval, userId, username, firstname, lastname, password,
|
||||
repeatPassword, email, officeId, notSelectedRoles, roles);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user