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