From 9872ffa2c8aa476434964118e6de68e7fd7c6bae Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Thu, 11 Oct 2018 15:28:13 +0300 Subject: [PATCH] Log an error if there are two resources with the same GUID. Change-Id: I377e9a68eda631efe7e78354cf2d3ee8e3756ce4 --- .../META-INF/MANIFEST.MF | 3 ++- .../structural2/StructuralRVIResolver.java | 20 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/bundles/org.simantics.structural2/META-INF/MANIFEST.MF b/bundles/org.simantics.structural2/META-INF/MANIFEST.MF index ad3c50fac..00ff7f724 100644 --- a/bundles/org.simantics.structural2/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.structural2/META-INF/MANIFEST.MF @@ -10,7 +10,8 @@ Require-Bundle: org.simantics.structural.ontology;bundle-version="1.0.0", org.simantics.issues.common;bundle-version="1.1.0", org.simantics.simulator.variable;bundle-version="1.0.0", org.simantics.scl.osgi;bundle-version="1.0.0", - org.simantics;bundle-version="1.0.0" + org.simantics;bundle-version="1.0.0", + org.slf4j.api;bundle-version="1.7.25" Export-Package: org.simantics.structural2, org.simantics.structural2.modelingRules, org.simantics.structural2.procedural, diff --git a/bundles/org.simantics.structural2/src/org/simantics/structural2/StructuralRVIResolver.java b/bundles/org.simantics.structural2/src/org/simantics/structural2/StructuralRVIResolver.java index 672edfca6..ec6b58361 100644 --- a/bundles/org.simantics.structural2/src/org/simantics/structural2/StructuralRVIResolver.java +++ b/bundles/org.simantics.structural2/src/org/simantics/structural2/StructuralRVIResolver.java @@ -8,6 +8,7 @@ import org.simantics.databoard.binding.Binding; import org.simantics.datatypes.literal.GUID; import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.common.utils.NameUtils; import org.simantics.db.exception.DatabaseException; import org.simantics.db.layer0.adapter.Instances; import org.simantics.db.layer0.exception.MissingVariableException; @@ -21,8 +22,11 @@ import org.simantics.db.layer0.variable.Variables; import org.simantics.layer0.Layer0; import org.simantics.simulation.ontology.SimulationResource; import org.simantics.structural.stubs.StructuralResource2; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class StructuralRVIResolver extends StandardRVIResolver { + private static final Logger LOGGER = LoggerFactory.getLogger(StructuralRVIResolver.class); protected boolean isRVIBase(ReadGraph graph, Variable variable) throws DatabaseException { if (Variables.isContext(graph, variable)) return true; @@ -118,7 +122,21 @@ public class StructuralRVIResolver extends StandardRVIResolver { Instances instances = graph.adapt(Layer0.getInstance(graph).Entity, Instances.class); GUID guid = new GUID(part.mostSignificant, part.leastSignificant); Collection queryResult = instances.find(graph, indexRoot, "GUID:"+guid.indexString()); - if(queryResult.size() != 1) return null; + if(queryResult.size() != 1) { + if(queryResult.size() > 1) { + StringBuilder b = new StringBuilder(); + boolean first = true; + for(Resource r : queryResult) { + if(first) + first = false; + else + b.append(", "); + b.append(NameUtils.getURIOrSafeNameInternal(graph, r)); + } + LOGGER.error("Found {} resources with the same GUID {}: {}.", queryResult.size(), guid, b); + } + return null; + } return getRVIPath(graph, variable, queryResult.iterator().next()); } -- 2.43.2