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