]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.issues.common/src/org/simantics/issues/common/MaxIssueSeverityRecursive.java
Multiple readers in db client
[simantics/platform.git] / bundles / org.simantics.issues.common / src / org / simantics / issues / common / MaxIssueSeverityRecursive.java
index 673b071bc13154d81c349de5db6e77407dadeac3..ed3d6c2b97f66c97d7e40a050c0699e9152b2f84 100644 (file)
@@ -1,94 +1,52 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.issues.common;\r
-\r
-import java.util.Set;\r
-\r
-import org.simantics.db.AsyncReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.TernaryAsyncRead;\r
-import org.simantics.db.procedure.AsyncMultiProcedure;\r
-import org.simantics.db.procedure.AsyncProcedure;\r
-import org.simantics.issues.Severity;\r
-import org.simantics.issues.ontology.IssueResource;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class MaxIssueSeverityRecursive extends TernaryAsyncRead<Resource, Resource, Set<Resource>, Severity> {\r
-\r
-    public MaxIssueSeverityRecursive(Resource resource, Resource childRelation, Set<Resource> typesToRecurse) {\r
-        super(resource, childRelation, typesToRecurse);\r
-    }\r
-\r
-//    @Override\r
-//    public Severity perform(ReadGraph graph) throws DatabaseException {\r
-//        Layer0 L0 = Layer0.getInstance(graph);\r
-//        IssueResource ISSUE = IssueResource.getInstance(graph);\r
-//        //System.out.println("severity: " + NameUtils.getSafeName(graph, resource));\r
-//        Collection<Resource> issues = graph.getObjects(resource, ISSUE.IsIssueContextOf);\r
-//        if (issues.isEmpty()) {\r
-//            // This content does not have directly attached issues, try to look\r
-//            // for some in the child components.\r
-//            return graph.syncRequest(new ChildMaxIssueSeverity(resource, L0.ConsistsOf));\r
-//        }\r
-//\r
-//        Severity maxSeverity = graph.syncRequest(new MaxIssueSeveritySingle(resource));\r
-//        if (maxSeverity == null)\r
-//            maxSeverity = graph.syncRequest(new ChildMaxIssueSeverity(resource, L0.ConsistsOf));\r
-//\r
-//        return maxSeverity;\r
-//    }\r
-\r
-    @Override\r
-    public void perform(AsyncReadGraph graph, final AsyncProcedure<Severity> procedure) {\r
-        IssueResource ISSUE = graph.getService(IssueResource.class);\r
-        //System.out.println(getClass().getSimpleName() + ": " + parameter);\r
-\r
-        graph.forEachObject(parameter, ISSUE.Issue_HasContext_Inverse, new AsyncMultiProcedure<Resource>() {\r
-            volatile int issues = 0;\r
-            @Override\r
-            public void execute(AsyncReadGraph graph, Resource result) {\r
-                ++issues;\r
-            }\r
-            @Override\r
-            public void finished(AsyncReadGraph graph) {\r
-                if (issues == 0) {\r
-                    // This content does not have directly attached issues, try to look\r
-                    // for some in the child components.\r
-                    graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure);\r
-                } else {\r
-                    // Try local issues first\r
-                    graph.asyncRequest(new MaxIssueSeveritySingle(parameter), new AsyncProcedure<Severity>() {\r
-                        @Override\r
-                        public void execute(AsyncReadGraph graph, Severity maxSeverity) {\r
-                            if (maxSeverity == null)\r
-                                // No severity for local issues, try children next.\r
-                                graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure);\r
-                            else\r
-                                procedure.execute(graph, maxSeverity);\r
-                        }\r
-                        @Override\r
-                        public void exception(AsyncReadGraph graph, Throwable throwable) {\r
-                            procedure.exception(graph, throwable);\r
-                        }\r
-                    });\r
-                }\r
-            }\r
-            @Override\r
-            public void exception(AsyncReadGraph graph, Throwable throwable) {\r
-                procedure.exception(graph, throwable);\r
-            }\r
-        });\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.issues.common;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.request.TernaryRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.issues.Severity;
+import org.simantics.issues.ontology.IssueResource;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class MaxIssueSeverityRecursive extends TernaryRead<Resource, Resource, Set<Resource>, Severity> {
+
+    public MaxIssueSeverityRecursive(Resource resource, Resource childRelation, Set<Resource> typesToRecurse) {
+        super(resource, childRelation, typesToRecurse);
+    }
+    
+    @Override
+    public Severity perform(ReadGraph graph) throws DatabaseException {
+
+        IssueResource ISSUE = graph.getService(IssueResource.class);
+
+        Collection<Resource> inv = graph.getObjects(parameter, ISSUE.Issue_HasContext_Inverse);
+        Collection<Resource> inv2 = graph.getObjects(parameter, ISSUE.Issue_ContextList_Element_Inverse);
+        if(inv.isEmpty() && inv2.isEmpty()) {
+            return graph.syncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3));
+        }
+        
+        Severity max = graph.syncRequest(new MaxIssueSeveritySingle(parameter));
+        if(max != null)
+            return max;
+        else
+            return graph.syncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3));
+            
+    }
+
+}