Skip to content
Snippets Groups Projects
Commit 730447bf authored by Thorsten Vitt's avatar Thorsten Vitt
Browse files

Fixed tree building and filename generation

parent bb499f84
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
}
......@@ -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));
}
/**
......
......@@ -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();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment