]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.issues.common/src/org/simantics/issues/common/MaxIssueSeveritySingle.java
Issue context modelling enhancements
[simantics/platform.git] / bundles / org.simantics.issues.common / src / org / simantics / issues / common / MaxIssueSeveritySingle.java
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());
+        
     }
     
     /**