1 package org.simantics.document.server.request;
3 import org.simantics.databoard.Bindings;
4 import org.simantics.databoard.Databoard;
5 import org.simantics.databoard.binding.Binding;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.Resource;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.layer0.request.VariableRead;
10 import org.simantics.db.layer0.variable.Variable;
11 import org.simantics.document.base.ontology.DocumentationResource;
12 import org.simantics.document.server.DocumentServerUtils;
13 import org.simantics.document.server.JSONObject;
14 import org.simantics.layer0.Layer0;
15 import org.simantics.structural.stubs.StructuralResource2;
18 * @author Antti Villberg
21 public class DefaultFields extends VariableRead<JSONObject> {
23 public DefaultFields(Variable variable) {
28 public JSONObject perform(ReadGraph graph) throws DatabaseException {
30 Layer0 L0 = Layer0.getInstance(graph);
31 StructuralResource2.getInstance(graph);
32 DocumentationResource DOC = DocumentationResource.getInstance(graph);
34 String id = DocumentServerUtils.getId(graph, variable);
36 Binding jsonBinding = graph.getService(Databoard.class).getBindingUnchecked(JSONObject.class);
37 JSONObject object = new JSONObject(jsonBinding, id);
39 Resource type = variable.getType(graph);
41 Variable parentConnectionPoint = DocumentServerUtils.getParentConnectionPoint(graph, variable);
42 while (parentConnectionPoint != null) {
43 Variable par = parentConnectionPoint.getParent(graph);
44 if(!DOC.Components_DummyContainer.equals(par.getType(graph))) break;
45 parentConnectionPoint = DocumentServerUtils.getParentConnectionPoint(graph, par);
48 if(parentConnectionPoint != null) {
49 String parent = DocumentServerUtils.getId(graph, parentConnectionPoint.getParent(graph));
50 Resource cpPredicate = parentConnectionPoint.getPossiblePredicateResource(graph);
52 if (DOC.Relations_partN.equals(cpPredicate)) {
53 i = DocumentServerUtils.findManualOrdinal(graph, variable);
55 i = graph.getPossibleRelatedValue(cpPredicate, DOC.Document_ChildRelation_ordinal, Bindings.STRING);
61 object.addJSONField("parent", parent);
62 object.addJSONField("parentOrd", i);
64 if(DOC.Components_Root.equals(type) || graph.isInheritedFrom(type, DOC.Components_Root)) {
65 object.addJSONField("parent", "root");
66 object.addJSONField("parentOrd", "0");
67 } if(!graph.isInheritedFrom(type, DOC.Components_ParentlessComponent)) {
68 object.addJSONField("parent", "");
69 object.addJSONField("parentOrd", "0");
73 object.addJSONField("id", id);
74 object.addJSONField("type", graph.<String>getRelatedValue(type, L0.HasName, Bindings.STRING));