001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kim.impl.responsibility; 017 018import java.util.Iterator; 019import java.util.List; 020import java.util.Map; 021 022import javax.persistence.Entity; 023import javax.persistence.Id; 024import javax.persistence.Inheritance; 025import javax.persistence.InheritanceType; 026import javax.persistence.Table; 027 028import org.apache.commons.lang.StringUtils; 029import org.kuali.rice.kim.api.KimConstants; 030import org.kuali.rice.kim.api.identity.Person; 031import org.kuali.rice.kim.api.responsibility.Responsibility; 032import org.kuali.rice.kim.api.responsibility.ResponsibilityContract; 033import org.kuali.rice.kim.api.services.KimApiServiceLocator; 034import org.kuali.rice.kim.api.type.KimType; 035import org.kuali.rice.kim.api.type.KimTypeAttribute; 036import org.kuali.rice.kim.api.type.KimTypeInfoService; 037import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo; 038import org.kuali.rice.kim.impl.group.GroupBo; 039import org.kuali.rice.kim.impl.identity.PersonImpl; 040import org.kuali.rice.kim.impl.role.RoleBo; 041import org.kuali.rice.kim.impl.role.RoleResponsibilityBo; 042import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; 043import org.kuali.rice.krad.service.DataDictionaryService; 044import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 045import org.springframework.util.AutoPopulatingList; 046 047@Entity 048@Table(name="ZZZ_FAKE_KRIM_RSP_T") 049@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) 050public class UberResponsibilityBo extends PersistableBusinessObjectBase implements ResponsibilityContract { 051 private static final long serialVersionUID = 1L; 052 053 @Id 054 private String id; 055 056 private String namespaceCode; 057 058 private String name; 059 060 private String description; 061 062 private String templateId; 063 064 private boolean active; 065 066 private ResponsibilityTemplateBo template = new ResponsibilityTemplateBo(); 067 068 private List<ResponsibilityAttributeBo> attributeDetails = new AutoPopulatingList<ResponsibilityAttributeBo>(ResponsibilityAttributeBo.class); 069 070 private List<RoleResponsibilityBo> roleResponsibilities = new AutoPopulatingList<RoleResponsibilityBo>(RoleResponsibilityBo.class); 071 072 private Map<String, String> attributes; 073 074 @Override 075 public Map<String, String> getAttributes() { 076 return attributeDetails != null ? KimAttributeDataBo.toAttributes(attributeDetails) : attributes; 077 } 078 079 /** 080 * Converts a mutable bo to its immutable counterpart 081 * 082 * @param bo the mutable business object 083 * @return the immutable object 084 */ 085 public static Responsibility to(ResponsibilityBo bo) { 086 if (bo == null) { 087 return null; 088 } 089 return Responsibility.Builder.create(bo).build(); 090 } 091 092 /** 093 * Converts a immutable object to its mutable counterpart 094 * 095 * @param im immutable object 096 * @return the mutable bo 097 */ 098 public static ResponsibilityBo from(Responsibility im) { 099 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}