Skip to content
Browse files

Merge branch 'stage' of github.com:atlasapi/atlas into stage

  • Loading branch information...
2 parents c715274 + 55bc79c commit 7ebb8b4f729b9ddae322054ab87014727c469041 @sbtourist sbtourist committed May 21, 2012
Showing with 13 additions and 14 deletions.
  1. +13 −14 src/main/java/org/atlasapi/remotesite/five/FiveUpdater.java
View
27 src/main/java/org/atlasapi/remotesite/five/FiveUpdater.java
@@ -5,7 +5,9 @@
import java.util.concurrent.TimeUnit;
import nu.xom.Builder;
+import nu.xom.Document;
import nu.xom.Element;
+import nu.xom.Elements;
import nu.xom.NodeFactory;
import nu.xom.Nodes;
@@ -37,7 +39,7 @@
private final FiveBrandProcessor processor;
private final Timestamper timestamper = new SystemClock();
- private final Builder parser = new Builder(new ShowProcessingNodeFactory());
+ private final Builder parser = new Builder();
private SimpleHttpClient streamHttpClient;
public FiveUpdater(ContentWriter contentWriter, AdapterLog log) {
@@ -55,11 +57,11 @@ private SimpleHttpClient buildFetcher(final AdapterLog log) {
.build();
}
- private final HttpResponseTransformer<Void> TRANSFORMER = new HttpResponseTransformer<Void>() {
+ private final HttpResponseTransformer<Document> TRANSFORMER = new HttpResponseTransformer<Document>() {
@Override
- public Void transform(HttpResponsePrologue response, InputStream in) throws HttpException, IOException {
+ public Document transform(HttpResponsePrologue response, InputStream in) throws HttpException, IOException {
try {
- parser.build(in);
+ return parser.build(in);
} catch (Exception e) {
log.record(new AdapterLogEntry(Severity.ERROR).withCause(e).withSource(getClass()).withDescription("Exception when processing shows document"));
Throwables.propagate(e);
@@ -74,7 +76,7 @@ public void runTask() {
Timestamp start = timestamper.timestamp();
log.record(new AdapterLogEntry(Severity.INFO).withDescription("Five update started from " + BASE_API_URL).withSource(getClass()));
- streamHttpClient.get(new SimpleHttpRequest<Void>(BASE_API_URL + "/shows", TRANSFORMER));
+ process(streamHttpClient.get(new SimpleHttpRequest<Document>(BASE_API_URL + "/shows", TRANSFORMER)));
Timestamp end = timestamper.timestamp();
log.record(new AdapterLogEntry(Severity.INFO).withDescription("Five update completed in " + start.durationTo(end).getStandardSeconds() + " seconds").withSource(getClass()));
@@ -85,12 +87,13 @@ public void runTask() {
}
}
- private class ShowProcessingNodeFactory extends NodeFactory {
-
+ private void process(Document document) {
int processed = 0, failed = 0;
- @Override
- public Nodes finishMakingElement(Element element) {
+ Elements elements = document.getRootElement().getFirstChildElement("shows").getChildElements();
+ for(int i = 0; i < elements.size(); i++) {
+ Element element = elements.get(i);
+
if (element.getLocalName().equalsIgnoreCase("show")) {
try {
processor.processShow(element);
@@ -100,12 +103,8 @@ public Nodes finishMakingElement(Element element) {
failed++;
}
reportStatus(String.format("%s processed. %s failed", ++processed, failed));
- } else if (element.getLocalName().equalsIgnoreCase("shows")){
- processed = 0;
- failed = 0;
}
-
- return super.finishMakingElement(element);
}
}
+
}

0 comments on commit 7ebb8b4

Please sign in to comment.
Something went wrong with that request. Please try again.