Search in sources :

Example 6 with AuditQueryCallback

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);
    }
}
Also used : HashMap(java.util.HashMap) AuditQueryParameters(org.alfresco.service.cmr.audit.AuditQueryParameters) ArrayList(java.util.ArrayList) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) AuditQueryCallback(org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with AuditQueryCallback

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);
}
Also used : AuditQueryParameters(org.alfresco.service.cmr.audit.AuditQueryParameters) ArrayList(java.util.ArrayList) UserInfo(org.alfresco.rest.api.model.UserInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) Date(java.util.Date) AuditApplication(org.alfresco.service.cmr.audit.AuditService.AuditApplication) AuditEntry(org.alfresco.rest.api.model.AuditEntry) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AuditQueryCallback(org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback) AuditService(org.alfresco.service.cmr.audit.AuditService) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AuditQueryParameters (org.alfresco.service.cmr.audit.AuditQueryParameters)7 AuditQueryCallback (org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)4 Serializable (java.io.Serializable)3 AuditEntry (org.alfresco.rest.api.model.AuditEntry)3 UserInfo (org.alfresco.rest.api.model.UserInfo)3 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)2 AuditApplication (org.alfresco.service.cmr.audit.AuditService.AuditApplication)2 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)2 IOException (java.io.IOException)1 MimetypeMap (org.alfresco.repo.content.MimetypeMap)1 DisabledServiceException (org.alfresco.rest.framework.core.exceptions.DisabledServiceException)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 AuditService (org.alfresco.service.cmr.audit.AuditService)1 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)1 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)1