use of org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback in project alfresco-remote-api by Alfresco.
the class AuditEntryDelete method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>(7);
Long id = getId(req);
if (id == null) {
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "audit.err.entry.id.notProvided");
}
final List<Long> auditEntryIds = new ArrayList<Long>();
// Need to check that the audit entry actually exists - otherwise we get into a concurrency retry loop
AuditQueryParameters params = new AuditQueryParameters();
AuditQueryCallback callback = new AuditQueryCallback() {
@Override
public boolean valuesRequired() {
return false;
}
@Override
public boolean handleAuditEntry(Long entryId, String applicationName, String user, long time, Map<String, Serializable> values) {
auditEntryIds.add(entryId);
return false;
}
@Override
public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) {
return true;
}
};
params.setToId(id);
params.setFromId(id);
auditService.auditQuery(callback, params, 1);
if (auditEntryIds.size() > 0) {
//
int deleted = auditService.clearAudit(auditEntryIds);
model.put(JSON_KEY_DELETED, deleted);
// Done
if (logger.isDebugEnabled()) {
logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
}
return model;
} else {
// Not found
throw new WebScriptException(Status.STATUS_NOT_FOUND, "audit.err.entry.id.notfound", id);
}
}
use of org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback in project alfresco-remote-api by Alfresco.
the class AuditImpl method getAuditEntry.
@Override
public AuditEntry getAuditEntry(String auditAppId, long auditEntryId, Parameters parameters) {
checkEnabled();
AuditService.AuditApplication auditApplication = findAuditAppByIdOr404(auditAppId);
// Execute the query
AuditQueryParameters params = new AuditQueryParameters();
params.setApplicationName(auditApplication.getName());
params.setFromId(auditEntryId);
params.setToId(auditEntryId + 1);
List<String> includeParam = new ArrayList<>();
if (parameters != null) {
includeParam.addAll(parameters.getInclude());
}
// Add values for single get
includeParam.add(PARAM_INCLUDE_VALUES);
final List<AuditEntry> results = new ArrayList<>();
// create the callback for auditQuery method
final AuditQueryCallback callback = new AuditQueryCallback() {
public boolean valuesRequired() {
return ((includeParam != null) && (includeParam.contains(PARAM_INCLUDE_VALUES)));
}
public boolean handleAuditEntryError(Long entryId, String errorMsg, Throwable error) {
throw new AlfrescoRuntimeException("Failed to retrieve audit data.", error);
}
public boolean handleAuditEntry(Long entryId, String applicationName, String userName, long time, Map<String, Serializable> values) {
UserInfo userInfo = Node.lookupUserInfo(userName, new HashMap<>(0), personService);
AuditEntry auditEntry = new AuditEntry(entryId, auditAppId, userInfo, new Date(time), values);
results.add(auditEntry);
return true;
}
};
auditService.auditQuery(callback, params, 1);
if (results.size() != 1) {
throw new EntityNotFoundException("" + auditEntryId);
}
return results.get(0);
}
Aggregations