1 17 package org.alfresco.repo.action.executer; 18 19 import java.io.Serializable ; 20 import java.util.Collection ; 21 import java.util.HashMap ; 22 import java.util.List ; 23 import java.util.Map ; 24 25 import org.alfresco.model.ContentModel; 26 import org.alfresco.repo.action.ParameterDefinitionImpl; 27 import org.alfresco.service.cmr.action.Action; 28 import org.alfresco.service.cmr.action.ParameterDefinition; 29 import org.alfresco.service.cmr.dictionary.DictionaryService; 30 import org.alfresco.service.cmr.dictionary.PropertyDefinition; 31 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 32 import org.alfresco.service.cmr.repository.NodeRef; 33 import org.alfresco.service.cmr.repository.NodeService; 34 import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; 35 import org.alfresco.service.namespace.QName; 36 37 42 public class LinkCategoryActionExecuter extends ActionExecuterAbstractBase 43 { 44 47 public static final String NAME = "link-category"; 48 public static final String PARAM_CATEGORY_ASPECT = "category-aspect"; 49 public static final String PARAM_CATEGORY_VALUE = "category-value"; 50 51 54 private NodeService nodeService; 55 56 59 private DictionaryService dictionaryService; 60 61 66 public void setNodeService(NodeService nodeService) 67 { 68 this.nodeService = nodeService; 69 } 70 71 76 public void setDictionaryService(DictionaryService dictionaryService) 77 { 78 this.dictionaryService = dictionaryService; 79 } 80 81 84 @Override 85 protected void addParameterDefintions(List <ParameterDefinition> paramList) 86 { 87 paramList.add(new ParameterDefinitionImpl(PARAM_CATEGORY_ASPECT, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_CATEGORY_ASPECT))); 88 paramList.add(new ParameterDefinitionImpl(PARAM_CATEGORY_VALUE, DataTypeDefinition.NODE_REF, true, getParamDisplayLabel(PARAM_CATEGORY_VALUE))); 89 } 90 91 94 @Override 95 protected void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) 96 { 97 if (this.nodeService.exists(actionedUponNodeRef) == true) 99 { 100 QName categoryAspect = (QName)ruleAction.getParameterValue(PARAM_CATEGORY_ASPECT); 102 NodeRef categoryValue = (NodeRef)ruleAction.getParameterValue(PARAM_CATEGORY_VALUE); 103 104 if (this.dictionaryService.isSubClass(categoryAspect, ContentModel.ASPECT_CLASSIFIABLE) == true) 106 { 107 QName categoryProperty = null; 109 Map <QName, PropertyDefinition> propertyDefs = this.dictionaryService.getAspect(categoryAspect).getProperties(); 110 for (Map.Entry <QName, PropertyDefinition> entry : propertyDefs.entrySet()) 111 { 112 if (DataTypeDefinition.CATEGORY.equals(entry.getValue().getDataType().getName()) == true) 113 { 114 categoryProperty = entry.getKey(); 116 break; 117 } 118 } 119 120 if (categoryAspect != null) 121 { 122 if (this.nodeService.hasAspect(actionedUponNodeRef, categoryAspect) == false) 123 { 124 Map <QName, Serializable > properties = new HashMap <QName, Serializable >(); 126 properties.put(categoryProperty, categoryValue); 127 this.nodeService.addAspect(actionedUponNodeRef, categoryAspect, properties); 128 } 129 else 130 { 131 Serializable value = this.nodeService.getProperty(actionedUponNodeRef, categoryProperty); 133 Collection <NodeRef> categories = DefaultTypeConverter.INSTANCE.getCollection(NodeRef.class, value); 134 if (categories.contains(categoryValue) == false) 135 { 136 categories.add(categoryValue); 137 this.nodeService.setProperty(actionedUponNodeRef, categoryProperty, (Serializable )categories); 138 } 139 } 140 } 141 } 142 } 143 } 144 } 145 | Popular Tags |