Search in sources :

Example 51 with ResultSet

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

the class MultiTDemoTest method createCategoriesImpl.

@SuppressWarnings("unchecked")
private void createCategoriesImpl(String tenantDomain) {
    if (tenantDomain.equals(TenantService.DEFAULT_DOMAIN)) {
        Collection<ChildAssociationRef> childAssocs = categoryService.getRootCategories(SPACES_STORE, ContentModel.ASPECT_GEN_CLASSIFIABLE);
        for (ChildAssociationRef childAssoc : childAssocs) {
            if (nodeService.getProperty(childAssoc.getChildRef(), ContentModel.PROP_NAME).equals("CatA")) {
                // re-runnable, else we need to delete the created categories
                return;
            }
        }
    }
    // Find all root categories
    String query = "PATH:\"/cm:generalclassifiable/*\"";
    ResultSet resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, query);
    int cnt = resultSet.length();
    NodeRef catA = createCategory(SPACES_STORE, null, "CatA", "CatA-" + tenantDomain);
    // ignore return
    createCategory(SPACES_STORE, catA, "SubCatA", "SubCatA-" + tenantDomain);
    NodeRef catB = createCategory(SPACES_STORE, null, "CatB", "CatB-" + tenantDomain);
    // ignore return
    createCategory(SPACES_STORE, catB, "SubCatB", "SubCatB-" + tenantDomain);
    cnt = cnt + 2;
    if (tenantDomain.equals(TEST_TENANT_DOMAIN2)) {
        NodeRef catC = createCategory(SPACES_STORE, null, "CatC", "CatC-" + tenantDomain);
        // ignore return
        createCategory(SPACES_STORE, catC, "SubCatC", "SubCatC-" + tenantDomain);
        cnt = cnt + 1;
    }
    resultSet.close();
    // Find all root categories
    resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, query);
    assertEquals(cnt, resultSet.length());
    resultSet.close();
    String queryMembers = "PATH:\"/cm:generalclassifiable//cm:catA/member\"";
    resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, queryMembers);
    assertEquals(0, resultSet.length());
    resultSet.close();
    NodeRef homeSpaceRef = getHomeSpaceFolderNode(AuthenticationUtil.getRunAsUser());
    NodeRef contentRef = addContent(homeSpaceRef, "tqbfjotld.txt", "The quick brown fox jumps over the lazy dog (tenant " + tenantDomain + ")", MimetypeMap.MIMETYPE_TEXT_PLAIN);
    assertFalse(nodeService.hasAspect(contentRef, ContentModel.ASPECT_GEN_CLASSIFIABLE));
    List<NodeRef> categories = (List<NodeRef>) nodeService.getProperty(contentRef, ContentModel.PROP_CATEGORIES);
    assertNull(categories);
    // Classify the node (ie. assign node to a particular category in a classification)
    categories = new ArrayList<NodeRef>(1);
    categories.add(catA);
    HashMap<QName, Serializable> catProps = new HashMap<QName, Serializable>();
    catProps.put(ContentModel.PROP_CATEGORIES, (Serializable) categories);
    nodeService.addAspect(contentRef, ContentModel.ASPECT_GEN_CLASSIFIABLE, catProps);
    assertTrue(nodeService.hasAspect(contentRef, ContentModel.ASPECT_GEN_CLASSIFIABLE));
    categories = (List<NodeRef>) nodeService.getProperty(contentRef, ContentModel.PROP_CATEGORIES);
    assertEquals(1, categories.size());
    // test ETHREEOH-210
    queryMembers = "PATH:\"/cm:generalclassifiable//cm:CatA/member\"";
    resultSet = searchService.query(SPACES_STORE, SearchService.LANGUAGE_LUCENE, queryMembers);
    assertEquals(1, resultSet.length());
    resultSet.close();
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResultSet(org.alfresco.service.cmr.search.ResultSet) List(java.util.List) ArrayList(java.util.ArrayList)

Example 52 with ResultSet

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

the class AbstractTenantRoutingContentStoreTest method createContent.

private NodeRef createContent(ServiceRegistry serviceRegistry) throws Exception {
    AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
    authenticationService.authenticate("admin", "admin".toCharArray());
    SearchService searchService = serviceRegistry.getSearchService();
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
    try {
        ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home\"");
        NodeRef companyHome = resultSet.getNodeRef(0);
        serviceRegistry.getFileFolderService().create(companyHome, "Test", ContentModel.TYPE_FOLDER);
        resultSet.close();
    } catch (Exception e) {
    }
    ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home/cm:Test\"");
    NodeRef node = resultSet.getNodeRef(0);
    resultSet.close();
    // assign name
    String name = "TestContent(" + Thread.currentThread().getName() + " " + System.currentTimeMillis() + ")";
    Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
    contentProps.put(ContentModel.PROP_NAME, name);
    // create content node
    NodeService nodeService = serviceRegistry.getNodeService();
    ChildAssociationRef association = nodeService.createNode(node, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, name), ContentModel.TYPE_CONTENT, contentProps);
    NodeRef content = association.getChildRef();
    // add titled aspect (for Web Client display)
    Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>();
    titledProps.put(ContentModel.PROP_TITLE, name);
    titledProps.put(ContentModel.PROP_DESCRIPTION, name);
    nodeService.addAspect(content, ContentModel.ASPECT_TITLED, titledProps);
    return content;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchService(org.alfresco.service.cmr.search.SearchService) ResultSet(org.alfresco.service.cmr.search.ResultSet) AuthenticationService(org.alfresco.service.cmr.security.AuthenticationService)

Example 53 with ResultSet

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

the class XPathNodeLocator method getNode.

/**
 * {@inheritDoc}
 */
@Override
public NodeRef getNode(NodeRef source, Map<String, Serializable> params) {
    String query = (String) params.get(QUERY_KEY);
    ParameterCheck.mandatoryString("query", query);
    StoreRef store = null;
    if (source != null) {
        store = source.getStoreRef();
    } else {
        String storeType = (String) params.get(STORE_TYPE_KEY);
        String storeId = (String) params.get(STORE_ID_KEY);
        if (storeType != null && storeId != null) {
            store = new StoreRef(storeType, storeId);
        } else
            store = defaultStore;
    }
    try {
        ResultSet results = searchService.query(store, SearchService.LANGUAGE_XPATH, query);
        List<NodeRef> nodes = results.getNodeRefs();
        if (nodes.size() > 0) {
            return nodes.get(0);
        }
    } catch (Exception e) {
        String msg = "Error while searching XPath. StoreRef: " + store + " Query: " + query;
        throw new AlfrescoRuntimeException(msg, e);
    }
    return null;
}
Also used : StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResultSet(org.alfresco.service.cmr.search.ResultSet) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 54 with ResultSet

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

the class InviteSenderTest method mockSearchService.

/**
 * Mocks up a SearchService that will return the template NodeRef when
 * queried.
 *
 * @return SearchService
 */
private SearchService mockSearchService() {
    SearchService searchService = mock(SearchService.class);
    ResultSet results = mock(ResultSet.class);
    List<NodeRef> nodeRefs = Arrays.asList(template);
    when(results.getNodeRefs()).thenReturn(nodeRefs);
    when(searchService.query((SearchParameters) any())).thenReturn(results);
    when(searchService.selectNodes(any(), any(String.class), any(), any(), eq(false))).thenReturn(nodeRefs);
    return searchService;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearchService(org.alfresco.service.cmr.search.SearchService) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Example 55 with ResultSet

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

the class ScriptSearchTest method mockServiceRegistry.

private ServiceRegistry mockServiceRegistry() {
    SearchService searchService = mock(SearchService.class);
    ResultSet results = mock(ResultSet.class);
    List<Pair<String, Integer>> fieldFacets1 = new ArrayList<>();
    fieldFacets1.add(new Pair<>(mimetype1, 1));
    fieldFacets1.add(new Pair<>(mimetype2, 2));
    List<Pair<String, Integer>> fieldFacets2 = new ArrayList<>();
    fieldFacets2.add(new Pair<>(modifier, 1));
    when(results.getFieldFacet(fieldFacet1)).thenReturn(fieldFacets1);
    when(results.getFieldFacet(fieldFacet2)).thenReturn(fieldFacets2);
    when(results.getFacetQueries()).thenReturn(new HashMap<>());
    when(searchService.query((SearchParameters) any())).thenReturn(results);
    FacetLabelDisplayHandlerRegistry displayHandlerRegistry = mock(FacetLabelDisplayHandlerRegistry.class);
    ServiceRegistry services = mock(ServiceRegistry.class);
    when(services.getSearchService()).thenReturn(searchService);
    when(displayHandlerRegistry.getDisplayHandler(fieldFacet1)).thenReturn(new MimetypeOrderDisplayHandler());
    when(displayHandlerRegistry.getDisplayHandler(fieldFacet2)).thenReturn(null);
    SolrFacetHelper solrFacetHelper = mock(SolrFacetHelper.class);
    when(solrFacetHelper.getBucketedFieldFacets()).thenReturn(new HashSet<>());
    when(services.getSolrFacetHelper()).thenReturn(solrFacetHelper);
    when(services.getFacetLabelDisplayHandlerRegistry()).thenReturn(displayHandlerRegistry);
    return services;
}
Also used : SearchService(org.alfresco.service.cmr.search.SearchService) ResultSet(org.alfresco.service.cmr.search.ResultSet) FacetLabelDisplayHandlerRegistry(org.alfresco.repo.search.impl.solr.facet.handler.FacetLabelDisplayHandlerRegistry) ServiceRegistry(org.alfresco.service.ServiceRegistry) Pair(org.alfresco.util.Pair) SolrFacetHelper(org.alfresco.repo.search.impl.solr.facet.SolrFacetHelper)

Aggregations

ResultSet (org.alfresco.service.cmr.search.ResultSet)112 NodeRef (org.alfresco.service.cmr.repository.NodeRef)57 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)49 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)22 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)20 Test (org.junit.Test)20 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)17 QName (org.alfresco.service.namespace.QName)16 StoreRef (org.alfresco.service.cmr.repository.StoreRef)14 ResultSetRow (org.alfresco.service.cmr.search.ResultSetRow)14 HashSet (java.util.HashSet)13 EmptyResultSet (org.alfresco.repo.search.EmptyResultSet)13 SearchService (org.alfresco.service.cmr.search.SearchService)13 NodeService (org.alfresco.service.cmr.repository.NodeService)12 IOException (java.io.IOException)11 List (java.util.List)11 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)11 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)10 PagingLuceneResultSet (org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet)10