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;
}
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;
}
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;
}
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);
}
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());
}
Aggregations