use of nl.knaw.huygens.timbuctoo.remote.rs.xml.RsRoot in project timbuctoo by HuygensING.
the class LinkExplorer method explore.
@Override
public Result<LinkList> explore(URI uri, ResultIndex index) {
Result<List<String>> stringResult = execute(uri, responseReader);
Result<LinkList> result = stringResult.map(stringListToLinkListConverter);
result.getInvalidUris().addAll(result.getContent().map(LinkList::getInvalidUris).orElse(Collections.emptySet()));
index.add(result);
// All valid uris point to ResourceSync documents (at least they should)
RsExplorer rsExplorer = new RsExplorer(getHttpClient(), rsContext);
for (URI rsUri : result.getContent().orElse(new LinkList()).getValidUris()) {
if (!index.contains(rsUri)) {
Result<RsRoot> child = rsExplorer.explore(rsUri, index);
result.addChild(child);
}
}
return result;
}
use of nl.knaw.huygens.timbuctoo.remote.rs.xml.RsRoot in project timbuctoo by HuygensING.
the class RsExplorer method extractCapability.
private Capability extractCapability(Result<RsRoot> result) {
String xmlString = result.getContent().map(RsRoot::getMetadata).flatMap(RsMd::getCapability).orElse("");
Capability capa = null;
try {
capa = Capability.forString(xmlString);
} catch (IllegalArgumentException e) {
result.addError(new RemoteResourceSyncFrameworkException(String.format("invalid value for capability: '%s'", xmlString)));
}
return capa;
}
use of nl.knaw.huygens.timbuctoo.remote.rs.xml.RsRoot in project timbuctoo by HuygensING.
the class ResultView method init.
private void init(Result<?> result, Interpreter interpreter) {
uri = result.getUri().toString();
ordinal = result.getOrdinal();
statusCode = result.getStatusCode();
contentType = result.getContent().map(o -> o.getClass().getSimpleName()).orElse("(no content)");
Object content = result.getContent().orElse(null);
if (content != null) {
if (content instanceof LinkList) {
LinkList linkList = (LinkList) content;
childCount = linkList.getValidUris().size();
} else if (content instanceof RsRoot) {
RsRoot<?, ?> rsRoot = (RsRoot) content;
childCount = rsRoot.getItemList().size();
Optional<Capability> optionalCapa = rsRoot.getCapability();
if (optionalCapa.isPresent()) {
capability = optionalCapa.get().xmlValue;
}
} else if (content instanceof Description) {
description = new DescriptionView((Result<Description>) result, interpreter);
}
}
if (result.getDescriptionResult().isPresent()) {
describedBy = new ResultView(result.getDescriptionResult().get(), interpreter);
}
errorList = result.getErrors().stream().map(throwable -> new ErrorView(throwable, interpreter)).collect(Collectors.toList());
invalidUris = result.getInvalidUris();
}
use of nl.knaw.huygens.timbuctoo.remote.rs.xml.RsRoot in project timbuctoo by HuygensING.
the class RsExplorerTest method verifyFindSourceDescription.
private void verifyFindSourceDescription(String path) {
getMockServer().when(HttpRequest.request().withMethod("GET").withPath(path), Times.exactly(1)).respond(HttpResponse.response().withStatusCode(200).withBody(createValidSourceDescription()));
URI uri = composeUri(path);
RsExplorer explorer = new RsExplorer(getHttpclient(), getRsContext());
ResultIndex index = new ResultIndex();
Result<RsRoot> result = explorer.explore(uri, index);
result.getErrors().forEach(Throwable::printStackTrace);
assertThat(result.getUri(), equalTo(uri));
assertThat(result.getStatusCode(), equalTo(200));
assertThat(result.getErrors().isEmpty(), is(true));
assertThat(result.getContent().isPresent(), is(true));
assertThat(result.getContent().map(RsRoot::getMetadata).flatMap(RsMd::getCapability).orElse("invalid"), equalTo("description"));
// index should contain the describedBy uri of the source description:
assertThat(index.contains(composeUri("/info_about_source.xml")), is(true));
// result should contain the describedByResult:
Result<Description> descriptionResult = result.getDescriptionResult().get();
assertThat(descriptionResult.getUri(), equalTo(composeUri("/info_about_source.xml")));
assertThat(descriptionResult.getContent().isPresent(), is(false));
assertThat(descriptionResult.getStatusCode(), equalTo(404));
}
use of nl.knaw.huygens.timbuctoo.remote.rs.xml.RsRoot in project timbuctoo by HuygensING.
the class RsExplorerTest method findWrongParentDocument.
@Test
public void findWrongParentDocument() throws Exception {
String path1 = "/foo/resourcedump.xml";
String path2 = "/bla/resourcedump.xml";
getMockServer().when(HttpRequest.request().withMethod("GET").withPath(path1), Times.exactly(1)).respond(HttpResponse.response().withStatusCode(200).withBody(createValidResourceDump(path2)));
getMockServer().when(HttpRequest.request().withMethod("GET").withPath(path2), Times.exactly(1)).respond(HttpResponse.response().withStatusCode(200).withBody(createValidResourceDump("/bar/whatever.xml")));
URI uri = composeUri(path1);
RsExplorer explorer = new RsExplorer(getHttpclient(), getRsContext());
ResultIndex index = new ResultIndex();
Result<RsRoot> result = explorer.explore(uri, index);
// result.listErrors().forEach(Throwable::printStackTrace);
assertThat(result.getUri(), equalTo(uri));
assertThat(result.getStatusCode(), equalTo(200));
assertThat(result.getErrors().isEmpty(), is(false));
assertThat(result.getErrors().get(0).getMessage(), containsString("invalid up relation:"));
assertThat(result.getContent().isPresent(), is(true));
assertThat(result.getContent().map(RsRoot::getMetadata).flatMap(RsMd::getCapability).orElse("invalid"), equalTo("resourcedump"));
URI uri2 = composeUri(path2);
Result<RsRoot> parentResult = (Result<RsRoot>) result.getParents().get(uri2);
parentResult.getErrors().forEach(Throwable::printStackTrace);
assertThat(parentResult.getUri(), equalTo(uri2));
assertThat(parentResult.getStatusCode(), equalTo(200));
assertThat(parentResult.getErrors().isEmpty(), is(true));
assertThat(parentResult.getContent().isPresent(), is(true));
assertThat(parentResult.getContent().map(RsRoot::getMetadata).flatMap(RsMd::getCapability).orElse("invalid"), equalTo("resourcedump"));
}
Aggregations