Skip to content

Commit

Permalink
Merge pull request #65 from TAMULib/fedora-collection-labels
Browse files Browse the repository at this point in the history
fedora collection labels by requesting object container
  • Loading branch information
jcreel committed May 1, 2019
2 parents aa6aae5 + f8e6a01 commit 311c5df
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 34 deletions.
14 changes: 11 additions & 3 deletions src/main/java/edu/tamu/iiif/service/AbstractManifestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,18 @@ public String getManifest(ManifestRequest request) throws IOException, URISyntax
return manifest;
}

protected RdfResource getRdfResource(String handle) throws NotFoundException {
String rdfUrl = getRdfUrl(handle);
protected RdfResource getRdfResourceByContextPath(String contextPath) throws NotFoundException {
String rdfUrl = getRdfUrl(contextPath);
Model model = getRdfModel(rdfUrl);
return getRdfResource(model, rdfUrl);
}

protected RdfResource getRdfResourceByUrl(String rdfUrl) throws NotFoundException {
Model model = getRdfModel(rdfUrl);
return getRdfResource(model, rdfUrl);
}

private RdfResource getRdfResource(Model model, String rdfUrl) {
// model.write(System.out, "JSON-LD");
// model.write(System.out, "RDF/XML");
return new RdfResource(model, model.getResource(rdfUrl));
Expand All @@ -147,7 +156,6 @@ protected Model getRdfModel(String url) throws NotFoundException {
protected String getRdf(String url) throws NotFoundException {
Optional<String> rdf = Optional.ofNullable(httpService.get(url));
if (rdf.isPresent()) {
// System.out.println("\n\n\n\n" + url + "\n\n" + rdf.get() + "\n\n\n\n");
return rdf.get();
}
throw new NotFoundException("RDF not found! " + url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DSpaceRdfCanvasManifestService extends AbstractDSpaceRdfManifestSer
public String generateManifest(ManifestRequest request) throws IOException, URISyntaxException {
String context = request.getContext();
String handle = extractHandle(context);
RdfResource rdfResource = getRdfResource(handle);
RdfResource rdfResource = getRdfResourceByContextPath(handle);
String url = rdfResource.getResource().getURI();
Canvas canvas = generateCanvas(request, new RdfResource(rdfResource, url.replace("rdf/handle", config.getWebapp() != null && config.getWebapp().length() > 0 ? config.getWebapp() + "/bitstream" : "bitstream").replaceAll(handle, context)));
return mapper.writeValueAsString(canvas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private Collection generateCollection(ManifestRequest request) throws URISyntaxE

String parameterizedContext = RdfModelUtility.getParameterizedId(request);

RdfResource rdfResource = getRdfResource(context);
RdfResource rdfResource = getRdfResourceByContextPath(context);

URI id = buildId(parameterizedContext);

Expand Down Expand Up @@ -77,15 +77,15 @@ private List<ManifestReference> getResourceManifests(ManifestRequest request, Rd
while (hasBitstreamIterator.hasNext()) {
String hasBitstreamHandlePath = getHandlePath(hasBitstreamIterator.next().toString());
String parameterizedHasBitstreamHandlePath = RdfModelUtility.getParameterizedId(hasBitstreamHandlePath, request);
RdfResource hasBitstreamRdfResource = getRdfResource(hasBitstreamHandlePath);
RdfResource hasBitstreamRdfResource = getRdfResourceByContextPath(hasBitstreamHandlePath);
manifests.add(new ManifestReferenceImpl(getDSpaceIiifPresentationUri(parameterizedHasBitstreamHandlePath), getLabel(hasBitstreamRdfResource)));
}
} else {
NodeIterator hasItemIterator = rdfResource.getAllNodesOfPropertyWithId(DSPACE_HAS_ITEM_PREDICATE);
while (hasItemIterator.hasNext()) {
String hasItemHandle = getHandle(hasItemIterator.next().toString());
String parameterizedHasItemHandle = RdfModelUtility.getParameterizedId(hasItemHandle, request);
RdfResource hasItemRdfResource = getRdfResource(hasItemHandle);
RdfResource hasItemRdfResource = getRdfResourceByContextPath(hasItemHandle);
manifests.add(new ManifestReferenceImpl(getDSpaceIiifPresentationUri(parameterizedHasItemHandle), getLabel(hasItemRdfResource)));
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ private List<CollectionReference> getSubcommunities(RdfResource rdfResource, Lis
NodeIterator subcommunityIterator = rdfResource.getAllNodesOfPropertyWithId(DSPACE_HAS_SUB_COMMUNITY_PREDICATE);
while (subcommunityIterator.hasNext()) {
String subcommunityHandle = getHandle(subcommunityIterator.next().toString());
RdfResource subcommunityRdfResource = getRdfResource(subcommunityHandle);
RdfResource subcommunityRdfResource = getRdfResourceByContextPath(subcommunityHandle);
collectionsToElide.addAll(getCollections(subcommunityRdfResource));
subcommunities.add(new CollectionReferenceImpl(getDSpaceIiifCollectionUri(subcommunityHandle), getLabel(subcommunityRdfResource)));
}
Expand All @@ -128,7 +128,7 @@ private List<CollectionReference> getCollections(RdfResource rdfResource) throws
NodeIterator collectionIterator = rdfResource.getAllNodesOfPropertyWithId(DSPACE_HAS_COLLECTION_PREDICATE);
while (collectionIterator.hasNext()) {
String collectionHandle = getHandle(collectionIterator.next().toString());
RdfResource collectionRdfResource = getRdfResource(collectionHandle);
RdfResource collectionRdfResource = getRdfResourceByContextPath(collectionHandle);
collections.add(new CollectionReferenceImpl(getDSpaceIiifCollectionUri(collectionHandle), getLabel(collectionRdfResource)));
}
return collections;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public String generateManifest(ManifestRequest request) throws IOException, URIS

String parameterizedContext = RdfModelUtility.getParameterizedId(request);

RdfResource rdfResource = getRdfResource(context);
RdfResource rdfResource = getRdfResourceByContextPath(context);

URI id = buildId(parameterizedContext);

Expand Down Expand Up @@ -116,7 +116,7 @@ private List<Sequence> getSequencesByPredicate(ManifestRequest request, RdfResou
while (nodeIterator.hasNext()) {
String uri = nodeIterator.next().toString();
String handle = getHandle(uri);
sequences.addAll(aggregateSequences(request, getRdfResource(handle)));
sequences.addAll(aggregateSequences(request, getRdfResourceByContextPath(handle)));
}
return sequences;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class DSpaceRdfSequenceManifestService extends AbstractDSpaceRdfManifestS

public String generateManifest(ManifestRequest request) throws IOException, URISyntaxException {
String context = request.getContext();
RdfResource rdfResource = getRdfResource(context);
RdfResource rdfResource = getRdfResourceByContextPath(context);
Sequence sequence = generateSequence(request, rdfResource);
return mapper.writeValueAsString(sequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FedoraPcdmCanvasManifestService extends AbstractFedoraPcdmManifestS

public String generateManifest(ManifestRequest request) throws IOException, URISyntaxException {
String context = request.getContext();
RdfResource rdfResource = getRdfResource(context);
RdfResource rdfResource = getRdfResourceByContextPath(context);
Canvas canvas = generateCanvas(request, rdfResource);
return mapper.writeValueAsString(canvas);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private Collection generateCollection(ManifestRequest request) throws URISyntaxE

String parameterizedContext = RdfModelUtility.getParameterizedId(request);

RdfResource rdfResource = getRdfResource(context);
RdfResource rdfResource = getRdfResourceByContextPath(context);

URI id = buildId(parameterizedContext);

Expand Down Expand Up @@ -101,17 +101,15 @@ private List<ManifestReference> getResourceManifests(ManifestRequest request, Rd
while (nodes.hasNext()) {
RDFNode node = nodes.next();
String parameterizedId = RdfModelUtility.getParameterizedId(node.toString(), request);
PropertyValueSimpleImpl label = getLabel(new RdfResource(rdfResource, node.toString()));
manifests.add(new ManifestReferenceImpl(getFedoraIiifPresentationUri(parameterizedId), label));
manifests.add(new ManifestReferenceImpl(getFedoraIiifPresentationUri(parameterizedId), getLabel(getRdfResourceByUrl(node.toString()))));
}
}
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(parameterizedId), label));
manifests.add(new ManifestReferenceImpl(getFedoraIiifPresentationUri(parameterizedId), getLabel(getRdfResourceByUrl(resource.getURI()))));
}
}
return manifests;
Expand Down Expand Up @@ -148,8 +146,7 @@ private void gatherResourceManifests(ManifestRequest request, RdfOrderedResource

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public String generateManifest(ManifestRequest request) throws IOException, URIS

String parameterizedContext = RdfModelUtility.getParameterizedId(request);

RdfResource rdfResource = getRdfResource(context);
RdfResource rdfResource = getRdfResourceByContextPath(context);

URI id = buildId(parameterizedContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class FedoraPcdmSequenceManifestService extends AbstractFedoraPcdmManifes

public String generateManifest(ManifestRequest request) throws IOException, URISyntaxException {
String context = request.getContext();
RdfResource rdfResource = getRdfResource(context);
RdfResource rdfResource = getRdfResourceByContextPath(context);
Sequence sequence = generateSequence(request, rdfResource);
return mapper.writeValueAsString(sequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void setup() {
@Test
public void testGetManifest() throws IOException, URISyntaxException {
when(httpService.get(eq(FEDORA_URL + "/mwbObjects/TGWCatalog"))).thenReturn(readFileToString(collectionRdf.getFile(), "UTF-8"));
when(httpService.get(eq(FEDORA_URL + "/mwbObjects/TGWCatalog/Pages/ExCat0084"))).thenReturn(readFileToString(itemRdf.getFile(), "UTF-8"));
when(httpService.get(eq(FEDORA_URL + "/mwbObjects/TGWCatalog/Pages/ExCat0084/fcr:metadata"))).thenReturn(readFileToString(itemRdf.getFile(), "UTF-8"));
when(httpService.get(eq(FEDORA_URL + "/mwbObjects/TGWCatalog/Pages/ExCat0084/files/fcr:metadata"))).thenReturn(readFileToString(itemFilesRdf.getFile(), "UTF-8"));
when(httpService.get(eq(FEDORA_URL + "/mwbObjects/TGWCatalog/Pages/ExCat0084/files/ExCat0084.jpg/fcr:metadata"))).thenReturn(readFileToString(itemFilesEntryRdf.getFile(), "UTF-8"));
Expand Down
24 changes: 12 additions & 12 deletions src/test/resources/mock/fedora/json/collection.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
{
"@context": "http://iiif.io/api/presentation/2/context.json",
"@id": "http://localhost:9000/fedora-pcdm/collection/mwbObjects/TGWCatalog",
"@type": "sc:Collection",
"logo": "https://brandguide.tamu.edu/assets/downloads/logos/TAM-Logo.png",
"description": "A page level collection of The Great War exhibit catalog. The assets are JPEGs created from TIFFs created when the catalog was digitized.",
"label": "The Great War Exhibit Catalog",
"logo": "https://brandguide.tamu.edu/assets/downloads/logos/TAM-Logo.png",
"manifests": [
{
"@id": "http://localhost:9000/fedora-pcdm/presentation/mwbObjects/TGWCatalog/Pages/ExCat0084",
"@type": "sc:Manifest",
"label": "The Great War Exhibit Catalog"
}
],
"metadata": [
{
"label": "isPartOf",
Expand All @@ -38,5 +28,15 @@
"value": "The Great War Exhibit Catalog"
}
],
"viewingHint": "multi-part"
"manifests": [
{
"label": "ExCat0084",
"@id": "http://localhost:9000/fedora-pcdm/presentation/mwbObjects/TGWCatalog/Pages/ExCat0084",
"@type": "sc:Manifest"
}
],
"viewingHint": "multi-part",
"@type": "sc:Collection",
"@id": "http://localhost:9000/fedora-pcdm/collection/mwbObjects/TGWCatalog",
"@context": "http://iiif.io/api/presentation/2/context.json"
}

0 comments on commit 311c5df

Please sign in to comment.