+ /**
+ * @param configurator
+ * @param urlString
+ * @return
+ */
+ public Job createIOServiceJob(OutputModelConfigurator configurator, String urlString) {
+ Assert.isNotNull(configurator, "Configuration may not be null");
+
+ // final Display display = Display.getCurrent();
+
+ Job job = new Job("Export: " + configurator.getClass().getSimpleName()) { //$NON-NLS-1$
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask("Exporting database. This will take some time.", IProgressMonitor.UNKNOWN);
+ try {
+ IIOService ioService = CdmApplicationState.getIOService();
+
+ ExportResult result = ioService.export(configurator);
+ ExportDataWrapper data = result.getExportData();
+ try{
+ if (result.getExportData().getType().equals(ExportResultType.BYTE_ARRAY)){
+ byte[] exportData = (byte[])data.getExportData();
+ if(exportData != null){
+ File file = new File(urlString);
+ FileOutputStream stream = new FileOutputStream(file);
+ stream.write(exportData);
+ stream.close();
+ }
+ } else if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){
+ Map<String, byte[]> resultMap = (Map<String, byte[]>)data.getExportData();
+ Set<String> keySet = resultMap.keySet();
+ for (String key: keySet){
+ byte[] fileData = resultMap.get(key);
+ String fileEnding ="";
+ if (configurator instanceof OutputModelConfigurator){
+ fileEnding = ".csv";
+ }
+ File file = new File(urlString+File.separator + key + fileEnding);
+ FileOutputStream stream = new FileOutputStream(file);
+ stream.write(fileData);
+ stream.close();
+ }
+
+ }else{
+ logger.error("This kind of result data is not supported yet." + result.getExportData().getType().toString());
+ }
+ } catch(Exception e){
+ logger.error(e.getStackTrace());
+ }
+ final StringBuilder reportText = new StringBuilder();
+ if(result!=null){
+ List<IoResultBase.Error> reports = result.getErrors();
+ reportText.append("Errors:\\r");
+ for (IoResultBase.Error bs : reports) {
+ reportText.append(bs.getMessage() + " - " +bs.getException().getStackTrace());
+ }
+ List<String> warnings = result.getWarnings();
+ reportText.append("Warnings:\\r");
+ for (String bs : warnings) {
+ reportText.append(bs);
+ }
+ List<IoResultBase.Error> exceptions = result.getExceptions();
+ reportText.append("Exceptions:\\r");
+ for (IoResultBase.Error bs : exceptions) {
+ reportText.append(bs.getMessage() + " - " +bs.getException().getStackTrace());
+ }
+
+
+ }
+ final Display display = Display.getDefault();
+ display.asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ // display reports with possibility to save
+ ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ dialog.setTitle(configurator.getClass().getSimpleName()+" Report");
+ dialog.setReportText(reportText.toString());
+ dialog.open();
+ CdmStore.getContextManager().notifyContextRefresh();
+ }
+ });
+
+
+
+ } catch (Exception e) {
+ MessagingUtils.errorDialog("Error exporting data",
+ this,
+ e.getMessage(),
+ TaxeditorStorePlugin.PLUGIN_ID,
+ e,
+ true);
+ }
+
+ return Status.OK_STATUS;
+ }
+ };
+ return job;
+ }
+
+
+