1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.impl.common.delegate;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.eclipse.persistence.annotations.JoinFetch;
20 import org.eclipse.persistence.annotations.JoinFetchType;
21 import org.kuali.rice.kim.api.common.delegate.DelegateMember;
22 import org.kuali.rice.kim.api.common.delegate.DelegateMemberContract;
23 import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo;
24 import org.kuali.rice.kim.impl.membership.AbstractMemberBo;
25 import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
26 import org.springframework.util.AutoPopulatingList;
27
28 import javax.persistence.CascadeType;
29 import javax.persistence.Column;
30 import javax.persistence.Entity;
31 import javax.persistence.GeneratedValue;
32 import javax.persistence.Id;
33 import javax.persistence.JoinColumn;
34 import javax.persistence.OneToMany;
35 import javax.persistence.Table;
36 import javax.persistence.Transient;
37 import java.sql.Timestamp;
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41
42 @Entity
43 @Table(name = "KRIM_DLGN_MBR_T")
44 public class DelegateMemberBo extends AbstractMemberBo implements DelegateMemberContract {
45 private static final long serialVersionUID = 1L;
46
47 @PortableSequenceGenerator(name = "KRIM_DLGN_MBR_ID_S")
48 @GeneratedValue(generator = "KRIM_DLGN_MBR_ID_S")
49 @Id
50 @Column(name = "DLGN_MBR_ID")
51 private String delegationMemberId;
52
53 @Column(name = "DLGN_ID")
54 private String delegationId;
55
56 @Column(name = "ROLE_MBR_ID")
57 private String roleMemberId;
58
59 @JoinFetch(value= JoinFetchType.OUTER)
60 @OneToMany(targetEntity = DelegateMemberAttributeDataBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
61 @JoinColumn(name = "DLGN_MBR_ID", referencedColumnName = "DLGN_MBR_ID")
62 private List<DelegateMemberAttributeDataBo> attributeDetails = new AutoPopulatingList<DelegateMemberAttributeDataBo>(DelegateMemberAttributeDataBo.class);
63
64 @Transient
65 private Map<String, String> attributes;
66
67
68
69
70
71
72
73 public Map<String, String> getQualifier() {
74 Map<String, String> attribs = new HashMap<String, String>();
75 if (attributeDetails == null) {
76 return attribs;
77 }
78 for (DelegateMemberAttributeDataBo attr : attributeDetails) {
79 attribs.put(attr.getKimAttribute().getAttributeName(), attr.getAttributeValue());
80 }
81 return attribs;
82 }
83
84 public List<DelegateMemberAttributeDataBo> getAttributeDetails() {
85 if (this.attributeDetails == null) {
86 return new AutoPopulatingList<DelegateMemberAttributeDataBo>(DelegateMemberAttributeDataBo.class);
87 }
88 return this.attributeDetails;
89 }
90
91 public void setAttributeDetails(List<DelegateMemberAttributeDataBo> attributeDetails) {
92 this.attributeDetails = attributeDetails;
93 }
94
95 @Override
96 public Map<String, String> getAttributes() {
97 return CollectionUtils.isNotEmpty(attributeDetails) ? KimAttributeDataBo.toAttributes(attributeDetails) : attributes;
98 }
99
100 public static DelegateMember to(DelegateMemberBo bo) {
101 if (bo == null) {
102 return null;
103 }
104 return DelegateMember.Builder.create(bo).build();
105 }
106
107 public static DelegateMemberBo from(DelegateMember immutable) {
108 if (immutable == null) {
109 return null;
110 }
111 DelegateMemberBo bo = new DelegateMemberBo();
112 bo.setDelegationMemberId(immutable.getDelegationMemberId());
113 bo.setActiveFromDateValue(immutable.getActiveFromDate() == null ? null : new Timestamp(immutable.getActiveFromDate().getMillis()));
114 bo.setActiveToDateValue(immutable.getActiveToDate() == null ? null : new Timestamp(immutable.getActiveToDate().getMillis()));
115 bo.setDelegationId(immutable.getDelegationId());
116 bo.setMemberId(immutable.getMemberId());
117 bo.setRoleMemberId(immutable.getRoleMemberId());
118 bo.setTypeCode(immutable.getType().getCode());
119 bo.setVersionNumber(immutable.getVersionNumber());
120 bo.setAttributes(immutable.getAttributes());
121 return bo;
122 }
123
124 @Override
125 public String getDelegationMemberId() {
126 return delegationMemberId;
127 }
128
129 public void setDelegationMemberId(String delegationMemberId) {
130 this.delegationMemberId = delegationMemberId;
131 }
132
133 @Override
134 public String getDelegationId() {
135 return delegationId;
136 }
137
138 public void setDelegationId(String delegationId) {
139 this.delegationId = delegationId;
140 }
141
142 @Override
143 public String getRoleMemberId() {
144 return roleMemberId;
145 }
146
147 public void setRoleMemberId(String roleMemberId) {
148 this.roleMemberId = roleMemberId;
149 }
150
151 public void setAttributes(Map<String, String> attributes) {
152 this.attributes = attributes;
153 }
154 }