Coverage Report - org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo
 
Classes in this File Line Coverage Branch Coverage Complexity
KimAttributeDataBo
27%
3/11
21%
3/14
0
KimAttributeDataBo$_createFrom_closure2
0%
0/7
0%
0/10
0
KimAttributeDataBo$_toAttributes_closure1
0%
0/7
0%
0/6
0
 
 1  
 /**
 2  
  * Copyright 2005-2011 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.common.attribute
 17  
 
 18  
 import javax.persistence.Transient
 19  
 import org.apache.commons.lang.StringUtils
 20  
 import org.kuali.rice.kim.api.common.attribute.KimAttributeDataContract
 21  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator
 22  
 import org.kuali.rice.kim.api.type.KimTypeAttribute
 23  
 import org.kuali.rice.kim.impl.type.KimTypeBo
 24  
 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase
 25  
 
 26  
 abstract class KimAttributeDataBo extends PersistableBusinessObjectBase implements KimAttributeDataContract {
 27  
     private static final long serialVersionUID = 1L;
 28  
 
 29  
     String id
 30  
     String attributeValue
 31  
     String kimAttributeId
 32  
     KimAttributeBo kimAttribute
 33  
     String kimTypeId
 34  
     @Transient
 35  
     KimTypeBo kimType
 36  
 
 37  
     abstract void setAssignedToId(String s);
 38  
 
 39  
     @Override
 40  
     KimAttributeBo getKimAttribute() {
 41  2
         return kimAttribute
 42  
     }
 43  
 
 44  
     @Override
 45  
     KimTypeBo getKimType() {
 46  2
         if (kimType == null && StringUtils.isNotEmpty(id)) {
 47  0
             kimType = KimTypeBo.from(KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId));
 48  
         }
 49  2
         return kimType;
 50  
     }
 51  
 
 52  
     static <T extends KimAttributeDataBo> Map<String, String> toAttributes(Collection<T> bos) {
 53  0
         def m = [:]
 54  0
         if(bos != null) {
 55  0
             bos.each {
 56  0
                 if (it != null) {
 57  0
                     KimTypeAttribute attribute = null;
 58  0
                     if ( it.kimType != null ) {
 59  0
                         attribute = KimTypeBo.to(it.kimType).getAttributeDefinitionById( it.getKimAttributeId() );
 60  
                     }
 61  0
                     if ( attribute != null ) {
 62  0
                         m[attribute.getKimAttribute().getAttributeName()] = it.getAttributeValue();
 63  
                     } else {
 64  0
                         m[it.getKimAttribute().getAttributeName()] = it.getAttributeValue();
 65  
                     }
 66  
                 }
 67  
             }
 68  
         }
 69  0
         return m;
 70  
     }
 71  
 
 72  
     /** creates a list of KimAttributeDataBos from attributes, kimTypeId, and assignedToId. */
 73  
     static <T extends KimAttributeDataBo> List<T> createFrom(Class<T> type, Map<String, String> attributes, String kimTypeId) {
 74  0
        if (attributes == null) {
 75  
            //purposely not using Collections.emptyList() b/c we do not want to return an unmodifiable list.
 76  0
            return new ArrayList<T>();
 77  
        }
 78  0
        return attributes.entrySet().collect {
 79  0
             KimTypeAttribute attr = KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId).getAttributeDefinitionByName(it.getKey());
 80  0
             if (attr != null && StringUtils.isNotBlank(it.getValue())) {
 81  0
                 T newDetail = type.newInstance();
 82  0
                 newDetail.setKimAttributeId(attr.getKimAttribute().getId());
 83  0
                 newDetail.setKimTypeId(kimTypeId);
 84  0
                 newDetail.setAttributeValue(it.getValue());
 85  0
                 return newDetail;
 86  
             }
 87  
         }
 88  
     }
 89  
 }