Search in sources :

Example 1 with ImageResource

use of de.digitalcollections.iiif.presentation.model.api.v2.ImageResource in project kramerius by ceskaexpedice.

the class IiifAPI method manifest.

@GET
@Path("{pid}/manifest")
@Produces({ MediaType.APPLICATION_JSON + ";charset=utf-8" })
public Response manifest(@PathParam("pid") String pid) {
    checkPid(pid);
    try {
        DocumentDto document = getIiifDocument(pid);
        PropertyValue titleLabel = new PropertyValueSimpleImpl(document.getTitle());
        Manifest manifest = new ManifestImpl(UriBuilder.fromUri(iiifUri).path(getClass(), "manifest").build(pid), titleLabel);
        List<String> fieldList = new ArrayList<String>();
        List<Canvas> canvases = new ArrayList<Canvas>();
        List<String> children = ItemResourceUtils.solrChildrenPids(pid, fieldList, solrAccess, solrMemoization);
        Map<String, Pair<Integer, Integer>> resolutions = getResolutions(children);
        for (String p : children) {
            String repPid = p.replace("/", "");
            if (repPid.equals(pid)) {
                continue;
            }
            DocumentDto page = getIiifDocument(repPid);
            if (!"page".equals(page.getModel()))
                continue;
            String id = ApplicationURL.applicationURL(this.requestProvider.get()) + "/canvas/" + repPid;
            Pair<Integer, Integer> resolution = resolutions.get(p);
            if (resolution != null) {
                Canvas canvas = new CanvasImpl(id, new PropertyValueSimpleImpl(page.getTitle()), resolution.getLeft(), resolution.getRight());
                ImageResource resource = new ImageResourceImpl();
                String resourceId = ApplicationURL.applicationURL(this.requestProvider.get()).toString() + "/iiif/" + repPid + "/full/full/0/default.jpg";
                resource.setType("dctypes:Image");
                resource.setId(resourceId);
                resource.setHeight(resolution.getLeft());
                resource.setWidth(resolution.getRight());
                resource.setFormat("image/jpeg");
                Service service = new ServiceImpl();
                service.setContext("http://iiif.io/api/image/2/context.json");
                service.setId(ApplicationURL.applicationURL(this.requestProvider.get()).toString() + "/iiif/" + repPid);
                service.setProfile("http://iiif.io/api/image/2/level1.json");
                resource.setService(service);
                Image image = new ImageImpl();
                image.setOn(new URI(id));
                image.setResource(resource);
                canvas.setImages(Collections.singletonList(image));
                canvases.add(canvas);
            }
        }
        // no pages - 500 ?
        if (canvases.isEmpty()) {
            throw new GenericApplicationException("cannot create manifest for pid '" + pid + "'");
        }
        Sequence sequence = new SequenceImpl();
        sequence.setCanvases(canvases);
        manifest.setSequences(Collections.singletonList(sequence));
        return Response.ok().entity(toJSON(manifest)).build();
    } catch (IOException e) {
        throw new GenericApplicationException(e.getMessage());
    } catch (URISyntaxException e) {
        throw new GenericApplicationException(e.getMessage());
    } catch (InterruptedException e) {
        throw new GenericApplicationException(e.getMessage());
    }
}
Also used : ArrayList(java.util.ArrayList) ManifestImpl(de.digitalcollections.iiif.presentation.model.impl.v2.ManifestImpl) SequenceImpl(de.digitalcollections.iiif.presentation.model.impl.v2.SequenceImpl) URISyntaxException(java.net.URISyntaxException) Image(de.digitalcollections.iiif.presentation.model.api.v2.Image) GenericApplicationException(cz.incad.kramerius.rest.api.exceptions.GenericApplicationException) URI(java.net.URI) ImageResourceImpl(de.digitalcollections.iiif.presentation.model.impl.v2.ImageResourceImpl) ImageResource(de.digitalcollections.iiif.presentation.model.api.v2.ImageResource) Pair(org.apache.commons.lang3.tuple.Pair) ServiceImpl(de.digitalcollections.iiif.presentation.model.impl.v2.ServiceImpl) Canvas(de.digitalcollections.iiif.presentation.model.api.v2.Canvas) PropertyValue(de.digitalcollections.iiif.presentation.model.api.v2.PropertyValue) Service(de.digitalcollections.iiif.presentation.model.api.v2.Service) Sequence(de.digitalcollections.iiif.presentation.model.api.v2.Sequence) IOException(java.io.IOException) Manifest(de.digitalcollections.iiif.presentation.model.api.v2.Manifest) ImageImpl(de.digitalcollections.iiif.presentation.model.impl.v2.ImageImpl) CanvasImpl(de.digitalcollections.iiif.presentation.model.impl.v2.CanvasImpl) PropertyValueSimpleImpl(de.digitalcollections.iiif.presentation.model.impl.v2.PropertyValueSimpleImpl) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

GenericApplicationException (cz.incad.kramerius.rest.api.exceptions.GenericApplicationException)1 Canvas (de.digitalcollections.iiif.presentation.model.api.v2.Canvas)1 Image (de.digitalcollections.iiif.presentation.model.api.v2.Image)1 ImageResource (de.digitalcollections.iiif.presentation.model.api.v2.ImageResource)1 Manifest (de.digitalcollections.iiif.presentation.model.api.v2.Manifest)1 PropertyValue (de.digitalcollections.iiif.presentation.model.api.v2.PropertyValue)1 Sequence (de.digitalcollections.iiif.presentation.model.api.v2.Sequence)1 Service (de.digitalcollections.iiif.presentation.model.api.v2.Service)1 CanvasImpl (de.digitalcollections.iiif.presentation.model.impl.v2.CanvasImpl)1 ImageImpl (de.digitalcollections.iiif.presentation.model.impl.v2.ImageImpl)1 ImageResourceImpl (de.digitalcollections.iiif.presentation.model.impl.v2.ImageResourceImpl)1 ManifestImpl (de.digitalcollections.iiif.presentation.model.impl.v2.ManifestImpl)1 PropertyValueSimpleImpl (de.digitalcollections.iiif.presentation.model.impl.v2.PropertyValueSimpleImpl)1 SequenceImpl (de.digitalcollections.iiif.presentation.model.impl.v2.SequenceImpl)1 ServiceImpl (de.digitalcollections.iiif.presentation.model.impl.v2.ServiceImpl)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1