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

[MODINVSTOR-1264] Add codes to Subject sources #1087

Merged
merged 7 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -28,6 +28,7 @@
* Add new date type fields to Instance schema ([MODINVSTOR-1188](https://folio-org.atlassian.net/browse/MODINVSTOR-1188))
* Implement endpoint for bulk instances upsert from external file ([MODINVSTOR-1225](https://folio-org.atlassian.net/browse/MODINVSTOR-1225))
* Add Subject source and Subject type to schema ([MODINVSTOR-1205](https://folio-org.atlassian.net/browse/MODINVSTOR-1205))
* Add codes to Subject sources ([MODINVSTOR-1264](https://folio-org.atlassian.net/browse/MODINVSTOR-1264))


### Bug fixes
Expand Down
6 changes: 5 additions & 1 deletion ramls/subject-source.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"type": "string"
},
"name": {
"description": "label for the subject source",
"description": "label for the subject source name",
"type": "string"
},
"code": {
"description": "label for the subject source code",
"type": "string"
},
"source": {
Expand Down
6 changes: 6 additions & 0 deletions reference-data/subject-sources/CanadianSubjectHeadings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "e894d0dc-621d-4b1d-98f6-6f7120eb0d45",
"name": "Canadian Subject Headings",
"code" : "cash",
"source": "folio"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "e894d0dc-621d-4b1d-98f6-6f7120eb0d41",
"name": "Library of Congress Children's and Young Adults' Subject Headings",
"code" : "cyac",
"source": "folio"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "e894d0dc-621d-4b1d-98f6-6f7120eb0d40",
"name": "Library of Congress Subject Headings",
"code" : "lcsh",
"source": "folio"
}
6 changes: 6 additions & 0 deletions reference-data/subject-sources/MedicalSubjectHeadings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "e894d0dc-621d-4b1d-98f6-6f7120eb0d42",
"name": "Medical Subject Headings",
"code" : "mesh",
"source": "folio"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "e894d0dc-621d-4b1d-98f6-6f7120eb0d43",
"name": "National Agricultural Library subject authority file",
"source": "folio"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": "e894d0dc-621d-4b1d-98f6-6f7120eb0d46",
"name": "Répertoire de vedettes-matière",
"code" : "rvm",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-sources/Sourcenotspecified.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "e894d0dc-621d-4b1d-98f6-6f7120eb0d44",
"name": "Source not specified",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Chronologicalterm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff5b6",
"name": "Chronological term",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Corporatename.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff5b2",
"name": "Corporate name",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Curriculumobjective.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff514",
"name": "Curriculum objective",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Facetedtopicalterms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff510",
"name": "Faceted topical terms",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff513",
"name": "Function",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Genreform.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff511",
"name": "Genre/form",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Geographicname.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff5b8",
"name": "Geographic name",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Hierarchicalplacename.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff515",
"name": "Hierarchical place name",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Meetingname.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff5b3",
"name": "Meeting name",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Namedevent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff5b5",
"name": "Named event",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Occupation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff512",
"name": "Occupation",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Personalname.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff5b1",
"name": "Personal name",
"source": "folio"
}
RomanChernetskyi marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
5 changes: 5 additions & 0 deletions reference-data/subject-types/Typeofentityunspecified.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff516",
"name": "Type of entity unspecified",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Uncontrolled.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff5b9",
"name": "Uncontrolled",
"source": "folio"
}
5 changes: 5 additions & 0 deletions reference-data/subject-types/Uniformtitle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d6488f88-1e74-40ce-81b5-b19a928ff5b4",
"name": "Uniform title",
"source": "folio"
}
19 changes: 7 additions & 12 deletions src/main/resources/templates/db_scripts/addSubjectSources.sql
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
INSERT INTO ${myuniversity}_${mymodule}.subject_source (id, jsonb)
VALUES ('e894d0dc-621d-4b1d-98f6-6f7120eb0d40',
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d40', 'name', 'Library of Congress Subject Headings', 'source', 'folio'))
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d40', 'name', 'Library of Congress Subject Headings', 'code', 'lcsh', 'source', 'folio'))
ON CONFLICT DO NOTHING;

INSERT INTO ${myuniversity}_${mymodule}.subject_source (id, jsonb)
VALUES ('e894d0dc-621d-4b1d-98f6-6f7120eb0d41',
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d41', 'name', 'Library of Congress Children''s and Young Adults'' Subject Headings', 'source', 'folio'))
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d41', 'name', 'Library of Congress Children''s and Young Adults'' Subject Headings', 'code', 'cyac', 'source', 'folio'))
ON CONFLICT DO NOTHING;
INSERT INTO ${myuniversity}_${mymodule}.subject_source (id, jsonb)
VALUES ('e894d0dc-621d-4b1d-98f6-6f7120eb0d42',
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d42', 'name', 'Medical Subject Headings', 'source', 'folio'))
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d42', 'name', 'Medical Subject Headings', 'code', 'mesh', 'source', 'folio'))
ON CONFLICT DO NOTHING;

INSERT INTO ${myuniversity}_${mymodule}.subject_source (id, jsonb)
VALUES ('e894d0dc-621d-4b1d-98f6-6f7120eb0d43',
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d43', 'name', 'National Agricultural Library subject authority file', 'source', 'folio'))
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d43', 'name', 'National Agricultural Library subject authority file', 'source', 'folio'))
ON CONFLICT DO NOTHING;

INSERT INTO ${myuniversity}_${mymodule}.subject_source (id, jsonb)
VALUES ('e894d0dc-621d-4b1d-98f6-6f7120eb0d44',
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d44', 'name', 'Source not specified', 'source', 'folio'))
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d44', 'name', 'Source not specified', 'source', 'folio'))
ON CONFLICT DO NOTHING;

INSERT INTO ${myuniversity}_${mymodule}.subject_source (id, jsonb)
VALUES ('e894d0dc-621d-4b1d-98f6-6f7120eb0d45',
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d45', 'name', 'Canadian Subject Headings', 'source', 'folio'))
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d45', 'name', 'Canadian Subject Headings', 'code', 'cash', 'source', 'folio'))
ON CONFLICT DO NOTHING;

INSERT INTO ${myuniversity}_${mymodule}.subject_source (id, jsonb)
VALUES ('e894d0dc-621d-4b1d-98f6-6f7120eb0d46',
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d46', 'name', 'Répertoire de vedettes-matière', 'source', 'folio'))
ON CONFLICT DO NOTHING;

INSERT INTO ${myuniversity}_${mymodule}.subject_source (id, jsonb)
VALUES ('e894d0dc-621d-4b1d-98f6-6f7120eb0d47',
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d47', 'name', 'Source specified in subfield $2', 'source', 'folio'))
json_build_object('id','e894d0dc-621d-4b1d-98f6-6f7120eb0d46', 'name', 'Répertoire de vedettes-matière', 'code', 'rvm', 'source', 'folio'))
ON CONFLICT DO NOTHING;
4 changes: 4 additions & 0 deletions src/main/resources/templates/db_scripts/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,10 @@
{
"fieldName": "name",
"tOps": "ADD"
},
{
"fieldName": "code",
"tOps": "ADD"
}
]
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/folio/rest/api/SubjectSourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.folio.utility.RestUtility.send;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import io.vertx.core.http.HttpMethod;
Expand Down Expand Up @@ -51,6 +52,31 @@ public void cannotCreateSubjectSourceWithDuplicateName()

JsonArray errors = response.getJson().getJsonArray("errors");
assertThat(errors.size(), is(1));
assertTrue(errors.getJsonObject(0).getString("message").contains("(jsonb ->> 'name'::text)) value already exists"));
}

@Test
public void cannotCreateSubjectSourceWithDuplicateCode()
throws InterruptedException, TimeoutException,
ExecutionException {

JsonObject subjectSource = new JsonObject()
.put("name", "Test")
.put("code", "test")
.put("source", "local");

subjectSourceClient.create(subjectSource);

CompletableFuture<Response> postCompleted = new CompletableFuture<>();
getClient().post(subjectSourcesUrl(""), subjectSource.put("name", "Test2"),
TENANT_ID, ResponseHandler.json(postCompleted));

Response response = postCompleted.get(TIMEOUT, TimeUnit.SECONDS);
assertThat(response.getStatusCode(), is(422));

JsonArray errors = response.getJson().getJsonArray("errors");
assertThat(errors.size(), is(1));
assertTrue(errors.getJsonObject(0).getString("message").contains("(jsonb ->> 'code'::text)) value already exists"));
}

@Test
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/folio/rest/impl/SubjectSourcesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protected SubjectSource sampleRecord() {
return new SubjectSource()
.withId(UUID.randomUUID().toString())
.withName("test_name")
.withCode("test_code")
.withSource(SubjectSource.Source.LOCAL);
}

Expand All @@ -46,7 +47,7 @@ protected Function<SubjectSources, List<SubjectSource>> collectionRecordsExtract

@Override
protected List<Function<SubjectSource, Object>> recordFieldExtractors() {
return List.of(SubjectSource::getName, SubjectSource::getSource);
return List.of(SubjectSource::getName, SubjectSource::getCode, SubjectSource::getSource);
}

@Override
Expand All @@ -66,6 +67,6 @@ protected UnaryOperator<SubjectSource> recordModifyingFunction() {

@Override
protected List<String> queries() {
return List.of("name==test_name");
return List.of("name==test_name", "code==test_code");
}
}
Loading