View Javadoc

1   /*
2    * Copyright 2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.help.HelpEntry;
26  import org.kuali.rice.kew.rule.RuleBaseValues;
27  import org.kuali.rice.kew.rule.RuleDelegation;
28  import org.kuali.rice.kew.rule.bo.RuleAttribute;
29  import org.kuali.rice.kew.rule.bo.RuleTemplate;
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<RuleTemplate> ruleTemplates = new ArrayList<RuleTemplate>();
53  	private List<RuleBaseValues> rules = new ArrayList<RuleBaseValues>();
54  	private List<RuleDelegation> ruleDelegations = new ArrayList<RuleDelegation>();
55  	private List<HelpEntry> help = new ArrayList<HelpEntry>();
56  
57  	public List<DocumentType> getDocumentTypes() {
58  		return documentTypes;
59  	}
60  
61  	public List<HelpEntry> getHelp() {
62  		return help;
63  	}
64  
65  	public List<RuleAttribute> getRuleAttributes() {
66  		return ruleAttributes;
67  	}
68  
69  	public List<RuleBaseValues> getRules() {
70  		return rules;
71  	}
72  
73  	public List<RuleTemplate> getRuleTemplates() {
74  		return ruleTemplates;
75  	}
76  
77  	public List<Group> getGroups() {
78  		return this.groups;
79  	}
80  
81  	public void setGroups(List<Group> groups) {
82  		this.groups = groups;
83  	}
84  
85  	public List<RuleDelegation> getRuleDelegations() {
86  		return this.ruleDelegations;
87  	}
88  	
89  	public void populateExportDataSet(ExportDataSet exportDataSet) {
90  		if (documentTypes != null && !documentTypes.isEmpty()) {
91  			exportDataSet.addDataSet(DOCUMENT_TYPES, documentTypes);
92  		}
93  		if (groups != null && !groups.isEmpty()) {
94  			exportDataSet.addDataSet(GROUPS, groups);
95  		}
96  		if (ruleAttributes != null && !ruleAttributes.isEmpty()) {
97  			exportDataSet.addDataSet(RULE_ATTRIBUTES, ruleAttributes);
98  		}
99  		if (ruleTemplates != null && !ruleTemplates.isEmpty()) {
100 			exportDataSet.addDataSet(RULE_TEMPLATES, ruleTemplates);
101 		}
102 		if (rules != null && !rules.isEmpty()) {
103 			exportDataSet.addDataSet(RULES, rules);
104 		}
105 		if (ruleDelegations != null && !ruleDelegations.isEmpty()) {
106 			exportDataSet.addDataSet(RULE_DELEGATIONS, ruleDelegations);
107 		}
108 		if (help != null && !help.isEmpty()) {
109 			exportDataSet.addDataSet(HELP, help);
110 		}
111 	}
112 	
113 	public ExportDataSet createExportDataSet() {
114 		ExportDataSet exportDataSet = new ExportDataSet();
115 		populateExportDataSet(exportDataSet);
116 		return exportDataSet;
117 	}
118 	
119 	public static KewExportDataSet fromExportDataSet(ExportDataSet exportDataSet) {
120 		KewExportDataSet kewExportDataSet = new KewExportDataSet();
121 		
122 		List<DocumentType> documentTypes = (List<DocumentType>)exportDataSet.getDataSets().get(DOCUMENT_TYPES);
123 		if (documentTypes != null) {
124 			kewExportDataSet.getDocumentTypes().addAll(documentTypes);
125 		}
126 		List<Group> groups = (List<Group>)exportDataSet.getDataSets().get(GROUPS);
127 		if (groups != null) {
128 			kewExportDataSet.getGroups().addAll(groups);
129 		}
130 		List<RuleAttribute> ruleAttributes = (List<RuleAttribute>)exportDataSet.getDataSets().get(RULE_ATTRIBUTES);
131 		if (ruleAttributes != null) {
132 			kewExportDataSet.getRuleAttributes().addAll(ruleAttributes);
133 		}
134 		List<RuleTemplate> ruleTemplates = (List<RuleTemplate>)exportDataSet.getDataSets().get(RULE_TEMPLATES);
135 		if (ruleTemplates != null) {
136 			kewExportDataSet.getRuleTemplates().addAll(ruleTemplates);
137 		}
138 		List<RuleBaseValues> rules = (List<RuleBaseValues>)exportDataSet.getDataSets().get(RULES);
139 		if (rules != null) {
140 			kewExportDataSet.getRules().addAll(rules);
141 		}
142 		List<RuleDelegation> ruleDelegations = (List<RuleDelegation>)exportDataSet.getDataSets().get(RULE_DELEGATIONS);
143 		if (ruleDelegations != null) {
144 			kewExportDataSet.getRuleDelegations().addAll(ruleDelegations);
145 		}
146 		List<HelpEntry> help = (List<HelpEntry>)exportDataSet.getDataSets().get(HELP);
147 		if (help != null) {
148 			kewExportDataSet.getHelp().addAll(help);
149 		}
150 		
151 		return kewExportDataSet;
152 	}
153 	
154 }