1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.export;
17
18 import org.kuali.rice.core.api.CoreApiServiceLocator;
19 import org.kuali.rice.core.api.impex.ExportDataSet;
20 import org.kuali.rice.kew.doctype.bo.DocumentType;
21 import org.kuali.rice.kew.rule.RuleBaseValues;
22 import org.kuali.rice.kew.rule.RuleDelegationBo;
23 import org.kuali.rice.kew.rule.bo.RuleAttribute;
24 import org.kuali.rice.kew.rule.bo.RuleTemplateBo;
25 import org.kuali.rice.kim.api.group.Group;
26 import org.kuali.rice.kim.impl.group.GroupBo;
27 import org.kuali.rice.krad.bo.Exporter;
28 import org.kuali.rice.krad.exception.ExportNotSupportedException;
29 import org.kuali.rice.krad.util.KRADConstants;
30
31 import java.io.IOException;
32 import java.io.OutputStream;
33 import java.util.ArrayList;
34 import java.util.List;
35
36
37
38
39
40
41
42
43
44
45 public class DataExporter implements Exporter {
46
47 private List<String> supportedFormats = new ArrayList<String>();
48
49 public DataExporter() {
50 supportedFormats.add(KRADConstants.XML_FORMAT);
51 }
52
53
54
55
56 @Override
57 public List<String> getSupportedFormats(Class<?> dataObjectClass) {
58 return supportedFormats;
59 }
60
61
62
63
64 protected ExportDataSet buildExportDataSet(Class<?> dataObjectClass, List<? extends Object> dataObjects) {
65 KewExportDataSet dataSet = new KewExportDataSet();
66 for (Object dataObject : dataObjects) {
67 if (dataObjectClass.equals(RuleAttribute.class)) {
68 dataSet.getRuleAttributes().add((RuleAttribute)dataObject);
69 } else if (dataObjectClass.equals(RuleTemplateBo.class)) {
70 dataSet.getRuleTemplates().add((RuleTemplateBo)dataObject);
71 } else if (dataObjectClass.equals(DocumentType.class)) {
72 dataSet.getDocumentTypes().add((DocumentType)dataObject);
73 } else if (dataObjectClass.equals(RuleBaseValues.class)) {
74 dataSet.getRules().add((RuleBaseValues)dataObject);
75 } else if (dataObjectClass.equals(RuleDelegationBo.class)) {
76 dataSet.getRuleDelegations().add((RuleDelegationBo)dataObject);
77 } else if (dataObjectClass.equals(GroupBo.class)) {
78 dataSet.getGroups().add((Group)dataObject);
79 }
80 }
81
82 ExportDataSet exportDataSet = new ExportDataSet();
83 dataSet.populateExportDataSet(exportDataSet);
84 return exportDataSet;
85 }
86
87
88
89
90
91
92 @Override
93 public void export(Class<?> dataObjectClass, List<? extends Object> dataObjects, String exportFormat, OutputStream outputStream) throws IOException,
94 ExportNotSupportedException {
95 if (!KRADConstants.XML_FORMAT.equals(exportFormat)) {
96 throw new ExportNotSupportedException("The given export format of "
97 + exportFormat
98 + " is not supported by the KEW XML Exporter!");
99 }
100 ExportDataSet dataSet = buildExportDataSet(dataObjectClass, dataObjects);
101 outputStream.write(CoreApiServiceLocator.getXmlExporterService()
102 .export(dataSet));
103 outputStream.flush();
104
105 }
106 }