MIFOSX-97: tidy up of maker checker based on audit work so far.

This commit is contained in:
Keith Woodlock
2013-01-07 16:23:06 +00:00
parent 32f4bc1d30
commit ff6eae40d3
6 changed files with 45 additions and 37 deletions
@@ -48,8 +48,7 @@ public class CommandsApiResource {
@Autowired @Autowired
public CommandsApiResource(final PlatformSecurityContext context, final PortfolioCommandsReadPlatformService readPlatformService, public CommandsApiResource(final PlatformSecurityContext context, final PortfolioCommandsReadPlatformService readPlatformService,
final DefaultToApiJsonSerializer<CommandSourceData> toApiJsonSerializer, final DefaultToApiJsonSerializer<CommandSourceData> toApiJsonSerializer,
final ApiRequestParameterHelper apiRequestParameterHelper, final ApiRequestParameterHelper apiRequestParameterHelper, final PortfolioCommandSourceWritePlatformService writePlatformService) {
final PortfolioCommandSourceWritePlatformService writePlatformService) {
this.context = context; this.context = context;
this.readPlatformService = readPlatformService; this.readPlatformService = readPlatformService;
this.toApiJsonSerializer = toApiJsonSerializer; this.toApiJsonSerializer = toApiJsonSerializer;
@@ -8,20 +8,26 @@ import org.joda.time.LocalDate;
final public class CommandSourceData { final public class CommandSourceData {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private Long id; private final Long id;
private String apiOperation; @SuppressWarnings("unused")
private String resource; private final String actionName;
private final Long resourceId; @SuppressWarnings("unused")
private final String entityName;
@SuppressWarnings("unused")
private final Long entityId;
@SuppressWarnings("unused")
private final String entityHref;
private String commandJson; private String commandJson;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private final LocalDate madeOnDate; 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) { final String commandJson, final LocalDate madeOnDate) {
this.id = id; this.id = id;
this.apiOperation = apiOperation; this.actionName = actionName;
this.resource = resource; this.entityName = entityName;
this.resourceId = resourceId; this.entityId = entityId;
this.entityHref = entityHref;
this.commandJson = commandJson; this.commandJson = commandJson;
this.madeOnDate = madeOnDate; this.madeOnDate = madeOnDate;
} }
@@ -29,12 +35,4 @@ final public class CommandSourceData {
public String json() { public String json() {
return this.commandJson; return this.commandJson;
} }
public boolean isUpdateRolePermissions() {
return this.apiOperation.equalsIgnoreCase("UPDATEPERMISSIONS") && this.resourceId != null;
}
public boolean isRoleResource() {
return this.resource.equalsIgnoreCase("ROLES");
}
} }
@@ -12,7 +12,7 @@ public class CommandWrapperBuilder {
private String entityName; private String entityName;
private Long entityId; private Long entityId;
private String href; private String href;
private String json; private String json = "{}";
private Long apptableId; private Long apptableId;
private Long datatableId; private Long datatableId;
@@ -217,18 +217,24 @@ public class CommandWrapperBuilder {
public CommandWrapperBuilder createClient() { public CommandWrapperBuilder createClient() {
this.actionName = "CREATE"; this.actionName = "CREATE";
this.entityName = "CLIENT"; this.entityName = "CLIENT";
this.href = "/clients/template";
return this; return this;
} }
public CommandWrapperBuilder updateClient() { public CommandWrapperBuilder updateClient(final Long clientId) {
this.actionName = "UPDATE"; this.actionName = "UPDATE";
this.entityName = "CLIENT"; this.entityName = "CLIENT";
this.entityId = clientId;
this.href = "/clients/" + clientId;
return this; return this;
} }
public CommandWrapperBuilder deleteClient() { public CommandWrapperBuilder deleteClient(final Long clientId) {
this.actionName = "DELETE"; this.actionName = "DELETE";
this.entityName = "CLIENT"; this.entityName = "CLIENT";
this.entityId = clientId;
this.href = "/clients/" + clientId;
this.json = "{}";
return this; return this;
} }
@@ -10,5 +10,5 @@ public interface PortfolioCommandsReadPlatformService {
CommandSourceData retrieveById(Long id); CommandSourceData retrieveById(Long id);
Collection<CommandSourceData> retrieveUnprocessChangesByResourceId(String apiResource, Long clientId); Collection<CommandSourceData> retrieveUnprocessChangesByEntityNameAndId(String entityName, Long entityId);
} }
@@ -29,7 +29,7 @@ public class PortfolioCommandsReadPlatformServiceImpl implements PortfolioComman
private static final class CommandSourceMapper implements RowMapper<CommandSourceData> { private static final class CommandSourceMapper implements RowMapper<CommandSourceData> {
public String schema() { 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 "; + "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 { public CommandSourceData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
final Long id = rs.getLong("id"); final Long id = rs.getLong("id");
final String taskOperation = rs.getString("taskOperation"); final String actionName = rs.getString("actionName");
final String taskEntity = rs.getString("taskEntity"); final String entityName = rs.getString("entityName");
final Long entityId = JdbcSupport.getLong(rs, "entityId"); final Long entityId = JdbcSupport.getLong(rs, "entityId");
final String taskJson = rs.getString("taskJson"); final String taskJson = rs.getString("taskJson");
final String getHref = rs.getString("getHref");
final LocalDate madeOnDate = JdbcSupport.getLocalDate(rs, "madeOnDate"); 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 @Override
public Collection<CommandSourceData> retrieveUnprocessChangesByResourceId(final String apiResource, final Long resourceId) { public Collection<CommandSourceData> retrieveUnprocessChangesByEntityNameAndId(final String entityName, final Long entityId) {
final CommandSourceMapper rm = new CommandSourceMapper(); final CommandSourceMapper rm = new CommandSourceMapper();
final String sql = "select " final String sql = "select "
+ rm.schema() + 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"; + " 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 });
} }
} }
@@ -182,8 +182,8 @@ public class ClientsApiResource {
private Collection<ClientData> retrieveAllUnprocessedDataChanges(final Long clientId) { private Collection<ClientData> retrieveAllUnprocessedDataChanges(final Long clientId) {
Collection<ClientData> dataChanges = new ArrayList<ClientData>(); Collection<ClientData> dataChanges = new ArrayList<ClientData>();
Collection<CommandSourceData> unprocessedChanges = this.commandSourceReadPlatformService.retrieveUnprocessChangesByResourceId( Collection<CommandSourceData> unprocessedChanges = this.commandSourceReadPlatformService.retrieveUnprocessChangesByEntityNameAndId(
"clients", clientId); "CLIENT", clientId);
for (CommandSourceData commandSourceData : unprocessedChanges) { for (CommandSourceData commandSourceData : unprocessedChanges) {
ClientData change = this.apiDataConversionService.convertInternalJsonFormatToClientDataChange(clientId, ClientData change = this.apiDataConversionService.convertInternalJsonFormatToClientDataChange(clientId,
commandSourceData.json()); commandSourceData.json());
@@ -220,8 +220,10 @@ public class ClientsApiResource {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String createClient(final String apiRequestBodyAsJson) { public String createClient(final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createClient().withUrl("/clients").withJson(apiRequestBodyAsJson) final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.build(); .createClient() //
.withJson(apiRequestBodyAsJson) //
.build(); //
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -234,8 +236,10 @@ public class ClientsApiResource {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String updateClient(@PathParam("clientId") final Long clientId, final String apiRequestBodyAsJson) { public String updateClient(@PathParam("clientId") final Long clientId, final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateClient().withUrl("/clients").withEntityId(clientId) final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.withJson(apiRequestBodyAsJson).build(); .updateClient(clientId) //
.withJson(apiRequestBodyAsJson) //
.build(); //
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@@ -248,8 +252,9 @@ public class ClientsApiResource {
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public String deleteClient(@PathParam("clientId") final Long clientId) { public String deleteClient(@PathParam("clientId") final Long clientId) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteClient().withUrl("/clients").withEntityId(clientId) final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.withJson("{}").build(); .deleteClient(clientId) //
.build(); //
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);