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%2FFunctions.java;h=4915fc002ecdbc91b0a54806f796daa8f730b85e;hp=6ec2e6734a5a70808dcb02d6ef9e05c43a3a97ef;hb=d9fee21e1ff594dfbaa51a0597b4695f289aa29d;hpb=6ff5e65793559d92443fcd1eb7e8d12a3bed9e9e diff --git a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java index 6ec2e6734..4915fc002 100644 --- a/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java +++ b/bundles/org.simantics.document.server/src/org/simantics/document/server/Functions.java @@ -23,8 +23,10 @@ import org.simantics.db.Session; import org.simantics.db.Statement; import org.simantics.db.WriteGraph; import org.simantics.db.common.primitiverequest.Adapter; +import org.simantics.db.common.procedure.adapter.TransientCacheAsyncListener; import org.simantics.db.common.procedure.adapter.TransientCacheListener; import org.simantics.db.common.request.BinaryRead; +import org.simantics.db.common.request.ResourceRead; import org.simantics.db.common.request.UniqueRead; import org.simantics.db.common.request.WriteResultRequest; import org.simantics.db.common.utils.Logger; @@ -212,28 +214,91 @@ public class Functions { }; - static class StandardDocumentProperties implements DocumentProperties { + static class DocumentPropertyKeys extends ResourceRead> { + + protected DocumentPropertyKeys(Resource resource) { + super(resource); + } @Override - public Collection getKeys(ReadGraph graph, Variable context) throws DatabaseException { - + public List perform(ReadGraph graph) throws DatabaseException { + + List result = new ArrayList<>(); + DocumentationResource DOC = DocumentationResource.getInstance(graph); - StandardGraphPropertyVariable asd = new StandardGraphPropertyVariable(graph, context, DOC.Properties_primitiveProperties); - Map ps = primitiveProperties.getVariables(graph, asd, null); - return ps.keySet(); - + + if(graph.hasStatement(resource, DOC.Properties_commands)) + result.add("commands"); + if(graph.hasStatement(resource, DOC.Properties_dataDefinitions)) + result.add("dataDefinitions"); + + DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class); + DirectStatements ds = dqs.getDirectPersistentStatements(graph, resource); + + for(Statement stm : ds) { + + Resource predicate = stm.getPredicate(); + PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate)); + + if(info.isHasProperty && info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) { + result.add(info.name); + } else { + Resource definition = graph.getPossibleObject(predicate, DOC.Document_definesAttributeRelation); + if(definition != null) { + PropertyInfo info2 = graph.syncRequest(new PropertyInfoRequest(definition)); + result.add(info2.name); + } + } + } + + return result; + + } + + } + + static class StandardDocumentProperties implements DocumentProperties { + + @Override + public Collection getKeys(ReadGraph graph, Variable parent) throws DatabaseException { + + if(parent instanceof StandardProceduralChildVariable) { + + StandardProceduralChildVariable procedural = (StandardProceduralChildVariable)parent; + List result = new ArrayList<>(); + for(Variable property : procedural.getProperties(graph)) { + if(property instanceof StandardAssertedGraphPropertyVariable) { + StandardAssertedGraphPropertyVariable ass = (StandardAssertedGraphPropertyVariable)property; + if("dataDefinitions".equals(ass.property.name) || "commands".equals(ass.property.name) || "pollingFunction".equals(ass.property.name)) { + result.add(ass.property.name); + } + continue; + } + Resource predicate = property.getPossiblePredicateResource(graph); + if(predicate != null) { + PropertyInfo info = graph.syncRequest(new PropertyInfoRequest(predicate)); + if(info.hasClassification(DocumentationResource.URIs.Document_AttributeRelation)) { + result.add(info.name); + } + } + } + + return result; + + } else { + + Resource parentRes = parent.getRepresents(graph); + return graph.syncRequest(new DocumentPropertyKeys(parentRes), TransientCacheAsyncListener.instance()); + + } + } @Override public Object getValue(ReadGraph graph, Variable context, String key) throws DatabaseException { - - DocumentationResource DOC = DocumentationResource.getInstance(graph); - StandardGraphPropertyVariable asd = new StandardGraphPropertyVariable(graph, context, DOC.Properties_primitiveProperties); - Map ps = primitiveProperties.getVariables(graph, asd, null); - return ps.get(key).getValue(graph); - + return context.getPropertyValue(graph, key); } - + } public static DocumentProperties primitiveProperties() throws DatabaseException {