Search in sources :

Example 56 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-repository by Alfresco.

the class CronScheduledQueryBasedTemplateActionDefinition method getNodes.

@Override
public List<NodeRef> getNodes() {
    LinkedList<NodeRef> nodeRefs = new LinkedList<NodeRef>();
    // Build the actual query string
    String queryTemplate = getQueryTemplate();
    // MNT-11598 workaround: de-escape \$\{foo\} or \#\{foo\}
    if (queryTemplate.contains("\\$\\{") || queryTemplate.contains("\\#\\{")) {
        queryTemplate = queryTemplate.replace("\\$\\{", "${");
        queryTemplate = queryTemplate.replace("\\#\\{", "#{");
        if (queryTemplate.contains("\\}")) {
            queryTemplate = queryTemplate.replace("\\}", "}");
        }
    }
    String query = templateService.processTemplateString(getTemplateActionModelFactory().getTemplateEngine(), queryTemplate, getTemplateActionModelFactory().getModel());
    // Execute the query
    SearchParameters sp = new SearchParameters();
    sp.setLanguage(getQueryLanguage());
    sp.setQuery(query);
    for (String storeRef : getStores()) {
        sp.addStore(new StoreRef(storeRef));
    }
    // Transform the reults into a node list
    ResultSet results = null;
    try {
        results = searchService.query(sp);
        for (ResultSetRow row : results) {
            nodeRefs.add(row.getNodeRef());
        }
    } finally {
        if (results != null) {
            results.close();
        }
    }
    return nodeRefs;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) StoreRef(org.alfresco.service.cmr.repository.StoreRef) ResultSet(org.alfresco.service.cmr.search.ResultSet) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) LinkedList(java.util.LinkedList)

Example 57 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-repository by Alfresco.

the class AuditMethodInterceptorTest method testAuditSearchServiceSearchParametersQuery.

/**
 * Test for <a href="https://issues.alfresco.com/jira/browse/MNT-16748">MNT-16748</a> <br>
 * Use {@link SearchService#query(SearchParameters)} to perform a query.
 */
public void testAuditSearchServiceSearchParametersQuery() throws Exception {
    // Run as admin
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    // Create SearchParameters to be used in query
    SearchParameters sp = new SearchParameters();
    sp.setLanguage(SearchService.LANGUAGE_XPATH);
    sp.setQuery("/app:company_home/app:dictionary");
    sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    // Perform a search
    @SuppressWarnings("unused") ResultSet rs = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<ResultSet>() {

        @Override
        public ResultSet execute() throws Throwable {
            return searchService.query(sp);
        }
    }, true, false);
    // Check the audit entries
    checkAuditEntries(APPLICATION_NAME_MNT_16748, SearchService.LANGUAGE_XPATH, "/app:company_home/app:dictionary", 1);
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Example 58 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-repository by Alfresco.

the class AlfrescoCmisServiceImpl method getCheckedOutDocs.

@Override
public ObjectList getCheckedOutDocs(String repositoryId, String folderId, String filter, String orderBy, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
    long start = System.currentTimeMillis();
    checkRepositoryId(repositoryId);
    // convert BigIntegers to int
    int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
    int skip = (skipCount == null || skipCount.intValue() < 0 ? 0 : skipCount.intValue());
    // prepare query
    SearchParameters params = new SearchParameters();
    params.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
    if (folderId == null) {
        params.setQuery("+=cm:workingCopyOwner:\"" + AuthenticationUtil.getFullyAuthenticatedUser() + "\"");
        params.addStore(connector.getRootStoreRef());
    } else {
        CMISNodeInfo folderInfo = getOrCreateFolderInfo(folderId, "Folder");
        params.setQuery("+=cm:workingCopyOwner:\"" + AuthenticationUtil.getFullyAuthenticatedUser() + "\" AND +=PARENT:\"" + folderInfo.getNodeRef().toString() + "\"");
        params.addStore(folderInfo.getNodeRef().getStoreRef());
    }
    // set up order
    if (orderBy != null) {
        String[] parts = orderBy.split(",");
        for (int i = 0; i < parts.length; i++) {
            String[] sort = parts[i].split(" +");
            if (sort.length < 1) {
                continue;
            }
            PropertyDefinitionWrapper propDef = connector.getOpenCMISDictionaryService().findPropertyByQueryName(sort[0]);
            if (propDef != null) {
                if (propDef.getPropertyDefinition().isOrderable()) {
                    QName sortProp = propDef.getPropertyAccessor().getMappedProperty();
                    if (sortProp != null) {
                        boolean sortAsc = (sort.length == 1) || sort[1].equalsIgnoreCase("asc");
                        params.addSort(propDef.getPropertyLuceneBuilder().getLuceneFieldName(), sortAsc);
                    } else {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Ignore sort property '" + sort[0] + " - mapping not found");
                        }
                    }
                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Ignore sort property '" + sort[0] + " - not orderable");
                    }
                }
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("Ignore sort property '" + sort[0] + " - query name not found");
                }
            }
        }
    }
    // execute query
    ResultSet resultSet = null;
    List<NodeRef> nodeRefs;
    try {
        resultSet = connector.getSearchService().query(params);
        nodeRefs = resultSet.getNodeRefs();
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }
    }
    // collect results
    ObjectListImpl result = new ObjectListImpl();
    List<ObjectData> list = new ArrayList<ObjectData>();
    result.setObjects(list);
    int skipCounter = skip;
    if (max > 0) {
        for (NodeRef nodeRef : nodeRefs) {
            // TODO - perhaps filter by path in the query instead?
            if (connector.filter(nodeRef)) {
                continue;
            }
            if (skipCounter > 0) {
                skipCounter--;
                continue;
            }
            if (list.size() == max) {
                break;
            }
            try {
                // create a CMIS object
                CMISNodeInfo ni = createNodeInfo(nodeRef);
                ObjectData object = connector.createCMISObject(ni, filter, includeAllowableActions, includeRelationships, renditionFilter, false, false);
                boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
                if (isObjectInfoRequired) {
                    getObjectInfo(repositoryId, ni.getObjectId(), includeRelationships);
                }
                // add it
                list.add(object);
            } catch (InvalidNodeRefException e) {
            // ignore invalid objects
            } catch (CmisObjectNotFoundException e) {
            // ignore objects that have not been found (perhaps because their type is unknown to CMIS)
            }
        }
    }
    // has more ?
    result.setHasMoreItems(nodeRefs.size() - skip > list.size());
    logGetObjectsCall("getCheckedOutDocs", start, folderId, list.size(), filter, includeAllowableActions, includeRelationships, renditionFilter, null, extension, skipCount, maxItems, orderBy, null);
    return result;
}
Also used : QName(org.alfresco.service.namespace.QName) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) ArrayList(java.util.ArrayList) CMISNodeInfo(org.alfresco.opencmis.dictionary.CMISNodeInfo) ObjectListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PropertyDefinitionWrapper(org.alfresco.opencmis.dictionary.PropertyDefinitionWrapper) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) ResultSet(org.alfresco.service.cmr.search.ResultSet) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 59 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-repository by Alfresco.

the class HiddenAspect method searchForName.

private ResultSet searchForName(StoreRef storeRef, String name) {
    SearchParameters sp = new SearchParameters();
    sp.addStore(storeRef);
    sp.setLanguage("lucene");
    sp.setQuery("@" + SearchLanguageConversion.escapeLuceneQuery(ContentModel.PROP_NAME.toString()) + ":\"" + name + "\"");
    sp.addLocale(new Locale("en"));
    return searchService.query(sp);
}
Also used : Locale(java.util.Locale) SearchParameters(org.alfresco.service.cmr.search.SearchParameters)

Example 60 with SearchParameters

use of org.alfresco.service.cmr.search.SearchParameters in project alfresco-repository by Alfresco.

the class TaggingServiceImpl method findTaggedNodesAndCountByTagName.

/**
 * @see org.alfresco.service.cmr.tagging.TaggingService#findTaggedNodesAndCountByTagName(StoreRef)
 */
@Override
public List<Pair<String, Integer>> findTaggedNodesAndCountByTagName(StoreRef storeRef) {
    String queryTaggeble = "ASPECT:\"" + ContentModel.ASPECT_TAGGABLE + "\"" + "-ASPECT:\"" + ContentModel.ASPECT_WORKING_COPY + "\"";
    SearchParameters sp = new SearchParameters();
    sp.setQuery(queryTaggeble);
    sp.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp.addStore(storeRef);
    sp.addFieldFacet(new FieldFacet("TAG"));
    ResultSet resultSet = null;
    try {
        // Do the search for nodes
        resultSet = this.searchService.query(sp);
        return resultSet.getFieldFacet("TAG");
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }
    }
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) FieldFacet(org.alfresco.service.cmr.search.SearchParameters.FieldFacet) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Aggregations

SearchParameters (org.alfresco.service.cmr.search.SearchParameters)120 ResultSet (org.alfresco.service.cmr.search.ResultSet)51 Test (org.junit.Test)41 NodeRef (org.alfresco.service.cmr.repository.NodeRef)33 ArrayList (java.util.ArrayList)25 StoreRef (org.alfresco.service.cmr.repository.StoreRef)16 IOException (java.io.IOException)15 HashMap (java.util.HashMap)14 QName (org.alfresco.service.namespace.QName)13 List (java.util.List)12 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)12 JSONObject (org.json.JSONObject)12 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)11 FieldHighlightParameters (org.alfresco.service.cmr.search.FieldHighlightParameters)11 Set (java.util.Set)10 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)10 RangeParameters (org.alfresco.service.cmr.search.RangeParameters)10 JSONArray (org.json.JSONArray)10 JSONTokener (org.json.JSONTokener)10 Locale (java.util.Locale)9