View Javadoc

1   /**
2    * Copyright 2005-2011 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.kim.api.group.Group;
30  
31  /**
32   * This is a description of what this class does - ewestfal don't forget to fill this in. 
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   *
36   */
37  public class KewExportDataSet {
38  
39  	public static final QName DOCUMENT_TYPES = new QName("KEW", "documentTypes");
40  	public static final QName GROUPS = new QName("KEW", "groups");
41  	public static final QName RULE_ATTRIBUTES = new QName("KEW", "ruleAttributes");
42  	public static final QName RULE_TEMPLATES = new QName("KEW", "ruleTemplates");
43  	public static final QName RULES = new QName("KEW", "rules");
44  	public static final QName RULE_DELEGATIONS = new QName("KEW", "ruleDelegations");
45  	public static final QName HELP = new QName("KEW", "help");
46  	public static final QName EDOCLITES = new QName("KEW", "eDocLites");
47  	
48  	private List<DocumentType> documentTypes = new ArrayList<DocumentType>();
49  	private List<Group> groups = new ArrayList<Group>();
50  	private List<RuleAttribute> ruleAttributes = new ArrayList<RuleAttribute>();
51  	private List<RuleTemplateBo> ruleTemplates = new ArrayList<RuleTemplateBo>();
52  	private List<RuleBaseValues> rules = new ArrayList<RuleBaseValues>();
53  	private List<RuleDelegationBo> ruleDelegations = new ArrayList<RuleDelegationBo>();
54  
55  	public List<DocumentType> getDocumentTypes() {
56  		return documentTypes;
57  	}
58  
59  	public List<RuleAttribute> getRuleAttributes() {
60  		return ruleAttributes;
61  	}
62  
63  	public List<RuleBaseValues> getRules() {
64  		return rules;
65  	}
66  
67  	public List<RuleTemplateBo> getRuleTemplates() {
68  		return ruleTemplates;
69  	}
70  
71  	public List<Group> getGroups() {
72  		return this.groups;
73  	}
74  
75  	public void setGroups(List<Group> groups) {
76  		this.groups = groups;
77  	}
78  
79  	public List<RuleDelegationBo> getRuleDelegations() {
80  		return this.ruleDelegations;
81  	}
82  	
83  	public void populateExportDataSet(ExportDataSet exportDataSet) {
84  		if (documentTypes != null && !documentTypes.isEmpty()) {
85  			exportDataSet.addDataSet(DOCUMENT_TYPES, documentTypes);
86  		}
87  		if (groups != null && !groups.isEmpty()) {
88  			exportDataSet.addDataSet(GROUPS, groups);
89  		}
90  		if (ruleAttributes != null && !ruleAttributes.isEmpty()) {
91  			exportDataSet.addDataSet(RULE_ATTRIBUTES, ruleAttributes);
92  		}
93  		if (ruleTemplates != null && !ruleTemplates.isEmpty()) {
94  			exportDataSet.addDataSet(RULE_TEMPLATES, ruleTemplates);
95  		}
96  		if (rules != null && !rules.isEmpty()) {
97  			exportDataSet.addDataSet(RULES, rules);
98  		}
99  		if (ruleDelegations != null && !ruleDelegations.isEmpty()) {
100 			exportDataSet.addDataSet(RULE_DELEGATIONS, ruleDelegations);
101 		}
102 	}
103 	
104 	public ExportDataSet createExportDataSet() {
105 		ExportDataSet exportDataSet = new ExportDataSet();
106 		populateExportDataSet(exportDataSet);
107 		return exportDataSet;
108 	}
109 	
110 	public static KewExportDataSet fromExportDataSet(ExportDataSet exportDataSet) {
111 		KewExportDataSet kewExportDataSet = new KewExportDataSet();
112 		
113 		List<DocumentType> documentTypes = (List<DocumentType>)exportDataSet.getDataSets().get(DOCUMENT_TYPES);
114 		if (documentTypes != null) {
115 			kewExportDataSet.getDocumentTypes().addAll(documentTypes);
116 		}
117 		List<Group> groups = (List<Group>)exportDataSet.getDataSets().get(GROUPS);
118 		if (groups != null) {
119 			kewExportDataSet.getGroups().addAll(groups);
120 		}
121 		List<RuleAttribute> ruleAttributes = (List<RuleAttribute>)exportDataSet.getDataSets().get(RULE_ATTRIBUTES);
122 		if (ruleAttributes != null) {
123 			kewExportDataSet.getRuleAttributes().addAll(ruleAttributes);
124 		}
125 		List<RuleTemplateBo> ruleTemplates = (List<RuleTemplateBo>)exportDataSet.getDataSets().get(RULE_TEMPLATES);
126 		if (ruleTemplates != null) {
127 			kewExportDataSet.getRuleTemplates().addAll(ruleTemplates);
128 		}
129 		List<RuleBaseValues> rules = (List<RuleBaseValues>)exportDataSet.getDataSets().get(RULES);
130 		if (rules != null) {
131 			kewExportDataSet.getRules().addAll(rules);
132 		}
133 		List<RuleDelegationBo> ruleDelegations = (List<RuleDelegationBo>)exportDataSet.getDataSets().get(RULE_DELEGATIONS);
134 		if (ruleDelegations != null) {
135 			kewExportDataSet.getRuleDelegations().addAll(ruleDelegations);
136 		}
137 		
138 		return kewExportDataSet;
139 	}
140 	
141 }