Search in sources :

Example 1 with Urlset

use of nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset in project timbuctoo by HuygensING.

the class RsEndpoint method getResourceList.

@GET
@Path("{ownerId}/{dataSetName}/resourcelist.xml")
@Produces(MediaType.APPLICATION_XML)
public Response getResourceList(@HeaderParam("authorization") String authHeader, @PathParam("ownerId") String owner, @PathParam("dataSetName") String dataSetName) throws IOException {
    User user = getUser(authHeader);
    Optional<Urlset> maybeResourceList = rsDocumentBuilder.getResourceList(user, owner, dataSetName);
    if (maybeResourceList.isPresent()) {
        return Response.ok(maybeResourceList.get()).build();
    } else if (user != null) {
        return Response.status(Response.Status.FORBIDDEN).build();
    } else {
        return Response.status(Response.Status.UNAUTHORIZED).build();
    }
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) Urlset(nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with Urlset

use of nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset in project timbuctoo by HuygensING.

the class RsDocumentBuilder method getCapabilityList.

/**
 * Get the capability list for the dataSet denoted by <code>ownerId</code> and <code>dataSetId</code>.
 * The {@link Optional} is empty if the dataSet is not published and the given <code>user</code> == <code>null</code>
 * or has no read access for the dataSet or the dataSet does not exist.
 *
 * @param user User that requests the list, may be <code>null</code>
 * @param ownerId ownerId
 * @param dataSetId dataSetId
 * @return the capability list for the dataSet denoted by <code>ownerId</code> and <code>dataSetId</code>
 */
public Optional<Urlset> getCapabilityList(@Nullable User user, String ownerId, String dataSetId) {
    Urlset capabilityList = null;
    Optional<DataSet> maybeDataSet = dataSetRepository.getDataSet(user, ownerId, dataSetId);
    if (maybeDataSet.isPresent()) {
        RsMd rsMd = new RsMd(Capability.CAPABILITYLIST.xmlValue);
        capabilityList = new Urlset(rsMd).addLink(new RsLn(REL_UP, rsUriHelper.uriForWellKnownResourceSync()));
        DataSetMetaData dataSetMetaData = maybeDataSet.get().getMetadata();
        String descriptionUrl = rsUriHelper.uriForRsDocument(dataSetMetaData, DESCRIPTION_FILENAME);
        capabilityList.addLink(new RsLn(REL_DESCRIBED_BY, descriptionUrl).withType(DESCRIPTION_TYPE));
        String loc = rsUriHelper.uriForRsDocument(dataSetMetaData, Capability.RESOURCELIST);
        UrlItem item = new UrlItem(loc).withMetadata(new RsMd(Capability.RESOURCELIST.xmlValue));
        capabilityList.addItem(item);
    }
    return Optional.ofNullable(capabilityList);
}
Also used : DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) RsLn(nl.knaw.huygens.timbuctoo.remote.rs.xml.RsLn) Urlset(nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) UrlItem(nl.knaw.huygens.timbuctoo.remote.rs.xml.UrlItem) RsMd(nl.knaw.huygens.timbuctoo.remote.rs.xml.RsMd)

Example 3 with Urlset

use of nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset in project timbuctoo by HuygensING.

the class RsDocumentBuilderTest method emptySourceDescription.

@Test
public void emptySourceDescription() throws Exception {
    when(dataSetRepository.getDataSetsWithReadAccess(null)).thenReturn(Collections.emptyList());
    Urlset sourceDescription = rsDocumentBuilder.getSourceDescription(null);
    String xml = rsBuilder.toXml(sourceDescription, true);
    // System.out.println(xml);
    rsBuilder.setXmlString(xml).build();
    Urlset sd = rsBuilder.getUrlset().get();
    assertThat(sd.getCapability().get(), is(Capability.DESCRIPTION));
    assertThat(sd.getItemList().size(), is(0));
}
Also used : Urlset(nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset) Test(org.junit.Test)

Example 4 with Urlset

use of nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset in project timbuctoo by HuygensING.

the class RsEndpoint method getCapabilityList.

@GET
@Path("{ownerId}/{dataSetName}/capabilitylist.xml")
@Produces(MediaType.APPLICATION_XML)
public Response getCapabilityList(@HeaderParam("authorization") String authHeader, @PathParam("ownerId") String owner, @PathParam("dataSetName") String dataSetName) {
    User user = getUser(authHeader);
    Optional<Urlset> maybeCapabilityList = rsDocumentBuilder.getCapabilityList(user, owner, dataSetName);
    if (maybeCapabilityList.isPresent()) {
        return Response.ok(maybeCapabilityList.get()).build();
    } else if (user != null) {
        return Response.status(Response.Status.FORBIDDEN).build();
    } else {
        return Response.status(Response.Status.UNAUTHORIZED).build();
    }
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) Urlset(nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with Urlset

use of nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset in project timbuctoo by HuygensING.

the class RsDocumentBuilder method getSourceDescription.

/**
 * Get the source description document. If <code>user</code> == <code>null</code> the source description will
 * only have links to capability lists of published dataSets. Otherwise the source description will have
 * links to capability lists of published dataSets and the dataSets for which the user has read access.
 *
 * @param user User that requests the document, may be <code>null</code>
 * @return the source description document.
 */
public Urlset getSourceDescription(@Nullable User user) {
    RsMd rsMd = new RsMd(Capability.DESCRIPTION.xmlValue);
    Urlset sourceDescription = new Urlset(rsMd);
    for (DataSet dataSet : dataSetRepository.getDataSetsWithReadAccess(user)) {
        DataSetMetaData dataSetMetaData = dataSet.getMetadata();
        String loc = rsUriHelper.uriForRsDocument(dataSetMetaData, Capability.CAPABILITYLIST);
        String descriptionUrl = rsUriHelper.uriForRsDocument(dataSetMetaData, DESCRIPTION_FILENAME);
        UrlItem item = new UrlItem(loc).withMetadata(new RsMd(Capability.CAPABILITYLIST.xmlValue)).addLink(new RsLn(REL_DESCRIBED_BY, descriptionUrl).withType(DESCRIPTION_TYPE));
        sourceDescription.addItem(item);
    }
    return sourceDescription;
}
Also used : DataSet(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet) RsLn(nl.knaw.huygens.timbuctoo.remote.rs.xml.RsLn) Urlset(nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset) DataSetMetaData(nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData) UrlItem(nl.knaw.huygens.timbuctoo.remote.rs.xml.UrlItem) RsMd(nl.knaw.huygens.timbuctoo.remote.rs.xml.RsMd)

Aggregations

Urlset (nl.knaw.huygens.timbuctoo.remote.rs.xml.Urlset)10 RsMd (nl.knaw.huygens.timbuctoo.remote.rs.xml.RsMd)5 RsLn (nl.knaw.huygens.timbuctoo.remote.rs.xml.RsLn)4 Test (org.junit.Test)4 UrlItem (nl.knaw.huygens.timbuctoo.remote.rs.xml.UrlItem)3 DataSet (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSet)3 DataSetMetaData (nl.knaw.huygens.timbuctoo.v5.dataset.dto.DataSetMetaData)3 URI (java.net.URI)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Sitemapindex (nl.knaw.huygens.timbuctoo.remote.rs.xml.Sitemapindex)2 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)2 InputStream (java.io.InputStream)1 URISyntaxException (java.net.URISyntaxException)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Capability (nl.knaw.huygens.timbuctoo.remote.rs.xml.Capability)1