AnsweredAssumed Answered

Dynamic contraint loading query with searchService

Question asked by anita.platos on Aug 26, 2013
Latest reply on Sep 5, 2013 by anita.platos
I am trying to have a constraint loading its data through a searchService-query. The problem is that when I start the Alfresco, it keeps locked in the query, but it never starts.
This is the code I´m using:
- The java code for constraint:

package org.myproject.mycontraints;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;

public class LoadingMyCombo extends ListOfValuesConstraint {
    private static NodeService nodeService;
    private static SearchService searchService;

    public void initialize() {

    public List<String> getAllowedValues() {
        List<String> allowedValues = getSearchResult();
        return allowedValues;

    private List<String> getSearchResult()
        List<String> allowedValues = new ArrayList<String>();
        String query ="PATH:\"/app:company_home/cm:DOCUMENTS\"";
        ResultSet resultSet = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_SOLR_FTS_ALFRESCO, query);
        for (ResultSetRow row : resultSet)
            allowedValues.add((String)nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_NAME));


        if (allowedValues.size() == 0)

        return allowedValues;

    public void setAllowedValues(List allowedValues) {

    public void evaluateCollection(Collection<Object> collection) {

    public void setNodeService(NodeService nodeService) {
       LoadingMyCombo.nodeService = nodeService;

    public void setSearchService(SearchService searchService) {
       LoadingMyCombo.searchService = searchService;


- The constraint declared in the model:

   <constraint name="prfx:load-my-combo" type="org.myproject.mycontraints.LoadingMyCombo" >
         <parameter name="allowedValues">
         <parameter name="caseSensitive"><value>true</value></parameter>

- The bean to associate with the nodeService

   <bean id="mytests.myconstraints.ConstraintInitializer" class="org.myproject.mycontraints.LoadingMyCombo">
      <property name="nodeService">
         <ref bean="nodeService"/>
      <property name="searchService">
         <ref bean="searchService"/>

Somebody knows if I´m doing something wrong or why it gets locked indefinitely  in the line where it executes the query?. I know that the query is well-done because I tested OK using the Node Browser console.
Thank you in advance