From 1c81fbef9ee510fed73b4539b95883822907ef1e Mon Sep 17 00:00:00 2001
From: Thorsten Vitt <thorsten.vitt@uni-wuerzburg.de>
Date: Thu, 26 Sep 2013 15:24:42 +0200
Subject: [PATCH] Don't call listAggregations for non-aggregations (workaround)

---
 .../aggregator/AggregationTreeWalker.java     | 25 ++++++++++++-------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/main/java/info/textgrid/services/aggregator/AggregationTreeWalker.java b/src/main/java/info/textgrid/services/aggregator/AggregationTreeWalker.java
index 8c4f626..90ed64d 100644
--- a/src/main/java/info/textgrid/services/aggregator/AggregationTreeWalker.java
+++ b/src/main/java/info/textgrid/services/aggregator/AggregationTreeWalker.java
@@ -29,14 +29,14 @@ public abstract class AggregationTreeWalker {
 	 * metadata. The specialized walk method's <var>again</var> parameter is
 	 * passed the information whether this object has been already seen before.
 	 * </p>
-	 * 
+	 *
 	 * <p>
 	 * The {@link AggregationTreeWalker} implementation calls
 	 * {@link #walkAggregation(ObjectType, boolean)} if the object's format
 	 * contains "aggregation", otherwise, the object is only added to the
 	 * registry. Clients should extend or override.
 	 * </p>
-	 * 
+	 *
 	 * @param object
 	 *            the metadata of the object to process.
 	 * @param again
@@ -69,7 +69,7 @@ protected boolean walk(final ObjectType object, final boolean again) {
 	/**
 	 * Iterates through the given <var>aggregation</var>'s contents unless it is
 	 * visited <var>again</var>.
-	 * 
+	 *
 	 * <p>
 	 * This method will issue a
 	 * {@linkplain SearchClient#listAggregation(String) TG-search request to
@@ -79,11 +79,11 @@ protected boolean walk(final ObjectType object, final boolean again) {
 	 * request does not return object metadata,
 	 * {@link #walkInaccessibleURI(String)} will be called instead.
 	 * </p>
-	 * 
+	 *
 	 * <p>
 	 * Clients may extend or override if they need special treatment.
 	 * </p>
-	 * 
+	 *
 	 * @param aggregation
 	 *            The metadata of the aggregation to list.
 	 * @param again
@@ -94,11 +94,17 @@ protected void walkAggregation(final ObjectType aggregation,
 			final boolean again) {
 		if (again)
 			return;
-		
+
+		// FIXME walkAggregation is also called for works, but it shouldn't.
+		// This is a workaround, we actually shoud factor out the work handling
+		// in the subclasses ...
+		if (!aggregation.getGeneric().getProvided().getFormat().contains("aggregation"))
+			return;
+
 		if (getRepository() == null)
 			throw new IllegalStateException(
 					"AggregationTreeWalkers must be initialized with a repository before use.");
-		
+
 		final SearchClient searchClient = getSearchClient(isPublic(aggregation));
 		final String id = aggregation.getGeneric().getGenerated()
 				.getTextgridUri().getValue();
@@ -121,6 +127,7 @@ protected void walkAggregation(final ObjectType aggregation,
 
 	}
 
+	/** for logging / debugging purposes */
 	private static String describe(final ObjectType object) {
 		final StringBuilder builder = new StringBuilder();
 		try {
@@ -161,9 +168,9 @@ protected SearchClient getSearchClient(final boolean isPublic) {
 	/**
 	 * Called by {@link #walkAggregation(ObjectType, boolean)} when the
 	 * aggregation contains entries for which there is no metadata included.
-	 * 
+	 *
 	 * The default implementation does nothing, clients may override.
-	 * 
+	 *
 	 * @param textgridUri
 	 *            the URI listed in the aggregation.
 	 */
-- 
GitLab