Search in sources :

Example 6 with FilterProp

use of org.alfresco.repo.node.getchildren.FilterProp in project records-management by Alfresco.

the class FilePlanComponentsApiUtils method getListChildrenFilterProps.

/**
 * Returns a List of filter properties specified by request parameters.
 * @param parameters The {@link Parameters} object to get the parameters passed into the request
 *        including:
 *        - filter, sort & paging params (where, orderBy, skipCount, maxItems)
 * @return The list of {@link FilterProp}. Can be null.
 */
public List<FilterProp> getListChildrenFilterProps(Parameters parameters, Set<String> listFolderChildrenEqualsQueryProperties) {
    List<FilterProp> filterProps = null;
    Query q = parameters.getQuery();
    if (q != null) {
        MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(listFolderChildrenEqualsQueryProperties, null);
        QueryHelper.walk(q, propertyWalker);
        Boolean isPrimary = propertyWalker.getProperty(RMNode.PARAM_ISPRIMARY, WhereClauseParser.EQUALS, Boolean.class);
        if (isPrimary != null) {
            filterProps = new ArrayList<>(1);
            filterProps.add(new FilterPropBoolean(GetChildrenCannedQuery.FILTER_QNAME_NODE_IS_PRIMARY, isPrimary));
        }
        Boolean isClosed = propertyWalker.getProperty(RMNode.PARAM_IS_CLOSED, WhereClauseParser.EQUALS, Boolean.class);
        if (isClosed != null) {
            filterProps = new ArrayList<>(1);
            filterProps.add(new FilterPropBoolean(RecordsManagementModel.PROP_IS_CLOSED, isClosed));
        }
    // TODO see how we can filter for categories that have retention schedule
    // Boolean hasRetentionSchedule = propertyWalker.getProperty(RMNode.PARAM_HAS_RETENTION_SCHEDULE, WhereClauseParser.EQUALS, Boolean.class);
    // if (hasRetentionSchedule != null)
    // {
    // filterProps = new ArrayList<>(1);
    // }
    }
    return filterProps;
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) GetChildrenCannedQuery(org.alfresco.repo.node.getchildren.GetChildrenCannedQuery) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean)

Example 7 with FilterProp

use of org.alfresco.repo.node.getchildren.FilterProp in project alfresco-remote-api by Alfresco.

the class NodesImpl method getListChildrenFilterProps.

/**
 * <p>Returns a List of filter properties specified by request parameters.</p>
 *
 * @param parameters The {@link Parameters} object to get the parameters passed into the request
 *        including:
 *        - filter, sort & paging params (where, orderBy, skipCount, maxItems)
 *        - incFiles, incFolders (both true by default)
 * @return The list of {@link FilterProp}. Can be null.
 */
protected List<FilterProp> getListChildrenFilterProps(final Parameters parameters) {
    List<FilterProp> filterProps = null;
    Query q = parameters.getQuery();
    if (q != null) {
        MapBasedQueryWalker propertyWalker = createListChildrenQueryWalker();
        QueryHelper.walk(q, propertyWalker);
        Boolean isPrimary = propertyWalker.getProperty(PARAM_ISPRIMARY, WhereClauseParser.EQUALS, Boolean.class);
        if (isPrimary != null) {
            filterProps = new ArrayList<>(1);
            filterProps.add(new FilterPropBoolean(GetChildrenCannedQuery.FILTER_QNAME_NODE_IS_PRIMARY, isPrimary));
        }
    }
    return filterProps;
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) GetChildrenCannedQuery(org.alfresco.repo.node.getchildren.GetChildrenCannedQuery) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean)

Example 8 with FilterProp

use of org.alfresco.repo.node.getchildren.FilterProp in project alfresco-remote-api by Alfresco.

the class SitesImpl method getSites.

public CollectionWithPagingInfo<Site> getSites(final Parameters parameters) {
    final BeanPropertiesFilter filter = parameters.getFilter();
    Paging paging = parameters.getPaging();
    PagingRequest pagingRequest = Util.getPagingRequest(paging);
    // pagingRequest.setRequestTotalCountMax(requestTotalCountMax)
    List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>();
    List<SortColumn> sortCols = parameters.getSorting();
    if ((sortCols != null) && (sortCols.size() > 0)) {
        for (SortColumn sortCol : sortCols) {
            QName sortPropQName = SORT_PARAMS_TO_QNAMES.get(sortCol.column);
            if (sortPropQName == null) {
                throw new InvalidArgumentException("Invalid sort field: " + sortCol.column);
            }
            sortProps.add(new Pair<>(sortPropQName, (sortCol.asc ? Boolean.TRUE : Boolean.FALSE)));
        }
    } else {
        // default sort order
        sortProps.add(new Pair<>(ContentModel.PROP_TITLE, Boolean.TRUE));
    }
    List<FilterProp> filterProps = getFilterPropListOfSites(parameters);
    final PagingResults<SiteInfo> pagingResult = siteService.listSites(filterProps, sortProps, pagingRequest);
    final List<SiteInfo> sites = pagingResult.getPage();
    int totalItems = pagingResult.getTotalResultCount().getFirst();
    final String personId = AuthenticationUtil.getFullyAuthenticatedUser();
    List<Site> page = new AbstractList<Site>() {

        @Override
        public Site get(int index) {
            SiteInfo siteInfo = sites.get(index);
            String role = null;
            if (filter.isAllowed(Site.ROLE)) {
                role = siteService.getMembersRole(siteInfo.getShortName(), personId);
            }
            return new Site(siteInfo, role);
        }

        @Override
        public int size() {
            return sites.size();
        }
    };
    return CollectionWithPagingInfo.asPaged(paging, page, pagingResult.hasMoreItems(), totalItems);
}
Also used : AbstractList(java.util.AbstractList) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) QName(org.alfresco.service.namespace.QName) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn) BeanPropertiesFilter(org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter) PagingRequest(org.alfresco.query.PagingRequest) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean) Pair(org.alfresco.util.Pair)

Example 9 with FilterProp

use of org.alfresco.repo.node.getchildren.FilterProp in project alfresco-remote-api by Alfresco.

the class SitesImpl method includeFilter.

// note: currently inclusive and OR-based
private boolean includeFilter(Map<QName, Serializable> propVals, List<FilterProp> filterProps) {
    for (FilterProp filterProp : filterProps) {
        Serializable propVal = propVals.get(filterProp.getPropName());
        if (propVal != null) {
            if ((filterProp instanceof FilterPropString) && (propVal instanceof String)) {
                String val = (String) propVal;
                String filter = (String) filterProp.getPropVal();
                switch((FilterPropString.FilterTypeString) filterProp.getFilterType()) {
                    case STARTSWITH:
                        if (val.startsWith(filter)) {
                            return true;
                        }
                        break;
                    case STARTSWITH_IGNORECASE:
                        if (val.toLowerCase().startsWith(filter.toLowerCase())) {
                            return true;
                        }
                        break;
                    case EQUALS:
                        if (val.equals(filter)) {
                            return true;
                        }
                        break;
                    case EQUALS_IGNORECASE:
                        if (val.equalsIgnoreCase(filter)) {
                            return true;
                        }
                        break;
                    case ENDSWITH:
                        if (val.endsWith(filter)) {
                            return true;
                        }
                        break;
                    case ENDSWITH_IGNORECASE:
                        if (val.toLowerCase().endsWith(filter.toLowerCase())) {
                            return true;
                        }
                        break;
                    case MATCHES:
                        if (val.matches(filter)) {
                            return true;
                        }
                        break;
                    case MATCHES_IGNORECASE:
                        if (val.toLowerCase().matches(filter.toLowerCase())) {
                            return true;
                        }
                        break;
                    default:
                }
            }
        }
        if ((filterProp instanceof FilterPropBoolean) && (propVal instanceof Boolean)) {
            Boolean val = (Boolean) propVal;
            Boolean filter = (Boolean) filterProp.getPropVal();
            return (val == filter);
        }
    }
    return false;
}
Also used : Serializable(java.io.Serializable) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString)

Example 10 with FilterProp

use of org.alfresco.repo.node.getchildren.FilterProp 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

FilterProp (org.alfresco.repo.node.getchildren.FilterProp)12 QName (org.alfresco.service.namespace.QName)6 AbstractList (java.util.AbstractList)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 FilterPropString (org.alfresco.repo.node.getchildren.FilterPropString)5 FilterPropBoolean (org.alfresco.repo.node.getchildren.FilterPropBoolean)4 UserInfo (org.alfresco.rest.api.model.UserInfo)4 Query (org.alfresco.rest.framework.resource.parameters.where.Query)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 Pair (org.alfresco.util.Pair)4 PagingRequest (org.alfresco.query.PagingRequest)3 GetChildrenCannedQuery (org.alfresco.repo.node.getchildren.GetChildrenCannedQuery)3 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)3 Paging (org.alfresco.rest.framework.resource.parameters.Paging)3 MapBasedQueryWalker (org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker)3 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)3 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 SortColumn (org.alfresco.rest.framework.resource.parameters.SortColumn)2