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 | |
import org.kuali.rice.krms.api.repository.context.ContextDefinition; |
8 | |
import org.kuali.rice.krms.api.repository.context.ContextDefinitionContract; |
9 | |
|
10 | |
|
11 | |
public class ContextBo extends PersistableBusinessObjectBase implements ContextDefinitionContract { |
12 | |
|
13 | |
def String id |
14 | |
def String name |
15 | |
def String namespace |
16 | |
def String typeId |
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 | 0 | return agendas |
30 | |
} |
31 | |
|
32 | |
@Override |
33 | |
public Map<String, String> getAttributes() { |
34 | 0 | HashMap<String, String> attributes = new HashMap<String, String>(); |
35 | 0 | for (attr in attributeBos) { |
36 | 0 | attributes.put( attr.attributeDefinition.name, attr.value ) |
37 | |
} |
38 | 0 | return attributes; |
39 | |
} |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
static ContextDefinition to(ContextBo bo) { |
47 | 0 | if (bo == null) { return null } |
48 | 0 | 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 | 0 | ContextBo bo = new ContextBo() |
60 | 0 | bo.id = im.id |
61 | 0 | bo.namespace = im.namespace |
62 | 0 | bo.name = im.name |
63 | 0 | bo.typeId = im.typeId |
64 | 0 | bo.agendas = new HashSet<AgendaBo>() |
65 | 0 | for (agenda in im.agendas){ |
66 | 0 | bo.agendas.add( AgendaBo.from(agenda) ) |
67 | |
} |
68 | |
|
69 | 0 | Set<ContextAttributeBo> attrs = new HashSet<ContextAttributeBo>(); |
70 | |
|
71 | |
|
72 | 0 | ContextAttributeBo attributeBo; |
73 | 0 | for (Entry<String,String> entry : im.getAttributes().entrySet()){ |
74 | 0 | KrmsAttributeDefinitionBo attrDefBo = KrmsRepositoryServiceLocator |
75 | |
.getKrmsAttributeDefinitionService() |
76 | 0 | .getKrmsAttributeBo(entry.getKey(), im.getNamespace()); |
77 | 0 | attributeBo = new ContextAttributeBo(); |
78 | 0 | attributeBo.setContextId( im.getId() ); |
79 | 0 | attributeBo.setAttributeDefinitionId( attrDefBo.getId() ); |
80 | 0 | attributeBo.setValue( entry.getValue() ); |
81 | 0 | attributeBo.setAttributeDefinition( attrDefBo ); |
82 | 0 | attrs.add( attributeBo ); |
83 | |
} |
84 | 0 | bo.setAttributeBos(attrs); |
85 | |
|
86 | 0 | bo.versionNumber = im.versionNumber |
87 | 0 | return bo |
88 | |
} |
89 | |
} |