Skip to content

Commit

Permalink
MODINVSTOR-1205 Add subjectTypeId and subjectSourceId to instance
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrokrutii authored Sep 9, 2024
1 parent 271d4e8 commit 41a10ff
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
4 changes: 2 additions & 2 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"provides": [
{
"id": "inventory",
"version": "13.2",
"version": "13.3",
"handlers": [
{
"methods": ["GET"],
Expand Down Expand Up @@ -604,7 +604,7 @@
},
{
"id": "instance-storage",
"version": "10.2"
"version": "10.3"
},
{
"id": "instance-storage-batch",
Expand Down
27 changes: 24 additions & 3 deletions src/main/java/org/folio/inventory/domain/instances/Subject.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,30 @@

public class Subject extends Authorized {
// JSON property names
public static final String VALUE_KEY = "value";
private static final String VALUE_KEY = "value";
private static final String SOURCE_KEY = "sourceId";
private static final String TYPE_KEY = "typeId";

private final String value;

public Subject(String value, String authorityId) {
private final String sourceId;

private final String typeId;

public Subject(String value, String authorityId, String sourceId, String typeId) {
super(authorityId);
this.value = value;
this.sourceId = sourceId;
this.typeId = typeId;
}

public Subject(JsonObject json) {
this(json.getString(VALUE_KEY), json.getString(AUTHORITY_ID_KEY));
this(
json.getString(VALUE_KEY),
json.getString(AUTHORITY_ID_KEY),
json.getString(SOURCE_KEY),
json.getString(TYPE_KEY)
);
}

public String getAuthorityId() {
Expand All @@ -24,4 +37,12 @@ public String getAuthorityId() {
public String getValue() {
return value;
}

public String getSourceId() {
return sourceId;
}

public String getTypeId() {
return typeId;
}
}
14 changes: 13 additions & 1 deletion src/test/java/api/InstancesApiExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.folio.inventory.config.InventoryConfigurationImpl;
import org.folio.inventory.domain.instances.Dates;
import org.folio.inventory.domain.instances.PublicationPeriod;
import org.folio.inventory.domain.instances.Subject;
import org.folio.inventory.domain.instances.titles.PrecedingSucceedingTitle;
import org.folio.inventory.support.JsonArrayHelper;
import org.folio.inventory.support.http.ContentType;
Expand Down Expand Up @@ -402,6 +403,8 @@ public void canUpdateAnExistingInstance()
ExecutionException {

UUID id = UUID.randomUUID();
final var sourceId = "sourceId";
final var typeId = "typeId";

JsonObject smallAngryPlanet = smallAngryPlanet(id);
smallAngryPlanet.put("natureOfContentTermIds",
Expand All @@ -417,7 +420,10 @@ public void canUpdateAnExistingInstance()
.put(PUBLICATION_PERIOD_KEY, publicationPeriodToJson(new PublicationPeriod(2000, 2012)))
.put(DATES_KEY, datesToJson(new Dates(dateTypeId, date1, date2)))
.put("natureOfContentTermIds",
new JsonArray().add(ApiTestSuite.getAudiobookNatureOfContentTermId()));
new JsonArray().add(ApiTestSuite.getAudiobookNatureOfContentTermId()))
.put("subjects", new JsonArray().add(
new Subject(null, null, sourceId, typeId)
));

URL instanceLocation = new URL(String.format("%s/%s", ApiRoot.instances(),
newInstance.getString("id")));
Expand Down Expand Up @@ -456,6 +462,12 @@ public void canUpdateAnExistingInstance()
assertThat(dates.getString(DATE_TYPE_ID_KEY), is(dateTypeId));
assertThat(dates.getString(DATE1_KEY), is(date1));
assertThat(dates.getString(DATE2_KEY), is(date2));

var subjects = updatedInstance.getJsonArray("subjects");
var subject = subjects.getJsonObject(0);
assertThat(subjects.size(), is(1));
assertThat(subject.getString(sourceId), is(sourceId));
assertThat(subject.getString(typeId), is(typeId));
}

@Test
Expand Down

0 comments on commit 41a10ff

Please sign in to comment.