X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.document.server%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2Frequest%2FNodeRequestStatic.java;h=8a65fb1fc33c93d12ce8d60ecfcab9ca59d59b52;hb=refs%2Fchanges%2F38%2F238%2F2;hp=1bb65316b1e87c094ffc02d0cdd09250b5597f51;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodeRequestStatic.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodeRequestStatic.java index 1bb65316b..8a65fb1fc 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodeRequestStatic.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/NodeRequestStatic.java @@ -1,123 +1,123 @@ -package org.simantics.document.server.request; - -import java.util.ArrayList; -import java.util.List; - -import org.simantics.databoard.Bindings; -import org.simantics.databoard.Databoard; -import org.simantics.databoard.binding.Binding; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.request.VariableRead; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.document.base.ontology.DocumentationResource; -import org.simantics.document.server.DocumentServerUtils; -import org.simantics.document.server.JSONObject; -import org.simantics.layer0.Layer0; -import org.simantics.structural.stubs.StructuralResource2; - -class NodeRequestStatic extends VariableRead { - - public NodeRequestStatic(Variable node) { - super(node); - } - - public static class Headers extends VariableRead { - - public Headers(Variable variable) { - super(variable); - } - - @Override - public JSONObject perform(ReadGraph graph) throws DatabaseException { - - Layer0 L0 = Layer0.getInstance(graph); - StructuralResource2.getInstance(graph); - DocumentationResource DOC = DocumentationResource.getInstance(graph); - - String id = DocumentServerUtils.getId(graph, variable); - - Binding jsonBinding = graph.getService(Databoard.class).getBindingUnchecked(JSONObject.class); - JSONObject object = new JSONObject(jsonBinding, id); - - Resource type = variable.getType(graph); - - Variable parentConnectionPoint = DocumentServerUtils.getParentConnectionPoint(graph, variable); - while (parentConnectionPoint != null) { - Variable par = parentConnectionPoint.getParent(graph); - if(!DOC.Components_DummyContainer.equals(par.getType(graph))) break; - parentConnectionPoint = DocumentServerUtils.getParentConnectionPoint(graph, par); - } - - if(parentConnectionPoint != null) { - String parent = DocumentServerUtils.getId(graph, parentConnectionPoint.getParent(graph)); - Resource cpPredicate = parentConnectionPoint.getPossiblePredicateResource(graph); - String i = null; - if (DOC.Relations_partN.equals(cpPredicate)) { - i = DocumentServerUtils.findManualOrdinal(graph, variable); - } else { - i = graph.getPossibleRelatedValue(cpPredicate, DOC.Document_ChildRelation_ordinal, Bindings.STRING); - } - if (i == null) { - i = "0"; - } - - object.addJSONField("parent", parent); - object.addJSONField("parentOrd", i); - } else { - if(DOC.Components_Root.equals(type) || graph.isInheritedFrom(type, DOC.Components_Root)) { - object.addJSONField("parent", "root"); - object.addJSONField("parentOrd", "0"); - } if(!graph.isInheritedFrom(type, DOC.Components_ParentlessComponent)) { - object.addJSONField("parent", ""); - object.addJSONField("parentOrd", "0"); - } - } - - object.addJSONField("id", id); - object.addJSONField("type", graph.getRelatedValue(type, L0.HasName, Bindings.STRING)); - return object; - - } - - } - - @Override - public JSONObject perform(ReadGraph graph) throws DatabaseException { - - long s = System.nanoTime(); - - JSONObject base = graph.syncRequest(new Headers(variable)); - JSONObject object = base.clone(); - - DocumentationResource DOC = DocumentationResource.getInstance(graph); - - for(Variable attrib : DocumentServerUtils.getStaticAttributes(graph, DOC, variable)) { - String name = attrib.getName(graph); - try { - Object value = DocumentServerUtils.getValue(graph, attrib); - object.addJSONField(name, value); - } catch (Throwable t) { - List errorList = object.getJSONField(NodeRequest.ERRORS); - if(errorList == null) - errorList = new ArrayList(); - - String errorMessage = NodeRequestUtils.formatErrorMessage(name, t); - - errorList.add(errorMessage); - object.addJSONField(NodeRequest.ERRORS, errorList); - } - - } - - if(DocumentRequest.PROFILE) { - long dura = System.nanoTime()-s; - System.err.println("NodeRequestStatic " + System.identityHashCode(this) + " " + variable.getURI(graph) + " in " + 1e-6*dura + "ms." + object); - } - - return object; - - } - +package org.simantics.document.server.request; + +import java.util.ArrayList; +import java.util.List; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.Databoard; +import org.simantics.databoard.binding.Binding; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.VariableRead; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.document.base.ontology.DocumentationResource; +import org.simantics.document.server.DocumentServerUtils; +import org.simantics.document.server.JSONObject; +import org.simantics.layer0.Layer0; +import org.simantics.structural.stubs.StructuralResource2; + +class NodeRequestStatic extends VariableRead { + + public NodeRequestStatic(Variable node) { + super(node); + } + + public static class Headers extends VariableRead { + + public Headers(Variable variable) { + super(variable); + } + + @Override + public JSONObject perform(ReadGraph graph) throws DatabaseException { + + Layer0 L0 = Layer0.getInstance(graph); + StructuralResource2.getInstance(graph); + DocumentationResource DOC = DocumentationResource.getInstance(graph); + + String id = DocumentServerUtils.getId(graph, variable); + + Binding jsonBinding = graph.getService(Databoard.class).getBindingUnchecked(JSONObject.class); + JSONObject object = new JSONObject(jsonBinding, id); + + Resource type = variable.getType(graph); + + Variable parentConnectionPoint = DocumentServerUtils.getParentConnectionPoint(graph, variable); + while (parentConnectionPoint != null) { + Variable par = parentConnectionPoint.getParent(graph); + if(!DOC.Components_DummyContainer.equals(par.getType(graph))) break; + parentConnectionPoint = DocumentServerUtils.getParentConnectionPoint(graph, par); + } + + if(parentConnectionPoint != null) { + String parent = DocumentServerUtils.getId(graph, parentConnectionPoint.getParent(graph)); + Resource cpPredicate = parentConnectionPoint.getPossiblePredicateResource(graph); + String i = null; + if (DOC.Relations_partN.equals(cpPredicate)) { + i = DocumentServerUtils.findManualOrdinal(graph, variable); + } else { + i = graph.getPossibleRelatedValue(cpPredicate, DOC.Document_ChildRelation_ordinal, Bindings.STRING); + } + if (i == null) { + i = "0"; + } + + object.addJSONField("parent", parent); + object.addJSONField("parentOrd", i); + } else { + if(DOC.Components_Root.equals(type) || graph.isInheritedFrom(type, DOC.Components_Root)) { + object.addJSONField("parent", "root"); + object.addJSONField("parentOrd", "0"); + } if(!graph.isInheritedFrom(type, DOC.Components_ParentlessComponent)) { + object.addJSONField("parent", ""); + object.addJSONField("parentOrd", "0"); + } + } + + object.addJSONField("id", id); + object.addJSONField("type", graph.getRelatedValue(type, L0.HasName, Bindings.STRING)); + return object; + + } + + } + + @Override + public JSONObject perform(ReadGraph graph) throws DatabaseException { + + long s = System.nanoTime(); + + JSONObject base = graph.syncRequest(new Headers(variable)); + JSONObject object = base.clone(); + + DocumentationResource DOC = DocumentationResource.getInstance(graph); + + for(Variable attrib : DocumentServerUtils.getStaticAttributes(graph, DOC, variable)) { + String name = attrib.getName(graph); + try { + Object value = DocumentServerUtils.getValue(graph, attrib); + object.addJSONField(name, value); + } catch (Throwable t) { + List errorList = object.getJSONField(NodeRequest.ERRORS); + if(errorList == null) + errorList = new ArrayList(); + + String errorMessage = NodeRequestUtils.formatErrorMessage(name, t); + + errorList.add(errorMessage); + object.addJSONField(NodeRequest.ERRORS, errorList); + } + + } + + if(DocumentRequest.PROFILE) { + long dura = System.nanoTime()-s; + System.err.println("NodeRequestStatic " + System.identityHashCode(this) + " " + variable.getURI(graph) + " in " + 1e-6*dura + "ms." + object); + } + + return object; + + } + } \ No newline at end of file