View Javadoc
1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kim.bo.ui;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  import javax.persistence.CascadeType;
24  import javax.persistence.Column;
25  import javax.persistence.Entity;
26  import javax.persistence.Id;
27  import javax.persistence.JoinColumn;
28  import javax.persistence.JoinColumns;
29  import javax.persistence.OneToMany;
30  import javax.persistence.Table;
31  import javax.persistence.Transient;
32  
33  import org.apache.commons.lang.StringUtils;
34  import org.eclipse.persistence.annotations.JoinFetch;
35  import org.eclipse.persistence.annotations.JoinFetchType;
36  import org.kuali.rice.core.api.membership.MemberType;
37  import org.kuali.rice.kim.api.KimConstants;
38  import org.kuali.rice.kim.api.group.Group;
39  import org.kuali.rice.kim.api.identity.principal.Principal;
40  import org.kuali.rice.kim.api.role.Role;
41  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
42  import org.kuali.rice.kim.impl.role.RoleMemberBo;
43  import org.kuali.rice.krad.data.KradDataServiceLocator;
44  import org.springframework.util.AutoPopulatingList;
45  
46  /**
47   * This is a description of what this class does - shyu don't forget to fill this in. 
48   * 
49   * @author Kuali Rice Team (rice.collab@kuali.org)
50   *
51   */
52  @Entity
53  @Table(name = "KRIM_PND_ROLE_MBR_MT")
54  public class KimDocumentRoleMember extends KimDocumentBoActivatableToFromEditableBase {
55  
56      private static final long serialVersionUID = -2463865643038170979L;
57  
58      @Id
59      @Column(name = "ROLE_MBR_ID")
60      protected String roleMemberId;
61  
62      @Column(name = "ROLE_ID")
63      protected String roleId;
64  
65      @Column(name = "MBR_ID")
66      protected String memberId;
67  
68      //TODO: remove the default                       
69      @Column(name = "MBR_TYP_CD")
70      protected String memberTypeCode = KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode();
71  
72      @Transient
73      protected String memberName;
74  
75      @Transient
76      protected String memberNamespaceCode;
77  
78      @Transient
79      protected String memberFullName;
80  
81      @JoinFetch(value= JoinFetchType.OUTER)
82      @OneToMany(targetEntity = KimDocumentRoleQualifier.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST })
83      @JoinColumns({ 
84          @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false), 
85          @JoinColumn(name = "ROLE_MBR_ID", referencedColumnName = "ROLE_MBR_ID", insertable = false, updatable = false) })
86      protected List<KimDocumentRoleQualifier> qualifiers = new AutoPopulatingList<KimDocumentRoleQualifier>(KimDocumentRoleQualifier.class);
87  
88      @Transient
89      protected String qualifiersToDisplay;
90  
91      @JoinFetch(value= JoinFetchType.OUTER)
92      @OneToMany(targetEntity = KimDocumentRoleResponsibilityAction.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST })
93      @JoinColumns({ 
94          @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false), 
95          @JoinColumn(name = "ROLE_MBR_ID", referencedColumnName = "ROLE_MBR_ID", insertable = false, updatable = false) })
96      private List<KimDocumentRoleResponsibilityAction> roleRspActions;
97  
98      public KimDocumentRoleMember() {
99          qualifiers = new ArrayList<KimDocumentRoleQualifier>();
100         roleRspActions = new ArrayList<KimDocumentRoleResponsibilityAction>();
101     }
102 
103     public int getNumberOfQualifiers() {
104         return qualifiers == null ? 0 : qualifiers.size();
105     }
106 
107     /**
108 	 * @return the memberId
109 	 */
110     public String getMemberId() {
111         return this.memberId;
112     }
113 
114     /**
115 	 * @param memberId the memberId to set
116 	 */
117     public void setMemberId(String memberId) {
118         this.memberId = memberId;
119     }
120 
121     public String getRoleMemberId() {
122         return this.roleMemberId;
123     }
124 
125     public void setRoleMemberId(String roleMemberId) {
126         this.roleMemberId = roleMemberId;
127     }
128 
129     public String getRoleId() {
130         return this.roleId;
131     }
132 
133     public void setRoleId(String roleId) {
134         this.roleId = roleId;
135     }
136 
137     public KimDocumentRoleQualifier getQualifier(String kimAttributeDefnId) {
138         for (KimDocumentRoleQualifier qualifier : qualifiers) {
139             if (qualifier.getKimAttrDefnId().equals(kimAttributeDefnId)) {
140                 return qualifier;
141             }
142         }
143         return null;
144     }
145 
146     public List<KimDocumentRoleQualifier> getQualifiers() {
147         return this.qualifiers;
148     }
149 
150     public void setQualifiers(List<KimDocumentRoleQualifier> qualifiers) {
151         this.qualifiers = qualifiers;
152     }
153 
154     /**
155 	 * @return the memberTypeCode
156 	 */
157     public String getMemberTypeCode() {
158         return this.memberTypeCode;
159     }
160 
161     /**
162 	 * @param memberTypeCode the memberTypeCode to set
163 	 */
164     public void setMemberTypeCode(String memberTypeCode) {
165         this.memberTypeCode = memberTypeCode;
166     }
167 
168     /**
169 	 * @return the memberName
170 	 */
171     public String getMemberName() {
172         if (memberName == null) {
173             populateDerivedValues();
174         }
175         return memberName;
176     }
177 
178     /**
179 	 * @param memberName the memberName to set
180 	 */
181     public void setMemberName(String memberName) {
182         this.memberName = memberName;
183     }
184 
185     public List<KimDocumentRoleResponsibilityAction> getRoleRspActions() {
186         return this.roleRspActions;
187     }
188 
189     public void setRoleRspActions(List<KimDocumentRoleResponsibilityAction> roleRspActions) {
190         this.roleRspActions = roleRspActions;
191     }
192 
193     /**
194 	 * @return the memberNamespaceCode
195 	 */
196     public String getMemberNamespaceCode() {
197         if (memberNamespaceCode == null) {
198             populateDerivedValues();
199         }
200         return memberNamespaceCode;
201     }
202 
203     /**
204 	 * @param memberNamespaceCode the memberNamespaceCode to set
205 	 */
206     public void setMemberNamespaceCode(String memberNamespaceCode) {
207         this.memberNamespaceCode = memberNamespaceCode;
208     }
209 
210     protected void populateDerivedValues() {
211         if (!StringUtils.isEmpty(getMemberId())) {
212             if (MemberType.PRINCIPAL.getCode().equals(getMemberTypeCode())) {
213                 Principal principalInfo = KimApiServiceLocator.getIdentityService().getPrincipal(getMemberId());
214                 if (principalInfo != null) {
215                     setMemberName(principalInfo.getPrincipalName());
216                 }
217             } else if (MemberType.GROUP.getCode().equals(getMemberTypeCode())) {
218                 Group groupInfo = KimApiServiceLocator.getGroupService().getGroup(getMemberId());
219                 if (groupInfo != null) {
220                     setMemberName(groupInfo.getName());
221                     setMemberNamespaceCode(groupInfo.getNamespaceCode());
222                 }
223             } else if (MemberType.ROLE.getCode().equals(getMemberTypeCode())) {
224                 Role roleInfo = KimApiServiceLocator.getRoleService().getRole(getMemberId());
225                 if (roleInfo != null) {
226                     setMemberName(roleInfo.getName());
227                     setMemberNamespaceCode(roleInfo.getNamespaceCode());
228                 }
229             }
230         }
231     }
232 
233     public boolean isRole() {
234         return getMemberTypeCode() != null && getMemberTypeCode().equals(MemberType.ROLE.getCode());
235     }
236 
237     public boolean isGroup() {
238         return getMemberTypeCode() != null && getMemberTypeCode().equals(MemberType.GROUP.getCode());
239     }
240 
241     public boolean isPrincipal() {
242         return getMemberTypeCode() != null && getMemberTypeCode().equals(MemberType.PRINCIPAL.getCode());
243     }
244 
245     public Map<String, String> getQualifierAsMap() {
246         Map<String, String> m = new HashMap<String, String>();
247         for (KimDocumentRoleQualifier data : getQualifiers()) {
248             if (data.getKimAttribute() == null) {
249                 KradDataServiceLocator.getDataObjectService().wrap(this).fetchRelationship("kimAttribute");
250             }
251             if (data.getKimAttribute() != null) {
252                 m.put(data.getKimAttribute().getAttributeName(), data.getAttrVal());
253             }
254         }
255         return m;
256     }
257 
258     public String getQualifiersToDisplay() {
259         return this.qualifiersToDisplay;
260     }
261 
262     public void setQualifiersToDisplay(String qualifiersToDisplay) {
263         this.qualifiersToDisplay = qualifiersToDisplay;
264     }
265 
266     public String getMemberFullName() {
267         return this.memberFullName;
268     }
269 
270 	public void setMemberFullName(String memberFullName) {
271 		this.memberFullName = memberFullName;
272 	}
273 
274     public boolean isMemberNameNull() {
275         if (memberName==null) {
276             return true;
277         }
278         return false;
279     }
280 
281     public boolean isMemberNameSpaceCodeNull() {
282         if (memberNamespaceCode==null) {
283             return true;
284         }
285         return false;
286     }
287 
288     public static void copyProperties(KimDocumentRoleMember copyToKimDocRoleMember, RoleMemberBo copyFromRoleMbrBo){
289         if(copyToKimDocRoleMember!=null && copyFromRoleMbrBo!=null) {
290             copyToKimDocRoleMember.setRoleId(copyFromRoleMbrBo.getRoleId());
291             copyToKimDocRoleMember.setMemberId(copyFromRoleMbrBo.getMemberId());
292             copyToKimDocRoleMember.setMemberName(copyFromRoleMbrBo.getMemberName());
293             copyToKimDocRoleMember.setMemberNamespaceCode(copyFromRoleMbrBo.getMemberNamespaceCode());
294             copyToKimDocRoleMember.setActive(copyFromRoleMbrBo.isActive());
295             copyToKimDocRoleMember.setActiveFromDate(copyFromRoleMbrBo.getActiveFromDateValue());
296             copyToKimDocRoleMember.setActiveToDate(copyFromRoleMbrBo.getActiveToDateValue());
297             copyToKimDocRoleMember.setVersionNumber(copyFromRoleMbrBo.getVersionNumber());
298             copyToKimDocRoleMember.setObjectId(copyFromRoleMbrBo.getObjectId());
299         }
300     }
301 }