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