class="org.simantics.browsing.ui.model.tests.FailTest"
constructor="get">
</type>
+ <type uri="http://www.simantics.org/Viewpoint-0.0/HasURITest"
+ class="org.simantics.browsing.ui.model.tests.HasURITest"
+ constructor="get">
+ </type>
+ <type uri="http://www.simantics.org/Viewpoint-0.0/InDevelopmentModeTest"
+ class="org.simantics.browsing.ui.model.tests.InDevelopmentModeTest"
+ constructor="get">
+ </type>
</target>
<target interface="org.simantics.browsing.ui.model.actions.IActionCategory">
--- /dev/null
+/*******************************************************************************
+ * 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;
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * 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();
+ }
+
+}
import org.simantics.layer0.Layer0;
public class DescriptionTooltipRule implements TooltipRule {
-
+
public static final DescriptionTooltipRule INSTANCE = new DescriptionTooltipRule();
-
+
public DescriptionTooltipRule() {
}
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<Object, Object> auxiliary) throws DatabaseException {
+ public boolean shouldCreateToolTip(ReadGraph graph, NodeContext context, Map<Object, Object> auxiliary) throws DatabaseException {
String content = getToolTipContent(graph, context);
if (content == null || content.isEmpty())
return false;
}
@Override
- public void finished(AsyncReadGraph graph) {
- user.finished(graph);
+ public void finished(AsyncReadGraph graph, C context) {
+ user.finished(graph, context);
}
@Override
}
@Override
- public void finished(AsyncReadGraph graph) {
+ public void finished(AsyncReadGraph graph, Resource parent) {
}
@Override
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
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<InternalEntry> result;
+ final Set<Resource> childrenWithNoName;
final AsyncContextMultiProcedure<InternalEntry, Resource> structure;
final AsyncContextMultiProcedure<InternalEntry, Resource> names;
- public static List<InternalEntry> walk(ReadGraph graph, ResourceMap<ExtentStatus> status, Collection<Resource> resources, Set<Resource> exclusions, boolean ignoreVirtual) throws DatabaseException {
+ public static Pair<List<InternalEntry>,Set<Resource>> walk(ReadGraph graph, ResourceMap<ExtentStatus> status, Collection<Resource> resources, Set<Resource> 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;
final DirectQuerySupport dqs = graph.getService(DirectQuerySupport.class);
result = new ArrayList<InternalEntry>();
-
+ childrenWithNoName = new HashSet<>();
names = dqs.compileForEachObject(graph, L0.HasName, new AsyncContextMultiProcedure<InternalEntry, Resource>() {
@Override
graph.forPossibleValue(nameResource, new Procedure<String>() {
@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
}
@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<InternalEntry, Resource>() {
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
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;
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<List<InternalEntry>,Set<Resource>> pair = ConsistsOfProcess.walk(graph, status, fringe, exclusions, ignoreVirtual);
+ state.internalEntries = pair.first;
for(InternalEntry entry : state.internalEntries) {
Resource r = entry.resource;
}
}
+ for(Resource unnamedChild : pair.second) {
+ if (status.put(unnamedChild, ExtentStatus.INTERNAL) == null) {
+ fringe.add(unnamedChild);
+ }
+ }
+
if (state.monitor.isCanceled())
throw new CancelTransactionException();
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);
}
* � All o are internal
* � All stm are included
*/
- List<InternalEntry> entries = ConsistsOfProcess.walk(graph, null, fringe, exclusions, true);
+ Pair<List<InternalEntry>,Set<Resource>> pair = ConsistsOfProcess.walk(graph, null, fringe, exclusions, true);
+ List<InternalEntry> entries = pair.first;
for(InternalEntry entry : entries) {
Resource r = entry.resource;
if (status.put(r, ExtentStatus.INTERNAL) == null) {
}
}
+ 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.
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;
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
return new GUIDExclusionFunction(graph);
// The root is OK - check everything beneath
- List<InternalEntry> entries = ConsistsOfProcess.walk(graph, null, Collections.singleton(r), Collections.emptySet(), true);
+ Pair<List<InternalEntry>,Set<Resource>> pair = ConsistsOfProcess.walk(graph, null, Collections.singleton(r), Collections.emptySet(), true);
+ List<InternalEntry> entries = pair.first;
for(InternalEntry entry : entries) {
if(findByIdentifier(graph, targetRoot, entry.resource))
return new GUIDExclusionFunction(graph);
}
}
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.dec();
return;
}
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.dec();
assert(size == count);
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;
}
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
}
} 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
}
}
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
}
// 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);
}
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
}
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;
}
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
}
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
}
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);
}
}
- procedure.finished(graph);
+ procedure.finished(graph, context);
// graph.state.dec(0);
}
*
* @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
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;
private boolean ignoreIdentifiers;
+ private TransferableGraphQueries query;
+
static class ResourceInfo {
final boolean hasURI;
String name;
}
}
- 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<String, ResourceInfo> orderedInfos = new TreeMap<>();
TIntObjectHashMap<ResourceInfo> 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<String, ResourceInfo> 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<String, TreeSet<Integer>> sortByPredicateUniqueStatements(TransferableGraph1 graph, int resource) {
+ /**
+ * Sorts statements by predicateURI in natural order
+ *
+ * @param graph
+ * @param resource
+ * @return
+ */
+ private TreeMap<String, TreeSet<Integer>> sortByPredicateUniqueStatements(int resource) {
TreeMap<String, TreeSet<Integer>> 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<Integer> objects = results.get(predicateURI);
if (objects == null) {
objects = new TreeSet<>();
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<statements.size();i+=2) {
- for (TreeSet<Integer> objects : sortByPredicateUniqueStatements(graph, resource).values()) {
+ for (TreeSet<Integer> 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);
+ }
}
}
}
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);
// 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")) {
}
}
- 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 = "\"" +
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;
// }
}
- 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)
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;
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);
}
return ((predicate & 0xffffffffL) << 32) | (object & 0xffffffffL);
}
- private void addInlineStatement(TransferableGraph1 graph, Map<String, Set<String>> statements, String predicate,
+ private void addInlineStatement(Map<String, Set<String>> statements, String predicate,
ResourceInfo objectInfo, int indent) {
Set<String> 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;
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;
return null;
Map<String, Set<String>> 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();
processed.add(stmId);
}
- TreeMap<String, Integer> predicateURIs = new TreeMap<>();
+ TreeMap<String, List<Integer>> 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);
// indent++;
// }
}
- String predicateURI = rewritePredicateURI(graph, predicate);
- predicateURIs.put(predicateURI, object);
+ String predicateURI = rewritePredicateURI(predicate);
+ List<Integer> objects = predicateURIs.get(predicateURI);
+ if (objects == null) {
+ objects = new ArrayList<>();
+ predicateURIs.put(predicateURI, objects);
+ }
+ objects.add(object);
}
- for (Entry<String, Integer> entry : predicateURIs.entrySet()) {
+ for (Entry<String, List<Integer>> 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<Integer> 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);
}
}
}
}
- TreeMap<String, Integer> ownedOrdered = new TreeMap<>();
+ TreeMap<String, Set<Integer>> 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<Integer> 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<String, Integer> entry : ownedOrdered.entrySet()) {
+ for (Entry<String, Set<Integer>> 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<Integer> 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<String, String> knownOntologies = new HashMap<>();
static {
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) {
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);
} 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)) {
}
}
}
- }
+ return true;
+ });
// Discover other resources
log("Discovering other resources..");
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);
@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);
}
}
}
}
- 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;
}
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<String> 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 {
} 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 {
}
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;
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);
}
}
for (ResourceInfo info : infos.valueCollection()) {
if (info.name.startsWith("blank")) {
- info.name = "blank" + findHash(graph, info);
+ info.name = "blank" + findHash(info);
}
}
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);
}
// 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);
}
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);
}
}
- private String calculateHash(TransferableGraph1 graph, ResourceInfo info) {
+ private String calculateHash(ResourceInfo info) {
StringBuilder statementHash = new StringBuilder();
TreeSet<String> parts = new TreeSet<>();
for (int i = 0; i < info.owned.size(); i += 2) {
// 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 + ";;;");
}
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);
}
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: <input .sharedOntology file> [<output .tg file>]");
- } 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();
}
}
--- /dev/null
+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<Identity> internalIdentities = new TIntObjectHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, NOT_FOUND);
+ private final TIntObjectHashMap<Identity> externalIdentities = new TIntObjectHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, NOT_FOUND);
+ private final TIntObjectHashMap<Identity> rootIdentities = new TIntObjectHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, NOT_FOUND);
+
+ private final TObjectIntHashMap<String> internalIdentitiesByURI = new TObjectIntHashMap<>();
+ private final TObjectIntHashMap<String> externalIdentitiesByURI = new TObjectIntHashMap<>();
+ private final TObjectIntHashMap<String> rootIdentitiesByURI = new TObjectIntHashMap<>();
+
+ private final TIntObjectHashMap<TIntArrayList> 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 "<internal reference " + id + ">:";
+ return getURI(identity);
+ }
+
+ private static final Comparator<Identity> IDENTITY_NAME_COMPARATOR = new Comparator<Identity>() {
+
+ @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<Identity> getChildren(Identity parent) {
+ TreeSet<Identity> 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<Identity> 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<String, TreeSet<Integer>> sortByPredicateUniqueStatements(int resource) {
+ TreeMap<String, TreeSet<Integer>> 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<Integer> 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;
+ }
+
+}
public class TransferableGraphUtils {
- public static Collection<Identity> getRoots(TransferableGraph1 tg) {
-
- ArrayList<Identity> result = new ArrayList<Identity>();
- 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<Identity> getRoots(TransferableGraph1 tg) {
+
+ ArrayList<Identity> result = new ArrayList<Identity>();
+ 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<tg.statements.length;i+=4) {
+ if(tg.statements[i] == resource) {
+ result.add(tg.statements[i+1]);
+ result.add(tg.statements[i+3]);
+ }
+ }
+ return result;
+ }
+
+ public static Collection<Identity> getChildren2(TransferableGraph1 tg, Identity parent) {
+ return getChildren2(tg, parent.resource);
+ }
+
+ public static Collection<Identity> getChildren2(TransferableGraph1 tg, int parentResource) {
+ TreeMap<String, Identity> 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<tg.statements.length;i+=4) {
- if(tg.statements[i] == resource) {
- result.add(tg.statements[i+1]);
- result.add(tg.statements[i+3]);
- }
- }
- return result;
- }
-
- public static Collection<Identity> getChildren(TransferableGraph1 tg, Identity parent) {
- TreeMap<String,Identity> 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<tg.statements.length;i+=4) {
- if(tg.statements[i] == parent.resource) {
- 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 = getPossibleObject(tg, tg.statements[i+3], hasName);
- if(possibleNameResource != 0) {
- 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 TIntArrayList getObjects(TransferableGraph1 tg, int subject, Identity predicate) {
- TIntArrayList result = new TIntArrayList();
- for(int i=0;i<tg.statements.length;i+=4) {
- if(tg.statements[i] == subject && tg.statements[i+1] == predicate.resource) {
- result.add(tg.statements[i+3]);
- }
- }
- return result;
- }
-
/**
* This implementation is no longer advised to use because it returns 0 as
* NOT_FOUND which is in fact a valid ID for resource in graph
*/
- @Deprecated
- public static int getPossibleObject(TransferableGraph1 tg, int subject, Identity predicate) {
- int result = 0;
- for(int i=0;i<tg.statements.length;i+=4) {
- if(tg.statements[i] == subject && tg.statements[i+1] == predicate.resource) {
- if(result != 0 && tg.statements[i+3] != result) return 0;
- result = tg.statements[i+3];
- }
- }
- return result;
- }
+ @Deprecated
+ public static Collection<Identity> getChildren(TransferableGraph1 tg, Identity parent) {
+ TreeMap<String,Identity> 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<tg.statements.length;i+=4) {
+ if(tg.statements[i] == parent.resource) {
+ 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 = getPossibleObject(tg, tg.statements[i+3], hasName);
+ if(possibleNameResource != 0) {
+ 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 TIntArrayList getObjects(TransferableGraph1 tg, int subject, Identity predicate) {
+ TIntArrayList result = new TIntArrayList();
+ for(int i=0;i<tg.statements.length;i+=4) {
+ if(tg.statements[i] == subject && tg.statements[i+1] == predicate.resource) {
+ result.add(tg.statements[i+3]);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * This implementation is no longer advised to use because it returns 0 as
+ * NOT_FOUND which is in fact a valid ID for resource in graph
+ */
+ @Deprecated
+ public static int getPossibleObject(TransferableGraph1 tg, int subject, Identity predicate) {
+ int result = 0;
+ for(int i=0;i<tg.statements.length;i+=4) {
+ if(tg.statements[i] == subject && tg.statements[i+1] == predicate.resource) {
+ if(result != 0 && tg.statements[i+3] != result) return 0;
+ result = tg.statements[i+3];
+ }
+ }
+ return result;
+ }
- public static final int NOT_FOUND = -2;
+ public static final int NOT_FOUND = -2;
- public static int getPossibleObject2(TransferableGraph1 tg, int subject, Identity predicate) {
- int result = NOT_FOUND;
+ public static int getPossibleObject2(TransferableGraph1 tg, int subject, Identity predicate) {
+ int result = NOT_FOUND;
for(int i=0;i<tg.statements.length;i+=4) {
if(tg.statements[i] == subject && tg.statements[i+1] == predicate.resource) {
if(result != NOT_FOUND && tg.statements[i+3] != result)
}
}
return result;
- }
-
- /**
- * @return 0 for presenting not found which is BAD
- * @see getPossibleObject2
- */
- @Deprecated
- public static int getPossibleObject(TransferableGraph1 tg, Identity subject, String predicate) {
- Identity p = findExternal(tg, predicate);
- if(p == null) return 0;
- return getPossibleObject(tg, subject.resource, p);
- }
-
+ }
+
+ /**
+ * @return 0 for presenting not found which is BAD
+ * @see getPossibleObject2
+ */
+ @Deprecated
+ public static int getPossibleObject(TransferableGraph1 tg, Identity subject, String predicate) {
+ Identity p = findExternal(tg, predicate);
+ if(p == null) return 0;
+ return getPossibleObject(tg, subject.resource, p);
+ }
+
public static int getPossibleObject2(TransferableGraph1 tg, Identity subject, String predicate) {
Identity p = findExternal(tg, predicate);
if (p == null)
return getPossibleObject2(tg, subject.resource, p);
}
- public static Map<Identity, String> getNames(TransferableGraph1 tg, Collection<Identity> ids) {
- Map<Identity, String> result = new HashMap<Identity, String>();
- for(Identity id : ids) {
- if(id.definition instanceof Internal) {
- Internal internal = (Internal)id.definition;
- result.put(id, internal.name);
- }
- }
- return result;
- }
+ public static Map<Identity, String> getNames(TransferableGraph1 tg, Collection<Identity> ids) {
+ Map<Identity, String> result = new HashMap<Identity, String>();
+ 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 "<internal reference " + 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.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 "<internal reference " + id + ">:";
+ }
- public static TIntObjectMap<Identity> mapIdentities(TransferableGraph1 tg) {
- return mapIdentities(tg.identities);
- }
+ public static TIntObjectMap<Identity> mapIdentities(TransferableGraph1 tg) {
+ return mapIdentities(tg.identities);
+ }
- public static TIntObjectMap<Identity> mapIdentities(Identity[] identities) {
- // Integer.MIN_VALUE cannot be the value of Identity.resource
- TIntObjectMap<Identity> map = new TIntObjectHashMap<>(identities.length, 0.5f, Integer.MIN_VALUE);
- for (Identity id : identities)
- map.put(id.resource, id);
- return map;
- }
+ public static TIntObjectMap<Identity> mapIdentities(Identity[] identities) {
+ // Integer.MIN_VALUE cannot be the value of Identity.resource
+ TIntObjectMap<Identity> 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<Identity> 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 "<internal reference " + id + ">:";
- }
+ public static String getURI(int resourceCount, TIntObjectMap<Identity> 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 "<internal reference " + id + ">:";
+ }
}
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
//ACTIONS.MigrateMasterTypical : ACT.Action
ACTIONS.RenameDiagramComponents : ACT.Action
ACTIONS.Help : ACT.Action
+ACTIONS.CopyURI : ACT.Action
ACTIONS.NavigateToSubstructure
@MOD.sclAction "navigateToSubstructureAction"
</type>
<resource uri="http://www.simantics.org/Modeling-0.0/ModelingActionContext/Actions/Help"
class="org.simantics.modeling.actions.Help" />
+ <resource uri="http://www.simantics.org/Modeling-0.0/ModelingActionContext/Actions/CopyURI"
+ class="org.simantics.modeling.actions.CopyURI" />
</target>
<target interface="org.simantics.db.layer0.adapter.DropActionFactory">
--- /dev/null
+/*******************************************************************************
+ * 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;
+ }
+
+}
@MOD.sclAction "createSTSTestAction"
ACTIONS.RunSTSTest
@MOD.sclAction "runSTSTestAction"
+ACTIONS.IgnoreSTSTest
+ @MOD.sclAction "ignoreSTSTestAction"
ACTIONS.NewSTSVariable
@MOD.sclAction "createSTSVariableAction"
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
importJava "org.simantics.tests.modelled.ui.TestsUIUtils" where
runSTSTestAction :: Resource -> <Proc> ()
+ ignoreSTSTestAction :: [Resource] -> <Proc> ()
createSTSSuiteAction :: Resource -> <Proc> ()
createSTSSuiteAction res = do
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 {
view.currentTest(test);
view.execute();
}
+
+ public static void ignoreSTSTestAction(List<Resource> 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);
+ }
+ }
+ });
+ }
}
// // }
// // }
// return new ModuleCompilationOptions(coverage);
-// }
+ // }
// });
SCLReportingHandler handler = (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER);
VP.FailTest <T VP.Test
L0.HasDescription "A test that is compatible with all content types and always fails, i.e. returns false."
+
+VP.HasURITest <T VP.Test
+ L0.HasDescription "A test that checks the Resource or Variable given as input has a proper URI."
+
+VP.InDevelopmentModeTest <T VP.Test
+ L0.HasDescription "A test that directly invokes org.eclipse.runtime.core.Platform.inDevelopmentMode()."
<li>Simantics R - <a href="https://www.simantics.org:8088/r/gitweb?p=simantics/r.git;a=summary">simantics/r.git</a></li>\r
<li>FMIL - <a href="https://www.simantics.org:8088/r/gitweb?p=simantics/fmil.git;a=summary">simantics/fmil.git</a></li>\r
<li>FMI Studio - <a href="https://www.simantics.org:8088/r/gitweb?p=members/fmi.git;a=summary">members/fmi.git</a></li>\r
-<li>Simupedia - <a href="https://www.simantics.org/svn/members/simupedia">Members SVN</a></li>\r
+<li>Simupedia - <a href="https://www.simantics.org:8088/r/gitweb?p=members/simupedia.git;a=summary">members/simupedia.git</a></li>\r
</ul>\r
<p>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.</p>\r
<hr />\r
<h2>Tag release/* branches</h2>\r
<p>When the release branches are ready for the release, tag them with the tag <code>vx.y.z[.w]</code>:</p>\r
<pre><code>git clone ssh://<user>@www.simantics.org:29418/simantics/platform.git\r
-cd platform \r
+cd platform\r
git checkout release/x.y.z[.w]\r
git tag vx.y.z[.w] -m "Simantics x.y.z[.w] simultaneous release"\r
git push origin --tags\r
</ul>\r
<h2>Disseminate information about the release</h2>\r
<ul>\r
-<li><a href="http://dev.simantics.org">Developer Wiki</a>: Update roadmap at http://dev.simantics.org/index.php/Roadmap</li>\r
-<li><a href="https://www.simantics.org/redmine/">Redmine</a>: Post news on the developer/user-visible changes here.</li>\r
+<li><a href="http://dev.simantics.org">Developer Wiki</a>: Update roadmap at <a href="http://dev.simantics.org/index.php/Roadmap">http://dev.simantics.org/index.php/Roadmap</a></li>\r
+<li><a href="https://www.simantics.org/redmine/">Redmine</a>: Post news on the developer/user-visible changes here</li>\r
<li><a href="https://www.simantics.org">simantics.org</a>: Post news on the release and a link to the redmine post</li>\r
<li><a href="https://www.simantics.org/members/">Members Wiki</a>: Update frame plan to reflect the realized dates and link to Redmine news</li>\r
<li><a href="mailto:simantics-developers@simantics.org">mailto:simantics-developers@simantics.org</a> Send "newsletter" to `simantics-developers@simantics.org:</li>\r
</ul>\r
<p><strong>Newsletter template:</strong></p>\r
<pre><code>Hello everyone,\r
- \r
+\r
Simantics release x.y.z[.w] has been released. Head over to\r
https://www.simantics.org/redmine/news/<news number>\r
for the release news.\r
<hr />\r
<h1>TODO</h1>\r
<ul>\r
+<li>Start using <a href="https://github.com/mbarbero/fr.obeo.releng.targetplatform">https://github.com/mbarbero/fr.obeo.releng.targetplatform</a> to generate <code>.target</code> files. <code>.tpd</code> files allow specifying version ranges instead of specific versions.</li>\r
+</ul>\r
+<ul>\r
<li>Create a parametrized release train pipeline build in Jenkins that creates all artifacts of a simantics release\r
<ul>\r
<li>Desktop, Sysdyn, R, Simupedia, FMIL, FMI Studio</li>\r
</li>\r
</ul>\r
<ul>\r
-<li>\r
-<p>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</p>\r
-</li>\r
-<li>\r
-<p>Start using https://github.com/mbarbero/fr.obeo.releng.targetplatform to generate <code>.target</code> files. <code>.tpd</code> files allow specifying version ranges instead of specific versions.</p>\r
-</li>\r
+<li>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</li>\r
</ul>\r
\r
</body>\r
* 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.
## 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:
# 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