Search in sources :

Example 1 with MetadataEntry

use of de.digitalcollections.iiif.model.MetadataEntry in project TranskribusCore by Transkribus.

the class IIIFUtils method readIiifMetadata.

public static TrpDocMetadata readIiifMetadata(Manifest manifest) {
    TrpDocMetadata md = new TrpDocMetadata();
    List<MetadataEntry> metaData = manifest.getMetadata();
    for (MetadataEntry entry : metaData) {
        switch(entry.getLabelString()) {
            case "Title":
                md.setTitle(entry.getValueString());
            case "Creator":
            case "Author":
                md.setAuthor(entry.getValueString());
        }
    }
    return md;
}
Also used : TrpDocMetadata(eu.transkribus.core.model.beans.TrpDocMetadata) MetadataEntry(de.digitalcollections.iiif.model.MetadataEntry)

Example 2 with MetadataEntry

use of de.digitalcollections.iiif.model.MetadataEntry in project cdmlib by cybertaxonomy.

the class ManifestComposer method mediaRepresentationMetaData.

/**
 * @deprecated unused as media metadata is now read via the mediaService,
 *  see {@link IMediaService#readResourceMetadataFiltered(MediaRepresentation)}
 */
@Deprecated
private List<MetadataEntry> mediaRepresentationMetaData(MediaRepresentation representation) {
    List<MetadataEntry> metadata = new ArrayList<>();
    boolean needsPrefix = representation.getParts().size() > 1;
    int partIndex = 1;
    for (MediaRepresentationPart part : representation.getParts()) {
        String prefix = "";
        if (needsPrefix) {
            prefix = "Part" + partIndex + " ";
        }
        if (part.getUri() != null) {
            try {
                CdmImageInfo cdmImageInfo = mediaInfoFactory.cdmImageInfo(part.getUri(), true);
                Map<String, String> result = cdmImageInfo.getMetaData();
                if (result != null) {
                    for (String key : result.keySet()) {
                        metadata.add(new MetadataEntry(key, result.get(key)));
                    }
                }
            } catch (IOException | HttpException e) {
                logger.error("Problem while loading image metadata", e);
                metadata.add(new MetadataEntry(prefix + " Error:", "Problem while loading image metadata <br/><small>(" + e.getLocalizedMessage() + ")</small>"));
            }
        }
    }
    return metadata;
}
Also used : MediaRepresentationPart(eu.etaxonomy.cdm.model.media.MediaRepresentationPart) CdmImageInfo(eu.etaxonomy.cdm.common.media.CdmImageInfo) ArrayList(java.util.ArrayList) MetadataEntry(de.digitalcollections.iiif.model.MetadataEntry) HttpException(org.apache.http.HttpException) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) IOException(java.io.IOException)

Example 3 with MetadataEntry

use of de.digitalcollections.iiif.model.MetadataEntry in project cdmlib by cybertaxonomy.

the class ManifestComposer method manifestFor.

<T extends IdentifiableEntity> Manifest manifestFor(EntityMediaContext<T> entityMediaContext, String onEntitiyType, String onEntityUuid) throws IOException {
    // Logger.getLogger(MediaUtils.class).setLevel(Level.DEBUG);
    // logger.setLevel(Level.DEBUG);
    List<Canvas> canvases = null;
    try {
        canvases = entityMediaContext.getMedia().parallelStream().map(m -> {
            try {
                return createCanvas(onEntitiyType, onEntityUuid, m);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    } catch (RuntimeException re) {
        // re-throw  IOException from lambda expression
        throw new IOException(re.getCause());
    }
    Sequence sequence = null;
    if (canvases.size() > 0) {
        sequence = new Sequence(iiifID(onEntitiyType, onEntityUuid, Sequence.class, "default"));
        sequence.setViewingDirection(ViewingDirection.LEFT_TO_RIGHT);
        sequence.setCanvases(canvases);
        sequence.setStartCanvas(canvases.get(0).getIdentifier());
    }
    Manifest manifest = new Manifest(iiifID(onEntitiyType, onEntityUuid, Manifest.class, null));
    if (sequence != null) {
        // manifest.setLabel(new PropertyValue("Media for " + onEntitiyType + "[" + onEntityUuid + "]")); // TODO better label!!
        manifest.addSequence(sequence);
    } else {
        // TODO better label!!
        manifest.setLabel(new PropertyValue("No media found for " + onEntitiyType + "[" + onEntityUuid + "]"));
    }
    List<MetadataEntry> entityMetadata = entityMetadata(entityMediaContext.getEntity());
    manifest.addMetadata(entityMetadata.toArray(new MetadataEntry[entityMetadata.size()]));
    copyAttributionAndLicenseToManifest(manifest);
    return manifest;
}
Also used : Optional(java.util.Optional) Canvas(de.digitalcollections.iiif.model.sharedcanvas.Canvas) PropertyValue(de.digitalcollections.iiif.model.PropertyValue) MetadataEntry(de.digitalcollections.iiif.model.MetadataEntry) IOException(java.io.IOException) Sequence(de.digitalcollections.iiif.model.sharedcanvas.Sequence) Manifest(de.digitalcollections.iiif.model.sharedcanvas.Manifest)

Example 4 with MetadataEntry

use of de.digitalcollections.iiif.model.MetadataEntry in project cdmlib by cybertaxonomy.

the class ManifestComposer method createCanvas.

public Optional<Canvas> createCanvas(String onEntitiyType, String onEntityUuid, Media media) throws IOException {
    Canvas canvas;
    MediaRepresentation thumbnailRepresentation = mediaTools.processAndFindBestMatchingRepresentation(media, null, null, 100, 100, thumbnailMimetypes, MediaUtils.MissingValueStrategy.MAX);
    MediaRepresentation fullSizeRepresentation = mediaTools.processAndFindBestMatchingRepresentation(media, null, null, Integer.MAX_VALUE, Integer.MAX_VALUE, null, MediaUtils.MissingValueStrategy.MAX);
    // MediaRepresentation thumbnailRepresentation = MediaUtils.findBestMatchingRepresentation(media, null, null, 100, 100, tumbnailMimetypes, MediaUtils.MissingValueStrategy.MAX);
    if (logger.isDebugEnabled()) {
        logger.debug("fullSizeRepresentation: " + fullSizeRepresentation.getParts().get(0).getUri());
        logger.debug("thumbnailRepresentation: " + thumbnailRepresentation.getParts().get(0).getUri());
    }
    List<ImageContent> thumbnailImageContents;
    List<ImageContent> fullSizeImageContents;
    // FIXME the below only makes sense if the media is an Image!!!!!
    if (fullSizeRepresentation != null) {
        fullSizeImageContents = representationPartsToImageContent(fullSizeRepresentation);
    } else {
        fullSizeImageContents = new ArrayList<>(0);
    }
    if (Objects.equals(fullSizeRepresentation, thumbnailRepresentation)) {
        thumbnailImageContents = fullSizeImageContents;
    } else {
        thumbnailImageContents = representationPartsToImageContent(thumbnailRepresentation);
    }
    if (fullSizeRepresentation == null) {
        return Optional.empty();
    }
    canvas = new Canvas(iiifID(onEntitiyType, onEntityUuid, Canvas.class, "media-" + media.getUuid()));
    for (Language lang : media.getAllTitles().keySet()) {
        LanguageString titleLocalized = media.getAllTitles().get(lang);
        canvas.addLabel(titleLocalized.getText());
    }
    canvas.setLabel(new PropertyValue(media.getTitleCache()));
    canvas.setThumbnails(thumbnailImageContents);
    for (ImageContent image : fullSizeImageContents) {
        canvas.addImage(image);
    }
    // explanation
    if (useThumbnailDimensionsForCanvas && !thumbnailImageContents.isEmpty()) {
        if (thumbnailImageContents.get(0).getHeight() != null && thumbnailImageContents.get(0).getHeight() > 0 && thumbnailImageContents.get(0).getWidth() != null && thumbnailImageContents.get(0).getWidth() > 0) {
            canvas.setHeight(thumbnailImageContents.get(0).getHeight());
            canvas.setWidth(thumbnailImageContents.get(0).getWidth());
        }
    }
    List<MetadataEntry> mediaMetadata = mediaMetaData(media);
    List<MetadataEntry> representationMetadata;
    try {
        representationMetadata = mediaService.readResourceMetadataFiltered(fullSizeRepresentation).entrySet().stream().map(e -> new MetadataEntry(e.getKey(), e.getValue())).collect(Collectors.toList());
        mediaMetadata.addAll(representationMetadata);
    } catch (IOException e) {
        logger.error("Error reading media metadata", e);
    } catch (HttpException e) {
        logger.error("Error accessing remote media resource", e);
    }
    // extractAndAddDesciptions(canvas, mediaMetadata);
    mediaMetadata = deduplicateMetadata(mediaMetadata);
    canvas = addAttributionAndLicense(media, canvas, mediaMetadata);
    orderMedatadaItems(canvas);
    canvas.addMetadata(mediaMetadata.toArray(new MetadataEntry[mediaMetadata.size()]));
    return Optional.of(canvas);
}
Also used : Language(eu.etaxonomy.cdm.model.common.Language) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString) ImageContent(de.digitalcollections.iiif.model.ImageContent) Canvas(de.digitalcollections.iiif.model.sharedcanvas.Canvas) MediaRepresentation(eu.etaxonomy.cdm.model.media.MediaRepresentation) PropertyValue(de.digitalcollections.iiif.model.PropertyValue) MetadataEntry(de.digitalcollections.iiif.model.MetadataEntry) HttpException(org.apache.http.HttpException) IOException(java.io.IOException)

Example 5 with MetadataEntry

use of de.digitalcollections.iiif.model.MetadataEntry in project cdmlib by cybertaxonomy.

the class ManifestComposer method deduplicateMetadata.

private List<MetadataEntry> deduplicateMetadata(List<MetadataEntry> mediaMetadata) {
    Map<String, MetadataEntry> dedupMap = new HashMap<>();
    mediaMetadata.stream().forEach(mde -> {
        String dedupKey = mde.getLabelString() + ":" + mde.getValueString();
        dedupMap.put(dedupKey, mde);
    });
    return new ArrayList<>(dedupMap.values());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MetadataEntry(de.digitalcollections.iiif.model.MetadataEntry) LanguageString(eu.etaxonomy.cdm.model.common.LanguageString)

Aggregations

MetadataEntry (de.digitalcollections.iiif.model.MetadataEntry)9 LanguageString (eu.etaxonomy.cdm.model.common.LanguageString)5 ArrayList (java.util.ArrayList)5 PropertyValue (de.digitalcollections.iiif.model.PropertyValue)4 ImageContent (de.digitalcollections.iiif.model.ImageContent)3 Canvas (de.digitalcollections.iiif.model.sharedcanvas.Canvas)3 Language (eu.etaxonomy.cdm.model.common.Language)3 IOException (java.io.IOException)3 Manifest (de.digitalcollections.iiif.model.sharedcanvas.Manifest)2 HttpException (org.apache.http.HttpException)2 Range (de.digitalcollections.iiif.model.sharedcanvas.Range)1 Sequence (de.digitalcollections.iiif.model.sharedcanvas.Sequence)1 CdmImageInfo (eu.etaxonomy.cdm.common.media.CdmImageInfo)1 Credit (eu.etaxonomy.cdm.model.common.Credit)1 IdentifiableSource (eu.etaxonomy.cdm.model.common.IdentifiableSource)1 Identifier (eu.etaxonomy.cdm.model.common.Identifier)1 MediaRepresentation (eu.etaxonomy.cdm.model.media.MediaRepresentation)1 MediaRepresentationPart (eu.etaxonomy.cdm.model.media.MediaRepresentationPart)1 Rights (eu.etaxonomy.cdm.model.media.Rights)1 TrpDocMetadata (eu.transkribus.core.model.beans.TrpDocMetadata)1