001 /**
002 * Copyright 2005-2012 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kew.export;
017
018 import java.util.ArrayList;
019 import java.util.List;
020
021 import javax.xml.namespace.QName;
022
023 import org.kuali.rice.core.api.impex.ExportDataSet;
024 import org.kuali.rice.kew.doctype.bo.DocumentType;
025 import org.kuali.rice.kew.rule.RuleBaseValues;
026 import org.kuali.rice.kew.rule.RuleDelegationBo;
027 import org.kuali.rice.kew.rule.bo.RuleAttribute;
028 import org.kuali.rice.kew.rule.bo.RuleTemplateBo;
029 import org.kuali.rice.kew.service.KEWServiceLocator;
030 import org.kuali.rice.kim.api.group.Group;
031
032 /**
033 * This is a description of what this class does - ewestfal don't forget to fill this in.
034 *
035 * @author Kuali Rice Team (rice.collab@kuali.org)
036 *
037 */
038 public class KewExportDataSet {
039
040 public static final QName DOCUMENT_TYPES = new QName("KEW", "documentTypes");
041 public static final QName GROUPS = new QName("KEW", "groups");
042 public static final QName RULE_ATTRIBUTES = new QName("KEW", "ruleAttributes");
043 public static final QName RULE_TEMPLATES = new QName("KEW", "ruleTemplates");
044 public static final QName RULES = new QName("KEW", "rules");
045 public static final QName RULE_DELEGATIONS = new QName("KEW", "ruleDelegations");
046 public static final QName HELP = new QName("KEW", "help");
047 public static final QName EDOCLITES = new QName("KEW", "eDocLites");
048
049 private List<DocumentType> documentTypes = new ArrayList<DocumentType>();
050 private List<Group> groups = new ArrayList<Group>();
051 private List<RuleAttribute> ruleAttributes = new ArrayList<RuleAttribute>();
052 private List<RuleTemplateBo> ruleTemplates = new ArrayList<RuleTemplateBo>();
053 private List<RuleBaseValues> rules = new ArrayList<RuleBaseValues>();
054 private List<RuleDelegationBo> ruleDelegations = new ArrayList<RuleDelegationBo>();
055
056 public List<DocumentType> getDocumentTypes() {
057 return documentTypes;
058 }
059
060 public List<RuleAttribute> getRuleAttributes() {
061 return ruleAttributes;
062 }
063
064 public List<RuleBaseValues> getRules() {
065 return rules;
066 }
067
068 public List<RuleTemplateBo> getRuleTemplates() {
069 return ruleTemplates;
070 }
071
072 public List<Group> getGroups() {
073 return this.groups;
074 }
075
076 public void setGroups(List<Group> groups) {
077 this.groups = groups;
078 }
079
080 public List<RuleDelegationBo> getRuleDelegations() {
081 return this.ruleDelegations;
082 }
083
084 public void populateExportDataSet(ExportDataSet exportDataSet) {
085 if (documentTypes != null && !documentTypes.isEmpty()) {
086 /*
087 * this is a terrible hack to fix a problem where not everything for document type is getting exported
088 * This is caused because the KEWModuleService creates an EBO from the api DocumentTypeService, which doesn't contain
089 * all the data needed for exporting.
090 *
091 * Sooo... we put this ugly code here until we can hope to remove EBOs from this project, or create a DocumentType dto class that
092 * contains the information needed
093 */
094 List<DocumentType> correctDocumentTypes = new ArrayList<DocumentType>();
095 for (DocumentType docType : documentTypes) {
096 correctDocumentTypes.add(KEWServiceLocator.getDocumentTypeService().findById(docType.getDocumentTypeId()));
097 }
098 exportDataSet.addDataSet(DOCUMENT_TYPES, correctDocumentTypes);
099 }
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 }