use of org.alfresco.util.ScriptPagingDetails in project alfresco-remote-api by Alfresco.
the class ArchivedNodesDelete method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
// Current user
String userID = AuthenticationUtil.getFullyAuthenticatedUser();
if (userID == null) {
throw new WebScriptException(HttpServletResponse.SC_UNAUTHORIZED, "Web Script [" + req.getServiceMatch().getWebScript().getDescription() + "] requires user authentication.");
}
StoreRef storeRef = parseRequestForStoreRef(req);
NodeRef nodeRef = parseRequestForNodeRef(req);
List<NodeRef> nodesToBePurged = new ArrayList<NodeRef>();
if (nodeRef != null) {
// check if the current user has the permission to purge the node
validatePermission(nodeRef, userID);
// If there is a specific NodeRef, then that is the only Node that should be purged.
// In this case, the NodeRef points to the actual node to be purged i.e. the node in
// the archive store.
nodesToBePurged.add(nodeRef);
} else {
// But if there is no specific NodeRef and instead there is only a StoreRef, then
// all nodes which were originally in that StoreRef should be purged.
// Create paging
ScriptPagingDetails paging = new ScriptPagingDetails(maxSizeView, 0);
PagingResults<NodeRef> result = getArchivedNodesFrom(storeRef, paging, null);
nodesToBePurged.addAll(result.getPage());
}
if (log.isDebugEnabled()) {
log.debug("Purging " + nodesToBePurged.size() + " nodes");
}
// Now having identified the nodes to be purged, we simply have to do it.
nodeArchiveService.purgeArchivedNodes(nodesToBePurged);
model.put(PURGED_NODES, nodesToBePurged);
return model;
}
use of org.alfresco.util.ScriptPagingDetails in project alfresco-remote-api by Alfresco.
the class FacetablePropertiesGet method unprotectedExecuteImpl.
@Override
protected Map<String, Object> unprotectedExecuteImpl(WebScriptRequest req, Status status, Cache cache) {
// We use any provided locale to localise some elements of the webscript response, but not all.
final String userLocaleString = req.getParameter(QUERY_PARAM_LOCALE);
final Locale userLocale = (userLocaleString == null) ? Locale.getDefault() : new Locale(userLocaleString);
// There are multiple defined URIs for this REST endpoint. Some define a "classname" template var.
final Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
final String contentClassName = templateVars.get(TEMPLATE_VAR_CLASSNAME);
final QName contentClassQName;
try {
contentClassQName = contentClassName == null ? null : QName.createQName(contentClassName, namespaceService);
} catch (NamespaceException e) {
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Unrecognised classname: " + contentClassName, e);
}
// Build an FTL model of facetable properties - this includes normal Alfresco properties and also
// 'synthetic' properties like size and mimetype. See below for more details.
final Map<String, Object> model = new HashMap<>();
final SortedSet<FacetablePropertyFTL<?>> facetableProperties;
if (contentClassQName == null) {
facetableProperties = toFacetablePropertyModel(facetService.getFacetableProperties(), userLocale);
final List<SyntheticPropertyDefinition> facetableSyntheticProperties = facetService.getFacetableSyntheticProperties();
facetableProperties.addAll(toFacetablePropertyModel_(facetableSyntheticProperties, userLocale));
} else {
facetableProperties = toFacetablePropertyModel(facetService.getFacetableProperties(contentClassQName), userLocale);
final List<SyntheticPropertyDefinition> facetableSyntheticProperties = facetService.getFacetableSyntheticProperties(contentClassQName);
facetableProperties.addAll(toFacetablePropertyModel_(facetableSyntheticProperties, userLocale));
}
// Always add some hard-coded facetable "properties"
// Note: TAG and SITE are Solr specials and don’t have namespaces
facetableProperties.add(new SpecialFacetablePropertyFTL("TAG", "Tag"));
facetableProperties.add(new SpecialFacetablePropertyFTL("SITE", "Site"));
// The webscript allows for some further filtering of results:
List<ResultFilter> filters = new ArrayList<>();
// Filter by property QName namespace:
final String namespaceFilter = req.getParameter(QUERY_PARAM_NAMESPACE);
if (namespaceFilter != null) {
filters.add(new ResultFilter() {
@Override
public boolean filter(FacetablePropertyFTL<?> facetableProperty) {
final QName propQName = facetableProperty.getQname();
Collection<String> prefixes = namespaceService.getPrefixes(propQName.getNamespaceURI());
return prefixes.contains(namespaceFilter);
}
});
}
List<FacetablePropertyFTL<?>> filteredFacetableProperties = filter(facetableProperties, filters);
if (logger.isDebugEnabled()) {
logger.debug("Retrieved " + facetableProperties.size() + " available facets; filtered to " + filteredFacetableProperties.size());
}
// Create paging
ScriptPagingDetails paging = new ScriptPagingDetails(getNonNegativeIntParameter(req, QUERY_PARAM_MAX_ITEMS, DEFAULT_MAX_ITEMS_PER_PAGE), getNonNegativeIntParameter(req, QUERY_PARAM_SKIP_COUNT, 0));
model.put(PROPERTIES_KEY, ModelUtil.page(filteredFacetableProperties, paging));
model.put("paging", ModelUtil.buildPaging(paging));
return model;
}
use of org.alfresco.util.ScriptPagingDetails in project alfresco-remote-api by Alfresco.
the class ArchivedNodesGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
Map<String, Object> model = new HashMap<String, Object>();
// We want to get all nodes in the archive which were originally
// contained in the following StoreRef.
StoreRef storeRef = parseRequestForStoreRef(req);
// Create paging
ScriptPagingDetails paging = new ScriptPagingDetails(getIntParameter(req, MAX_ITEMS, DEFAULT_MAX_ITEMS_PER_PAGE), getIntParameter(req, SKIP_COUNT, 0));
PagingResults<NodeRef> result = getArchivedNodesFrom(storeRef, paging, req.getParameter(NAME_FILTER));
List<NodeRef> nodeRefs = result.getPage();
List<ArchivedNodeState> deletedNodes = new ArrayList<ArchivedNodeState>(nodeRefs.size());
for (NodeRef archivedNode : nodeRefs) {
ArchivedNodeState state = ArchivedNodeState.create(archivedNode, serviceRegistry);
deletedNodes.add(state);
}
// Now do the paging
// ALF-19111. Note: Archived nodes CQ, supports Paging,
// so no need to use the ModelUtil.page method to build the page again.
model.put(DELETED_NODES, deletedNodes);
// Because we haven't used ModelUtil.page method, we need to set the total items manually.
paging.setTotalItems(deletedNodes.size());
model.put("paging", ModelUtil.buildPaging(paging));
return model;
}
use of org.alfresco.util.ScriptPagingDetails in project alfresco-remote-api by Alfresco.
the class SiteAdminSitesGet method executeImpl.
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
// check the current user access rights
if (!siteService.isSiteAdmin(currentUser)) {
// Note: security, no message to indicate why
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Resource not found.");
}
// Create paging
final ScriptPagingDetails paging = new ScriptPagingDetails(getIntParameter(req, MAX_ITEMS, DEFAULT_MAX_ITEMS_PER_PAGE), getIntParameter(req, SKIP_COUNT, 0));
// request a total count of found items
paging.setRequestTotalCountMax(Integer.MAX_VALUE);
final List<FilterProp> filterProp = getFilterProperties(req.getParameter(NAME_FILTER));
final List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>();
sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_NAME, true));
PagingResults<SiteInfo> pagingResults = AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<PagingResults<SiteInfo>>() {
public PagingResults<SiteInfo> doWork() throws Exception {
return siteService.listSites(filterProp, sortProps, paging);
}
}, AuthenticationUtil.getAdminUserName());
List<SiteInfo> result = pagingResults.getPage();
List<SiteState> sites = new ArrayList<SiteState>(result.size());
for (SiteInfo info : result) {
sites.add(SiteState.create(info, siteService.listMembers(info.getShortName(), null, SiteModel.SITE_MANAGER, 0), currentUser, nodeService, personService));
}
Map<String, Object> sitesData = new HashMap<String, Object>(6);
// Site data
sitesData.put("items", sites);
// Paging data
sitesData.put("count", result.size());
sitesData.put("hasMoreItems", pagingResults.hasMoreItems());
sitesData.put("totalItems", (pagingResults.getTotalResultCount() == null ? -1 : pagingResults.getTotalResultCount().getFirst()));
sitesData.put("skipCount", paging.getSkipCount());
sitesData.put("maxItems", paging.getMaxItems());
// Create the model from the site and pagination data
Map<String, Object> model = new HashMap<String, Object>(1);
model.put("data", sitesData);
return model;
}
Aggregations