Coverage Report - org.kuali.rice.kim.bo.ui.KimDocumentRoleMember
 
Classes in this File Line Coverage Branch Coverage Complexity
KimDocumentRoleMember
0%
0/69
0%
0/38
1.607
 
 1  
 /**
 2  
  * Copyright 2005-2011 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 org.hibernate.annotations.GenericGenerator;
 19  
 import org.hibernate.annotations.Parameter;
 20  
 import org.kuali.rice.core.api.membership.MemberType;
 21  
 import org.kuali.rice.kim.api.KimConstants;
 22  
 import org.kuali.rice.kim.api.group.Group;
 23  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 24  
 import org.kuali.rice.kim.api.role.Role;
 25  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 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.FetchType;
 32  
 import javax.persistence.GeneratedValue;
 33  
 import javax.persistence.Id;
 34  
 import javax.persistence.IdClass;
 35  
 import javax.persistence.JoinColumn;
 36  
 import javax.persistence.JoinColumns;
 37  
 import javax.persistence.OneToMany;
 38  
 import javax.persistence.Table;
 39  
 import javax.persistence.Transient;
 40  
 import java.util.ArrayList;
 41  
 import java.util.HashMap;
 42  
 import java.util.List;
 43  
 import java.util.Map;
 44  
 
 45  
 /**
 46  
  * This is a description of what this class does - shyu don't forget to fill this in. 
 47  
  * 
 48  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 49  
  *
 50  
  */
 51  
 @IdClass(KimDocumentRoleMemberId.class)
 52  
 @Entity
 53  
 @Table(name="KRIM_PND_ROLE_MBR_MT")
 54  
 public class KimDocumentRoleMember  extends KimDocumentBoActivatableToFromEditableBase {
 55  
         private static final long serialVersionUID = -2463865643038170979L;
 56  
 
 57  
         @Id
 58  
         @GeneratedValue(generator="KRIM_ROLE_MBR_ID_S")
 59  
         @GenericGenerator(name="KRIM_ROLE_MBR_ID_S",strategy="org.kuali.rice.core.jpa.spring.RiceNumericStringSequenceStyleGenerator",parameters={
 60  
                         @Parameter(name="sequence_name",value="KRIM_ROLE_MBR_ID_S"),
 61  
                         @Parameter(name="value_column",value="id")
 62  
                 })
 63  
         @Column(name="ROLE_MBR_ID")
 64  
         protected String roleMemberId;
 65  
         
 66  
         @Column(name="ROLE_ID")
 67  
         protected String roleId;
 68  
         @Column(name="MBR_ID")
 69  
         protected String memberId;
 70  
         
 71  
         //TODO: remove the default
 72  0
         @Column(name="MBR_TYP_CD")
 73  
         protected String memberTypeCode = KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode();
 74  
         @Transient
 75  
         protected String memberName;
 76  
         @Transient
 77  
         protected String memberNamespaceCode;
 78  
         
 79  
         protected String memberFullName;
 80  
 
 81  0
         @OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
 82  
         @JoinColumns({
 83  
             @JoinColumn(name="ROLE_MBR_ID", insertable = false, updatable = false), 
 84  
             @JoinColumn(name="FDOC_NBR", insertable = false, updatable = false)
 85  
         })
 86  
         protected List <KimDocumentRoleQualifier> qualifiers = new AutoPopulatingList(KimDocumentRoleQualifier.class);
 87  
         @Transient
 88  
         protected String qualifiersToDisplay;
 89  
         
 90  
         @OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
 91  
         @JoinColumns({
 92  
             @JoinColumn(name="ROLE_MBR_ID", insertable = false, updatable = false), 
 93  
             @JoinColumn(name="FDOC_NBR", insertable = false, updatable = false)
 94  
         })
 95  
         private List<KimDocumentRoleResponsibilityAction> roleRspActions;
 96  
 
 97  0
         public KimDocumentRoleMember() {
 98  0
                 qualifiers = new ArrayList <KimDocumentRoleQualifier>();
 99  0
                 roleRspActions = new ArrayList <KimDocumentRoleResponsibilityAction>();
 100  0
         }
 101  
 
 102  
         public int getNumberOfQualifiers(){
 103  0
                 return qualifiers==null?0:qualifiers.size();
 104  
         }
 105  
         
 106  
         /**
 107  
          * @return the memberId
 108  
          */
 109  
         public String getMemberId() {
 110  0
                 return this.memberId;
 111  
         }
 112  
 
 113  
         /**
 114  
          * @param memberId the memberId to set
 115  
          */
 116  
         public void setMemberId(String memberId) {
 117  0
                 this.memberId = memberId;
 118  0
         }
 119  
 
 120  
         public String getRoleMemberId() {
 121  0
                 return this.roleMemberId;
 122  
         }
 123  
 
 124  
         public void setRoleMemberId(String roleMemberId) {
 125  0
                 this.roleMemberId = roleMemberId;
 126  0
         }
 127  
 
 128  
         public String getRoleId() {
 129  0
                 return this.roleId;
 130  
         }
 131  
 
 132  
         public void setRoleId(String roleId) {
 133  0
                 this.roleId = roleId;
 134  0
         }
 135  
 
 136  
         public KimDocumentRoleQualifier getQualifier(String kimAttributeDefnId) {
 137  0
                 for(KimDocumentRoleQualifier qualifier:qualifiers){
 138  0
                         if(qualifier.getKimAttrDefnId().equals(kimAttributeDefnId)) {
 139  0
                                 return qualifier;
 140  
             }
 141  
                 }
 142  0
                 return null;
 143  
         }
 144  
 
 145  
         public List<KimDocumentRoleQualifier> getQualifiers() {
 146  0
                 return this.qualifiers;
 147  
         }
 148  
 
 149  
         public void setQualifiers(List<KimDocumentRoleQualifier> qualifiers) {
 150  0
                 this.qualifiers = qualifiers;
 151  0
         }
 152  
 
 153  
         /**
 154  
          * @return the memberTypeCode
 155  
          */
 156  
         public String getMemberTypeCode() {
 157  0
                 return this.memberTypeCode;
 158  
         }
 159  
 
 160  
         /**
 161  
          * @param memberTypeCode the memberTypeCode to set
 162  
          */
 163  
         public void setMemberTypeCode(String memberTypeCode) {
 164  0
                 this.memberTypeCode = memberTypeCode;
 165  0
         }
 166  
 
 167  
         /**
 168  
          * @return the memberName
 169  
          */
 170  
         public String getMemberName() {
 171  0
                 if ( memberName == null ) {
 172  0
                         populateDerivedValues();
 173  
                 }
 174  0
                 return memberName;
 175  
         }
 176  
 
 177  
         /**
 178  
          * @param memberName the memberName to set
 179  
          */
 180  
         public void setMemberName(String memberName) {
 181  0
                 this.memberName = memberName;
 182  0
         }
 183  
 
 184  
         public List<KimDocumentRoleResponsibilityAction> getRoleRspActions() {
 185  0
                 return this.roleRspActions;
 186  
         }
 187  
 
 188  
         public void setRoleRspActions(
 189  
                         List<KimDocumentRoleResponsibilityAction> roleRspActions) {
 190  0
                 this.roleRspActions = roleRspActions;
 191  0
         }
 192  
 
 193  
         /**
 194  
          * @return the memberNamespaceCode
 195  
          */
 196  
         public String getMemberNamespaceCode() {
 197  0
                 if ( memberNamespaceCode == null ) {
 198  0
                         populateDerivedValues();
 199  
                 }
 200  0
                 return memberNamespaceCode;
 201  
         }
 202  
 
 203  
         /**
 204  
          * @param memberNamespaceCode the memberNamespaceCode to set
 205  
          */
 206  
         public void setMemberNamespaceCode(String memberNamespaceCode) {
 207  0
                 this.memberNamespaceCode = memberNamespaceCode;
 208  0
         }
 209  
 
 210  
         protected void populateDerivedValues() {
 211  0
         if(MemberType.PRINCIPAL.getCode().equals(getMemberTypeCode())){
 212  0
             Principal principalInfo = KimApiServiceLocator.getIdentityService().getPrincipal(getMemberId());
 213  0
                 if (principalInfo != null) {
 214  0
                         setMemberName(principalInfo.getPrincipalName());
 215  
                 }                                
 216  0
         } else if(MemberType.GROUP.getCode().equals(getMemberTypeCode())){
 217  0
                 Group groupInfo = KimApiServiceLocator.getGroupService().getGroup(getMemberId());
 218  0
                 if (groupInfo != null) {
 219  0
                         setMemberName(groupInfo.getName());
 220  0
                         setMemberNamespaceCode(groupInfo.getNamespaceCode());
 221  
                 }
 222  
                 
 223  0
         } else if(MemberType.ROLE.getCode().equals(getMemberTypeCode())){
 224  0
                 Role role = KimApiServiceLocator.getRoleService().getRole(getMemberId());
 225  0
                 setMemberName(role.getName());
 226  0
                 setMemberNamespaceCode(role.getNamespaceCode());
 227  
         }
 228  0
         }
 229  
         
 230  
         public boolean isRole(){
 231  0
                 return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.ROLE.getCode());
 232  
         }
 233  
         
 234  
         public boolean isGroup(){
 235  0
                 return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.GROUP.getCode());
 236  
         }
 237  
 
 238  
         public boolean isPrincipal(){
 239  0
                 return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.PRINCIPAL.getCode());
 240  
         }
 241  
 
 242  
         public Map<String, String> getQualifierAsMap() {
 243  0
                 Map<String, String> m = new HashMap<String, String>();
 244  0
                 for ( KimDocumentRoleQualifier data : getQualifiers() ) {
 245  0
                         if (data.getKimAttribute() == null){
 246  0
                                 data.refreshReferenceObject("kimAttribute");
 247  
                         }
 248  0
                         if (data.getKimAttribute() != null){
 249  0
                                 m.put( data.getKimAttribute().getAttributeName(), data.getAttrVal() );
 250  
                         }
 251  
                 }
 252  0
                 return m;
 253  
         }
 254  
 
 255  
         /**
 256  
          * @return the qualifiersToDisplay
 257  
          */
 258  
         public String getQualifiersToDisplay() {
 259  0
                 return this.qualifiersToDisplay;
 260  
         }
 261  
 
 262  
         /**
 263  
          * @param qualifiersToDisplay the qualifiersToDisplay to set
 264  
          */
 265  
         public void setQualifiersToDisplay(String qualifiersToDisplay) {
 266  0
                 this.qualifiersToDisplay = qualifiersToDisplay;
 267  0
         }
 268  
         
 269  
         /**
 270  
          * @return the memberFullName
 271  
          */
 272  
         public String getMemberFullName() {
 273  0
                 return this.memberFullName;
 274  
         }
 275  
 
 276  
         /**
 277  
          * @param memberFullName the memberFullName to set
 278  
          */
 279  
         public void setMemberFullName(String memberFullName) {
 280  0
                 this.memberFullName = memberFullName;
 281  0
         }
 282  
 
 283  
 }