]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues.common/src/org/simantics/issues/common/CountModelIssuesBySeverity.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.issues.common / src / org / simantics / issues / common / CountModelIssuesBySeverity.java
1 /*******************************************************************************
2  * Copyright (c) 2013 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.map.TObjectIntMap;
15 import gnu.trove.map.hash.TObjectIntHashMap;
16
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.common.request.ObjectsWithType;
20 import org.simantics.db.common.request.TernaryRead;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.issues.Severity;
23 import org.simantics.issues.ontology.IssueResource;
24 import org.simantics.layer0.Layer0;
25
26 /**
27  * @author Tuukka Lehtonen
28  * @see CountModelIssuesWithSeverity
29  */
30 public class CountModelIssuesBySeverity extends TernaryRead<Resource, Boolean, Severity, TObjectIntMap<Severity>> {
31
32     public CountModelIssuesBySeverity(Resource model, boolean onlyUnresolved, Severity minSeverity) {
33         super(model, onlyUnresolved, minSeverity);
34     }
35
36     @Override
37     public TObjectIntMap<Severity> perform(ReadGraph graph) throws DatabaseException {
38         Layer0 L0 = Layer0.getInstance(graph);
39         IssueResource ISSUE = IssueResource.getInstance(graph);
40
41         TObjectIntMap<Severity> result = new TObjectIntHashMap<Severity>();
42         for (Resource issue : graph.syncRequest(new ObjectsWithType(parameter, L0.ConsistsOf, ISSUE.Issue))) {
43             if (parameter2 && graph.hasStatement(issue, ISSUE.Resolved))
44                 continue;
45             Severity s = IssueUtils.toSeverity(ISSUE, graph.getPossibleObject(issue, ISSUE.Issue_HasSeverity));
46             if (null != s && s.compareTo(parameter3) <= 0)
47                 result.adjustOrPutValue(s, 1, 1);
48         }
49         return result;
50     }
51
52 }