1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.krms.impl.repository |
17 | |
|
18 | |
import java.util.Map.Entry |
19 | |
|
20 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
21 | |
|
22 | |
import org.kuali.rice.krms.api.repository.term.TermResolverDefinition; |
23 | |
import org.kuali.rice.krms.api.repository.term.TermResolverDefinitionContract; |
24 | |
|
25 | |
public class TermResolverBo extends PersistableBusinessObjectBase implements TermResolverDefinitionContract { |
26 | |
|
27 | |
def String id |
28 | |
def String namespace |
29 | |
def String name |
30 | |
def String contextId |
31 | |
def String typeId |
32 | |
def String outputId |
33 | |
|
34 | |
def TermSpecificationBo output |
35 | |
def Set<TermSpecificationBo> prerequisites |
36 | |
def Set<TermResolverParameterSpecificationBo> parameterSpecifications; |
37 | |
def Set<TermResolverAttributeBo> attributeBos |
38 | |
|
39 | |
public void setParameterNames(Set<String> pns) { |
40 | 0 | if (pns != null) { |
41 | 0 | parameterSpecifications = new HashSet<TermResolverParameterSpecificationBo>(); |
42 | 0 | for (String pn : pns) { |
43 | 0 | TermResolverParameterSpecificationBo paramSpecBo = new TermResolverParameterSpecificationBo(); |
44 | 0 | paramSpecBo.setName(pn); |
45 | 0 | paramSpecBo.setTermResolverId(id); |
46 | 0 | parameterSpecifications.add(paramSpecBo); |
47 | |
} |
48 | |
} |
49 | |
} |
50 | |
|
51 | |
public Set<String> getParameterNames() { |
52 | 0 | Set<String> results = Collections.emptySet(); |
53 | |
|
54 | 0 | if (parameterSpecifications != null && parameterSpecifications.size() > 0) { |
55 | 0 | results = new HashSet<String>(); |
56 | 0 | for (parmSpec in parameterSpecifications) { |
57 | 0 | results.add( parmSpec.name ); |
58 | |
} |
59 | |
} |
60 | 0 | return results; |
61 | |
} |
62 | |
|
63 | |
public Map<String, String> getAttributes() { |
64 | 0 | HashMap<String, String> attributes = new HashMap<String, String>(); |
65 | 0 | for (attr in attributeBos) { |
66 | 0 | attributes.put( attr.attributeDefinition.name, attr.value ) |
67 | |
} |
68 | 0 | return attributes; |
69 | |
} |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
static TermResolverDefinition to(TermResolverBo bo) { |
77 | 0 | if (bo == null) { return null } |
78 | 0 | return org.kuali.rice.krms.api.repository.term.TermResolverDefinition.Builder.create(bo).build() |
79 | |
} |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
static TermResolverBo from(TermResolverDefinition im) { |
87 | 0 | if (im == null) { return null } |
88 | |
|
89 | 0 | TermResolverBo bo = new TermResolverBo() |
90 | 0 | bo.id = im.id |
91 | 0 | bo.namespace = im.namespace |
92 | 0 | bo.name = im.name |
93 | 0 | bo.typeId = im.typeId |
94 | 0 | bo.output = TermSpecificationBo.from(im.output) |
95 | 0 | bo.outputId = im.output.id |
96 | 0 | bo.parameterNames = new HashSet<String>() |
97 | 0 | for (paramName in im.parameterNames) { |
98 | 0 | bo.parameterSpecifications.add(TermResolverParameterSpecificationBo.from(im, paramName)) |
99 | |
} |
100 | 0 | bo.prerequisites = new HashSet<TermSpecificationBo>() |
101 | 0 | for (prereq in im.prerequisites){ |
102 | 0 | bo.prerequisites.add (TermSpecificationBo.from(prereq)) |
103 | |
} |
104 | |
|
105 | |
|
106 | 0 | Set<TermResolverAttributeBo> attrs = new HashSet<TermResolverAttributeBo>(); |
107 | |
|
108 | |
|
109 | 0 | TermResolverAttributeBo attributeBo; |
110 | 0 | for (Entry<String,String> entry : im.getAttributes().entrySet()){ |
111 | 0 | KrmsAttributeDefinitionBo attrDefBo = KrmsRepositoryServiceLocator |
112 | |
.getKrmsAttributeDefinitionService() |
113 | 0 | .getKrmsAttributeBo(entry.getKey(), im.getNamespace()); |
114 | 0 | attributeBo = new TermResolverAttributeBo(); |
115 | 0 | attributeBo.setTermResolverId( im.getId() ); |
116 | 0 | attributeBo.setAttributeDefinitionId( attrDefBo.getId() ); |
117 | 0 | attributeBo.setValue( entry.getValue() ); |
118 | 0 | attributeBo.setAttributeDefinition( attrDefBo ); |
119 | 0 | attrs.add( attributeBo ); |
120 | |
} |
121 | 0 | bo.setAttributeBos(attrs); |
122 | 0 | bo.versionNumber = im.versionNumber |
123 | 0 | return bo |
124 | |
} |
125 | |
public TermSpecificationBo getOutput(){ |
126 | 0 | return output; |
127 | |
} |
128 | |
|
129 | |
} |