Search in sources :

Example 1 with ScriptPagingDetails

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;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ScriptPagingDetails(org.alfresco.util.ScriptPagingDetails)

Example 2 with ScriptPagingDetails

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;
}
Also used : Locale(java.util.Locale) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) SpecialFacetablePropertyFTL(org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.SpecialFacetablePropertyFTL) StandardFacetablePropertyFTL(org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.StandardFacetablePropertyFTL) SyntheticFacetablePropertyFTL(org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.SyntheticFacetablePropertyFTL) SpecialFacetablePropertyFTL(org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.SpecialFacetablePropertyFTL) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) SyntheticPropertyDefinition(org.alfresco.repo.search.impl.solr.facet.SolrFacetService.SyntheticPropertyDefinition) NamespaceException(org.alfresco.service.namespace.NamespaceException) Collection(java.util.Collection) ScriptPagingDetails(org.alfresco.util.ScriptPagingDetails)

Example 3 with ScriptPagingDetails

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;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ScriptPagingDetails(org.alfresco.util.ScriptPagingDetails)

Example 4 with ScriptPagingDetails

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;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) PagingResults(org.alfresco.query.PagingResults) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) FilterTypeString(org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) ScriptPagingDetails(org.alfresco.util.ScriptPagingDetails) Pair(org.alfresco.util.Pair)

Aggregations

ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ScriptPagingDetails (org.alfresco.util.ScriptPagingDetails)4 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 StoreRef (org.alfresco.service.cmr.repository.StoreRef)2 QName (org.alfresco.service.namespace.QName)2 Collection (java.util.Collection)1 Locale (java.util.Locale)1 PagingResults (org.alfresco.query.PagingResults)1 FilterProp (org.alfresco.repo.node.getchildren.FilterProp)1 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)1 FilterTypeString (org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString)1 SyntheticPropertyDefinition (org.alfresco.repo.search.impl.solr.facet.SolrFacetService.SyntheticPropertyDefinition)1 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)1 SpecialFacetablePropertyFTL (org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.SpecialFacetablePropertyFTL)1 StandardFacetablePropertyFTL (org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.StandardFacetablePropertyFTL)1 SyntheticFacetablePropertyFTL (org.alfresco.repo.web.scripts.facet.FacetablePropertyFTL.SyntheticFacetablePropertyFTL)1 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)1 NamespaceException (org.alfresco.service.namespace.NamespaceException)1