X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.document.server%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2FDocumentServerUtils.java;h=d8294c5e09e0c202e6a96bf2ade19932281d6fae;hb=3850fec72035293b9a4ede780d01aedc5fbc9056;hp=5e1f5cc30e798aff45343b8f8c5f4483b6d8a9cc;hpb=6f11a60dee43d620d500c0cf5af34a1d91c80a8b;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentServerUtils.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentServerUtils.java index 5e1f5cc30..d8294c5e0 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentServerUtils.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/DocumentServerUtils.java @@ -12,7 +12,7 @@ import java.util.TreeMap; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; -import org.simantics.db.common.request.UnaryRead; +import org.simantics.db.common.request.BinaryRead; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.request.VariableRead; import org.simantics.db.layer0.variable.ProxyChildVariable; @@ -24,7 +24,6 @@ import org.simantics.document.server.request.NodeRequest; import org.simantics.document.server.request.NodeRequestUtils; import org.simantics.structural2.variables.Connection; import org.simantics.structural2.variables.VariableConnectionPointDescriptor; -import org.simantics.utils.datastructures.Pair; import org.simantics.utils.strings.AlphanumComparator; public class DocumentServerUtils { @@ -127,7 +126,7 @@ public class DocumentServerUtils { public static Variable getPossibleOtherConnectionPoint(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException { - Collection descs = conn.getConnectionPointDescriptors(graph, null); + Collection descs = conn.getConnectionPointDescriptors(graph, connectionPoint.getParent(graph), null); if(descs.size() != 2) return null; for(VariableConnectionPointDescriptor desc : descs) { @@ -141,7 +140,7 @@ public class DocumentServerUtils { public static Variable getPossibleChildConnectionPoint(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException { - Collection descs = conn.getConnectionPointDescriptors(graph, null); + Collection descs = conn.getConnectionPointDescriptors(graph, connectionPoint.getParent(graph), null); if(descs.size() != 2) return null; DocumentationResource DOC = DocumentationResource.getInstance(graph); @@ -161,7 +160,7 @@ public class DocumentServerUtils { ArrayList connectionPoints = new ArrayList(); - Collection descs = conn.getConnectionPointDescriptors(graph, null); + Collection descs = conn.getConnectionPointDescriptors(graph, connectionPoint.getParent(graph), null); for(VariableConnectionPointDescriptor desc : descs) { if(desc.isFlattenedFrom(graph, connectionPoint)) continue; @@ -174,7 +173,7 @@ public class DocumentServerUtils { public static Variable getPossibleCommandTriggerConnectionPoint(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException { - Collection cpts = conn.getConnectionPoints(graph, null); + Collection cpts = conn.getConnectionPoints(graph, connectionPoint.getParent(graph), null); Variable result = null; @@ -192,7 +191,7 @@ public class DocumentServerUtils { public static Collection getPossibleOtherConnectionPoints(ReadGraph graph, Variable connectionPoint, Connection conn) throws DatabaseException { - Collection cpts = conn.getConnectionPoints(graph, null); + Collection cpts = conn.getConnectionPoints(graph, connectionPoint.getParent(graph), null); if(cpts.size() < 2) return Collections.emptyList(); @@ -237,11 +236,11 @@ public class DocumentServerUtils { if (otherCp != null) { return otherCp; } else { - Variable parentCp = graph.sync(new UnaryRead(conn) { + Variable parentCp = graph.sync(new BinaryRead(connectionPoint.getParent(graph), conn) { @Override public Variable perform(ReadGraph graph) throws DatabaseException { DocumentationResource DOC = DocumentationResource.getInstance(graph); - Collection descs = parameter.getConnectionPointDescriptors(graph, null); + Collection descs = parameter2.getConnectionPointDescriptors(graph, parameter, null); for(VariableConnectionPointDescriptor desc : descs) { if (DOC.Relations_partN.equals(desc.getConnectionPointResource(graph))) { @@ -294,40 +293,33 @@ public class DocumentServerUtils { return variable.getProperties(graph, DOC.Document_AttributeRelation); } - public static class AttributesRequest extends VariableRead>> { + public static class AttributesRequest extends VariableRead { public AttributesRequest(Variable variable) { super(variable); } @Override - public Pair> perform(ReadGraph graph) throws DatabaseException { - ArrayList statics = new ArrayList(); - DocumentationResource DOC = DocumentationResource.getInstance(graph); - - Variable primitives = variable.getProperty(graph, DOC.Properties_primitiveProperties); - for(Variable property : primitives.getProperties(graph)) { - statics.add(property); - // NO SUPPORT FOR DYNAMICS AT THIS STAGE - } + public JSONObject perform(ReadGraph graph) throws DatabaseException { + + DocumentationResource DOC = DocumentationResource.getInstance(graph); - JSONObject staticContent = computeStatic(graph, variable, statics); + DocumentProperties properties = variable.getPropertyValue(graph, DOC.Properties_primitiveProperties); - return new Pair>(staticContent, Collections.emptyList()); + return computeStatic(graph, variable, properties); } - JSONObject computeStatic(ReadGraph graph, Variable variable, ArrayList statics) throws DatabaseException { + JSONObject computeStatic(ReadGraph graph, Variable variable, DocumentProperties statics) throws DatabaseException { JSONObject base = graph.syncRequest(new org.simantics.document.server.request.DefaultFields(variable)); JSONObject object = base.clone(); - for(Variable attrib : statics) { - String name = attrib.getName(graph); + for(String name : statics.getKeys(graph, variable)) { try { if (name.equals(NodeRequest.PROPERTY_VALUE_EXCEPTIONS)) { @SuppressWarnings("unchecked") - Map exceptions = (Map)DocumentServerUtils.getValue(graph, attrib); + Map exceptions = (Map)statics.getValue(graph, variable, name);//(Map)DocumentServerUtils.getValue(graph, attrib); List errorList = object.getJSONField(NodeRequest.ERRORS); if(errorList == null) @@ -340,8 +332,7 @@ public class DocumentServerUtils { object.addJSONField(NodeRequest.ERRORS, errorList); } else { - Object value = DocumentServerUtils.getValue(graph, attrib); - object.addJSONField(name, value); + object.addJSONField(name, statics.getValue(graph, variable, name)); } } catch (Throwable t) { List errorList = object.getJSONField(NodeRequest.ERRORS); @@ -363,8 +354,7 @@ public class DocumentServerUtils { } public static Collection getDynamicAttributes(ReadGraph graph, final DocumentationResource DOC, Variable variable) throws DatabaseException { - Pair> attribs = graph.syncRequest(new AttributesRequest(variable)); - return attribs.second; + return Collections.emptyList(); } public static Variable getPossibleDocumentRootVariable(ReadGraph graph, Variable documentPart) throws DatabaseException {