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();
}
}
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);
}
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));
}
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();
}
}
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;
}
Aggregations