From: Antti Villberg Date: Mon, 31 Jul 2017 05:26:45 +0000 (+0300) Subject: Issue context modelling enhancements X-Git-Tag: v1.31.0~264^2~21 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=6c13a0fe40ac29598b401abded6460285c95c3c8 Issue context modelling enhancements refs #7391 Change-Id: Ib1ecb5f161cf85487ee5b6ff43f5640b645ca600 --- diff --git a/bundles/org.simantics.issues.common/src/org/simantics/issues/common/MaxIssueSeverityRecursive.java b/bundles/org.simantics.issues.common/src/org/simantics/issues/common/MaxIssueSeverityRecursive.java index db537ee26..7646271e3 100644 --- a/bundles/org.simantics.issues.common/src/org/simantics/issues/common/MaxIssueSeverityRecursive.java +++ b/bundles/org.simantics.issues.common/src/org/simantics/issues/common/MaxIssueSeverityRecursive.java @@ -12,6 +12,8 @@ package org.simantics.issues.common; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import org.simantics.db.AsyncReadGraph; import org.simantics.db.Resource; @@ -29,66 +31,71 @@ public class MaxIssueSeverityRecursive extends TernaryAsyncRead typesToRecurse) { super(resource, childRelation, typesToRecurse); } - -// @Override -// public Severity perform(ReadGraph graph) throws DatabaseException { -// Layer0 L0 = Layer0.getInstance(graph); -// IssueResource ISSUE = IssueResource.getInstance(graph); -// //System.out.println("severity: " + NameUtils.getSafeName(graph, resource)); -// Collection issues = graph.getObjects(resource, ISSUE.IsIssueContextOf); -// if (issues.isEmpty()) { -// // This content does not have directly attached issues, try to look -// // for some in the child components. -// return graph.syncRequest(new ChildMaxIssueSeverity(resource, L0.ConsistsOf)); -// } -// -// Severity maxSeverity = graph.syncRequest(new MaxIssueSeveritySingle(resource)); -// if (maxSeverity == null) -// maxSeverity = graph.syncRequest(new ChildMaxIssueSeverity(resource, L0.ConsistsOf)); -// -// return maxSeverity; -// } - + @Override public void perform(AsyncReadGraph graph, final AsyncProcedure procedure) { + IssueResource ISSUE = graph.getService(IssueResource.class); - //System.out.println(getClass().getSimpleName() + ": " + parameter); + + AtomicInteger issues = new AtomicInteger(); + AtomicBoolean excepted = new AtomicBoolean(false); graph.forEachObject(parameter, ISSUE.Issue_HasContext_Inverse, new AsyncMultiProcedure() { - volatile int issues = 0; @Override public void execute(AsyncReadGraph graph, Resource result) { - ++issues; + issues.incrementAndGet(); } @Override public void finished(AsyncReadGraph graph) { - if (issues == 0) { - // This content does not have directly attached issues, try to look - // for some in the child components. - graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure); - } else { - // Try local issues first - graph.asyncRequest(new MaxIssueSeveritySingle(parameter), new AsyncProcedure() { - @Override - public void execute(AsyncReadGraph graph, Severity maxSeverity) { - if (maxSeverity == null) - // No severity for local issues, try children next. - graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure); - else - procedure.execute(graph, maxSeverity); - } - @Override - public void exception(AsyncReadGraph graph, Throwable throwable) { - procedure.exception(graph, throwable); - } - }); - } + } @Override public void exception(AsyncReadGraph graph, Throwable throwable) { - procedure.exception(graph, throwable); + if(excepted.compareAndSet(false, true)) + procedure.exception(graph, throwable); } }); + + graph.forEachObject(parameter, ISSUE.Issue_ContextList_Element_Inverse, new AsyncMultiProcedure() { + @Override + public void execute(AsyncReadGraph graph, Resource result) { + issues.incrementAndGet(); + } + @Override + public void finished(AsyncReadGraph graph) { + + } + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + if(excepted.compareAndSet(false, true)) + procedure.exception(graph, throwable); + } + }); + + if(excepted.get()) return; + + if (issues.get() == 0) { + // This content does not have directly attached issues, try to look + // for some in the child components. + graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure); + } else { + // Try local issues first + graph.asyncRequest(new MaxIssueSeveritySingle(parameter), new AsyncProcedure() { + @Override + public void execute(AsyncReadGraph graph, Severity maxSeverity) { + if (maxSeverity == null) + // No severity for local issues, try children next. + graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure); + else + procedure.execute(graph, maxSeverity); + } + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + if(excepted.compareAndSet(false, true)) + procedure.exception(graph, throwable); + } + }); + } } } diff --git a/bundles/org.simantics.issues.common/src/org/simantics/issues/common/MaxIssueSeveritySingle.java b/bundles/org.simantics.issues.common/src/org/simantics/issues/common/MaxIssueSeveritySingle.java index e8ed917aa..89816d6fa 100644 --- a/bundles/org.simantics.issues.common/src/org/simantics/issues/common/MaxIssueSeveritySingle.java +++ b/bundles/org.simantics.issues.common/src/org/simantics/issues/common/MaxIssueSeveritySingle.java @@ -14,8 +14,12 @@ package org.simantics.issues.common; import java.util.concurrent.atomic.AtomicReference; import org.simantics.db.AsyncReadGraph; +import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.common.request.ResourceAsyncRead; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.common.utils.ListUtils; +import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.AsyncMultiProcedure; import org.simantics.db.procedure.AsyncProcedure; import org.simantics.issues.Severity; @@ -52,11 +56,12 @@ public class MaxIssueSeveritySingle extends ResourceAsyncRead{ @Override public void perform(AsyncReadGraph graph, final AsyncProcedure procedure) { + final IssueResource ISSUE = graph.getService(IssueResource.class); - //System.out.println(getClass().getSimpleName() + ": " + resource); + + AtomicReference maxSeverity = new AtomicReference(); graph.forEachObject(resource, ISSUE.Issue_HasContext_Inverse, new AsyncMultiProcedure() { - AtomicReference maxSeverity = new AtomicReference(); @Override public void execute(AsyncReadGraph graph, final Resource issue) { @@ -69,13 +74,54 @@ public class MaxIssueSeveritySingle extends ResourceAsyncRead{ } @Override public void finished(AsyncReadGraph graph) { - procedure.execute(graph, maxSeverity.get()); } @Override public void exception(AsyncReadGraph graph, Throwable throwable) { procedure.exception(graph, throwable); } }); + + graph.forEachObject(resource, ISSUE.Issue_ContextList_Element_Inverse, new AsyncMultiProcedure() { + @Override + public void execute(AsyncReadGraph graph, final Resource element) { + + graph.asyncRequest(new ResourceRead(element) { + @Override + public Resource perform(ReadGraph graph) throws DatabaseException { + Resource list = ListUtils.getListElementList(graph, resource); + return graph.getSingleObject(list, ISSUE.Issue_HasContexts_Inverse); + } + }, new AsyncProcedure() { + + @Override + public void execute(AsyncReadGraph graph, Resource issue) { + /* + * Compare severity of each related issue and find the maximum severity. + * The issues that are not resolved and have active issue source manager + * are taken into account. + */ + acceptIfNotResolved(graph, procedure, ISSUE, issue, maxSeverity); + } + + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + procedure.exception(graph, throwable); + } + }); + + + } + @Override + public void finished(AsyncReadGraph graph) { + } + @Override + public void exception(AsyncReadGraph graph, Throwable throwable) { + procedure.exception(graph, throwable); + } + }); + + procedure.execute(graph, maxSeverity.get()); + } /** diff --git a/bundles/org.simantics.issues.ontology/graph/Issue.pgraph b/bundles/org.simantics.issues.ontology/graph/Issue.pgraph index 47a8160b5..c68e561f4 100644 --- a/bundles/org.simantics.issues.ontology/graph/Issue.pgraph +++ b/bundles/org.simantics.issues.ontology/graph/Issue.pgraph @@ -27,12 +27,16 @@ ISSUE.ContinuousIssueSource -- ISSUE.Issue.HasContext -- ISSUE.Issue.HasSeverity --> ISSUE.Severity -- ISSUE.Issue.HasContexts --> L0.List -- ISSUE.Issue.HasContexts --> ISSUE.Issue.ContextList -- ISSUE.Issue.contexts ==> "[Resource]" -- ISSUE.Issue.severity ==> "String" -- ISSUE.Issue.resource ==> "String" TabContribution" -MOD.SymbolCodeStyle : DIA.Style \ No newline at end of file +MOD.SymbolCodeStyle : DIA.Style + +MOD.IssueDecorationStyle : DIA.Style \ No newline at end of file diff --git a/bundles/org.simantics.modeling.ui/adapters.xml b/bundles/org.simantics.modeling.ui/adapters.xml index 891ac0d46..495e4e406 100644 --- a/bundles/org.simantics.modeling.ui/adapters.xml +++ b/bundles/org.simantics.modeling.ui/adapters.xml @@ -439,4 +439,10 @@ + + + + + \ No newline at end of file