mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged 5.2.N-AUDIT-API (5.2.2) to 5.2.N (5.2.2)
137875 anechifor: REPO-1784 - Retrieve Audit Applications Implementation subtask - REPO-2580 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@137958 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -25,14 +25,23 @@
|
||||
*/
|
||||
package org.alfresco.rest.api.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.alfresco.rest.api.Audit;
|
||||
import org.alfresco.rest.api.model.AuditApp;
|
||||
import org.alfresco.rest.framework.core.exceptions.DisabledServiceException;
|
||||
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Paging;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.service.cmr.audit.AuditService;
|
||||
|
||||
import java.util.Map;
|
||||
import org.alfresco.service.cmr.audit.AuditService.AuditApplication;
|
||||
|
||||
/**
|
||||
* Handles audit (applications & entries)
|
||||
@@ -52,7 +61,7 @@ public class AuditImpl implements Audit
|
||||
|
||||
private void checkEnabled()
|
||||
{
|
||||
if (! auditService.isAuditEnabled())
|
||||
if (!auditService.isAuditEnabled())
|
||||
{
|
||||
throw new DisabledServiceException(DISABLED);
|
||||
}
|
||||
@@ -89,4 +98,46 @@ public class AuditImpl implements Audit
|
||||
}
|
||||
return auditApp;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user