AnsweredAssumed Answered

Reproducing a node browser query in Java code.

Question asked by sfoster on Feb 14, 2012
Latest reply on Dec 26, 2014 by krunalpatel
Hi,

I'm trying to use the SearchService to retrieve all nodes of a certain type. I tested the query in the node browser, which returns a single noderef as expected. However, I can't reproduce this in Java code.

The lucene query is:  TYPE:"{http://www.adnovate.com/model/projectmanagement/1.0}project"

The Java code I'm using is:


    @Override
    public List<Project> getProjects() {
        RetryingTransactionCallback<List<NodeRef>> searchCallback = new RetryingTransactionCallback<List<NodeRef>>() {
            public List<NodeRef> execute() throws Throwable {
                List<NodeRef> nodeRefs = serviceRegistry
                        .getSearchService()
                        .query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE,
                                SearchService.LANGUAGE_LUCENE,
                                "TYPE:\"" + ProjectManagementModel.TYPE_PROJECT.toString() + "\"")
                        .getNodeRefs();
                return nodeRefs;
            }
        };

        List<Project> projects = new LinkedList<Project>();
        List<NodeRef> nodeRefs = serviceRegistry.getTransactionService()
                .getRetryingTransactionHelper().doInTransaction(searchCallback, true);

        for (NodeRef nodeRef : nodeRefs) {
            projects.add(getProject(nodeRef));
        }

        return projects;
    }

The code was mainly borrowed from the NodeBrowserScript class.

The alfresco version is 4.0.b.

Any help would be much appreciated.

Outcomes