Coverage Report - org.kuali.rice.kim.bo.role.impl.KimResponsibilityImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
KimResponsibilityImpl
0%
0/91
0%
0/26
1.464
 
 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.bo.role.impl;
 17  
 
 18  
 import java.util.Iterator;
 19  
 import java.util.LinkedHashMap;
 20  
 import java.util.List;
 21  
 
 22  
 import javax.persistence.CascadeType;
 23  
 import javax.persistence.Column;
 24  
 import javax.persistence.Entity;
 25  
 import javax.persistence.FetchType;
 26  
 import javax.persistence.Id;
 27  
 import javax.persistence.JoinColumn;
 28  
 import javax.persistence.OneToMany;
 29  
 import javax.persistence.Table;
 30  
 
 31  
 import org.apache.commons.lang.StringUtils;
 32  
 import org.kuali.rice.kim.bo.role.KimResponsibility;
 33  
 import org.kuali.rice.kim.bo.role.dto.KimResponsibilityInfo;
 34  
 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
 35  
 import org.kuali.rice.kim.bo.types.dto.KimTypeAttributeInfo;
 36  
 import org.kuali.rice.kim.bo.types.dto.KimTypeInfo;
 37  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 38  
 import org.kuali.rice.kim.service.KimTypeInfoService;
 39  
 import org.kuali.rice.kim.util.KimConstants;
 40  
 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
 41  
 import org.kuali.rice.kns.service.DataDictionaryService;
 42  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 43  
 import org.kuali.rice.kns.util.TypedArrayList;
 44  
 
 45  
 /**
 46  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 47  
  */
 48  
 @Entity
 49  
 @Table(name="KRIM_RSP_T")
 50  0
 public class KimResponsibilityImpl extends PersistableBusinessObjectBase implements KimResponsibility {
 51  
 
 52  
         private static final long serialVersionUID = 1L;
 53  
         
 54  
         @Id
 55  
         @Column(name="RSP_ID")
 56  
         protected String responsibilityId;
 57  
         @Column(name="NMSPC_CD")
 58  
         protected String namespaceCode;
 59  
         @Column(name="NM")
 60  
         protected String name;
 61  
         @Column(name="DESC_TXT", length=400)
 62  
         protected String description;
 63  
         @Column(name="ACTV_IND")
 64  
         protected boolean active;
 65  
 
 66  0
         @OneToMany(targetEntity=ResponsibilityAttributeDataImpl.class,cascade={CascadeType.ALL},fetch=FetchType.LAZY)
 67  
         @JoinColumn(name="RSP_ID", insertable=false, updatable=false)
 68  
         protected List<ResponsibilityAttributeDataImpl> detailObjects = new TypedArrayList(ResponsibilityAttributeDataImpl.class);
 69  
         
 70  
         protected String templateId;
 71  0
         protected KimResponsibilityTemplateImpl template = new KimResponsibilityTemplateImpl();
 72  
         
 73  0
         protected List<RoleResponsibilityImpl> roleResponsibilities = new TypedArrayList(RoleResponsibilityImpl.class);
 74  
         
 75  
         /**
 76  
          * @see org.kuali.rice.kns.bo.Inactivateable#isActive()
 77  
          */
 78  
         public boolean isActive() {
 79  0
                 return active;
 80  
         }
 81  
 
 82  
         /**
 83  
          * @see org.kuali.rice.kns.bo.Inactivateable#setActive(boolean)
 84  
          */
 85  
         public void setActive(boolean active) {
 86  0
                 this.active = active;
 87  0
         }
 88  
 
 89  
         /**
 90  
          * @see org.kuali.rice.kim.bo.role.KimResponsibility#getDescription()
 91  
          */
 92  
         public String getDescription() {
 93  0
                 return description;
 94  
         }
 95  
 
 96  
         /**
 97  
          * @see org.kuali.rice.kim.bo.role.KimResponsibility#getResponsibilityId()
 98  
          */
 99  
         public String getResponsibilityId() {
 100  0
                 return responsibilityId;
 101  
         }
 102  
 
 103  
         /**
 104  
          * @see org.kuali.rice.kim.bo.role.KimResponsibility#getName()
 105  
          */
 106  
         public String getName() {
 107  0
                 return name;
 108  
         }
 109  
 
 110  
         /**
 111  
          * @see org.kuali.rice.kim.bo.role.KimResponsibility#getName()
 112  
          */
 113  
         public String getNameToDisplay() {
 114  0
                 if(template!=null && StringUtils.equals(template.getName(), name)){
 115  0
                         return name;
 116  
                 } else{
 117  0
                         return template.getName()+" "+name;
 118  
                 }
 119  
         }
 120  
 
 121  
         public void setDescription(String responsibilityDescription) {
 122  0
                 this.description = responsibilityDescription;
 123  0
         }
 124  
 
 125  
         public void setName(String responsibilityName) {
 126  0
                 this.name = responsibilityName;
 127  0
         }
 128  
 
 129  
         /**
 130  
          * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
 131  
          */
 132  
         @SuppressWarnings("unchecked")
 133  
         @Override
 134  
         protected LinkedHashMap toStringMapper() {
 135  0
                 LinkedHashMap m = new LinkedHashMap();
 136  0
                 m.put( "responsibilityId", responsibilityId );
 137  0
                 m.put( "name", name );
 138  0
                 m.put( "details", getDetails() );
 139  0
                 return m;
 140  
         }
 141  
 
 142  
         public KimResponsibilityInfo toSimpleInfo() {
 143  0
                 KimResponsibilityInfo dto = new KimResponsibilityInfo();
 144  
                 
 145  0
                 dto.setResponsibilityId( getResponsibilityId() );
 146  0
                 dto.setNamespaceCode( getNamespaceCode() );
 147  0
                 dto.setName( getName() );
 148  0
                 dto.setDescription( getDescription() );
 149  0
                 dto.setActive( isActive() );
 150  0
                 dto.setDetails( getDetails() );
 151  
                 
 152  0
                 return dto;
 153  
         }
 154  
         
 155  
         public List<ResponsibilityAttributeDataImpl> getDetailObjects() {
 156  0
                 return this.detailObjects;
 157  
         }
 158  
 
 159  
         public void setDetailObjects(List<ResponsibilityAttributeDataImpl> detailObjects) {
 160  0
                 this.detailObjects = detailObjects;
 161  0
                 detailsAsAttributeSet = null;
 162  0
         }
 163  
         
 164  
         public boolean hasDetails() {
 165  0
                 return !detailObjects.isEmpty();
 166  
         }
 167  
         
 168  0
         protected transient AttributeSet detailsAsAttributeSet = null;
 169  
         
 170  
         public AttributeSet getDetails() {
 171  0
                 if ( detailsAsAttributeSet == null ) {
 172  0
                         KimTypeInfo kimType = getTypeInfoService().getKimType( getTemplate().getKimTypeId() );
 173  0
                         AttributeSet m = new AttributeSet();
 174  0
                         for ( ResponsibilityAttributeDataImpl data : getDetailObjects() ) {
 175  0
                                 KimTypeAttributeInfo attribute = null;
 176  0
                                 if ( kimType != null ) {
 177  0
                                         attribute = kimType.getAttributeDefinition( data.getKimAttributeId() );
 178  
                                 }
 179  0
                                 if ( attribute != null ) {
 180  0
                                         m.put( attribute.getAttributeName(), data.getAttributeValue() );
 181  
                                 } else {
 182  0
                                         m.put( data.getKimAttribute().getAttributeName(), data.getAttributeValue() );
 183  
                                 }
 184  0
                         }
 185  0
                         detailsAsAttributeSet = m;
 186  
                 }
 187  0
                 return detailsAsAttributeSet;
 188  
         }
 189  
 
 190  
         public KimResponsibilityTemplateImpl getTemplate() {
 191  0
                 return this.template;
 192  
         }
 193  
 
 194  
         public void setTemplate(KimResponsibilityTemplateImpl template) {
 195  0
                 this.template = template;
 196  0
         }
 197  
 
 198  
         public String getNamespaceCode() {
 199  0
                 return this.namespaceCode;
 200  
         }
 201  
 
 202  
         public void setNamespaceCode(String namespaceCode) {
 203  0
                 this.namespaceCode = namespaceCode;
 204  0
         }
 205  
 
 206  
         public String getTemplateId() {
 207  0
                 return this.templateId;
 208  
         }
 209  
 
 210  
         public void setTemplateId(String templateId) {
 211  0
                 this.templateId = templateId;
 212  0
         }
 213  
 
 214  
         public void setResponsibilityId(String responsibilityId) {
 215  0
                 this.responsibilityId = responsibilityId;
 216  0
         }
 217  
 
 218  
         /**
 219  
          * @return the roleResponsibilities
 220  
          */
 221  
         public List<RoleResponsibilityImpl> getRoleResponsibilities() {
 222  0
                 return this.roleResponsibilities;
 223  
         }
 224  
 
 225  
         /**
 226  
          * @param roleResponsibilities the roleResponsibilities to set
 227  
          */
 228  
         public void setRoleResponsibilities(
 229  
                         List<RoleResponsibilityImpl> roleResponsibilities) {
 230  0
                 this.roleResponsibilities = roleResponsibilities;
 231  0
         }
 232  
 
 233  
 
 234  
         public String getDetailObjectsValues(){
 235  0
                 StringBuffer detailObjectsToDisplay = new StringBuffer();
 236  0
                 Iterator<ResponsibilityAttributeDataImpl> respIter = getDetailObjects().iterator();
 237  0
                 while ( respIter.hasNext() ) {
 238  0
                         ResponsibilityAttributeDataImpl responsibilityAttributeData = respIter.next();
 239  0
                         detailObjectsToDisplay.append( responsibilityAttributeData.getAttributeValue() );
 240  0
                         if ( respIter.hasNext() ) {
 241  0
                                 detailObjectsToDisplay.append( KimConstants.KimUIConstants.COMMA_SEPARATOR );
 242  
                         }
 243  0
                 }
 244  0
                 return detailObjectsToDisplay.toString();
 245  
         }
 246  
 
 247  
         public String getDetailObjectsToDisplay() {
 248  0
                 KimTypeInfo kimType = getTypeInfoService().getKimType( getTemplate().getKimTypeId() );
 249  0
                 StringBuffer detailObjectsToDisplay = new StringBuffer();
 250  0
                 Iterator<ResponsibilityAttributeDataImpl> respIter = getDetailObjects().iterator();
 251  0
                 while ( respIter.hasNext() ) {
 252  0
                         ResponsibilityAttributeDataImpl responsibilityAttributeData = respIter.next();
 253  0
                         detailObjectsToDisplay.append( getKimAttributeLabelFromDD(kimType.getAttributeDefinition(responsibilityAttributeData.getKimAttributeId())));
 254  0
                         detailObjectsToDisplay.append( KimConstants.KimUIConstants.NAME_VALUE_SEPARATOR );
 255  0
                         detailObjectsToDisplay.append( responsibilityAttributeData.getAttributeValue() );
 256  0
                         if ( respIter.hasNext() ) {
 257  0
                                 detailObjectsToDisplay.append( KimConstants.KimUIConstants.COMMA_SEPARATOR );
 258  
                         }
 259  0
                 }
 260  0
                 return detailObjectsToDisplay.toString();
 261  
         }
 262  
         
 263  
         protected String getKimAttributeLabelFromDD( KimTypeAttributeInfo attribute ){
 264  0
             return getDataDictionaryService().getAttributeLabel(attribute.getComponentName(), attribute.getAttributeName() );
 265  
     }
 266  
 
 267  
         transient private DataDictionaryService dataDictionaryService;
 268  
         public DataDictionaryService getDataDictionaryService() {
 269  0
                 if(dataDictionaryService == null){
 270  0
                         dataDictionaryService = KNSServiceLocator.getDataDictionaryService();
 271  
                 }
 272  0
                 return dataDictionaryService;
 273  
         }
 274  
 
 275  
         private transient static KimTypeInfoService kimTypeInfoService;
 276  
         protected KimTypeInfoService getTypeInfoService() {
 277  0
                 if(kimTypeInfoService == null){
 278  0
                         kimTypeInfoService = KIMServiceLocator.getTypeInfoService();
 279  
                 }
 280  0
                 return kimTypeInfoService;
 281  
         }
 282  
 }