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
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,4 @@ void shouldDetectFieldChangesInInnerObjectCollectionAndInnerObject() {
private static Map<String, Object> getMap(Instance obj) {
return new JsonObject(Json.encode(obj)).getMap();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

import io.vertx.core.json.Json;
import io.vertx.core.json.JsonObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.folio.CopilotGenerated;
import org.folio.domain.diff.FieldChangeDto;
import org.folio.rest.external.AdditionalCallNumber;
import org.folio.rest.external.HoldingsRecord;
import org.folio.util.inventory.InventoryResourceType;
import org.folio.utils.UnitTest;
Expand Down Expand Up @@ -52,7 +56,32 @@ void shouldDetectFieldModifiedChange() {
.containsExactlyInAnyOrder(FieldChangeDto.modified("callNumber", "callNumber", "Call Number 1", "Call Number 2"));
}

@Test
void shouldDetectNewAdditionalCallNumber() {
List<AdditionalCallNumber> additionalCallNumberList = new ArrayList<>();
AdditionalCallNumber additionalCallNumber = new AdditionalCallNumber().withCallNumber("123").withPrefix("A").withSuffix("Z");
additionalCallNumberList.add(additionalCallNumber);
var oldItem = getMap(new HoldingsRecord().withId("1").withAdditionalCallNumbers(additionalCallNumberList));
AdditionalCallNumber additionalCallNumberNew = new AdditionalCallNumber().withCallNumber("456").withPrefix("A").withSuffix("Z");
additionalCallNumberList.add(additionalCallNumberNew);
var newItem = getMap(new HoldingsRecord().withId("1").withAdditionalCallNumbers(additionalCallNumberList));
var changeRecordDTO = holdingsDiffCalculator.calculateDiff(oldItem, newItem);
assertThat(changeRecordDTO.getCollectionChanges()).hasSize(1);
}

@Test
void shouldDetectAdditionalCallNumberChange() {
List<AdditionalCallNumber> additionalCallNumberList = new ArrayList<>();
AdditionalCallNumber additionalCallNumber = new AdditionalCallNumber().withCallNumber("123").withPrefix("A").withSuffix("Z");
additionalCallNumberList.add(additionalCallNumber);
var oldItem = getMap(new HoldingsRecord().withId("1").withAdditionalCallNumbers(additionalCallNumberList));
additionalCallNumberList.getFirst().setCallNumber("456");
var newItem = getMap(new HoldingsRecord().withId("1").withAdditionalCallNumbers(additionalCallNumberList));
var changeRecordDTO = holdingsDiffCalculator.calculateDiff(oldItem, newItem);
assertThat(changeRecordDTO.getCollectionChanges()).hasSize(1);
}

private static Map<String, Object> getMap(HoldingsRecord obj) {
return new JsonObject(Json.encode(obj)).getMap();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

import io.vertx.core.json.Json;
import io.vertx.core.json.JsonObject;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.folio.CopilotGenerated;
import org.folio.domain.diff.FieldChangeDto;
import org.folio.rest.external.AdditionalCallNumber;
import org.folio.rest.external.Item;
import org.folio.util.inventory.InventoryResourceType;
import org.folio.utils.UnitTest;
Expand Down Expand Up @@ -54,7 +58,32 @@ void shouldDetectFieldModifiedChange() {
.containsExactlyInAnyOrder(FieldChangeDto.modified("barcode", "barcode", "Barcode 1", "Barcode 2"));
}

@Test
void shouldDetectNewAdditionalCallNumber() {
List<AdditionalCallNumber> additionalCallNumberList = new ArrayList<>();
AdditionalCallNumber additionalCallNumber = new AdditionalCallNumber().withCallNumber("123").withPrefix("A").withSuffix("Z");
additionalCallNumberList.add(additionalCallNumber);
var oldItem = getMap(new Item().withId("1").withAdditionalCallNumbers(additionalCallNumberList));
AdditionalCallNumber additionalCallNumberNew = new AdditionalCallNumber().withCallNumber("456").withPrefix("A").withSuffix("Z");
additionalCallNumberList.add(additionalCallNumberNew);
var newItem = getMap(new Item().withId("1").withAdditionalCallNumbers(additionalCallNumberList));
var changeRecordDTO = itemDiffCalculator.calculateDiff(oldItem, newItem);
assertThat(changeRecordDTO.getCollectionChanges()).hasSize(1);
}

@Test
void shouldDetectAdditionalCallNumberChange() {
List<AdditionalCallNumber> additionalCallNumberList = new ArrayList<>();
AdditionalCallNumber additionalCallNumber = new AdditionalCallNumber().withCallNumber("123").withPrefix("A").withSuffix("Z");
additionalCallNumberList.add(additionalCallNumber);
var oldItem = getMap(new Item().withId("1").withAdditionalCallNumbers(additionalCallNumberList));
additionalCallNumberList.getFirst().setCallNumber("456");
var newItem = getMap(new Item().withId("1").withAdditionalCallNumbers(additionalCallNumberList));
var changeRecordDTO = itemDiffCalculator.calculateDiff(oldItem, newItem);
assertThat(changeRecordDTO.getCollectionChanges()).hasSize(1);
}

private static Map<String, Object> getMap(Item obj) {
return new JsonObject(Json.encode(obj)).getMap();
}
}
}
20 changes: 20 additions & 0 deletions ramls/schemas/external/additionalCallNumber.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "An additional call number",
"type": "object",
"properties": {
"typeId": {
"type": "string"
},
"prefix": {
"type": "string"
},
"callNumber": {
"type": "string"
},
"suffix": {
"type": "string"
}
},
"required": ["callNumber"]
}
8 changes: 8 additions & 0 deletions ramls/schemas/external/holdingsRecord.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
"callNumberTypeId": {
"type": "string"
},
"additionalCallNumbers": {
"type": "array",
"items": {
"type": "object",
"$ref": "additionalCallNumber.json",
"uniqueItems": true
}
},
"copyNumber": {
"type": "string"
},
Expand Down
8 changes: 8 additions & 0 deletions ramls/schemas/external/item.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@
"itemLevelCallNumberTypeId": {
"type": "string"
},
"additionalCallNumbers": {
"type": "array",
"items": {
"type": "object",
"$ref": "additionalCallNumber.json",
"uniqueItems": true
}
},
"lastCheckIn": {
"properties": {
"dateTime": {
Expand Down