| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| BusinessObjectPropertySerializibilityEvaluator |
|
| 5.0;5 |
| 1 | /* | |
| 2 | * Copyright 2007-2008 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.List; | |
| 19 | ||
| 20 | import org.apache.commons.lang.StringUtils; | |
| 21 | import org.kuali.rice.kns.datadictionary.DataDictionary; | |
| 22 | import org.kuali.rice.kns.datadictionary.DocumentEntry; | |
| 23 | import org.kuali.rice.kns.datadictionary.WorkflowProperties; | |
| 24 | import org.kuali.rice.kns.datadictionary.WorkflowProperty; | |
| 25 | import org.kuali.rice.kns.datadictionary.WorkflowPropertyGroup; | |
| 26 | import org.kuali.rice.kns.document.Document; | |
| 27 | import org.kuali.rice.kns.service.KNSServiceLocatorWeb; | |
| 28 | ||
| 29 | /** | |
| 30 | * This implementation of {@link PropertySerializabilityEvaluator} uses the <workflowProperties> defined within the data dictionary | |
| 31 | * for a document. If the property being serialized corresponds to one of the properties in the data dictionary, then it will be serialized. | |
| 32 | * If a property specified in the data dictionary corresponds to a business object, then all primitives will be serialized of the business object. | |
| 33 | * All primitives of a primitive that has already been serialized will be serialized as well. If a property specified in the data dictionary corresponds | |
| 34 | * to a collection, then all primitives of all collection elements will be serialized. | |
| 35 | * | |
| 36 | */ | |
| 37 | 0 | public class BusinessObjectPropertySerializibilityEvaluator extends PropertySerializabilityEvaluatorBase implements PropertySerializabilityEvaluator { |
| 38 | ||
| 39 | /** | |
| 40 | * Reads the data dictionary to determine which properties of the document should be serialized. | |
| 41 | * | |
| 42 | * @see org.kuali.rice.kns.util.documentserializer.PropertySerializabilityEvaluator#initializeEvaluator(org.kuali.rice.kns.document.Document) | |
| 43 | */ | |
| 44 | public void initializeEvaluator(Document document) { | |
| 45 | 0 | DataDictionary dictionary = KNSServiceLocatorWeb.getDataDictionaryService().getDataDictionary(); |
| 46 | 0 | DocumentEntry docEntry = dictionary.getDocumentEntry(document.getDocumentHeader().getWorkflowDocument().getDocumentType()); |
| 47 | 0 | WorkflowProperties workflowProperties = docEntry.getWorkflowProperties(); |
| 48 | 0 | List<WorkflowPropertyGroup> groups = workflowProperties.getWorkflowPropertyGroups(); |
| 49 | ||
| 50 | 0 | serializableProperties = new PropertySerializerTrie(); |
| 51 | ||
| 52 | 0 | for (WorkflowPropertyGroup group : groups) { |
| 53 | // the basepath of each workflow property group is serializable | |
| 54 | 0 | if (StringUtils.isEmpty(group.getBasePath())) { |
| 55 | // automatically serialize all primitives of document when the base path is null or empty string | |
| 56 | 0 | serializableProperties.addSerializablePropertyName(document.getBasePathToDocumentDuringSerialization(), false); |
| 57 | } | |
| 58 | else { | |
| 59 | 0 | serializableProperties.addSerializablePropertyName(group.getBasePath(), false); |
| 60 | } | |
| 61 | ||
| 62 | 0 | for (WorkflowProperty property : group.getWorkflowProperties()) { |
| 63 | String fullPath; | |
| 64 | 0 | if (StringUtils.isEmpty(group.getBasePath())) { |
| 65 | 0 | fullPath = document.getBasePathToDocumentDuringSerialization() + "." + property.getPath(); |
| 66 | } | |
| 67 | else { | |
| 68 | 0 | fullPath = group.getBasePath() + "." + property.getPath(); |
| 69 | } | |
| 70 | 0 | serializableProperties.addSerializablePropertyName(fullPath, false); |
| 71 | 0 | } |
| 72 | } | |
| 73 | 0 | } |
| 74 | ||
| 75 | } |