WIP Audit services

This commit is contained in:
John Woodlock
2012-12-09 20:57:28 +00:00
parent 0717d02a38
commit 3cc91463c0
6 changed files with 43 additions and 14 deletions
@@ -54,9 +54,10 @@ public class AuditApiResource {
// final String extraCriteria = getCriteria(sqlSearch, officeId, // final String extraCriteria = getCriteria(sqlSearch, officeId,
// externalId, displayName, firstName, lastName, hierarchy); // externalId, displayName, firstName, lastName, hierarchy);
final Collection<AuditData> auditEntries = this.auditReadPlatformService.retrieveAuditEntries();
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
final Collection<AuditData> auditEntries = this.auditReadPlatformService.retrieveAuditEntries(settings.isIncludeJson());
return this.toApiJsonSerializer.serialize(settings, auditEntries, RESPONSE_DATA_PARAMETERS); return this.toApiJsonSerializer.serialize(settings, auditEntries, RESPONSE_DATA_PARAMETERS);
} }
@@ -4,6 +4,6 @@ import java.util.Collection;
public interface AuditReadPlatformService { public interface AuditReadPlatformService {
Collection<AuditData> retrieveAuditEntries(); Collection<AuditData> retrieveAuditEntries(boolean includeJson);
} }
@@ -27,9 +27,14 @@ public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
private static final class AuditMapper implements RowMapper<AuditData> { private static final class AuditMapper implements RowMapper<AuditData> {
public String schema() { public String schema(boolean includeJson) {
String commandAsJsonString = "";
if (includeJson) commandAsJsonString = ", mc.command_as_json as commandAsJson ";
return " mc.id as id, mc.api_operation as apiOperation, mc.api_resource as resource, mc.resource_id as resourceId," return " mc.id as id, mc.api_operation as apiOperation, mc.api_resource as resource, mc.resource_id as resourceId,"
+ " mk.username as maker, mc.made_on_date as madeOnDate, ck.username as checker, mc.checked_on_date as checkedOnDate, mc.command_as_json as commandAsJson " + " mk.username as maker, mc.made_on_date as madeOnDate, ck.username as checker, mc.checked_on_date as checkedOnDate"
+ commandAsJsonString
+ " from m_portfolio_command_source mc " + " left join m_appuser mk on mk.id = mc.maker_id" + " from m_portfolio_command_source mc " + " left join m_appuser mk on mk.id = mc.maker_id"
+ " left join m_appuser ck on ck.id = mc.checker_id"; + " left join m_appuser ck on ck.id = mc.checker_id";
} }
@@ -45,18 +50,25 @@ public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
final LocalDate madeOnDate = JdbcSupport.getLocalDate(rs, "madeOnDate"); final LocalDate madeOnDate = JdbcSupport.getLocalDate(rs, "madeOnDate");
final String checker = rs.getString("checker"); final String checker = rs.getString("checker");
final LocalDate checkedOnDate = JdbcSupport.getLocalDate(rs, "checkedOnDate"); final LocalDate checkedOnDate = JdbcSupport.getLocalDate(rs, "checkedOnDate");
final String commandAsJson = rs.getString("commandAsJson"); String commandAsJson;
//commandAsJson might not be on the select list of columns
try {
commandAsJson = rs.getString("commandAsJson");
} catch (SQLException e) {
commandAsJson = null;
}
return new AuditData(id, apiOperation, resource, resourceId, maker, madeOnDate, checker, checkedOnDate, commandAsJson); return new AuditData(id, apiOperation, resource, resourceId, maker, madeOnDate, checker, checkedOnDate, commandAsJson);
} }
} }
@Override @Override
public Collection<AuditData> retrieveAuditEntries() { public Collection<AuditData> retrieveAuditEntries(boolean includeJson) {
context.authenticatedUser(); context.authenticatedUser();
final AuditMapper rm = new AuditMapper(); final AuditMapper rm = new AuditMapper();
final String sql = "select " + rm.schema() final String sql = "select " + rm.schema(includeJson)
+ " where mc.checker_id is null order by mc.made_on_date DESC, mc.api_resource ASC, mc.api_operation ASC"; // + " where mc.checker_id is null order by mc.made_on_date DESC, mc.api_resource ASC, mc.api_operation ASC";
+ " order by id DESC";
return this.jdbcTemplate.query(sql, rm, new Object[] {}); return this.jdbcTemplate.query(sql, rm, new Object[] {});
} }
@@ -98,6 +98,15 @@ public class ApiParameterHelper {
} }
return makerCheckerable; return makerCheckerable;
} }
public static boolean includeJson(final MultivaluedMap<String, String> queryParams) {
boolean includeJson = false;
if (queryParams.getFirst("includeJson") != null) {
String includeJsonValue = queryParams.getFirst("includeJson");
includeJson = "true".equalsIgnoreCase(includeJsonValue);
}
return includeJson;
}
public static boolean genericResultSet(final MultivaluedMap<String, String> queryParams) { public static boolean genericResultSet(final MultivaluedMap<String, String> queryParams) {
boolean genericResultSet = false; boolean genericResultSet = false;
@@ -28,7 +28,8 @@ public class ApiRequestParameterHelper {
final boolean template = ApiParameterHelper.template(queryParameters); final boolean template = ApiParameterHelper.template(queryParameters);
final Long commandId = ApiParameterHelper.commandId(queryParameters); final Long commandId = ApiParameterHelper.commandId(queryParameters);
final boolean makerCheckerable = ApiParameterHelper.makerCheckerable(queryParameters); final boolean makerCheckerable = ApiParameterHelper.makerCheckerable(queryParameters);
final boolean includeJson = ApiParameterHelper.includeJson(queryParameters);
return ApiRequestJsonSerializationSettings.from(prettyPrint, responseParameters, template, commandId, makerCheckerable); return ApiRequestJsonSerializationSettings.from(prettyPrint, responseParameters, template, commandId, makerCheckerable, includeJson);
} }
} }
@@ -13,23 +13,25 @@ public class ApiRequestJsonSerializationSettings {
private final boolean template; private final boolean template;
private final Long commandId; private final Long commandId;
private final boolean makerCheckerable; private final boolean makerCheckerable;
private final boolean includeJson;
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) { final boolean template, final Long commandId, final boolean makerCheckerable, final boolean includeJson) {
this.prettyPrint = prettyPrint; this.prettyPrint = prettyPrint;
this.parametersForPartialResponse = parametersForPartialResponse; this.parametersForPartialResponse = parametersForPartialResponse;
this.template = template; this.template = template;
this.commandId = commandId; this.commandId = commandId;
this.makerCheckerable = makerCheckerable; this.makerCheckerable = makerCheckerable;
this.includeJson = includeJson;
} }
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) { final boolean template, final Long commandId, final boolean makerCheckerable, final boolean includeJson) {
// FIXME - kw - rather than always creating new objects for this could // FIXME - kw - rather than always creating new objects for this could
// just send by common ones like, prettyprint=false, empty response // just send by common ones like, prettyprint=false, empty response
// parameters // parameters
return new ApiRequestJsonSerializationSettings(prettyPrint, parametersForPartialResponse, template, commandId, makerCheckerable); return new ApiRequestJsonSerializationSettings(prettyPrint, parametersForPartialResponse, template, commandId, makerCheckerable, includeJson);
} }
public boolean isPrettyPrint() { public boolean isPrettyPrint() {
@@ -39,10 +41,14 @@ public class ApiRequestJsonSerializationSettings {
public boolean isTemplate() { public boolean isTemplate() {
return this.template; return this.template;
} }
public boolean isMakerCheckerable() { public boolean isMakerCheckerable() {
return this.makerCheckerable; return this.makerCheckerable;
} }
public boolean isIncludeJson() {
return this.includeJson;
}
public Long getCommandId() { public Long getCommandId() {
return this.commandId; return this.commandId;