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.impl.role;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import javax.persistence.CascadeType;
22  import javax.persistence.Column;
23  import javax.persistence.Convert;
24  import javax.persistence.Entity;
25  import javax.persistence.GeneratedValue;
26  import javax.persistence.Id;
27  import javax.persistence.JoinColumn;
28  import javax.persistence.OneToMany;
29  import javax.persistence.Table;
30  import javax.persistence.Transient;
31  
32  import org.joda.time.DateTime;
33  import org.kuali.rice.core.api.membership.MemberType;
34  import org.kuali.rice.kim.api.role.Role;
35  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
36  import org.kuali.rice.kim.api.type.KimType;
37  import org.kuali.rice.kim.api.type.KimTypeInfoService;
38  import org.kuali.rice.kim.framework.role.RoleEbo;
39  import org.kuali.rice.kim.impl.type.KimTypeBo;
40  import org.kuali.rice.krad.bo.DataObjectBase;
41  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
42  import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
43  import org.springframework.util.AutoPopulatingList;
44  
45  @Entity
46  @Table(name = "KRIM_ROLE_T")
47  public class RoleBo extends DataObjectBase implements RoleEbo {
48  
49      private static final long serialVersionUID = 1L;
50  
51      @PortableSequenceGenerator(name = "KRIM_ROLE_ID_S")
52      @GeneratedValue(generator = "KRIM_ROLE_ID_S")
53      @Id
54      @Column(name = "ROLE_ID")
55      private String id;
56  
57      @Column(name = "ROLE_NM")
58      private String name;
59  
60      @Column(name = "DESC_TXT")
61      private String description;
62  
63      @Column(name = "ACTV_IND")
64      @Convert(converter = BooleanYNConverter.class)
65      private boolean active;
66  
67      @Column(name = "KIM_TYP_ID")
68      private String kimTypeId;
69  
70      @Column(name = "NMSPC_CD")
71      private String namespaceCode;
72  
73      @OneToMany(targetEntity = RoleMemberBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
74      @JoinColumn(name = "ROLE_ID", referencedColumnName = "ROLE_ID", insertable = false, updatable = false)
75      private List<RoleMemberBo> members = new AutoPopulatingList<RoleMemberBo>(RoleMemberBo.class);
76  
77      @Transient
78      private String principalName;
79  
80      @Transient
81      private String groupNamespaceCode;
82  
83      @Transient
84      private String groupName;
85  
86      @Transient
87      private String permNamespaceCode;
88  
89      @Transient
90      private String permName;
91  
92      @Transient
93      private String permTmplNamespaceCode;
94  
95      @Transient
96      private String permTmplName;
97  
98      @Transient
99      private String respNamespaceCode;
100 
101     @Transient
102     private String respName;
103 
104     @Transient
105     private String respTmplNamespaceCode;
106 
107     @Transient
108     private String respTmplName;
109 
110     @Transient
111     private transient KimTypeInfoService kimTypeInfoService;
112 
113     protected List<String> getMembersOfType(String memberTypeCode) {
114         List<String> roleMembers = new ArrayList<String>();
115         for (RoleMemberBo member : getMembers()) {
116             if (member.getType().equals(MemberType.valueOf(memberTypeCode)) && member.isActive(new DateTime())) {
117                 roleMembers.add(member.getMemberId());
118             }
119         }
120         return roleMembers;
121     }
122 
123     public KimTypeBo getKimRoleType() {
124         if (kimTypeId == null) {
125             return null;
126         }
127         KimType type = getTypeInfoService().getKimType(kimTypeId);
128         if (type == null) {
129             return null;
130         }
131         return KimTypeBo.from(type);
132     }
133 
134     protected KimTypeInfoService getTypeInfoService() {
135         if (kimTypeInfoService == null) {
136             kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService();
137         }
138         return kimTypeInfoService;
139     }
140 
141     public static Role to(RoleBo bo) {
142         if (bo == null) {
143             return null;
144         }
145         return Role.Builder.create(bo).build();
146     }
147 
148     public static RoleBo from(Role immutable) {
149         if (immutable == null) {
150             return null;
151         }
152         RoleBo bo = new RoleBo();
153         bo.id = immutable.getId();
154         bo.name = immutable.getName();
155         bo.namespaceCode = immutable.getNamespaceCode();
156         bo.description = immutable.getDescription();
157         bo.kimTypeId = immutable.getKimTypeId();
158         bo.active = immutable.isActive();
159         bo.setVersionNumber(immutable.getVersionNumber());
160         bo.setObjectId(immutable.getObjectId());
161         return bo;
162     }
163 
164     @Override
165     public String getId() {
166         return id;
167     }
168 
169     public void setId(String id) {
170         this.id = id;
171     }
172 
173     @Override
174     public String getName() {
175         return name;
176     }
177 
178     public void setName(String name) {
179         this.name = name;
180     }
181 
182     @Override
183     public String getDescription() {
184         return description;
185     }
186 
187     public void setDescription(String description) {
188         this.description = description;
189     }
190 
191     public boolean getActive() {
192         return active;
193     }
194 
195     @Override
196     public boolean isActive() {
197         return active;
198     }
199 
200     public void setActive(boolean active) {
201         this.active = active;
202     }
203 
204     @Override
205     public String getKimTypeId() {
206         return kimTypeId;
207     }
208 
209     public void setKimTypeId(String kimTypeId) {
210         this.kimTypeId = kimTypeId;
211     }
212 
213     @Override
214     public String getNamespaceCode() {
215         return namespaceCode;
216     }
217 
218     public void setNamespaceCode(String namespaceCode) {
219         this.namespaceCode = namespaceCode;
220     }
221 
222     public List<RoleMemberBo> getMembers() {
223         return members;
224     }
225 
226     public void setMembers(List<RoleMemberBo> members) {
227         this.members = members;
228     }
229 
230     public String getPrincipalName() {
231         return principalName;
232     }
233 
234     public void setPrincipalName(String principalName) {
235         this.principalName = principalName;
236     }
237 
238     public String getGroupNamespaceCode() {
239         return groupNamespaceCode;
240     }
241 
242     public void setGroupNamespaceCode(String groupNamespaceCode) {
243         this.groupNamespaceCode = groupNamespaceCode;
244     }
245 
246     public String getGroupName() {
247         return groupName;
248     }
249 
250     public void setGroupName(String groupName) {
251         this.groupName = groupName;
252     }
253 
254     public String getPermNamespaceCode() {
255         return permNamespaceCode;
256     }
257 
258     public void setPermNamespaceCode(String permNamespaceCode) {
259         this.permNamespaceCode = permNamespaceCode;
260     }
261 
262     public String getPermName() {
263         return permName;
264     }
265 
266     public void setPermName(String permName) {
267         this.permName = permName;
268     }
269 
270     public String getPermTmplNamespaceCode() {
271         return permTmplNamespaceCode;
272     }
273 
274     public void setPermTmplNamespaceCode(String permTmplNamespaceCode) {
275         this.permTmplNamespaceCode = permTmplNamespaceCode;
276     }
277 
278     public String getPermTmplName() {
279         return permTmplName;
280     }
281 
282     public void setPermTmplName(String permTmplName) {
283         this.permTmplName = permTmplName;
284     }
285 
286     public String getRespNamespaceCode() {
287         return respNamespaceCode;
288     }
289 
290     public void setRespNamespaceCode(String respNamespaceCode) {
291         this.respNamespaceCode = respNamespaceCode;
292     }
293 
294     public String getRespName() {
295         return respName;
296     }
297 
298     public void setRespName(String respName) {
299         this.respName = respName;
300     }
301 
302     public String getRespTmplNamespaceCode() {
303         return respTmplNamespaceCode;
304     }
305 
306     public void setRespTmplNamespaceCode(String respTmplNamespaceCode) {
307         this.respTmplNamespaceCode = respTmplNamespaceCode;
308     }
309 
310     public String getRespTmplName() {
311         return respTmplName;
312     }
313 
314     public void setRespTmplName(String respTmplName) {
315         this.respTmplName = respTmplName;
316     }
317 
318     @Override
319     public void refresh() {
320     }
321 }