Search in sources :

Example 1 with HasTarget

use of eu.europeana.metis.schema.jibx.HasTarget 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

RecordRelatedIndexingException (eu.europeana.indexing.exception.RecordRelatedIndexingException)1 SetupRelatedIndexingException (eu.europeana.indexing.exception.SetupRelatedIndexingException)1 Aggregation (eu.europeana.metis.schema.jibx.Aggregation)1 Created (eu.europeana.metis.schema.jibx.Created)1 EuropeanaAggregationType (eu.europeana.metis.schema.jibx.EuropeanaAggregationType)1 HasBody (eu.europeana.metis.schema.jibx.HasBody)1 HasQualityAnnotation (eu.europeana.metis.schema.jibx.HasQualityAnnotation)1 HasTarget (eu.europeana.metis.schema.jibx.HasTarget)1 QualityAnnotation (eu.europeana.metis.schema.jibx.QualityAnnotation)1