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