View Javadoc
1   /**
2    * Copyright 2005-2016 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.Iterator;
19  
20  import javax.persistence.Column;
21  import javax.persistence.Entity;
22  import javax.persistence.GeneratedValue;
23  import javax.persistence.Id;
24  import javax.persistence.Table;
25  import javax.persistence.Transient;
26  
27  import org.apache.commons.lang.StringUtils;
28  import org.kuali.rice.kim.api.KimConstants;
29  import org.kuali.rice.kim.api.permission.Permission;
30  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
31  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
32  
33  /**
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   */
36  @Entity
37  @Table(name = "KRIM_PND_ROLE_PERM_T")
38  public class KimDocumentRolePermission extends KimDocumentBoActivatableBase {
39  
40      private static final long serialVersionUID = 1L;
41  
42      @PortableSequenceGenerator(name = "KRIM_ROLE_PERM_ID_S")
43      @GeneratedValue(generator = "KRIM_ROLE_PERM_ID_S")
44      @Id
45      @Column(name = "ROLE_PERM_ID")
46      protected String rolePermissionId;
47  
48      @Column(name = "ROLE_ID")
49      protected String roleId;
50  
51      @Column(name = "PERM_ID")
52      protected String permissionId;
53  
54      @Transient
55      protected Permission permission;
56  
57      @Transient
58      protected String name;
59  
60      @Transient
61      protected String namespaceCode;
62  
63      public String getPermissionId() {
64          return permissionId;
65      }
66  
67      public String getRoleId() {
68          return roleId;
69      }
70  
71      public String getRolePermissionId() {
72          return rolePermissionId;
73      }
74  
75      public void setPermissionId(String permissionId) {
76          this.permissionId = permissionId;
77      }
78  
79      public void setRoleId(String roleId) {
80          this.roleId = roleId;
81      }
82  
83      public void setRolePermissionId(String rolePermissionId) {
84          this.rolePermissionId = rolePermissionId;
85      }
86  
87      public Permission getPermission() {
88          if (null != permissionId) {
89              if (permission == null || !StringUtils.equals(permission.getId(), permissionId)) {
90                  permission = KimApiServiceLocator.getPermissionService().getPermission(permissionId);
91              }
92          }
93          return permission;
94      }
95  
96      public String getPermissionDetailValues() {
97          Permission perm = getPermission();
98          StringBuilder sb = new StringBuilder();
99          if (perm.getAttributes() != null) {
100             Iterator<String> keyIter = perm.getAttributes().keySet().iterator();
101             while (keyIter.hasNext()) {
102                 String key = keyIter.next();
103                 sb.append(key).append('=').append(perm.getAttributes().get(key));
104                 if (keyIter.hasNext()) {
105                     sb.append(KimConstants.KimUIConstants.COMMA_SEPARATOR).append(" ");
106                 }
107             }
108         }
109         return sb.toString();
110     }
111 
112     public void setPermission(Permission permission) {
113         this.permission = permission;
114     }
115 
116     public String getName() {
117         if (null == permission) {
118             getPermission();
119         }
120         if (null == permission) {
121             return "";
122         }
123         return permission.getName();
124     }
125 
126     public String getNamespaceCode() {
127         if (null == permission) {
128             getPermission();
129         }
130         if (null == permission) {
131             return "";
132         }
133         return permission.getNamespaceCode();
134     }
135 }