Coverage Report - org.kuali.rice.kim.document.IdentityManagementKimDocument
 
Classes in this File Line Coverage Branch Coverage Complexity
IdentityManagementKimDocument
0%
0/43
0%
0/16
1.8
 
 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.document;
 17  
 
 18  
 import org.apache.log4j.Logger;
 19  
 import org.kuali.rice.core.api.delegation.DelegationType;
 20  
 import org.kuali.rice.kim.api.KimConstants;
 21  
 import org.kuali.rice.kim.api.type.KimAttributeField;
 22  
 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegation;
 23  
 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember;
 24  
 import org.kuali.rice.krad.document.TransactionalDocumentBase;
 25  
 import org.kuali.rice.krad.service.KRADServiceLocator;
 26  
 import org.kuali.rice.krad.service.SequenceAccessorService;
 27  
 import org.springframework.util.AutoPopulatingList;
 28  
 
 29  
 import javax.persistence.AssociationOverride;
 30  
 import javax.persistence.AssociationOverrides;
 31  
 import javax.persistence.AttributeOverride;
 32  
 import javax.persistence.AttributeOverrides;
 33  
 import javax.persistence.CascadeType;
 34  
 import javax.persistence.Column;
 35  
 import javax.persistence.FetchType;
 36  
 import javax.persistence.JoinColumn;
 37  
 import javax.persistence.MappedSuperclass;
 38  
 import javax.persistence.OneToMany;
 39  
 import javax.persistence.Transient;
 40  
 import java.util.List;
 41  
 
 42  
 /**
 43  
  * This is a description of what this class does - bhargavp don't forget to fill this in. 
 44  
  * 
 45  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 46  
  *
 47  
  */
 48  
 @MappedSuperclass
 49  
 @AttributeOverrides({
 50  
         @AttributeOverride(name="documentNumber",column=@Column(name="FDOC_NBR"))
 51  
 })
 52  
 @AssociationOverrides({
 53  
         @AssociationOverride(name="documentHeader",joinColumns=@JoinColumn(name="FDOC_NBR",referencedColumnName="DOC_HDR_ID",insertable=false,updatable=false))
 54  
 })
 55  0
 public class IdentityManagementKimDocument extends TransactionalDocumentBase {
 56  
 
 57  0
         protected static final Logger LOG = Logger.getLogger(IdentityManagementKimDocument.class);
 58  
         
 59  0
         @OneToMany(targetEntity=RoleDocumentDelegation.class, fetch=FetchType.EAGER, cascade={CascadeType.ALL})
 60  
     @JoinColumn(name="FDOC_NBR",insertable=false,updatable=false)
 61  
         protected List<RoleDocumentDelegation> delegations = new AutoPopulatingList(RoleDocumentDelegation.class);
 62  0
         @Transient
 63  
         protected List<RoleDocumentDelegationMember> delegationMembers = new AutoPopulatingList(RoleDocumentDelegationMember.class);
 64  
         @Transient
 65  
         protected transient SequenceAccessorService sequenceAccessorService;
 66  
         
 67  
         protected void addDelegationMemberToDelegation(RoleDocumentDelegationMember delegationMember){
 68  
                 RoleDocumentDelegation delegation;
 69  0
                 if(DelegationType.PRIMARY.getCode().equals(delegationMember.getDelegationTypeCode())){
 70  0
                         delegation = getPrimaryDelegation();
 71  
                 } else{
 72  0
                         delegation = getSecondaryDelegation();
 73  
                 }
 74  0
                 delegationMember.setDelegationId(delegation.getDelegationId());
 75  0
                 delegation.getMembers().add(delegationMember);
 76  0
                 delegation.setRoleId(delegationMember.getRoleBo().getId());
 77  0
                 delegation.setKimTypeId(delegationMember.getRoleBo().getKimTypeId());
 78  0
         }
 79  
 
 80  
         protected RoleDocumentDelegation getPrimaryDelegation(){
 81  0
                 RoleDocumentDelegation primaryDelegation = null;
 82  0
                 for(RoleDocumentDelegation delegation: getDelegations()){
 83  0
                         if(delegation.isDelegationPrimary()) {
 84  0
                                 primaryDelegation = delegation;
 85  
             }
 86  
                 }
 87  0
                 if(primaryDelegation==null){
 88  0
                         primaryDelegation = new RoleDocumentDelegation();
 89  0
                         primaryDelegation.setDelegationId(getDelegationId());
 90  0
                         primaryDelegation.setDelegationTypeCode(DelegationType.PRIMARY.getCode());
 91  0
                         getDelegations().add(primaryDelegation);
 92  
                 }
 93  0
                 return primaryDelegation;
 94  
         }
 95  
 
 96  
         protected String getDelegationId(){
 97  0
                 return getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_DLGN_ID_S).toString();
 98  
         }
 99  
         
 100  
         protected RoleDocumentDelegation getSecondaryDelegation(){
 101  0
                 RoleDocumentDelegation secondaryDelegation = null;
 102  0
                 for(RoleDocumentDelegation delegation: getDelegations()){
 103  0
                         if(delegation.isDelegationSecondary()) {
 104  0
                                 secondaryDelegation = delegation;
 105  
             }
 106  
                 }
 107  0
                 if(secondaryDelegation==null){
 108  0
                         secondaryDelegation = new RoleDocumentDelegation();
 109  0
                         secondaryDelegation.setDelegationId(getDelegationId());
 110  0
                         secondaryDelegation.setDelegationTypeCode(DelegationType.SECONDARY.getCode());
 111  0
                         getDelegations().add(secondaryDelegation);
 112  
                 }
 113  0
                 return secondaryDelegation;
 114  
         }
 115  
 
 116  
         /**
 117  
          * @return the delegations
 118  
          */
 119  
         public List<RoleDocumentDelegation> getDelegations() {
 120  0
                 return this.delegations;
 121  
         }
 122  
 
 123  
         /**
 124  
          * @param delegations the delegations to set
 125  
          */
 126  
         public void setDelegations(List<RoleDocumentDelegation> delegations) {
 127  0
                 this.delegations = delegations;
 128  0
         }
 129  
 
 130  
         /**
 131  
          * @return the delegationMembers
 132  
          */
 133  
         public List<RoleDocumentDelegationMember> getDelegationMembers() {
 134  0
                 return this.delegationMembers;
 135  
         }
 136  
 
 137  
         /**
 138  
          * @param delegationMembers the delegationMembers to set
 139  
          */
 140  
         public void setDelegationMembers(
 141  
                         List<RoleDocumentDelegationMember> delegationMembers) {
 142  0
                 this.delegationMembers = delegationMembers;
 143  0
         }
 144  
         
 145  
         protected SequenceAccessorService getSequenceAccessorService(){
 146  0
                 if(this.sequenceAccessorService==null){
 147  0
                     this.sequenceAccessorService = KRADServiceLocator.getSequenceAccessorService();
 148  
                 }
 149  0
                 return this.sequenceAccessorService;
 150  
         }
 151  
 
 152  
     public String getKimAttributeDefnId(KimAttributeField definition){
 153  0
                    return definition.getId();
 154  
     }
 155  
 
 156  
 }