use of org.mycore.iiif.image.model.MCRIIIFImageInformation 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();
}
}
use of org.mycore.iiif.image.model.MCRIIIFImageInformation 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);
}
}
use of org.mycore.iiif.image.model.MCRIIIFImageInformation 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;
}
use of org.mycore.iiif.image.model.MCRIIIFImageInformation 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();
}
}
Aggregations