Search in sources :

Example 6 with AuditApplication

use of org.alfresco.service.cmr.audit.AuditService.AuditApplication in project alfresco-remote-api by Alfresco.

the class AuditClearPost method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>(7);
    String appName = getParamAppName(req);
    if (appName == null) {
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, "audit.err.app.notProvided");
    }
    AuditApplication app = auditService.getAuditApplications().get(appName);
    if (app == null) {
        throw new WebScriptException(Status.STATUS_NOT_FOUND, "audit.err.app.notFound", appName);
    }
    // Get from/to times
    // might be null
    Long fromTime = getParamFromTime(req);
    // might be null
    Long toTime = getParamToTime(req);
    // Clear
    int cleared = auditService.clearAudit(appName, fromTime, toTime);
    model.put(JSON_KEY_CLEARED, cleared);
    // Done
    if (logger.isDebugEnabled()) {
        logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
    }
    return model;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) AuditApplication(org.alfresco.service.cmr.audit.AuditService.AuditApplication)

Example 7 with AuditApplication

use of org.alfresco.service.cmr.audit.AuditService.AuditApplication in project alfresco-remote-api by Alfresco.

the class AuditControlGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>(7);
    String appName = getParamAppName(req);
    String path = getParamPath(req);
    boolean enabledGlobal = auditService.isAuditEnabled();
    Map<String, AuditApplication> appsByName = auditService.getAuditApplications();
    // Check that the application exists
    if (appName != null) {
        if (path == null) {
            throw new WebScriptException(Status.STATUS_BAD_REQUEST, "audit.err.path.notProvided");
        }
        AuditApplication app = appsByName.get(appName);
        if (app == null) {
            throw new WebScriptException(Status.STATUS_NOT_FOUND, "audit.err.app.notFound", appName);
        }
        // Discard all the other applications
        appsByName = Collections.singletonMap(appName, app);
    }
    model.put(JSON_KEY_ENABLED, enabledGlobal);
    model.put(JSON_KEY_APPLICATIONS, appsByName.values());
    // Done
    if (logger.isDebugEnabled()) {
        logger.debug("Result: \n\tRequest: " + req + "\n\tModel: " + model);
    }
    return model;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) AuditApplication(org.alfresco.service.cmr.audit.AuditService.AuditApplication)

Example 8 with AuditApplication

use of org.alfresco.service.cmr.audit.AuditService.AuditApplication in project alfresco-remote-api by Alfresco.

the class AuditImpl method getAuditApps.

@Override
public CollectionWithPagingInfo<AuditApp> getAuditApps(Paging paging) {
    checkEnabled();
    Map<String, AuditService.AuditApplication> auditApplicationsByName = auditService.getAuditApplications();
    Set<String> audAppsName = new TreeSet<String>(auditApplicationsByName.keySet());
    Iterator<String> audAppsNameIt = audAppsName.iterator();
    int skipCount = paging.getSkipCount();
    int maxItems = paging.getMaxItems();
    int totalItems = audAppsName.size();
    int end = skipCount + maxItems;
    if (skipCount >= totalItems) {
        List<AuditApp> empty = Collections.emptyList();
        return CollectionWithPagingInfo.asPaged(paging, empty, false, totalItems);
    }
    List<AuditApp> auditApps = new ArrayList<AuditApp>(totalItems);
    int count = 0;
    for (int i = 0; i < end && audAppsNameIt.hasNext(); i++) {
        String auditAppName = audAppsNameIt.next();
        if (i < skipCount) {
            continue;
        }
        count++;
        AuditApplication auditApplication = auditApplicationsByName.get(auditAppName);
        auditApps.add(new AuditApp(auditApplication.getKey().substring(1), auditApplication.getName(), auditApplication.isEnabled()));
    }
    boolean hasMoreItems = (skipCount + count < totalItems);
    return CollectionWithPagingInfo.asPaged(paging, auditApps, hasMoreItems, totalItems);
}
Also used : AuditApp(org.alfresco.rest.api.model.AuditApp) TreeSet(java.util.TreeSet) AuditApplication(org.alfresco.service.cmr.audit.AuditService.AuditApplication) ArrayList(java.util.ArrayList)

Example 9 with AuditApplication

use of org.alfresco.service.cmr.audit.AuditService.AuditApplication 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)

Example 10 with AuditApplication

use of org.alfresco.service.cmr.audit.AuditService.AuditApplication in project alfresco-remote-api by Alfresco.

the class AuditImpl method deleteAuditEntries.

@Override
public void deleteAuditEntries(String auditAppId, Parameters parameters) {
    checkEnabled();
    AuditService.AuditApplication auditApplication = findAuditAppByIdOr404(auditAppId);
    Query q = parameters.getQuery();
    if ((q == null) || (q.getTree() == null)) {
        throw new InvalidArgumentException("where clause is required to delete audit entries (" + auditAppId + ")");
    }
    // delete via "where" clause
    DeleteAuditEntriesQueryWalker walker = new DeleteAuditEntriesQueryWalker();
    QueryHelper.walk(q, walker);
    Long fromId = walker.getFromId();
    Long toId = walker.getToId();
    validateWhereBetween(auditAppId, fromId, toId);
    Long fromTime = walker.getFromTime();
    Long toTime = walker.getToTime();
    validateWhereBetween(auditAppId, fromTime, toTime);
    if ((fromId != null) && (fromTime != null)) {
        throw new InvalidArgumentException("where clause is invalid - cannot specify both createdAt & id (" + auditAppId + ")");
    }
    if (fromId != null) {
        // ignore
        auditService.clearAuditByIdRange(auditApplication.getName(), fromId, toId);
    // response
    } else if (fromTime != null) {
        // ignore
        auditService.clearAudit(auditApplication.getName(), fromTime, toTime);
    // response
    }
// return success (even if nothing is deleted)
}
Also used : AuditApplication(org.alfresco.service.cmr.audit.AuditService.AuditApplication) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Query(org.alfresco.rest.framework.resource.parameters.where.Query) AuditService(org.alfresco.service.cmr.audit.AuditService)

Aggregations

AuditApplication (org.alfresco.service.cmr.audit.AuditService.AuditApplication)12 AuditService (org.alfresco.service.cmr.audit.AuditService)7 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 AuditApp (org.alfresco.rest.api.model.AuditApp)3 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 Date (java.util.Date)2 Map (java.util.Map)2 AuditEntry (org.alfresco.rest.api.model.AuditEntry)2 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)2 Query (org.alfresco.rest.framework.resource.parameters.where.Query)2 AuditQueryParameters (org.alfresco.service.cmr.audit.AuditQueryParameters)2 AuditQueryCallback (org.alfresco.service.cmr.audit.AuditService.AuditQueryCallback)2 Serializable (java.io.Serializable)1 TreeSet (java.util.TreeSet)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 UserInfo (org.alfresco.rest.api.model.UserInfo)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 Paging (org.alfresco.rest.framework.resource.parameters.Paging)1 TypeConversionException (org.alfresco.service.cmr.repository.datatype.TypeConversionException)1