1 17 package org.alfresco.repo.action.evaluator; 18 19 import java.io.Serializable ; 20 import java.util.Collection ; 21 import java.util.List ; 22 import java.util.Map ; 23 24 import org.alfresco.model.ContentModel; 25 import org.alfresco.repo.action.ParameterDefinitionImpl; 26 import org.alfresco.service.cmr.action.ActionCondition; 27 import org.alfresco.service.cmr.action.ParameterDefinition; 28 import org.alfresco.service.cmr.dictionary.DictionaryService; 29 import org.alfresco.service.cmr.dictionary.PropertyDefinition; 30 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 31 import org.alfresco.service.cmr.repository.NodeRef; 32 import org.alfresco.service.cmr.repository.NodeService; 33 import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; 34 import org.alfresco.service.namespace.QName; 35 36 41 public class InCategoryEvaluator extends ActionConditionEvaluatorAbstractBase 42 { 43 46 public static final String NAME = "in-category"; 47 public static final String PARAM_CATEGORY_ASPECT = "category-aspect"; 48 public static final String PARAM_CATEGORY_VALUE = "category-value"; 49 50 53 private NodeService nodeService; 54 55 58 private DictionaryService dictionaryService; 59 60 65 public void setNodeService(NodeService nodeService) 66 { 67 this.nodeService = nodeService; 68 } 69 70 75 public void setDictionaryService(DictionaryService dictionaryService) 76 { 77 this.dictionaryService = dictionaryService; 78 } 79 80 83 @Override 84 protected void addParameterDefintions(List <ParameterDefinition> paramList) 85 { 86 paramList.add(new ParameterDefinitionImpl(PARAM_CATEGORY_ASPECT, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_CATEGORY_ASPECT))); 87 paramList.add(new ParameterDefinitionImpl(PARAM_CATEGORY_VALUE, DataTypeDefinition.NODE_REF, true, getParamDisplayLabel(PARAM_CATEGORY_VALUE))); 88 } 89 90 93 @Override 94 protected boolean evaluateImpl( 95 ActionCondition ruleCondition, 96 NodeRef actionedUponNodeRef) 97 { 98 boolean result = false; 99 100 if (this.nodeService.exists(actionedUponNodeRef) == true) 102 { 103 QName categoryAspect = (QName)ruleCondition.getParameterValue(PARAM_CATEGORY_ASPECT); 105 NodeRef categoryValue = (NodeRef)ruleCondition.getParameterValue(PARAM_CATEGORY_VALUE); 106 107 if (this.dictionaryService.isSubClass(categoryAspect, ContentModel.ASPECT_CLASSIFIABLE) == true && 109 this.nodeService.hasAspect(actionedUponNodeRef, categoryAspect) == true) 110 { 111 QName categoryProperty = null; 113 Map <QName, PropertyDefinition> propertyDefs = this.dictionaryService.getAspect(categoryAspect).getProperties(); 114 for (Map.Entry <QName, PropertyDefinition> entry : propertyDefs.entrySet()) 115 { 116 if (DataTypeDefinition.CATEGORY.equals(entry.getValue().getDataType().getName()) == true) 117 { 118 categoryProperty = entry.getKey(); 120 break; 121 } 122 } 123 124 if (categoryProperty != null) 125 { 126 Serializable value = this.nodeService.getProperty(actionedUponNodeRef, categoryProperty); 128 if (value != null) 129 { 130 Collection <NodeRef> actualCategories = DefaultTypeConverter.INSTANCE.getCollection(NodeRef.class, value); 131 for (NodeRef nodeRef : actualCategories) 132 { 133 if (nodeRef != null && nodeRef.equals(categoryValue) == true) 134 { 135 result = true; 136 break; 137 } 138 } 139 } 140 } 141 } 142 143 } 144 145 return result; 146 } 147 } 148 | Popular Tags |