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