Coverage Report - org.kuali.rice.kim.impl.type.IdentityManagementTypeAttributeTransactionalDocument
 
Classes in this File Line Coverage Branch Coverage Complexity
IdentityManagementTypeAttributeTransactionalDocument
0%
0/31
0%
0/18
1.9
 
 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.document.IdentityManagementKimDocument;
 24  
 import org.kuali.rice.kim.framework.services.KimFrameworkServiceLocator;
 25  
 import org.kuali.rice.kim.framework.type.KimTypeService;
 26  
 import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
 27  
 
 28  
 import javax.persistence.Transient;
 29  
 import java.util.HashMap;
 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 List<KimAttributeField> 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  
         public List<KimAttributeField> getDefinitions() {
 97  0
                 if (definitions == null || definitions.isEmpty()) {
 98  0
                 KimTypeService kimTypeService = getKimTypeService(getKimType());
 99  0
                 if(kimTypeService!=null)
 100  0
                         this.definitions = kimTypeService.getAttributeDefinitions(getKimType().getId());
 101  
                 }
 102  0
                 return this.definitions;
 103  
         }
 104  
 
 105  
     public Map<String, KimAttributeField> getDefinitionsKeyedByAttributeName() {
 106  0
         final Map<String, KimAttributeField> map = new HashMap<String, KimAttributeField>();
 107  0
         for (KimAttributeField field : getDefinitions()) {
 108  0
             map.put(field.getAttributeField().getName(), field);
 109  
         }
 110  0
         return map;
 111  
         }
 112  
 
 113  
 
 114  
         public void setDefinitions(List<KimAttributeField> definitions) {
 115  0
                 this.definitions = definitions;
 116  0
         }
 117  
 
 118  
         protected KimTypeService getKimTypeService(KimType kimType){
 119  0
                 if( kimTypeService==null){
 120  0
                     kimTypeService = KimFrameworkServiceLocator.getKimTypeService(kimType);
 121  
                 }
 122  0
                 return kimTypeService;
 123  
         }
 124  
 
 125  
 }