Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/met 5806 support embeddable resources profile #675

Merged
merged 16 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions metis-media-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,10 @@
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ class AudioVideoProcessor implements MediaProcessor {
private static String globalFfprobeCommand;

private final CommandExecutor commandExecutor;

private final String ffprobeCommand;

private MediaProcessor nextProcessor;
/**
* Constructor. This is a wrapper for {@link AudioVideoProcessor#AudioVideoProcessor(CommandExecutor, String)} where the
* property is detected. It is advisable to use this constructor for non-testing purposes.
Expand Down Expand Up @@ -133,6 +135,16 @@ public boolean downloadResourceForFullProcessing() {
return false;
}

/**
* This creates structure to enable a chain of media processors
*
* @param nextProcessable next media processor in the chain
*/
@Override
public void setNextProcessor(MediaProcessor nextProcessable) {
this.nextProcessor = nextProcessable;
}

@Override
public ResourceExtractionResultImpl copyMetadata(Resource resource, String detectedMimeType) {
final AbstractResourceMetadata metadata =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class ImageProcessor implements MediaProcessor {

private final ThumbnailGenerator thumbnailGenerator;

private MediaProcessor nextProcessor;
/**
* Constructor.
*
Expand All @@ -39,6 +39,16 @@ public boolean downloadResourceForFullProcessing() {
return true;
}

/**
* This creates structure to enable a chain of media processors
*
* @param nextProcessable next media processor in the chain
*/
@Override
public void setNextProcessor(MediaProcessor nextProcessable) {
this.nextProcessor = nextProcessable;
}

@Override
public ResourceExtractionResultImpl copyMetadata(Resource resource, String detectedMimeType)
throws MediaExtractionException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package eu.europeana.metis.mediaprocessing.extraction;

import eu.europeana.metis.mediaprocessing.exception.MediaExtractionException;
import eu.europeana.metis.mediaprocessing.model.Resource;
import eu.europeana.metis.mediaprocessing.model.ResourceExtractionResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LinkedProcessor implements MediaProcessor {
jeortizquan marked this conversation as resolved.
Show resolved Hide resolved
public static final Logger LOGGER = LoggerFactory.getLogger(LinkedProcessor.class);

private MediaProcessor nextProcessor;
/**
* Process a resource by extracting the metadata from the content.
*
* @param resource The resource to process. Note that the resource may not have content (see
* {@link MediaExtractorImpl#shouldDownloadForFullProcessing(String)}).
* @param detectedMimeType The mime type that was detected for this resource (may deviate from the mime type that was provided
* by the server and which is stored in {@link Resource#getProvidedMimeType()}).
* @param mainThumbnailAvailable Whether the main thumbnail for this record is available. This may influence the decision on
* whether to generate a thumbnail for this resource.
* @return The result of the processing.
* @throws MediaExtractionException In case something went wrong during the extraction.
*/
@Override
public ResourceExtractionResult extractMetadata(Resource resource, String detectedMimeType, boolean mainThumbnailAvailable)
throws MediaExtractionException {
LOGGER.info("Extracting metadata for resource {}", resource);
return this.nextProcessor.extractMetadata(resource, detectedMimeType, mainThumbnailAvailable);
}

/**
* Process a resource by copying the metadata from the input without performing any extraction.
*
* @param resource The resource to process. The resource is not expected to have content.
* @param detectedMimeType The mime type that was detected for this resource (may deviate from the mime type that was provided
* by the server and which is stored in {@link Resource#getProvidedMimeType()}).
* @return The result of the processing.
* @throws MediaExtractionException In case something went wrong during the extraction.
*/
@Override
public ResourceExtractionResult copyMetadata(Resource resource, String detectedMimeType) throws MediaExtractionException {
LOGGER.info("Copying metadata for resource {}", resource);
return this.nextProcessor.copyMetadata(resource, detectedMimeType);
}

/**
* @return Whether the processor needs the downloaded resource for full processing.
*/
@Override
public boolean downloadResourceForFullProcessing() {
return this.nextProcessor.downloadResourceForFullProcessing();
}

/**
* This creates structure to enable a chain of media processors
*
* @param nextProcessable next media processor in the chain
*/
@Override
public void setNextProcessor(MediaProcessor nextProcessable) {
this.nextProcessor = nextProcessable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import eu.europeana.metis.mediaprocessing.model.ResourceExtractionResultImpl;

class Media3dProcessor implements MediaProcessor {

private MediaProcessor nextProcessor;
@Override
public ResourceExtractionResult extractMetadata(Resource resource, String detectedMimeType, boolean mainThumbnailAvailable)
throws MediaExtractionException {
Expand All @@ -29,4 +29,14 @@ public ResourceExtractionResult copyMetadata(Resource resource, String detectedM
public boolean downloadResourceForFullProcessing() {
return false;
}

/**
* This creates structure to enable a chain of media processors
*
* @param nextProcessable next media processor in the chain
*/
@Override
public void setNextProcessor(MediaProcessor nextProcessable) {
this.nextProcessor = nextProcessable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ enum ProcessingMode {FULL, REDUCED, NONE}
private final AudioVideoProcessor audioVideoProcessor;
private final TextProcessor textProcessor;
private final Media3dProcessor media3dProcessor;
private final OEmbedProcessor oEmbedProcessor;
private final LinkedProcessor linkedProcessor;

/**
* Constructor meant for testing purposes.
Expand All @@ -63,15 +65,19 @@ enum ProcessingMode {FULL, REDUCED, NONE}
* @param textProcessor A text processor.
*/
MediaExtractorImpl(ResourceDownloadClient resourceDownloadClient,
MimeTypeDetectHttpClient mimeTypeDetectHttpClient, TikaWrapper tika, ImageProcessor imageProcessor,
AudioVideoProcessor audioVideoProcessor, TextProcessor textProcessor, Media3dProcessor media3dProcessor) {
MimeTypeDetectHttpClient mimeTypeDetectHttpClient, TikaWrapper tika,
ImageProcessor imageProcessor, AudioVideoProcessor audioVideoProcessor,
TextProcessor textProcessor, Media3dProcessor media3dProcessor,
OEmbedProcessor oEmbedProcessor, LinkedProcessor linkedProcessor) {
this.resourceDownloadClient = resourceDownloadClient;
this.mimeTypeDetectHttpClient = mimeTypeDetectHttpClient;
this.tika = tika;
this.imageProcessor = imageProcessor;
this.audioVideoProcessor = audioVideoProcessor;
this.textProcessor = textProcessor;
this.media3dProcessor = media3dProcessor;
this.oEmbedProcessor = oEmbedProcessor;
this.linkedProcessor = linkedProcessor;
}

/**
Expand Down Expand Up @@ -102,6 +108,18 @@ public MediaExtractorImpl(int redirectCount, int thumbnailGenerateTimeout,
this.textProcessor = new TextProcessor(thumbnailGenerator,
new PdfToImageConverter(new CommandExecutor(thumbnailGenerateTimeout)));
this.media3dProcessor = new Media3dProcessor();
this.oEmbedProcessor = new OEmbedProcessor();
this.linkedProcessor = new LinkedProcessor();
initChainOfProcessors();
}

private void initChainOfProcessors() {
jeortizquan marked this conversation as resolved.
Show resolved Hide resolved
this.imageProcessor.setNextProcessor(null);
this.audioVideoProcessor.setNextProcessor(null);
this.media3dProcessor.setNextProcessor(null);
this.linkedProcessor.setNextProcessor(oEmbedProcessor);
this.oEmbedProcessor.setNextProcessor(textProcessor);
this.textProcessor.setNextProcessor(null);
}

@Override
Expand Down Expand Up @@ -196,7 +214,7 @@ String detectType(Path path, String providedMimeType) throws IOException {
MediaProcessor chooseMediaProcessor(MediaType mediaType) {
final MediaProcessor processor;
switch (mediaType) {
case TEXT -> processor = textProcessor;
case TEXT, OTHER -> processor = linkedProcessor;
case AUDIO, VIDEO -> processor = audioVideoProcessor;
case IMAGE -> processor = imageProcessor;
case THREE_D -> processor = media3dProcessor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ ResourceExtractionResult copyMetadata(Resource resource, String detectedMimeType
*/
boolean downloadResourceForFullProcessing();

/**
* This creates structure to enable a chain of media processors
* @param nextProcessable next media processor in the chain
*/
void setNextProcessor(MediaProcessor nextProcessable);

/**
* Purges negative values.
*
Expand Down
Loading