1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.validation;
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.kew.api.extension.ExtensionDefinition;
22 import org.kuali.rice.kew.api.extension.ExtensionRepositoryService;
23 import org.kuali.rice.kew.api.extension.ExtensionUtils;
24 import org.kuali.rice.kew.api.validation.RuleValidationContext;
25 import org.kuali.rice.kew.api.validation.ValidationResults;
26 import org.kuali.rice.kew.framework.validation.RuleValidationAttributeExporterService;
27 import org.kuali.rice.kew.rule.RuleValidationAttribute;
28 import org.springframework.beans.factory.annotation.Required;
29
30
31
32
33
34
35
36 public class RuleValidationAttributeExporterServiceImpl implements RuleValidationAttributeExporterService {
37 private static final Logger LOG = Logger.getLogger(RuleValidationAttributeExporterServiceImpl.class);
38
39 private ExtensionRepositoryService extensionRepositoryService;
40
41 @Required
42 public void setExtensionRepositoryService(ExtensionRepositoryService extensionRepositoryService) {
43 this.extensionRepositoryService = extensionRepositoryService;
44 }
45 private ExtensionRepositoryService getExtensionRepositoryService() {
46 return this.extensionRepositoryService;
47 }
48
49 @Override
50 public ValidationResults validate(String attributeName, RuleValidationContext validationContext) {
51 if (StringUtils.isBlank(attributeName)) {
52 throw new RiceIllegalArgumentException("attribute name was null or blank");
53 }
54 RuleValidationAttribute attr = loadAttribute(attributeName);
55 return attr.validate(validationContext);
56 }
57
58
59
60
61
62
63
64 protected RuleValidationAttribute loadAttribute(String attributeName) {
65 ExtensionDefinition extensionDefinition = getExtensionRepositoryService().getExtensionByName(attributeName);
66 if (extensionDefinition == null) {
67 throw new RiceIllegalArgumentException("Failed to locate a RuleValidationAttribute with the given name: " + attributeName);
68 }
69 RuleValidationAttribute attribute = ExtensionUtils.loadExtension(extensionDefinition);
70 if (attribute == null) {
71 throw new RiceIllegalArgumentException("Failed to load RuleValidationAttribute for: " + extensionDefinition);
72 }
73 return attribute;
74 }
75 }