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();
}
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;
}
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;
}
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;
}
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;
}
Aggregations