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

Bug fix/normalize media #119

Merged
merged 5 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 3 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<relativePath/>
<version>3.3.5</version> <!-- lookup parent from repository -->
<version>3.4.1</version> <!-- lookup parent from repository -->
</parent>
<artifactId>handle-manager</artifactId>
<version>0.0.1-SNAPSHOT</version>
Expand All @@ -21,8 +21,8 @@
<testcontainers.version>1.19.8</testcontainers.version>
<apache-commons.version>4.3</apache-commons.version>
<mockito-inline.version>5.2.0</mockito-inline.version>
<mongodb-driver.version>5.1.1</mongodb-driver.version>
<okhttp3.version>4.10.0</okhttp3.version>
<mongodb-driver.version>5.2.1</mongodb-driver.version>
<okhttp3.version>4.12.0</okhttp3.version>
<version.victools>4.35.0</version.victools>
<sonar.coverage.jacoco.xmlReportPaths>
../app-it/target/site/jacoco-aggregate/jacoco.xml
Expand Down Expand Up @@ -252,26 +252,6 @@
<groupId>org.jacoco</groupId>
<version>0.8.7</version>
</plugin>
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>${jooq.version}</version>
<configuration>
<configurationFile>src/main/resources/jooq-configuration.xml</configurationFile>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${glassfish-jaxb.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private UpsertMediaResult processUpsertRequestMedia(
List<DigitalMediaRequestAttributes> mediaRequests) throws JsonProcessingException {
var existingMediaMap = getExistingRecordsFromNormalisedIds(mediaRequests
.stream()
.map(DigitalMediaRequestAttributes::getPrimaryMediaId)
.map(ServiceUtils::normalizeMediaId)
.toList(), PRIMARY_MEDIA_ID.get()
);
var newMedia = new ArrayList<DigitalMediaRequestAttributes>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import static eu.dissco.core.handlemanager.domain.fdo.FdoType.MAS;
import static eu.dissco.core.handlemanager.domain.fdo.FdoType.ORGANISATION;
import static eu.dissco.core.handlemanager.domain.fdo.FdoType.SOURCE_SYSTEM;
import static eu.dissco.core.handlemanager.service.ServiceUtils.normalizeMediaId;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
Expand Down Expand Up @@ -492,7 +493,7 @@ public FdoRecord prepareNewDigitalMediaRecord(DigitalMediaRequestAttributes requ
fdoAttributes.putAll(
prepareGeneratedAttributes(handle, FdoType.DIGITAL_MEDIA, timestamp, isDraft));
fdoAttributes.putAll(prepareGeneratedAttributesDoi(timestamp));
return new FdoRecord(handle, FdoType.DIGITAL_MEDIA, fdoAttributes, request.getPrimaryMediaId(),
return new FdoRecord(handle, FdoType.DIGITAL_MEDIA, fdoAttributes, normalizeMediaId(request),
fdoAttributes.values());
}

Expand All @@ -502,7 +503,7 @@ public FdoRecord prepareUpdatedDigitalMediaRecord(DigitalMediaRequestAttributes
var fdoAttributes = prepareUpdatedDigitalMediaAttributes(request,
previousVersion.handle(), timestamp, previousVersion, incrementVersion);
return new FdoRecord(previousVersion.handle(), FdoType.DIGITAL_MEDIA, fdoAttributes,
request.getPrimaryMediaId(), fdoAttributes.values());
normalizeMediaId(request), fdoAttributes.values());
}

public Map<FdoProfile, FdoAttribute> prepareDigitalMediaAttributes(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eu.dissco.core.handlemanager.service;

import eu.dissco.core.handlemanager.schema.DigitalMediaRequestAttributes;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -22,4 +23,8 @@ private ServiceUtils() {
);
}

public static String normalizeMediaId(DigitalMediaRequestAttributes request) {
return request.getLinkedDigitalObjectPid() + ":" + request.getPrimaryMediaId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this is probably good. Although with this particular issue this wouldn't have solved it as it were multiple images with the same URL for the same linkedDigitalObject. But we will fix that at ingestion so that should never occur again

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

import static com.mongodb.client.model.Filters.eq;
import static com.mongodb.client.model.Filters.in;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.FDO_LOCAL_ID_MEDIA;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.HANDLE;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.HANDLE_ALT;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.MAPPER;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.NORMALISED_PRIMARY_SPECIMEN_OBJECT_ID_TESTVAL;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.PREFIX;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.PRIMARY_MEDIA_ID_TESTVAL;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.givenDigitalMediaFdoRecord;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.givenDigitalSpecimenFdoRecord;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.givenHandleFdoRecord;
Expand Down Expand Up @@ -217,7 +217,7 @@ void testSearchByPrimaryLocalIdMedia() throws Exception {

// When
var result = repository.searchByPrimaryLocalId(FdoProfile.PRIMARY_MEDIA_ID.get(),
List.of(PRIMARY_MEDIA_ID_TESTVAL)).get(0);
List.of(FDO_LOCAL_ID_MEDIA)).get(0);

// Then
assertThat(result.handle()).isEqualTo(expected.handle());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static eu.dissco.core.handlemanager.testUtils.TestUtils.CATALOG_ID_TEST;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.CREATED;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.DOC_BUILDER_FACTORY;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.FDO_LOCAL_ID_MEDIA;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.HANDLE;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.HANDLE_ALT;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.ISSUED_FOR_AGENT_NAME_TESTVAL;
Expand All @@ -19,7 +20,6 @@
import static eu.dissco.core.handlemanager.testUtils.TestUtils.NORMALISED_PRIMARY_SPECIMEN_OBJECT_ID_TESTVAL;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.ORCHESTRATION_URL;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.PREFIX;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.PRIMARY_MEDIA_ID_TESTVAL;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.ROR_DOMAIN;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.ROR_IDENTIFIER;
import static eu.dissco.core.handlemanager.testUtils.TestUtils.SPECIMEN_HOST_NAME_TESTVAL;
Expand Down Expand Up @@ -315,7 +315,7 @@ void testPrepareNewMediaRecordMin() throws Exception {
void testPrepareUpdatedMediaRecord() throws Exception {
// Given
var previousVersion = givenDigitalMediaFdoRecord(HANDLE);
var expected = givenUpdatedFdoRecord(FdoType.DIGITAL_MEDIA, PRIMARY_MEDIA_ID_TESTVAL);
var expected = givenUpdatedFdoRecord(FdoType.DIGITAL_MEDIA, FDO_LOCAL_ID_MEDIA);
var request = givenDigitalMediaUpdated();

// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public class TestUtils {
public static final String MEDIA_HOST_NAME_TESTVAL = SPECIMEN_HOST_NAME_TESTVAL;
public static final String LINKED_DO_PID_TESTVAL = HANDLE;
public static final String PRIMARY_MEDIA_ID_TESTVAL = "https://images.com/ABC";
public static final String FDO_LOCAL_ID_MEDIA = HANDLE + ":" + PRIMARY_MEDIA_ID_TESTVAL;
// Mappings
public static final String SOURCE_DATA_STANDARD_TESTVAL = "dwc";
// MAS
Expand Down Expand Up @@ -398,7 +399,7 @@ public static FdoRecord givenMongoResponse(String handle, FdoType fdoType, Strin

public static FdoRecord givenDigitalMediaFdoRecord(String handle) throws Exception {
var attributes = genDigitalMediaAttributes(handle, CREATED);
return new FdoRecord(handle, DIGITAL_MEDIA, attributes, PRIMARY_MEDIA_ID_TESTVAL,
return new FdoRecord(handle, DIGITAL_MEDIA, attributes, FDO_LOCAL_ID_MEDIA,
attributes.values());
}

Expand Down Expand Up @@ -959,15 +960,17 @@ private static List<XmlElement> defaultLocations(String handle, FdoType type, bo
locations.add(
new XmlElement(i.getAndIncrement(), "1", UI_URL + "/dm/" + handle, "HTML"));
locations.add(
new XmlElement(i.getAndIncrement(), "0", API_URL + "/digital-media/v1/" + handle, "JSON"));
new XmlElement(i.getAndIncrement(), "0", API_URL + "/digital-media/v1/" + handle,
"JSON"));
if (addKeyLoc) {
locations.add(
new XmlElement(i.getAndIncrement(), "0", PRIMARY_MEDIA_ID_TESTVAL, "MEDIA"));
}
}
case ANNOTATION -> {
locations.add(
new XmlElement(i.getAndIncrement(), "1", API_URL + "/annotations/v1/" + handle, "JSON"));
new XmlElement(i.getAndIncrement(), "1", API_URL + "/annotations/v1/" + handle,
"JSON"));
}
case ORGANISATION -> {
if (addKeyLoc) {
Expand Down
Loading