Skip to content

Commit

Permalink
MODINVSTOR-1205 Update mapping of the Instance from/to json
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrokrutii committed Aug 29, 2024
1 parent af5b69d commit 92a62a7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@
},
{
"id": "instance-storage",
"version": "10.0"
"version": "10.0 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 SUBJECT_SOURCE_KEY = "subjectSourceId";
private static final String SUBJECT_TYPE_KEY = "subjectTypeId";

private final String value;

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

private final String subjectTypeId;

public Subject(String value, String authorityId, String subjectSourceId, String subjectTypeId) {
super(authorityId);
this.value = value;
this.subjectSourceId = subjectSourceId;
this.subjectTypeId = subjectTypeId;
}

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(SUBJECT_SOURCE_KEY),
json.getString(SUBJECT_TYPE_KEY)
);
}

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

public String getSubjectSourceId() {
return subjectSourceId;
}

public String getSubjectTypeId() {
return subjectTypeId;
}
}
14 changes: 13 additions & 1 deletion src/test/java/api/InstancesApiExamples.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.folio.inventory.config.InventoryConfiguration;
import org.folio.inventory.config.InventoryConfigurationImpl;
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 @@ -387,6 +388,8 @@ public void canUpdateAnExistingInstance()
ExecutionException {

UUID id = UUID.randomUUID();
final var subjectSourceId = "subjectSourceId";
final var subjectTypeId = "subjectTypeId";

JsonObject smallAngryPlanet = smallAngryPlanet(id);
smallAngryPlanet.put("natureOfContentTermIds",
Expand All @@ -400,7 +403,10 @@ public void canUpdateAnExistingInstance()
.put(TAGS_KEY, new JsonObject().put(TAG_LIST_KEY, new JsonArray().add(tagNameTwo)))
.put(PUBLICATION_PERIOD_KEY, publicationPeriodToJson(new PublicationPeriod(2000, 2012)))
.put("natureOfContentTermIds",
new JsonArray().add(ApiTestSuite.getAudiobookNatureOfContentTermId()));
new JsonArray().add(ApiTestSuite.getAudiobookNatureOfContentTermId()))
.put("subjects", new JsonArray().add(
new Subject(null, null, subjectSourceId, subjectTypeId)
));

URL instanceLocation = new URL(String.format("%s/%s", ApiRoot.instances(),
newInstance.getString("id")));
Expand Down Expand Up @@ -434,6 +440,12 @@ public void canUpdateAnExistingInstance()
var publicationPeriod = updatedInstance.getJsonObject(PUBLICATION_PERIOD_KEY);
assertThat(publicationPeriod.getInteger("start"), is(2000));
assertThat(publicationPeriod.getInteger("end"), is(2012));

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

@Test
Expand Down

0 comments on commit 92a62a7

Please sign in to comment.