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