Coverage Report - org.kuali.rice.kim.impl.type.KimTypeAttributesHelper
 
Classes in this File Line Coverage Branch Coverage Complexity
KimTypeAttributesHelper
0%
0/36
0%
0/28
2.455
 
 1  
 /*
 2  
  * Copyright 2007-2009 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.type;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.kim.api.type.KimType;
 20  
 import org.kuali.rice.kim.api.type.KimTypeService;
 21  
 import org.kuali.rice.kim.bo.impl.KimAttributes;
 22  
 import org.kuali.rice.kim.bo.types.dto.AttributeDefinitionMap;
 23  
 import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
 24  
 import org.kuali.rice.kim.service.KIMServiceLocatorWeb;
 25  
 import org.kuali.rice.kim.util.KimConstants;
 26  
 import org.kuali.rice.krad.datadictionary.AttributeDefinition;
 27  
 import org.kuali.rice.krad.datadictionary.KimAttributeDefinition;
 28  
 
 29  
 import java.io.Serializable;
 30  
 import java.util.List;
 31  
 import java.util.Map;
 32  
 
 33  
 /**
 34  
  * This is a description of what this class does - bhargavp don't forget to fill this in. 
 35  
  * 
 36  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 37  
  *
 38  
  */
 39  
 public class KimTypeAttributesHelper implements Serializable {
 40  
 
 41  
         private KimType kimType;
 42  
         private transient KimTypeService kimTypeService;
 43  
         private List<? extends KimAttributes> attributes;
 44  
         private transient AttributeDefinitionMap definitions;
 45  
         private transient Map<String,Object> attributeEntry;
 46  
 
 47  0
         public KimTypeAttributesHelper(KimType kimType){
 48  0
                 this.kimType = kimType;
 49  0
         }
 50  
 
 51  
         /**
 52  
          * @return the attributes
 53  
          */
 54  
         public List<? extends KimAttributes> getAttributes() {
 55  0
                 return this.attributes;
 56  
         }
 57  
 
 58  
         /**
 59  
          * @return the kimType
 60  
          */
 61  
         public KimType getKimType() {
 62  0
                 return this.kimType;
 63  
         }
 64  
 
 65  
         public KimTypeService getKimTypeService(KimType kimType){
 66  0
                 if(this.kimTypeService==null){
 67  0
                     this.kimTypeService = KIMServiceLocatorWeb.getKimTypeService(kimType);
 68  
                 }
 69  0
                 return this.kimTypeService;
 70  
         }
 71  
         
 72  
         public Map<String,Object> getAttributeEntry() {
 73  0
                 if(attributeEntry==null || attributeEntry.isEmpty())
 74  0
                         attributeEntry = KIMServiceLocatorInternal.getUiDocumentService().getAttributeEntries(getDefinitions());
 75  0
                 return attributeEntry;
 76  
         }
 77  
 
 78  
     public String getKimAttributeDefnId(AttributeDefinition definition){
 79  0
             return ((KimAttributeDefinition)definition).getKimAttrDefnId();
 80  
     }
 81  
     
 82  
         /**
 83  
          * Returns an {@link AttributeDefinitionMap}
 84  
          * 
 85  
          * @return
 86  
          */
 87  
         public AttributeDefinitionMap getDefinitions() {
 88  0
                 if (definitions == null || definitions.isEmpty()) {
 89  0
                 KimTypeService kimTypeService = getKimTypeService(getKimType());
 90  0
                 if(kimTypeService!=null)
 91  0
                         this.definitions = kimTypeService.getAttributeDefinitions(getKimType().getId());
 92  
                 }
 93  0
                 return this.definitions;
 94  
         }
 95  
 
 96  
         public AttributeDefinitionMap getDefinitionsKeyedByAttributeName() {
 97  0
                 AttributeDefinitionMap definitionsKeyedBySortCode = getDefinitions();
 98  0
                 AttributeDefinitionMap returnValue = new AttributeDefinitionMap();
 99  0
                 if (definitionsKeyedBySortCode != null) {
 100  0
                         for (AttributeDefinition definition : definitionsKeyedBySortCode.values()) {
 101  0
                                 returnValue.put(definition.getName(), definition);
 102  
                         }
 103  
                 }
 104  0
                 return returnValue;
 105  
         }
 106  
         
 107  
         public String getCommaDelimitedAttributesLabels(String commaDelimitedAttributesNamesList){
 108  0
                 String[] names = StringUtils.splitByWholeSeparator(commaDelimitedAttributesNamesList, KimConstants.KimUIConstants.COMMA_SEPARATOR);
 109  0
                 StringBuffer commaDelimitedAttributesLabels = new StringBuffer();
 110  0
                 for(String name: names){
 111  0
                         commaDelimitedAttributesLabels.append(getAttributeEntry().get(name.trim())+KimConstants.KimUIConstants.COMMA_SEPARATOR);
 112  
                 }
 113  0
         if(commaDelimitedAttributesLabels.toString().endsWith(KimConstants.KimUIConstants.COMMA_SEPARATOR))
 114  0
                 commaDelimitedAttributesLabels.delete(commaDelimitedAttributesLabels.length()-KimConstants.KimUIConstants.COMMA_SEPARATOR.length(), commaDelimitedAttributesLabels.length());
 115  0
         return commaDelimitedAttributesLabels.toString();
 116  
         }
 117  
 
 118  
         public AttributeDefinition getAttributeDefinition(String attributeName){
 119  0
                 return getDefinitionsKeyedByAttributeName().get(attributeName);
 120  
         }
 121  
         
 122  
         public String getAttributeValue(Map<String, String> aSet, String attributeName){
 123  0
                 if(StringUtils.isEmpty(attributeName) || aSet==null) return null;
 124  0
                 for(String attributeNameKey: aSet.keySet()){
 125  0
                         if(attributeName.equals(attributeNameKey))
 126  0
                                 return aSet.get(attributeNameKey);
 127  
                 }
 128  0
                 return null;
 129  
         }
 130  
 }