1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.issues.common;
\r
14 import java.util.Set;
\r
16 import org.simantics.db.AsyncReadGraph;
\r
17 import org.simantics.db.Resource;
\r
18 import org.simantics.db.common.request.TernaryAsyncRead;
\r
19 import org.simantics.db.procedure.AsyncMultiProcedure;
\r
20 import org.simantics.db.procedure.AsyncProcedure;
\r
21 import org.simantics.issues.Severity;
\r
22 import org.simantics.issues.ontology.IssueResource;
\r
25 * @author Tuukka Lehtonen
\r
27 public class MaxIssueSeverityRecursive extends TernaryAsyncRead<Resource, Resource, Set<Resource>, Severity> {
\r
29 public MaxIssueSeverityRecursive(Resource resource, Resource childRelation, Set<Resource> typesToRecurse) {
\r
30 super(resource, childRelation, typesToRecurse);
\r
34 // public Severity perform(ReadGraph graph) throws DatabaseException {
\r
35 // Layer0 L0 = Layer0.getInstance(graph);
\r
36 // IssueResource ISSUE = IssueResource.getInstance(graph);
\r
37 // //System.out.println("severity: " + NameUtils.getSafeName(graph, resource));
\r
38 // Collection<Resource> issues = graph.getObjects(resource, ISSUE.IsIssueContextOf);
\r
39 // if (issues.isEmpty()) {
\r
40 // // This content does not have directly attached issues, try to look
\r
41 // // for some in the child components.
\r
42 // return graph.syncRequest(new ChildMaxIssueSeverity(resource, L0.ConsistsOf));
\r
45 // Severity maxSeverity = graph.syncRequest(new MaxIssueSeveritySingle(resource));
\r
46 // if (maxSeverity == null)
\r
47 // maxSeverity = graph.syncRequest(new ChildMaxIssueSeverity(resource, L0.ConsistsOf));
\r
49 // return maxSeverity;
\r
53 public void perform(AsyncReadGraph graph, final AsyncProcedure<Severity> procedure) {
\r
54 IssueResource ISSUE = graph.getService(IssueResource.class);
\r
55 //System.out.println(getClass().getSimpleName() + ": " + parameter);
\r
57 graph.forEachObject(parameter, ISSUE.Issue_HasContext_Inverse, new AsyncMultiProcedure<Resource>() {
\r
58 volatile int issues = 0;
\r
60 public void execute(AsyncReadGraph graph, Resource result) {
\r
64 public void finished(AsyncReadGraph graph) {
\r
66 // This content does not have directly attached issues, try to look
\r
67 // for some in the child components.
\r
68 graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure);
\r
70 // Try local issues first
\r
71 graph.asyncRequest(new MaxIssueSeveritySingle(parameter), new AsyncProcedure<Severity>() {
\r
73 public void execute(AsyncReadGraph graph, Severity maxSeverity) {
\r
74 if (maxSeverity == null)
\r
75 // No severity for local issues, try children next.
\r
76 graph.asyncRequest(new ChildMaxIssueSeverity(parameter, parameter2, parameter3), procedure);
\r
78 procedure.execute(graph, maxSeverity);
\r
81 public void exception(AsyncReadGraph graph, Throwable throwable) {
\r
82 procedure.exception(graph, throwable);
\r
88 public void exception(AsyncReadGraph graph, Throwable throwable) {
\r
89 procedure.exception(graph, throwable);
\r