From 730447bf3382015255a35c25a76897d300e3cf38 Mon Sep 17 00:00:00 2001 From: Thorsten Vitt <thorsten.vitt@uni-wuerzburg.de> Date: Mon, 27 May 2013 12:01:37 +0000 Subject: [PATCH] Fixed tree building and filename generation git-svn-id: https://develop.sub.uni-goettingen.de/repos/textgrid/trunk/services/aggregator@14096 7c539038-3410-0410-b1ec-0f2a7bf1c452 --- .../services/aggregator/tree/Aggregation.java | 7 ++++- .../aggregator/tree/AggregationEntry.java | 29 ++++++++++--------- .../tree/AggregationTreeFactory.java | 21 +++++++++----- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/main/java/info/textgrid/services/aggregator/tree/Aggregation.java b/src/main/java/info/textgrid/services/aggregator/tree/Aggregation.java index 153f072..5458c08 100644 --- a/src/main/java/info/textgrid/services/aggregator/tree/Aggregation.java +++ b/src/main/java/info/textgrid/services/aggregator/tree/Aggregation.java @@ -5,6 +5,7 @@ import java.util.List; import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; public class Aggregation extends AggregationEntry { @@ -21,12 +22,16 @@ public Aggregation(final ObjectType metadata, final Aggregation parent) { @Override public String toString() { - return super.toString() + ": [" + Joiner.on(", ").join(children) + "]"; + return super.toString() + ": [" + (children == null? "!!!" : Joiner.on(", ").join(children)) + "]"; } protected Aggregation add(final AggregationEntry child) { children.add(child); return this; } + + public List<AggregationEntry> getChildren() { + return ImmutableList.copyOf(children); + } } diff --git a/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java b/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java index 881cdc7..d545aa1 100644 --- a/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java +++ b/src/main/java/info/textgrid/services/aggregator/tree/AggregationEntry.java @@ -5,6 +5,7 @@ import java.io.File; import java.net.URI; import java.text.MessageFormat; +import java.util.logging.Logger; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; @@ -13,29 +14,31 @@ * Represents an entry in an aggregation. */ public class AggregationEntry { + + private static Logger logger = Logger.getLogger("info.textgrid.services.aggregator.tree"); private final ObjectType metadata; - protected final ImmutableList<Aggregation> path; + protected final Optional<Aggregation> parent; protected AggregationEntry(final ObjectType metadata) { - this.metadata = metadata; - path = ImmutableList.of(); + this(metadata, null); } protected AggregationEntry(final ObjectType metadata, final Aggregation parent) { - path = ImmutableList.<Aggregation> builder().addAll(parent.path) - .add(parent).build(); this.metadata = metadata; - parent.add(this); + this.parent = Optional.fromNullable(parent); + if (this.parent.isPresent()) { + parent.add(this); + logger.info(MessageFormat.format("{0} has parent {1}", this, parent)); + } else { + logger.info(MessageFormat.format("{0} has no parent", this)); + } } protected Optional<Aggregation> getParent() { - if (path.isEmpty()) - return Optional.absent(); - else - return Optional.of(path.get(path.size() - 1)); + return parent; } public ObjectType getMetadata() { @@ -53,10 +56,10 @@ protected String getSimpleFileName(final boolean withExtension) { getMetadata().getGeneric().getGenerated().getTextgridUri() .getValue()).getSchemeSpecificPart(); if (withExtension) - return baseName; - else return FileExtensionMap.getInstance().addExtension(baseName, getMetadata().getGeneric().getProvided().getFormat()); + else + return baseName; } /** @@ -73,7 +76,7 @@ protected File getFileName(final boolean withExtension) { return new File(parent.get().getFileName(false), getSimpleFileName(withExtension)); else - return new File(getSimpleFileName(false)); + return new File(getSimpleFileName(withExtension)); } /** 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 0a43829..3db55f0 100644 --- a/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java +++ b/src/main/java/info/textgrid/services/aggregator/tree/AggregationTreeFactory.java @@ -2,20 +2,26 @@ import info.textgrid.namespaces.metadata.core._2010.ObjectType; import info.textgrid.services.aggregator.AggregationTreeWalker; +import info.textgrid.services.aggregator.ITextGridRep; +import java.text.MessageFormat; import java.util.Deque; +import java.util.logging.Logger; import com.google.common.collect.Lists; public class AggregationTreeFactory extends AggregationTreeWalker { private final Deque<Aggregation> stack = Lists.newLinkedList(); - private final Aggregation root; + private Aggregation root; + private static Logger logger = Logger.getLogger("info.textgrid.services.aggregator.tree"); - protected AggregationTreeFactory(final ObjectType root) { + protected AggregationTreeFactory(final ObjectType root, ITextGridRep repository, String sid) { super(); - this.root = new Aggregation(root); - stack.push(this.root); + this.setRepository(repository); + this.setSid(sid); +// this.root = new Aggregation(root); +// stack.push(this.root); walkAggregation(root, false); } @@ -34,15 +40,16 @@ protected void walkAggregation(final ObjectType aggregation, final boolean again) { stack.push(new Aggregation(aggregation, stack.peek())); super.walkAggregation(aggregation, again); - stack.pop(); + logger.info(MessageFormat.format("Walking aggregation {0}", stack.peek())); + this.root = stack.pop(); } protected Aggregation getRoot() { return root; } - public static Aggregation create(final ObjectType root) { - return new AggregationTreeFactory(root).getRoot(); + public static Aggregation create(final ObjectType root, ITextGridRep repository, String sid) { + return new AggregationTreeFactory(root, repository, sid).getRoot(); } } -- GitLab