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.impl.responsibility;
17  
18  import java.util.Iterator;
19  import java.util.List;
20  import java.util.Map;
21  
22  import javax.persistence.Entity;
23  import javax.persistence.Id;
24  import javax.persistence.Inheritance;
25  import javax.persistence.InheritanceType;
26  import javax.persistence.Table;
27  
28  import org.apache.commons.lang.StringUtils;
29  import org.kuali.rice.kim.api.KimConstants;
30  import org.kuali.rice.kim.api.identity.Person;
31  import org.kuali.rice.kim.api.responsibility.Responsibility;
32  import org.kuali.rice.kim.api.responsibility.ResponsibilityContract;
33  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
34  import org.kuali.rice.kim.api.type.KimType;
35  import org.kuali.rice.kim.api.type.KimTypeAttribute;
36  import org.kuali.rice.kim.api.type.KimTypeInfoService;
37  import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo;
38  import org.kuali.rice.kim.impl.group.GroupBo;
39  import org.kuali.rice.kim.impl.identity.PersonImpl;
40  import org.kuali.rice.kim.impl.role.RoleBo;
41  import org.kuali.rice.kim.impl.role.RoleResponsibilityBo;
42  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
43  import org.kuali.rice.krad.service.DataDictionaryService;
44  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
45  import org.springframework.util.AutoPopulatingList;
46  
47  @Entity
48  @Table(name="ZZZ_FAKE_KRIM_RSP_T")
49  @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
50  public class UberResponsibilityBo extends PersistableBusinessObjectBase implements ResponsibilityContract {
51      private static final long serialVersionUID = 1L;
52  
53      @Id
54      private String id;
55  
56      private String namespaceCode;
57  
58      private String name;
59  
60      private String description;
61  
62      private String templateId;
63  
64      private boolean active;
65  
66      private ResponsibilityTemplateBo template = new ResponsibilityTemplateBo();
67  
68      private List<ResponsibilityAttributeBo> attributeDetails = new AutoPopulatingList<ResponsibilityAttributeBo>(ResponsibilityAttributeBo.class);
69  
70      private List<RoleResponsibilityBo> roleResponsibilities = new AutoPopulatingList<RoleResponsibilityBo>(RoleResponsibilityBo.class);
71  
72      private Map<String, String> attributes;
73  
74      @Override
75      public Map<String, String> getAttributes() {
76          return attributeDetails != null ? KimAttributeDataBo.toAttributes(attributeDetails) : attributes;
77      }
78  
79      /**
80       * Converts a mutable bo to its immutable counterpart
81       *
82       * @param bo the mutable business object
83       * @return the immutable object
84       */
85      public static Responsibility to(ResponsibilityBo bo) {
86          if (bo == null) {
87              return null;
88          }
89          return Responsibility.Builder.create(bo).build();
90      }
91  
92      /**
93       * Converts a immutable object to its mutable counterpart
94       *
95       * @param im immutable object
96       * @return the mutable bo
97       */
98      public static ResponsibilityBo from(Responsibility im) {
99          if (im == null) {
100             return null;
101         }
102         ResponsibilityBo bo = new ResponsibilityBo();
103         bo.id = im.getId();
104         bo.namespaceCode = im.getNamespaceCode();
105         bo.name = im.getName();
106         bo.description = im.getDescription();
107         bo.active = im.isActive();
108         bo.templateId = im.getTemplate() != null ? im.getTemplate().getId() : null;
109         bo.template = ResponsibilityTemplateBo.from(im.getTemplate());
110         bo.attributes = im.getAttributes();
111         bo.setVersionNumber(im.getVersionNumber());
112         bo.setObjectId(im.getObjectId());
113         return bo;
114     }
115 
116     public ResponsibilityTemplateBo getTemplate() {
117         return template;
118     }
119 
120     public String getDetailObjectsValues() {
121         StringBuffer detailObjectsToDisplayBuffer = new StringBuffer();
122         Iterator<ResponsibilityAttributeBo> respIter = attributeDetails.iterator();
123         while (respIter.hasNext()) {
124             ResponsibilityAttributeBo respAttributeData = respIter.next();
125             detailObjectsToDisplayBuffer.append(respAttributeData.getAttributeValue());
126             if (respIter.hasNext()) {
127                 detailObjectsToDisplayBuffer.append(KimConstants.KimUIConstants.COMMA_SEPARATOR);
128             }
129         }
130         return detailObjectsToDisplayBuffer.toString();
131     }
132 
133     public String getDetailObjectsToDisplay() {
134         final KimType kimType = getTypeInfoService().getKimType(getTemplate().getKimTypeId());
135         StringBuffer detailObjects = new StringBuffer();
136         Iterator<ResponsibilityAttributeBo> respIter = attributeDetails.iterator();
137         while (respIter.hasNext()) {
138             ResponsibilityAttributeBo bo = respIter.next();
139             detailObjects.append(getKimAttributeLabelFromDD(kimType.getAttributeDefinitionById(bo.getKimAttributeId()))).append(":").append(bo.getAttributeValue());
140             if (respIter.hasNext()) {
141                 detailObjects.append(KimConstants.KimUIConstants.COMMA_SEPARATOR);
142             }
143         }
144         return detailObjects.toString();
145     }
146 
147     private String getKimAttributeLabelFromDD(KimTypeAttribute attribute) {
148         return getDataDictionaryService().getAttributeLabel(attribute.getKimAttribute().getComponentName(), attribute.getKimAttribute().getAttributeName());
149     }
150 
151     private DataDictionaryService getDataDictionaryService() {
152         return KRADServiceLocatorWeb.getDataDictionaryService();
153     }
154 
155     private KimTypeInfoService getTypeInfoService() {
156         return KimApiServiceLocator.getKimTypeInfoService();
157     }
158 
159     @Override
160     public String getId() {
161         return id;
162     }
163 
164     public void setId(String id) {
165         this.id = id;
166     }
167 
168     @Override
169     public String getNamespaceCode() {
170         return namespaceCode;
171     }
172 
173     public void setNamespaceCode(String namespaceCode) {
174         this.namespaceCode = namespaceCode;
175     }
176 
177     @Override
178     public String getName() {
179         return name;
180     }
181 
182     public void setName(String name) {
183         this.name = name;
184     }
185 
186     @Override
187     public String getDescription() {
188         return description;
189     }
190 
191     public void setDescription(String description) {
192         this.description = description;
193     }
194 
195     public String getTemplateId() {
196         return templateId;
197     }
198 
199     public void setTemplateId(String templateId) {
200         this.templateId = templateId;
201     }
202 
203     public boolean getActive() {
204         return active;
205     }
206 
207     @Override
208     public boolean isActive() {
209         return active;
210     }
211 
212     public void setActive(boolean active) {
213         this.active = active;
214     }
215 
216     public void setTemplate(ResponsibilityTemplateBo template) {
217         this.template = template;
218     }
219 
220     public List<ResponsibilityAttributeBo> getAttributeDetails() {
221         return attributeDetails;
222     }
223 
224     public void setAttributeDetails(List<ResponsibilityAttributeBo> attributeDetails) {
225         this.attributeDetails = attributeDetails;
226     }
227 
228     public List<RoleResponsibilityBo> getRoleResponsibilities() {
229         return roleResponsibilities;
230     }
231 
232     public void setRoleResponsibilities(List<RoleResponsibilityBo> roleResponsibilities) {
233         this.roleResponsibilities = roleResponsibilities;
234     }
235 
236     public void setAttributes(Map<String, String> attributes) {
237         this.attributes = attributes;
238     }
239     
240     private List<RoleBo> assignedToRoles = new AutoPopulatingList<RoleBo>(RoleBo.class);
241     private String assignedToRoleNamespaceForLookup;
242     private String assignedToRoleNameForLookup;
243     private RoleBo assignedToRole = new RoleBo();
244     private String assignedToPrincipalNameForLookup;
245     private Person assignedToPrincipal = new PersonImpl();
246     private String assignedToGroupNamespaceForLookup;
247     private String assignedToGroupNameForLookup;
248     private GroupBo assignedToGroup = new GroupBo();
249     private String attributeName;
250     private String attributeValue;
251     private String detailCriteria;
252 
253     public String getAssignedToRolesToDisplay() {
254         StringBuffer assignedToRolesToDisplay = new StringBuffer();
255         for (RoleBo roleImpl : assignedToRoles) {
256             assignedToRolesToDisplay.append(getRoleDetailsToDisplay(roleImpl));
257         }
258 
259         return StringUtils.chomp(assignedToRolesToDisplay.toString(), KimConstants.KimUIConstants.COMMA_SEPARATOR);
260     }
261 
262     public String getRoleDetailsToDisplay(RoleBo roleImpl) {
263         return roleImpl.getNamespaceCode().trim() + " " + roleImpl.getName().trim() + KimConstants.KimUIConstants.COMMA_SEPARATOR;
264     }
265 
266     public List<RoleBo> getAssignedToRoles() {
267         return assignedToRoles;
268     }
269 
270     public void setAssignedToRoles(List<RoleBo> assignedToRoles) {
271         this.assignedToRoles = assignedToRoles;
272     }
273 
274     public String getAssignedToRoleNamespaceForLookup() {
275         return assignedToRoleNamespaceForLookup;
276     }
277 
278     public void setAssignedToRoleNamespaceForLookup(String assignedToRoleNamespaceForLookup) {
279         this.assignedToRoleNamespaceForLookup = assignedToRoleNamespaceForLookup;
280     }
281 
282     public String getAssignedToRoleNameForLookup() {
283         return assignedToRoleNameForLookup;
284     }
285 
286     public void setAssignedToRoleNameForLookup(String assignedToRoleNameForLookup) {
287         this.assignedToRoleNameForLookup = assignedToRoleNameForLookup;
288     }
289 
290     public RoleBo getAssignedToRole() {
291         return assignedToRole;
292     }
293 
294     public void setAssignedToRole(RoleBo assignedToRole) {
295         this.assignedToRole = assignedToRole;
296     }
297 
298     public String getAssignedToPrincipalNameForLookup() {
299         return assignedToPrincipalNameForLookup;
300     }
301 
302     public void setAssignedToPrincipalNameForLookup(String assignedToPrincipalNameForLookup) {
303         this.assignedToPrincipalNameForLookup = assignedToPrincipalNameForLookup;
304     }
305 
306     public Person getAssignedToPrincipal() {
307         return assignedToPrincipal;
308     }
309 
310     public void setAssignedToPrincipal(Person assignedToPrincipal) {
311         this.assignedToPrincipal = assignedToPrincipal;
312     }
313 
314     public String getAssignedToGroupNamespaceForLookup() {
315         return assignedToGroupNamespaceForLookup;
316     }
317 
318     public void setAssignedToGroupNamespaceForLookup(String assignedToGroupNamespaceForLookup) {
319         this.assignedToGroupNamespaceForLookup = assignedToGroupNamespaceForLookup;
320     }
321 
322     public String getAssignedToGroupNameForLookup() {
323         return assignedToGroupNameForLookup;
324     }
325 
326     public void setAssignedToGroupNameForLookup(String assignedToGroupNameForLookup) {
327         this.assignedToGroupNameForLookup = assignedToGroupNameForLookup;
328     }
329 
330     public GroupBo getAssignedToGroup() {
331         return assignedToGroup;
332     }
333 
334     public void setAssignedToGroup(GroupBo assignedToGroup) {
335         this.assignedToGroup = assignedToGroup;
336     }
337 
338     public String getAttributeName() {
339         return attributeName;
340     }
341 
342     public void setAttributeName(String attributeName) {
343         this.attributeName = attributeName;
344     }
345 
346     public String getAttributeValue() {
347         return attributeValue;
348     }
349 
350     public void setAttributeValue(String attributeValue) {
351         this.attributeValue = attributeValue;
352     }
353 
354     public String getDetailCriteria() {
355         return detailCriteria;
356     }
357 
358     public void setDetailCriteria(String detailCriteria) {
359         this.detailCriteria = detailCriteria;
360     }
361 
362 
363 }