X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.document.server%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fserver%2Frequest%2FServerSCLValueRequest.java;h=7f9473861708decb38097a0ee5530657956820a1;hb=ee8f590cd00bf1f046062f623b024f26ef17f4e1;hp=7d1af5f4c1ea6d765811c036986a96a08ba2736a;hpb=e807368d0e75809e0797d9cea1063b046fabf352;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java index 7d1af5f4c..7f9473861 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/request/ServerSCLValueRequest.java @@ -6,10 +6,12 @@ import java.util.Map; import org.simantics.databoard.Bindings; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.Statement; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.IndexRoot; import org.simantics.db.common.request.PossibleTypedParent; import org.simantics.db.common.request.UnaryRead; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.scl.AbstractExpressionCompilationContext; import org.simantics.db.layer0.scl.AbstractExpressionCompilationRequest; @@ -43,7 +45,7 @@ import org.simantics.utils.datastructures.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest { +public class ServerSCLValueRequest extends ServerSCLValueRequestBase { private final Pair componentTypeAndRoot; private final Resource literal; @@ -89,39 +91,9 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< return Pair.make(parent.getType(graph), root); } - private static Pair getComponentTypeAndRoot(ReadGraph graph, Resource component, Resource literal) throws DatabaseException { - if(component != null) { - Resource type = graph.syncRequest(new FindPossibleComponentTypeRequest(component)); - if(type != null) { - Resource root = graph.syncRequest(new IndexRoot(type)); - // System.err.println("getComponentTypeAndRoot3 " + graph.getPossibleURI(component) + " => " + graph.getPossibleURI(type) + " " + graph.getPossibleURI(root)); - return Pair.make(type, root); - } else { - Resource doc = graph.syncRequest(new PossibleTypedParent(component, DocumentationResource.getInstance(graph).Document)); - if(doc != null) { - Resource componentType = graph.getSingleType(doc); - Resource root = graph.syncRequest(new IndexRoot(doc)); - return Pair.make(componentType, root); - } else { - System.err.println("component = " + component); - Resource root = graph.syncRequest(new IndexRoot(component)); -// Resource componentType = graph.getSingleType(doc); - return Pair.make(null, root); - } - } - // TODO: For Antti to consider and fix later - // Introduced to handle procedural user components where component == null - } else if (literal != null) { - Resource root = graph.syncRequest(new IndexRoot(literal)); - return Pair.make(null, root); - } else { - throw new DatabaseException("Couldn't resolve component type and root for component == null && literal == null"); - } - } - public static Object compileAndEvaluate(ReadGraph graph, Variable context) throws DatabaseException { SCLContext sclContext = SCLContext.getCurrent(); - Object oldGraph = sclContext.get("graph"); + Object oldGraph = sclContext.get("graph"); try { Function1 exp = compile(graph, context); sclContext.put("graph", graph); @@ -131,7 +103,7 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< } catch (Throwable t) { throw new DatabaseException(t); } finally { - sclContext.put("graph", oldGraph); + sclContext.put("graph", oldGraph); } } @@ -274,6 +246,20 @@ public class ServerSCLValueRequest extends AbstractExpressionCompilationRequest< public static Function1 validate(ReadGraph graph, Variable context) throws DatabaseException { return graph.syncRequest(new ServerSCLValueValidationRequest(graph, context), TransientCacheListener.instance()); } + + @Override + protected String getContextDescription(ReadGraph graph) throws DatabaseException { + Layer0 L0 = Layer0.getInstance(graph); + Statement possibleOwner = graph.getPossibleStatement(literal, L0.IsOwnedBy); + if(possibleOwner != null) { + String uri = graph.getPossibleURI(possibleOwner.getObject()); + if(uri != null) { + String propertyName = NameUtils.getSafeName(graph, graph.getInverse(possibleOwner.getPredicate())); + return uri + "#" + propertyName; + } + } + return super.getContextDescription(graph); + } public static class ServerSCLValueValidationRequest extends ServerSCLValueRequest {