]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues.common/src/org/simantics/issues/common/IssuesOfSeverity.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.issues.common / src / org / simantics / issues / common / IssuesOfSeverity.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.issues.common;
13
14 import gnu.trove.set.hash.THashSet;
15
16 import java.util.Set;
17
18 import org.simantics.databoard.Bindings;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.common.request.ResourceRead2;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.db.layer0.variable.Variable;
24 import org.simantics.issues.ontology.IssueResource;
25 import org.simantics.layer0.Layer0;
26
27 /**
28  * @author Tuukka Lehtonen
29  * 
30  * @see ErrorIssues
31  * @see WarningIssues
32  * @see NoteIssues
33  * @see FatalIssues
34  * @see InfoIssues
35  */
36 public class IssuesOfSeverity extends ResourceRead2<Set<Variable>> {
37
38     public IssuesOfSeverity(Resource project, Resource expectedSeverity) {
39         super(project, expectedSeverity);
40     }
41
42     protected Resource getExpectedSeverity(ReadGraph graph, IssueResource issue) {
43         return resource2;
44     }
45
46     @Override
47     public Set<Variable> perform(ReadGraph graph) throws DatabaseException {
48         Layer0 L0 = Layer0.getInstance(graph);
49         IssueResource ISSUE = IssueResource.getInstance(graph);
50         Set<Variable> result = new THashSet<Variable>();
51         Resource expectedSeverity = getExpectedSeverity(graph, ISSUE);
52         String expectedSeverityName = graph.getRelatedValue(expectedSeverity, L0.HasName, Bindings.STRING);
53         assert expectedSeverity != null;
54         for (Variable issue : graph.syncRequest(new AllVisibleIssues(resource))) {
55             if (expectedSeverityName.equals(issue.getPossiblePropertyValue(graph, "severity")))
56                 result.add(issue);
57         }
58         return result;
59     }
60
61     public static IssuesOfSeverity error(ReadGraph graph, Resource resource) {
62         return new IssuesOfSeverity(resource, IssueResource.getInstance(graph).Severity_Error);
63     }
64
65     public static IssuesOfSeverity warning(ReadGraph graph, Resource resource) {
66         return new IssuesOfSeverity(resource, IssueResource.getInstance(graph).Severity_Warning);
67     }
68
69     public static IssuesOfSeverity fatal(ReadGraph graph, Resource resource) {
70         return new IssuesOfSeverity(resource, IssueResource.getInstance(graph).Severity_Fatal);
71     }
72
73     public static IssuesOfSeverity info(ReadGraph graph, Resource resource) {
74         return new IssuesOfSeverity(resource, IssueResource.getInstance(graph).Severity_Info);
75     }
76
77     public static IssuesOfSeverity note(ReadGraph graph, Resource resource) {
78         return new IssuesOfSeverity(resource, IssueResource.getInstance(graph).Severity_Note);
79     }
80
81 }