1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.responsibility; |
17 | |
|
18 | |
|
19 | |
import javax.persistence.CascadeType |
20 | |
import javax.persistence.Column |
21 | |
import javax.persistence.Entity |
22 | |
import javax.persistence.FetchType |
23 | |
import javax.persistence.Id |
24 | |
import javax.persistence.JoinColumn |
25 | |
import javax.persistence.OneToMany |
26 | |
import javax.persistence.OneToOne |
27 | |
import javax.persistence.Table |
28 | |
import org.hibernate.annotations.Fetch |
29 | |
import org.hibernate.annotations.FetchMode |
30 | |
import org.hibernate.annotations.Type |
31 | |
import org.kuali.rice.core.api.mo.common.Attributes |
32 | |
import org.kuali.rice.kim.api.responsibility.Responsibility |
33 | |
import org.kuali.rice.kim.api.responsibility.ResponsibilityContract |
34 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator |
35 | |
import org.kuali.rice.kim.api.type.KimType |
36 | |
import org.kuali.rice.kim.api.type.KimTypeAttribute |
37 | |
import org.kuali.rice.kim.api.type.KimTypeInfoService |
38 | |
import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo |
39 | |
import org.kuali.rice.kim.impl.role.RoleResponsibilityBo |
40 | |
import org.kuali.rice.kns.bo.PersistableBusinessObjectBase |
41 | |
import org.kuali.rice.kns.service.DataDictionaryService |
42 | |
import org.kuali.rice.kns.service.KNSServiceLocatorWeb |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
@Entity |
48 | |
@Table(name = "KRIM_RSP_T") |
49 | |
public class ResponsibilityBo extends PersistableBusinessObjectBase implements ResponsibilityContract { |
50 | |
|
51 | |
private static final long serialVersionUID = 1L; |
52 | |
|
53 | |
@Id |
54 | |
@Column(name = "RSP_ID") |
55 | |
String id |
56 | |
|
57 | |
@Column(name="NMSPC_CD") |
58 | |
String namespaceCode |
59 | |
|
60 | |
@Column(name="NM") |
61 | |
String name |
62 | |
|
63 | |
@Column(name="DESC_TXT", length=400) |
64 | |
String description; |
65 | |
|
66 | |
@Column(name="PERM_TMPL_ID") |
67 | |
String templateId |
68 | |
|
69 | |
@Column(name="ACTV_IND") |
70 | |
@Type(type="yes_no") |
71 | |
boolean active |
72 | |
|
73 | |
@OneToOne(targetEntity=ResponsibilityTemplateBo.class,cascade=[],fetch=FetchType.EAGER) |
74 | |
@JoinColumn(name="PERM_TMPL_ID", insertable=false, updatable=false) |
75 | |
ResponsibilityTemplateBo template; |
76 | |
|
77 | |
@OneToMany(targetEntity=ResponsibilityAttributeBo.class,cascade=[CascadeType.ALL],fetch=FetchType.EAGER,mappedBy="id") |
78 | |
@Fetch(value = FetchMode.SELECT) |
79 | |
List<ResponsibilityAttributeBo> attributeDetails |
80 | |
|
81 | |
@OneToMany(targetEntity=RoleResponsibilityBo.class,cascade=[CascadeType.ALL],fetch=FetchType.EAGER,mappedBy="id") |
82 | |
@Fetch(value = FetchMode.SELECT) |
83 | |
List<RoleResponsibilityBo> roleResponsibilities |
84 | |
|
85 | |
Attributes attributes |
86 | |
|
87 | |
Attributes getAttributes() { |
88 | 0 | return attributeDetails != null ? KimAttributeDataBo.toAttributes(attributeDetails) : attributes |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
static Responsibility to(ResponsibilityBo bo) { |
97 | 0 | if (bo == null) { |
98 | 0 | return null |
99 | |
} |
100 | |
|
101 | 0 | return Responsibility.Builder.create(bo).build(); |
102 | |
} |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
static ResponsibilityBo from(Responsibility im) { |
110 | 0 | if (im == null) { |
111 | 0 | return null |
112 | |
} |
113 | |
|
114 | 0 | ResponsibilityBo bo = new ResponsibilityBo() |
115 | 0 | bo.id = im.id |
116 | 0 | bo.namespaceCode = im.namespaceCode |
117 | 0 | bo.name = im.name |
118 | 0 | bo.description = im.description |
119 | 0 | bo.active = im.active |
120 | 0 | bo.template = ResponsibilityTemplateBo.from(im.template); |
121 | 0 | bo.templateId = im.template.id; |
122 | 0 | bo.attributes = im.attributes |
123 | 0 | bo.versionNumber = im.versionNumber |
124 | 0 | bo.objectId = im.objectId; |
125 | |
|
126 | 0 | return bo |
127 | |
} |
128 | |
|
129 | |
ResponsibilityTemplateBo getTemplate() { |
130 | 0 | return template; |
131 | |
} |
132 | |
|
133 | |
|
134 | |
String getDetailObjectsValues(){ |
135 | 0 | return attributeDetails.collect {it.attributeValue}.join(",") |
136 | |
} |
137 | |
|
138 | |
public String getDetailObjectsToDisplay() { |
139 | 0 | final KimType kimType = getTypeInfoService().getKimType( getTemplate().getKimTypeId() ); |
140 | |
|
141 | 0 | return attributeDetails.collect { |
142 | 0 | getKimAttributeLabelFromDD(kimType.getAttributeDefinitionById(it.kimAttributeId)) + ":" + it.attributeValue |
143 | |
}.join(",") |
144 | |
} |
145 | |
|
146 | |
private String getKimAttributeLabelFromDD( KimTypeAttribute attribute ){ |
147 | 0 | return getDataDictionaryService().getAttributeLabel(attribute.getKimAttribute().getComponentName(), attribute.getKimAttribute().getAttributeName() ); |
148 | |
} |
149 | |
|
150 | |
private DataDictionaryService dataDictionaryService; |
151 | |
private DataDictionaryService getDataDictionaryService() { |
152 | 0 | if(dataDictionaryService == null){ |
153 | 0 | dataDictionaryService = KNSServiceLocatorWeb.getDataDictionaryService(); |
154 | |
} |
155 | 0 | return dataDictionaryService; |
156 | |
} |
157 | |
|
158 | |
private KimTypeInfoService kimTypeInfoService; |
159 | |
private KimTypeInfoService getTypeInfoService() { |
160 | 0 | if(kimTypeInfoService == null){ |
161 | 0 | kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService(); |
162 | |
} |
163 | 0 | return kimTypeInfoService; |
164 | |
} |
165 | |
} |