Skip to content

Commit

Permalink
Merge pull request #52 from TAMULib/store-allow-disallow-in-manifest-id
Browse files Browse the repository at this point in the history
pass allow/disallow query param to appropriate ids within manifest
  • Loading branch information
wwelling committed Mar 23, 2019
2 parents 14948cb + 821f51e commit 99fee85
Show file tree
Hide file tree
Showing 15 changed files with 436 additions and 40 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
<version>${iiif-presentation.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/tamu/iiif/controller/ManifestRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public boolean isUpdate() {
}

public String getAllowed() {
return String.join(",", allowed);
return String.join(";", allowed);
}

public String getDisallowed() {
return String.join(",", disallowed);
return String.join(";", disallowed);
}

public static ManifestRequest of(String path, boolean update, List<String> allowed, List<String> disallowed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import edu.tamu.iiif.model.rdf.RdfCanvas;
import edu.tamu.iiif.model.rdf.RdfResource;
import edu.tamu.iiif.service.AbstractManifestService;
import edu.tamu.iiif.utility.RdfModelUtility;

@ConditionalOnExpression(DSPACE_RDF_CONDITION)
public abstract class AbstractDSpaceRdfManifestService extends AbstractManifestService {
Expand All @@ -61,18 +62,20 @@ protected Sequence generateSequence(ManifestRequest request, RdfResource rdfReso
String uri = rdfResource.getResource().getURI();
String handle = getHandle(uri);
PropertyValueSimpleImpl label = new PropertyValueSimpleImpl(handle);
Sequence sequence = new SequenceImpl(getDSpaceIiifSequenceUri(handle), label);
String parameterizedHandle = RdfModelUtility.getParameterizedId(handle, request);
Sequence sequence = new SequenceImpl(getDSpaceIiifSequenceUri(parameterizedHandle), label);
sequence.setCanvases(getCanvases(request, rdfResource));
return sequence;
}

protected Canvas generateCanvas(ManifestRequest request, RdfResource rdfResource) throws IOException, URISyntaxException {
String uri = rdfResource.getResource().getURI();
PropertyValueSimpleImpl label = new PropertyValueSimpleImpl(getBitstreamPath(uri));
String parameterizedUri = RdfModelUtility.getParameterizedId(uri, request);

RdfCanvas rdfCanvas = getDSpaceRdfCanvas(request, rdfResource);

Canvas canvas = new CanvasImpl(getDSpaceIiifCanvasUri(getHandlePath(uri)), label, rdfCanvas.getHeight(), rdfCanvas.getWidth());
Canvas canvas = new CanvasImpl(getDSpaceIiifCanvasUri(getHandlePath(parameterizedUri)), label, rdfCanvas.getHeight(), rdfCanvas.getWidth());

canvas.setImages(rdfCanvas.getImages());

Expand Down Expand Up @@ -219,11 +222,11 @@ private List<Canvas> getCanvases(ManifestRequest request, RdfResource rdfResourc
private RdfCanvas getDSpaceRdfCanvas(ManifestRequest request, RdfResource rdfResource) throws URISyntaxException, InvalidUrlException {
String uri = rdfResource.getResource().getURI();
RdfCanvas rdfCanvas = new RdfCanvas();
String canvasId = getHandlePath(uri);
String parameterizedCanvasId = RdfModelUtility.getParameterizedId(getHandlePath(uri), request);

RdfResource fileFedoraRdfResource = new RdfResource(rdfResource, uri);

Optional<Image> image = generateImage(request, fileFedoraRdfResource, canvasId);
Optional<Image> image = generateImage(request, fileFedoraRdfResource, parameterizedCanvasId);
if (image.isPresent()) {

rdfCanvas.addImage(image.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,24 @@
import edu.tamu.iiif.exception.NotFoundException;
import edu.tamu.iiif.model.ManifestType;
import edu.tamu.iiif.model.rdf.RdfResource;
import edu.tamu.iiif.utility.RdfModelUtility;

@Service
public class DSpaceRdfCollectionManifestService extends AbstractDSpaceRdfManifestService {

@Override
protected String generateManifest(ManifestRequest request) throws URISyntaxException, IOException {
String context = request.getContext();
return mapper.writeValueAsString(generateCollection(context));
return mapper.writeValueAsString(generateCollection(request));
}

private Collection generateCollection(String handle) throws URISyntaxException, NotFoundException {
RdfResource rdfResource = getRdfResource(handle);
private Collection generateCollection(ManifestRequest request) throws URISyntaxException, NotFoundException {
String context = request.getContext();

String parameterizedContext = RdfModelUtility.getParameterizedId(request);

RdfResource rdfResource = getRdfResource(context);

URI id = buildId(handle);
URI id = buildId(parameterizedContext);

PropertyValueSimpleImpl label = getTitle(rdfResource);

Expand All @@ -50,12 +54,12 @@ private Collection generateCollection(String handle) throws URISyntaxException,

Collection collection = new CollectionImpl(id, label, metadata);

List<CollectionReference> collections = getSubcollections(rdfResource);
List<CollectionReference> collections = getSubcollections(request, rdfResource);
if (!collections.isEmpty()) {
collection.setSubCollections(collections);
}

collection.setManifests(getResourceManifests(rdfResource));
collection.setManifests(getResourceManifests(request, rdfResource));

collection.setDescription(getDescription(rdfResource));

Expand All @@ -66,7 +70,7 @@ private Collection generateCollection(String handle) throws URISyntaxException,
return collection;
}

private List<CollectionReference> getSubcollections(RdfResource rdfResource) throws URISyntaxException, NotFoundException {
private List<CollectionReference> getSubcollections(ManifestRequest request, RdfResource rdfResource) throws URISyntaxException, NotFoundException {
List<CollectionReference> subcollections = getSubcommunities(rdfResource);

List<CollectionReference> collections = getCollections(rdfResource);
Expand Down Expand Up @@ -121,22 +125,24 @@ private List<CollectionReference> getCollectionsToElide(RdfResource rdfResource)
return collectionsToElide;
}

private List<ManifestReference> getResourceManifests(RdfResource rdfResource) throws URISyntaxException {
private List<ManifestReference> getResourceManifests(ManifestRequest request, RdfResource rdfResource) throws URISyntaxException {
List<ManifestReference> manifests = new ArrayList<ManifestReference>();
if (isItem(rdfResource.getModel())) {
String uri = rdfResource.getResource().getURI();
String handle = getHandle(uri);
NodeIterator bitstreamIterator = rdfResource.getAllNodesOfPropertyWithId(DSPACE_HAS_BITSTREAM_PREDICATE);
while (bitstreamIterator.hasNext()) {
String bitstreamHandlePath = getHandlePath(bitstreamIterator.next().toString());
manifests.add(new ManifestReferenceImpl(getDSpaceIiifPresentationUri(bitstreamHandlePath), new PropertyValueSimpleImpl(handle)));
String parameterizedBitstreamHandlePath = RdfModelUtility.getParameterizedId(bitstreamHandlePath, request);
manifests.add(new ManifestReferenceImpl(getDSpaceIiifPresentationUri(parameterizedBitstreamHandlePath), new PropertyValueSimpleImpl(handle)));
}
} else {
NodeIterator collectionIterator = rdfResource.getAllNodesOfPropertyWithId(DSPACE_HAS_ITEM_PREDICATE);
while (collectionIterator.hasNext()) {
String uri = collectionIterator.next().toString();
String handle = getHandle(uri);
manifests.add(new ManifestReferenceImpl(getDSpaceIiifPresentationUri(handle), new PropertyValueSimpleImpl(handle)));
String parameterizedHandle = RdfModelUtility.getParameterizedId(handle, request);
manifests.add(new ManifestReferenceImpl(getDSpaceIiifPresentationUri(parameterizedHandle), new PropertyValueSimpleImpl(handle)));
}
}
return manifests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@
import edu.tamu.iiif.exception.NotFoundException;
import edu.tamu.iiif.model.ManifestType;
import edu.tamu.iiif.model.rdf.RdfResource;
import edu.tamu.iiif.utility.RdfModelUtility;

@Service
public class DSpaceRdfPresentationManifestService extends AbstractDSpaceRdfManifestService {

public String generateManifest(ManifestRequest request) throws IOException, URISyntaxException {
String context = request.getContext();

String parameterizedContext = RdfModelUtility.getParameterizedId(request);

RdfResource rdfResource = getRdfResource(context);

URI id = buildId(context);
URI id = buildId(parameterizedContext);

PropertyValueSimpleImpl label = getTitle(rdfResource);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import edu.tamu.iiif.model.rdf.RdfOrderedResource;
import edu.tamu.iiif.model.rdf.RdfResource;
import edu.tamu.iiif.service.AbstractManifestService;
import edu.tamu.iiif.utility.RdfModelUtility;

@ConditionalOnExpression(FEDORA_PCDM_CONDITION)
public abstract class AbstractFedoraPcdmManifestService extends AbstractManifestService {
Expand All @@ -68,20 +69,20 @@ public abstract class AbstractFedoraPcdmManifestService extends AbstractManifest
protected String fedoraPcdmIdentifier;

protected Sequence generateSequence(ManifestRequest request, RdfResource rdfResource) throws IOException, URISyntaxException {
String id = rdfResource.getResource().getURI();
String parameterizedId = RdfModelUtility.getParameterizedId(rdfResource.getResource().getURI(), request);
PropertyValueSimpleImpl label = getLabel(rdfResource);
Sequence sequence = new SequenceImpl(getFedoraIiifSequenceUri(id), label);
Sequence sequence = new SequenceImpl(getFedoraIiifSequenceUri(parameterizedId), label);
sequence.setCanvases(getCanvases(request, rdfResource));
return sequence;
}

protected Canvas generateCanvas(ManifestRequest request, RdfResource rdfResource) throws IOException, URISyntaxException {
String id = rdfResource.getResource().getURI();
String parameterizedId = RdfModelUtility.getParameterizedId(rdfResource.getResource().getURI(), request);
PropertyValueSimpleImpl label = getLabel(rdfResource);

RdfCanvas rdfCanvas = getFedoraRdfCanvas(request, rdfResource);

Canvas canvas = new CanvasImpl(getFedoraIiifCanvasUri(id), label, rdfCanvas.getHeight(), rdfCanvas.getWidth());
Canvas canvas = new CanvasImpl(getFedoraIiifCanvasUri(parameterizedId), label, rdfCanvas.getHeight(), rdfCanvas.getWidth());

canvas.setImages(rdfCanvas.getImages());

Expand Down Expand Up @@ -273,7 +274,7 @@ private void generateOrderedCanvases(ManifestRequest request, RdfOrderedResource
private RdfCanvas getFedoraRdfCanvas(ManifestRequest request, RdfResource rdfResource) throws URISyntaxException, JsonProcessingException, MalformedURLException, IOException {
RdfCanvas rdfCanvas = new RdfCanvas();

String canvasId = rdfResource.getResource().getURI();
String parameterizedCanvasId = RdfModelUtility.getParameterizedId(rdfResource.getResource().getURI(), request);

Statement canvasStatement = rdfResource.getStatementOfPropertyWithId(LDP_CONTAINS_PREDICATE);

Expand All @@ -293,7 +294,7 @@ private RdfCanvas getFedoraRdfCanvas(ManifestRequest request, RdfResource rdfRes
RdfResource fileRdfResource = new RdfResource(fileModel, node.toString());

if (fileRdfResource.containsStatement(RDF_TYPE_PREDICATE, PCDM_FILE)) {
Optional<Image> image = generateImage(request, fileRdfResource, canvasId);
Optional<Image> image = generateImage(request, fileRdfResource, parameterizedCanvasId);
if (image.isPresent()) {
rdfCanvas.addImage(image.get());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,25 @@
import edu.tamu.iiif.model.ManifestType;
import edu.tamu.iiif.model.rdf.RdfOrderedResource;
import edu.tamu.iiif.model.rdf.RdfResource;
import edu.tamu.iiif.utility.RdfModelUtility;

@Service
public class FedoraPcdmCollectionManifestService extends AbstractFedoraPcdmManifestService {

@Override
protected String generateManifest(ManifestRequest request) throws URISyntaxException, IOException {
String context = request.getContext();
return mapper.writeValueAsString(generateCollection(request, context));

return mapper.writeValueAsString(generateCollection(request));
}

private Collection generateCollection(ManifestRequest request, String context) throws URISyntaxException, IOException {
private Collection generateCollection(ManifestRequest request) throws URISyntaxException, IOException {
String context = request.getContext();

String parameterizedContext = RdfModelUtility.getParameterizedId(request);

RdfResource rdfResource = getRdfResource(context);

URI id = buildId(context);
URI id = buildId(parameterizedContext);

PropertyValueSimpleImpl label = getLabel(rdfResource);

Expand Down Expand Up @@ -113,18 +117,19 @@ private List<ManifestReference> getResourceManifests(ManifestRequest request, Rd
NodeIterator nodes = rdfResource.getNodesOfPropertyWithId(PCDM_HAS_MEMBER_PREDICATE);
while (nodes.hasNext()) {
RDFNode node = nodes.next();
String id = node.toString();
String parameterizedId = RdfModelUtility.getParameterizedId(node.toString(), request);
PropertyValueSimpleImpl label = getLabel(new RdfResource(rdfResource, node.toString()));
manifests.add(new ManifestReferenceImpl(getFedoraIiifPresentationUri(id), label));
manifests.add(new ManifestReferenceImpl(getFedoraIiifPresentationUri(parameterizedId), label));
}
}

if (manifests.isEmpty()) {
ResIterator resources = rdfResource.listResourcesWithPropertyWithId(PCDM_HAS_FILE_PREDICATE);
while (resources.hasNext()) {
Resource resource = resources.next();
String parameterizedId = RdfModelUtility.getParameterizedId(resource.getURI(), request);
PropertyValueSimpleImpl label = getLabel(new RdfResource(resource.getModel(), resource));
manifests.add(new ManifestReferenceImpl(getFedoraIiifPresentationUri(resource.getURI()), label));
manifests.add(new ManifestReferenceImpl(getFedoraIiifPresentationUri(parameterizedId), label));
}
}

Expand Down Expand Up @@ -159,8 +164,11 @@ private void gatherResourceManifests(ManifestRequest request, RdfOrderedResource
}

if (id.isPresent()) {

String parameterizedActualId = RdfModelUtility.getParameterizedId(id.get(), request);

PropertyValueSimpleImpl label = getLabel(rdfOrderedResource);
manifests.add(new ManifestReferenceImpl(getFedoraIiifPresentationUri(id.get()), label));
manifests.add(new ManifestReferenceImpl(getFedoraIiifPresentationUri(parameterizedActualId), label));

Optional<String> nextId = getIdByPredicate(model, IANA_NEXT_PREDICATE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@
import edu.tamu.iiif.controller.ManifestRequest;
import edu.tamu.iiif.model.ManifestType;
import edu.tamu.iiif.model.rdf.RdfResource;
import edu.tamu.iiif.utility.RdfModelUtility;

@Service
public class FedoraPcdmPresentationManifestService extends AbstractFedoraPcdmManifestService {

public String generateManifest(ManifestRequest request) throws IOException, URISyntaxException {
String context = request.getContext();

String parameterizedContext = RdfModelUtility.getParameterizedId(request);

RdfResource rdfResource = getRdfResource(context);

URI id = buildId(context);
URI id = buildId(parameterizedContext);

PropertyValueSimpleImpl label = getLabel(rdfResource);

Expand Down
14 changes: 14 additions & 0 deletions src/main/java/edu/tamu/iiif/utility/RdfModelUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Statement;

import edu.tamu.iiif.controller.ManifestRequest;
import edu.tamu.iiif.model.rdf.RdfResource;

public class RdfModelUtility {
Expand Down Expand Up @@ -43,4 +44,17 @@ public static Optional<String> getObject(RdfResource rdfResource, String uri) {
return metadatum;
}

public static String getParameterizedId(String id, ManifestRequest request) {
if (!request.getAllowed().isEmpty()) {
id += "?allow=" + request.getAllowed();
} else if (!request.getDisallowed().isEmpty()) {
id += "?disallow=" + request.getDisallowed();
}
return id;
}

public static String getParameterizedId(ManifestRequest request) {
return getParameterizedId(request.getContext(), request);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ public class DSpaceRdfPresentationManifestServiceTest extends AbstractDSpaceRdfM
@Value("classpath:mock/dspace/json/presentation.json")
private Resource presentation;

@Value("classpath:mock/dspace/json/presentation-allow.json")
private Resource presentationAllow;

@Value("classpath:mock/dspace/json/presentation-disallow.json")
private Resource presentationDisallow;

@Value("classpath:mock/dspace/rdf/collection.rdf")
private Resource collectionRdf;

Expand Down Expand Up @@ -99,14 +105,14 @@ public void testGetCollectionManifest() throws IOException, URISyntaxException {
public void testGetManifestAllowed() throws IOException, URISyntaxException {
setupMocks();
String manifest = dspaceRdfPresentationManifestService.getManifest(ManifestRequest.of("123456789/158308", false, Arrays.asList(new String[] { "image/png", "image/jpeg" }), Arrays.asList(new String[] {})));
assertEquals(objectMapper.readValue(presentation.getFile(), JsonNode.class), objectMapper.readValue(manifest, JsonNode.class));
assertEquals(objectMapper.readValue(presentationAllow.getFile(), JsonNode.class), objectMapper.readValue(manifest, JsonNode.class));
}

@Test
public void testGetManifestDisallowed() throws IOException, URISyntaxException {
setupMocks();
String manifest = dspaceRdfPresentationManifestService.getManifest(ManifestRequest.of("123456789/158308", false, Arrays.asList(new String[] {}), Arrays.asList(new String[] { "image/bmp", "image/jpeg" })));
assertEquals(objectMapper.readValue(presentation.getFile(), JsonNode.class), objectMapper.readValue(manifest, JsonNode.class));
assertEquals(objectMapper.readValue(presentationDisallow.getFile(), JsonNode.class), objectMapper.readValue(manifest, JsonNode.class));
}

@Test
Expand Down
Loading

0 comments on commit 99fee85

Please sign in to comment.