View Javadoc

1   /**
2    * Copyright 2005-2014 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.kim.api.responsibility.Responsibility;
21  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
22  import org.kuali.rice.kim.impl.responsibility.ResponsibilityBo;
23  import org.springframework.util.AutoPopulatingList;
24  
25  import javax.persistence.Column;
26  import javax.persistence.Entity;
27  import javax.persistence.GeneratedValue;
28  import javax.persistence.Id;
29  import javax.persistence.IdClass;
30  import javax.persistence.Table;
31  import javax.persistence.Transient;
32  import java.util.List;
33  
34  /**
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   */
37  @IdClass(KimDocumentRoleResponsibilityId.class)
38  @Entity
39  @Table(name="KRIM_PND_ROLE_RSP_T")
40  public class KimDocumentRoleResponsibility extends KimDocumentBoActivatableBase {
41  	
42  	private static final long serialVersionUID = -4465768714850961538L;
43  	@Id
44  	@GeneratedValue(generator="KRIM_ROLE_RSP_ACTN_ID_S")
45  	@GenericGenerator(name="KRIM_ROLE_RSP_ACTN_ID_S",strategy="org.kuali.rice.core.jpa.spring.RiceNumericStringSequenceStyleGenerator",parameters={
46  			@Parameter(name="sequence_name",value="KRIM_ROLE_RSP_ACTN_ID_S"),
47  			@Parameter(name="value_column",value="id")
48  		})
49  	@Column(name="ROLE_RSP_ID")
50  	protected String roleResponsibilityId;
51  	@Column(name="ROLE_ID")
52  	protected String roleId;
53  	@Column(name="RSP_ID")
54  	protected String responsibilityId;
55  	// temporary default value in lieu of optimistic locking
56  	@Column(name="VER_NBR")
57  	protected Long versionNumber = (long) 0;
58  	@Transient
59  	protected ResponsibilityBo kimResponsibility;
60  	@Transient
61  	protected List<KimDocumentRoleResponsibilityAction> roleRspActions = new AutoPopulatingList(KimDocumentRoleResponsibilityAction.class);
62      @Transient
63      protected String name;
64      @Transient
65      protected String namespaceCode;
66  
67  	public String getRoleId() {
68  		return roleId;
69  	}
70  
71  	public void setRoleId(String roleId) {
72  		this.roleId = roleId;
73  	}
74  
75  	public void setRoleResponsibilityId(String roleResponsibilityId) {
76  		this.roleResponsibilityId = roleResponsibilityId;
77  	}
78  
79  	/**
80  	 * @return the roleResponsibilityId
81  	 */
82  	public String getRoleResponsibilityId() {
83  		return this.roleResponsibilityId;
84  	}
85  
86  	/**
87  	 * @return the kimResponsibility
88  	 */
89  	public ResponsibilityBo getKimResponsibility() {
90  		if ( kimResponsibility == null && responsibilityId != null ) {
91  			//TODO: this needs to be changed to use the KimResponsibilityInfo object
92  			// but the changes are involved in the UiDocumentService based on the copyProperties method used
93  			// to move the data to/from the document/real objects
94              Responsibility info = KimApiServiceLocator.getResponsibilityService().getResponsibility(getResponsibilityId());
95              kimResponsibility = ResponsibilityBo.from(info);
96  		}
97  		return this.kimResponsibility;
98  	}
99  
100 	/**
101 	 * @param responsibilityId the responsibilityId to set
102 	 */
103 	public void setResponsibilityId(String responsibilityId) {
104 		this.responsibilityId = responsibilityId;
105 	}
106 
107 	/**
108 	 * @param kimResponsibility the kimResponsibility to set
109 	 */
110 	public void setKimResponsibility(ResponsibilityBo kimResponsibility) {
111 		this.kimResponsibility = kimResponsibility;
112 	}
113 
114 	/**
115 	 * @return the responsibilityId
116 	 */
117 	public String getResponsibilityId() {
118     		return this.responsibilityId;
119 	}
120 
121 	/**
122 	 * @return the roleRspActions
123 	 */
124 	public KimDocumentRoleResponsibilityAction getRoleRspAction() {
125 		if(this.roleRspActions!=null && this.roleRspActions.size()>0)
126 			return this.roleRspActions.get(0);
127 		return null;
128 	}
129 
130 	/**
131 	 * @return the roleRspActions
132 	 */
133 	public List<KimDocumentRoleResponsibilityAction> getRoleRspActions() {
134 		return this.roleRspActions;
135 	}
136 
137 	/**
138 	 * @param roleRspActions the roleRspActions to set
139 	 */
140 	public void setRoleRspActions(
141 			List<KimDocumentRoleResponsibilityAction> roleRspActions) {
142 		this.roleRspActions = roleRspActions;
143 	}
144 
145     public String getName(){
146         if( null == kimResponsibility ) {
147             getKimResponsibility();
148         }
149 
150         if (null == kimResponsibility) {
151             return "";
152         }
153 
154         return kimResponsibility.getName();
155     }
156 
157     public String getNamespaceCode(){
158         if( null == kimResponsibility ) {
159             getKimResponsibility();
160         }
161 
162         if (null == kimResponsibility) {
163             return "";
164         }
165 
166         return kimResponsibility.getNamespaceCode();
167     }
168 }