WIP Audit
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package org.mifosplatform.audit.api;
|
package org.mifosplatform.audit.api;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -12,7 +13,9 @@ import javax.ws.rs.core.Context;
|
|||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
import org.mifosplatform.commands.service.PortfolioCommandsReadPlatformService;
|
import org.mifosplatform.infrastructure.core.api.ApiRequestParameterHelper;
|
||||||
|
import org.mifosplatform.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||||
|
import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
@@ -23,33 +26,46 @@ import org.springframework.stereotype.Component;
|
|||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class AuditApiResource {
|
public class AuditApiResource {
|
||||||
|
|
||||||
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "taskName", "madeOnDate"));
|
private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<String>(
|
||||||
private final String resourceNameForPermissions = "MAKERCHECKER";
|
Arrays.asList("id", "apiOperation", "resource", "resourceId",
|
||||||
|
"makerId", "madeOnDate", "checkerId", "checkedOnDate",
|
||||||
|
"commandAsJson"));
|
||||||
|
private final String resourceNameForPermissions = "AUDIT";
|
||||||
|
|
||||||
private final PlatformSecurityContext context;
|
private final PlatformSecurityContext context;
|
||||||
private final PortfolioCommandsReadPlatformService readPlatformService;
|
private final AuditReadPlatformService auditReadPlatformService;
|
||||||
|
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||||
|
private final DefaultToApiJsonSerializer<AuditData> toApiJsonSerializer;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public AuditApiResource(final PlatformSecurityContext context, final PortfolioCommandsReadPlatformService readPlatformService) {
|
public AuditApiResource(final PlatformSecurityContext context,
|
||||||
this.context = context;
|
final AuditReadPlatformService auditReadPlatformService,
|
||||||
this.readPlatformService = readPlatformService;
|
final ApiRequestParameterHelper apiRequestParameterHelper,
|
||||||
}
|
final DefaultToApiJsonSerializer<AuditData> toApiJsonSerializer) {
|
||||||
|
this.context = context;
|
||||||
|
this.auditReadPlatformService = auditReadPlatformService;
|
||||||
|
this.apiRequestParameterHelper = apiRequestParameterHelper;
|
||||||
|
this.toApiJsonSerializer = toApiJsonSerializer;
|
||||||
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Consumes({ MediaType.APPLICATION_JSON })
|
@Consumes({ MediaType.APPLICATION_JSON })
|
||||||
@Produces({ MediaType.APPLICATION_JSON })
|
@Produces({ MediaType.APPLICATION_JSON })
|
||||||
public String retrieveAuditEntries(@Context final UriInfo uriInfo) {
|
public String retrieveAuditEntries(@Context final UriInfo uriInfo) {
|
||||||
|
|
||||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
context.authenticatedUser().validateHasReadPermission(
|
||||||
/*
|
resourceNameForPermissions);
|
||||||
final Collection<CommandSourceData> entries = this.readPlatformService.retrieveAllEntriesToBeChecked();
|
|
||||||
|
|
||||||
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
// final String extraCriteria = getCriteria(sqlSearch, officeId,
|
||||||
return this.toApiJsonSerializer.serialize(settings, entries, RESPONSE_DATA_PARAMETERS);
|
// externalId, displayName, firstName, lastName, hierarchy);
|
||||||
*/
|
|
||||||
return "nothing";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
final Collection<AuditData> auditEntries = this.auditReadPlatformService
|
||||||
|
.retrieveAuditEntries();
|
||||||
|
|
||||||
|
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper
|
||||||
|
.process(uriInfo.getQueryParameters());
|
||||||
|
return this.toApiJsonSerializer.serialize(settings, auditEntries,
|
||||||
|
RESPONSE_DATA_PARAMETERS);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package org.mifosplatform.audit.api;
|
||||||
|
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Immutable data object representing client data.
|
||||||
|
*/
|
||||||
|
final public class AuditData {
|
||||||
|
|
||||||
|
private final Long id;
|
||||||
|
private final String apiOperation;
|
||||||
|
private final String resource;
|
||||||
|
private final Long resourceId;
|
||||||
|
private final String maker;
|
||||||
|
private final LocalDate madeOnDate;
|
||||||
|
private final String checker;
|
||||||
|
private final LocalDate checkedOnDate;
|
||||||
|
private final String commandAsJson;
|
||||||
|
|
||||||
|
public AuditData(final Long id, final String apiOperation,
|
||||||
|
final String resource, final Long resourceId, final String maker,
|
||||||
|
final LocalDate madeOnDate, final String checker,
|
||||||
|
final LocalDate checkedOnDate, final String commandAsJson) {
|
||||||
|
|
||||||
|
this.id = id;
|
||||||
|
this.apiOperation = apiOperation;
|
||||||
|
this.resource = resource;
|
||||||
|
this.resourceId = resourceId;
|
||||||
|
this.maker = maker;
|
||||||
|
this.madeOnDate = madeOnDate;
|
||||||
|
this.checker = checker;
|
||||||
|
this.checkedOnDate = checkedOnDate;
|
||||||
|
this.commandAsJson = commandAsJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getApiOperation() {
|
||||||
|
return this.apiOperation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResource() {
|
||||||
|
return this.resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getResourceId() {
|
||||||
|
return this.resourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMaker() {
|
||||||
|
return this.maker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getMadeOnDate() {
|
||||||
|
return this.madeOnDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getChecker() {
|
||||||
|
return this.checker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDate getCheckedOnDate() {
|
||||||
|
return this.checkedOnDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommandAsJson() {
|
||||||
|
return this.commandAsJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package org.mifosplatform.audit.api;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public interface AuditReadPlatformService {
|
||||||
|
|
||||||
|
Collection<AuditData> retrieveAuditEntries();
|
||||||
|
|
||||||
|
}
|
||||||
+72
@@ -0,0 +1,72 @@
|
|||||||
|
package org.mifosplatform.audit.api;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.joda.time.LocalDate;
|
||||||
|
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
||||||
|
import org.mifosplatform.infrastructure.core.service.TenantAwareRoutingDataSource;
|
||||||
|
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class AuditReadPlatformServiceImpl implements AuditReadPlatformService {
|
||||||
|
|
||||||
|
private final JdbcTemplate jdbcTemplate;
|
||||||
|
private final PlatformSecurityContext context;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public AuditReadPlatformServiceImpl(final PlatformSecurityContext context,
|
||||||
|
final TenantAwareRoutingDataSource dataSource) {
|
||||||
|
this.context = context;
|
||||||
|
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class AuditMapper implements RowMapper<AuditData> {
|
||||||
|
|
||||||
|
public String schema() {
|
||||||
|
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 "
|
||||||
|
+ " 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";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AuditData mapRow(final ResultSet rs,
|
||||||
|
@SuppressWarnings("unused") final int rowNum)
|
||||||
|
throws SQLException {
|
||||||
|
|
||||||
|
final Long id = rs.getLong("id");
|
||||||
|
final String apiOperation = rs.getString("apiOperation");
|
||||||
|
final String resource = rs.getString("resource");
|
||||||
|
final Long resourceId = JdbcSupport.getLong(rs, "resourceId");
|
||||||
|
final String maker = rs.getString("maker");
|
||||||
|
final LocalDate madeOnDate = JdbcSupport.getLocalDate(rs,
|
||||||
|
"madeOnDate");
|
||||||
|
final String checker = rs.getString("checker");
|
||||||
|
final LocalDate checkedOnDate = JdbcSupport.getLocalDate(rs,
|
||||||
|
"checkedOnDate");
|
||||||
|
final String taskJson = rs.getString("taskJson");
|
||||||
|
return new AuditData(id, apiOperation, resource, resourceId, maker,
|
||||||
|
madeOnDate, checker, checkedOnDate, taskJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<AuditData> retrieveAuditEntries() {
|
||||||
|
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";
|
||||||
|
|
||||||
|
return this.jdbcTemplate.query(sql, rm, new Object[] {});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user