Issue context modelling enhancements 83/783/1
authorAntti Villberg <antti.villberg@semantum.fi>
Mon, 31 Jul 2017 05:26:45 +0000 (08:26 +0300)
committerAntti Villberg <antti.villberg@semantum.fi>
Mon, 31 Jul 2017 05:26:45 +0000 (08:26 +0300)
refs #7391

Change-Id: Ib1ecb5f161cf85487ee5b6ff43f5640b645ca600

bundles/org.simantics.issues.common/src/org/simantics/issues/common/MaxIssueSeverityRecursive.java
bundles/org.simantics.issues.common/src/org/simantics/issues/common/MaxIssueSeveritySingle.java
bundles/org.simantics.issues.ontology/graph/Issue.pgraph
bundles/org.simantics.modeling.ontology/graph/Modeling.pgraph
bundles/org.simantics.modeling.ui/adapters.xml

index db537ee26ac6d4ed826773b39deb81bc122307fe..7646271e3d91443564d9d51fd47af401d2b9ca68 100644 (file)
@@ -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<Resource, Resour
     public MaxIssueSeverityRecursive(Resource resource, Resource childRelation, Set<Resource> 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<Resource> 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<Severity> 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<Resource>() {
-            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<Severity>() {
-                        @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<Resource>() {
+            @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<Severity>() {
+                @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);
+                }
+            });
+        }
     }
 
 }
index e8ed917aad52182f701f1060fb5a289ce49f1325..89816d6faa42fb2c3d70ae3443901ce3194d85bb 100644 (file)
@@ -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<Severity>{
 
     @Override
     public void perform(AsyncReadGraph graph, final AsyncProcedure<Severity> procedure) {
+       
         final IssueResource ISSUE = graph.getService(IssueResource.class);
-        //System.out.println(getClass().getSimpleName() + ": " + resource);
+
+        AtomicReference<Severity> maxSeverity = new AtomicReference<Severity>();
 
         graph.forEachObject(resource, ISSUE.Issue_HasContext_Inverse, new AsyncMultiProcedure<Resource>() {
-            AtomicReference<Severity> maxSeverity = new AtomicReference<Severity>();
             @Override
             public void execute(AsyncReadGraph graph, final Resource issue) {
                 
@@ -69,13 +74,54 @@ public class MaxIssueSeveritySingle extends ResourceAsyncRead<Severity>{
             }
             @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<Resource>() {
+            @Override
+            public void execute(AsyncReadGraph graph, final Resource element) {
+               
+               graph.asyncRequest(new ResourceRead<Resource>(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<Resource>() {
+
+                                       @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());
+        
     }
     
     /**
index 47a8160b55dd44b718033bfd5667a60486831247..c68e561f43abd47687828347037378d3366de08f 100644 (file)
@@ -27,12 +27,16 @@ ISSUE.ContinuousIssueSource <T ISSUE.IssueSource
 ISSUE.DynamicIssueSource <T ISSUE.IssueSource
     L0.HasDescription "A dynamic issue source is a source that is browsed purely through the Variable interface to produce a single subtree to represent issues. The issues do not have to have a database resource representation backing them."
 
+ISSUE.Issue.ContextList <T L0.List
+    @L0.assert L0.List.ElementPredicate
+      ISSUE.Issue.ContextList.Element <R L0.List.ElementWithInverse
+
 ISSUE.Issue <T L0.Entity
     L0.HasDescription "A notification of specified severity about an issue in the model."
     >-- ISSUE.Issue.HasContext <R L0.IsRelatedTo
       L0.InverseOf ISSUE.Issue.HasContext.Inverse <R L0.IsRelatedTo
     >-- ISSUE.Issue.HasSeverity --> ISSUE.Severity <R L0.DependsOn : L0.FunctionalRelation
-    >-- ISSUE.Issue.HasContexts --> L0.List <R L0.DependsOn
+    >-- ISSUE.Issue.HasContexts --> ISSUE.Issue.ContextList <R L0.DependsOn
     >-- ISSUE.Issue.contexts ==> "[Resource]" <R L0.HasProperty : L0.FunctionalRelation
     >-- ISSUE.Issue.severity ==> "String" <R L0.HasProperty : L0.FunctionalRelation
     >-- ISSUE.Issue.resource ==> "String" <R L0.HasProperty : L0.FunctionalRelation
index e9b91f71aeaba0aedf6369bb4d8119a53e4d9bbd..fe566684dc1a183c7f00c7aa021ec26961f17c9a 100644 (file)
@@ -515,4 +515,6 @@ MOD.SVGTabContribution : SEL.SCLTabContribution
     "svgTabContribution"
     "() -> <Proc> 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
index 891ac0d46ba1cdbb77e37e8ce9803c1708068dc7..495e4e40631b91b140fef805b4d57c578bff3308 100644 (file)
                </type>
        </target>
 
+       <target interface="org.simantics.scenegraph.profile.Style">
+               <resource uri="http://www.simantics.org/Modeling-0.0/IssueDecorationStyle"
+                       class="org.simantics.modeling.ui.diagram.style.IssueDecorationStyle">
+               </resource>
+       </target>
+
 </adapters>
\ No newline at end of file