View Javadoc

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.document;
17  
18  import java.util.List;
19  
20  import org.apache.log4j.Logger;
21  import org.kuali.rice.kew.util.KEWConstants;
22  import org.kuali.rice.kim.bo.ui.RoleDocumentDelegation;
23  import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember;
24  import org.kuali.rice.kim.util.KimConstants;
25  import org.kuali.rice.kns.datadictionary.AttributeDefinition;
26  import org.kuali.rice.kns.datadictionary.KimDataDictionaryAttributeDefinition;
27  import org.kuali.rice.kns.datadictionary.KimNonDataDictionaryAttributeDefinition;
28  import org.kuali.rice.kns.document.TransactionalDocumentBase;
29  import org.kuali.rice.kns.service.KNSServiceLocator;
30  import org.kuali.rice.kns.service.SequenceAccessorService;
31  import org.kuali.rice.kns.util.TypedArrayList;
32  
33  /**
34   * This is a description of what this class does - bhargavp don't forget to fill this in. 
35   * 
36   * @author Kuali Rice Team (rice.collab@kuali.org)
37   *
38   */
39  public class IdentityManagementKimDocument extends TransactionalDocumentBase {
40  
41  	protected static final Logger LOG = Logger.getLogger(IdentityManagementKimDocument.class);
42  	
43  	protected List<RoleDocumentDelegation> delegations = new TypedArrayList(RoleDocumentDelegation.class);
44  	protected List<RoleDocumentDelegationMember> delegationMembers = new TypedArrayList(RoleDocumentDelegationMember.class);
45  
46  	protected transient SequenceAccessorService sequenceAccessorService;
47  	
48  	protected void addDelegationMemberToDelegation(RoleDocumentDelegationMember delegationMember){
49  		RoleDocumentDelegation delegation;
50  		if(KEWConstants.DELEGATION_PRIMARY.equals(delegationMember.getDelegationTypeCode())){
51  			delegation = getPrimaryDelegation();
52  		} else{
53  			delegation = getSecondaryDelegation();
54  		}
55  		delegationMember.setDelegationId(delegation.getDelegationId());
56  		delegation.getMembers().add(delegationMember);
57  		delegation.setRoleId(delegationMember.getRoleImpl().getRoleId());
58  		delegation.setKimTypeId(delegationMember.getRoleImpl().getKimTypeId());
59  	}
60  
61  	protected RoleDocumentDelegation getPrimaryDelegation(){
62  		RoleDocumentDelegation primaryDelegation = null;
63  		for(RoleDocumentDelegation delegation: getDelegations()){
64  			if(delegation.isDelegationPrimary())
65  				primaryDelegation = delegation;
66  		}
67  		if(primaryDelegation==null){
68  			primaryDelegation = new RoleDocumentDelegation();
69  			primaryDelegation.setDelegationId(getDelegationId());
70  			primaryDelegation.setDelegationTypeCode(KEWConstants.DELEGATION_PRIMARY);
71  			getDelegations().add(primaryDelegation);
72  		}
73  		return primaryDelegation;
74  	}
75  
76  	protected String getDelegationId(){
77  		return getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_DLGN_ID_S).toString();
78  	}
79  	
80  	protected RoleDocumentDelegation getSecondaryDelegation(){
81  		RoleDocumentDelegation secondaryDelegation = null;
82  		for(RoleDocumentDelegation delegation: getDelegations()){
83  			if(delegation.isDelegationSecondary())
84  				secondaryDelegation = delegation;
85  		}
86  		if(secondaryDelegation==null){
87  			secondaryDelegation = new RoleDocumentDelegation();
88  			secondaryDelegation.setDelegationId(getDelegationId());
89  			secondaryDelegation.setDelegationTypeCode(KEWConstants.DELEGATION_SECONDARY);
90  			getDelegations().add(secondaryDelegation);
91  		}
92  		return secondaryDelegation;
93  	}
94  
95  	/**
96  	 * @return the delegations
97  	 */
98  	public List<RoleDocumentDelegation> getDelegations() {
99  		return this.delegations;
100 	}
101 
102 	/**
103 	 * @param delegations the delegations to set
104 	 */
105 	public void setDelegations(List<RoleDocumentDelegation> delegations) {
106 		this.delegations = delegations;
107 	}
108 
109 	/**
110 	 * @return the delegationMembers
111 	 */
112 	public List<RoleDocumentDelegationMember> getDelegationMembers() {
113 		return this.delegationMembers;
114 	}
115 
116 	/**
117 	 * @param delegationMembers the delegationMembers to set
118 	 */
119 	public void setDelegationMembers(
120 			List<RoleDocumentDelegationMember> delegationMembers) {
121 		this.delegationMembers = delegationMembers;
122 	}
123 	
124 	protected SequenceAccessorService getSequenceAccessorService(){
125 		if(this.sequenceAccessorService==null){
126 	    	this.sequenceAccessorService = KNSServiceLocator.getSequenceAccessorService();
127 		}
128 		return this.sequenceAccessorService;
129 	}
130 
131     public String getKimAttributeDefnId(AttributeDefinition definition){
132     	if (definition instanceof KimDataDictionaryAttributeDefinition) {
133     		return ((KimDataDictionaryAttributeDefinition)definition).getKimAttrDefnId();
134     	} else {
135     		return ((KimNonDataDictionaryAttributeDefinition)definition).getKimAttrDefnId();
136     	}
137     }
138 
139 }