View Javadoc

1   /**
2    * Copyright 2005-2013 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.kew.export;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import javax.xml.namespace.QName;
22  
23  import org.kuali.rice.core.api.impex.ExportDataSet;
24  import org.kuali.rice.kew.doctype.bo.DocumentType;
25  import org.kuali.rice.kew.rule.RuleBaseValues;
26  import org.kuali.rice.kew.rule.RuleDelegationBo;
27  import org.kuali.rice.kew.rule.bo.RuleAttribute;
28  import org.kuali.rice.kew.rule.bo.RuleTemplateBo;
29  import org.kuali.rice.kew.service.KEWServiceLocator;
30  import org.kuali.rice.kim.api.group.Group;
31  
32  /**
33   * This is a description of what this class does - ewestfal don't forget to fill this in. 
34   * 
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   *
37   */
38  public class KewExportDataSet {
39  
40  	public static final QName DOCUMENT_TYPES = new QName("KEW", "documentTypes");
41  	public static final QName GROUPS = new QName("KEW", "groups");
42  	public static final QName RULE_ATTRIBUTES = new QName("KEW", "ruleAttributes");
43  	public static final QName RULE_TEMPLATES = new QName("KEW", "ruleTemplates");
44  	public static final QName RULES = new QName("KEW", "rules");
45  	public static final QName RULE_DELEGATIONS = new QName("KEW", "ruleDelegations");
46  	public static final QName HELP = new QName("KEW", "help");
47  	public static final QName EDOCLITES = new QName("KEW", "eDocLites");
48  	
49  	private List<DocumentType> documentTypes = new ArrayList<DocumentType>();
50  	private List<Group> groups = new ArrayList<Group>();
51  	private List<RuleAttribute> ruleAttributes = new ArrayList<RuleAttribute>();
52  	private List<RuleTemplateBo> ruleTemplates = new ArrayList<RuleTemplateBo>();
53  	private List<RuleBaseValues> rules = new ArrayList<RuleBaseValues>();
54  	private List<RuleDelegationBo> ruleDelegations = new ArrayList<RuleDelegationBo>();
55  
56  	public List<DocumentType> getDocumentTypes() {
57  		return documentTypes;
58  	}
59  
60  	public List<RuleAttribute> getRuleAttributes() {
61  		return ruleAttributes;
62  	}
63  
64  	public List<RuleBaseValues> getRules() {
65  		return rules;
66  	}
67  
68  	public List<RuleTemplateBo> getRuleTemplates() {
69  		return ruleTemplates;
70  	}
71  
72  	public List<Group> getGroups() {
73  		return this.groups;
74  	}
75  
76  	public void setGroups(List<Group> groups) {
77  		this.groups = groups;
78  	}
79  
80  	public List<RuleDelegationBo> getRuleDelegations() {
81  		return this.ruleDelegations;
82  	}
83  	
84  	public void populateExportDataSet(ExportDataSet exportDataSet) {
85  		if (documentTypes != null && !documentTypes.isEmpty()) {
86              /* 
87               * this is a terrible hack to fix a problem where not everything for document type is getting exported 
88               * This is caused because the KEWModuleService creates an EBO from the api DocumentTypeService, which doesn't contain
89               * all the data needed for exporting.
90               * 
91               * Sooo... we put this ugly code here until we can hope to remove EBOs from this project, or create a DocumentType dto class that 
92               * contains the information needed
93               */
94              List<DocumentType> correctDocumentTypes = new ArrayList<DocumentType>();
95              for (DocumentType docType : documentTypes) {
96                  correctDocumentTypes.add(KEWServiceLocator.getDocumentTypeService().findById(docType.getDocumentTypeId()));
97              }
98  			exportDataSet.addDataSet(DOCUMENT_TYPES, correctDocumentTypes);
99  		}
100 		if (groups != null && !groups.isEmpty()) {
101 			exportDataSet.addDataSet(GROUPS, groups);
102 		}
103 		if (ruleAttributes != null && !ruleAttributes.isEmpty()) {
104 			exportDataSet.addDataSet(RULE_ATTRIBUTES, ruleAttributes);
105 		}
106 		if (ruleTemplates != null && !ruleTemplates.isEmpty()) {
107 			exportDataSet.addDataSet(RULE_TEMPLATES, ruleTemplates);
108 		}
109 		if (rules != null && !rules.isEmpty()) {
110 			exportDataSet.addDataSet(RULES, rules);
111 		}
112 		if (ruleDelegations != null && !ruleDelegations.isEmpty()) {
113 			exportDataSet.addDataSet(RULE_DELEGATIONS, ruleDelegations);
114 		}
115 	}
116 	
117 	public ExportDataSet createExportDataSet() {
118 		ExportDataSet exportDataSet = new ExportDataSet();
119 		populateExportDataSet(exportDataSet);
120 		return exportDataSet;
121 	}
122 	
123 	public static KewExportDataSet fromExportDataSet(ExportDataSet exportDataSet) {
124 		KewExportDataSet kewExportDataSet = new KewExportDataSet();
125 		
126 		List<DocumentType> documentTypes = (List<DocumentType>)exportDataSet.getDataSets().get(DOCUMENT_TYPES);
127 		if (documentTypes != null) {
128 			kewExportDataSet.getDocumentTypes().addAll(documentTypes);
129 		}
130 		List<Group> groups = (List<Group>)exportDataSet.getDataSets().get(GROUPS);
131 		if (groups != null) {
132 			kewExportDataSet.getGroups().addAll(groups);
133 		}
134 		List<RuleAttribute> ruleAttributes = (List<RuleAttribute>)exportDataSet.getDataSets().get(RULE_ATTRIBUTES);
135 		if (ruleAttributes != null) {
136 			kewExportDataSet.getRuleAttributes().addAll(ruleAttributes);
137 		}
138 		List<RuleTemplateBo> ruleTemplates = (List<RuleTemplateBo>)exportDataSet.getDataSets().get(RULE_TEMPLATES);
139 		if (ruleTemplates != null) {
140 			kewExportDataSet.getRuleTemplates().addAll(ruleTemplates);
141 		}
142 		List<RuleBaseValues> rules = (List<RuleBaseValues>)exportDataSet.getDataSets().get(RULES);
143 		if (rules != null) {
144 			kewExportDataSet.getRules().addAll(rules);
145 		}
146 		List<RuleDelegationBo> ruleDelegations = (List<RuleDelegationBo>)exportDataSet.getDataSets().get(RULE_DELEGATIONS);
147 		if (ruleDelegations != null) {
148 			kewExportDataSet.getRuleDelegations().addAll(ruleDelegations);
149 		}
150 		
151 		return kewExportDataSet;
152 	}
153 	
154 }