X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.document.server%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2FDocumentServerUtils.java;h=73c510317314e6937c4688ce5407c7146dd73081;hp=4821bbd1ca0e4c48a1cbe71210d1e53acb2c20be;hb=d9fee21e1ff594dfbaa51a0597b4695f289aa29d;hpb=de86e08dadfd2733d23b3fe2817b27ae835d9f3b 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 4821bbd1c..73c510317 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 @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; @@ -18,12 +19,10 @@ import org.simantics.db.layer0.variable.ProxyChildVariable; import org.simantics.db.layer0.variable.Variable; import org.simantics.db.layer0.variable.Variables; import org.simantics.document.base.ontology.DocumentationResource; -import org.simantics.document.server.Functions.RootVariable; 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 { @@ -126,7 +125,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.getConnection2().getConnectionPointDescriptors(graph, connectionPoint.getParent(graph), null); if(descs.size() != 2) return null; for(VariableConnectionPointDescriptor desc : descs) { @@ -140,7 +139,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.getConnection2().getConnectionPointDescriptors(graph, connectionPoint.getParent(graph), null); if(descs.size() != 2) return null; DocumentationResource DOC = DocumentationResource.getInstance(graph); @@ -173,7 +172,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.getConnection2().getConnectionPoints(graph, connectionPoint.getParent(graph), null); Variable result = null; @@ -191,7 +190,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.getConnection2().getConnectionPoints(graph, connectionPoint.getParent(graph), null); if(cpts.size() < 2) return Collections.emptyList(); @@ -205,12 +204,17 @@ public class DocumentServerUtils { public static String getId(ReadGraph graph, Variable node) throws DatabaseException { - if(node == null) return "root"; - else { - String uri = node.getURI(graph); - int l = uri.lastIndexOf(ProxyChildVariable.CONTEXT_END); - return uri.substring(l+4); - } + if(node == null) return "root"; + else { + String name = node.getName(graph); + if(ProxyChildVariable.CONTEXT_END.equals(name)) return ""; + else { + String parentId = getId(graph, node.getParent(graph)); + if(parentId.isEmpty()) return name; + else return parentId + "/" + name; + } + + } } @@ -292,66 +296,66 @@ public class DocumentServerUtils { public static Collection getAttributes(ReadGraph graph, DocumentationResource DOC, Variable variable) throws DatabaseException { 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 - } - - JSONObject staticContent = computeStatic(graph, variable, statics); - - return new Pair>(staticContent, Collections.emptyList()); - + public JSONObject perform(ReadGraph graph) throws DatabaseException { + DocumentProperties properties = variable.getPropertyValue(graph, "primitiveProperties"); + 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 { - Object value = DocumentServerUtils.getValue(graph, attrib); - object.addJSONField(name, value); + if (name.equals(NodeRequest.PROPERTY_VALUE_EXCEPTIONS)) { + @SuppressWarnings("unchecked") + Map exceptions = (Map)statics.getValue(graph, variable, name); + + List errorList = object.getJSONField(NodeRequest.ERRORS); + if(errorList == null) + errorList = new ArrayList<>(); + + for (Map.Entry entry : exceptions.entrySet()) { + String errorMessage = NodeRequestUtils.formatErrorMessage(entry.getKey(), entry.getValue()); + errorList.add(errorMessage); + } + object.addJSONField(NodeRequest.ERRORS, errorList); + } else { + object.addJSONField(name, statics.getValue(graph, variable, name)); + } } 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); + List errorList = object.getJSONField(NodeRequest.ERRORS); + if(errorList == null) + errorList = new ArrayList<>(1); + + String errorMessage = NodeRequestUtils.formatErrorMessage(name, t); + errorList.add(errorMessage); + object.addJSONField(NodeRequest.ERRORS, errorList); } } return object; - + } - + } 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 { - if(documentPart instanceof RootVariable) return documentPart; + if(ProxyChildVariable.CONTEXT_END.equals(documentPart.getName(graph))) return documentPart; Variable parent = documentPart.getParent(graph); if(parent == null) return null; return getPossibleDocumentRootVariable(graph, parent);