Skip to content

Commit

Permalink
Merge branch 'feat/MET-5806-oembed-for-generic-resources-part-2' into…
Browse files Browse the repository at this point in the history
… feat/MET-5806-oembed-for-generic-resources-part-3

# Conflicts:
#	metis-media-service/src/main/java/eu/europeana/metis/mediaprocessing/RdfDeserializerImpl.java
#	metis-media-service/src/main/java/eu/europeana/metis/mediaprocessing/extraction/oembed/OEmbedValidation.java
#	metis-media-service/src/test/java/eu/europeana/metis/mediaprocessing/RdfDeserializerImplTest.java
  • Loading branch information
jochen-vermeulen committed Oct 2, 2024
2 parents 3d26b4a + 78616e5 commit 542b74c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import static eu.europeana.metis.mediaprocessing.RdfXpathConstants.EDM_OBJECT;
import static eu.europeana.metis.mediaprocessing.RdfXpathConstants.EDM_WEBRESOURCE;
import static eu.europeana.metis.mediaprocessing.RdfXpathConstants.SVCS_SERVICE;
import static eu.europeana.metis.mediaprocessing.model.UrlType.HAS_VIEW;
import static eu.europeana.metis.mediaprocessing.model.UrlType.IS_SHOWN_BY;

import eu.europeana.metis.mediaprocessing.exception.RdfDeserializationException;
import eu.europeana.metis.mediaprocessing.model.EnrichedRdf;
Expand Down Expand Up @@ -55,18 +53,16 @@
class RdfDeserializerImpl implements RdfDeserializer {

private static final String OEMBED_NAMESPACE = "https://oembed.com/";
private static final String XPATH_HAS_SERVICE =
"svcs:has_service/@rdf:resource = " + SVCS_SERVICE + "[" +
EDM_WEBRESOURCE + "/svcs:has_service/@rdf:resource = " + SVCS_SERVICE + "/@rdf:about" +
" and dcterms:conformsTo/@rdf:resource = \"" + OEMBED_NAMESPACE + "\"]/@rdf:about";
private static final String XPATH_WEB_RESOURCE =
EDM_WEBRESOURCE + "[" + XPATH_HAS_SERVICE + "]";
private static final String XPATH_OEMBED_SERVICES =
SVCS_SERVICE + "[dcterms:conformsTo/@rdf:resource = \"" + OEMBED_NAMESPACE + "\"]";
private static final String XPATH_OEMBED_WEB_RESOURCES = EDM_WEBRESOURCE
+ "[svcs:has_service/@rdf:resource = " + XPATH_OEMBED_SERVICES + "/@rdf:about]";
private static final String XPATH_IS_OEMBED_RESOURCE_CONDITION = "[. = "
+ XPATH_OEMBED_WEB_RESOURCES + "/@rdf:about]";
private static final String OEMBED_XPATH_CONDITION_IS_SHOWN_BY =
EDM_IS_SHOWN_BY + "[" + EDM_IS_SHOWN_BY + " = " + XPATH_WEB_RESOURCE + "/@rdf:about]";
EDM_IS_SHOWN_BY + XPATH_IS_OEMBED_RESOURCE_CONDITION;
private static final String OEMBED_XPATH_CONDITION_HAS_VIEW =
EDM_HAS_VIEW + "[" + EDM_HAS_VIEW + "=" + XPATH_WEB_RESOURCE + "/@rdf:about]";

private static final Set<UrlType> URL_TYPES_FOR_OEMBED = EnumSet.of(IS_SHOWN_BY, HAS_VIEW);
EDM_HAS_VIEW + XPATH_IS_OEMBED_RESOURCE_CONDITION;

private final UnmarshallingContextWrapper unmarshallingContext = new UnmarshallingContextWrapper();
private final XPathExpressionWrapper getObjectExpression = new XPathExpressionWrapper(
Expand Down Expand Up @@ -215,10 +211,6 @@ private Set<String> getOEmbedUrls(Document document) throws RdfDeserializationEx
.collect(Collectors.toSet());
}

private boolean hasConfigurationForOembed(String url, Set<String> oEmbedUrls) {
return oEmbedUrls.contains(url);
}

@FunctionalInterface
private interface DeserializationOperation<R> {

Expand Down Expand Up @@ -337,9 +329,7 @@ Map<String, ResourceInfo> getResourceEntries(Document document,
final Map<String, ResourceInfo> result = HashMap.newHashMap(urls.size());
final Set<String> oEmbedUrls = getOEmbedUrls(document);
for (Entry<String, Set<UrlType>> entry : urls.entrySet()) {
boolean isConfiguredForOembed =
URL_TYPES_FOR_OEMBED.stream().anyMatch(entry.getValue()::contains) &&
hasConfigurationForOembed(entry.getKey(), oEmbedUrls);
boolean isConfiguredForOembed = oEmbedUrls.contains(entry.getKey());
result.put(entry.getKey(), new ResourceInfo(entry.getValue(), isConfiguredForOembed));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.net.URISyntaxException;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -175,7 +176,7 @@ public static void checkValidWidthAndHeightDimensions(OEmbedModel oEmbedModel, S
public static double getDurationFromModel(OEmbedModel oEmbedModel) {
double duration;
try {
duration = Double.parseDouble(oEmbedModel.getDuration());
duration = Optional.ofNullable(oEmbedModel.getDuration()).map(Double::parseDouble).orElse(0.0);
} catch (NumberFormatException e) {
duration = 0.0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void testGetResourceUrlsFromOEmbedCondition()
final Map<String, ResourceInfo> resultAllTypes = new RdfDeserializerImpl()
.getResourceEntries(document, Set.of(UrlType.values()));

// then check the oEmbedResources where succesfully identified.
// then check the oEmbedResources where successfully identified.
assertEquals(2, resultAllTypes.size());
assertEquals(Collections.singleton(UrlType.HAS_VIEW), resultAllTypes.get(hasView).urlTypes());
assertTrue( resultAllTypes.get(hasView).configuredForOembed());
Expand Down Expand Up @@ -240,18 +240,11 @@ void testGetOEmbeddableObjectsFromSample_NoMatchingService() throws RdfDeseriali

// then
assertEquals(2, rdfResourceEntry.size());
assertTrue(rdfResourceEntry
.stream()
.anyMatch(
r -> r.getResourceUrl().equals("https://vimeo.com/api/oembed.json?url=https%3A%2F%2Fvimeo.com%2F42947250")
&& !r.isResourceConfiguredForOembed()
)
&& rdfResourceEntry
.stream()
.anyMatch(
r -> r.getResourceUrl().equals("http://www.cmcassociates.co.uk/Skara_Brae/landing/sb_pass_pano.html")
&& !r.isResourceConfiguredForOembed()
)
);
assertTrue(rdfResourceEntry.stream().anyMatch(r -> r.getResourceUrl()
.equals("https://vimeo.com/api/oembed.json?url=https%3A%2F%2Fvimeo.com%2F42947250")
&& !r.isResourceConfiguredForOembed()));
assertTrue(rdfResourceEntry.stream().anyMatch(r -> r.getResourceUrl()
.equals("http://www.cmcassociates.co.uk/Skara_Brae/landing/sb_pass_pano.html")
&& !r.isResourceConfiguredForOembed()));
}
}

0 comments on commit 542b74c

Please sign in to comment.