Search in sources :

Example 1 with Aggregation

use of eu.europeana.metis.schema.jibx.Aggregation in project metis-framework by europeana.

the class RdfWrapperTest method testGetFirstResourceOfType.

@Test
void testGetFirstResourceOfType() {
    // Setup tests - create RDF and aggregations
    final Aggregation firstAggregation = new Aggregation();
    final Aggregation middleAggregation = new Aggregation();
    final Aggregation lastAggregation = new Aggregation();
    final RDF rdf = new RDF();
    rdf.setAggregationList(Arrays.asList(null, firstAggregation, middleAggregation, lastAggregation));
    final RdfWrapper instance = new RdfWrapper(rdf);
    // Test - try with non-existing values
    assertFalse(instance.getFirstResourceOfType(UrlType.OBJECT).isPresent());
    assertFalse(instance.getFirstResourceOfType(UrlType.HAS_VIEW).isPresent());
    assertFalse(instance.getFirstResourceOfType(UrlType.IS_SHOWN_AT).isPresent());
    assertFalse(instance.getFirstResourceOfType(UrlType.IS_SHOWN_BY).isPresent());
    // Setup tests - object links
    final String firstObject = "firstObject";
    final String lastObject = "lastObject";
    firstAggregation.setObject(new _Object());
    firstAggregation.getObject().setResource(firstObject);
    middleAggregation.setObject(new _Object());
    middleAggregation.getObject().setResource(lastObject);
    lastAggregation.setObject(null);
    // Setup tests - hasView links
    final String firstHasView = "firstHasView";
    final String middleHasView = "middleHasView";
    final String lastHasView = "lastHasView";
    firstAggregation.setHasViewList(null);
    middleAggregation.setHasViewList(Arrays.asList(null, new HasView(), new HasView(), new HasView()));
    middleAggregation.getHasViewList().get(2).setResource(firstHasView);
    middleAggregation.getHasViewList().get(3).setResource(middleHasView);
    lastAggregation.setHasViewList(Collections.singletonList(new HasView()));
    lastAggregation.getHasViewList().get(0).setResource(lastHasView);
    // Setup tests - isShownAt links
    final String firstIsShownAt = "firstIsShownAt";
    final String lastIsShownAt = "lastIsShownAt";
    firstAggregation.setIsShownAt(new IsShownAt());
    middleAggregation.setIsShownAt(new IsShownAt());
    middleAggregation.getIsShownAt().setResource(firstIsShownAt);
    lastAggregation.setIsShownAt(new IsShownAt());
    lastAggregation.getIsShownAt().setResource(lastIsShownAt);
    // Setup tests - isShownBy links
    final String firstIsShownBy = "firstIsShownBy";
    final String lastIsShownBy = "lastIsShownBy";
    firstAggregation.setIsShownBy(new IsShownBy());
    firstAggregation.getIsShownBy().setResource(" ");
    middleAggregation.setIsShownBy(new IsShownBy());
    middleAggregation.getIsShownBy().setResource(firstIsShownBy);
    lastAggregation.setIsShownBy(new IsShownBy());
    lastAggregation.getIsShownBy().setResource(lastIsShownBy);
    // Test - try with existing values
    assertEquals(firstObject, instance.getFirstResourceOfType(UrlType.OBJECT).orElse(null));
    assertEquals(firstHasView, instance.getFirstResourceOfType(UrlType.HAS_VIEW).orElse(null));
    assertEquals(firstIsShownAt, instance.getFirstResourceOfType(UrlType.IS_SHOWN_AT).orElse(null));
    assertEquals(firstIsShownBy, instance.getFirstResourceOfType(UrlType.IS_SHOWN_BY).orElse(null));
}
Also used : Aggregation(eu.europeana.metis.schema.jibx.Aggregation) IsShownAt(eu.europeana.metis.schema.jibx.IsShownAt) RDF(eu.europeana.metis.schema.jibx.RDF) IsShownBy(eu.europeana.metis.schema.jibx.IsShownBy) eu.europeana.metis.schema.jibx._Object(eu.europeana.metis.schema.jibx._Object) HasView(eu.europeana.metis.schema.jibx.HasView) Test(org.junit.jupiter.api.Test)

Example 2 with Aggregation

use of eu.europeana.metis.schema.jibx.Aggregation in project metis-framework by europeana.

the class EnrichmentUtilsTest method testSetAdditionalDataCompletenessMoreThanZero.

@Test
void testSetAdditionalDataCompletenessMoreThanZero() {
    Aggregation aggregation = spy(new Aggregation());
    Choice dateChoice = new Choice();
    Date date = new Date();
    Choice titleChoice = new Choice();
    Title title = new Title();
    date.setString("1990");
    dateChoice.setDate(date);
    title.setString("The Sudbury Neutrino Observatory: Observation of Flavor Change for Solar Neutrinos");
    titleChoice.setTitle(title);
    ArrayList<Choice> choices = new ArrayList<>();
    choices.add(dateChoice);
    choices.add(titleChoice);
    PROXY_PROVIDER.setChoiceList(choices);
    ArrayList<ProxyType> proxyList = new ArrayList<>();
    proxyList.add(PROXY_EUROPEANA);
    proxyList.add(PROXY_PROVIDER);
    TEST_RDF.setProxyList(proxyList);
    _Object object = new _Object();
    object.setResource("/260/_kmo_av_sid_45006");
    doReturn(object).when(aggregation).getObject();
    doReturn(Collections.singletonList(aggregation)).when(TEST_RDF).getAggregationList();
    EnrichmentUtils.setAdditionalData(TEST_RDF);
    EuropeanaAggregationType aggregationTypeResult = TEST_RDF.getEuropeanaAggregationList().get(0);
    assertTrue(Integer.parseInt(aggregationTypeResult.getCompleteness().getString()) > 0);
}
Also used : Aggregation(eu.europeana.metis.schema.jibx.Aggregation) Choice(eu.europeana.metis.schema.jibx.EuropeanaType.Choice) ArrayList(java.util.ArrayList) Title(eu.europeana.metis.schema.jibx.Title) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) eu.europeana.metis.schema.jibx._Object(eu.europeana.metis.schema.jibx._Object) EuropeanaAggregationType(eu.europeana.metis.schema.jibx.EuropeanaAggregationType) Date(eu.europeana.metis.schema.jibx.Date) Test(org.junit.jupiter.api.Test)

Example 3 with Aggregation

use of eu.europeana.metis.schema.jibx.Aggregation in project metis-framework by europeana.

the class EnrichmentUtilsTest method setUp.

@BeforeEach
void setUp() {
    EuropeanaProxy europeanaProxy = new EuropeanaProxy();
    EuropeanaProxy providerProxy = new EuropeanaProxy();
    europeanaProxy.setEuropeanaProxy(true);
    providerProxy.setEuropeanaProxy(false);
    PROXY_EUROPEANA.setAbout("/proxy/europeana/260/_kmo_av_sid_45006");
    PROXY_EUROPEANA.setEuropeanaProxy(europeanaProxy);
    PROXY_PROVIDER.setAbout("/proxy/provider/260/_kmo_av_sid_45006");
    PROXY_PROVIDER.setEuropeanaProxy(providerProxy);
    EUROPEANA_AGGREGATION_TYPE.setAbout("/aggregation/europeana/260/_kmo_av_sid_45006");
    TEST_RDF.setEuropeanaAggregationList(Collections.singletonList(EUROPEANA_AGGREGATION_TYPE));
    doReturn(Collections.singletonList(new Aggregation())).when(TEST_RDF).getAggregationList();
}
Also used : Aggregation(eu.europeana.metis.schema.jibx.Aggregation) EuropeanaProxy(eu.europeana.metis.schema.jibx.EuropeanaProxy) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with Aggregation

use of eu.europeana.metis.schema.jibx.Aggregation in project metis-framework by europeana.

the class RdfEntityUtils method replaceValueWithLinkInAggregation.

/**
 * Replace matching aggregation values with their found corresponding links.
 *
 * @param rdf the rdf to update
 * @param link the about value to use
 * @param searchTermAggregation the aggregation search term to use for finding the matched values
 */
public static void replaceValueWithLinkInAggregation(RDF rdf, String link, SearchTermContext searchTermAggregation) {
    final List<Aggregation> aggregationList = rdf.getAggregationList();
    for (FieldType<? extends AboutType> aggregationFieldType : searchTermAggregation.getFieldTypes()) {
        aggregationList.stream().flatMap(((AggregationFieldType) aggregationFieldType)::extractFields).filter(resourceOrLiteralType -> resourceOrLiteralAndSearchTermEquality(resourceOrLiteralType, searchTermAggregation)).forEach(resourceOrLiteralType -> {
            final Resource resource = new Resource();
            resource.setResource(link);
            resourceOrLiteralType.setResource(resource);
            resourceOrLiteralType.setLang(new Lang());
            resourceOrLiteralType.setString("");
        });
    }
}
Also used : Aggregation(eu.europeana.metis.schema.jibx.Aggregation) Arrays(java.util.Arrays) AggregationFieldType(eu.europeana.enrichment.api.internal.AggregationFieldType) SearchTerm(eu.europeana.enrichment.api.internal.SearchTerm) RDF(eu.europeana.metis.schema.jibx.RDF) Supplier(java.util.function.Supplier) StringUtils(org.apache.commons.lang3.StringUtils) Aggregation(eu.europeana.metis.schema.jibx.Aggregation) ResourceOrLiteralType(eu.europeana.metis.schema.jibx.ResourceOrLiteralType) ArrayList(java.util.ArrayList) ProxyFieldType(eu.europeana.enrichment.api.internal.ProxyFieldType) AboutType(eu.europeana.metis.schema.jibx.AboutType) Lang(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Lang) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) FieldType(eu.europeana.enrichment.api.internal.FieldType) SearchTermContext(eu.europeana.enrichment.api.internal.SearchTermContext) Map(java.util.Map) EuropeanaType(eu.europeana.metis.schema.jibx.EuropeanaType) EnumMap(java.util.EnumMap) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) ProxyType(eu.europeana.metis.schema.jibx.ProxyType) Optional(java.util.Optional) Collections(java.util.Collections) Resource(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource) Lang(eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Lang)

Example 5 with Aggregation

use of eu.europeana.metis.schema.jibx.Aggregation in project metis-framework by europeana.

the class RdfTierUtils method setTierInternal.

private static void setTierInternal(RDF rdf, Tier tier) throws IndexingException {
    // Get the right instance of RdfTier.
    final RdfTier rdfTier = tiersByValue.get(tier);
    if (rdfTier == null) {
        throw new SetupRelatedIndexingException("Cannot find settings for tier value " + tier.getClass());
    }
    // Determine if there is something to reference and somewhere to add the reference.
    final RdfWrapper rdfWrapper = new RdfWrapper(rdf);
    final Set<String> aggregationAbouts = rdfWrapper.getAggregations().stream().filter(Objects::nonNull).map(Aggregation::getAbout).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
    if (aggregationAbouts.isEmpty()) {
        throw new RecordRelatedIndexingException("Cannot find provider aggregation in record.");
    }
    final EuropeanaAggregationType europeanaAggregation = rdfWrapper.getEuropeanaAggregation().orElseThrow(() -> new RecordRelatedIndexingException("Cannot find Europeana aggregation in record."));
    final String choAbout = Optional.ofNullable(europeanaAggregation.getAggregatedCHO()).map(AggregatedCHO::getResource).orElseThrow(() -> new RecordRelatedIndexingException("Cannot find aggregated CHO in Europeana aggregation."));
    final String annotationAboutBase = "/item" + choAbout;
    // Create the annotation
    final QualityAnnotation annotation = new QualityAnnotation();
    final Created created = new Created();
    created.setString(Instant.now().toString());
    annotation.setCreated(created);
    annotation.setHasTargetList(aggregationAbouts.stream().map(about -> {
        final HasTarget hasTarget = new HasTarget();
        hasTarget.setResource(about);
        return hasTarget;
    }).collect(Collectors.toList()));
    final HasBody hasBody = new HasBody();
    hasBody.setResource(rdfTier.getUri());
    annotation.setHasBody(hasBody);
    annotation.setAbout(annotationAboutBase + rdfTier.getAboutSuffix());
    // Add the annotation (remove all annotations with the same about)
    final Stream<QualityAnnotation> existingAnnotations = rdfWrapper.getQualityAnnotations().stream().filter(existingAnnotation -> !annotation.getAbout().equals(existingAnnotation.getAbout()));
    rdf.setQualityAnnotationList(Stream.concat(existingAnnotations, Stream.of(annotation)).collect(Collectors.toList()));
    // Add the link to the annotation to the europeana aggregation.
    final HasQualityAnnotation link = new HasQualityAnnotation();
    link.setResource(annotation.getAbout());
    final Stream<HasQualityAnnotation> existingLinks = Optional.ofNullable(europeanaAggregation.getHasQualityAnnotationList()).stream().flatMap(Collection::stream).filter(existingLink -> !link.getResource().equals(existingLink.getResource()));
    europeanaAggregation.setHasQualityAnnotationList(Stream.concat(existingLinks, Stream.of(link)).collect(Collectors.toList()));
}
Also used : HasQualityAnnotation(eu.europeana.metis.schema.jibx.HasQualityAnnotation) HasBody(eu.europeana.metis.schema.jibx.HasBody) SetupRelatedIndexingException(eu.europeana.indexing.exception.SetupRelatedIndexingException) HasTarget(eu.europeana.metis.schema.jibx.HasTarget) Created(eu.europeana.metis.schema.jibx.Created) Aggregation(eu.europeana.metis.schema.jibx.Aggregation) RecordRelatedIndexingException(eu.europeana.indexing.exception.RecordRelatedIndexingException) HasQualityAnnotation(eu.europeana.metis.schema.jibx.HasQualityAnnotation) QualityAnnotation(eu.europeana.metis.schema.jibx.QualityAnnotation) EuropeanaAggregationType(eu.europeana.metis.schema.jibx.EuropeanaAggregationType)

Aggregations

Aggregation (eu.europeana.metis.schema.jibx.Aggregation)5 EuropeanaAggregationType (eu.europeana.metis.schema.jibx.EuropeanaAggregationType)2 ProxyType (eu.europeana.metis.schema.jibx.ProxyType)2 RDF (eu.europeana.metis.schema.jibx.RDF)2 eu.europeana.metis.schema.jibx._Object (eu.europeana.metis.schema.jibx._Object)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 AggregationFieldType (eu.europeana.enrichment.api.internal.AggregationFieldType)1 FieldType (eu.europeana.enrichment.api.internal.FieldType)1 ProxyFieldType (eu.europeana.enrichment.api.internal.ProxyFieldType)1 SearchTerm (eu.europeana.enrichment.api.internal.SearchTerm)1 SearchTermContext (eu.europeana.enrichment.api.internal.SearchTermContext)1 RecordRelatedIndexingException (eu.europeana.indexing.exception.RecordRelatedIndexingException)1 SetupRelatedIndexingException (eu.europeana.indexing.exception.SetupRelatedIndexingException)1 AboutType (eu.europeana.metis.schema.jibx.AboutType)1 Created (eu.europeana.metis.schema.jibx.Created)1 Date (eu.europeana.metis.schema.jibx.Date)1 EuropeanaProxy (eu.europeana.metis.schema.jibx.EuropeanaProxy)1 EuropeanaType (eu.europeana.metis.schema.jibx.EuropeanaType)1 Choice (eu.europeana.metis.schema.jibx.EuropeanaType.Choice)1