| 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 java.io.IOException; |
| 19 | |
import java.io.OutputStream; |
| 20 | |
import java.util.ArrayList; |
| 21 | |
import java.util.List; |
| 22 | |
|
| 23 | |
import org.kuali.rice.core.api.CoreApiServiceLocator; |
| 24 | |
import org.kuali.rice.core.api.impex.ExportDataSet; |
| 25 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
| 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 | |
import org.kuali.rice.kim.impl.group.GroupBo; |
| 32 | |
import org.kuali.rice.krad.bo.Exporter; |
| 33 | |
import org.kuali.rice.krad.exception.ExportNotSupportedException; |
| 34 | |
import org.kuali.rice.krad.util.KRADConstants; |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
public class DataExporter implements Exporter { |
| 46 | |
|
| 47 | 0 | private List<String> supportedFormats = new ArrayList<String>(); |
| 48 | |
|
| 49 | 0 | public DataExporter() { |
| 50 | 0 | supportedFormats.add(KRADConstants.XML_FORMAT); |
| 51 | 0 | } |
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
@Override |
| 57 | |
public List<String> getSupportedFormats(Class<?> dataObjectClass) { |
| 58 | 0 | return supportedFormats; |
| 59 | |
} |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
protected ExportDataSet buildExportDataSet(Class<?> dataObjectClass, List<? extends Object> dataObjects) { |
| 65 | 0 | KewExportDataSet dataSet = new KewExportDataSet(); |
| 66 | 0 | for (Object dataObject : dataObjects) { |
| 67 | 0 | if (dataObjectClass.equals(RuleAttribute.class)) { |
| 68 | 0 | dataSet.getRuleAttributes().add((RuleAttribute)dataObject); |
| 69 | 0 | } else if (dataObjectClass.equals(RuleTemplate.class)) { |
| 70 | 0 | dataSet.getRuleTemplates().add((RuleTemplate)dataObject); |
| 71 | 0 | } else if (dataObjectClass.equals(DocumentType.class)) { |
| 72 | 0 | dataSet.getDocumentTypes().add((DocumentType)dataObject); |
| 73 | 0 | } else if (dataObjectClass.equals(RuleBaseValues.class)) { |
| 74 | 0 | dataSet.getRules().add((RuleBaseValues)dataObject); |
| 75 | 0 | } else if (dataObjectClass.equals(RuleDelegation.class)) { |
| 76 | 0 | dataSet.getRuleDelegations().add((RuleDelegation)dataObject); |
| 77 | 0 | } else if (dataObjectClass.equals(GroupBo.class)) { |
| 78 | 0 | dataSet.getGroups().add((Group)dataObject); |
| 79 | |
} |
| 80 | |
} |
| 81 | |
|
| 82 | 0 | ExportDataSet exportDataSet = new ExportDataSet(); |
| 83 | 0 | dataSet.populateExportDataSet(exportDataSet); |
| 84 | 0 | 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 | 0 | if (!KRADConstants.XML_FORMAT.equals(exportFormat)) { |
| 96 | 0 | throw new ExportNotSupportedException("The given export format of " |
| 97 | |
+ exportFormat |
| 98 | |
+ " is not supported by the KEW XML Exporter!"); |
| 99 | |
} |
| 100 | 0 | ExportDataSet dataSet = buildExportDataSet(dataObjectClass, dataObjects); |
| 101 | 0 | outputStream.write(CoreApiServiceLocator.getXmlExporterService() |
| 102 | |
.export(dataSet)); |
| 103 | 0 | outputStream.flush(); |
| 104 | |
|
| 105 | 0 | } |
| 106 | |
} |