Coverage Report - org.kuali.rice.kim.impl.responsibility.ResponsibilityBo
 
Classes in this File Line Coverage Branch Coverage Complexity
ResponsibilityBo
0%
0/29
0%
0/10
0
ResponsibilityBo$_getDetailObjectsToDisplay_closure2
0%
0/1
N/A
0
ResponsibilityBo$_getDetailObjectsValues_closure1
0%
0/1
N/A
0
 
 1  
 /*
 2  
  * Copyright 2007-2008 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 responsibilitys and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kim.impl.responsibility;
 17  
 
 18  
 
 19  
 import javax.persistence.CascadeType
 20  
 import javax.persistence.Column
 21  
 import javax.persistence.Entity
 22  
 import javax.persistence.FetchType
 23  
 import javax.persistence.Id
 24  
 import javax.persistence.JoinColumn
 25  
 import javax.persistence.OneToMany
 26  
 import javax.persistence.OneToOne
 27  
 import javax.persistence.Table
 28  
 import org.hibernate.annotations.Fetch
 29  
 import org.hibernate.annotations.FetchMode
 30  
 import org.hibernate.annotations.Type
 31  
 import org.kuali.rice.core.api.mo.common.Attributes
 32  
 import org.kuali.rice.kim.api.responsibility.Responsibility
 33  
 import org.kuali.rice.kim.api.responsibility.ResponsibilityContract
 34  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator
 35  
 import org.kuali.rice.kim.api.type.KimType
 36  
 import org.kuali.rice.kim.api.type.KimTypeAttribute
 37  
 import org.kuali.rice.kim.api.type.KimTypeInfoService
 38  
 import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo
 39  
 import org.kuali.rice.kim.impl.role.RoleResponsibilityBo
 40  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase
 41  
 import org.kuali.rice.krad.service.DataDictionaryService
 42  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb
 43  
 
 44  
 @Entity
 45  
 @Table(name = "KRIM_RSP_T")
 46  
 public class ResponsibilityBo extends PersistableBusinessObjectBase implements ResponsibilityContract {
 47  
 
 48  
     private static final long serialVersionUID = 1L;
 49  
 
 50  
     @Id
 51  
     @Column(name = "RSP_ID")
 52  
     String id
 53  
 
 54  
     @Column(name="NMSPC_CD")
 55  
     String namespaceCode
 56  
 
 57  
     @Column(name="NM")
 58  
     String name
 59  
 
 60  
     @Column(name="DESC_TXT", length=400)
 61  
     String description;
 62  
 
 63  
     @Column(name="PERM_TMPL_ID")
 64  
     String templateId
 65  
 
 66  
     @Column(name="ACTV_IND")
 67  
     @Type(type="yes_no")
 68  
     boolean active
 69  
 
 70  
     @OneToOne(targetEntity=ResponsibilityTemplateBo.class,cascade=[],fetch=FetchType.EAGER)
 71  
     @JoinColumn(name="PERM_TMPL_ID", insertable=false, updatable=false)
 72  
     ResponsibilityTemplateBo template;
 73  
 
 74  
     @OneToMany(targetEntity=ResponsibilityAttributeBo.class,cascade=[CascadeType.ALL],fetch=FetchType.EAGER,mappedBy="id")
 75  
     @Fetch(value = FetchMode.SELECT)
 76  
     List<ResponsibilityAttributeBo> attributeDetails
 77  
 
 78  
     @OneToMany(targetEntity=RoleResponsibilityBo.class,cascade=[CascadeType.ALL],fetch=FetchType.EAGER,mappedBy="id")
 79  
     @Fetch(value = FetchMode.SELECT)
 80  
     List<RoleResponsibilityBo> roleResponsibilities
 81  
 
 82  
     Attributes attributes
 83  
 
 84  
     Attributes getAttributes() {
 85  0
         return attributeDetails != null ? KimAttributeDataBo.toAttributes(attributeDetails) : attributes
 86  
     }
 87  
 
 88  
     /**
 89  
      * Converts a mutable bo to its immutable counterpart
 90  
      * @param bo the mutable business object
 91  
      * @return the immutable object
 92  
      */
 93  
     static Responsibility to(ResponsibilityBo bo) {
 94  0
         if (bo == null) {
 95  0
             return null
 96  
         }
 97  
 
 98  0
         return Responsibility.Builder.create(bo).build();
 99  
     }
 100  
 
 101  
     /**
 102  
      * Converts a immutable object to its mutable counterpart
 103  
      * @param im immutable object
 104  
      * @return the mutable bo
 105  
      */
 106  
     static ResponsibilityBo from(Responsibility im) {
 107  0
         if (im == null) {
 108  0
             return null
 109  
         }
 110  
 
 111  0
         ResponsibilityBo bo = new ResponsibilityBo()
 112  0
         bo.id = im.id
 113  0
         bo.namespaceCode = im.namespaceCode
 114  0
         bo.name = im.name
 115  0
         bo.description = im.description
 116  0
         bo.active = im.active
 117  0
         bo.templateId = im.template.getId()
 118  0
         bo.template = ResponsibilityTemplateBo.from(im.template)
 119  0
         bo.attributes = im.attributes
 120  0
         bo.versionNumber = im.versionNumber
 121  0
                 bo.objectId = im.objectId;
 122  
 
 123  0
         return bo
 124  
     }
 125  
 
 126  
     ResponsibilityTemplateBo getTemplate() {
 127  0
         return template;
 128  
     }
 129  
 
 130  
     //FIXME: temporary methods
 131  
     String getDetailObjectsValues(){
 132  0
                 return attributeDetails.collect {it.attributeValue}.join(",")
 133  
         }
 134  
 
 135  
     String getDetailObjectsToDisplay() {
 136  0
                 final KimType kimType = getTypeInfoService().getKimType( getTemplate().getKimTypeId() );
 137  
 
 138  0
         return attributeDetails.collect {
 139  0
             getKimAttributeLabelFromDD(kimType.getAttributeDefinitionById(it.kimAttributeId)) + ":" + it.attributeValue
 140  
         }.join(",")
 141  
         }
 142  
 
 143  
     private String getKimAttributeLabelFromDD( KimTypeAttribute attribute ){
 144  0
             return getDataDictionaryService().getAttributeLabel(attribute.getKimAttribute().getComponentName(), attribute.getKimAttribute().getAttributeName() );
 145  
     }
 146  
 
 147  
         private DataDictionaryService dataDictionaryService;
 148  
         private DataDictionaryService getDataDictionaryService() {
 149  0
                 if(dataDictionaryService == null){
 150  0
                         dataDictionaryService = KRADServiceLocatorWeb.getDataDictionaryService();
 151  
                 }
 152  0
                 return dataDictionaryService;
 153  
         }
 154  
 
 155  
         private KimTypeInfoService kimTypeInfoService;
 156  
         private KimTypeInfoService getTypeInfoService() {
 157  0
                 if(kimTypeInfoService == null){
 158  0
                         kimTypeInfoService = KimApiServiceLocator.getKimTypeInfoService();
 159  
                 }
 160  0
                 return kimTypeInfoService;
 161  
         }
 162  
 }