View Javadoc

1   /**
2    * Copyright 2005-2012 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.krad.util.documentserializer;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.krad.datadictionary.DataDictionary;
20  import org.kuali.rice.krad.datadictionary.DocumentEntry;
21  import org.kuali.rice.krad.datadictionary.WorkflowProperties;
22  import org.kuali.rice.krad.datadictionary.WorkflowProperty;
23  import org.kuali.rice.krad.datadictionary.WorkflowPropertyGroup;
24  import org.kuali.rice.krad.document.Document;
25  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
26  
27  import java.util.List;
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  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.krad.util.documentserializer.PropertySerializabilityEvaluator#initializeEvaluator(org.kuali.rice.krad.document.Document)
43       */
44  	@Override
45      public void initializeEvaluatorForDocument(Document document) {
46          DataDictionary dictionary = KRADServiceLocatorWeb.getDataDictionaryService().getDataDictionary();
47          DocumentEntry docEntry = dictionary.getDocumentEntry(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
48          WorkflowProperties workflowProperties = docEntry.getWorkflowProperties();
49          List<WorkflowPropertyGroup> groups = workflowProperties.getWorkflowPropertyGroups();
50          
51          serializableProperties = new PropertySerializerTrie();
52          
53          for (WorkflowPropertyGroup group : groups) {
54              // the basepath of each workflow property group is serializable
55              if (StringUtils.isEmpty(group.getBasePath())) {
56                  // automatically serialize all primitives of document when the base path is null or empty string
57                  serializableProperties.addSerializablePropertyName(document.getBasePathToDocumentDuringSerialization(), false);
58              }
59              else {
60                 serializableProperties.addSerializablePropertyName(group.getBasePath(), false);
61              }
62              
63              for (WorkflowProperty property : group.getWorkflowProperties()) {
64                  String fullPath;
65                  if (StringUtils.isEmpty(group.getBasePath())) {
66                      fullPath = document.getBasePathToDocumentDuringSerialization() + "." + property.getPath();
67                  }
68                  else {
69                      fullPath = group.getBasePath() + "." + property.getPath(); 
70                  }
71                  serializableProperties.addSerializablePropertyName(fullPath, false);
72              }
73          }
74      }
75  
76  }