| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kew.impl.rule.attribute; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.apache.log4j.Logger; |
| 20 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
| 21 | |
import org.kuali.rice.core.api.uif.RemotableAttributeField; |
| 22 | |
import org.kuali.rice.kew.api.extension.ExtensionDefinition; |
| 23 | |
import org.kuali.rice.kew.api.extension.ExtensionRepositoryService; |
| 24 | |
import org.kuali.rice.kew.api.extension.ExtensionUtils; |
| 25 | |
import org.kuali.rice.kew.api.rule.RoleName; |
| 26 | |
import org.kuali.rice.kew.api.validation.ValidationResults; |
| 27 | |
import org.kuali.rice.kew.exception.WorkflowServiceError; |
| 28 | |
import org.kuali.rice.kew.framework.rule.attribute.WorkflowRuleAttributeHandlerService; |
| 29 | |
import org.kuali.rice.kew.rule.RoleAttribute; |
| 30 | |
import org.kuali.rice.kew.rule.WorkflowRuleAttribute; |
| 31 | |
import org.kuali.rice.kew.rule.WorkflowRuleSearchAttribute; |
| 32 | |
import org.kuali.rice.kew.rule.XmlConfiguredAttribute; |
| 33 | |
import org.kuali.rice.kns.util.FieldUtils; |
| 34 | |
import org.kuali.rice.kns.web.ui.Row; |
| 35 | |
|
| 36 | |
import javax.jws.WebParam; |
| 37 | |
import java.util.ArrayList; |
| 38 | |
import java.util.List; |
| 39 | |
import java.util.Map; |
| 40 | |
|
| 41 | 0 | public class WorkflowRuleAttributeHandlerServiceImpl implements WorkflowRuleAttributeHandlerService { |
| 42 | 0 | private static final Logger LOG = Logger.getLogger(WorkflowRuleAttributeHandlerServiceImpl.class); |
| 43 | |
|
| 44 | |
private ExtensionRepositoryService extensionRepositoryService; |
| 45 | |
|
| 46 | |
@Override |
| 47 | |
public List<RemotableAttributeField> getSearchRows(String attributeName) { |
| 48 | 0 | if (StringUtils.isBlank(attributeName)) { |
| 49 | 0 | throw new RiceIllegalArgumentException("attributeName was null or blank"); |
| 50 | |
} |
| 51 | 0 | Object searchAttribute = loadAttribute(attributeName); |
| 52 | 0 | List<Row> rows = null; |
| 53 | |
|
| 54 | 0 | if (WorkflowRuleSearchAttribute.class.isAssignableFrom(searchAttribute.getClass())) { |
| 55 | 0 | rows = ((WorkflowRuleSearchAttribute)searchAttribute).getSearchRows(); |
| 56 | |
} else { |
| 57 | 0 | rows = ((WorkflowRuleAttribute)searchAttribute).getRuleRows(); |
| 58 | |
} |
| 59 | |
|
| 60 | 0 | return FieldUtils.convertRowsToAttributeFields(rows); |
| 61 | |
} |
| 62 | |
|
| 63 | |
@Override |
| 64 | |
public boolean isWorkflowRuleAttribute(String attributeName) { |
| 65 | 0 | if (StringUtils.isBlank(attributeName)) { |
| 66 | 0 | throw new RiceIllegalArgumentException("attributeName was null or blank"); |
| 67 | |
} |
| 68 | 0 | Object workflowRuleAttribute = loadAttribute(attributeName); |
| 69 | 0 | return workflowRuleAttribute instanceof WorkflowRuleAttribute; |
| 70 | |
} |
| 71 | |
|
| 72 | |
@Override |
| 73 | |
public List<RemotableAttributeField> getRuleRows(String attributeName) { |
| 74 | 0 | if (StringUtils.isBlank(attributeName)) { |
| 75 | 0 | throw new RiceIllegalArgumentException("attributeName was null or blank"); |
| 76 | |
} |
| 77 | 0 | WorkflowRuleAttribute attribute = loadAttribute(attributeName); |
| 78 | 0 | List<Row> rows = attribute.getRuleRows(); |
| 79 | |
|
| 80 | 0 | return FieldUtils.convertRowsToAttributeFields(rows); |
| 81 | |
} |
| 82 | |
|
| 83 | |
@Override |
| 84 | |
public List<RemotableAttributeField> getRoutingDataRows(String attributeName) { |
| 85 | 0 | if (StringUtils.isBlank(attributeName)) { |
| 86 | 0 | throw new RiceIllegalArgumentException("attributeName was null or blank"); |
| 87 | |
} |
| 88 | 0 | WorkflowRuleAttribute attribute = loadAttribute(attributeName); |
| 89 | 0 | List<Row> rows = attribute.getRoutingDataRows(); |
| 90 | |
|
| 91 | 0 | return FieldUtils.convertRowsToAttributeFields(rows); |
| 92 | |
} |
| 93 | |
|
| 94 | |
@Override |
| 95 | |
public ValidationResults validateRoutingData(@WebParam(name = "attributeName") String attributeName, Map<String, String> paramMap) { |
| 96 | 0 | if (StringUtils.isBlank(attributeName)) { |
| 97 | 0 | throw new RiceIllegalArgumentException("attributeName was null or blank"); |
| 98 | |
} |
| 99 | 0 | WorkflowRuleAttribute attribute = loadAttribute(attributeName); |
| 100 | 0 | List<WorkflowServiceError> errors = attribute.validateRoutingData(paramMap); |
| 101 | 0 | ValidationResults.Builder builder = ValidationResults.Builder.create(); |
| 102 | 0 | for (WorkflowServiceError error : errors) { |
| 103 | 0 | builder.addError(error.getArg1(), error.getMessage()); |
| 104 | |
} |
| 105 | 0 | return builder.build(); |
| 106 | |
} |
| 107 | |
|
| 108 | |
@Override |
| 109 | |
public ValidationResults validateSearchData(@WebParam(name = "attributeName") String attributeName, Map<String, String> paramMap) { |
| 110 | 0 | if (StringUtils.isBlank(attributeName)) { |
| 111 | 0 | throw new RiceIllegalArgumentException("attributeName was null or blank"); |
| 112 | |
} |
| 113 | 0 | WorkflowRuleAttribute attribute = loadAttribute(attributeName); |
| 114 | 0 | List<WorkflowServiceError> errors = attribute.validateRoutingData(paramMap); |
| 115 | 0 | ValidationResults.Builder builder = ValidationResults.Builder.create(); |
| 116 | 0 | for (WorkflowServiceError error : errors) { |
| 117 | 0 | builder.addError(error.getArg1(), error.getMessage()); |
| 118 | |
} |
| 119 | 0 | return builder.build(); |
| 120 | |
} |
| 121 | |
|
| 122 | |
@Override |
| 123 | |
public ValidationResults validateRuleData(@WebParam(name = "attributeName") String attributeName, Map<String, String> paramMap) { |
| 124 | 0 | if (StringUtils.isBlank(attributeName)) { |
| 125 | 0 | throw new RiceIllegalArgumentException("customizerName was null or blank"); |
| 126 | |
} |
| 127 | 0 | List<WorkflowServiceError> errors = new ArrayList<WorkflowServiceError>(); |
| 128 | 0 | Object attribute = loadAttribute(attributeName); |
| 129 | 0 | if (WorkflowRuleSearchAttribute.class.isAssignableFrom(attribute.getClass())) { |
| 130 | 0 | errors = ((WorkflowRuleSearchAttribute)attribute).validateSearchData(paramMap); |
| 131 | |
} else { |
| 132 | 0 | errors = ((WorkflowRuleAttribute)attribute).validateRoutingData(paramMap); |
| 133 | |
} |
| 134 | 0 | ValidationResults.Builder builder = ValidationResults.Builder.create(); |
| 135 | 0 | for (WorkflowServiceError error : errors) { |
| 136 | 0 | builder.addError(error.getArg1(), error.getMessage()); |
| 137 | |
} |
| 138 | 0 | return builder.build(); |
| 139 | |
} |
| 140 | |
|
| 141 | |
@Override |
| 142 | |
public List<RoleName> getRoleNames(String attributeName) { |
| 143 | 0 | Object roleAttribute = loadAttribute(attributeName); |
| 144 | 0 | if (!RoleAttribute.class.isAssignableFrom(roleAttribute.getClass())) { |
| 145 | 0 | throw new RiceIllegalArgumentException("Failed to locate a RoleAttribute with the given name: " + attributeName); |
| 146 | |
} |
| 147 | 0 | return ((RoleAttribute)roleAttribute).getRoleNames(); |
| 148 | |
} |
| 149 | |
|
| 150 | |
private WorkflowRuleAttribute loadAttribute(String attributeName) { |
| 151 | 0 | ExtensionDefinition extensionDefinition = getExtensionRepositoryService().getExtensionByName(attributeName); |
| 152 | 0 | if (extensionDefinition == null) { |
| 153 | 0 | throw new RiceIllegalArgumentException("Failed to locate a WorkflowRuleAttribute with the given name: " + attributeName); |
| 154 | |
} |
| 155 | 0 | Object attribute = ExtensionUtils.loadExtension(extensionDefinition); |
| 156 | 0 | if (attribute == null) { |
| 157 | 0 | throw new RiceIllegalArgumentException("Failed to load WorkflowRuleAttribute for: " + extensionDefinition); |
| 158 | |
} |
| 159 | 0 | if (!WorkflowRuleAttribute.class.isAssignableFrom(attribute.getClass())) { |
| 160 | 0 | throw new RiceIllegalArgumentException("Failed to locate a WorkflowRuleAttribute with the given name: " + attributeName); |
| 161 | |
} |
| 162 | 0 | if (attribute instanceof XmlConfiguredAttribute) { |
| 163 | 0 | ((XmlConfiguredAttribute)attribute).setExtensionDefinition(extensionDefinition); |
| 164 | |
} |
| 165 | |
|
| 166 | 0 | return (WorkflowRuleAttribute)attribute; |
| 167 | |
} |
| 168 | |
|
| 169 | |
|
| 170 | |
protected ExtensionRepositoryService getExtensionRepositoryService() { |
| 171 | 0 | return extensionRepositoryService; |
| 172 | |
} |
| 173 | |
|
| 174 | |
public void setExtensionRepositoryService(ExtensionRepositoryService extensionRepositoryService) { |
| 175 | 0 | this.extensionRepositoryService = extensionRepositoryService; |
| 176 | 0 | } |
| 177 | |
} |