1 17 package org.alfresco.repo.action; 18 19 import java.text.MessageFormat ; 20 import java.util.ArrayList ; 21 import java.util.List ; 22 23 import org.alfresco.i18n.I18NUtil; 24 import org.alfresco.service.cmr.action.ParameterDefinition; 25 import org.alfresco.service.cmr.action.ParameterizedItem; 26 import org.alfresco.service.cmr.action.ParameterizedItemDefinition; 27 import org.alfresco.service.cmr.rule.RuleServiceException; 28 29 36 public abstract class ParameterizedItemAbstractBase extends CommonResourceAbstractBase 37 { 38 41 private static final String ERR_MAND_PROP = "A value for the mandatory parameter {0} has not been set on the rule item {1}"; 42 43 46 private static final String TITLE = "title"; 47 private static final String DESCRIPTION = "description"; 48 private static final String DISPLAY_LABEL = "display-label"; 49 50 53 protected RuntimeActionService runtimeActionService; 54 55 58 public String toString() 59 { 60 StringBuilder sb = new StringBuilder (60); 61 sb.append("ParameterizedItem") 62 .append("[ title='").append(getTitleKey()).append("'") 63 .append(", description='").append(getDescriptionKey()).append("'") 64 .append("]"); 65 return sb.toString(); 66 } 67 68 73 protected List <ParameterDefinition> getParameterDefintions() 74 { 75 List <ParameterDefinition> result = new ArrayList <ParameterDefinition>(); 76 addParameterDefintions(result); 77 return result; 78 } 79 80 85 protected abstract void addParameterDefintions(List <ParameterDefinition> paramList); 86 87 92 public void setRuntimeActionService(RuntimeActionService runtimeActionService) 93 { 94 this.runtimeActionService = runtimeActionService; 95 } 96 97 102 protected String getTitleKey() 103 { 104 return this.name + "." + TITLE; 105 } 106 107 112 protected String getDescriptionKey() 113 { 114 return this.name + "." + DESCRIPTION; 115 } 116 117 122 protected boolean getAdhocPropertiesAllowed() 123 { 124 return false; 126 } 127 128 134 protected String getParamDisplayLabel(String paramName) 135 { 136 return I18NUtil.getMessage(this.name + "." + paramName + "." + DISPLAY_LABEL); 137 } 138 139 145 protected void checkMandatoryProperties(ParameterizedItem ruleItem, ParameterizedItemDefinition ruleItemDefinition) 146 { 147 List <ParameterDefinition> definitions = ruleItemDefinition.getParameterDefinitions(); 148 for (ParameterDefinition definition : definitions) 149 { 150 if (definition.isMandatory() == true) 151 { 152 if (ruleItem.getParameterValue(definition.getName()) == null) 154 { 155 throw new RuleServiceException( 157 MessageFormat.format(ERR_MAND_PROP, new Object []{definition.getName(), ruleItemDefinition.getName()})); 158 } 159 } 160 } 161 162 } 163 } 164 | Popular Tags |