1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.role; |
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.GeneratedValue |
24 | |
import javax.persistence.Id |
25 | |
import javax.persistence.JoinColumn |
26 | |
import javax.persistence.OneToMany |
27 | |
import javax.persistence.Table |
28 | |
import javax.persistence.Transient |
29 | |
import org.hibernate.annotations.GenericGenerator |
30 | |
import org.hibernate.annotations.Parameter |
31 | |
import org.kuali.rice.kim.api.role.Role |
32 | |
import org.kuali.rice.kim.api.role.RoleMember |
33 | |
import org.kuali.rice.kim.api.role.RoleMemberContract |
34 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator |
35 | |
import org.kuali.rice.kim.api.type.KimTypeInfoService |
36 | |
import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo |
37 | |
import org.kuali.rice.kim.impl.membership.AbstractMemberBo |
38 | |
import org.springframework.util.AutoPopulatingList |
39 | |
import java.sql.Timestamp |
40 | |
import org.kuali.rice.core.api.membership.MemberType |
41 | |
|
42 | |
@Entity |
43 | |
@Table(name = "KRIM_ROLE_MBR_T") |
44 | |
public class RoleMemberBo extends AbstractMemberBo implements RoleMemberContract { |
45 | |
|
46 | |
private static final long serialVersionUID = 1L; |
47 | |
|
48 | |
@Id |
49 | |
@GeneratedValue(generator = "KRIM_ROLE_MBR_ID_S") |
50 | |
@GenericGenerator(name = "KRIM_ROLE_MBR_ID_S", strategy = "org.kuali.rice.core.jpa.spring.RiceNumericStringSequenceStyleGenerator", parameters = [ |
51 | |
@Parameter(name = "sequence_name", value = "KRIM_ROLE_MBR_ID_S"), |
52 | |
@Parameter(name = "value_column", value = "id") |
53 | |
]) |
54 | |
@Column(name = "ROLE_MBR_ID") |
55 | |
String roleMemberId; |
56 | |
|
57 | |
@Column(name = "ROLE_ID") |
58 | |
String roleId; |
59 | |
|
60 | |
@Column(name = "MBR_TYP_CD") |
61 | |
private String memberTypeCode |
62 | |
|
63 | |
@OneToMany(targetEntity = RoleMemberAttributeDataBo.class, cascade = [CascadeType.ALL], fetch = FetchType.EAGER) |
64 | |
@JoinColumn(name = "ROLE_MBR_ID", insertable = false, updatable = false) |
65 | |
List<RoleMemberAttributeDataBo> attributeDetails; |
66 | |
|
67 | |
@Transient |
68 | |
List<RoleResponsibilityActionBo> roleRspActions; |
69 | |
|
70 | |
@Transient |
71 | |
Map<String,String> attributes |
72 | |
|
73 | |
|
74 | |
List<RoleMemberAttributeDataBo> getAttributeDetails() { |
75 | 0 | if (this.attributeDetails == null) { |
76 | 0 | return new AutoPopulatingList(RoleMemberAttributeDataBo.class); |
77 | |
} |
78 | 0 | return this.attributeDetails; |
79 | |
} |
80 | |
|
81 | |
void setAttributeDetails(List<RoleMemberAttributeDataBo> attributeDetails) { |
82 | 0 | this.attributeDetails = attributeDetails; |
83 | |
} |
84 | |
|
85 | |
Map<String,String> getAttributes() { |
86 | 0 | return attributeDetails != null ? KimAttributeDataBo.toAttributes(attributeDetails) : attributes |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
public String getMemberTypeCode() { |
111 | 1 | return memberTypeCode; |
112 | |
} |
113 | |
|
114 | |
public MemberType getMemberType() { |
115 | 0 | return MemberType.fromCode(memberTypeCode) |
116 | |
} |
117 | |
|
118 | |
public void setMemberType(MemberType type) { |
119 | 0 | this.memberTypeCode = type.getCode() |
120 | |
} |
121 | |
|
122 | |
public static RoleMember to(RoleMemberBo bo) { |
123 | 0 | if (bo == null) {return null;} |
124 | 0 | return RoleMember.Builder.create(bo).build(); |
125 | |
} |
126 | |
|
127 | |
public static RoleMemberBo from(RoleMember immutable) { |
128 | 2 | if (immutable == null) { return null; } |
129 | |
|
130 | 2 | return new RoleMemberBo( |
131 | |
roleMemberId: immutable.roleMemberId, |
132 | |
roleId: immutable.roleId, |
133 | 2 | roleRspActions: immutable.roleRspActions.collect { RoleResponsibilityActionBo.from(it) }, |
134 | |
memberId: immutable.memberId, |
135 | |
memberTypeCode: immutable.memberTypeCode, |
136 | 2 | activeFromDateValue: immutable.activeFromDate == null ? null : new Timestamp(immutable.activeFromDate.getMillis()), |
137 | 2 | activeToDateValue: immutable.activeToDate == null ? null : new Timestamp(immutable.activeToDate.getMillis()), |
138 | |
) |
139 | |
} |
140 | |
} |