07-28-2011 02:43 AM
package my.alfresco.constraint;
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 LuceneSearchListConstraint 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:\"/cm:generalclassifiable//cm:MyCategories/*\"";
ResultSet resultSet = searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, SearchService.LANGUAGE_LUCENE, 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) {
LuceneSearchListConstraint.nodeService = nodeService;
}
public void setSearchService(SearchService searchService) {
LuceneSearchListConstraint.searchService = searchService;
}
}
<bean id="LuceneSearchListConstraintInitializer" class="my.alfresco.constraint.LuceneSearchListConstraint">
<property name="nodeService">
<ref bean="nodeService"/>
</property>
<property name="searchService">
<ref bean="searchService"/>
</property>
</bean>
<constraints>
<constraint name="my:myList" type="my.alfresco.constraint.LuceneSearchListConstraint">
<parameter name="allowedValues">
<list>
</list>
</parameter>
</constraint>
</constraints>
09-05-2011 07:07 AM
07-15-2019 06:29 AM
Hi,
Is this approach working for anyone? Populatinig the dropdown using List of Values Constraint code from datalist.
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.