1 | |
package org.kuali.rice.krms.impl.repository |
2 | |
|
3 | |
import java.util.Map.Entry |
4 | |
|
5 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
6 | |
import org.kuali.rice.krms.api.repository.context.ContextDefinition; |
7 | |
import org.kuali.rice.krms.api.repository.context.ContextDefinitionContract; |
8 | |
|
9 | |
|
10 | |
public class ContextBo extends PersistableBusinessObjectBase implements ContextDefinitionContract { |
11 | |
|
12 | |
def String id |
13 | |
def String name |
14 | |
def String namespace |
15 | |
def String typeId |
16 | |
def String description |
17 | |
|
18 | |
def Set<AgendaBo> agendas |
19 | |
|
20 | |
def Set<ContextAttributeBo> attributeBos |
21 | |
def Set<ContextValidEventBo> validEvents |
22 | |
def Set<ContextValidActionBo> validActions |
23 | |
|
24 | |
def Long versionNumber |
25 | |
|
26 | |
|
27 | |
@Override |
28 | |
public Set<AgendaBo> getAgendas(){ |
29 | 1 | return agendas |
30 | |
} |
31 | |
|
32 | |
@Override |
33 | |
public Map<String, String> getAttributes() { |
34 | 2 | HashMap<String, String> attributes = new HashMap<String, String>(); |
35 | 2 | for (attr in attributeBos) { |
36 | 0 | attributes.put( attr.attributeDefinition.name, attr.value ) |
37 | |
} |
38 | 2 | return attributes; |
39 | |
} |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
static ContextDefinition to(ContextBo bo) { |
47 | 0 | if (bo == null) { return null } |
48 | 1 | return org.kuali.rice.krms.api.repository.context.ContextDefinition.Builder.create(bo).build() |
49 | |
} |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
static ContextBo from(ContextDefinition im) { |
57 | 0 | if (im == null) { return null } |
58 | |
|
59 | 1 | ContextBo bo = new ContextBo() |
60 | 1 | bo.id = im.id |
61 | 1 | bo.namespace = im.namespace |
62 | 1 | bo.name = im.name |
63 | 1 | bo.typeId = im.typeId |
64 | 1 | bo.description = im.description |
65 | 1 | bo.agendas = new HashSet<AgendaBo>() |
66 | 1 | for (agenda in im.agendas){ |
67 | 0 | bo.agendas.add( AgendaBo.from(agenda) ) |
68 | |
} |
69 | |
|
70 | 1 | Set<ContextAttributeBo> attrs = new HashSet<ContextAttributeBo>(); |
71 | |
|
72 | |
|
73 | 1 | ContextAttributeBo attributeBo; |
74 | 1 | for (Entry<String,String> entry : im.getAttributes().entrySet()){ |
75 | 0 | KrmsAttributeDefinitionBo attrDefBo = KrmsRepositoryServiceLocator |
76 | |
.getKrmsAttributeDefinitionService() |
77 | 0 | .getKrmsAttributeBo(entry.getKey(), im.getNamespace()); |
78 | 0 | attributeBo = new ContextAttributeBo(); |
79 | 0 | attributeBo.setContextId( im.getId() ); |
80 | 0 | attributeBo.setAttributeDefinitionId( attrDefBo.getId() ); |
81 | 0 | attributeBo.setValue( entry.getValue() ); |
82 | 0 | attributeBo.setAttributeDefinition( attrDefBo ); |
83 | 0 | attrs.add( attributeBo ); |
84 | |
} |
85 | 1 | bo.setAttributeBos(attrs); |
86 | |
|
87 | 1 | bo.versionNumber = im.versionNumber |
88 | 1 | return bo |
89 | |
} |
90 | |
} |