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