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