1 package org.simantics.graph.compiler.internal.validation;
\r
3 import java.util.Collection;
\r
5 import org.simantics.graph.compiler.GraphCompilerPreferences;
\r
6 import org.simantics.graph.compiler.internal.store.LocationStore;
\r
7 import org.simantics.graph.compiler.internal.templates.TemplateDefinitionStore;
\r
8 import org.simantics.graph.query.Res;
\r
9 import org.simantics.graph.store.GraphStore;
\r
10 import org.simantics.graph.store.StatementCollision;
\r
11 import org.simantics.ltk.Problem;
\r
13 public class ReportCollisions implements Runnable {
\r
14 GraphCompilerPreferences preferences;
\r
15 Collection<Problem> problems;
\r
18 public ReportCollisions(
\r
19 GraphCompilerPreferences preferences, Collection<Problem> problems,
\r
21 this.preferences = preferences;
\r
22 this.problems = problems;
\r
26 private static String abbreviateURI(Res res) {
\r
29 String uri = res.toString();
\r
30 return uri.replace("http://www.simantics.org/", "");
\r
35 LocationStore locations = store.getStore(LocationStore.class);
\r
36 for(int c : store.values.getCollisions().toArray())
\r
37 problems.add(new Problem(
\r
38 locations.getLocation(c),
\r
39 "Two literal values are given for the same resource."));
\r
40 for(int c : store.identities.getCollisions().toArray())
\r
41 problems.add(new Problem(
\r
42 locations.getLocation(c),
\r
43 "Two different identities are given for the same resource."));
\r
44 for(int c : store.getStore(TemplateDefinitionStore.class).getCollisions().toArray())
\r
45 problems.add(new Problem(
\r
46 locations.getLocation(c),
\r
47 "Two template definitions are given for the same resource."));
\r
48 if(preferences.validate)
\r
49 for(StatementCollision collision : store.statements.getCollisions()) {
\r
50 problems.add(new Problem(
\r
51 locations.getLocation(collision.subject),
\r
52 "The same statement is defined " + collision.count + " times: " +
\r
53 abbreviateURI(store.idToRes(collision.subject)) + ", " +
\r
54 abbreviateURI(store.idToRes(collision.predicate)) + ", " +
\r
55 abbreviateURI(store.idToRes(collision.object))));
\r