Skip to content

Commit

Permalink
Merge pull request #107 from TAMULib/pdf-pages
Browse files Browse the repository at this point in the history
add page to image resource service and cleanup
  • Loading branch information
wwelling authored Apr 29, 2021
2 parents 7399c80 + 17a9aad commit 6372a6f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
37 changes: 17 additions & 20 deletions src/main/java/edu/tamu/iiif/service/AbstractManifestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected OptionalImageWithInfo generateImage(ManifestRequest request, RdfResour
String url = rdfResource.getResource().getURI();
OptionalImageResourceWithInfo imageResource = generateImageResource(request, rdfResource, page);
if (imageResource.isPresent()) {
Image image = new ImageImpl(getImageInfoUri(url, page));
Image image = new ImageImpl(getImageInfoUri(url));
image.setResource(imageResource.get());
image.setOn(getCanvasUri(canvasId));
return OptionalImageWithInfo.of(Optional.of(image), imageResource.getImageResourceInfo());
Expand All @@ -199,20 +199,20 @@ protected OptionalImageResourceWithInfo generateImageResource(ManifestRequest re

if (include) {
logger.info("Including: " + url);
URI infoUri = getImageInfoUri(url, 0);
URI infoUri = getImageInfoUri(url);

Optional<JsonNode> imageInfoNode = getImageInfo(infoUri.toString());

if (imageInfoNode.isPresent()) {
ImageResource imageResource = new ImageResourceImpl(getImageFullUri(url, page));
ImageResource imageResource = new ImageResourceImpl(getImageFullUri(url));

imageResource.setFormat(optionalMimeType.get());

imageResource.setHeight(imageInfoNode.get().get(HEIGHT).asInt());

imageResource.setWidth(imageInfoNode.get().get(WIDTH).asInt());

imageResource.setServices(getServices(rdfResource, page, getIiifImageServiceName()));
imageResource.setServices(getServices(rdfResource, getIiifImageServiceName()));

return OptionalImageResourceWithInfo.of(Optional.of(imageResource), imageInfoNode);
} else {
Expand Down Expand Up @@ -274,30 +274,30 @@ protected String fetchImageInfo(String url) throws NotFoundException {
throw new NotFoundException("Image information not found!");
}

protected URI getImageUri(String url, int page) throws URISyntaxException {
return URI.create(joinPath(imageServerUrl, getResourceId(url, page)));
protected URI getImageUri(String url) throws URISyntaxException {
return URI.create(joinPath(imageServerUrl, getResourceId(url)));
}

protected URI getImageFullUri(String url, int page) throws URISyntaxException {
return URI.create(joinPath(imageServerUrl, getResourceId(url, page), IIIF_FULL_PATH));
protected URI getImageFullUri(String url) throws URISyntaxException {
return URI.create(joinPath(imageServerUrl, getResourceId(url), IIIF_FULL_PATH));
}

protected URI getImageThumbnailUrl(String url, int page) throws URISyntaxException {
return URI.create(joinPath(imageServerUrl, getResourceId(url, page), IIIF_THUMBNAIL_PATH));
protected URI getImageThumbnailUrl(String url) throws URISyntaxException {
return URI.create(joinPath(imageServerUrl, getResourceId(url), IIIF_THUMBNAIL_PATH));
}

protected URI getImageInfoUri(String url, int page) throws URISyntaxException {
return URI.create(joinPath(imageServerUrl, getResourceId(url, page), IMAGE_JSON));
protected URI getImageInfoUri(String url) throws URISyntaxException {
return URI.create(joinPath(imageServerUrl, getResourceId(url), IMAGE_JSON));
}

protected URI serviceUrlToThumbnailUri(URI serviceUrl) throws URISyntaxException {
return URI.create(joinPath(serviceUrl.toString(), IIIF_THUMBNAIL_PATH));
}

protected List<Service> getServices(RdfResource rdfResource, int page, String... names) throws URISyntaxException {
protected List<Service> getServices(RdfResource rdfResource, String... names) throws URISyntaxException {
List<Service> services = new ArrayList<Service>();
for (String name : names) {
services.add(getService(rdfResource, name, page));
services.add(getService(rdfResource, name));
}
return services;
}
Expand All @@ -320,16 +320,13 @@ protected Optional<Thumbnail> getThumbnail(List<Sequence> sequences) throws URIS
return optionalThumbnail;
}

private String getResourceId(String url, int page) throws URISyntaxException {
private String getResourceId(String url) throws URISyntaxException {
String id;
try {
id = resourceResolver.lookup(url);
} catch (NotFoundException e) {
id = resourceResolver.create(url);
}
if (page > 0) {
id += ";" + page;
}
return id;
}

Expand Down Expand Up @@ -392,8 +389,8 @@ protected List<Metadata> getMetadata(RdfResource rdfResource) {

protected abstract AbstractIiifConfig getConfig();

private Service getService(RdfResource rdfResource, String name, int page) throws URISyntaxException {
Service service = new ServiceImpl(getImageUri(rdfResource.getResource().getURI(), page));
private Service getService(RdfResource rdfResource, String name) throws URISyntaxException {
Service service = new ServiceImpl(getImageUri(rdfResource.getResource().getURI()));
service.setLabel(new PropertyValueSimpleImpl(name));
service.setContext(IIIF_IMAGE_API_CONTEXT);
service.setProfile(IIIF_IMAGE_API_LEVEL_ZERO_PROFILE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
import de.digitalcollections.iiif.presentation.model.api.v2.ImageResource;
import de.digitalcollections.iiif.presentation.model.api.v2.PropertyValue;
import de.digitalcollections.iiif.presentation.model.api.v2.Sequence;
import de.digitalcollections.iiif.presentation.model.api.v2.Service;
import de.digitalcollections.iiif.presentation.model.impl.v2.CanvasImpl;
import de.digitalcollections.iiif.presentation.model.impl.v2.ImageImpl;
import de.digitalcollections.iiif.presentation.model.impl.v2.ImageResourceImpl;
import de.digitalcollections.iiif.presentation.model.impl.v2.PropertyValueSimpleImpl;
import de.digitalcollections.iiif.presentation.model.impl.v2.SequenceImpl;
import de.digitalcollections.iiif.presentation.model.impl.v2.ServiceImpl;
import edu.tamu.iiif.config.model.AbstractIiifConfig;
import edu.tamu.iiif.config.model.DSpaceRdfIiifConfig;
import edu.tamu.iiif.controller.ManifestRequest;
Expand Down Expand Up @@ -213,7 +215,14 @@ private Canvas getCanvasPage(Canvas canvas, int page) {
imageResource.setFormat(ir.getFormat());
imageResource.setHeight(ir.getHeight());
imageResource.setWidth(ir.getWidth());
imageResource.setServices(ir.getServices());
List<Service> services = ir.getServices().stream().map(s -> {
Service service = new ServiceImpl(s.getId().toString() + ";" + page);
service.setLabel(s.getLabel());
service.setContext(s.getContext());
service.setProfile(s.getProfile());
return service;
}).collect(Collectors.toList());
imageResource.setServices(services);
image.setResource(imageResource);
image.setOn(i.getOn());
return image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DSpaceRdfImageManifestService extends AbstractDSpaceRdfManifestServ
public String generateManifest(ManifestRequest request) throws IOException, URISyntaxException {
String context = request.getContext();
String dspacePath = config.getWebapp() != null && config.getWebapp().length() > 0 ? joinPath(config.getUrl(), config.getWebapp(), "bitstream", context) : joinPath(config.getUrl(), "bitstream", context);
URI uri = getImageUri(dspacePath, 0);
URI uri = getImageUri(dspacePath);
return fetchImageInfo(uri.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class FedoraPcdmImageManifestService extends AbstractFedoraPcdmManifestSe
public String generateManifest(ManifestRequest request) throws IOException, URISyntaxException {
String context = request.getContext();
String fedoraPath = joinPath(config.getUrl(), context);
URI uri = getImageUri(fedoraPath, 0);
URI uri = getImageUri(fedoraPath);
return fetchImageInfo(uri.toString());
}

Expand Down

0 comments on commit 6372a6f

Please sign in to comment.