1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.impl.extension;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.core.api.CoreConstants;
21 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
22 import org.kuali.rice.kew.api.extension.ExtensionDefinition;
23 import org.kuali.rice.kew.api.extension.ExtensionRepositoryService;
24 import org.kuali.rice.kew.rule.bo.RuleAttribute;
25 import org.kuali.rice.kew.rule.service.RuleAttributeService;
26 import org.w3c.dom.Element;
27
28 import javax.xml.bind.annotation.XmlAccessType;
29 import javax.xml.bind.annotation.XmlAccessorType;
30 import javax.xml.bind.annotation.XmlAnyElement;
31 import javax.xml.bind.annotation.XmlElement;
32 import javax.xml.bind.annotation.XmlRootElement;
33 import javax.xml.bind.annotation.XmlType;
34 import java.util.ArrayList;
35 import java.util.Collection;
36 import java.util.Collections;
37 import java.util.List;
38
39
40
41
42
43
44
45 @XmlRootElement(name = ExtensionRepositoryServiceImpl.Constants.ROOT_ELEMENT_NAME)
46 @XmlAccessorType(XmlAccessType.NONE)
47 @XmlType(name = ExtensionRepositoryServiceImpl.Constants.TYPE_NAME, propOrder = {
48 ExtensionRepositoryServiceImpl.Elements.RULE_ATTRIBUTE_SERVICE,
49 CoreConstants.CommonElements.FUTURE_ELEMENTS
50 })
51 public class ExtensionRepositoryServiceImpl implements ExtensionRepositoryService {
52
53
54
55
56
57 private ExtensionRepositoryServiceImpl() {
58 this.ruleAttributeService = null;
59 }
60
61 @XmlElement(name = Elements.RULE_ATTRIBUTE_SERVICE, required = true)
62 private RuleAttributeService ruleAttributeService;
63
64
65 @Override
66 public ExtensionDefinition getExtensionById(String id) throws RiceIllegalArgumentException {
67 if (StringUtils.isBlank(id)) {
68 throw new RiceIllegalArgumentException("id was null or blank");
69 }
70 RuleAttribute ruleAttribute = ruleAttributeService.findByRuleAttributeId(id);
71 return translateFromRuleAttribute(ruleAttribute);
72 }
73
74
75 @Override
76 public ExtensionDefinition getExtensionByName(String name) throws RiceIllegalArgumentException {
77 if (StringUtils.isBlank(name)) {
78 throw new RiceIllegalArgumentException("name was null or blank");
79 }
80 RuleAttribute ruleAttribute = ruleAttributeService.findByName(name);
81 return translateFromRuleAttribute(ruleAttribute);
82 }
83
84 @Override
85 public List<ExtensionDefinition> getExtensionsByResourceDescriptor(
86 String resourceDescriptor) throws RiceIllegalArgumentException {
87 if (StringUtils.isBlank(resourceDescriptor)) {
88 throw new RiceIllegalArgumentException("resourceDescriptor was null or blank");
89 }
90 List<RuleAttribute> ruleAttributes = ruleAttributeService.findByClassName(resourceDescriptor);
91 if (CollectionUtils.isNotEmpty(ruleAttributes)) {
92 List<ExtensionDefinition> definitions = new ArrayList<ExtensionDefinition>();
93 for (RuleAttribute ruleAttribute : ruleAttributes) {
94 definitions.add(translateFromRuleAttribute(ruleAttribute));
95 }
96 return Collections.unmodifiableList(definitions);
97 }
98
99 return Collections.emptyList();
100 }
101
102 private ExtensionDefinition translateFromRuleAttribute(RuleAttribute ruleAttribute) {
103 return RuleAttribute.to(ruleAttribute);
104 }
105
106
107
108
109
110 public void setRuleAttributeService(RuleAttributeService ruleAttributeService) {
111 this.ruleAttributeService = ruleAttributeService;
112 }
113
114 @SuppressWarnings("unused")
115 @XmlAnyElement
116 private final Collection<Element> _futureElements = null;
117
118
119
120
121
122 static class Constants {
123 static final String ROOT_ELEMENT_NAME = "extensionRepositoryService";
124 static final String TYPE_NAME = "ExtensionRepositoryService";
125 }
126
127
128
129
130
131 static class Elements {
132 static final String RULE_ATTRIBUTE_SERVICE = "ruleAttributeService";
133 }
134 }