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.krad.bo;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.kim.api.group.Group;
20  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
21  import javax.persistence.Entity;
22  import javax.persistence.Table;
23  import javax.persistence.Transient;
24  import javax.persistence.UniqueConstraint;
25  
26  
27  /**
28   * Ad Hoc Route Workgroup Business Object.
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  @Entity
33  @Table(name="KRNS_ADHOC_RTE_ACTN_RECIP_T",uniqueConstraints= {
34          @UniqueConstraint(name="KRNS_ADHOC_RTE_ACTN_RECIP_TC0",columnNames="OBJ_ID")
35  })
36  public class AdHocRouteWorkgroup extends AdHocRouteRecipient {
37      private static final long serialVersionUID = 1L;
38  
39      @Transient
40      private String recipientNamespaceCode;
41  
42      @Transient
43      private String recipientName;
44  
45      @Transient
46      private Group group;
47  
48      /**
49       * Sets type to {@link #WORKGROUP_TYPE}.
50       */
51      public AdHocRouteWorkgroup() {
52          setType(WORKGROUP_TYPE);
53      }
54  
55      @Override
56      public void setType(Integer type) {
57          if (!WORKGROUP_TYPE.equals(type)) {
58              throw new IllegalArgumentException("cannot change type to " + type);
59          }
60          super.setType(type);
61      }
62  
63      @Override
64      public void setId(String id) {
65          super.setId(id);
66  
67          if (StringUtils.isNotBlank(id)) {
68              group = KimApiServiceLocator.getGroupService().getGroup(id);
69              setGroup(group);
70          }
71      }
72  
73      @Override
74      public String getName() {
75          return "";
76      }
77  
78      /**
79       * Gets recipient namespace code.
80       * @return namespace code
81       */
82      public String getRecipientNamespaceCode() {
83          return this.recipientNamespaceCode;
84      }
85  
86      /**
87       * Setter for {@link #getRecipientNamespaceCode()}.
88       *
89       * @param recipientNamespaceCode recipient namespace code
90       */
91      public void setRecipientNamespaceCode(String recipientNamespaceCode) {
92          this.recipientNamespaceCode = recipientNamespaceCode;
93  
94          if (StringUtils.isNotBlank(recipientNamespaceCode) && StringUtils.isNotBlank(recipientName)) {
95              group = KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(recipientNamespaceCode, recipientName);
96              setGroup(group);
97          }
98      }
99  
100     /**
101      * Gets recipient name.
102      *
103      * @return recipient name
104      */
105     public String getRecipientName() {
106         return this.recipientName;
107     }
108 
109     /**
110      * Setter for {@link #recipientName}.
111      *
112      * @param recipientName recipient name
113      */
114     public void setRecipientName(String recipientName) {
115         this.recipientName = recipientName;
116 
117         if (StringUtils.isNotBlank(recipientNamespaceCode) && StringUtils.isNotBlank(recipientName)) {
118             group = KimApiServiceLocator.getGroupService().getGroupByNamespaceCodeAndName(recipientNamespaceCode, recipientName);
119             setGroup(group);
120         }
121     }
122 
123     public Group getGroup() {
124         return group;
125     }
126 
127     public void setGroup(Group group) {
128         this.group = group;
129 
130         if (group != null) {
131             this.id = group.getId();
132             this.recipientNamespaceCode = group.getNamespaceCode();
133             this.recipientName = group.getName();
134         }
135     }
136 
137 }