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 b26406dc5a60c8bd9e6095fdc07e3f80de43bbe8..b85e56d95dc6984c4d7ff44cc364e47ddd3cef4b 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(); }