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