1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.coa.identity;
17
18 import java.util.ArrayList;
19 import java.util.HashMap;
20 import java.util.List;
21 import java.util.Map;
22
23 import org.apache.commons.collections.CollectionUtils;
24 import org.joda.time.DateTime;
25 import org.kuali.rice.core.api.membership.MemberType;
26 import org.kuali.rice.core.api.mo.common.active.InactivatableFromToUtils;
27 import org.kuali.rice.kim.api.group.Group;
28 import org.kuali.rice.kim.api.identity.principal.Principal;
29 import org.kuali.rice.kim.api.role.Role;
30 import org.kuali.rice.kim.api.role.RoleMemberContract;
31 import org.kuali.rice.kim.api.role.RoleResponsibilityActionContract;
32 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
33 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
34
35 public class OleKimDocRoleMember extends PersistableBusinessObjectBase implements RoleMemberContract {
36
37 protected String id;
38 protected String memberId;
39 protected String memberName;
40 protected String memberNamespaceCode;
41 protected String roleId;
42 protected MemberType type;
43 protected Map<String,String> attributes = new HashMap<String, String>();
44 protected boolean active = true;
45 protected DateTime activeFromDate;
46 protected DateTime activeToDate;
47 protected List<OleKimRoleResponsibilityAction> roleRspActions = new ArrayList<OleKimRoleResponsibilityAction>();
48
49 public OleKimDocRoleMember() {}
50
51 public OleKimDocRoleMember( RoleMemberContract b ) {
52 id = b.getId();
53 roleId = b.getRoleId();
54 attributes = b.getAttributes();
55
56 if (!CollectionUtils.isEmpty(b.getRoleRspActions())) {
57 for (RoleResponsibilityActionContract rra : b.getRoleRspActions()) {
58 roleRspActions.add( new OleKimRoleResponsibilityAction(rra) );
59 }
60 }
61
62 memberId = b.getMemberId();
63 type = b.getType();
64 activeFromDate = b.getActiveFromDate();
65 activeToDate = b.getActiveToDate();
66 versionNumber = b.getVersionNumber();
67 }
68
69 public OleKimDocRoleMember( String roleId, MemberType type) {
70 this();
71 this.roleId = roleId;
72 this.type = type;
73 }
74
75 public OleKimDocRoleMember(String roleId, MemberType type, String memberId) {
76 this( roleId, type );
77 this.memberId = memberId;
78 }
79
80 @Override
81 public String getId() {
82 return id;
83 }
84 public void setId(String id) {
85 this.id = id;
86 }
87 @Override
88 public String getMemberId() {
89 return memberId;
90 }
91 public void setMemberId(String memberId) {
92 memberName = null;
93 memberNamespaceCode = null;
94 this.memberId = memberId;
95 }
96
97 protected void loadMemberInfo() {
98 if ( MemberType.ROLE.equals( type ) ) {
99 Role role = KimApiServiceLocator.getRoleService().getRole(memberId);
100 if ( role != null ) {
101 memberName = role.getName();
102 memberNamespaceCode = role.getNamespaceCode();
103 }
104 } else if ( MemberType.GROUP.equals( type ) ) {
105 Group group = KimApiServiceLocator.getGroupService().getGroup(memberId);
106 if ( group != null ) {
107 memberName = group.getName();
108 memberNamespaceCode = group.getNamespaceCode();
109 }
110 } else {
111 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(memberId);
112 if ( principal != null ) {
113 memberName = principal.getPrincipalName();
114 memberNamespaceCode = "";
115 }
116 }
117 }
118
119 @Override
120 public String getMemberName() {
121 if ( memberName == null && memberId != null ) {
122 loadMemberInfo();
123 }
124 return memberName;
125 }
126 public void setMemberName(String memberName) {
127 this.memberName = memberName;
128 }
129 @Override
130 public String getMemberNamespaceCode() {
131 if ( memberNamespaceCode == null && memberId != null ) {
132 loadMemberInfo();
133 }
134 return memberNamespaceCode;
135 }
136 public void setMemberNamespaceCode(String memberNamespaceCode) {
137 this.memberNamespaceCode = memberNamespaceCode;
138 }
139 @Override
140 public String getRoleId() {
141 return roleId;
142 }
143 public void setRoleId(String roleId) {
144 this.roleId = roleId;
145 }
146 @Override
147 public Map<String, String> getAttributes() {
148 return attributes;
149 }
150 public void setAttributes(Map<String, String> attributes) {
151 this.attributes = attributes;
152 }
153 @Override
154 public boolean isActive() {
155 return active;
156 }
157 public void setActive(boolean active) {
158 this.active = active;
159 }
160 @Override
161 public DateTime getActiveFromDate() {
162 return activeFromDate;
163 }
164 public void setActiveFromDate(DateTime activeFromDate) {
165 this.activeFromDate = activeFromDate;
166 }
167 @Override
168 public DateTime getActiveToDate() {
169 return activeToDate;
170 }
171 public void setActiveToDate(DateTime activeToDate) {
172 this.activeToDate = activeToDate;
173 }
174 @Override
175 public List<OleKimRoleResponsibilityAction> getRoleRspActions() {
176 return roleRspActions;
177 }
178 public void setRoleRspActions(List<OleKimRoleResponsibilityAction> roleRspActions) {
179 this.roleRspActions = roleRspActions;
180 }
181 @Override
182 public MemberType getType() {
183 return type;
184 }
185 public void setType(MemberType type) {
186 this.type = type;
187 }
188 @Override
189 public boolean isActive(DateTime activeAsOfDate) {
190 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null);
191 }
192
193 }