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