From ff6eae40d32e95120cf51a7fcd2610ea9833fa81 Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Mon, 7 Jan 2013 16:23:06 +0000 Subject: [PATCH] MIFOSX-97: tidy up of maker checker based on audit work so far. --- .../commands/api/CommandsApiResource.java | 3 +- .../commands/data/CommandSourceData.java | 30 +++++++++---------- .../service/CommandWrapperBuilder.java | 12 ++++++-- .../PortfolioCommandsReadPlatformService.java | 2 +- ...tfolioCommandsReadPlatformServiceImpl.java | 14 ++++----- .../client/api/ClientsApiResource.java | 21 ++++++++----- 6 files changed, 45 insertions(+), 37 deletions(-) diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/api/CommandsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/api/CommandsApiResource.java index bdff8740f..18b2cd776 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/api/CommandsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/api/CommandsApiResource.java @@ -48,8 +48,7 @@ public class CommandsApiResource { @Autowired public CommandsApiResource(final PlatformSecurityContext context, final PortfolioCommandsReadPlatformService readPlatformService, final DefaultToApiJsonSerializer toApiJsonSerializer, - final ApiRequestParameterHelper apiRequestParameterHelper, - final PortfolioCommandSourceWritePlatformService writePlatformService) { + final ApiRequestParameterHelper apiRequestParameterHelper, final PortfolioCommandSourceWritePlatformService writePlatformService) { this.context = context; this.readPlatformService = readPlatformService; this.toApiJsonSerializer = toApiJsonSerializer; diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/data/CommandSourceData.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/data/CommandSourceData.java index a7990aa7e..421551ceb 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/data/CommandSourceData.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/data/CommandSourceData.java @@ -8,20 +8,26 @@ import org.joda.time.LocalDate; final public class CommandSourceData { @SuppressWarnings("unused") - private Long id; - private String apiOperation; - private String resource; - private final Long resourceId; + private final Long id; + @SuppressWarnings("unused") + private final String actionName; + @SuppressWarnings("unused") + private final String entityName; + @SuppressWarnings("unused") + private final Long entityId; + @SuppressWarnings("unused") + private final String entityHref; private String commandJson; @SuppressWarnings("unused") private final LocalDate madeOnDate; - public CommandSourceData(final Long id, final String apiOperation, final String resource, final Long resourceId, + public CommandSourceData(final Long id, final String actionName, final String entityName, final Long entityId, final String entityHref, final String commandJson, final LocalDate madeOnDate) { this.id = id; - this.apiOperation = apiOperation; - this.resource = resource; - this.resourceId = resourceId; + this.actionName = actionName; + this.entityName = entityName; + this.entityId = entityId; + this.entityHref = entityHref; this.commandJson = commandJson; this.madeOnDate = madeOnDate; } @@ -29,12 +35,4 @@ final public class CommandSourceData { public String json() { return this.commandJson; } - - public boolean isUpdateRolePermissions() { - return this.apiOperation.equalsIgnoreCase("UPDATEPERMISSIONS") && this.resourceId != null; - } - - public boolean isRoleResource() { - return this.resource.equalsIgnoreCase("ROLES"); - } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java index 8d9d9db1c..c9c41f22b 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/CommandWrapperBuilder.java @@ -12,7 +12,7 @@ public class CommandWrapperBuilder { private String entityName; private Long entityId; private String href; - private String json; + private String json = "{}"; private Long apptableId; private Long datatableId; @@ -217,18 +217,24 @@ public class CommandWrapperBuilder { public CommandWrapperBuilder createClient() { this.actionName = "CREATE"; this.entityName = "CLIENT"; + this.href = "/clients/template"; return this; } - public CommandWrapperBuilder updateClient() { + public CommandWrapperBuilder updateClient(final Long clientId) { this.actionName = "UPDATE"; this.entityName = "CLIENT"; + this.entityId = clientId; + this.href = "/clients/" + clientId; return this; } - public CommandWrapperBuilder deleteClient() { + public CommandWrapperBuilder deleteClient(final Long clientId) { this.actionName = "DELETE"; this.entityName = "CLIENT"; + this.entityId = clientId; + this.href = "/clients/" + clientId; + this.json = "{}"; return this; } diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandsReadPlatformService.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandsReadPlatformService.java index 9bfafc27d..2c917003f 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandsReadPlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandsReadPlatformService.java @@ -10,5 +10,5 @@ public interface PortfolioCommandsReadPlatformService { CommandSourceData retrieveById(Long id); - Collection retrieveUnprocessChangesByResourceId(String apiResource, Long clientId); + Collection retrieveUnprocessChangesByEntityNameAndId(String entityName, Long entityId); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandsReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandsReadPlatformServiceImpl.java index f828e29b8..4676ae856 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandsReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/commands/service/PortfolioCommandsReadPlatformServiceImpl.java @@ -29,7 +29,7 @@ public class PortfolioCommandsReadPlatformServiceImpl implements PortfolioComman private static final class CommandSourceMapper implements RowMapper { public String schema() { - return " mc.id as id, mc.action_name as taskOperation, mc.entity_name as taskEntity, mc.resource_id as entityId," + return " mc.id as id, mc.action_name as actionName, mc.entity_name as entityName, mc.resource_id as entityId, mc.api_get_url as getHref, " + "mc.command_as_json as taskJson, mc.made_on_date as madeOnDate from m_portfolio_command_source mc "; } @@ -37,14 +37,14 @@ public class PortfolioCommandsReadPlatformServiceImpl implements PortfolioComman public CommandSourceData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException { final Long id = rs.getLong("id"); - final String taskOperation = rs.getString("taskOperation"); - final String taskEntity = rs.getString("taskEntity"); + final String actionName = rs.getString("actionName"); + final String entityName = rs.getString("entityName"); final Long entityId = JdbcSupport.getLong(rs, "entityId"); final String taskJson = rs.getString("taskJson"); - + final String getHref = rs.getString("getHref"); final LocalDate madeOnDate = JdbcSupport.getLocalDate(rs, "madeOnDate"); - return new CommandSourceData(id, taskOperation, taskEntity, entityId, taskJson, madeOnDate); + return new CommandSourceData(id, actionName, entityName, entityId, getHref, taskJson, madeOnDate); } } @@ -69,13 +69,13 @@ public class PortfolioCommandsReadPlatformServiceImpl implements PortfolioComman } @Override - public Collection retrieveUnprocessChangesByResourceId(final String apiResource, final Long resourceId) { + public Collection retrieveUnprocessChangesByEntityNameAndId(final String entityName, final Long entityId) { final CommandSourceMapper rm = new CommandSourceMapper(); final String sql = "select " + rm.schema() + " where mc.entity_name like ? and mc.resource_id = ? and mc.checker_id is null and mc.processing_result_enum = 2 order by mc.made_on_date DESC, mc.action_name ASC"; - return this.jdbcTemplate.query(sql, rm, new Object[] { apiResource, resourceId }); + return this.jdbcTemplate.query(sql, rm, new Object[] { entityName, entityId }); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientsApiResource.java index a73e9c0a6..c68fe8d01 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/client/api/ClientsApiResource.java @@ -182,8 +182,8 @@ public class ClientsApiResource { private Collection retrieveAllUnprocessedDataChanges(final Long clientId) { Collection dataChanges = new ArrayList(); - Collection unprocessedChanges = this.commandSourceReadPlatformService.retrieveUnprocessChangesByResourceId( - "clients", clientId); + Collection unprocessedChanges = this.commandSourceReadPlatformService.retrieveUnprocessChangesByEntityNameAndId( + "CLIENT", clientId); for (CommandSourceData commandSourceData : unprocessedChanges) { ClientData change = this.apiDataConversionService.convertInternalJsonFormatToClientDataChange(clientId, commandSourceData.json()); @@ -220,8 +220,10 @@ public class ClientsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String createClient(final String apiRequestBodyAsJson) { - final CommandWrapper commandRequest = new CommandWrapperBuilder().createClient().withUrl("/clients").withJson(apiRequestBodyAsJson) - .build(); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .createClient() // + .withJson(apiRequestBodyAsJson) // + .build(); // final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); @@ -234,8 +236,10 @@ public class ClientsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String updateClient(@PathParam("clientId") final Long clientId, final String apiRequestBodyAsJson) { - final CommandWrapper commandRequest = new CommandWrapperBuilder().updateClient().withUrl("/clients").withEntityId(clientId) - .withJson(apiRequestBodyAsJson).build(); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .updateClient(clientId) // + .withJson(apiRequestBodyAsJson) // + .build(); // final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); @@ -248,8 +252,9 @@ public class ClientsApiResource { @Produces({ MediaType.APPLICATION_JSON }) public String deleteClient(@PathParam("clientId") final Long clientId) { - final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteClient().withUrl("/clients").withEntityId(clientId) - .withJson("{}").build(); + final CommandWrapper commandRequest = new CommandWrapperBuilder() // + .deleteClient(clientId) // + .build(); // final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);