08-26-2013 06:50 AM
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;
}
}
<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>
<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>
08-27-2013 02:39 AM
08-28-2013 01:16 AM
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class LoadingMyCombo extends ListOfValuesConstraint implements ApplicationContextAware{
private static ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException{
this.applicationContext = applicationContext;
}
@Override
public void initialize() {
}
@Override
public List<String> getAllowedValues() {
List<String> allowedValues = getSearchResult();
super.setAllowedValues(allowedValues);
return allowedValues;
}
private List<String> getSearchResult()
{
NodeService nodeService =(NodeService)applicationContext.getBean("alfresco NodeServiceid");
SearchService searchService = (SearchService)applicationContext.getBean("alfresco searchServcieid");
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;
}
09-02-2013 07:50 AM
public List<String> getAllowedValues() {
conta++;
P.p ("getAllowedValues() "+conta);
if (conta<4) allowedValues = getEmptyList ();
else allowedValues = getSearchResult();
super.setAllowedValues(allowedValues);
return allowedValues;
}
private List getEmptyList ()
{
List valuesResult = new ArrayList();
valuesResult.add("");
return valuesResult;
}
12-18-2015 09:34 AM
09-02-2013 11:18 AM
<bean id="mytests.myconstraints.ConstraintInitializer" class="org.myproject.mycontraints.LoadingMyCombo" depends-on="repositoryEndBootstrapBean">
09-03-2013 05:05 AM
…
import org.alfresco.web.bean.repository.Node;
…
public Node getNode() {return node;}
public void setNode(Node node) {this.node = node;}
…
09-03-2013 05:48 AM
import org.alfresco.web.bean.repository.MapNode;
import org.alfresco.web.bean.repository.Node;
MapNode node = new MapNode(nodeRef);
09-05-2013 08:13 AM
09-05-2013 12:10 PM
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.