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