1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kim.impl.common.attribute |
18 | |
|
19 | |
import javax.persistence.Transient |
20 | |
import org.apache.commons.lang.StringUtils |
21 | |
import org.kuali.rice.kim.api.common.attribute.KimAttributeDataContract |
22 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator |
23 | |
import org.kuali.rice.kim.api.type.KimTypeAttribute |
24 | |
import org.kuali.rice.kim.impl.type.KimTypeBo |
25 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
26 | |
|
27 | |
abstract class KimAttributeDataBo extends PersistableBusinessObjectBase implements KimAttributeDataContract { |
28 | |
private static final long serialVersionUID = 1L; |
29 | |
|
30 | |
String id |
31 | |
String attributeValue |
32 | |
String kimAttributeId |
33 | |
KimAttributeBo kimAttribute |
34 | |
String kimTypeId |
35 | |
@Transient |
36 | |
KimTypeBo kimType |
37 | |
|
38 | |
abstract void setAssignedToId(String s); |
39 | |
|
40 | |
@Override |
41 | |
KimAttributeBo getKimAttribute() { |
42 | 18 | return kimAttribute |
43 | |
} |
44 | |
|
45 | |
@Override |
46 | |
KimTypeBo getKimType() { |
47 | 34 | if (kimType == null && StringUtils.isNotEmpty(id)) { |
48 | 0 | kimType = KimTypeBo.from(KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId)); |
49 | |
} |
50 | 34 | return kimType; |
51 | |
} |
52 | |
|
53 | |
static <T extends KimAttributeDataBo> Map<String, String> toAttributes(Collection<T> bos) { |
54 | 16 | def m = [:] |
55 | 16 | if(bos != null) { |
56 | 16 | bos.each { |
57 | 16 | if (it != null) { |
58 | 16 | KimTypeAttribute attribute = null; |
59 | 16 | if ( it.kimType != null ) { |
60 | 16 | attribute = KimTypeBo.to(it.kimType).getAttributeDefinitionById( it.getKimAttributeId() ); |
61 | |
} |
62 | 16 | if ( attribute != null ) { |
63 | 0 | m[attribute.getKimAttribute().getAttributeName()] = it.getAttributeValue(); |
64 | |
} else { |
65 | 16 | m[it.getKimAttribute().getAttributeName()] = it.getAttributeValue(); |
66 | |
} |
67 | |
} |
68 | |
} |
69 | |
} |
70 | 16 | return m; |
71 | |
} |
72 | |
|
73 | |
|
74 | |
static <T extends KimAttributeDataBo> List<T> createFrom(Class<T> type, Map<String, String> attributes, String kimTypeId) { |
75 | 0 | if (attributes == null) { |
76 | |
|
77 | 0 | return new ArrayList<T>(); |
78 | |
} |
79 | 0 | return attributes.entrySet().collect { |
80 | 0 | KimTypeAttribute attr = KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId).getAttributeDefinitionByName(it.getKey()); |
81 | 0 | if (attr != null && StringUtils.isNotBlank(it.getValue())) { |
82 | 0 | T newDetail = type.newInstance(); |
83 | 0 | newDetail.setKimAttributeId(attr.getKimAttribute().getId()); |
84 | 0 | newDetail.setKimTypeId(kimTypeId); |
85 | 0 | newDetail.setAttributeValue(it.getValue()); |
86 | 0 | return newDetail; |
87 | |
} |
88 | |
} |
89 | |
} |
90 | |
} |