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;
}
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;
}
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);
}
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);
}
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)
}
Aggregations