From: Hannu Niemistö Date: Tue, 1 Aug 2017 14:45:59 +0000 (+0300) Subject: Merge "(refs #7371) Support expression cloning for ECHRSelect" X-Git-Tag: v1.31.0~264^2~13 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=5f777aa757a8eef106aeaf621d3b030162fa6bb8;hp=4ebc60b24db646dc2c64dd54190b029b8e28d030 Merge "(refs #7371) Support expression cloning for ECHRSelect" --- diff --git a/bundles/org.simantics.browsing.ui.model/adapters.xml b/bundles/org.simantics.browsing.ui.model/adapters.xml index 50b343479..4276f3feb 100644 --- a/bundles/org.simantics.browsing.ui.model/adapters.xml +++ b/bundles/org.simantics.browsing.ui.model/adapters.xml @@ -181,6 +181,14 @@ class="org.simantics.browsing.ui.model.tests.FailTest" constructor="get"> + + + + diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tests/HasURITest.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tests/HasURITest.java new file mode 100644 index 000000000..344362588 --- /dev/null +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tests/HasURITest.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2017 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.browsing.ui.model.tests; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.InvalidVariableException; +import org.simantics.db.layer0.variable.Variable; + +/** + * @author Tuukka Lehtonen + * @since 1.30.0 + */ +public enum HasURITest implements Test { + INSTANCE; + + public static HasURITest get() { + return INSTANCE; + } + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class) || contentType.equals(Variable.class); + } + + @Override + public boolean test(ReadGraph graph, Object content) throws DatabaseException { + if (content instanceof Resource) { + return graph.getPossibleURI((Resource) content) != null; + } else if (content instanceof Variable) { + try { + Variable v = (Variable) content; + return v.getURI(graph) != null; + } catch (InvalidVariableException e) { + return false; + } + } + return false; + } + +} diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tests/InDevelopmentModeTest.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tests/InDevelopmentModeTest.java new file mode 100644 index 000000000..fa85e256b --- /dev/null +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tests/InDevelopmentModeTest.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2017 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.browsing.ui.model.tests; + +import org.eclipse.core.runtime.Platform; +import org.simantics.db.ReadGraph; +import org.simantics.db.exception.DatabaseException; + +/** + * @author Tuukka Lehtonen + * @since 1.30.0 + */ +public enum InDevelopmentModeTest implements Test { + INSTANCE; + + public static InDevelopmentModeTest get() { + return INSTANCE; + } + + @Override + public boolean isCompatible(Class contentType) { + return true; + } + + @Override + public boolean test(ReadGraph graph, Object content) throws DatabaseException { + return Platform.inDevelopmentMode(); + } + +} diff --git a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tooltips/DescriptionTooltipRule.java b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tooltips/DescriptionTooltipRule.java index 7bef8e22c..a9ebb9dfc 100644 --- a/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tooltips/DescriptionTooltipRule.java +++ b/bundles/org.simantics.browsing.ui.model/src/org/simantics/browsing/ui/model/tooltips/DescriptionTooltipRule.java @@ -18,9 +18,9 @@ import org.simantics.db.layer0.variable.Variable; import org.simantics.layer0.Layer0; public class DescriptionTooltipRule implements TooltipRule { - + public static final DescriptionTooltipRule INSTANCE = new DescriptionTooltipRule(); - + public DescriptionTooltipRule() { } @@ -58,28 +58,26 @@ public class DescriptionTooltipRule implements TooltipRule { public boolean isCompatible(Class contentType) { return (contentType == Resource.class || contentType == Variable.class); } - + private static String getToolTipContent(ReadGraph graph, NodeContext nodeContext) throws DatabaseException { Object input = nodeContext.getConstant(BuiltinKeys.INPUT); - String content = null; if (input instanceof Variable) { Variable var = (Variable) input; - Resource res = var.getPredicateResource(graph); - Layer0 L0 = Layer0.getInstance(graph); - String description = graph.getPossibleRelatedValue2(res, L0.HasDescription); - return description; + Resource res = var.getPossiblePredicateResource(graph); + if (res != null) { + Layer0 L0 = Layer0.getInstance(graph); + return graph.getPossibleRelatedValue2(res, L0.HasDescription); + } } else if (input instanceof Resource) { Resource res = (Resource) input; - Layer0 L0 = Layer0.getInstance(graph); - String description = graph.getPossibleRelatedValue2(res, L0.HasDescription); - return description; + return graph.getPossibleRelatedValue2(res, L0.HasDescription); } - return content; + return null; } @Override - public boolean shouldCreateToolTip(ReadGraph graph , NodeContext context, Map auxiliary) throws DatabaseException { + public boolean shouldCreateToolTip(ReadGraph graph, NodeContext context, Map auxiliary) throws DatabaseException { String content = getToolTipContent(graph, context); if (content == null || content.isEmpty()) return false; diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java index 07d385235..188917994 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/ForEachObjectContextProcedure.java @@ -32,8 +32,8 @@ public final class ForEachObjectContextProcedure implements AsyncContextMulti } @Override - public void finished(AsyncReadGraph graph) { - user.finished(graph); + public void finished(AsyncReadGraph graph, C context) { + user.finished(graph, context); } @Override diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java index 9ec12047c..4162f9163 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/DependenciesRelation.java @@ -145,7 +145,7 @@ public class DependenciesRelation extends UnsupportedRelation implements Generic } @Override - public void finished(AsyncReadGraph graph) { + public void finished(AsyncReadGraph graph, Resource parent) { } @Override diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java index d910f13ff..a2e64868f 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ConsistsOfProcess.java @@ -2,6 +2,7 @@ package org.simantics.db.layer0.util; import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -17,22 +18,25 @@ import org.simantics.db.procedure.AsyncContextMultiProcedure; import org.simantics.db.procedure.Procedure; import org.simantics.db.service.DirectQuerySupport; import org.simantics.layer0.Layer0; +import org.simantics.utils.datastructures.Pair; class ConsistsOfProcess { final List result; + final Set childrenWithNoName; final AsyncContextMultiProcedure structure; final AsyncContextMultiProcedure names; - public static List walk(ReadGraph graph, ResourceMap status, Collection resources, Set exclusions, boolean ignoreVirtual) throws DatabaseException { + public static Pair,Set> walk(ReadGraph graph, ResourceMap status, Collection resources, Set exclusions, boolean ignoreVirtual) throws DatabaseException { ConsistsOfProcess process = new ConsistsOfProcess(graph, status, resources, exclusions, ignoreVirtual); - return process.result; + return Pair.make(process.result, process.childrenWithNoName); } static class InternalEntry { public InternalEntry parent; public Resource resource; public String name; + public boolean valid = true; InternalEntry(InternalEntry parent, Resource resource, String name) { this.parent = parent; this.resource = resource; @@ -46,7 +50,7 @@ class ConsistsOfProcess { final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class); result = new ArrayList(); - + childrenWithNoName = new HashSet<>(); names = dqs.compileForEachObject(graph, L0.HasName, new AsyncContextMultiProcedure() { @Override @@ -58,8 +62,16 @@ class ConsistsOfProcess { graph.forPossibleValue(nameResource, new Procedure() { @Override - public void execute(String result) { - entry.name = result; + public void execute(String name) { + if(!entry.valid) return; + + if(name == null) { + entry.valid = false; + } else if (entry.name != null) { + entry.valid = false; + } else { + entry.name = name; + } } @Override @@ -76,9 +88,19 @@ class ConsistsOfProcess { } @Override - public void finished(AsyncReadGraph graph) { + public void finished(AsyncReadGraph graph, InternalEntry entry) { + if(entry.valid) { + if(entry.name != null) { + result.add(entry); + } else { + // This one did not have a name - not a valid internal + childrenWithNoName.add(entry.resource); + } + } else { + // Something wrong has happened. Do not treat as valid internal + childrenWithNoName.add(entry.resource); + } } - }); structure = dqs.compileForEachObject(graph, L0.ConsistsOf, new AsyncContextMultiProcedure() { @@ -90,16 +112,14 @@ class ConsistsOfProcess { if(!ignoreVirtual || child.isPersistent()) { InternalEntry entry = new InternalEntry(parent, child, null); - if(result.add(entry)) { - dqs.forEachObjectCompiled(graph, child, entry, structure); - dqs.forEachObjectCompiled(graph, child, entry, names); - } + dqs.forEachObjectCompiled(graph, child, entry, structure); + dqs.forEachObjectCompiled(graph, child, entry, names); } } @Override - public void finished(AsyncReadGraph graph) { + public void finished(AsyncReadGraph graph, InternalEntry parent) { } @Override diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/DomainProcessor3.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/DomainProcessor3.java index bd67680db..7a0a5f06b 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/DomainProcessor3.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/DomainProcessor3.java @@ -34,6 +34,7 @@ import org.simantics.db.service.TransferableGraphSupport; import org.simantics.graph.db.TransferableGraphSource; import org.simantics.layer0.Layer0; import org.simantics.scl.runtime.function.Function1; +import org.simantics.utils.datastructures.Pair; import gnu.trove.list.array.TIntArrayList; import gnu.trove.map.hash.TIntIntHashMap; @@ -504,7 +505,8 @@ public class DomainProcessor3 { this.datatypeBinding = Bindings.getBindingUnchecked(Datatype.class); this.datatypeSerializer = graph.getService(Databoard.class).getSerializerUnchecked(this.datatypeBinding); - state.internalEntries = ConsistsOfProcess.walk(graph, status, fringe, exclusions, ignoreVirtual); + Pair,Set> pair = ConsistsOfProcess.walk(graph, status, fringe, exclusions, ignoreVirtual); + state.internalEntries = pair.first; for(InternalEntry entry : state.internalEntries) { Resource r = entry.resource; @@ -518,6 +520,12 @@ public class DomainProcessor3 { } } + for(Resource unnamedChild : pair.second) { + if (status.put(unnamedChild, ExtentStatus.INTERNAL) == null) { + fringe.add(unnamedChild); + } + } + if (state.monitor.isCanceled()) throw new CancelTransactionException(); diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSource.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSource.java index f0a0893eb..1d3cf61f5 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSource.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/ModelTransferableGraphSource.java @@ -416,8 +416,12 @@ public class ModelTransferableGraphSource implements TransferableGraphSource { if(state.internalEntries != null) { for(InternalEntry ie : state.internalEntries) { - if(ie.parent != null && ie.name != null) { - procedure.execute(resolveInternal(graph, support, ie, internalMap)); + if(ie.parent != null) { + if(ie.name != null) { + procedure.execute(resolveInternal(graph, support, ie, internalMap)); + } else { + // In this case there is a child that has no HasName => this should be treated as a blank + } } else { throw new DatabaseException("Invalid internal entry " + ie); } diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Subgraphs.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Subgraphs.java index c7e697e62..518efc882 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Subgraphs.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/Subgraphs.java @@ -991,7 +991,8 @@ public class Subgraphs { * � All o are internal * � All stm are included */ - List entries = ConsistsOfProcess.walk(graph, null, fringe, exclusions, true); + Pair,Set> pair = ConsistsOfProcess.walk(graph, null, fringe, exclusions, true); + List entries = pair.first; for(InternalEntry entry : entries) { Resource r = entry.resource; if (status.put(r, ExtentStatus.INTERNAL) == null) { @@ -1003,6 +1004,12 @@ public class Subgraphs { } } + for(Resource unnamedChild : pair.second) { + if (status.put(unnamedChild, ExtentStatus.INTERNAL) == null) { + fringe.add(unnamedChild); + } + } + /* * This loop resolves the transitive closure of all p < IsRelatedTo such that p does not contain the SharedRange tag. * Such resources are guaranteed to be internal. diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/TGRepresentationUtils.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/TGRepresentationUtils.java index ffa399743..0bd71af86 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/TGRepresentationUtils.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/util/TGRepresentationUtils.java @@ -14,6 +14,7 @@ package org.simantics.db.layer0.util; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Set; import org.simantics.datatypes.literal.GUID; import org.simantics.db.ReadGraph; @@ -26,6 +27,7 @@ import org.simantics.db.layer0.util.ConsistsOfProcess.InternalEntry; import org.simantics.db.layer0.util.DomainProcessor3.ExclusionDecision; import org.simantics.layer0.Layer0; import org.simantics.scl.runtime.function.Function1; +import org.simantics.utils.datastructures.Pair; /** * @author Antti Villberg @@ -63,7 +65,8 @@ public class TGRepresentationUtils { return new GUIDExclusionFunction(graph); // The root is OK - check everything beneath - List entries = ConsistsOfProcess.walk(graph, null, Collections.singleton(r), Collections.emptySet(), true); + Pair,Set> pair = ConsistsOfProcess.walk(graph, null, Collections.singleton(r), Collections.emptySet(), true); + List entries = pair.first; for(InternalEntry entry : entries) { if(findByIdentifier(graph, targetRoot, entry.resource)) return new GUIDExclusionFunction(graph); diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java index ea1c779fa..1d3563fc1 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/QuerySupportImpl.java @@ -306,7 +306,7 @@ public class QuerySupportImpl implements QuerySupport { } } - procedure.finished(graph); + procedure.finished(graph, context); // graph.dec(); return; diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java index 69450de7c..c0ead5d07 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/IntHash.java @@ -304,7 +304,7 @@ public class IntHash extends IntHashTrait { } - procedure.finished(graph); + procedure.finished(graph, context); // graph.dec(); assert(size == count); diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java index 42ca6b018..da3b7903e 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ObjectTable.java @@ -167,7 +167,7 @@ public final class ObjectTable extends Table { if (ClusterTraits.statementIndexIsDirect(objectIndex)) { int key = modifier.execute(objectIndex); procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), key)); - procedure.finished(graph); + procedure.finished(graph, context); // graph.dec(); return; } diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java index 23d15dcfd..90519a36c 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceElementSmall.java @@ -477,7 +477,7 @@ public final class ResourceElementSmall { if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) { int completeRef = getCompleteObjectRef(table, index); if (0 == completeRef) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // no objects for given complete type } @@ -496,19 +496,19 @@ public final class ResourceElementSmall { } else { // One complete type element. CompleteRef is resource reference. ClusterI.CompleteTypeEnum rCompleteType = ResourceElementSmall.getCompleteType(table, index); if (pCompleteType != rCompleteType) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // Complete predicate does not match. } procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), modifier.execute(completeRef))); } - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished } short p1 = getStm1Predicate(table, index); if (0 == p1) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished, no statements } @@ -525,7 +525,7 @@ public final class ResourceElementSmall { } short p2 = getStm2Predicate(table, index); if (0 == p2 || pRef != p2) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished, one statements } @@ -539,7 +539,7 @@ public final class ResourceElementSmall { // return true; // loop broken by procedure // return false; // loop finished procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), modifier.execute(o2))); - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); } diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java index 84090af41..e997b7318 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/ResourceTable.java @@ -514,7 +514,7 @@ final class ResourceElement { if (ClusterI.CompleteTypeEnum.NotComplete != pCompleteType) { int completeRef = getCompleteObjectRef(table, index); if (0 == completeRef) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // no objects for given complete type } @@ -543,14 +543,14 @@ final class ResourceElement { ForeachObject t = new ForeachObject(); // CompleteRef is complete object set index. ct.foreachComplete(completeRef, t, null, support, modifier); - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished } // one complete type element ClusterI.CompleteTypeEnum completeType = ClusterTraits.completeReferenceGetType(completeRef); if (pCompleteType != completeType) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; } @@ -562,7 +562,7 @@ final class ResourceElement { int externalRef = ClusterTraits.createForeignReference(clusterIndex, resourceIndex); procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), modifier.execute(externalRef))); } - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished } @@ -570,7 +570,7 @@ final class ResourceElement { long l = table[i]; int p1 = (int) (l >>> 32); if (0 == p1) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished, no statements } @@ -588,13 +588,13 @@ final class ResourceElement { long l2 = table[++i]; int p2 = (int) (l2 >>> 32); if (pRef != p2) { - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); return; // loop finished, one statements } int o2 = (int)l2; procedure.execute(graph, context, new ResourceImpl(graph.getResourceSupport(), modifier.execute(o2))); - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); } diff --git a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java index df5920c47..2c57f3627 100644 --- a/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java +++ b/bundles/org.simantics.db.procore/src/org/simantics/db/procore/cluster/TableIntArraySet.java @@ -184,7 +184,7 @@ final class TableIntArraySet { } - procedure.finished(graph); + procedure.finished(graph, context); // graph.state.dec(0); } diff --git a/bundles/org.simantics.db/src/org/simantics/db/procedure/AsyncContextMultiProcedure.java b/bundles/org.simantics.db/src/org/simantics/db/procedure/AsyncContextMultiProcedure.java index 875ee37ab..c393d32da 100644 --- a/bundles/org.simantics.db/src/org/simantics/db/procedure/AsyncContextMultiProcedure.java +++ b/bundles/org.simantics.db/src/org/simantics/db/procedure/AsyncContextMultiProcedure.java @@ -43,7 +43,7 @@ public interface AsyncContextMultiProcedure { * * @param graph asynchronous graph access */ - void finished(AsyncReadGraph graph); + void finished(AsyncReadGraph graph, Context context); /** * If an error occurs in the processing of the database request that diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/representation/PrettyPrintTG.java b/bundles/org.simantics.graph/src/org/simantics/graph/representation/PrettyPrintTG.java index 2d4171e1c..cb06d6add 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/representation/PrettyPrintTG.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/representation/PrettyPrintTG.java @@ -11,7 +11,6 @@ import java.nio.file.Paths; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -64,6 +63,8 @@ public class PrettyPrintTG { private boolean ignoreIdentifiers; + private TransferableGraphQueries query; + static class ResourceInfo { final boolean hasURI; String name; @@ -104,43 +105,51 @@ public class PrettyPrintTG { } } - public PrettyPrintTG(StringBuilder b, boolean ignoreIdentifiers) throws NoSuchAlgorithmException { + public PrettyPrintTG(TransferableGraph1 tg, StringBuilder b, boolean ignoreIdentifiers) throws NoSuchAlgorithmException { output = b; m = MessageDigest.getInstance("SHA-256"); this.ignoreIdentifiers = ignoreIdentifiers; + + this.query = new TransferableGraphQueries(tg); } - public PrettyPrintTG() throws NoSuchAlgorithmException { - this(new StringBuilder(), false); + public PrettyPrintTG(TransferableGraph1 tg) throws NoSuchAlgorithmException { + this(tg, new StringBuilder(), false); } TreeMap orderedInfos = new TreeMap<>(); TIntObjectHashMap infos = new TIntObjectHashMap<>(); - String tgNodeName(String name) { + private static String tgNodeName(String name) { if (name.contains(" ")) return "\"" + name + "\""; else return name; } - ResourceInfo recurseURI(TransferableGraph1 graph, Identity parent, String parentName, int parentId) { - String name = parentName + "." + tgNodeName(TransferableGraphUtils.getName(parent)); - ResourceInfo info = new ResourceInfo(true, name, parent.resource, parentId); - orderedInfos.put(name, info); - // infos.put(parent.resource, info); - for (Identity child : TransferableGraphUtils.getChildren(graph, parent)) { - recurseURI(graph, child, name, info.resource); - } + private ResourceInfo recurseURI(Map infos, Identity identity, String parentName, int parentId) { + String name = parentName + "." + tgNodeName(TransferableGraphUtils.getName(identity)); + int identityResource = identity.resource; + ResourceInfo info = new ResourceInfo(true, name, identityResource, parentId); + infos.put(name, info); + for (Identity child : query.getChildren(identity)) + recurseURI(infos, child, name, identityResource); return info; } - private TreeMap> sortByPredicateUniqueStatements(TransferableGraph1 graph, int resource) { + /** + * Sorts statements by predicateURI in natural order + * + * @param graph + * @param resource + * @return + */ + private TreeMap> sortByPredicateUniqueStatements(int resource) { TreeMap> results = new TreeMap<>(); - TIntArrayList statements = TransferableGraphUtils.getStatements(graph, resource); + TIntArrayList statements = query.getStatements(resource); for (int i = 0; i < statements.size(); i += 2) { int predicate = statements.get(i); - String predicateURI = TransferableGraphUtils.getURI(graph, predicate); + String predicateURI = query.getURI(predicate); TreeSet objects = results.get(predicateURI); if (objects == null) { objects = new TreeSet<>(); @@ -151,32 +160,32 @@ public class PrettyPrintTG { return results; } - void discoverBlank(TransferableGraph1 graph, int resource, TIntArrayList todo) throws Exception { + void discoverBlank(int resource, TIntArrayList todo) throws Exception { // TIntArrayList statements = // TransferableGraphUtils.getStatements(graph, resource); // for(int i=0;i objects : sortByPredicateUniqueStatements(graph, resource).values()) { + for (TreeSet objects : sortByPredicateUniqueStatements(resource).values()) { for (int object : objects) { // int object = statements.get(i+1); - Identity objectId = TransferableGraphUtils.getIdentity(graph, object); + Identity objectId = query.getIdentity(object); if (objectId != null) { if (objectId.definition instanceof External) continue; } - Value value = TransferableGraphUtils.findValue(graph, object); + Value value = query.findValue(object); if (value != null) { infos.put(object, new ResourceInfo(false, printValue(value), object, resource)); - continue; - } - ResourceInfo existing = infos.get(object); - if (existing == null) { - - existing = new ResourceInfo(false, "blank" + blankCounter++, object, resource); - - // System.out.println("created blank" + blankCounter + " - // with object " + object + " resource " + resource); - infos.put(object, existing); - todo.add(object); + } else { + ResourceInfo existing = infos.get(object); + if (existing == null) { + + existing = new ResourceInfo(false, "blank" + blankCounter++, object, resource); + + // System.out.println("created blank" + blankCounter + " + // with object " + object + " resource " + resource); + infos.put(object, existing); + todo.add(object); + } } } } @@ -188,10 +197,10 @@ public class PrettyPrintTG { return new BigInteger(1, m.digest()).toString(16); } - void discoverOwners(TransferableGraph1 graph, ResourceInfo info) { + void discoverOwners(ResourceInfo info) { log("Discovering owners for {}", info); int resource = info.resource; - TIntArrayList statements = TransferableGraphUtils.getStatements(graph, resource); + TIntArrayList statements = query.getStatements(resource); for (int i = 0; i < statements.size(); i += 2) { int predicate = statements.get(i); int object = statements.get(i + 1); @@ -201,7 +210,7 @@ public class PrettyPrintTG { // Check if predicate is inverse, this just resolves all // predicates to be inverse with ending "Inverse".. - String predicateUri = rewritePredicateURI(graph, predicate); + String predicateUri = rewritePredicateURI(predicate); if (!predicateUri.endsWith("Inverse") && !predicateUri.endsWith("Of")) { existing.ownedResourcesWithPredicates.put(resource, predicate); // if (predicateUri.endsWith("Of")) { @@ -241,7 +250,7 @@ public class PrettyPrintTG { } } - public static String getExternalURI(TransferableGraph1 tg, External ext) { + public String getExternalURI(External ext) { String name = ext.name; if (name.contains(" ")) name = name.replace(" ", "_").replaceAll("@", "_");// name = "\"" + @@ -249,9 +258,9 @@ public class PrettyPrintTG { int parentId = ext.parent; // if(parentId == 0) return ext.name; // else { - Identity id = TransferableGraphUtils.getIdentity(tg, parentId); + Identity id = query.getIdentity(parentId); if (id.definition instanceof External) { - return getExternalURI(tg, (External) id.definition) + "/" + name; + return getExternalURI((External) id.definition) + "/" + name; } else if (id.definition instanceof Root) { Root root = (Root) id.definition; return "http:/" + root.name + "/" + name; @@ -261,20 +270,20 @@ public class PrettyPrintTG { // } } - public static String getExternalURI(TransferableGraph1 tg, int resource) { - Identity id = TransferableGraphUtils.getIdentity(tg, resource); + public String getExternalURI(int resource) { + Identity id = query.getIdentity(resource); if (id == null) return null; if (id.definition instanceof External) { External ext = (External) id.definition; - return getExternalURI(tg, ext); + return getExternalURI(ext); } return null; } - String rewritePredicateURI(TransferableGraph1 graph, int predicate) { + String rewritePredicateURI(int predicate) { - String uri = getExternalURI(graph, predicate); + String uri = getExternalURI(predicate); if (uri == null) { ResourceInfo info = infos.get(predicate); if (info != null) @@ -301,7 +310,7 @@ public class PrettyPrintTG { output.append(" "); } - String printBlank(TransferableGraph1 graph, String predicateURI2, ResourceInfo info, int indent) { + String printBlank(String predicateURI2, ResourceInfo info, int indent) { if (info.hasURI) return null; @@ -328,7 +337,7 @@ public class PrettyPrintTG { if (info.ownedResourcesWithPredicates.isEmpty()) { if (DEBUG) System.out.print("printBlank"); - String uri = printURI(graph, info, false, indent, false); + String uri = printURI(info, false, indent, false); if (uri != null) output.append(uri); } @@ -354,14 +363,14 @@ public class PrettyPrintTG { return ((predicate & 0xffffffffL) << 32) | (object & 0xffffffffL); } - private void addInlineStatement(TransferableGraph1 graph, Map> statements, String predicate, + private void addInlineStatement(Map> statements, String predicate, ResourceInfo objectInfo, int indent) { Set objects = statements.get(predicate); if (objects == null) { objects = new TreeSet<>(); statements.put(predicate, objects); } - String uri = printURI(graph, objectInfo, false, indent + 1, true); + String uri = printURI(objectInfo, false, indent + 1, true); if (uri != null) { // TODO: this is not the right place to remove trailing newline uri = uri.endsWith("\n") ? uri.substring(0, uri.length() - 2) : uri; @@ -382,7 +391,7 @@ public class PrettyPrintTG { objects.add(object); } - String printURI(TransferableGraph1 graph, ResourceInfo info, boolean requireURI, int indent, boolean inline) { + String printURI(ResourceInfo info, boolean requireURI, int indent, boolean inline) { if (requireURI && !info.hasURI) return null; @@ -393,8 +402,7 @@ public class PrettyPrintTG { return null; Map> statements = new TreeMap<>(); - Identity consistsOf = TransferableGraphUtils.findExternal(graph, - "http://www.simantics.org/Layer0-1.1/ConsistsOf"); + Identity consistsOf = query.findExternalByURI("http://www.simantics.org/Layer0-1.1/ConsistsOf"); // Identity partOf = TransferableGraphUtils.findExternal(graph, // "http://www.simantics.org/Layer0-1.1/PartOf"); TLongHashSet processed = new TLongHashSet(); @@ -410,9 +418,9 @@ public class PrettyPrintTG { processed.add(stmId); } - TreeMap predicateURIs = new TreeMap<>(); + TreeMap> predicateURIs = new TreeMap<>(); - TIntArrayList rawStatements = TransferableGraphUtils.getStatements(graph, info.resource); + TIntArrayList rawStatements = query.getStatements(info.resource); if (DEBUG) System.out.println( "rawStatements size for " + info.name + " : " + rawStatements.size() + " " + rawStatements); @@ -442,32 +450,38 @@ public class PrettyPrintTG { // indent++; // } } - String predicateURI = rewritePredicateURI(graph, predicate); - predicateURIs.put(predicateURI, object); + String predicateURI = rewritePredicateURI(predicate); + List objects = predicateURIs.get(predicateURI); + if (objects == null) { + objects = new ArrayList<>(); + predicateURIs.put(predicateURI, objects); + } + objects.add(object); } - for (Entry entry : predicateURIs.entrySet()) { + for (Entry> entry : predicateURIs.entrySet()) { String predicateURI = entry.getKey(); - int object = entry.getValue(); - - ResourceInfo objectInfo = infos.get(object); - if (objectInfo == null) { - String objectURI = rewritePredicateURI(graph, object); - if (DEBUG) - System.out.println(" adding statement " + predicateURI + " " + objectURI); - addStatement(statements, predicateURI, objectURI); - } else if (objectInfo.ownedBy.size() == 1 && objectInfo.ownedBy.contains(info)) { - // inline printing with _ - if (DEBUG) - System.out.println(" adding inline statement " + predicateURI + " " + objectInfo.name); - addInlineStatement(graph, statements, predicateURI, objectInfo, indent); - } else { - String objectName = objectInfo.name; - if (objectName.startsWith("blank")) { - objectName = getBlankRewrite(objectName); + List objects = entry.getValue(); + for (int object : objects) { + ResourceInfo objectInfo = infos.get(object); + if (objectInfo == null) { + String objectURI = rewritePredicateURI(object); + if (DEBUG) + System.out.println(" adding statement " + predicateURI + " " + objectURI); + addStatement(statements, predicateURI, objectURI); + } else if (objectInfo.ownedBy.size() == 1 && objectInfo.ownedBy.contains(info)) { + // inline printing with _ + if (DEBUG) + System.out.println(" adding inline statement " + predicateURI + " " + objectInfo.name); + addInlineStatement(statements, predicateURI, objectInfo, indent); + } else { + String objectName = objectInfo.name; + if (objectName.startsWith("blank")) { + objectName = getBlankRewrite(objectName); + } + if (DEBUG) + System.out.println(" adding statement " + predicateURI + " " + objectName); + addStatement(statements, predicateURI, objectName); } - if (DEBUG) - System.out.println(" adding statement " + predicateURI + " " + objectName); - addStatement(statements, predicateURI, objectName); } } @@ -547,46 +561,37 @@ public class PrettyPrintTG { } } - TreeMap ownedOrdered = new TreeMap<>(); + TreeMap> ownedOrdered = new TreeMap<>(); for (int i = 0; i < info.owned.size(); i += 2) { - String predicateURI = rewritePredicateURI(graph, info.owned.get(i)); - ownedOrdered.put(predicateURI, info.owned.get(i + 1)); + String predicateURI = rewritePredicateURI(info.owned.get(i)); + Set owneds = ownedOrdered.get(predicateURI); + if (owneds == null) { + owneds = new TreeSet<>(); + ownedOrdered.put(predicateURI, owneds); + } + owneds.add(info.owned.get(i + 1)); } if (DEBUG) System.out.println(info.name + " : " + ownedOrdered.keySet()); - for (Entry entry : ownedOrdered.entrySet()) { + for (Entry> entry : ownedOrdered.entrySet()) { String predicateURI = entry.getKey(); - int owned = entry.getValue(); - ResourceInfo ownedInfo = infos.get(owned); - - String blank = printBlank(graph, predicateURI, ownedInfo, indent + 1); - if (blank != null) { - output.append(blank); + Set owneds = entry.getValue(); + for (int owned : owneds) { + ResourceInfo ownedInfo = infos.get(owned); + + String blank = printBlank(predicateURI, ownedInfo, indent + 1); + if (blank != null) { + output.append(blank); + } } } return output.toString(); } - void prettyPrint(Path input, Path output) throws Exception { - - System.out.format("Converting exported shared ontology%n\t" + input.toString() - + "%nto bundle-compatible ontology%n\t" + output.toString()); - try (InputStream is = new BufferedInputStream(Files.newInputStream(input), 128 * 1024)) { - DataInput dis = new DataInputStream(is); - org.simantics.databoard.container.DataContainer container = DataContainers.readFile(dis); - Binding binding = TransferableGraph1.BINDING; - TransferableGraph1 graph = (TransferableGraph1) container.content.getValue(binding); - prettyPrint(graph); - Files.write(output, this.output.toString().getBytes()); - - } - - } - static Map knownOntologies = new HashMap<>(); static { @@ -607,26 +612,26 @@ public class PrettyPrintTG { knownOntologies.put("http://www.semantum.fi/SimupediaWorkbench-1.0", "SIMUPEDIA_WORKBENCH"); } - void prettyPrint(TransferableGraph1 graph) throws Exception { + void prettyPrint() throws Exception { log("Starting prettyPrint for TransferableGraph with {} resources, {} identities, {} statements and {} values", - graph.resourceCount, graph.identities, graph.statements.length, graph.values.length); + query.getGraph().resourceCount, query.getGraph().identities, query.getGraph().statements.length, query.getGraph().values.length); - for (Identity id : graph.identities) { + query.forIdentities(id -> { + int identityResource = id.resource; if (id.definition instanceof Internal) { Internal internal = (Internal) id.definition; - Identity parent = TransferableGraphUtils.getIdentity(graph, internal.parent); - if (parent.definition instanceof External) { + Identity parent = query.getIdentity(internal.parent); + if (parent.definition instanceof External || parent.definition instanceof Root) { log("Resolving internal identity {}", id); String name = "BASE"; - ResourceInfo info = new ResourceInfo(true, name, id.resource, -1); - info.aliasURI = TransferableGraphUtils.getURI(graph, id.resource); + ResourceInfo info = new ResourceInfo(true, name, identityResource, -1); + info.aliasURI = query.getURI(identityResource); info.newResource = true; orderedInfos.put(name, info); // infos.put(id.resource, info); log(" which parent is external {} and has an aliasURI {}", parent, info.aliasURI); - for (Identity child : TransferableGraphUtils.getChildren(graph, id)) { - recurseURI(graph, child, name, info.resource); - } + for (Identity child : query.getChildren(id)) + recurseURI(orderedInfos, child, name, identityResource); log(" and has {} children", infos.size()); } } else if (id.definition instanceof External) { @@ -640,7 +645,7 @@ public class PrettyPrintTG { String prefix = ext.name.substring(0, index); int index2 = ext.name.indexOf('/', index); String ontology = index2 == -1 ? ext.name : ext.name.substring(0, index2); - String uri = TransferableGraphUtils.getURI(graph, id.resource); + String uri = query.getURI(identityResource); log(" which was resolved as URI={} and prefix={}", uri, prefix); @@ -648,7 +653,7 @@ public class PrettyPrintTG { } else if (ext.name.contains("-")) { log("Resolving possible ontology {}", ext); - String uri = TransferableGraphUtils.getURI(graph, id.resource); + String uri = query.getURI(identityResource); Matcher m = versionExtractPattern.matcher(uri); if (m.matches()) { if (!ontologies.containsKey(uri)) { @@ -660,7 +665,8 @@ public class PrettyPrintTG { } } } - } + return true; + }); // Discover other resources log("Discovering other resources.."); @@ -675,10 +681,10 @@ public class PrettyPrintTG { while (!todo.isEmpty()) { int resource = todo.removeAt(todo.size() - 1); - discoverBlank(graph, resource, todo); + discoverBlank(resource, todo); } for (ResourceInfo info : infos.valueCollection()) - discoverOwners(graph, info); + discoverOwners(info); // for(ResourceInfo info : infos.valueCollection()) // fixInstanceOf(graph, info); @@ -697,12 +703,15 @@ public class PrettyPrintTG { @Override public boolean execute(int owner, int predicate) { + ResourceInfo ownerInfo = infos.get(owner); ownerInfo.owned.add(predicate); ownerInfo.owned.add(info.resource); return false; } }); + } else { + System.err.println("Here we are with " + info); } } @@ -717,21 +726,18 @@ public class PrettyPrintTG { } } - Identity routeGraphConn = TransferableGraphUtils.findExternal(graph, - "http://www.simantics.org/Diagram-2.2/RouteGraphConnection"); - Identity instanceOf = TransferableGraphUtils.findExternal(graph, - "http://www.simantics.org/Layer0-1.1/InstanceOf"); - Identity diagramConnetionToConnection = TransferableGraphUtils.findExternal(graph, - "http://www.simantics.org/Modeling-1.2/DiagramConnectionToConnection"); + Identity routeGraphConn = query.findExternalByURI("http://www.simantics.org/Diagram-2.2/RouteGraphConnection"); + Identity instanceOf = query.findExternalByURI("http://www.simantics.org/Layer0-1.1/InstanceOf"); + Identity diagramConnetionToConnection = query.findExternalByURI("http://www.simantics.org/Modeling-1.2/DiagramConnectionToConnection"); + Identity elemTo = query.findExternalByURI("http://www.simantics.org/Modeling-1.2/ElementToComponent"); for (ResourceInfo infoo : infos.valueCollection()) { - Identity elemTo = TransferableGraphUtils.findExternal(graph, "http://www.simantics.org/Modeling-1.2/ElementToComponent"); if (elemTo != null) { - int elemToComponent = TransferableGraphUtils.getPossibleObject2(graph, infoo.resource, elemTo); + int elemToComponent = query.getPossibleObject(infoo.resource, elemTo); if (elemToComponent != TransferableGraphUtils.NOT_FOUND) { - Identity component = TransferableGraphUtils.getIdentity(graph, elemToComponent); - Identity internal = TransferableGraphUtils.getIdentity(graph, infoo.resource); + Identity component = query.getIdentity(elemToComponent); + Identity internal = query.getIdentity(infoo.resource); if (internal.definition instanceof Internal && component.definition instanceof Internal) { Internal iComponent = (Internal) component.definition; infoo.name = infoo.name.substring(0, infoo.name.lastIndexOf(".") + 1) + iComponent.name; @@ -740,29 +746,29 @@ public class PrettyPrintTG { } if (instanceOf != null) { - int instOf = TransferableGraphUtils.getPossibleObject2(graph, infoo.resource, instanceOf); + int instOf = query.getPossibleObject( infoo.resource, instanceOf); if (instOf != TransferableGraphUtils.NOT_FOUND && routeGraphConn != null) { if (instOf == routeGraphConn.resource) { // Found routegraphconnection, change name // Lets go to configuration - int connection = TransferableGraphUtils.getPossibleObject2(graph, infoo.resource, + int connection = query.getPossibleObject( infoo.resource, diagramConnetionToConnection); if (connection != TransferableGraphUtils.NOT_FOUND) { // Gather all inverse statements to construct unique // name List nameParts = new ArrayList<>(); - TIntArrayList statements = TransferableGraphUtils.getStatements(graph, connection); + TIntArrayList statements = query.getStatements(connection); for (int i = 0; i < statements.size(); i += 2) { int predicate = statements.get(i); - Identity possibleInverse = TransferableGraphUtils.getIdentity(graph, predicate); + Identity possibleInverse = query.getIdentity(predicate); if (possibleInverse != null) { int inverseRelation = TransferableGraphUtils.NOT_FOUND; int parentId = TransferableGraphUtils.NOT_FOUND; if (possibleInverse.definition instanceof Internal) { Internal iPossibleInverse = (Internal) possibleInverse.definition; if (iPossibleInverse.name.equals("Inverse")) { - inverseRelation = TransferableGraphUtils.getPossibleObject2(graph, + inverseRelation = query.getPossibleObject( connection, possibleInverse); parentId = iPossibleInverse.parent; } else { @@ -771,7 +777,7 @@ public class PrettyPrintTG { } else if (possibleInverse.definition instanceof External) { External ePossibleInverse = (External) possibleInverse.definition; if (ePossibleInverse.name.equals("Inverse")) { - inverseRelation = TransferableGraphUtils.getPossibleObject2(graph, + inverseRelation = query.getPossibleObject( connection, possibleInverse); parentId = ePossibleInverse.parent; } else { @@ -782,8 +788,8 @@ public class PrettyPrintTG { } if (inverseRelation != TransferableGraphUtils.NOT_FOUND) { // Ok found something - Identity object = TransferableGraphUtils.getIdentity(graph, inverseRelation); - Identity parent = TransferableGraphUtils.getIdentity(graph, parentId); + Identity object = query.getIdentity(inverseRelation); + Identity parent = query.getIdentity(parentId); String objectName, parentName; if (object.definition instanceof Internal) { objectName = ((Internal) object.definition).name; @@ -818,7 +824,6 @@ public class PrettyPrintTG { infoo.name = infoo.name.substring(0, infoo.name.lastIndexOf(".") + 1) + name; } else { LOGGER.error("Could not find connection for " + infoo + ". Statements of graph below"); - LOGGER.error(Arrays.toString(graph.statements)); LOGGER.error("Subject -> Predicate : " + infoo.resource + " -> " + diagramConnetionToConnection.resource); } @@ -828,7 +833,7 @@ public class PrettyPrintTG { } for (ResourceInfo info : infos.valueCollection()) { if (info.name.startsWith("blank")) { - info.name = "blank" + findHash(graph, info); + info.name = "blank" + findHash(info); } } @@ -839,7 +844,7 @@ public class PrettyPrintTG { for (ResourceInfo info : order.values()) { if (DEBUG) System.out.print("info "); - String uri = printURI(graph, info, true, 0, false); + String uri = printURI(info, true, 0, false); if (uri != null) output.append(uri); } @@ -854,7 +859,7 @@ public class PrettyPrintTG { // These will be printed later rblanks.put(getBlankRewrite(info.name), info); } else { - String uri = printURI(graph, info, false, 0, false); + String uri = printURI(info, false, 0, false); if (uri != null) output.append(uri); } @@ -865,7 +870,7 @@ public class PrettyPrintTG { if (!info.hasURI && info.ownedResourcesWithPredicates.size() != 1) { if (DEBUG) System.out.print("ownedResources "); - String uri = printURI(graph, info, false, 0, false); + String uri = printURI(info, false, 0, false); if (uri != null) output.append(uri); } @@ -886,7 +891,7 @@ public class PrettyPrintTG { } - private String calculateHash(TransferableGraph1 graph, ResourceInfo info) { + private String calculateHash(ResourceInfo info) { StringBuilder statementHash = new StringBuilder(); TreeSet parts = new TreeSet<>(); for (int i = 0; i < info.owned.size(); i += 2) { @@ -895,7 +900,7 @@ public class PrettyPrintTG { // Lets resolve a unique name for this based on the statements this // one has - String predicatee = rewritePredicateURI(graph, predicate); + String predicatee = rewritePredicateURI(predicate); ResourceInfo objInfo = infos.get(object); parts.add(predicatee + "->" + objInfo.name + ";;;"); } @@ -921,14 +926,14 @@ public class PrettyPrintTG { return hash; } - private String findHash(TransferableGraph1 graph, ResourceInfo info) { + private String findHash(ResourceInfo info) { if (info.name.startsWith("blank")) { String hash = hashes.get(info.name); if (hash == null) { String oldName = info.name; if (DEBUG) System.out.print("calculating hash for " + oldName + " "); - hash = calculateHash(graph, info); + hash = calculateHash(info); if (hashes.put(oldName, hash) != null) { System.err.println("!!!!A clash occured for " + info + " with hash " + hash); } @@ -943,19 +948,31 @@ public class PrettyPrintTG { public static String print(TransferableGraph1 tg, boolean ignoreIdentifiers) throws Exception { StringBuilder b = new StringBuilder(); - new PrettyPrintTG(b, ignoreIdentifiers).prettyPrint(tg); + new PrettyPrintTG(tg, b, ignoreIdentifiers).prettyPrint(); return b.toString(); } public static void main(String[] args) throws Exception { if (args.length < 1) { System.out.println("Required arguments: []"); - } else if (args.length < 2) { - Path input = Paths.get(args[0]); - Path output = input.getParent().resolve(input.getName(input.getNameCount() - 1) + ".fixed"); - new PrettyPrintTG().prettyPrint(input, output); + } + Path input; + Path output; + if (args.length < 2) { + input = Paths.get(args[0]); + output = input.getParent().resolve(input.getName(input.getNameCount() - 1) + ".fixed"); } else { - new PrettyPrintTG().prettyPrint(Paths.get(args[0]), Paths.get(args[1])); + input = Paths.get(args[0]); + output = Paths.get(args[1]); + } + System.out.format("Converting exported shared ontology%n\t" + input.toString() + + "%nto bundle-compatible ontology%n\t" + output.toString()); + try (InputStream is = new BufferedInputStream(Files.newInputStream(input), 128 * 1024)) { + DataInput dis = new DataInputStream(is); + org.simantics.databoard.container.DataContainer container = DataContainers.readFile(dis); + Binding binding = TransferableGraph1.BINDING; + TransferableGraph1 graph = (TransferableGraph1) container.content.getValue(binding); + new PrettyPrintTG(graph).prettyPrint(); } } diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphQueries.java b/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphQueries.java new file mode 100644 index 000000000..5d4c1850b --- /dev/null +++ b/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphQueries.java @@ -0,0 +1,205 @@ +package org.simantics.graph.representation; + +import java.util.Comparator; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; + +import gnu.trove.impl.Constants; +import gnu.trove.list.array.TIntArrayList; +import gnu.trove.map.hash.TIntObjectHashMap; +import gnu.trove.map.hash.TObjectIntHashMap; +import gnu.trove.procedure.TObjectProcedure; + +public class TransferableGraphQueries { + + private static final int NOT_FOUND = TransferableGraphUtils.NOT_FOUND; + + private final TransferableGraph1 tg; + + private final TIntObjectHashMap internalIdentities = new TIntObjectHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, NOT_FOUND); + private final TIntObjectHashMap externalIdentities = new TIntObjectHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, NOT_FOUND); + private final TIntObjectHashMap rootIdentities = new TIntObjectHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, NOT_FOUND); + + private final TObjectIntHashMap internalIdentitiesByURI = new TObjectIntHashMap<>(); + private final TObjectIntHashMap externalIdentitiesByURI = new TObjectIntHashMap<>(); + private final TObjectIntHashMap rootIdentitiesByURI = new TObjectIntHashMap<>(); + + private final TIntObjectHashMap statementsCache = new TIntObjectHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, NOT_FOUND); + + public TransferableGraphQueries(TransferableGraph1 graph) { + this.tg = graph; + + // Calculate internals + initializeIdentities(); + } + + private void initializeIdentities() { + for (Identity identity : tg.identities) { + IdentityDefinition definition = identity.definition; + if (definition instanceof Internal) { + Internal internal = (Internal) definition; + internalIdentities.put(identity.resource, identity); + internalIdentitiesByURI.put(getURI(identity), identity.resource); + } else if (definition instanceof External) { + External external = (External) definition; + externalIdentities.put(identity.resource, identity); + externalIdentitiesByURI.put(getURI(identity), identity.resource); + } else if (definition instanceof Root) { + Root root = (Root) definition; + rootIdentities.put(identity.resource, identity); + rootIdentitiesByURI.put(getURI(identity), identity.resource); + } + } + } + + public String getURI(Identity identity) { + IdentityDefinition definition = identity.definition; + if(definition instanceof External) { + External def = (External)definition; + if(def.parent == -1) return "http:/"; + else return getURI(def.parent) + "/" + def.name; + } else if(definition instanceof Root) { + Root def = (Root)definition; + if(def.name.isEmpty()) return "http:/"; + return def.name; + } else if (definition instanceof Internal) { + Internal def = (Internal)definition; + return getURI(def.parent) + "/" + def.name; + } else { + return ""; + } + } + + public String getURI(int id) { + Identity identity = getIdentity(id); + if (identity == null) + return ":"; + return getURI(identity); + } + + private static final Comparator IDENTITY_NAME_COMPARATOR = new Comparator() { + + @Override + public int compare(Identity o1, Identity o2) { + if (o1.definition instanceof Internal && o2.definition instanceof Internal) { + Internal i1 = (Internal) o1.definition; + Internal i2 = (Internal) o2.definition; + return i1.name.compareTo(i2.name); + } else if (o1.definition instanceof External && o2.definition instanceof External) { + External e1 = (External) o1.definition; + External e2 = (External) o2.definition; + return e1.name.compareTo(e2.name); + } else { + throw new IllegalArgumentException(o1 + " " + o2); + } + } + }; + + public Set getChildren(Identity parent) { + TreeSet children = new TreeSet<>(IDENTITY_NAME_COMPARATOR); + internalIdentities.forEachEntry((resource, identity) -> { + Internal internal = (Internal) identity.definition; + if (internal.parent == parent.resource) + children.add(identity); + return true; + }); + + return children; + } + + public Identity findInternalByName(String name) { + int internal = internalIdentitiesByURI.get(name); + if (internal == NOT_FOUND) + return null; + return internalIdentities.get(internal); + } + + private Identity findExternalByName(String name) { + int external = externalIdentitiesByURI.get(name); + if (external == NOT_FOUND) + return null; + return externalIdentities.get(external); + } + + private Identity findExternalByNameAndParent(String name, int parent) { + Identity external = findExternalByName(name); + if (external.resource == parent) + return external; + return null; + } + + public Identity findExternalByURI(String uri) { + int v = externalIdentitiesByURI.get(uri); + if (v == NOT_FOUND) + return null; + return externalIdentities.get(v); + } + + public Identity findRootByName(String name) { + int root = rootIdentitiesByURI.get(name); + if (root == NOT_FOUND) + return null; + return rootIdentities.get(root); + } + + public String getName(Identity identity) { + return TransferableGraphUtils.getName(identity); + } + + public void forIdentities(TObjectProcedure procedure) { + for (Identity identity : tg.identities) { + if (!procedure.execute(identity)) { + break; + } + } + } + + public Identity getIdentity(int resource) { + Identity result = rootIdentities.get(resource); + if (result == null) + result = externalIdentities.get(resource); + if (result == null) + result = internalIdentities.get(resource); + return result; + } + + public Value findValue(int object) { + return TransferableGraphUtils.findValue(tg, object); + } + + public TreeMap> sortByPredicateUniqueStatements(int resource) { + TreeMap> results = new TreeMap<>(); + TIntArrayList statements = getStatements(resource); + for (int i = 0; i < statements.size(); i += 2) { + int predicate = statements.get(i); + String predicateURI = getURI(predicate); + TreeSet objects = results.get(predicateURI); + if (objects == null) { + objects = new TreeSet<>(); + } + objects.add(statements.get(i + 1)); + results.put(predicateURI, objects); + } + return results; + } + + public TIntArrayList getStatements(int resource) { +// System.out.println("getting statements with " + resource); + TIntArrayList statements = statementsCache.get(resource); + if (statements == null) { + statements = TransferableGraphUtils.getStatements(tg, resource); + statementsCache.put(resource, statements); + } + return statements; + } + + public int getPossibleObject(int subject, Identity predicate) { + return TransferableGraphUtils.getPossibleObject2(tg, subject, predicate); + } + + public TransferableGraph1 getGraph() { + return tg; + } + +} diff --git a/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java b/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java index b210d8dd7..10637ad65 100644 --- a/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java +++ b/bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraphUtils.java @@ -16,156 +16,205 @@ import gnu.trove.map.hash.TIntObjectHashMap; public class TransferableGraphUtils { - public static Collection getRoots(TransferableGraph1 tg) { - - ArrayList result = new ArrayList(); - for(Identity id : tg.identities) { - if(id.definition instanceof Root) result.add(id); - } - return result; - - } - - public static Identity findRootWithName(TransferableGraph1 tg, String name) { - - for(Identity id : tg.identities) { - if(id.definition instanceof Root) { - Root ext = (Root)id.definition; - if(ext.name.equals(name)) return id; - } - } - return null; - - } + public static Collection getRoots(TransferableGraph1 tg) { + + ArrayList result = new ArrayList(); + for(Identity id : tg.identities) { + if(id.definition instanceof Root) result.add(id); + } + return result; + + } + + public static Identity findRootWithName(TransferableGraph1 tg, String name) { + + for(Identity id : tg.identities) { + if(id.definition instanceof Root) { + Root ext = (Root)id.definition; + if(ext.name.equals(name)) return id; + } + } + return null; + + } - public static Identity findExternalWithName(TransferableGraph1 tg, String name) { - - for(Identity id : tg.identities) { - if(id.definition instanceof External) { - External ext = (External)id.definition; - if(ext.name.equals(name)) return id; - } - } - return null; - - } + public static Identity findExternalWithName(TransferableGraph1 tg, String name) { + + for(Identity id : tg.identities) { + if(id.definition instanceof External) { + External ext = (External)id.definition; + if(ext.name.equals(name)) return id; + } + } + return null; + + } + + public static Identity findExternalWithNameAndParent(TransferableGraph1 tg, int parent, String name) { + + for(Identity id : tg.identities) { + if(id.definition instanceof External) { + External ext = (External)id.definition; + if(ext.name.equals(name) && ext.parent == parent) return id; + } + } + return null; + + } + + public static Identity findExternal(TransferableGraph1 tg, String uri) { + + Identity identity = findExternalWithName(tg, "http:/"); + if(identity == null) identity = findExternalWithName(tg, ""); + if(identity == null) identity = findRootWithName(tg, ""); + if("http:/".equals(uri)) return identity; + String[] tokens = uri.substring("http://".length()).split("/"); + for(String token : tokens) { + identity = findExternalWithNameAndParent(tg, identity.resource, token); + if (identity == null) { + return null; + } + } + return identity; + + } + + public static Identity getIdentity(TransferableGraph1 tg, int resource) { + for(Identity id : tg.identities) { + if(id.resource == resource) return id; + } + return null; + } + + public static TIntArrayList getStatements(TransferableGraph1 tg, int resource) { + TIntArrayList result = new TIntArrayList(); + for(int i=0;i getChildren2(TransferableGraph1 tg, Identity parent) { + return getChildren2(tg, parent.resource); + } + + public static Collection getChildren2(TransferableGraph1 tg, int parentResource) { + TreeMap result = new TreeMap<>(); + for (Identity id : tg.identities) { + if (id.definition instanceof Internal) { + Internal internal = (Internal) id.definition; + if (internal.parent == parentResource) + result.put(internal.name, id); + } + } + Identity consistsOf = findExternal(tg, "http://www.simantics.org/Layer0-1.1/ConsistsOf"); + Identity hasName = findExternal(tg, "http://www.simantics.org/Layer0-1.1/HasName"); + for (int i = 0; i < tg.statements.length; i += 4) { + if (tg.statements[i] == parentResource) { + if (tg.statements[i + 1] == consistsOf.resource) { + Identity identity = getIdentity(tg, tg.statements[i + 3]); + if (identity != null) { + if (identity.definition instanceof Internal) { + Internal internal = (Internal) identity.definition; + result.put(internal.name, identity); + } + } else { + int possibleNameResource = getPossibleObject2(tg, tg.statements[i + 3], hasName); + if (possibleNameResource != NOT_FOUND) { + Value value = findValue(tg, possibleNameResource); + if (value != null) { + try { + String name = (String) value.value.getValue(Bindings.STRING); + result.put(name, new Identity(tg.statements[i + 3], new Internal(tg.statements[i], name))); + } catch (AdaptException e) { + e.printStackTrace(); + } + } + } + } + } + } + } + return result.values(); + } - public static Identity findExternalWithNameAndParent(TransferableGraph1 tg, int parent, String name) { - - for(Identity id : tg.identities) { - if(id.definition instanceof External) { - External ext = (External)id.definition; - if(ext.name.equals(name) && ext.parent == parent) return id; - } - } - return null; - - } - - public static Identity findExternal(TransferableGraph1 tg, String uri) { - - Identity identity = findExternalWithName(tg, "http:/"); - if(identity == null) identity = findExternalWithName(tg, ""); - if(identity == null) identity = findRootWithName(tg, ""); - if("http:/".equals(uri)) return identity; - String[] tokens = uri.substring("http://".length()).split("/"); - for(String token : tokens) { - identity = findExternalWithNameAndParent(tg, identity.resource, token); - if (identity == null) { - return null; - } - } - return identity; - - } - - public static Identity getIdentity(TransferableGraph1 tg, int resource) { - for(Identity id : tg.identities) { - if(id.resource == resource) return id; - } - return null; - } - - public static TIntArrayList getStatements(TransferableGraph1 tg, int resource) { - TIntArrayList result = new TIntArrayList(); - for(int i=0;i getChildren(TransferableGraph1 tg, Identity parent) { - TreeMap result = new TreeMap<>(); - for(Identity id : tg.identities) { - if(id.definition instanceof Internal) { - Internal internal = (Internal)id.definition; - if(internal.parent == parent.resource) result.put(internal.name, id); - } - } - Identity consistsOf = findExternal(tg, "http://www.simantics.org/Layer0-1.1/ConsistsOf"); - Identity hasName = findExternal(tg, "http://www.simantics.org/Layer0-1.1/HasName"); - for(int i=0;i getChildren(TransferableGraph1 tg, Identity parent) { + TreeMap result = new TreeMap<>(); + for(Identity id : tg.identities) { + if(id.definition instanceof Internal) { + Internal internal = (Internal)id.definition; + if(internal.parent == parent.resource) result.put(internal.name, id); + } + } + Identity consistsOf = findExternal(tg, "http://www.simantics.org/Layer0-1.1/ConsistsOf"); + Identity hasName = findExternal(tg, "http://www.simantics.org/Layer0-1.1/HasName"); + for(int i=0;i getNames(TransferableGraph1 tg, Collection ids) { - Map result = new HashMap(); - for(Identity id : ids) { - if(id.definition instanceof Internal) { - Internal internal = (Internal)id.definition; - result.put(id, internal.name); - } - } - return result; - } + public static Map getNames(TransferableGraph1 tg, Collection ids) { + Map result = new HashMap(); + for(Identity id : ids) { + if(id.definition instanceof Internal) { + Internal internal = (Internal)id.definition; + result.put(id, internal.name); + } + } + return result; + } - public static String getName(TransferableGraph1 tg, Identity id) { - return getName(id); - } + public static String getName(TransferableGraph1 tg, Identity id) { + return getName(id); + } - public static String getName(Identity id) { - if(id.definition instanceof Internal) { - Internal internal = (Internal)id.definition; - return internal.name; - } else if(id.definition instanceof External) { - External external = (External)id.definition; - return external.name; - } else if(id.definition instanceof Root) { - Root root = (Root)id.definition; - return root.name; - } else { - Optional optional = (Optional)id.definition; - return optional.name; - } - } + public static String getName(Identity id) { + if(id.definition instanceof Internal) { + Internal internal = (Internal)id.definition; + return internal.name; + } else if(id.definition instanceof External) { + External external = (External)id.definition; + return external.name; + } else if(id.definition instanceof Root) { + Root root = (Root)id.definition; + return root.name; + } else { + Optional optional = (Optional)id.definition; + return optional.name; + } + } - public static String getRootType(Identity id) { - if(id.definition instanceof Root) { - Root root = (Root)id.definition; - return root.type; - } else { - throw new IllegalArgumentException("Expected root, got " + id); - } - } + public static String getRootType(Identity id) { + if(id.definition instanceof Root) { + Root root = (Root)id.definition; + return root.type; + } else { + throw new IllegalArgumentException("Expected root, got " + id); + } + } - public static Value findValue(TransferableGraph1 tg, int subject) { - for(Value v : tg.values) { - if(v.resource == subject) return v; - } - return null; - } - - public static String getURI(TransferableGraph1 tg, int id) { - return getURI(tg.resourceCount, tg.identities, id); - } - - public static String getURI(int resourceCount, Identity[] identities, int id) { - for(Identity identity : identities) { - if(identity.resource == id) { - IdentityDefinition definition = identity.definition; - if(definition instanceof External) { - External def = (External)definition; - if(def.parent == -1) return "http:/"; - else return getURI(resourceCount, identities, def.parent) + "/" + def.name; - } else if(definition instanceof Root) { - Root def = (Root)definition; - if(def.name.isEmpty()) return "http:/"; - return def.name; - } else if (definition instanceof Internal) { - Internal def = (Internal)definition; - return getURI(resourceCount, identities, def.parent) + "/" + def.name; - } else { - return ""; - } - } - } - return ":"; - } + public static Value findValue(TransferableGraph1 tg, int subject) { + for(Value v : tg.values) { + if(v.resource == subject) return v; + } + return null; + } + + public static String getURI(TransferableGraph1 tg, int id) { + return getURI(tg.identities, id); + } + + public static String getURI(Identity[] identities, int id) { + for(Identity identity : identities) { + if(identity.resource == id) { + IdentityDefinition definition = identity.definition; + if(definition instanceof External) { + External def = (External)definition; + if(def.parent == -1) return "http:/"; + else return getURI(identities, def.parent) + "/" + def.name; + } else if(definition instanceof Root) { + Root def = (Root)definition; + if(def.name.isEmpty()) return "http:/"; + return def.name; + } else if (definition instanceof Internal) { + Internal def = (Internal)definition; + return getURI(identities, def.parent) + "/" + def.name; + } else { + return ""; + } + } + } + return ":"; + } - public static TIntObjectMap mapIdentities(TransferableGraph1 tg) { - return mapIdentities(tg.identities); - } + public static TIntObjectMap mapIdentities(TransferableGraph1 tg) { + return mapIdentities(tg.identities); + } - public static TIntObjectMap mapIdentities(Identity[] identities) { - // Integer.MIN_VALUE cannot be the value of Identity.resource - TIntObjectMap map = new TIntObjectHashMap<>(identities.length, 0.5f, Integer.MIN_VALUE); - for (Identity id : identities) - map.put(id.resource, id); - return map; - } + public static TIntObjectMap mapIdentities(Identity[] identities) { + // Integer.MIN_VALUE cannot be the value of Identity.resource + TIntObjectMap map = new TIntObjectHashMap<>(identities.length, 0.5f, Integer.MIN_VALUE); + for (Identity id : identities) + map.put(id.resource, id); + return map; + } - public static String getURI(int resourceCount, TIntObjectMap identities, int id) { - Identity identity = identities.get(id); - if(identity != null) { - IdentityDefinition definition = identity.definition; - if(definition instanceof External) { - External def = (External)definition; - if(def.parent == -1) return "http:/"; - else return getURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name); - } else if(definition instanceof Root) { - Root def = (Root)definition; - if(def.name.isEmpty()) return "http:/"; - return def.name; - } else if (definition instanceof Internal) { - Internal def = (Internal)definition; - return getURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name); - } else { - return ""; - } - } - return ":"; - } + public static String getURI(int resourceCount, TIntObjectMap identities, int id) { + Identity identity = identities.get(id); + if(identity != null) { + IdentityDefinition definition = identity.definition; + if(definition instanceof External) { + External def = (External)definition; + if(def.parent == -1) return "http:/"; + else return getURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name); + } else if(definition instanceof Root) { + Root def = (Root)definition; + if(def.name.isEmpty()) return "http:/"; + return def.name; + } else if (definition instanceof Internal) { + Internal def = (Internal)definition; + return getURI(resourceCount, identities, def.parent) + "/" + URIStringUtils.escape(def.name); + } else { + return ""; + } + } + return ":"; + } } diff --git a/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph b/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph index 0255339ac..86171a31a 100644 --- a/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph +++ b/bundles/org.simantics.modeling.ontology/graph/ModelingViewpoint.pgraph @@ -420,10 +420,23 @@ MOD.Contributions.Help : VP.ActionContribution VP.ActionContribution.HasCategory VP.EditActionCategory VP.ActionContribution.HasNodeType L0.Entity VP.ActionContribution.HasAction ACTIONS.Help - + +MOD.Contributions.CopyURI : VP.ActionContribution + L0.HasLabel "Copy URI" + VP.ActionContribution.HasImage SILK.clipboard + VP.ActionContribution.HasCategory VP.EditActionCategory + VP.ActionContribution.HasNodeType L0.Entity + VP.ActionContribution.HasNodeType MBC.Variable + VP.ActionContribution.HasAction ACTIONS.CopyURI + VP.ActionContribution.IsVisibleIf _ : VP.AndTest + VP.AndTest.HasTest + _ : VP.InDevelopmentModeTest + _ : VP.HasURITest + // Actions MAC VP.BrowseContext.HasActionContribution MOD.Contributions.Help + VP.BrowseContext.HasActionContribution MOD.Contributions.CopyURI VP.BrowseContext.HasActionContribution _ : VP.ActionContribution L0.HasLabel "Migrate" VP.ActionContribution.HasImage SILK.star @@ -659,6 +672,7 @@ ACTIONS.CompilePGraphs : ACT.Action //ACTIONS.MigrateMasterTypical : ACT.Action ACTIONS.RenameDiagramComponents : ACT.Action ACTIONS.Help : ACT.Action +ACTIONS.CopyURI : ACT.Action ACTIONS.NavigateToSubstructure @MOD.sclAction "navigateToSubstructureAction" diff --git a/bundles/org.simantics.modeling/adapters.xml b/bundles/org.simantics.modeling/adapters.xml index 0e3870c35..b74449f82 100644 --- a/bundles/org.simantics.modeling/adapters.xml +++ b/bundles/org.simantics.modeling/adapters.xml @@ -161,6 +161,8 @@ + diff --git a/bundles/org.simantics.modeling/src/org/simantics/modeling/actions/CopyURI.java b/bundles/org.simantics.modeling/src/org/simantics/modeling/actions/CopyURI.java new file mode 100644 index 000000000..cdb56beea --- /dev/null +++ b/bundles/org.simantics.modeling/src/org/simantics/modeling/actions/CopyURI.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2017 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.actions; + +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.widgets.Display; +import org.simantics.Simantics; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.adapter.ActionFactory; +import org.simantics.db.layer0.request.PossibleURI; +import org.simantics.db.layer0.request.VariableURI; +import org.simantics.db.layer0.variable.Variable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Jani Simomaa + * @since 1.30.0 + */ +public class CopyURI implements ActionFactory { + + private static final Logger LOGGER = LoggerFactory.getLogger(CopyURI.class); + + @Override + public Runnable create(Object target) { + return () -> { + try { + String uri = getPossibleURI(target); + if (uri != null) { + Clipboard cb = new Clipboard(Display.getCurrent()); + cb.setContents(new Object[] { uri }, new Transfer[] { TextTransfer.getInstance() }); + } + } catch (Exception e) { + LOGGER.error("Could not get URI for input {} to copy to clipboard", target, e); + } + }; + } + + private String getPossibleURI(Object input) throws DatabaseException { + if (input instanceof Resource) { + return Simantics.getSession().syncRequest(new PossibleURI((Resource) input)); + } else if (input instanceof Variable) { + return Simantics.getSession().syncRequest(new VariableURI((Variable) input)); + } + return null; + } + +} diff --git a/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph b/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph index a0e60d0b3..bcae4c480 100644 --- a/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph +++ b/bundles/org.simantics.tests.modelled.ui.ontology/graph/TestsUI.pgraph @@ -57,6 +57,8 @@ ACTIONS.NewSTSTest @MOD.sclAction "createSTSTestAction" ACTIONS.RunSTSTest @MOD.sclAction "runSTSTestAction" +ACTIONS.IgnoreSTSTest + @MOD.sclAction "ignoreSTSTestAction" ACTIONS.NewSTSVariable @MOD.sclAction "createSTSVariableAction" @@ -82,6 +84,13 @@ MAC VP.ActionContribution.HasNodeType TESTS.STSSuite VP.ActionContribution.HasNodeType TESTS.STSTest VP.ActionContribution.HasAction ACTIONS.RunSTSTest + VP.BrowseContext.HasActionContribution _ : VP.ActionContribution + L0.HasLabel "Ignore" + VP.ActionContribution.HasImage SILK.control_play + VP.ActionContribution.HasCategory VP.EditActionCategory + VP.ActionContribution.HasNodeType TESTS.STSSuite + VP.ActionContribution.HasNodeType TESTS.STSTest + VP.ActionContribution.HasAction ACTIONS.IgnoreSTSTest VP.BrowseContext.HasActionContribution _ : VP.ActionContribution L0.HasLabel "STS Variable" VP.ActionContribution.HasImage SILK.page_white_edit diff --git a/bundles/org.simantics.tests.modelled.ui/scl/Simantics/TestsUI.scl b/bundles/org.simantics.tests.modelled.ui/scl/Simantics/TestsUI.scl index 53218224a..0b99fe784 100644 --- a/bundles/org.simantics.tests.modelled.ui/scl/Simantics/TestsUI.scl +++ b/bundles/org.simantics.tests.modelled.ui/scl/Simantics/TestsUI.scl @@ -7,6 +7,7 @@ createSTSTestAction res = do importJava "org.simantics.tests.modelled.ui.TestsUIUtils" where runSTSTestAction :: Resource -> () + ignoreSTSTestAction :: [Resource] -> () createSTSSuiteAction :: Resource -> () createSTSSuiteAction res = do diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/TestsUIUtils.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/TestsUIUtils.java index 651ee47df..b24f445e2 100644 --- a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/TestsUIUtils.java +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/TestsUIUtils.java @@ -1,10 +1,16 @@ package org.simantics.tests.modelled.ui; import java.io.IOException; +import java.util.List; import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.simantics.Simantics; +import org.simantics.databoard.Bindings; import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; import org.simantics.db.exception.DatabaseException; +import org.simantics.db.request.Write; +import org.simantics.tests.modelled.ontology.TestsResource; import org.simantics.ui.workbench.e4.E4WorkbenchUtils; public class TestsUIUtils { @@ -20,4 +26,17 @@ public class TestsUIUtils { view.currentTest(test); view.execute(); } + + public static void ignoreSTSTestAction(List tests) throws DatabaseException { + Simantics.getSession().syncRequest(new Write() { + + @Override + public void perform(WriteGraph graph) throws DatabaseException { + TestsResource TESTS = TestsResource.getInstance(graph); + for (Resource test : tests) { + graph.claimLiteral(test, TESTS.ignore, true, Bindings.BOOLEAN); + } + } + }); + } } diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java index 3ce1b0158..78964403f 100644 --- a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java @@ -117,7 +117,7 @@ public class ModelledSTSTest { // // } // // } // return new ModuleCompilationOptions(coverage); -// } + // } // }); SCLReportingHandler handler = (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER); diff --git a/bundles/org.simantics.viewpoint.ontology/graph/ViewpointTests.pgraph b/bundles/org.simantics.viewpoint.ontology/graph/ViewpointTests.pgraph index 1eb13238f..4f297e417 100644 --- a/bundles/org.simantics.viewpoint.ontology/graph/ViewpointTests.pgraph +++ b/bundles/org.simantics.viewpoint.ontology/graph/ViewpointTests.pgraph @@ -35,3 +35,9 @@ VP.InstanceOfTest Simantics R - simantics/r.git
  • FMIL - simantics/fmil.git
  • FMI Studio - members/fmi.git
  • -
  • Simupedia - Members SVN
  • +
  • Simupedia - members/simupedia.git
  • For simplicity, each of these components are versioned accoring to platform versioning, i.e. for Platform SDK 1.26.0 there will be Simantics Desktop 1.26.0, Sysdyn 1.26.0, and so on.


    @@ -478,7 +478,7 @@ refs #yyyy

    Tag release/* branches

    When the release branches are ready for the release, tag them with the tag vx.y.z[.w]:

    git clone ssh://<user>@www.simantics.org:29418/simantics/platform.git
    -cd platform    
    +cd platform
     git checkout release/x.y.z[.w]
     git tag vx.y.z[.w] -m "Simantics x.y.z[.w] simultaneous release"
     git push origin --tags
    @@ -556,15 +556,15 @@ separate Mediawiki installation.

    Disseminate information about the release

    Newsletter template:

    Hello everyone,
    -   
    +
     Simantics release x.y.z[.w] has been released. Head over to
     https://www.simantics.org/redmine/news/<news number>
     for the release news.
    @@ -583,6 +583,9 @@ Insert some general thoughts on the release...
     

    TODO

    +
    • Create a parametrized release train pipeline build in Jenkins that creates all artifacts of a simantics release
      • Desktop, Sysdyn, R, Simupedia, FMIL, FMI Studio
      • @@ -590,12 +593,7 @@ Insert some general thoughts on the release...
        -
      • -

        Incorporate tutorial code in the platform repository as a separate folder to allow platform builds to directly ensure that the tutorial code still builds OK

        -
      • -
      • -

        Start using https://github.com/mbarbero/fr.obeo.releng.targetplatform to generate .target files. .tpd files allow specifying version ranges instead of specific versions.

        -
      • +
      • Incorporate tutorial code in the platform repository as a separate folder to allow platform builds to directly ensure that the tutorial code still builds OK
      diff --git a/releng/doc/release.md b/releng/doc/release.md index 79359efd2..871b1d0aa 100644 --- a/releng/doc/release.md +++ b/releng/doc/release.md @@ -36,7 +36,7 @@ Plug-in components that are part of the release train: * Simantics R - [simantics/r.git](https://www.simantics.org:8088/r/gitweb?p=simantics/r.git;a=summary) * FMIL - [simantics/fmil.git](https://www.simantics.org:8088/r/gitweb?p=simantics/fmil.git;a=summary) * FMI Studio - [members/fmi.git](https://www.simantics.org:8088/r/gitweb?p=members/fmi.git;a=summary) -* Simupedia - [Members SVN](https://www.simantics.org/svn/members/simupedia) +* Simupedia - [members/simupedia.git](https://www.simantics.org:8088/r/gitweb?p=members/simupedia.git;a=summary) For simplicity, each of these components are versioned accoring to platform versioning, i.e. for Platform SDK 1.26.0 there will be Simantics Desktop 1.26.0, Sysdyn 1.26.0, and so on. @@ -246,8 +246,8 @@ separate Mediawiki installation. ## Disseminate information about the release -* [Developer Wiki](http://dev.simantics.org): Update roadmap at http://dev.simantics.org/index.php/Roadmap -* [Redmine](https://www.simantics.org/redmine/): Post news on the developer/user-visible changes here. +* [Developer Wiki](http://dev.simantics.org): Update roadmap at [http://dev.simantics.org/index.php/Roadmap](http://dev.simantics.org/index.php/Roadmap) +* [Redmine](https://www.simantics.org/redmine/): Post news on the developer/user-visible changes here * [simantics.org](https://www.simantics.org): Post news on the release and a link to the redmine post * [Members Wiki](https://www.simantics.org/members/): Update frame plan to reflect the realized dates and link to Redmine news * [mailto:simantics-developers@simantics.org](mailto:simantics-developers@simantics.org) Send "newsletter" to `simantics-developers@simantics.org: @@ -278,11 +278,11 @@ Insert some general thoughts on the release... # TODO -* Create a parametrized release train pipeline build in Jenkins that creates all artifacts of a simantics release - * Desktop, Sysdyn, R, Simupedia, FMIL, FMI Studio +* Start using [https://github.com/mbarbero/fr.obeo.releng.targetplatform](https://github.com/mbarbero/fr.obeo.releng.targetplatform) to generate `.target` files. `.tpd` files allow specifying version ranges instead of specific versions. -* Incorporate tutorial code in the platform repository as a separate folder to allow platform builds to directly ensure that the tutorial code still builds OK +* Create a parametrized release train pipeline build in Jenkins that creates all artifacts of a simantics release + * Desktop, Sysdyn, R, Simupedia, FMIL, FMI Studio -* Start using https://github.com/mbarbero/fr.obeo.releng.targetplatform to generate `.target` files. `.tpd` files allow specifying version ranges instead of specific versions. +* Incorporate tutorial code in the platform repository as a separate folder to allow platform builds to directly ensure that the tutorial code still builds OK \ No newline at end of file