Revision 63fb5a6d
Added by Andreas Müller almost 3 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java | ||
---|---|---|
60 | 60 |
import eu.etaxonomy.cdm.api.application.CdmApplicationState; |
61 | 61 |
import eu.etaxonomy.cdm.api.service.IProgressMonitorService; |
62 | 62 |
import eu.etaxonomy.cdm.api.service.UpdateResult; |
63 |
import eu.etaxonomy.cdm.api.service.dto.CdmEntityIdentifier; |
|
64 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
65 |
import eu.etaxonomy.cdm.common.SetMap; |
|
63 | 66 |
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor; |
64 | 67 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
65 | 68 |
import eu.etaxonomy.cdm.io.common.ExportDataWrapper; |
... | ... | |
706 | 709 |
if (remotingMonitor.getResult() instanceof ExportResult) { |
707 | 710 |
reportSb.append(((ExportResult)remotingMonitor.getResult()).createReport()); |
708 | 711 |
}else if (remotingMonitor.getResult() instanceof UpdateResult){ |
709 |
if (((UpdateResult)remotingMonitor.getResult()).isOk()){ |
|
710 |
int count = ((UpdateResult)remotingMonitor.getResult()).getUpdatedObjects().size(); |
|
711 |
if (count == 0){ |
|
712 |
count = ((UpdateResult)remotingMonitor.getResult()).getUpdatedCdmIds().size(); |
|
713 |
} |
|
714 |
|
|
715 |
reportSb.append("Update successful. \n"+"Updated Objects: " +count); |
|
716 |
} |
|
717 |
if (!((UpdateResult)remotingMonitor.getResult()).getExceptions().isEmpty()){ |
|
718 |
reportSb.append(((UpdateResult)remotingMonitor.getResult()).getExceptions().toString()); |
|
719 |
} |
|
712 |
UpdateResult result = (UpdateResult)remotingMonitor.getResult(); |
|
713 |
createUpdateResultReport(reportSb, result); |
|
720 | 714 |
}else if (remotingMonitor.getReports()!= null){ |
721 | 715 |
for (String o:remotingMonitor.getReports()){ |
722 | 716 |
reportSb.append(o); |
723 | 717 |
} |
724 | 718 |
} |
725 |
if(showResult && !StringUtils.isBlank(reportSb.toString()) && reportSb.length() != 0) { |
|
719 |
String report = reportSb.toString(); |
|
720 |
if(showResult && !StringUtils.isBlank(report)) { |
|
726 | 721 |
Display.getDefault().asyncExec(new Runnable() { |
727 | 722 |
@Override |
728 | 723 |
public void run() { |
729 | 724 |
// display reports with possibility to save |
730 | 725 |
ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); |
731 | 726 |
dialog.setTitle(label + " Report"); |
732 |
dialog.setReportText(reportSb.toString());
|
|
727 |
dialog.setReportText(report); |
|
733 | 728 |
dialog.open(); |
734 | 729 |
} |
735 | 730 |
}); |
736 | 731 |
} |
737 | 732 |
} |
738 | 733 |
|
734 |
public static void createUpdateResultReport(final StringBuilder reportSb, UpdateResult result) { |
|
735 |
if (result.isOk() || result.isAbort()){ |
|
736 |
SetMap<Class<? extends CdmBase>, Integer> map = getUpdateResultStatistics(result); |
|
737 |
reportSb.append("Update successful. \n" |
|
738 |
+ "Updated Objects: " + map.sizeAll() + "\n================\n"); |
|
739 |
for (Class<? extends CdmBase> clazz : map.keySet()){ |
|
740 |
reportSb.append( CdmUtils.userFriendlyClassName(clazz)+": " + map.get(clazz).size() + "\n"); |
|
741 |
} |
|
742 |
} |
|
743 |
if (!result.getExceptions().isEmpty()){ |
|
744 |
reportSb.append(result.getExceptions().toString()); |
|
745 |
} |
|
746 |
} |
|
747 |
|
|
748 |
//TODO move to cdmlib |
|
749 |
public static SetMap<Class<? extends CdmBase>, Integer> getUpdateResultStatistics(UpdateResult result) { |
|
750 |
SetMap<Class<? extends CdmBase>, Integer> map = new SetMap<>(); |
|
751 |
for (CdmBase cdmBase : result.getUpdatedObjects()){ |
|
752 |
map.putItem(cdmBase.getClass(), cdmBase.getId()); |
|
753 |
} |
|
754 |
for (CdmEntityIdentifier entity : result.getUpdatedCdmIds()){ |
|
755 |
map.putItem(entity.getCdmClass(), entity.getId()); |
|
756 |
} |
|
757 |
|
|
758 |
return map; |
|
759 |
} |
|
760 |
|
|
739 | 761 |
private static void createExportResult(final String label, String urlString, boolean createZip, |
740 | 762 |
IRemotingProgressMonitor remotingMonitor) { |
741 | 763 |
|
Also available in: Unified diff
ref #6359 improve reporting for longrunning tasks with UpdateResult in TaxEditor