WIP Audit services
This commit is contained in:
@@ -54,9 +54,10 @@ public class AuditApiResource {
|
||||
// final String extraCriteria = getCriteria(sqlSearch, officeId,
|
||||
// externalId, displayName, firstName, lastName, hierarchy);
|
||||
|
||||
final Collection<AuditData> auditEntries = this.auditReadPlatformService.retrieveAuditEntries();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -4,6 +4,6 @@ import java.util.Collection;
|
||||
|
||||
public interface AuditReadPlatformService {
|
||||
|
||||
Collection<AuditData> retrieveAuditEntries();
|
||||
Collection<AuditData> retrieveAuditEntries(boolean includeJson);
|
||||
|
||||
}
|
||||
+18
-6
@@ -27,9 +27,14 @@ public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
|
||||
|
||||
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,"
|
||||
+ " 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"
|
||||
+ " 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 String checker = rs.getString("checker");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AuditData> retrieveAuditEntries() {
|
||||
public Collection<AuditData> retrieveAuditEntries(boolean includeJson) {
|
||||
context.authenticatedUser();
|
||||
|
||||
final AuditMapper rm = new AuditMapper();
|
||||
final String sql = "select " + rm.schema()
|
||||
+ " where mc.checker_id is null order by mc.made_on_date DESC, mc.api_resource ASC, mc.api_operation ASC";
|
||||
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";
|
||||
+ " order by id DESC";
|
||||
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] {});
|
||||
}
|
||||
|
||||
+9
@@ -98,6 +98,15 @@ public class ApiParameterHelper {
|
||||
}
|
||||
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) {
|
||||
boolean genericResultSet = false;
|
||||
|
||||
+2
-1
@@ -28,7 +28,8 @@ public class ApiRequestParameterHelper {
|
||||
final boolean template = ApiParameterHelper.template(queryParameters);
|
||||
final Long commandId = ApiParameterHelper.commandId(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);
|
||||
}
|
||||
}
|
||||
+10
-4
@@ -13,23 +13,25 @@ public class ApiRequestJsonSerializationSettings {
|
||||
private final boolean template;
|
||||
private final Long commandId;
|
||||
private final boolean makerCheckerable;
|
||||
private final boolean includeJson;
|
||||
|
||||
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.parametersForPartialResponse = parametersForPartialResponse;
|
||||
this.template = template;
|
||||
this.commandId = commandId;
|
||||
this.makerCheckerable = makerCheckerable;
|
||||
this.includeJson = includeJson;
|
||||
}
|
||||
|
||||
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
|
||||
// just send by common ones like, prettyprint=false, empty response
|
||||
// parameters
|
||||
return new ApiRequestJsonSerializationSettings(prettyPrint, parametersForPartialResponse, template, commandId, makerCheckerable);
|
||||
return new ApiRequestJsonSerializationSettings(prettyPrint, parametersForPartialResponse, template, commandId, makerCheckerable, includeJson);
|
||||
}
|
||||
|
||||
public boolean isPrettyPrint() {
|
||||
@@ -39,10 +41,14 @@ public class ApiRequestJsonSerializationSettings {
|
||||
public boolean isTemplate() {
|
||||
return this.template;
|
||||
}
|
||||
|
||||
|
||||
public boolean isMakerCheckerable() {
|
||||
return this.makerCheckerable;
|
||||
}
|
||||
|
||||
public boolean isIncludeJson() {
|
||||
return this.includeJson;
|
||||
}
|
||||
|
||||
public Long getCommandId() {
|
||||
return this.commandId;
|
||||
|
||||
Reference in New Issue
Block a user