+ private void export(IProgressMonitor monitor, PrintStream out) throws DatabaseException {
+ SubMonitor progress = SubMonitor.convert(monitor, Messages.ExportIssuesAsCsv_ExportIssues, IProgressMonitor.UNKNOWN);
+ Simantics.getSession().syncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ Collection<Variable> activeIssues = graph.syncRequest(new AllVisibleIssues(Simantics.getProjectResource()));
+ out.println("# Exported issues (" + activeIssues.size() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ for (Variable issue : activeIssues) {
+ exportIssue(graph, issue, out, 0);
+ progress.worked(1);
+ }
+
+ Map<String, Variable> dynamicIssueSources = nameMap(graph,
+ graph.syncRequest(new DynamicIssueSources(Simantics.getProjectResource())));
+ if (!dynamicIssueSources.isEmpty()) {
+ out.println();
+ out.println("# Dynamic Issues"); //$NON-NLS-1$
+ for (Variable source : dynamicIssueSources.values()) {
+ exportDynamicIssueSource(progress, graph, source, out, 0);
+ }
+ }
+ }
+ });
+ }
+
+ private Map<String, Variable> nameMap(ReadGraph graph, Set<Variable> sources) throws DatabaseException {
+ TreeMap<String, Variable> sorted = new TreeMap<>();
+ for (Variable v : sources) {
+ String name = v.getPossiblePropertyValue(graph, "HasDescription", Bindings.STRING); //$NON-NLS-1$
+ if (name == null)
+ name = v.getName(graph);
+ sorted.put(name, v);
+ }
+ return sorted;
+ }
+
+ protected void exportDynamicIssueSource(IProgressMonitor monitor, ReadGraph graph, Variable issue, PrintStream out, int startColumn) throws DatabaseException {
+ exportIssue(graph, issue, out, startColumn);
+ for (Variable child : issue.getChildren(graph)) {
+ exportDynamicIssueSource(monitor, graph, child, out, startColumn+1);
+ monitor.worked(1);
+ }
+ }
+
+ private void exportIssue(ReadGraph graph, Variable issue, PrintStream out, int startColumn) throws DatabaseException {
+ String description = StringUtils.safeString( (String) issue.getPossiblePropertyValue(graph, "HasDescription") ); //$NON-NLS-1$
+ String severity = StringUtils.safeString( (String) issue.getPossiblePropertyValue(graph, "severity") ); //$NON-NLS-1$
+ String resource = StringUtils.safeString( (String) issue.getPossiblePropertyValue(graph, "resource") ); //$NON-NLS-1$
+ String path = StringUtils.safeString( (String) issue.getPossiblePropertyValue(graph, "path") ); //$NON-NLS-1$
+ for (int i = 0; i < startColumn; ++i)
+ out.print(";"); //$NON-NLS-1$
+ out.println(description + ";" + severity + ";" + resource + ";" + path); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+