Search in sources :

Example 16 with ResultSet

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

the class RMAfterInvocationProvider method decide.

private QueryEngineResults decide(Authentication authentication, Object object, ConfigAttributeDefinition config, QueryEngineResults returnedObject) {
    Map<Set<String>, ResultSet> map = returnedObject.getResults();
    Map<Set<String>, ResultSet> answer = new HashMap<Set<String>, ResultSet>(map.size(), 1.0f);
    for (Map.Entry<Set<String>, ResultSet> entry : map.entrySet()) {
        ResultSet raw = entry.getValue();
        ResultSet permed;
        if (PagingLuceneResultSet.class.isAssignableFrom(raw.getClass())) {
            permed = decide(authentication, object, config, (PagingLuceneResultSet) raw);
        } else {
            permed = decide(authentication, object, config, raw);
        }
        answer.put(entry.getKey(), permed);
    }
    return new QueryEngineResults(answer);
}
Also used : QueryEngineResults(org.alfresco.repo.search.impl.querymodel.QueryEngineResults) PagingLuceneResultSet(org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet) ResultSet(org.alfresco.service.cmr.search.ResultSet) Set(java.util.Set) FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) BitSet(java.util.BitSet) HashMap(java.util.HashMap) PagingLuceneResultSet(org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet) ResultSet(org.alfresco.service.cmr.search.ResultSet) FilteringResultSet(org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet) PagingLuceneResultSet(org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with ResultSet

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

the class RecordsManagementSearchServiceImpl method search.

/**
 * @see org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchService#search(java.lang.String, java.lang.String, org.alfresco.module.org_alfresco_module_rm.search.RecordsManagementSearchParameters)
 */
@Override
public List<Pair<NodeRef, NodeRef>> search(String siteId, String query, RecordsManagementSearchParameters rmSearchParameters) {
    // build the full RM query
    StringBuilder fullQuery = new StringBuilder(1024);
    fullQuery.append("PATH:\"").append(SITES_SPACE_QNAME_PATH).append("cm:").append(ISO9075.encode(siteId)).append("/cm:documentLibrary//*\"").append(" AND (").append(buildQueryString(query, rmSearchParameters)).append(")");
    // create the search parameters
    SearchParameters searchParameters = new SearchParameters();
    searchParameters.setQuery(fullQuery.toString());
    searchParameters.setLanguage(SearchService.LANGUAGE_FTS_ALFRESCO);
    searchParameters.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    searchParameters.setMaxItems(rmSearchParameters.getMaxItems());
    searchParameters.setNamespace(RecordsManagementModel.RM_URI);
    // set sort
    for (SortItem entry : rmSearchParameters.getSortOrder()) {
        searchParameters.addSort(entry.property.toPrefixString(namespaceService), entry.assc);
    }
    // set templates
    for (Entry<String, String> entry : rmSearchParameters.getTemplates().entrySet()) {
        searchParameters.addQueryTemplate(entry.getKey(), entry.getValue());
    }
    // execute query
    ResultSet resultSet = searchService.query(searchParameters);
    // process results
    List<Pair<NodeRef, NodeRef>> result = new ArrayList<Pair<NodeRef, NodeRef>>(resultSet.length());
    for (ChildAssociationRef childAssoc : resultSet.getChildAssocRefs()) {
        result.add(new Pair<NodeRef, NodeRef>(childAssoc.getParentRef(), childAssoc.getChildRef()));
    }
    // return results
    return result;
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResultSet(org.alfresco.service.cmr.search.ResultSet) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) Pair(org.alfresco.util.Pair)

Example 18 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet in project acs-community-packaging by Alfresco.

the class BrowseBean method searchBrowseNodes.

/**
 * Search for a list of nodes using the specific search context
 *
 * @param searchContext    To use to perform the search
 */
private void searchBrowseNodes(SearchContext searchContext) {
    long startTime = 0;
    if (logger.isDebugEnabled())
        startTime = System.currentTimeMillis();
    // get the searcher object to build the query
    String query = searchContext.buildQuery(getMinimumSearchLength());
    if (query == null) {
        // failed to build a valid query, the user probably did not enter the
        // minimum text required to construct a valid search
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), MSG_SEARCH_MINIMUM), new Object[] { getMinimumSearchLength() }));
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        return;
    }
    // perform the search against the repo
    UserTransaction tx = null;
    ResultSet results = null;
    try {
        tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
        tx.begin();
        // build up the search parameters
        SearchParameters sp = new SearchParameters();
        sp.setLanguage(SearchService.LANGUAGE_LUCENE);
        sp.setQuery(query);
        sp.addStore(Repository.getStoreRef());
        // limit search results size as configured
        int searchLimit = Application.getClientConfig(FacesContext.getCurrentInstance()).getSearchMaxResults();
        if (searchLimit > 0) {
            sp.setLimitBy(LimitBy.FINAL_SIZE);
            sp.setLimit(searchLimit);
        }
        sp.setBulkFetchEnabled(Application.getClientConfig(FacesContext.getCurrentInstance()).isBulkFetchEnabled());
        results = this.getSearchService().query(sp);
        if (logger.isDebugEnabled())
            logger.debug("Search results returned: " + results.length());
        // create a list of items from the results
        this.containerNodes = new ArrayList<Node>(results.length());
        this.contentNodes = new ArrayList<Node>(results.length());
        if (results.length() != 0) {
            // in case of dynamic config, only lookup once
            Set<NodeEventListener> nodeEventListeners = getNodeEventListeners();
            for (ResultSetRow row : results) {
                NodeRef nodeRef = row.getNodeRef();
                if (this.getNodeService().exists(nodeRef)) {
                    // find it's type so we can see if it's a node we are interested in
                    QName type = this.getNodeService().getType(nodeRef);
                    // make sure the type is defined in the data dictionary
                    TypeDefinition typeDef = this.getDictionaryService().getType(type);
                    if (typeDef != null) {
                        MapNode node = null;
                        // look for Space or File nodes
                        if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) && this.getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                            // create our Node representation
                            node = new MapNode(nodeRef, this.getNodeService(), false);
                            node.addPropertyResolver("path", this.resolverPath);
                            node.addPropertyResolver("displayPath", this.resolverDisplayPath);
                            node.addPropertyResolver("icon", this.resolverSpaceIcon);
                            node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                            this.containerNodes.add(node);
                        } else if (this.getDictionaryService().isSubClass(type, ContentModel.TYPE_CONTENT)) {
                            // create our Node representation
                            node = new MapNode(nodeRef, this.getNodeService(), false);
                            setupCommonBindingProperties(node);
                            node.addPropertyResolver("path", this.resolverPath);
                            node.addPropertyResolver("displayPath", this.resolverDisplayPath);
                            this.contentNodes.add(node);
                        } else // look for File Link object node
                        if (ApplicationModel.TYPE_FILELINK.equals(type)) {
                            // create our File Link Node representation
                            node = new MapNode(nodeRef, this.getNodeService(), false);
                            // only display the user has the permissions to navigate to the target of the link
                            NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
                            if (new Node(destRef).hasPermission(PermissionService.READ) == true) {
                                node.addPropertyResolver("url", this.resolverLinkUrl);
                                node.addPropertyResolver("downloadUrl", this.resolverLinkDownload);
                                node.addPropertyResolver("webdavUrl", this.resolverLinkWebdavUrl);
                                node.addPropertyResolver("cifsPath", this.resolverLinkCifsPath);
                                node.addPropertyResolver("fileType16", this.resolverFileType16);
                                node.addPropertyResolver("fileType32", this.resolverFileType32);
                                node.addPropertyResolver("lang", this.resolverLang);
                                node.addPropertyResolver("path", this.resolverPath);
                                node.addPropertyResolver("displayPath", this.resolverDisplayPath);
                                this.contentNodes.add(node);
                            }
                        } else if (ApplicationModel.TYPE_FOLDERLINK.equals(type)) {
                            // create our Folder Link Node representation
                            node = new MapNode(nodeRef, this.getNodeService(), false);
                            // only display the user has the permissions to navigate to the target of the link
                            NodeRef destRef = (NodeRef) node.getProperties().get(ContentModel.PROP_LINK_DESTINATION);
                            if (new Node(destRef).hasPermission(PermissionService.READ) == true) {
                                node.addPropertyResolver("icon", this.resolverSpaceIcon);
                                node.addPropertyResolver("smallIcon", this.resolverSmallIcon);
                                node.addPropertyResolver("path", this.resolverPath);
                                node.addPropertyResolver("displayPath", this.resolverDisplayPath);
                                this.containerNodes.add(node);
                            }
                        }
                        // inform any listeners that a Node wrapper has been created
                        if (node != null) {
                            for (NodeEventListener listener : nodeEventListeners) {
                                listener.created(node, type);
                            }
                        }
                    } else {
                        if (logger.isWarnEnabled())
                            logger.warn("Found invalid object in database: id = " + nodeRef + ", type = " + type);
                    }
                } else {
                    if (logger.isWarnEnabled())
                        logger.warn("Missing object returned from search indexes: id = " + nodeRef + " search query: " + query);
                }
            }
        }
        // commit the transaction
        tx.commit();
    } catch (InvalidNodeRefException refErr) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] { refErr.getNodeRef() }), refErr);
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } catch (SearcherException serr) {
        logger.info("Search failed for: " + query, serr);
        Utils.addErrorMessage(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_QUERY));
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } catch (Throwable err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_SEARCH), new Object[] { err.getMessage() }), err);
        this.containerNodes = Collections.<Node>emptyList();
        this.contentNodes = Collections.<Node>emptyList();
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } finally {
        if (results != null) {
            results.close();
        }
    }
    if (logger.isDebugEnabled()) {
        long endTime = System.currentTimeMillis();
        logger.debug("Time to query and build map nodes: " + (endTime - startTime) + "ms");
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) MapNode(org.alfresco.web.bean.repository.MapNode) SearcherException(org.alfresco.repo.search.SearcherException) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) NodeRef(org.alfresco.service.cmr.repository.NodeRef) SearcherException(org.alfresco.repo.search.SearcherException) ResultSet(org.alfresco.service.cmr.search.ResultSet) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException)

Example 19 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet in project acs-community-packaging by Alfresco.

the class BaseReassignDialog method pickerCallback.

/**
 * Query callback method executed by the Generic Picker component.
 * This method is part of the contract to the Generic Picker, it is up to the backing bean
 * to execute whatever query is appropriate and return the results.
 *
 * @param filterIndex        Index of the filter drop-down selection
 * @param contains           Text from the contains textbox
 *
 * @return An array of SelectItem objects containing the results to display in the picker.
 */
public SelectItem[] pickerCallback(int filterIndex, String contains) {
    FacesContext context = FacesContext.getCurrentInstance();
    // quick exit if not enough characters entered for a search
    String search = contains.trim();
    int searchMin = Application.getClientConfig(context).getPickerSearchMinimum();
    if (search.length() < searchMin) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(context, MSG_SEARCH_MINIMUM), searchMin));
        return new SelectItem[0];
    }
    SelectItem[] items;
    UserTransaction tx = null;
    ResultSet resultSet = null;
    try {
        tx = Repository.getUserTransaction(context, true);
        tx.begin();
        int maxResults = Application.getClientConfig(context).getInviteUsersMaxResults();
        if (maxResults <= 0) {
            maxResults = Utils.getPersonMaxResults();
        }
        List<PersonInfo> persons = getPersonService().getPeople(Utils.generatePersonFilter(contains.trim()), true, Utils.generatePersonSort(), new PagingRequest(maxResults, null)).getPage();
        ArrayList<SelectItem> itemList = new ArrayList<SelectItem>(persons.size());
        for (PersonInfo person : persons) {
            String username = person.getUserName();
            if (AuthenticationUtil.getGuestUserName().equals(username) == false) {
                String firstName = person.getFirstName();
                String lastName = person.getLastName();
                String name = (firstName != null ? firstName : "") + ' ' + (lastName != null ? lastName : "");
                SelectItem item = new SortableSelectItem(username, name + " [" + username + "]", lastName != null ? lastName : username);
                itemList.add(item);
            }
        }
        items = new SelectItem[itemList.size()];
        itemList.toArray(items);
        Arrays.sort(items);
        // commit the transaction
        tx.commit();
    } catch (Throwable err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
        items = new SelectItem[0];
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }
    }
    return items;
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) PersonInfo(org.alfresco.service.cmr.security.PersonService.PersonInfo) ArrayList(java.util.ArrayList) SortableSelectItem(org.alfresco.web.ui.common.SortableSelectItem) PagingRequest(org.alfresco.query.PagingRequest) SortableSelectItem(org.alfresco.web.ui.common.SortableSelectItem) SelectItem(javax.faces.model.SelectItem) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Example 20 with ResultSet

use of org.alfresco.service.cmr.search.ResultSet in project acs-community-packaging by Alfresco.

the class TrashcanDialog method getItems.

/**
 * @return the list of deleted items to display
 */
public List<Node> getItems() {
    // to get deleted items from deleted items store
    // use a search to find the items - also filters by name/username
    List<Node> itemNodes = null;
    UserTransaction tx = null;
    ResultSet results = null;
    try {
        tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
        tx.begin();
        // get the root node to the deleted items store
        if (getArchiveRootRef() != null && property.isShowItems()) {
            String query = buildSearchQuery();
            SearchParameters sp = new SearchParameters();
            sp.setLanguage(SearchService.LANGUAGE_LUCENE);
            sp.setQuery(query);
            // the Archived Node store
            sp.addStore(getArchiveRootRef().getStoreRef());
            results = getSearchService().query(sp);
            itemNodes = new ArrayList<Node>(results.length());
        }
        if (results != null && results.length() != 0) {
            for (ResultSetRow row : results) {
                NodeRef nodeRef = row.getNodeRef();
                if (getNodeService().exists(nodeRef)) {
                    QName type = getNodeService().getType(nodeRef);
                    MapNode node = new MapNode(nodeRef, getNodeService(), false);
                    node.addPropertyResolver("locationPath", resolverLocationPath);
                    node.addPropertyResolver("displayPath", resolverDisplayPath);
                    node.addPropertyResolver("deletedDate", resolverDeletedDate);
                    node.addPropertyResolver("deletedBy", resolverDeletedBy);
                    node.addPropertyResolver("isFolder", resolverIsFolder);
                    if (getDictionaryService().isSubClass(type, ContentModel.TYPE_FOLDER) == true && getDictionaryService().isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                        node.addPropertyResolver("typeIcon", this.resolverSmallIcon);
                    } else {
                        node.addPropertyResolver("typeIcon", this.resolverFileType16);
                    }
                    itemNodes.add(node);
                }
            }
        }
        tx.commit();
    } catch (Throwable err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), new Object[] { err.getMessage() }), err);
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    } finally {
        if (results != null) {
            results.close();
        }
    }
    property.setListedItems((itemNodes != null ? itemNodes : Collections.<Node>emptyList()));
    return property.getListedItems();
}
Also used : UserTransaction(javax.transaction.UserTransaction) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) MapNode(org.alfresco.web.bean.repository.MapNode) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ResultSet(org.alfresco.service.cmr.search.ResultSet)

Aggregations

ResultSet (org.alfresco.service.cmr.search.ResultSet)34 NodeRef (org.alfresco.service.cmr.repository.NodeRef)20 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)20 EmptyResultSet (org.alfresco.repo.search.EmptyResultSet)12 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)12 SearchRequestContext (org.alfresco.rest.api.search.context.SearchRequestContext)11 Test (org.junit.Test)11 SearchQuery (org.alfresco.rest.api.search.model.SearchQuery)10 ArrayList (java.util.ArrayList)9 SearchContext (org.alfresco.rest.api.search.context.SearchContext)9 Matchers.anyString (org.mockito.Matchers.anyString)9 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 ListMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.ListMetric)8 Metric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.Metric)8 PercentileMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.PercentileMetric)8 SimpleMetric (org.alfresco.repo.search.impl.solr.facet.facetsresponse.SimpleMetric)8 QName (org.alfresco.service.namespace.QName)8 NodeService (org.alfresco.service.cmr.repository.NodeService)7 List (java.util.List)6