Coverage Report - org.kuali.rice.kns.util.documentserializer.MaintenanceDocumentPropertySerializibilityEvaluator
 
Classes in this File Line Coverage Branch Coverage Complexity
MaintenanceDocumentPropertySerializibilityEvaluator
0%
0/30
0%
0/20
3
 
 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.kns.util.documentserializer;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.apache.commons.lang.StringUtils;
 22  
 import org.kuali.rice.kns.datadictionary.DataDictionary;
 23  
 import org.kuali.rice.kns.datadictionary.MaintainableCollectionDefinition;
 24  
 import org.kuali.rice.kns.datadictionary.MaintainableFieldDefinition;
 25  
 import org.kuali.rice.kns.datadictionary.MaintainableItemDefinition;
 26  
 import org.kuali.rice.kns.datadictionary.MaintainableSectionDefinition;
 27  
 import org.kuali.rice.kns.datadictionary.MaintainableSubSectionHeaderDefinition;
 28  
 import org.kuali.rice.kns.datadictionary.MaintenanceDocumentEntry;
 29  
 import org.kuali.rice.kns.service.KNSServiceLocatorWeb;
 30  
 
 31  
 
 32  0
 public class MaintenanceDocumentPropertySerializibilityEvaluator 
 33  
                                 extends PropertySerializabilityEvaluatorBase implements PropertySerializabilityEvaluator {
 34  
 
 35  
     /**
 36  
      * Reads the data dictionary to determine which properties of the document should be serialized.
 37  
      * 
 38  
      * @see org.kuali.rice.kns.util.documentserializer.PropertySerializabilityEvaluator#initializeEvaluator(org.kuali.rice.kns.document.Document)
 39  
      */
 40  
         @Override
 41  
     public void initializeEvaluatorForDataObject(Object businessObject){
 42  0
         DataDictionary dictionary = KNSServiceLocatorWeb.getDataDictionaryService().getDataDictionary();
 43  0
         MaintenanceDocumentEntry maintenanceDocumentEntry = 
 44  
                 dictionary.getMaintenanceDocumentEntryForBusinessObjectClass(businessObject.getClass());
 45  0
         serializableProperties = new PropertySerializerTrie();
 46  0
         populateSerializableProperties(maintenanceDocumentEntry.getMaintainableSections());
 47  0
         serializableProperties.addSerializablePropertyName("boNotes", true);
 48  0
         serializableProperties.addSerializablePropertyName("boNotes.attachment", true);
 49  0
     }
 50  
     
 51  
     private void populateSerializableProperties(List<MaintainableSectionDefinition> maintainableSectionDefinitions){
 52  0
         for(MaintainableSectionDefinition maintainableSectionDefinition: maintainableSectionDefinitions){
 53  0
                 populateSerializablePropertiesWithItems("", maintainableSectionDefinition.getMaintainableItems());
 54  
         }
 55  0
     }
 56  
 
 57  
     private void populateSerializablePropertiesWithItems(String basePath, List<MaintainableItemDefinition> maintainableItems){
 58  0
             for(MaintainableItemDefinition maintainableItemDefinition: maintainableItems){
 59  0
             if(maintainableItemDefinition instanceof MaintainableFieldDefinition){
 60  0
                 serializableProperties.addSerializablePropertyName(getFullItemName(basePath, maintainableItemDefinition.getName()), true);
 61  0
             } else if(maintainableItemDefinition instanceof MaintainableCollectionDefinition){
 62  0
                     serializableProperties.addSerializablePropertyName(getFullItemName(basePath, maintainableItemDefinition.getName()), true);
 63  0
                     populateSerializablePropertiesWithItems(getFullItemName(basePath, maintainableItemDefinition.getName()), 
 64  
                                     getAllMaintainableFieldDefinitionsForSerialization(
 65  
                                     (MaintainableCollectionDefinition)maintainableItemDefinition));                    
 66  0
             } else if(maintainableItemDefinition instanceof MaintainableSubSectionHeaderDefinition){
 67  
                     //Ignore
 68  
             }
 69  
             }
 70  0
     }
 71  
 
 72  
     private String getFullItemName(String basePath, String itemName){
 73  0
             return StringUtils.isEmpty(basePath) ? itemName : basePath+"."+itemName;
 74  
     }
 75  
     
 76  
     public List<MaintainableItemDefinition> getAllMaintainableFieldDefinitionsForSerialization(
 77  
                     MaintainableCollectionDefinition maintainableCollectionDefinition){
 78  0
                 List<MaintainableItemDefinition> allMaintainableItemDefinitions = new ArrayList<MaintainableItemDefinition>();
 79  
 
 80  0
                 if(maintainableCollectionDefinition.getMaintainableFields()!=null){
 81  0
                         allMaintainableItemDefinitions.addAll(maintainableCollectionDefinition.getMaintainableFields());
 82  
                 }
 83  
 
 84  0
                 if(maintainableCollectionDefinition.getSummaryFields()!=null){
 85  0
                         allMaintainableItemDefinitions.addAll(
 86  
                                         (List<MaintainableFieldDefinition>)maintainableCollectionDefinition.getSummaryFields());
 87  
                 }
 88  
 
 89  0
                 if(maintainableCollectionDefinition.getDuplicateIdentificationFields()!=null){
 90  0
                         allMaintainableItemDefinitions.addAll(maintainableCollectionDefinition.getDuplicateIdentificationFields());
 91  
                 }
 92  
 
 93  
                 /*if(maintainableCollectionMap!=null){
 94  
                         updateMaintainableCollectionDefinitionForSerialization(maintainableCollectionMap.values());
 95  
                         allMaintainableItemDefinitions.addAll(maintainableCollectionMap.values());
 96  
                 }*/
 97  0
                 if(maintainableCollectionDefinition.getMaintainableCollections()!=null){
 98  0
                         allMaintainableItemDefinitions.addAll(maintainableCollectionDefinition.getMaintainableCollections());
 99  
                 }
 100  
 
 101  0
                 return allMaintainableItemDefinitions;
 102  
         }
 103  
     
 104  
 }