use of org.alfresco.service.cmr.search.SearchService in project alfresco-repository by Alfresco.
the class LuceneCategoryServiceImpl method getChildren.
private Collection<ChildAssociationRef> getChildren(NodeRef categoryRef, Mode mode, Depth depth, boolean sortByName, String filter, int fetchSize) {
if (categoryRef == null) {
return Collections.<ChildAssociationRef>emptyList();
}
// for solr
categoryRef = tenantService.getBaseName(categoryRef);
ResultSet resultSet = null;
try {
StringBuilder luceneQuery = new StringBuilder(64);
switch(mode) {
case ALL:
luceneQuery.append("PATH:\"");
luceneQuery.append(buildXPath(nodeService.getPath(categoryRef))).append("/");
if (depth.equals(Depth.ANY)) {
luceneQuery.append("/");
}
luceneQuery.append("*").append("\" ");
break;
case MEMBERS:
luceneQuery.append("PATH:\"");
luceneQuery.append(buildXPath(nodeService.getPath(categoryRef))).append("/");
if (depth.equals(Depth.ANY)) {
luceneQuery.append("/");
}
luceneQuery.append("member").append("\" ");
break;
case SUB_CATEGORIES:
luceneQuery.append("+PATH:\"");
luceneQuery.append(buildXPath(nodeService.getPath(categoryRef))).append("/");
if (depth.equals(Depth.ANY)) {
luceneQuery.append("/");
}
luceneQuery.append("*").append("\" ");
luceneQuery.append("+TYPE:\"" + ContentModel.TYPE_CATEGORY.toString() + "\"");
break;
}
if (filter != null) {
luceneQuery.append(" " + "+@cm\\:name:\"*" + filter + "*\"");
}
// Get a searcher that will include Categories added in this transaction
SearchService searcher = indexerAndSearcher.getSearcher(categoryRef.getStoreRef(), true);
// Perform the search
SearchParameters searchParameters = new SearchParameters();
resultSet = searcher.query(categoryRef.getStoreRef(), "lucene", luceneQuery.toString(), null);
searchParameters.setLanguage("lucene");
if (sortByName) {
searchParameters.addSort("@" + ContentModel.PROP_NAME, true);
}
searchParameters.setQuery(luceneQuery.toString());
searchParameters.setLimit(-1);
searchParameters.setMaxItems(fetchSize);
searchParameters.setLimitBy(LimitBy.FINAL_SIZE);
searchParameters.addStore(categoryRef.getStoreRef());
resultSet = searcher.query(searchParameters);
// Convert from search results to the required Child Assocs
return resultSetToChildAssocCollection(resultSet);
} finally {
if (resultSet != null) {
resultSet.close();
}
}
}
use of org.alfresco.service.cmr.search.SearchService in project alfresco-repository by Alfresco.
the class FFCLoadsOfFiles method doExample.
public static void doExample(ServiceRegistry serviceRegistry) throws Exception {
//
// locate the company home node
//
SearchService searchService = serviceRegistry.getSearchService();
NodeService nodeService = serviceRegistry.getNodeService();
NamespaceService namespaceService = serviceRegistry.getNamespaceService();
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
NodeRef rootNodeRef = nodeService.getRootNode(storeRef);
List<NodeRef> results = searchService.selectNodes(rootNodeRef, "/app:company_home", null, namespaceService, false);
if (results.size() == 0) {
throw new AlfrescoRuntimeException("Can't find /app:company_home");
}
NodeRef companyHomeNodeRef = results.get(0);
results = searchService.selectNodes(companyHomeNodeRef, "./cm:LoadTest", null, namespaceService, false);
final NodeRef loadTestHome;
if (results.size() == 0) {
loadTestHome = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "LoadTest"), ContentModel.TYPE_FOLDER).getChildRef();
} else {
loadTestHome = results.get(0);
}
if ((currentDoc + docsPerTx) > totalNumDocs) {
docsPerTx = totalNumDocs - currentDoc;
}
// Create new Space
String spaceName = "Bulk Load Space (" + System.currentTimeMillis() + ") from " + currentDoc + " to " + (currentDoc + docsPerTx - 1) + " of " + totalNumDocs;
Map<QName, Serializable> spaceProps = new HashMap<QName, Serializable>();
spaceProps.put(ContentModel.PROP_NAME, spaceName);
NodeRef newSpace = nodeService.createNode(loadTestHome, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, spaceName), ContentModel.TYPE_FOLDER, spaceProps).getChildRef();
// create new content node within new Space home
for (int k = 1; k <= docsPerTx; k++) {
currentDoc++;
System.out.println("About to start document " + currentDoc);
// assign name
String name = "BulkLoad (" + System.currentTimeMillis() + ") " + currentDoc;
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(newSpace, 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);
//
// write some content to new node
//
ContentService contentService = serviceRegistry.getContentService();
ContentWriter writer = contentService.getWriter(content, ContentModel.PROP_CONTENT, true);
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
writer.setEncoding("UTF-8");
String text = "This is some text in a doc";
writer.putContent(text);
System.out.println("About to get child assocs ");
// nodeService.getChildAssocs(newSpace);
for (int count = 0; count <= 10000; count++) {
nodeService.getChildAssocs(newSpace);
}
}
// doSearch(searchService);
System.out.println("About to end transaction ");
}
use of org.alfresco.service.cmr.search.SearchService in project alfresco-repository by Alfresco.
the class InviteSenderTest method mockServices.
/**
* @return ServiceRegistry
*/
private ServiceRegistry mockServices() {
ActionService mockActionService = mockActionService();
NodeService mockNodeService = mockNodeService();
PersonService mockPersonService = mockPersonService();
SearchService mockSearchService = mockSearchService();
SiteService mockSiteService = mockSiteService();
FileFolderService mockFileFolderService = mockFileFolderService();
RepoAdminService mockRepoAdminService = mockRepoAdminService();
SysAdminParams sysAdminParams = new SysAdminParamsImpl();
ServiceRegistry services = mock(ServiceRegistry.class);
when(services.getActionService()).thenReturn(mockActionService);
when(services.getNodeService()).thenReturn(mockNodeService);
when(services.getPersonService()).thenReturn(mockPersonService);
when(services.getSearchService()).thenReturn(mockSearchService);
when(services.getSiteService()).thenReturn(mockSiteService);
when(services.getFileFolderService()).thenReturn(mockFileFolderService);
when(services.getSysAdminParams()).thenReturn(sysAdminParams);
when(services.getRepoAdminService()).thenReturn(mockRepoAdminService);
return services;
}
use of org.alfresco.service.cmr.search.SearchService in project alfresco-repository by Alfresco.
the class InviteModeratedSenderTest 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(emailTemplateNodeRef);
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.SearchService in project alfresco-repository by Alfresco.
the class LoadTester method setUp.
@Override
public void setUp() throws Exception {
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
authenticationService = serviceRegistry.getAuthenticationService();
imapService = serviceRegistry.getImapService();
importerService = serviceRegistry.getImporterService();
NodeService nodeService = serviceRegistry.getNodeService();
SearchService searchService = serviceRegistry.getSearchService();
NamespaceService namespaceService = serviceRegistry.getNamespaceService();
PersonService personService = serviceRegistry.getPersonService();
FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
TransactionService transactionService = serviceRegistry.getTransactionService();
PermissionService permissionService = serviceRegistry.getPermissionService();
// start the transaction
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
authenticationService.authenticate(USER_NAME, USER_PASSWORD.toCharArray());
anotherUserName = "test_imap_user";
NodeRef person = personService.getPerson(anotherUserName);
if (person != null) {
personService.deletePerson(anotherUserName);
PropertyMap testUser = new PropertyMap();
testUser.put(ContentModel.PROP_USERNAME, anotherUserName);
testUser.put(ContentModel.PROP_FIRSTNAME, anotherUserName);
testUser.put(ContentModel.PROP_LASTNAME, anotherUserName);
testUser.put(ContentModel.PROP_EMAIL, anotherUserName + "@alfresco.com");
testUser.put(ContentModel.PROP_JOBTITLE, "jobTitle");
personService.createPerson(testUser);
}
if (authenticationService.authenticationExists(anotherUserName)) {
authenticationService.deleteAuthentication(anotherUserName);
}
authenticationService.createAuthentication(anotherUserName, anotherUserName.toCharArray());
user = new AlfrescoImapUser(anotherUserName + "@alfresco.com", anotherUserName, anotherUserName);
String storePath = "workspace://SpacesStore";
String companyHomePathInStore = "/app:company_home";
StoreRef storeRef = new StoreRef(storePath);
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
NodeRef companyHomeNodeRef = nodeRefs.get(0);
ChildApplicationContextFactory imap = (ChildApplicationContextFactory) ctx.getBean("imap");
ApplicationContext imapCtx = imap.getApplicationContext();
ImapServiceImpl imapServiceImpl = (ImapServiceImpl) imapCtx.getBean("imapService");
// Delete test folder
nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_ROOT_FOLDER_NAME, null, namespaceService, false);
if (nodeRefs.size() == 1) {
NodeRef ch = nodeRefs.get(0);
nodeService.deleteNode(ch);
}
// Creating IMAP test folder for IMAP root
LinkedList<String> folders = new LinkedList<String>();
folders.add(TEST_IMAP_ROOT_FOLDER_NAME);
FileFolderServiceImpl.makeFolders(fileFolderService, companyHomeNodeRef, folders, ContentModel.TYPE_FOLDER);
// Setting IMAP root
RepositoryFolderConfigBean imapHome = new RepositoryFolderConfigBean();
imapHome.setStore(storePath);
imapHome.setRootPath(companyHomePathInStore);
imapHome.setFolderPath(TEST_IMAP_ROOT_FOLDER_NAME);
imapServiceImpl.setImapHome(imapHome);
// Starting IMAP
imapServiceImpl.startupInTxn(true);
nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_ROOT_FOLDER_NAME, null, namespaceService, false);
// Used to create User's folder
NodeRef userFolderRef = imapService.getUserImapHomeRef(anotherUserName);
permissionService.setPermission(userFolderRef, anotherUserName, PermissionService.ALL_PERMISSIONS, true);
importTestData("imap/load_test_data.acp", userFolderRef);
reauthenticate(anotherUserName, anotherUserName);
AlfrescoImapFolder testDataFolder = imapService.getOrCreateMailbox(user, TEST_DATA_FOLDER_NAME, true, false);
SimpleStoredMessage m = testDataFolder.getMessages().get(0);
m = testDataFolder.getMessage(m.getUid());
AlfrescoImapFolder folder = imapService.getOrCreateMailbox(user, TEST_FOLDER_NAME, false, true);
logger.info("Creating folders...");
long t = System.currentTimeMillis();
try {
for (int i = 0; i < MESSAGE_QUANTITY; i++) {
System.out.println("i = " + i);
folder.appendMessage(m.getMimeMessage(), new Flags(), new Date());
}
} catch (Exception e) {
logger.error(e, e);
}
t = System.currentTimeMillis() - t;
logger.info("Create time: " + t + " ms (" + t / 1000 + " s (" + t / 60000 + " min))");
txn.commit();
}
Aggregations