Search in sources :

Example 1 with MCRIIIFImageNotFoundException

use of org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException in project mycore by MyCoRe-Org.

the class MCRIIIFImageResource method getInfo.

@GET
@Produces(MCRIIIFMediaType.APPLICATION_LD_JSON)
@Path("{" + IDENTIFIER_PARAM + "}/info.json")
public Response getInfo(@PathParam(IMPL_PARAM) String implString, @PathParam(IDENTIFIER_PARAM) String identifier) {
    try {
        MCRIIIFImageImpl impl = getImpl(implString);
        MCRIIIFImageInformation information = impl.getInformation(identifier);
        MCRIIIFImageProfile profile = getProfile(impl);
        information.profile.add(IIIF_IMAGE_API_2_LEVEL2);
        information.profile.add(profile);
        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        return Response.ok().header("Access-Control-Allow-Origin", "*").header("Link", buildCanonicalURL(impl, identifier)).header("Profile", buildProfileURL()).entity(gson.toJson(information)).build();
    } catch (MCRIIIFImageNotFoundException e) {
        return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
    } catch (MCRIIIFImageProvidingException | UnsupportedEncodingException e) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    } catch (MCRAccessException e) {
        return Response.status(Response.Status.FORBIDDEN).entity(e.getMessage()).build();
    }
}
Also used : MCRIIIFImageNotFoundException(org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException) MCRIIIFImageProfile(org.mycore.iiif.image.model.MCRIIIFImageProfile) GsonBuilder(com.google.gson.GsonBuilder) MCRIIIFImageInformation(org.mycore.iiif.image.model.MCRIIIFImageInformation) MCRAccessException(org.mycore.access.MCRAccessException) Gson(com.google.gson.Gson) MCRIIIFImageProvidingException(org.mycore.iiif.image.impl.MCRIIIFImageProvidingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MCRIIIFImageImpl(org.mycore.iiif.image.impl.MCRIIIFImageImpl) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with MCRIIIFImageNotFoundException

use of org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException in project mycore by MyCoRe-Org.

the class MCRIVIEWIIIFImageImpl method getInformation.

public MCRIIIFImageInformation getInformation(String identifier) throws MCRIIIFImageNotFoundException, MCRIIIFImageProvidingException, MCRAccessException {
    try {
        Path tiledFile = tileFileProvider.getTiledFile(identifier);
        MCRTiledPictureProps tiledPictureProps = getTiledPictureProps(tiledFile);
        MCRIIIFImageInformation imageInformation = new MCRIIIFImageInformation(MCRIIIFBase.API_IMAGE_2, buildURL(identifier), DEFAULT_PROTOCOL, tiledPictureProps.getWidth(), tiledPictureProps.getHeight());
        MCRIIIFImageTileInformation tileInformation = new MCRIIIFImageTileInformation(256, 256);
        for (int i = 0; i < tiledPictureProps.getZoomlevel(); i++) {
            tileInformation.scaleFactors.add((int) Math.pow(2, i));
        }
        imageInformation.tiles.add(tileInformation);
        return imageInformation;
    } catch (FileSystemNotFoundException e) {
        LOGGER.error("Could not find Iview ZIP for {}", identifier, e);
        throw new MCRIIIFImageNotFoundException(identifier);
    }
}
Also used : Path(java.nio.file.Path) MCRIIIFImageNotFoundException(org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException) MCRIIIFImageTileInformation(org.mycore.iiif.image.model.MCRIIIFImageTileInformation) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) MCRIIIFImageInformation(org.mycore.iiif.image.model.MCRIIIFImageInformation) MCRTiledPictureProps(org.mycore.imagetiler.MCRTiledPictureProps)

Example 3 with MCRIIIFImageNotFoundException

use of org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException in project mycore by MyCoRe-Org.

the class MCRMetsMods2IIIFConverter method convert.

public MCRIIIFManifest convert() {
    MCRIIIFManifest manifest = new MCRIIIFManifest();
    // root chapter ^= manifest metadata
    LogicalStructMap logicalStructMap = (LogicalStructMap) mets.getStructMap("LOGICAL");
    LogicalDiv divContainer = logicalStructMap.getDivContainer();
    List<MCRIIIFMetadata> metadata = extractMedataFromLogicalDiv(mets, divContainer);
    manifest.metadata = metadata;
    manifest.setId(this.identifier);
    PhysicalStructMap physicalStructMap = (PhysicalStructMap) mets.getStructMap("PHYSICAL");
    PhysicalDiv physicalDivContainer = physicalStructMap.getDivContainer();
    String id = physicalDivContainer.getId();
    MCRIIIFSequence sequence = new MCRIIIFSequence(id);
    List<PhysicalSubDiv> children = physicalDivContainer.getChildren();
    MCRIIIFImageImpl imageImpl = MCRIIIFImageImpl.getInstance(getImageImplName());
    MCRIIIFImageProfile profile = imageImpl.getProfile();
    profile.setId(MCRIIIFImageUtil.getProfileLink(imageImpl));
    sequence.canvases = children.stream().map(physicalSubDiv -> {
        String order = physicalSubDiv.asElement().getAttributeValue("ORDER");
        String orderLabel = physicalSubDiv.getOrderLabel();
        String contentids = physicalSubDiv.getContentids();
        String label = Stream.of(order, orderLabel, contentids).filter(o -> o != null && !o.isEmpty()).collect(Collectors.joining(" - "));
        String identifier = this.physicalIdentifierMap.get(physicalSubDiv);
        try {
            MCRIIIFImageInformation information = imageImpl.getInformation(identifier);
            MCRIIIFCanvas canvas = new MCRIIIFCanvas(identifier, label, information.width, information.height);
            MCRIIIFAnnotation annotation = new MCRIIIFAnnotation(identifier, canvas);
            canvas.images.add(annotation);
            MCRIIIFResource resource = new MCRIIIFResource(information.getId(), MCRDCMIType.Image);
            resource.setWidth(information.width);
            resource.setHeight(information.height);
            MCRIIIFService service = new MCRIIIFService(information.getId(), profile.getContext());
            service.profile = MCRIIIFImageProfile.IIIF_PROFILE_2_0;
            resource.setService(service);
            annotation.setResource(resource);
            return canvas;
        } catch (MCRIIIFImageNotFoundException | MCRIIIFImageProvidingException e) {
            throw new MCRException("Error while providing ImageInfo for " + identifier, e);
        } catch (MCRAccessException e) {
            LOGGER.warn("User has no access to {}", identifier);
            return null;
        }
    }).filter(Objects::nonNull).collect(Collectors.toList());
    manifest.sequences.add(sequence);
    List<MCRIIIFRange> complete = new ArrayList<>();
    processDivContainer(complete, divContainer);
    manifest.structures.addAll(complete);
    manifest.setLabel(metadata.stream().filter(m -> m.getLabel().equals("title")).findFirst().get().getStringValue().get());
    return manifest;
}
Also used : PhysicalDiv(org.mycore.mets.model.struct.PhysicalDiv) MCRIIIFCanvas(org.mycore.iiif.presentation.model.basic.MCRIIIFCanvas) MCRIIIFImageUtil(org.mycore.iiif.image.MCRIIIFImageUtil) MCRIIIFImageImpl(org.mycore.iiif.image.impl.MCRIIIFImageImpl) MCRConstants(org.mycore.common.MCRConstants) MCRIIIFImageProvidingException(org.mycore.iiif.image.impl.MCRIIIFImageProvidingException) MCRIIIFImageProfile(org.mycore.iiif.image.model.MCRIIIFImageProfile) HashMap(java.util.HashMap) MCRIIIFSequence(org.mycore.iiif.presentation.model.basic.MCRIIIFSequence) MCRException(org.mycore.common.MCRException) ArrayList(java.util.ArrayList) Document(org.jdom2.Document) MCRIIIFService(org.mycore.iiif.presentation.model.attributes.MCRIIIFService) FileGrp(org.mycore.mets.model.files.FileGrp) Map(java.util.Map) MCRDCMIType(org.mycore.iiif.presentation.model.attributes.MCRDCMIType) MCRIIIFResource(org.mycore.iiif.presentation.model.attributes.MCRIIIFResource) MCRAccessException(org.mycore.access.MCRAccessException) File(org.mycore.mets.model.files.File) PhysicalStructMap(org.mycore.mets.model.struct.PhysicalStructMap) MCRIIIFAnnotation(org.mycore.iiif.presentation.model.additional.MCRIIIFAnnotation) MCRIIIFViewingHint(org.mycore.iiif.presentation.model.attributes.MCRIIIFViewingHint) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MCRIIIFManifest(org.mycore.iiif.presentation.model.basic.MCRIIIFManifest) Mets(org.mycore.mets.model.Mets) Collectors(java.util.stream.Collectors) MCRIIIFRange(org.mycore.iiif.presentation.model.basic.MCRIIIFRange) LogicalDiv(org.mycore.mets.model.struct.LogicalDiv) MDTYPE(org.mycore.mets.model.struct.MDTYPE) PhysicalSubDiv(org.mycore.mets.model.struct.PhysicalSubDiv) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) MCRIIIFImageNotFoundException(org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException) MCRIIIFImageInformation(org.mycore.iiif.image.model.MCRIIIFImageInformation) LogicalStructMap(org.mycore.mets.model.struct.LogicalStructMap) DmdSec(org.mycore.mets.model.sections.DmdSec) MdWrap(org.mycore.mets.model.struct.MdWrap) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) MCRIIIFMetadata(org.mycore.iiif.presentation.model.attributes.MCRIIIFMetadata) PhysicalStructMap(org.mycore.mets.model.struct.PhysicalStructMap) ArrayList(java.util.ArrayList) MCRIIIFSequence(org.mycore.iiif.presentation.model.basic.MCRIIIFSequence) PhysicalSubDiv(org.mycore.mets.model.struct.PhysicalSubDiv) MCRIIIFRange(org.mycore.iiif.presentation.model.basic.MCRIIIFRange) LogicalStructMap(org.mycore.mets.model.struct.LogicalStructMap) LogicalDiv(org.mycore.mets.model.struct.LogicalDiv) MCRIIIFCanvas(org.mycore.iiif.presentation.model.basic.MCRIIIFCanvas) MCRIIIFMetadata(org.mycore.iiif.presentation.model.attributes.MCRIIIFMetadata) MCRIIIFService(org.mycore.iiif.presentation.model.attributes.MCRIIIFService) MCRIIIFImageImpl(org.mycore.iiif.image.impl.MCRIIIFImageImpl) MCRException(org.mycore.common.MCRException) MCRIIIFManifest(org.mycore.iiif.presentation.model.basic.MCRIIIFManifest) MCRIIIFImageInformation(org.mycore.iiif.image.model.MCRIIIFImageInformation) MCRIIIFResource(org.mycore.iiif.presentation.model.attributes.MCRIIIFResource) MCRAccessException(org.mycore.access.MCRAccessException) PhysicalDiv(org.mycore.mets.model.struct.PhysicalDiv) MCRIIIFImageProfile(org.mycore.iiif.image.model.MCRIIIFImageProfile) MCRIIIFAnnotation(org.mycore.iiif.presentation.model.additional.MCRIIIFAnnotation) Objects(java.util.Objects)

Example 4 with MCRIIIFImageNotFoundException

use of org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException in project mycore by MyCoRe-Org.

the class MCRIIIFImageResource method getImage.

@GET
@Path("{" + IDENTIFIER_PARAM + "}/{region}/{size}/{rotation}/{quality}.{format}")
public Response getImage(@PathParam(IMPL_PARAM) String implStr, @PathParam(IDENTIFIER_PARAM) String identifier, @PathParam("region") String region, @PathParam("size") String size, @PathParam("rotation") String rotation, @PathParam("quality") String quality, @PathParam("format") String format) {
    try {
        MCRIIIFImageImpl impl = getImpl(implStr);
        MCRIIIFImageInformation information = impl.getInformation(identifier);
        MCRIIIFRegionParser rp = new MCRIIIFRegionParser(region, information.width, information.height);
        MCRIIIFImageSourceRegion sourceRegion = rp.parseImageRegion();
        MCRIIIFScaleParser sp = new MCRIIIFScaleParser(size, sourceRegion.getX2() - sourceRegion.getX1(), sourceRegion.getY2() - sourceRegion.getY1());
        MCRIIIFImageTargetSize targetSize = sp.parseTargetScale();
        MCRIIIFRotationParser rotationParser = new MCRIIIFRotationParser(rotation);
        MCRIIIFImageTargetRotation parsedRotation = rotationParser.parse();
        MCRIIIFImageQuality imageQuality = MCRIIIFImageQuality.fromString(quality);
        BufferedImage provide = impl.provide(identifier, sourceRegion, targetSize, parsedRotation, imageQuality, format);
        Response.Status status = rp.isCompleteValid() ? Response.Status.OK : Response.Status.BAD_REQUEST;
        Response.ResponseBuilder responseBuilder = Response.status(status);
        return responseBuilder.header("Link", buildCanonicalURL(impl, identifier)).header("Profile", buildProfileURL()).type("image/" + format).entity((StreamingOutput) outputStream -> ImageIO.write(provide, format, outputStream)).build();
    } catch (MCRIIIFImageNotFoundException e) {
        return Response.status(Response.Status.NOT_FOUND).entity(e.getMessage()).build();
    } catch (IllegalArgumentException | MCRIIIFUnsupportedFormatException e) {
        return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build();
    } catch (MCRAccessException e) {
        return Response.status(Response.Status.FORBIDDEN).entity(e.getMessage()).build();
    } catch (Exception e) {
        LOGGER.error(() -> "Error while getting Image " + identifier + " from " + implStr + " with region: " + region + ", size: " + size + ", rotation: " + rotation + ", quality: " + quality + ", format: " + format, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
    }
}
Also used : MCRIIIFImageTargetRotation(org.mycore.iiif.image.model.MCRIIIFImageTargetRotation) MCRIIIFImageInformation(org.mycore.iiif.image.model.MCRIIIFImageInformation) MCRAccessException(org.mycore.access.MCRAccessException) MCRIIIFImageQuality(org.mycore.iiif.image.model.MCRIIIFImageQuality) StreamingOutput(javax.ws.rs.core.StreamingOutput) MCRIIIFUnsupportedFormatException(org.mycore.iiif.image.impl.MCRIIIFUnsupportedFormatException) BufferedImage(java.awt.image.BufferedImage) URISyntaxException(java.net.URISyntaxException) MCRIIIFImageProvidingException(org.mycore.iiif.image.impl.MCRIIIFImageProvidingException) MCRAccessException(org.mycore.access.MCRAccessException) MCRIIIFUnsupportedFormatException(org.mycore.iiif.image.impl.MCRIIIFUnsupportedFormatException) MCRIIIFImageNotFoundException(org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Response(javax.ws.rs.core.Response) MCRIIIFImageNotFoundException(org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException) MCRIIIFImageTargetSize(org.mycore.iiif.image.model.MCRIIIFImageTargetSize) MCRIIIFImageSourceRegion(org.mycore.iiif.image.model.MCRIIIFImageSourceRegion) MCRIIIFRotationParser(org.mycore.iiif.image.parser.MCRIIIFRotationParser) MCRIIIFRegionParser(org.mycore.iiif.image.parser.MCRIIIFRegionParser) MCRIIIFScaleParser(org.mycore.iiif.image.parser.MCRIIIFScaleParser) MCRIIIFImageImpl(org.mycore.iiif.image.impl.MCRIIIFImageImpl) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

MCRIIIFImageNotFoundException (org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException)4 MCRIIIFImageInformation (org.mycore.iiif.image.model.MCRIIIFImageInformation)4 MCRAccessException (org.mycore.access.MCRAccessException)3 MCRIIIFImageImpl (org.mycore.iiif.image.impl.MCRIIIFImageImpl)3 MCRIIIFImageProvidingException (org.mycore.iiif.image.impl.MCRIIIFImageProvidingException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 MCRIIIFImageProfile (org.mycore.iiif.image.model.MCRIIIFImageProfile)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 BufferedImage (java.awt.image.BufferedImage)1 URISyntaxException (java.net.URISyntaxException)1 FileSystemNotFoundException (java.nio.file.FileSystemNotFoundException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1