1 package org.simantics.issues.common;
5 import org.simantics.databoard.Bindings;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.common.request.PossibleIndexRoot;
9 import org.simantics.db.exception.DatabaseException;
10 import org.simantics.db.layer0.variable.Variable;
11 import org.simantics.db.layer0.variable.Variables;
12 import org.simantics.issues.ontology.IssueResource;
13 import org.simantics.layer0.Layer0;
14 import org.simantics.scl.reflection.annotations.SCLValue;
18 @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")
19 public static String defaultDescription(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
20 return context.getParent(graph).getLabel(graph);
23 @SCLValue(type = "a -> b -> c")
24 public static Object dependencyBaseRealizationFunction(Object _graph, Object _model) throws DatabaseException {
25 // ReadGraph graph = (ReadGraph)_graph;
26 Resource model = (Resource)_model;
28 // SimulationResource SIMU = SimulationResource.getInstance(graph);
29 // if(graph.isInstanceOf(model, SIMU.Model))
30 // return graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration);
35 @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")
36 public static String standardIssueSeverity(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {
37 Layer0 L0 = Layer0.getInstance(graph);
38 IssueResource ISSUE = IssueResource.getInstance(graph);
39 Resource issue = property.getParent(graph).getRepresents(graph);
40 Resource severity = graph.getPossibleObject(issue, ISSUE.Issue_HasSeverity);
43 return graph.getPossibleRelatedValue(severity, L0.HasName, Bindings.STRING);
46 @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")
47 public static String standardIssueResource(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {
48 Layer0 L0 = Layer0.getInstance(graph);
49 List<Resource> contexts = IssueUtils.getContextsForProperty(graph, property);
50 if(contexts.isEmpty()) return "";
51 Resource context = contexts.get(0);
52 String name = graph.getPossibleRelatedValue(context, L0.HasName, Bindings.STRING);
53 if((name != null && !name.isEmpty())) return name;
54 if(!graph.hasStatement(context)) return "Removed - please run batch validations";
55 return context.toString();
58 @SCLValue(type = "ReadGraph -> Resource -> Variable -> String")
59 public static String standardIssuePath(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {
60 Layer0 L0 = Layer0.getInstance(graph);
61 List<Resource> contexts = IssueUtils.getContextsForProperty(graph, property);
62 if(contexts.isEmpty()) return "";
63 Resource parent = graph.getPossibleObject(contexts.get(0), L0.PartOf);
64 if(parent == null) return "";
65 Resource issueRoot = Variables.getPossibleIndexRoot(graph, property);
66 if(issueRoot == null) return "";
67 Resource contextRoot = graph.sync(new PossibleIndexRoot(parent));
68 if(contextRoot == null) return "";
69 if(issueRoot.equals(contextRoot)) {
70 String uri = graph.getURI(parent);
71 String contextURI = graph.getURI(contextRoot);
72 return IssueUtils.pathString(uri, contextURI.length()+1);
74 String uri = graph.getURI(parent);
75 String modelURI = graph.getURI(graph.getRootLibrary());
76 return IssueUtils.pathString(uri, modelURI.length()+1);