use of org.mycore.iiif.presentation.model.basic.MCRIIIFCanvas 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;
}
Aggregations