Skip to content
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* DELETE_INCOMING repeatable field action not removing duplicate scalar values from string arrays ([MODDICORE-507](https://folio-org.atlassian.net/browse/MODDICORE-507))
* Fix 035 being split on update when same $a in incoming and existing ([MODSOURCE-1014](https://folio-org.atlassian.net/browse/MODSOURCE-1014))
* Fix StringIndexOutOfBoundsException and NPE when the target subfield is empty in a field mapping profile
* Fix only the last incoming value being kept when "Delete all existing and add these" is applied to an initially empty repeatable field ([MODDICORE-516](https://folio-org.atlassian.net/browse/MODDICORE-516))

### Tech Dept
* Migrate tests from JUnit 4 to JUnit 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ private void setRepeatableValueByAction(RepeatableFieldValue value, String repea
setValueByFieldPath(repeatableFieldPath, currentObject);
break;
case EXCHANGE_EXISTING:
if (!value.isAlreadyRemovedForExchange() && pathObject != null && !pathObject.isEmpty()) {
findAndRemoveTheMostNestedFieldIfNeeded(currentPath, true);
if (!value.isAlreadyRemovedForExchange()) {
if (pathObject != null && !pathObject.isEmpty()) {
findAndRemoveTheMostNestedFieldIfNeeded(currentPath, true);
}
value.setAlreadyRemovedForExchange(true);
}
setValueByFieldPath(repeatableFieldPath, currentObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
import org.folio.processing.value.Value;
import org.folio.rest.jaxrs.model.EntityType;
import org.folio.rest.jaxrs.model.MappingRule;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

class JsonBasedWriterUnitTest {
private static final JsonBasedWriter WRITER = new JsonBasedWriter(EntityType.INSTANCE);
Expand Down Expand Up @@ -328,6 +330,38 @@ void shouldWrite_RepeatableExchangeValues() throws IOException {
assertEquals(expectedInstance, resultInstance);
}

@DisplayName("should write all incoming values when exchanging existing, whatever the existing content")
@ParameterizedTest
@ValueSource(strings = {
"{\"item\":{\"electronicAccess\":[]}}",
"{\"item\":{\"electronicAccess\":[{\"uri\":\"http://old\"}]}}"
})
void shouldWriteAllIncomingValues_whenExchangeExisting(String existingItem) throws IOException {
// arrange
DataImportEventPayload eventContext = new DataImportEventPayload();
HashMap<String, String> context = new HashMap<>();
context.put(EntityType.ITEM.value(), existingItem);
eventContext.setContext(context);
JsonBasedWriter writer = new JsonBasedWriter(EntityType.ITEM);

Map<String, Value> link1 = new HashMap<>();
link1.put("item.electronicAccess[].uri", StringValue.of("http://url1"));
Map<String, Value> link2 = new HashMap<>();
link2.put("item.electronicAccess[].uri", StringValue.of("http://url2"));
RepeatableFieldValue field =
RepeatableFieldValue.of(List.of(link1, link2), EXCHANGE_EXISTING, "electronicAccess");

// act
writer.initialize(eventContext);
writer.write("item.electronicAccess[]", field);
writer.getResult(eventContext);

// assert
String expectedItem =
"{\"item\":{\"electronicAccess\":[{\"uri\":\"http://url1\"},{\"uri\":\"http://url2\"}]}}";
assertEquals(expectedItem, eventContext.getContext().get(EntityType.ITEM.value()));
}

@Test
void shouldWrite_RepeatableExtendValues() throws IOException {
// given
Expand Down Expand Up @@ -493,7 +527,8 @@ void shouldNotChangeContext_RepeatableExchangeValuesIfEntityIsEmpty() throws IOE
// then
String expectedInstance =
"""
{"instance":{"contributor":[{"active":true,"names":["1","2","3"],"id":"UUID2"}]}}\
{"instance":{"contributor":[{"active":false,"names":["Heins","Rattu","Tabrani"],"id":"UUID"},\
{"active":true,"names":["1","2","3"],"id":"UUID2"}]}}\
""";
String resultInstance = eventContext.getContext().get(EntityType.INSTANCE.value());
assertEquals(expectedInstance, resultInstance);
Expand Down
Loading