Java Code Examples for org.alfresco.service.cmr.search.ResultSet#getNodeRefs()

The following examples show how to use org.alfresco.service.cmr.search.ResultSet#getNodeRefs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiddenAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Searches for nodes in the given store that should be hidden (i.e. match the hidden pattern)
 * and hides them if they are not already hidden.
 * 
 * @param storeRef StoreRef
 */
public void checkHidden(StoreRef storeRef)
{
    for(HiddenFileInfo filter : filters)
    {
        String pattern = filter.getFilter();

        ResultSet rs = searchForName(storeRef, pattern);
        for(NodeRef nodeRef : rs.getNodeRefs())
        {
            if(!hasHiddenAspect(nodeRef))
            {
                hideNode(nodeRef, filter.getVisibilityMask(), true, true, false);
            }
        }
    }
}
 
Example 2
Source File: TaggingServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see org.alfresco.service.cmr.tagging.TaggingService#findTaggedNodes(StoreRef, java.lang.String)
 */
public List<NodeRef> findTaggedNodes(StoreRef storeRef, String tag)
{
    // Lower the case of the tag
    tag = tag.toLowerCase();
    ResultSet resultSet= null;
    
    try
    {
        // Do the search for nodes
        resultSet = this.searchService.query(
            storeRef, 
            SearchService.LANGUAGE_LUCENE, 
            "+PATH:\"/cm:taggable/cm:" + ISO9075.encode(tag) + "/member\"");
        List<NodeRef> nodeRefs = resultSet.getNodeRefs();
        return nodeRefs;
    }
    finally
    {
        if(resultSet != null) {resultSet.close();}
    }
}
 
Example 3
Source File: TaggingServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see org.alfresco.service.cmr.tagging.TaggingService#findTaggedNodes(StoreRef, java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
 */
public List<NodeRef> findTaggedNodes(StoreRef storeRef, String tag, NodeRef nodeRef)
{
    // Lower the case of the tag
    tag = tag.toLowerCase();
    
    // Get path
    Path nodePath = this.nodeService.getPath(nodeRef);
    String pathString = nodePath.toPrefixString(this.namespaceService);
    ResultSet resultSet = null;
    
    try
    {
        // Do query
        resultSet = this.searchService.query(
            storeRef, 
            SearchService.LANGUAGE_LUCENE, 
            "+PATH:\"" + pathString + "//*\" +PATH:\"/cm:taggable/cm:" + ISO9075.encode(tag) + "/member\"");
        List<NodeRef> nodeRefs = resultSet.getNodeRefs();
        return nodeRefs;
    }
    finally
    {
        if(resultSet != null) {resultSet.close();}
    }
}
 
Example 4
Source File: LockServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Get the locks given a store and query string.
 * 
 * @param storeRef      the store reference
 * @param query         the query string
 * @return              the locked nodes
 * @deprecated Uses search and does not report on ephemeral locks.
 */
@Deprecated
private List<NodeRef> getLocks(StoreRef storeRef, String query)
{
    List<NodeRef> result = new ArrayList<NodeRef>();
    ResultSet resultSet = null;
    try
    {
        resultSet = this.searchService.query(
                storeRef,
                SearchService.LANGUAGE_LUCENE, 
                query);
        result = resultSet.getNodeRefs();
    }
    finally
    {
        if (resultSet != null)
        {
            resultSet.close();
        }
    }
    return result;
}
 
Example 5
Source File: PersonServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private List<NodeRef> getPeopleFtsList(String pattern, PagingRequest pagingRequest) throws Throwable
{
    // Think this code is based on org.alfresco.repo.jscript.People.getPeopleImplSearch(String, StringTokenizer, int, int)
    List<NodeRef> people = null;

    SearchParameters params = new SearchParameters();
    params.addQueryTemplate("_PERSON", "|%firstName OR |%lastName OR |%userName");
    params.setDefaultFieldName("_PERSON");

    StringBuilder query = new StringBuilder(256);

    query.append("TYPE:\"").append(ContentModel.TYPE_PERSON).append("\" AND (");

    StringTokenizer t = new StringTokenizer(pattern, " ");

    if (t.countTokens() == 1)
    {
        // fts-alfresco property search i.e. location:"maidenhead"
        query.append('"').append(pattern).append("*\"");
    }
    else
    {
        // multiple terms supplied - look for first and second name etc.
        // assume first term is first name, any more are second i.e.
        // "Fraun van de Wiels"
        // also allow fts-alfresco property search to reduce results
        params.setDefaultOperator(SearchParameters.Operator.AND);
        StringBuilder multiPartNames = new StringBuilder(pattern.length());
        int numOfTokens = t.countTokens();
        int counter = 1;
        String term = null;
        // MNT-8539, in order to support firstname and lastname search
        while (t.hasMoreTokens())
        {
            term = t.nextToken();
            // ALF-11311, in order to support multi-part
            // firstNames/lastNames, we need to use the whole tokenized term for both
            // firstName and lastName
            if (term.endsWith("*"))
            {
                term = term.substring(0, term.lastIndexOf("*"));
            }
            multiPartNames.append("\"");
            multiPartNames.append(term);
            multiPartNames.append("*\"");
            if (numOfTokens > counter)
            {
                multiPartNames.append(' ');
            }
            counter++;
        }
        // ALF-11311, in order to support multi-part firstNames/lastNames,
        // we need to use the whole tokenized term for both firstName and lastName.
        // e.g. "john junior lewis martinez", where "john junior" is the first
        // name and "lewis martinez" is the last name.
        if (multiPartNames.length() > 0)
        {
            query.append("firstName:");
            query.append(multiPartNames);
            query.append(" OR lastName:");
            query.append(multiPartNames);
        }
    }
    query.append(")");

    // define the search parameters
    params.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
    params.addStore(this.storeRef);
    params.setQuery(query.toString());
    if (pagingRequest.getMaxItems() > 0)
    {
        params.setLimitBy(LimitBy.FINAL_SIZE);
        params.setLimit(pagingRequest.getMaxItems());
    }

    ResultSet results = null;
    try
    {
        results = searchService.query(params);
        people = results.getNodeRefs();
    }
    catch (Throwable err)
    {
        if (logger.isDebugEnabled())
        {
            logger.debug("Failed to execute people search: " + query.toString(), err);
        }

        throw err;
    }
    finally
    {
        if (results != null)
        {
            results.close();
        }
    }

    return people;
}
 
Example 6
Source File: SiteServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public List<SiteInfo> findSites(String filter, int size)
{
    List<SiteInfo> result;
    
    NodeRef siteRoot = getSiteRoot();
    if (siteRoot == null)
    {
        result = Collections.emptyList();
    }
    else
    {
        // get the sites that match the specified names
        StringBuilder query = new StringBuilder(128);
        query.append("+TYPE:\"").append(SiteModel.TYPE_SITE).append('"');
        
        final boolean filterIsPresent = filter != null && filter.length() > 0;

        if (filterIsPresent)
        {
            query.append(" AND (");
            String escNameFilter = SearchLanguageConversion.escapeLuceneQuery(filter.replace('"', ' '));
            String[] tokenizedFilter = SearchLanguageConversion.tokenizeString(escNameFilter);
            
            //cm:name
            query.append(" cm:name:\" ");
            for( int i = 0; i < tokenizedFilter.length; i++)
            {
              if (i!=0) //Not first element 
              {
                  query.append("?");
              }
              query.append(tokenizedFilter[i].toLowerCase());
            }
            query.append("*\"");
            
            //cm:title
            query.append(" OR ")
                 .append(" cm:title: (");
            for( int i = 0; i < tokenizedFilter.length; i++)
            {
              if (i!=0) //Not first element 
              {
                  query.append(" AND ");
              }
              query.append("\""+tokenizedFilter[i]+"*\" ");
            }
            query.append(")");

            query.append(" OR cm:description:\"" + escNameFilter + "\"");            
            query.append(")");
        }
        
        SearchParameters sp = new SearchParameters();
        sp.addStore(siteRoot.getStoreRef());
        sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
        sp.setQuery(query.toString());
        if (size > 0)
        {
            sp.setLimit(size);
            sp.setLimitBy(LimitBy.FINAL_SIZE);
        }
        
        if(logger.isDebugEnabled())
        {
           logger.debug("Search parameters are: " + sp);
        }
        
        ResultSet results = null;
        try
        {
            results = this.searchService.query(sp);
            result = new ArrayList<SiteInfo>(results.length());
            for (NodeRef site : results.getNodeRefs())
            {
              result.add(createSiteInfo(site));
            }
        }
        catch (LuceneQueryParserException lqpe)
        {
           //Log the error but suppress is from the user
           logger.error("LuceneQueryParserException with findSites()", lqpe);
           result = Collections.emptyList();
        }
        finally
        {
            if (results != null) results.close();
        }
    }
    
    return result;
}
 
Example 7
Source File: SiteServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public List<SiteInfo> findSites(String filter, String sitePresetFilter, int size)
{
    List<SiteInfo> result;
    
    NodeRef siteRoot = getSiteRoot();
    if (siteRoot == null)
    {
        result = Collections.emptyList();
    }
    else
    {
        // get the sites that match the specified names
        StringBuilder query = new StringBuilder(128);
        query.append("+PARENT:\"").append(siteRoot.toString()).append('"');

        final boolean filterIsPresent = filter != null && filter.length() > 0;
        // The filter string is only used in the Lucene query if it restricts results.
        // A search for name/title/description = "*" does not need to be put into the Lucene query.
        // This allows users to search for "*" in the site-finder.
        final boolean filterIsPresentAndNecessary = filterIsPresent && !filter.equals("*");
        final boolean sitePresetFilterIsPresent = sitePresetFilter != null && sitePresetFilter.length() > 0;
        
        if (filterIsPresentAndNecessary || sitePresetFilterIsPresent)
        {
            query.append(" +(");
            if (filterIsPresentAndNecessary)
            {
                String escNameFilter = SearchLanguageConversion.escapeLuceneQuery(filter.replace('"', ' '));
                
                query.append(" @cm\\:name:\"*" + escNameFilter + "*\"")
                     .append(" @cm\\:title:\"" + escNameFilter + "\"")
                     .append(" @cm\\:description:\"" + escNameFilter + "\"");
            }
            if (sitePresetFilterIsPresent)
            {
                String escPresetFilter = SearchLanguageConversion.escapeLuceneQuery(sitePresetFilter.replace('"', ' '));
                query.append(" @st\\:sitePreset:\"" + escPresetFilter + "\"");
            }
            
            query.append(")");
        }
        
        SearchParameters sp = new SearchParameters();
        sp.addStore(siteRoot.getStoreRef());
        sp.setLanguage(SearchService.LANGUAGE_LUCENE);
        sp.setQuery(query.toString());
        if (size > 0)
        {
            sp.setLimit(size);
            sp.setLimitBy(LimitBy.FINAL_SIZE);
        }
        ResultSet results = this.searchService.query(sp);
        try
        {
            result = new ArrayList<SiteInfo>(results.length());
            for (NodeRef site : results.getNodeRefs())
            {
                // Ignore any node type that is not a "site"
                QName siteClassName = this.nodeService.getType(site);
                if (this.dictionaryService.isSubClass(siteClassName, SiteModel.TYPE_SITE))
                {
                    result.add(createSiteInfo(site));
                }
            }
        }
        finally
        {
            results.close();
        }
    }
    
    return result;
}
 
Example 8
Source File: QuickShareServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Pair<String, NodeRef> getTenantNodeRefFromSharedId(final String sharedId)
{
    NodeRef nodeRef = TenantUtil.runAsDefaultTenant(new TenantRunAsWork<NodeRef>()
    {
        public NodeRef doWork() throws Exception
        {
            return (NodeRef) attributeService.getAttribute(ATTR_KEY_SHAREDIDS_ROOT, sharedId);
        }
    });

    if (nodeRef == null)
    {
        /* TODO
         * Temporary fix for RA-1093 and MNT-16224. The extra lookup should be
         * removed (the same as before, just throw the 'InvalidSharedIdException' exception) when we
         * have a system wide patch to remove the 'shared' aspect of the nodes that have been archived while shared.
         */
        // TMDQ
        final String query = "+TYPE:\"cm:content\" AND +ASPECT:\"qshare:shared\" AND =qshare:sharedId:\"" + sharedId + "\"";
        SearchParameters sp = new SearchParameters();
        sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
        sp.setQuery(query);
        sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);

        List<NodeRef> nodeRefs = null;
        ResultSet results = null;
        try
        {
            results = searchService.query(sp);
            nodeRefs = results.getNodeRefs();
        }
        catch (Exception ex)
        {
            throw new InvalidSharedIdException(sharedId);
        }
        finally
        {
            if (results != null)
            {
                results.close();
            }
        }
        if (nodeRefs.size() != 1)
        {
            throw new InvalidSharedIdException(sharedId);
        }
        nodeRef = tenantService.getName(nodeRefs.get(0));
    }

    // note: relies on tenant-specific (ie. mangled) nodeRef
    String tenantDomain = tenantService.getDomain(nodeRef.getStoreRef().getIdentifier());
    return new Pair<>(tenantDomain, tenantService.getBaseName(nodeRef));
}
 
Example 9
Source File: PatchThumbnailsAsRenditionsGet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
    if (logger.isInfoEnabled())
    {
        logger.debug("Patching legacy thumbnails by applying appropriate rendition aspect");
    }
    List<NodeRef> resultNodeRefs = null; 
    ResultSet types = null;

    try
    {
        types = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, QUERY);
        resultNodeRefs = types.getNodeRefs();
    }
    finally
    {
        if (types != null) {types.close();}
    }
    
    long patchedNodeRefs = 0;
    
    for (NodeRef nodeRef : resultNodeRefs)
    {
        if (nodeService.exists(nodeRef) == false ||
                renditionService.isRendition(nodeRef))
        {
            continue;
        }
        
        // Now add one of the two aspects depending on parent location.
        ChildAssociationRef sourceNode = renditionService.getSourceNode(nodeRef);
        ChildAssociationRef primaryParent = nodeService.getPrimaryParent(nodeRef);
        QName aspectToApply;
        if (primaryParent.getParentRef().equals(sourceNode.getParentRef()))
        {
            aspectToApply = RenditionModel.ASPECT_HIDDEN_RENDITION;
        }
        else
        {
            aspectToApply = RenditionModel.ASPECT_VISIBLE_RENDITION;
        }

        if (logger.isDebugEnabled())
        {
            StringBuilder msg = new StringBuilder();
            msg.append("Applying aspect ")
                .append(aspectToApply)
                .append(" to node ")
                .append(nodeRef);
            logger.debug(msg.toString());
        }
        nodeService.addAspect(nodeRef, aspectToApply, null);
        patchedNodeRefs++;
    }

    Map<String, Object> model = new HashMap<String, Object>();
	model.put("patchedNodeCount", new Long(patchedNodeRefs));
	
    return model;
}
 
Example 10
Source File: QueriesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
public CollectionWithPagingInfo<T> find(Parameters parameters,
    String termName, int minTermLength, String queryTemplateName,
    Sort sort, Map<String, QName> sortParamsToQNames, SortColumn... defaultSort)
{
    SearchParameters sp = new SearchParameters();
    sp.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
    sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    sp.setDefaultFieldName(queryTemplateName);
    
    String term = getTerm(parameters, termName, minTermLength);

    StringBuilder query = new StringBuilder();
    buildQuery(query, term, sp, queryTemplateName);
    sp.setQuery(query.toString());

    Paging paging = parameters.getPaging();
    PagingRequest pagingRequest = Util.getPagingRequest(paging);
    
    List<SortColumn> defaultSortCols = (defaultSort != null ? Arrays.asList(defaultSort) : Collections.emptyList());
    if (sort == IN_QUERY_SORT)
    {
        addSortOrder(parameters, sortParamsToQNames, defaultSortCols, sp);

        sp.setSkipCount(pagingRequest.getSkipCount());
        sp.setMaxItems(pagingRequest.getMaxItems());
    }
    
    ResultSet queryResults = null;
    List<T> collection = null;
    try
    {
        queryResults = searchService.query(sp);
        
        List<NodeRef> nodeRefs = queryResults.getNodeRefs();
        
        if (sort == POST_QUERY_SORT)
        {
            nodeRefs = postQuerySort(parameters, sortParamsToQNames, defaultSortCols, nodeRefs);
        }
        
        collection = newList(nodeRefs.size());
        List<String> includeParam = parameters.getInclude();

        for (NodeRef nodeRef : nodeRefs)
        {
            T t = convert(nodeRef, includeParam);
            collection.add(t);
        }

        if (sort == POST_QUERY_SORT)
        {
            return listPage(collection, paging);
        }
        else
        {
            return CollectionWithPagingInfo.asPaged(paging, collection, queryResults.hasMore(), Long.valueOf(queryResults.getNumberFound()).intValue());
        }
    }
    finally
    {
        if (queryResults != null)
        {
            queryResults.close();
        }
    }
}