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 | @Override | |
45 | public void initializeEvaluatorForDocument(Document document) { | |
46 | 0 | DataDictionary dictionary = KNSServiceLocatorWeb.getDataDictionaryService().getDataDictionary(); |
47 | 0 | DocumentEntry docEntry = dictionary.getDocumentEntry(document.getDocumentHeader().getWorkflowDocument().getDocumentType()); |
48 | 0 | WorkflowProperties workflowProperties = docEntry.getWorkflowProperties(); |
49 | 0 | List<WorkflowPropertyGroup> groups = workflowProperties.getWorkflowPropertyGroups(); |
50 | ||
51 | 0 | serializableProperties = new PropertySerializerTrie(); |
52 | ||
53 | 0 | for (WorkflowPropertyGroup group : groups) { |
54 | // the basepath of each workflow property group is serializable | |
55 | 0 | if (StringUtils.isEmpty(group.getBasePath())) { |
56 | // automatically serialize all primitives of document when the base path is null or empty string | |
57 | 0 | serializableProperties.addSerializablePropertyName(document.getBasePathToDocumentDuringSerialization(), false); |
58 | } | |
59 | else { | |
60 | 0 | serializableProperties.addSerializablePropertyName(group.getBasePath(), false); |
61 | } | |
62 | ||
63 | 0 | for (WorkflowProperty property : group.getWorkflowProperties()) { |
64 | String fullPath; | |
65 | 0 | if (StringUtils.isEmpty(group.getBasePath())) { |
66 | 0 | fullPath = document.getBasePathToDocumentDuringSerialization() + "." + property.getPath(); |
67 | } | |
68 | else { | |
69 | 0 | fullPath = group.getBasePath() + "." + property.getPath(); |
70 | } | |
71 | 0 | serializableProperties.addSerializablePropertyName(fullPath, false); |
72 | 0 | } |
73 | } | |
74 | 0 | } |
75 | ||
76 | } |