From ca27f93ef6b927333979c3cb7bf8c3a5afa4c877 Mon Sep 17 00:00:00 2001
From: Thorsten Vitt <thorsten.vitt@uni-wuerzburg.de>
Date: Tue, 18 Jun 2013 11:16:57 +0000
Subject: [PATCH] ZIP: Don't forget the work objects.

If an edition is associated with a work object that it doesn't
aggregate, the work object is manually added to the aggregation tree.

git-svn-id: https://develop.sub.uni-goettingen.de/repos/textgrid/trunk/services/aggregator@14164 7c539038-3410-0410-b1ec-0f2a7bf1c452
---
 .../tree/AggregationTreeFactory.java          | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java b/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java
index b26406d..b85e56d 100644
--- a/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java
+++ b/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java
@@ -1,13 +1,19 @@
 package info.textgrid.services.aggregator.tree;
 
 import info.textgrid.namespaces.metadata.core._2010.ObjectType;
+import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.AuthFault;
+import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.IoFault;
+import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.MetadataParseFault;
+import info.textgrid.namespaces.middleware.tgcrud.services.tgcrudservice.ObjectNotFoundFault;
 import info.textgrid.services.aggregator.AggregationTreeWalker;
 import info.textgrid.services.aggregator.ITextGridRep;
 
 import java.util.Deque;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import com.google.common.collect.Lists;
+import com.ibm.icu.text.MessageFormat;
 
 public class AggregationTreeFactory extends AggregationTreeWalker {
 
@@ -39,6 +45,48 @@ protected void walkAggregation(final ObjectType aggregation,
 			final boolean again) {
 		stack.push(new Aggregation(aggregation, stack.peek()));
 		super.walkAggregation(aggregation, again);
+
+		if (aggregation.getEdition() != null
+				&& aggregation.getEdition().getIsEditionOf() != null) {
+			final String workURI = aggregation.getEdition().getIsEditionOf();
+			if (!seen.contains(workURI)) {
+				try {
+					final ObjectType workObject = getRepository()
+							.getCRUDService()
+							.readMetadata(getSid(), "", workURI).getObject();
+					walkAggregation(workObject, again);
+				} catch (final MetadataParseFault e) {
+					logger.log(
+							Level.WARNING,
+							MessageFormat
+									.format("Failed to retrieve work metadata for URI {0}, edition {1}",
+											workURI, stack.peek()), e);
+					walkInaccessibleURI(workURI);
+				} catch (final ObjectNotFoundFault e) {
+					logger.log(
+							Level.WARNING,
+							MessageFormat
+									.format("Failed to retrieve work metadata for URI {0}, edition {1}",
+											workURI, stack.peek()), e);
+					walkInaccessibleURI(workURI);
+				} catch (final IoFault e) {
+					logger.log(
+							Level.WARNING,
+							MessageFormat
+									.format("Failed to retrieve work metadata for URI {0}, edition {1}",
+											workURI, stack.peek()), e);
+					walkInaccessibleURI(workURI);
+				} catch (final AuthFault e) {
+					logger.log(
+							Level.WARNING,
+							MessageFormat
+									.format("Failed to retrieve work metadata for URI {0}, edition {1}",
+											workURI, stack.peek()), e);
+					walkInaccessibleURI(workURI);
+				}
+			}
+		}
+
 		this.root = stack.pop();
 	}
 
-- 
GitLab