diff --git a/common/plugins/eu.esdihumboldt.hale.common.instance.graph/src/eu/esdihumboldt/hale/common/instance/graph/reference/ReferenceGraph.java b/common/plugins/eu.esdihumboldt.hale.common.instance.graph/src/eu/esdihumboldt/hale/common/instance/graph/reference/ReferenceGraph.java index 4e977381b1..00eee91861 100644 --- a/common/plugins/eu.esdihumboldt.hale.common.instance.graph/src/eu/esdihumboldt/hale/common/instance/graph/reference/ReferenceGraph.java +++ b/common/plugins/eu.esdihumboldt.hale.common.instance.graph/src/eu/esdihumboldt/hale/common/instance/graph/reference/ReferenceGraph.java @@ -27,7 +27,6 @@ import java.util.NoSuchElementException; import java.util.Queue; import java.util.Set; -import java.util.stream.Collectors; import javax.annotation.Nullable; @@ -136,7 +135,7 @@ public InstanceCollection next() { List instances = getNextAtomicPart(); biggestAtom = Math.max(biggestAtom, instances.size()); - if (part.size() + instances.size() > maxObjects) { + if (part.size() > 0 && part.size() + instances.size() > maxObjects) { // add to part candidates for later use nextCandidates.add(instances); if (!verticesLeft()) { @@ -199,7 +198,14 @@ public InstanceCollection next() { */ private List getNextAtomicPart() { // select an arbitrary vertex - Vertex vtx = graph.someVertex(); + Vertex vtx = null; + + if (handleFirst != null) { + vtx = graph.getVertex(handleFirst); + } + if (vtx == null) { + vtx = graph.someVertex(); + } if (vtx != null) { // get all vertices associated with that vertex final Set visited = new LinkedHashSet<>(); @@ -236,22 +242,20 @@ public Boolean compute(LoopBundle loop) { result.add(ref); } else { - Iterable referers = associated.getVertices(Direction.IN); Set ids = new HashSet<>(); - if (referers != null) { - for (Vertex referer : referers) { - Object ident = referer.getId(); - if (ident != null) { - ids.add(ident.toString()); - } + for (Vertex referer : associated.getVertices(Direction.IN)) { + Object ident = referer.getId(); + if (ident != null) { + ids.add(ident.toString()); } } + if (ids.isEmpty()) { log.warn("Encountered referenced object w/o associated instance: " + associated.getId()); } else { - String enumIds = ids.stream().collect(Collectors.joining(", ")); + String enumIds = String.join(", ", ids); log.warn("Encountered referenced object w/o associated instance: " + associated.getId() + " - referenced from " + enumIds); } @@ -294,16 +298,22 @@ public void remove() { private boolean partitioned = false; + private final T handleFirst; + /** * Create a new reference graph from the given instance collection. * * @param inspector the instance inspector to use * @param instances the + * @param handleFirst the ID of the first instance to handle, optional and + * can be null */ - public ReferenceGraph(IdentityReferenceInspector inspector, InstanceCollection instances) { + public ReferenceGraph(IdentityReferenceInspector inspector, InstanceCollection instances, + T handleFirst) { this.graph = new CustomTinkerGraph(); this.inspector = inspector; this.originalCollection = instances; + this.handleFirst = handleFirst; populate(instances); @@ -311,6 +321,14 @@ public ReferenceGraph(IdentityReferenceInspector inspector, InstanceCollectio identifiedVertices.clear(); } + /** + * @param inspector the instance inspector to use + * @param instances the + */ + public ReferenceGraph(IdentityReferenceInspector inspector, InstanceCollection instances) { + this(inspector, instances, null); + } + /** * Populate the graph with the instances from the given collection. * diff --git a/io/plugins/eu.esdihumboldt.hale.io.gml/src/eu/esdihumboldt/hale/io/gml/writer/XPlanGmlInstanceWriter.java b/io/plugins/eu.esdihumboldt.hale.io.gml/src/eu/esdihumboldt/hale/io/gml/writer/XPlanGmlInstanceWriter.java index 66613cdb2b..fd3a0b81e5 100644 --- a/io/plugins/eu.esdihumboldt.hale.io.gml/src/eu/esdihumboldt/hale/io/gml/writer/XPlanGmlInstanceWriter.java +++ b/io/plugins/eu.esdihumboldt.hale.io.gml/src/eu/esdihumboldt/hale/io/gml/writer/XPlanGmlInstanceWriter.java @@ -155,7 +155,7 @@ private void partitionByPlan(ProgressIndicator progress, IOReporter reporter) for (String planId : planIdToInstancesMapping.keySet()) { MultiInstanceCollection mic = new MultiInstanceCollection( Arrays.asList(planIdToInstancesMapping.get(planId), nonPlanInstances)); - ReferenceGraph rg = new ReferenceGraph(new XMLInspector(), mic); + ReferenceGraph rg = new ReferenceGraph(new XMLInspector(), mic, planId); Iterator p = rg.partition(1, reporter); while (p.hasNext()) {