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