]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.issues.common/src/org/simantics/issues/common/All.java
9173101eee8d77e57f218791d551ac9d2e5f6ff5
[simantics/platform.git] / bundles / org.simantics.issues.common / src / org / simantics / issues / common / All.java
1 package org.simantics.issues.common;
2
3 import java.util.List;
4
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;
15
16 public class All {
17         
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);
21     }
22     
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;
27         return model;
28 //        SimulationResource SIMU = SimulationResource.getInstance(graph);
29 //        if(graph.isInstanceOf(model, SIMU.Model))
30 //            return graph.getSingleObject(model, SimulationResource.getInstance(graph).HasConfiguration);
31 //        else return null;
32
33     }
34     
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);
41         if (severity == null)
42                 return "Undefined";
43         return graph.getPossibleRelatedValue(severity, L0.HasName, Bindings.STRING);
44     }
45
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();
56     }
57
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);
73         } else {
74                 String uri = graph.getURI(parent);
75                 String modelURI = graph.getURI(graph.getRootLibrary());
76                 return IssueUtils.pathString(uri, modelURI.length()+1);
77         }
78     }
79
80     @SCLValue(type = "ReadGraph -> Resource -> Variable -> [Resource]")
81     public static List<Resource> standardIssueContexts(ReadGraph graph, Resource converter, Variable property) throws DatabaseException {
82         return IssueUtils.getContextsForProperty(graph, property);
83     }
84
85 }