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

MET-5632 update tier representation in mongo #645

Merged
merged 5 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package eu.europeana.indexing.fullbean;
jeortizquan marked this conversation as resolved.
Show resolved Hide resolved

import eu.europeana.corelib.definitions.edm.entity.AbstractEdmEntity;
import eu.europeana.corelib.definitions.edm.entity.QualityAnnotation;
import eu.europeana.corelib.solr.entity.EuropeanaAggregationImpl;
import eu.europeana.metis.schema.jibx.EuropeanaAggregationType;
import eu.europeana.metis.schema.jibx.ResourceType;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;

Expand Down Expand Up @@ -63,13 +61,6 @@ public EuropeanaAggregationImpl apply(EuropeanaAggregationType aggregation) {
.map(ResourceType::getResource).orElse(null);
mongoAggregation.setEdmPreview(edmPreview);

// << to be updated with mongo parent ticket MET-5631
mongoAggregation.setDqvHasQualityAnnotation(
qualityAnnotations.stream()
.filter(Objects::nonNull)
.map(AbstractEdmEntity::getAbout)
.toArray(String[]::new));
// << to be updated with mongo parent ticket MET-5631
return mongoAggregation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,9 @@
public class QualityAnnotationFieldInput implements
Function<QualityAnnotation, QualityAnnotationImpl> {

private final String about;

public QualityAnnotationFieldInput(String about) {
this.about = about;
}

@Override
public QualityAnnotationImpl apply(QualityAnnotation qualityAnnotation) {
QualityAnnotationImpl qualityAnnotationImpl = new QualityAnnotationImpl();
final String aboutTierSuffix = qualityAnnotation.getHasBody()
.getResource()
.startsWith("http://www.europeana.eu/schemas/epf/metadataTier") ?
"#metadataTier" : "#contentTier";

qualityAnnotationImpl.setAbout("/item" + about + aboutTierSuffix);
qualityAnnotationImpl.setCreated(
Optional.ofNullable(qualityAnnotation.getCreated()).map(ResourceOrLiteralType::getString)
.orElse(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static Date convertToDate(String dateString) {
return Date.from(Instant.from(DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(dateString)));
}

private static <S, T> List<T> convertList(List<S> sourceList, Function<S, T> converter,
protected static <S, T> List<T> convertList(List<S> sourceList, Function<S, T> converter,
jeortizquan marked this conversation as resolved.
Show resolved Hide resolved
boolean returnNullIfEmpty) {
final List<T> result = sourceList.stream().map(converter).collect(Collectors.toList());
if (result.isEmpty() && returnNullIfEmpty) {
Expand All @@ -50,7 +50,7 @@ private static <S, T> List<T> convertList(List<S> sourceList, Function<S, T> con
return result;
}

private static List<QualityAnnotation> getQualityAnnotations(RdfWrapper rdfWrappedRecord) {
protected static List<QualityAnnotation> getQualityAnnotations(RdfWrapper rdfWrappedRecord) {
return rdfWrappedRecord.getAggregations()
.stream()
.flatMap(qa -> {
Expand Down Expand Up @@ -88,11 +88,8 @@ public FullBeanImpl convertRdfToFullBean(RdfWrapper record) {
fullBean.setOrganizations(convertList(record.getOrganizations(), new OrganizationFieldInput(), false));
fullBean.setLicenses(convertList(record.getLicenses(), new LicenseFieldInput(), false));
fullBean.setServices(convertList(record.getServices(), new ServiceFieldInput(), false));
// >> this will be updated in a next ticket the mongo part parent ticket MET-5631
var qualityAnnotationsList = convertList(getQualityAnnotations(record), new QualityAnnotationFieldInput(record.getAbout()),
false);
var qualityAnnotationsList = convertList(getQualityAnnotations(record), new QualityAnnotationFieldInput(), false);
fullBean.setQualityAnnotations(qualityAnnotationsList);
// << this will be updated in a next ticket the mongo part parent ticket MET-5631

// Set properties related to the Europeana aggregation
fullBean.setEuropeanaCollectionName(new String[]{record.getDatasetName()});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package eu.europeana.indexing.fullbean;

import static eu.europeana.indexing.fullbean.RdfToFullBeanConverter.convertList;
import static eu.europeana.indexing.fullbean.RdfToFullBeanConverter.getQualityAnnotations;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;

import eu.europeana.corelib.definitions.edm.entity.EuropeanaAggregation;
import eu.europeana.indexing.base.IndexingTestUtils;
import eu.europeana.indexing.utils.RdfWrapper;
import eu.europeana.metis.schema.convert.RdfConversionUtils;
import eu.europeana.metis.schema.convert.SerializationException;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;

class EuropeanaAggregationFieldInputTest {

private EuropeanaAggregationFieldInput europeanaAggregationFieldInput;

@Test
void apply() throws SerializationException {
final RdfConversionUtils conversionUtils = new RdfConversionUtils();
final RdfWrapper inputRdf = new RdfWrapper(conversionUtils.convertStringToRdf(
IndexingTestUtils.getResourceFileContent("europeana_record_rdf.xml")));
europeanaAggregationFieldInput = new EuropeanaAggregationFieldInput(
convertList(getQualityAnnotations(inputRdf), new QualityAnnotationFieldInput(), false));

List<EuropeanaAggregation> aggregationList = inputRdf.getEuropeanaAggregation().stream()
.map(a -> europeanaAggregationFieldInput.apply(a))
.collect(Collectors.toList());

assertFalse(aggregationList.isEmpty());
assertEquals("/aggregation/europeana/277/CMC_HA_1185", aggregationList.getFirst().getAbout());
assertEquals("/277/CMC_HA_1185", aggregationList.getFirst().getAggregatedCHO());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package eu.europeana.indexing.fullbean;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import eu.europeana.corelib.solr.entity.QualityAnnotationImpl;
import eu.europeana.metis.schema.jibx.Created;
import eu.europeana.metis.schema.jibx.HasBody;
import eu.europeana.metis.schema.jibx.HasTarget;
import eu.europeana.metis.schema.jibx.QualityAnnotation;
import eu.europeana.metis.schema.jibx.ResourceOrLiteralType.ConfidenceLevel;
import eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Lang;
import eu.europeana.metis.schema.jibx.ResourceOrLiteralType.Resource;
import eu.europeana.metis.schema.jibx.ResourceOrLiteralType.WasGeneratedBy;
import java.math.BigDecimal;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Test;

class QualityAnnotationFieldInputTest {

@NotNull
private static QualityAnnotation getQualityAnnotation() {
QualityAnnotation qualityAnnotation = new QualityAnnotation();
qualityAnnotation.setCreated(getCreated());
HasBody hasBody = new HasBody();
hasBody.setResource("bodyResource");
HasTarget hasTarget = new HasTarget();
hasTarget.setResource("targetResource");
qualityAnnotation.setHasBody(hasBody);
qualityAnnotation.setHasTargetList(List.of(hasTarget));
return qualityAnnotation;
}

@NotNull
private static Created getCreated() {
Created created = new Created();
Lang lang = new Lang();
lang.setLang("NL");
created.setLang(lang);
created.setString("created");
Resource resource = new Resource();
resource.setResource("resource");
created.setResource(resource);
ConfidenceLevel confidenceLevel = new ConfidenceLevel();
confidenceLevel.setConfidenceLevel(BigDecimal.TEN);
created.setConfidenceLevel(confidenceLevel);
WasGeneratedBy wasGeneratedBy = new WasGeneratedBy();
wasGeneratedBy.setWasGeneratedBy("generatedBy");
created.setWasGeneratedBy(wasGeneratedBy);
return created;
}

@Test
void apply() {
QualityAnnotationFieldInput qualityAnnotationFieldInput = new QualityAnnotationFieldInput();

QualityAnnotationImpl qualityAnnotationResult = qualityAnnotationFieldInput.apply(getQualityAnnotation());

assertNotNull(qualityAnnotationResult);
assertNull(qualityAnnotationResult.getAbout());
assertEquals("created", qualityAnnotationResult.getCreated());
assertEquals("bodyResource", qualityAnnotationResult.getBody());
assertEquals("targetResource", qualityAnnotationResult.getTarget()[0]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package eu.europeana.indexing.fullbean;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import eu.europeana.corelib.solr.bean.impl.FullBeanImpl;
import eu.europeana.indexing.base.IndexingTestUtils;
import eu.europeana.indexing.utils.RdfWrapper;
import eu.europeana.metis.schema.convert.RdfConversionUtils;
import eu.europeana.metis.schema.convert.SerializationException;
import org.junit.jupiter.api.Test;

class RdfToFullBeanConverterTest {

@Test
void convertRdfToFullBean() throws SerializationException {
RdfToFullBeanConverter rdfToFullBeanConverter = new RdfToFullBeanConverter();
final RdfConversionUtils conversionUtils = new RdfConversionUtils();
final RdfWrapper inputRdf = new RdfWrapper(conversionUtils.convertStringToRdf(
IndexingTestUtils.getResourceFileContent("europeana_record_rdf.xml")));

FullBeanImpl fullBean = rdfToFullBeanConverter.convertRdfToFullBean(inputRdf);

assertAbout(fullBean);
assertAgents(fullBean);
assertAggregations(fullBean);
assertConcepts(fullBean);
assertEuropeanaAggregation(fullBean);
assertEuropeanaCollection(fullBean);
assertLicenses(fullBean);
assertOrganizations(fullBean);
assertPlaces(fullBean);
assertProvidedCHOs(fullBean);
assertProxies(fullBean);
assertQualityAnnotations(fullBean);
assertServices(fullBean);
assertSizes(fullBean);
assertTimeSpans(fullBean);
assertTimestamps(fullBean);
}

private static void assertTimestamps(FullBeanImpl fullBean) {
assertEquals("1970-01-01T00:00:00Z", fullBean.getTimestampCreated().toInstant().toString());
assertEquals("1970-01-01T00:00:00Z", fullBean.getTimestampUpdated().toInstant().toString());
}

private static void assertAbout(FullBeanImpl fullBean) {
assertEquals("/277/CMC_HA_1185", fullBean.getAbout());
}

private static void assertEuropeanaCollection(FullBeanImpl fullBean) {
assertEquals("277_local_09012024_1543", fullBean.getEuropeanaCollectionName()[0]);
}

private static void assertProxies(FullBeanImpl fullBean) {
assertEquals("/proxy/europeana/277/CMC_HA_1185", fullBean.getProxies().get(0).getAbout());
jeortizquan marked this conversation as resolved.
Show resolved Hide resolved
assertEquals("/proxy/provider/277/CMC_HA_1185", fullBean.getProxies().get(1).getAbout());
}

private static void assertAgents(FullBeanImpl fullBean) {
assertNotNull(fullBean.getAgents());
assertEquals(0, fullBean.getAgents().size());
}

private static void assertLicenses(FullBeanImpl fullBean) {
assertNotNull(fullBean.getLicenses());
assertEquals(0, fullBean.getLicenses().size());
}

private static void assertServices(FullBeanImpl fullBean) {
assertNotNull(fullBean.getServices());
assertEquals(0, fullBean.getServices().size());
}

private static void assertQualityAnnotations(FullBeanImpl fullBean) {
assertNotNull(fullBean.getQualityAnnotations());
assertEquals(0, fullBean.getQualityAnnotations().size());
}

private static void assertProvidedCHOs(FullBeanImpl fullBean) {
assertEquals("/277/CMC_HA_1185", fullBean.getProvidedCHOs().getFirst().getAbout());
assertEquals(0, fullBean.getProvidedCHOs().getFirst().getOwlSameAs().length);
}

private static void assertEuropeanaAggregation(FullBeanImpl fullBean) {
assertNotNull(fullBean.getEuropeanaAggregation());
assertEquals("http://www.cmcassociates.co.uk/Skara_Brae/images/panorama_photos/link7-8grassyknoll/_I2P1856_th.jpg",
fullBean.getEuropeanaAggregation().getEdmPreview());
assertEquals("/aggregation/europeana/277/CMC_HA_1185", fullBean.getEuropeanaAggregation().getAbout());
assertNull(fullBean.getEuropeanaAggregation().getDqvHasQualityAnnotation());
}

private static void assertAggregations(FullBeanImpl fullBean) {
assertEquals("http://www.cmcassociates.co.uk/Skara_Brae/images/panorama_photos/link7-8grassyknoll/_I2P1856.JPG",
fullBean.getAggregations().getFirst().getEdmIsShownBy());
assertEquals("http://www.cmcassociates.co.uk/Skara_Brae/landing/sb_pass_photo.html",
fullBean.getAggregations().getFirst().getEdmIsShownAt());
assertEquals("http://www.cmcassociates.co.uk/Skara_Brae/images/panorama_photos/link7-8grassyknoll/_I2P1856_th.jpg",
fullBean.getAggregations().getFirst().getEdmObject());
assertEquals("/aggregation/provider/277/CMC_HA_1185", fullBean.getAggregations().getFirst().getAbout());
}

private static void assertConcepts(FullBeanImpl fullBean) {
assertEquals("http://vocab.getty.edu/aat/300000810", fullBean.getConcepts().get(0).getAbout());
assertEquals("http://vocab.getty.edu/aat/300008372", fullBean.getConcepts().get(1).getAbout());
assertEquals("http://data.europeana.eu/concept/48", fullBean.getConcepts().get(2).getAbout());
assertEquals("http://data.europeana.eu/concept/25", fullBean.getConcepts().get(3).getAbout());
}

private static void assertOrganizations(FullBeanImpl fullBean) {
assertEquals("http://data.europeana.eu/organization/1482250000004502043", fullBean.getOrganizations().get(0).getAbout());
assertEquals("http://data.europeana.eu/organization/1482250000004671084", fullBean.getOrganizations().get(1).getAbout());
}

private static void assertTimeSpans(FullBeanImpl fullBean) {
assertEquals("HA/1185#timespan", fullBean.getTimespans().get(0).getAbout());
assertEquals("#19XX", fullBean.getTimespans().get(1).getAbout());
assertEquals("http://data.europeana.eu/timespan/20", fullBean.getTimespans().get(2).getAbout());
}

private static void assertSizes(FullBeanImpl fullBean) {
assertEquals(10, fullBean.getEuropeanaCompleteness());
assertEquals(2, fullBean.getOrganizations().size());
assertEquals(0, fullBean.getAgents().size());
assertEquals(3, fullBean.getTimespans().size());
assertEquals(4, fullBean.getConcepts().size());
assertEquals(1, fullBean.getAggregations().size());
assertEquals(1, fullBean.getProvidedCHOs().size());
assertEquals(2, fullBean.getProxies().size());
assertEquals(0, fullBean.getLicenses().size());
assertEquals(0, fullBean.getServices().size());
assertEquals(0, fullBean.getQualityAnnotations().size());
}

private static void assertPlaces(FullBeanImpl fullBean) {
assertEquals("iid:6744/SP.1", fullBean.getPlaces().getFirst().getAbout());
assertEquals(59.04861f, fullBean.getPlaces().getFirst().getLatitude());
assertEquals(-3.343056f, fullBean.getPlaces().getFirst().getLongitude());
assertEquals(7.0f, fullBean.getPlaces().getFirst().getAltitude());
}
}
Loading