Project

General

Profile

Revision 91b9bc97

ID91b9bc973b443e1076af0f4a275a590bb9f219fe
Parent e3492ca9
Child 6cf49987

Added by Katja Luther over 2 years ago

remove task from progress view after finish

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java
237 237
            // get the remoting monitor the first time to make sure that the
238 238
            // operation is valid
239 239
            final IProgressMonitorService progressMonitorService = CdmApplicationState.getCurrentAppConfig().getProgressMonitorService();
240
//            final IRemotingProgressMonitor firstRemotingMonitor = progressMonitorService.getRemotingMonitor(uuid);
241
//            if(firstRemotingMonitor == null) {
242
//                throw new IllegalStateException("Remoting progress monitor is null");
243
//            }
240
            final IRemotingProgressMonitor firstRemotingMonitor = progressMonitorService.getRemotingMonitor(uuid);
241
            if(firstRemotingMonitor == null) {
242
                throw new IllegalStateException("Remoting progress monitor is null");
243
            }
244
            if (firstRemotingMonitor.isDone()){
245
                createExportResult(label, urlString, createZip, firstRemotingMonitor);
246
            }
244 247

  
245 248
            Job job = new Job(label) {
246 249

  
......
260 263
                    } catch (Exception ex) {
261 264
                        return new Status(Status.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ex);
262 265
                    }
263
                    final StringBuilder reportSb = new StringBuilder();
264
                    if (remotingMonitor.getResult() instanceof ExportResult){
265
                    	ExportResult result = (ExportResult)remotingMonitor.getResult();
266

  
267
	                    reportSb.append(result.createReport());
268

  
269
	                    if(!StringUtils.isBlank(reportSb.toString())) {
270
	                        Display.getDefault().asyncExec(new Runnable() {
271
	                            @Override
272
	                            public void run() {
273
	                                // display reports with possibility to save
274
	                                ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
275
	                                dialog.setTitle(label + " Report");
276
	                                dialog.setReportText(reportSb.toString());
277
	                                dialog.open();
278
	                            }
279
	                        });
280
	                    }
281

  
282
	                    if (urlString != null){
283
	                    	 ExportDataWrapper data = result.getExportData();
284
	                         try{
285
	                             if (result.getExportData().getType().equals(ExportResultType.BYTE_ARRAY)){
286
	                                 byte[] exportData = (byte[])data.getExportData();
287
	                                 if(exportData != null){
288
	                                     File file = new File(urlString);
289
	                                     FileOutputStream stream = new FileOutputStream(file);
290
	                                     Writer out = new BufferedWriter(new OutputStreamWriter(
291
	                                 			stream, "UTF8"));
292

  
293
	                                 	stream.write(exportData);
294
	                                    out.flush();
295
	                                    stream.close();
296
	                                 }
297
	                             } else if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){
298
	                                 Map<String, byte[]> resultMap = (Map<String, byte[]>)data.getExportData();
299
	                                 Set<String> keySet = resultMap.keySet();
300
	                                 SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
301
	                                 Calendar cal = Calendar.getInstance();
302
	                                 String fileEnding = ".csv";
303

  
304
	                                 if (createZip){
305
	                            		 File file = new File(urlString+File.separator +  sdf.format(cal.getTime())+ ".zip");
306
	                                     FileOutputStream stream = new FileOutputStream(file);
307
	                                     ZipOutputStream zos = new ZipOutputStream(stream);
308
	                                     for (String key: keySet){
309
	                                    	byte[] fileData = resultMap.get(key);
310
	                                    	ZipEntry entry = new ZipEntry( key + fileEnding);
311
	         								zos.putNextEntry(entry);
312
	         								zos.write(fileData);
313
	         								zos.closeEntry();
314
	                                     }
315
	                                     zos.close();
316
	                            	 }else{
317
	                            		if(result.getExportType().equals(ExportType.DWCA)){
318

  
319
	                                        File file = new File(urlString);
320
	                                        FileOutputStream stream = new FileOutputStream(file);
321
	                                        ZipOutputStream zos = new ZipOutputStream(stream);
322
	                                        for (String key: keySet){
323
             	                               	byte[] fileData = resultMap.get(key);
324
             	                               	ZipEntry entry = new ZipEntry( key);
325
             	    								zos.putNextEntry(entry);
326
             	    								zos.write(fileData);
327
             	    								zos.closeEntry();
328
	                                         }
329
	                                         zos.close();
330
	                                      }else{
331
		                            		 for (String key: keySet){
332
		                            			 byte[] fileData = resultMap.get(key);
333
		                            			 File file = new File(urlString+File.separator + key + fileEnding);
334
		                                         FileOutputStream stream = new FileOutputStream(file);
335
		                                         Writer out = new BufferedWriter(new OutputStreamWriter(
336
		                                     			stream, "UTF8"));
337
		                                         stream.write(fileData);
338
		                                         stream.close();
339
		                                     }
340
	                                      }
341
	                            	 }
342
	                            }else{
343
	                                 logger.error("This kind of result data is not supported yet." + result.getExportData().getType().toString());
344
	                             }
345
	                         } catch(Exception e){
346
	                             logger.error(e.getStackTrace());
347
	                         }
348
	                    }
349
                    }
266

  
267
                    createExportResult(label, urlString, createZip, remotingMonitor);
350 268
                    return Status.OK_STATUS;
351 269
                }
352 270

  
271

  
272

  
353 273
                @Override
354 274
                protected void canceling() {
355 275
                    CdmStore.getCurrentApplicationConfiguration().getProgressMonitorService().cancel(uuid);
......
683 603
            if(firstRemotingMonitor == null) {
684 604
                throw new IllegalStateException("Remoting progress monitor is null");
685 605
            }
606
            if (firstRemotingMonitor.isDone()){
607
                createResult(label, showResult, firstRemotingMonitor);
608
                return Status.OK_STATUS;
609
            }
686 610

  
687 611
            Job job = new Job(label) {
688 612

  
......
702 626
                    } catch (Exception ex) {
703 627
                        return new Status(Status.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ex);
704 628
                    }
705
                    final StringBuilder reportSb = new StringBuilder();
629

  
706 630

  
707 631
                    // collect reports
708 632
//	                    for(String report : remotingMonitor.getResult()) {
709
                    if (remotingMonitor.getResult() instanceof ExportResult) {
710
                        reportSb.append(((ExportResult)remotingMonitor.getResult()).createReport());
711
                    }else if (remotingMonitor.getResult() instanceof UpdateResult){
712
                        if (((UpdateResult)remotingMonitor.getResult()).isOk()){
713
                            reportSb.append("Update successfull. \n"+"Updated Objects: " + ((UpdateResult)remotingMonitor.getResult()).getUpdatedObjects().size());
714
                        }
715
                        if (!((UpdateResult)remotingMonitor.getResult()).getExceptions().isEmpty()){
716
                            reportSb.append(((UpdateResult)remotingMonitor.getResult()).getExceptions().toString());
717
                        }
718
                    }
719
//	                    }
720
                    if(showResult && !StringUtils.isBlank(reportSb.toString()) && reportSb.length() != 0) {
721
                        Display.getDefault().asyncExec(new Runnable() {
722
                            @Override
723
                            public void run() {
724
                                // display reports with possibility to save
725
                                ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
726
                                dialog.setTitle(label + " Report");
727
                                dialog.setReportText(reportSb.toString());
728
                                dialog.open();
729
                            }
730
                        });
731
                    }
633
                    createResult(label, showResult, remotingMonitor);
634

  
732 635
                    return Status.OK_STATUS;
733 636
                }
734 637

  
638

  
639

  
735 640
                @Override
736 641
                protected void canceling() {
737 642
                    CdmStore.getCurrentApplicationConfiguration().getProgressMonitorService().cancel(uuid);
......
739 644
            };
740 645

  
741 646
            // configure the job
742
            job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
743 647
            job.setUser(true);
744 648
            // schedule job
745 649
            job.schedule();
......
756 660
        return Status.OK_STATUS;
757 661
        }
758 662

  
663

  
664
    private static void createResult(final String label, final boolean showResult,
665
            IRemotingProgressMonitor remotingMonitor) {
666
        final StringBuilder reportSb = new StringBuilder();
667
        if (remotingMonitor.getResult() instanceof ExportResult) {
668
            reportSb.append(((ExportResult)remotingMonitor.getResult()).createReport());
669
        }else if (remotingMonitor.getResult() instanceof UpdateResult){
670
            if (((UpdateResult)remotingMonitor.getResult()).isOk()){
671
                reportSb.append("Update successfull. \n"+"Updated Objects: " + ((UpdateResult)remotingMonitor.getResult()).getUpdatedObjects().size());
672
            }
673
            if (!((UpdateResult)remotingMonitor.getResult()).getExceptions().isEmpty()){
674
                reportSb.append(((UpdateResult)remotingMonitor.getResult()).getExceptions().toString());
675
            }
676
        }
677
//          }
678
        if(showResult && !StringUtils.isBlank(reportSb.toString()) && reportSb.length() != 0) {
679
            Display.getDefault().asyncExec(new Runnable() {
680
                @Override
681
                public void run() {
682
                    // display reports with possibility to save
683
                    ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
684
                    dialog.setTitle(label + " Report");
685
                    dialog.setReportText(reportSb.toString());
686
                    dialog.open();
687
                }
688
            });
689
        }
690
    }
691

  
692
    private static void createExportResult(final String label, String urlString, boolean createZip,
693
            IRemotingProgressMonitor remotingMonitor) {
694

  
695
        final StringBuilder reportSb = new StringBuilder();
696
        if (remotingMonitor.getResult() instanceof ExportResult){
697
            ExportResult result = (ExportResult)remotingMonitor.getResult();
698

  
699
            reportSb.append(result.createReport());
700

  
701
            if(!StringUtils.isBlank(reportSb.toString())) {
702
                Display.getDefault().asyncExec(new Runnable() {
703
                    @Override
704
                    public void run() {
705
                        // display reports with possibility to save
706
                        ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
707
                        dialog.setTitle(label + " Report");
708
                        dialog.setReportText(reportSb.toString());
709
                        dialog.open();
710
                    }
711
                });
712
            }
713

  
714
            if (urlString != null){
715
                 ExportDataWrapper data = result.getExportData();
716
                 try{
717
                     if (result.getExportData().getType().equals(ExportResultType.BYTE_ARRAY)){
718
                         byte[] exportData = (byte[])data.getExportData();
719
                         if(exportData != null){
720
                             File file = new File(urlString);
721
                             FileOutputStream stream = new FileOutputStream(file);
722
                             Writer out = new BufferedWriter(new OutputStreamWriter(
723
                                    stream, "UTF8"));
724

  
725
                            stream.write(exportData);
726
                            out.flush();
727
                            stream.close();
728
                         }
729
                     } else if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){
730
                         Map<String, byte[]> resultMap = (Map<String, byte[]>)data.getExportData();
731
                         Set<String> keySet = resultMap.keySet();
732
                         SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
733
                         Calendar cal = Calendar.getInstance();
734
                         String fileEnding = ".csv";
735

  
736
                         if (createZip){
737
                             File file = new File(urlString+File.separator +  sdf.format(cal.getTime())+ ".zip");
738
                             FileOutputStream stream = new FileOutputStream(file);
739
                             ZipOutputStream zos = new ZipOutputStream(stream);
740
                             for (String key: keySet){
741
                                byte[] fileData = resultMap.get(key);
742
                                ZipEntry entry = new ZipEntry( key + fileEnding);
743
                                zos.putNextEntry(entry);
744
                                zos.write(fileData);
745
                                zos.closeEntry();
746
                             }
747
                             zos.close();
748
                         }else{
749
                            if(result.getExportType().equals(ExportType.DWCA)){
750

  
751
                                File file = new File(urlString);
752
                                FileOutputStream stream = new FileOutputStream(file);
753
                                ZipOutputStream zos = new ZipOutputStream(stream);
754
                                for (String key: keySet){
755
                                    byte[] fileData = resultMap.get(key);
756
                                    ZipEntry entry = new ZipEntry( key);
757
                                        zos.putNextEntry(entry);
758
                                        zos.write(fileData);
759
                                        zos.closeEntry();
760
                                 }
761
                                 zos.close();
762
                              }else{
763
                                 for (String key: keySet){
764
                                     byte[] fileData = resultMap.get(key);
765
                                     File file = new File(urlString+File.separator + key + fileEnding);
766
                                     FileOutputStream stream = new FileOutputStream(file);
767
                                     Writer out = new BufferedWriter(new OutputStreamWriter(
768
                                            stream, "UTF8"));
769
                                     stream.write(fileData);
770
                                     stream.close();
771
                                 }
772
                              }
773
                         }
774
                    }else{
775
                         logger.error("This kind of result data is not supported yet." + result.getExportData().getType().toString());
776
                     }
777
                 } catch(Exception e){
778
                     logger.error(e.getStackTrace());
779
                 }
780
            }
781
        }
782
    }
759 783
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)