Search in sources :

Example 1 with RsRoot

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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) RsRoot(nl.knaw.huygens.timbuctoo.remote.rs.xml.RsRoot) URI(java.net.URI)

Example 2 with RsRoot

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;
}
Also used : Capability(nl.knaw.huygens.timbuctoo.remote.rs.xml.Capability) RsRoot(nl.knaw.huygens.timbuctoo.remote.rs.xml.RsRoot)

Example 3 with RsRoot

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();
}
Also used : Description(nl.knaw.huygens.timbuctoo.remote.rs.discover.Description) Optional(java.util.Optional) RsRoot(nl.knaw.huygens.timbuctoo.remote.rs.xml.RsRoot) LinkList(nl.knaw.huygens.timbuctoo.remote.rs.discover.LinkList) Result(nl.knaw.huygens.timbuctoo.remote.rs.discover.Result)

Example 4 with RsRoot

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));
}
Also used : RsRoot(nl.knaw.huygens.timbuctoo.remote.rs.xml.RsRoot) URI(java.net.URI) RsMd(nl.knaw.huygens.timbuctoo.remote.rs.xml.RsMd)

Example 5 with RsRoot

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"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) RsRoot(nl.knaw.huygens.timbuctoo.remote.rs.xml.RsRoot) URI(java.net.URI) RsMd(nl.knaw.huygens.timbuctoo.remote.rs.xml.RsMd) Test(org.junit.Test)

Aggregations

RsRoot (nl.knaw.huygens.timbuctoo.remote.rs.xml.RsRoot)9 URI (java.net.URI)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Test (org.junit.Test)4 RsMd (nl.knaw.huygens.timbuctoo.remote.rs.xml.RsMd)3 List (java.util.List)2 Optional (java.util.Optional)2 Capability (nl.knaw.huygens.timbuctoo.remote.rs.xml.Capability)2 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 JAXBException (javax.xml.bind.JAXBException)1 Description (nl.knaw.huygens.timbuctoo.remote.rs.discover.Description)1 LinkList (nl.knaw.huygens.timbuctoo.remote.rs.discover.LinkList)1 Result (nl.knaw.huygens.timbuctoo.remote.rs.discover.Result)1 ResourceSyncContext (nl.knaw.huygens.timbuctoo.remote.rs.xml.ResourceSyncContext)1 RsBuilder (nl.knaw.huygens.timbuctoo.remote.rs.xml.RsBuilder)1 RsItem (nl.knaw.huygens.timbuctoo.remote.rs.xml.RsItem)1