1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.document; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.apache.log4j.Logger; |
20 | |
import org.hibernate.annotations.Fetch; |
21 | |
import org.hibernate.annotations.FetchMode; |
22 | |
import org.hibernate.annotations.Type; |
23 | |
import org.kuali.rice.core.api.mo.common.Attributes; |
24 | |
import org.kuali.rice.core.util.AttributeSet; |
25 | |
import org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO; |
26 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
27 | |
import org.kuali.rice.kim.api.type.KimType; |
28 | |
import org.kuali.rice.kim.bo.types.dto.AttributeDefinitionMap; |
29 | |
import org.kuali.rice.kim.bo.ui.GroupDocumentMember; |
30 | |
import org.kuali.rice.kim.bo.ui.GroupDocumentQualifier; |
31 | |
import org.kuali.rice.kim.service.KIMServiceLocatorInternal; |
32 | |
import org.kuali.rice.kim.util.KimConstants; |
33 | |
import org.kuali.rice.kns.service.SequenceAccessorService; |
34 | |
import org.springframework.util.AutoPopulatingList; |
35 | |
|
36 | |
import javax.persistence.AttributeOverride; |
37 | |
import javax.persistence.AttributeOverrides; |
38 | |
import javax.persistence.CascadeType; |
39 | |
import javax.persistence.Column; |
40 | |
import javax.persistence.Entity; |
41 | |
import javax.persistence.FetchType; |
42 | |
import javax.persistence.JoinColumn; |
43 | |
import javax.persistence.OneToMany; |
44 | |
import javax.persistence.Table; |
45 | |
import javax.persistence.Transient; |
46 | |
import java.util.ArrayList; |
47 | |
import java.util.HashMap; |
48 | |
import java.util.List; |
49 | |
import java.util.Map; |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
@Entity |
59 | |
@AttributeOverrides({ |
60 | |
@AttributeOverride(name="documentNumber",column=@Column(name="FDOC_NBR")) |
61 | |
}) |
62 | |
@Table(name="KRIM_GRP_DOCUMENT_T") |
63 | |
public class IdentityManagementGroupDocument extends IdentityManagementTypeAttributeTransactionalDocument { |
64 | 0 | private static final Logger LOG = Logger.getLogger(IdentityManagementGroupDocument.class); |
65 | |
|
66 | |
private static final long serialVersionUID = 1L; |
67 | |
|
68 | |
|
69 | |
@Column(name="GRP_ID") |
70 | |
protected String groupId; |
71 | |
@Column(name="KIM_TYP_ID") |
72 | |
protected String groupTypeId; |
73 | |
@Transient |
74 | |
protected String groupTypeName; |
75 | |
@Column(name="GRP_NMSPC") |
76 | |
protected String groupNamespace; |
77 | |
@Column(name="GRP_NM") |
78 | |
protected String groupName; |
79 | |
@Column(name="GRP_DESC") |
80 | |
protected String groupDescription; |
81 | 0 | @Type(type="yes_no") |
82 | |
@Column(name="ACTV_IND") |
83 | |
protected boolean active = true; |
84 | |
|
85 | |
@Transient |
86 | |
protected boolean editing; |
87 | |
|
88 | 0 | @OneToMany(targetEntity = GroupDocumentMember.class, fetch = FetchType.EAGER, cascade=CascadeType.ALL) |
89 | |
@Fetch(value = FetchMode.SELECT) |
90 | |
@JoinColumn(name="FDOC_NBR", insertable = false, updatable = false) |
91 | |
private List<GroupDocumentMember> members = new AutoPopulatingList(GroupDocumentMember.class); |
92 | 0 | @OneToMany(targetEntity = GroupDocumentQualifier.class, fetch = FetchType.EAGER, cascade=CascadeType.ALL) |
93 | |
@Fetch(value = FetchMode.SELECT) |
94 | |
@JoinColumn(name="FDOC_NBR", insertable = false, updatable = false) |
95 | |
private List<GroupDocumentQualifier> qualifiers = new AutoPopulatingList(GroupDocumentQualifier.class); |
96 | |
|
97 | 0 | public IdentityManagementGroupDocument() { |
98 | 0 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
public boolean isActive() { |
104 | 0 | return this.active; |
105 | |
} |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
public void setActive(boolean active) { |
111 | 0 | this.active = active; |
112 | 0 | } |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
public void setRoleId(String groupId) { |
118 | 0 | this.groupId = groupId; |
119 | 0 | } |
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
public void addMember(GroupDocumentMember member) { |
125 | 0 | getMembers().add(member); |
126 | 0 | } |
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
public KimType getKimType() { |
132 | 0 | return KimApiServiceLocator.getKimTypeInfoService().getKimType(getGroupTypeId()); |
133 | |
} |
134 | |
|
135 | |
public GroupDocumentMember getBlankMember() { |
136 | 0 | return new GroupDocumentMember(); |
137 | |
} |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
@Override |
143 | |
public void doRouteStatusChange(DocumentRouteStatusChangeDTO statusChangeEvent) { |
144 | 0 | super.doRouteStatusChange(statusChangeEvent); |
145 | 0 | if (getDocumentHeader().getWorkflowDocument().stateIsProcessed()) { |
146 | 0 | KIMServiceLocatorInternal.getUiDocumentService().saveGroup(this); |
147 | |
} |
148 | 0 | } |
149 | |
|
150 | |
@Override |
151 | |
public void prepareForSave(){ |
152 | |
String groupId; |
153 | 0 | if(StringUtils.isBlank(getGroupId())){ |
154 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
155 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
156 | |
"KRIM_GRP_ID_S", this.getClass()); |
157 | 0 | groupId = nextSeq.toString(); |
158 | 0 | setGroupId(groupId); |
159 | 0 | } else{ |
160 | 0 | groupId = getGroupId(); |
161 | |
} |
162 | 0 | if(getMembers()!=null){ |
163 | |
String groupMemberId; |
164 | 0 | for(GroupDocumentMember member: getMembers()){ |
165 | 0 | member.setGroupId(getGroupId()); |
166 | 0 | if(StringUtils.isBlank(member.getGroupMemberId())){ |
167 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
168 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
169 | |
"KRIM_GRP_MBR_ID_S", this.getClass()); |
170 | 0 | groupMemberId = nextSeq.toString(); |
171 | 0 | member.setGroupMemberId(groupMemberId); |
172 | |
} |
173 | 0 | if (StringUtils.isBlank(member.getDocumentNumber())) { |
174 | 0 | member.setDocumentNumber(getDocumentNumber()); |
175 | |
} |
176 | |
} |
177 | |
} |
178 | 0 | int index = 0; |
179 | |
|
180 | 0 | if(getDefinitions()!=null){ |
181 | 0 | for(String key : getDefinitions().keySet()) { |
182 | 0 | if ( getQualifiers().size() > index ) { |
183 | 0 | GroupDocumentQualifier qualifier = getQualifiers().get(index); |
184 | 0 | qualifier.setKimAttrDefnId(getKimAttributeDefnId(getDefinitions().get(key))); |
185 | 0 | qualifier.setKimTypId(getKimType().getId()); |
186 | 0 | qualifier.setGroupId(groupId); |
187 | |
} |
188 | 0 | index++; |
189 | |
} |
190 | |
} |
191 | 0 | } |
192 | |
|
193 | |
public void initializeDocumentForNewGroup() { |
194 | 0 | if(StringUtils.isBlank(this.groupId)){ |
195 | 0 | SequenceAccessorService sas = getSequenceAccessorService(); |
196 | 0 | Long nextSeq = sas.getNextAvailableSequenceNumber( |
197 | |
KimConstants.SequenceNames.KRIM_GROUP_ID_S, this.getClass()); |
198 | 0 | this.groupId = nextSeq.toString(); |
199 | |
} |
200 | 0 | if(StringUtils.isBlank(this.groupTypeId)) { |
201 | 0 | this.groupTypeId = "1"; |
202 | |
} |
203 | 0 | } |
204 | |
|
205 | |
public String getGroupId(){ |
206 | |
|
207 | |
|
208 | |
|
209 | 0 | return groupId; |
210 | |
} |
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
public void setGroupId(String groupId) { |
216 | 0 | this.groupId = groupId; |
217 | 0 | } |
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
public String getGroupName() { |
223 | 0 | return this.groupName; |
224 | |
} |
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
public void setGroupName(String groupName) { |
230 | 0 | this.groupName = groupName; |
231 | 0 | } |
232 | |
|
233 | |
public String getGroupDescription() { |
234 | 0 | return this.groupDescription; |
235 | |
} |
236 | |
|
237 | |
public void setGroupDescription(String groupDescription) { |
238 | 0 | this.groupDescription = groupDescription; |
239 | 0 | } |
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
public String getGroupNamespace() { |
245 | 0 | return this.groupNamespace; |
246 | |
} |
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
public void setGroupNamespace(String groupNamespace) { |
252 | 0 | this.groupNamespace = groupNamespace; |
253 | 0 | } |
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
public String getGroupTypeId() { |
259 | 0 | return this.groupTypeId; |
260 | |
} |
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
public void setGroupTypeId(String groupTypeId) { |
266 | 0 | this.groupTypeId = groupTypeId; |
267 | 0 | } |
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
public String getGroupTypeName() { |
273 | 0 | return this.groupTypeName; |
274 | |
} |
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | |
public void setGroupTypeName(String groupTypeName) { |
280 | 0 | this.groupTypeName = groupTypeName; |
281 | 0 | } |
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
public List<GroupDocumentMember> getMembers() { |
287 | 0 | return this.members; |
288 | |
} |
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
public void setMembers(List<GroupDocumentMember> members) { |
294 | 0 | this.members = members; |
295 | 0 | } |
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
public List<GroupDocumentQualifier> getQualifiers() { |
301 | 0 | return this.qualifiers; |
302 | |
} |
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
public void setQualifiers(List<GroupDocumentQualifier> qualifiers) { |
308 | 0 | this.qualifiers = qualifiers; |
309 | 0 | } |
310 | |
|
311 | |
public GroupDocumentQualifier getQualifier(String kimAttributeDefnId) { |
312 | 0 | for(GroupDocumentQualifier qualifier: qualifiers){ |
313 | 0 | if(qualifier.getKimAttrDefnId().equals(kimAttributeDefnId)) |
314 | 0 | return qualifier; |
315 | |
} |
316 | 0 | return null; |
317 | |
} |
318 | |
|
319 | |
public Attributes getQualifiersAsAttributes() { |
320 | 0 | Map<String, String> attributes = new HashMap<String, String>(); |
321 | 0 | for(GroupDocumentQualifier qualifier: qualifiers){ |
322 | 0 | if ( qualifier.getKimAttribute() != null ) { |
323 | 0 | attributes.put(qualifier.getKimAttribute().getAttributeName(), qualifier.getAttrVal()); |
324 | |
} else { |
325 | 0 | LOG.warn( "Unknown attribute ID on group: " + qualifier.getKimAttrDefnId() + " / value=" + qualifier.getAttrVal()); |
326 | 0 | attributes.put("Unknown Attribute ID: " + qualifier.getKimAttrDefnId(), qualifier.getAttrVal()); |
327 | |
} |
328 | |
} |
329 | 0 | return Attributes.fromMap(attributes); |
330 | |
} |
331 | |
|
332 | |
public void setDefinitions(AttributeDefinitionMap definitions) { |
333 | 0 | super.setDefinitions(definitions); |
334 | 0 | if(getQualifiers()==null || getQualifiers().size()<1){ |
335 | |
GroupDocumentQualifier qualifier; |
336 | 0 | setQualifiers(new ArrayList<GroupDocumentQualifier>()); |
337 | 0 | if(getDefinitions()!=null){ |
338 | 0 | for(String key : getDefinitions().keySet()) { |
339 | 0 | qualifier = new GroupDocumentQualifier(); |
340 | 0 | qualifier.setKimAttrDefnId(getKimAttributeDefnId(getDefinitions().get(key))); |
341 | 0 | getQualifiers().add(qualifier); |
342 | |
} |
343 | |
} |
344 | |
} |
345 | 0 | } |
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
public boolean isEditing() { |
351 | 0 | return this.editing; |
352 | |
} |
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
public void setEditing(boolean editing) { |
358 | 0 | this.editing = editing; |
359 | 0 | } |
360 | |
|
361 | |
public void setKimType(KimType kimType) { |
362 | 0 | super.setKimType(kimType); |
363 | 0 | if (kimType != null){ |
364 | 0 | setGroupTypeId(kimType.getId()); |
365 | 0 | setGroupTypeName(kimType.getName()); |
366 | |
} |
367 | 0 | } |
368 | |
} |