Dynamic contraint loading query with searchService
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2013 06:50 AM
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:
- The constraint declared in the model:
- The bean to associate with the nodeService
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
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;import org.alfresco.service.cmr.search.ResultSet;import org.alfresco.service.cmr.search.ResultSetRow;import org.alfresco.service.cmr.search.SearchService; public class LoadingMyCombo extends ListOfValuesConstraint { private static NodeService nodeService; private static SearchService searchService; @Override public void initialize() { } @Override public List<String> getAllowedValues() { List<String> allowedValues = getSearchResult(); super.setAllowedValues(allowedValues); 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)); Collections.sort(allowedValues); if (allowedValues.size() == 0) allowedValues.add(""); return allowedValues; } @SuppressWarnings("unchecked") @Override public void setAllowedValues(List allowedValues) { } @Override 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"> <list> </list> </parameter> <parameter name="caseSensitive"><value>true</value></parameter> </constraint>
- The bean to associate with the nodeService
<bean id="mytests.myconstraints.ConstraintInitializer" class="org.myproject.mycontraints.LoadingMyCombo"> <property name="nodeService"> <ref bean="nodeService"/> </property> <property name="searchService"> <ref bean="searchService"/> </property> </bean>
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
Labels:
- Labels:
-
Archive
10 REPLIES 10

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-10-2014 06:41 AM
Hi Anita,
I had the same yours problem and I resolved him with your suggestions about counter!
Like you said this is not a very elegant solution.
Can you give me an example about the better solution with ftl control you were talking about?
Thank you very much!
I had the same yours problem and I resolved him with your suggestions about counter!
Like you said this is not a very elegant solution.
Can you give me an example about the better solution with ftl control you were talking about?
Thank you very much!
