Merged 5.2.N-AUDIT-API (5.2.2) to 5.2.N (5.2.2)

137930 anechifor: REPO-2555 audit-entries retrieve


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@137973 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2017-07-12 12:11:09 +00:00
parent 97299a3616
commit 1b35b79dfa
2 changed files with 46 additions and 10 deletions

View File

@@ -46,6 +46,7 @@ public interface Audit
String VALUES_KEY = "valuesKey"; String VALUES_KEY = "valuesKey";
String CREATED_BY_USER = "createdByUser"; String CREATED_BY_USER = "createdByUser";
String CREATED_AT = "createdAt"; String CREATED_AT = "createdAt";
String ID = "id";
/** /**
* Gets a single audit application by id * Gets a single audit application by id

View File

@@ -26,6 +26,7 @@
package org.alfresco.rest.api.impl; package org.alfresco.rest.api.impl;
import java.io.Serializable; import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@@ -59,6 +60,8 @@ import org.alfresco.service.cmr.audit.AuditService;
import org.alfresco.service.cmr.audit.AuditService.AuditApplication; import org.alfresco.service.cmr.audit.AuditService.AuditApplication;
import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback; import org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback;
import org.alfresco.util.Pair; import org.alfresco.util.Pair;
import org.apache.commons.beanutils.ConvertUtils;
import org.springframework.extensions.surf.util.ISO8601DateFormat;
/** /**
* Handles audit (applications & entries) * Handles audit (applications & entries)
@@ -195,6 +198,8 @@ public class AuditImpl implements Audit
entriesAudit = getQueryResultAuditEntries(auditAppId, propertyWalker, MAX_ITEMS_AUDIT_ENTRIES, forward); entriesAudit = getQueryResultAuditEntries(auditAppId, propertyWalker, MAX_ITEMS_AUDIT_ENTRIES, forward);
} }
// clear null elements
entriesAudit.removeAll(Collections.singleton(null));
// paging // paging
Paging paging = parameters.getPaging(); Paging paging = parameters.getPaging();
@@ -256,9 +261,13 @@ public class AuditImpl implements Audit
*/ */
private static class AuditEntryQueryWalker extends MapBasedQueryWalker private static class AuditEntryQueryWalker extends MapBasedQueryWalker
{ {
private Long fromTime; private String fromTime;
private Long toTime; private String toTime;
private Long fromId;
private Long toId;
public AuditEntryQueryWalker() public AuditEntryQueryWalker()
{ {
@@ -276,17 +285,23 @@ public class AuditImpl implements Audit
{ {
if (propertyName.equals(CREATED_AT)) if (propertyName.equals(CREATED_AT))
{ {
fromTime = new Long(firstValue); fromTime = firstValue;
toTime = new Long(secondValue); toTime = secondValue;
}
if (propertyName.equals(ID))
{
fromId = new Long(firstValue);
toId = new Long(secondValue);
} }
} }
public Long getFromTime() public String getFromTime()
{ {
return fromTime; return fromTime;
} }
public Long getToTime() public String getToTime()
{ {
return toTime; return toTime;
} }
@@ -305,6 +320,17 @@ public class AuditImpl implements Audit
{ {
return getProperty(VALUES_VALUE, WhereClauseParser.EQUALS, String.class); return getProperty(VALUES_VALUE, WhereClauseParser.EQUALS, String.class);
} }
public Long getFromId()
{
return fromId;
}
public Long getToId()
{
return toId;
}
} }
/** /**
@@ -317,9 +343,7 @@ public class AuditImpl implements Audit
*/ */
public List<AuditEntry> getQueryResultAuditEntries(String auditAppId, AuditEntryQueryWalker propertyWalker, int maxItem, Boolean forward) public List<AuditEntry> getQueryResultAuditEntries(String auditAppId, AuditEntryQueryWalker propertyWalker, int maxItem, Boolean forward)
{ {
final List<AuditEntry> results = new ArrayList<AuditEntry>(); final List<AuditEntry> results = new ArrayList<AuditEntry>();
AuditApplication auditApplication = findAuditAppById(auditAppId); AuditApplication auditApplication = findAuditAppById(auditAppId);
if (auditApplication != null) if (auditApplication != null)
{ {
@@ -331,8 +355,17 @@ public class AuditImpl implements Audit
params.setForward(forward); params.setForward(forward);
params.setApplicationName(auditApplicationName); params.setApplicationName(auditApplicationName);
params.setUser(propertyWalker.getCreatedByUser()); params.setUser(propertyWalker.getCreatedByUser());
params.setFromTime(propertyWalker.getFromTime()); if (propertyWalker.getFromTime() != null)
params.setToTime(propertyWalker.getToTime()); {
params.setFromTime(ISO8601DateFormat.parse(propertyWalker.getFromTime().replace(" ","+")).getTime());
}
if (propertyWalker.getToTime() != null)
{
params.setToTime(ISO8601DateFormat.parse(propertyWalker.getToTime().replace(" ","+")).getTime());
}
params.setFromId(propertyWalker.getFromId());
params.setToId(propertyWalker.getToId());
if (propertyWalker.getValuesKey() != null && propertyWalker.getValuesValue() != null) if (propertyWalker.getValuesKey() != null && propertyWalker.getValuesValue() != null)
{ {
params.addSearchKey(propertyWalker.getValuesKey(), propertyWalker.getValuesValue()); params.addSearchKey(propertyWalker.getValuesKey(), propertyWalker.getValuesValue());
@@ -341,6 +374,7 @@ public class AuditImpl implements Audit
// create the callback for auditQuery method // create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback() final AuditQueryCallback callback = new AuditQueryCallback()
{ {
public boolean valuesRequired() public boolean valuesRequired()
{ {
return true; return true;
@@ -353,6 +387,7 @@ public class AuditImpl implements Audit
public boolean handleAuditEntry(Long entryId, String applicationName, String user, long time, Map<String, Serializable> values) public boolean handleAuditEntry(Long entryId, String applicationName, String user, long time, Map<String, Serializable> values)
{ {
AuditEntry auditEntry = new AuditEntry(entryId, auditAppId, new UserInfo(null, user, null), new Date(time), values); AuditEntry auditEntry = new AuditEntry(entryId, auditAppId, new UserInfo(null, user, null), new Date(time), values);
results.add(auditEntry); results.add(auditEntry);
return true; return true;