Skip to content

Commit

Permalink
feat(instance-date-types): implement instance-date-types endpoint (#1049
Browse files Browse the repository at this point in the history
)

Closes: MODINVSTOR-1235
psmagin authored Jul 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 6525b40 commit 9baaa1e
Showing 30 changed files with 653 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
* Required sourceId field in holdings record ([MODINVSTOR-1161](https://folio-org.atlassian.net/browse/MODINVSTOR-1161))

### New APIs versions
* Provides `instance-date-types 1.0`
* Provides `instance-storage 10.1`
* Requires `holdings-storage 6.1`

@@ -13,6 +14,7 @@
* Implement domain event production for campus create/update/delete ([MODINVSTOR-1217](https://issues.folio.org/browse/MODINVSTOR-1217))
* Implement domain event production for institution create/update/delete ([MODINVSTOR-1218](https://issues.folio.org/browse/MODINVSTOR-1218))
* Implement a POST request to get Holdings and Instances ([MODINVSTOR-1223](https://folio-org.atlassian.net/browse/MODINVSTOR-1223))
* Implement instance-date-types endpoint ([MODINVSTOR-1235](https://folio-org.atlassian.net/browse/MODINVSTOR-1235))

### Bug fixes
* Unintended update of instance records \_version (optimistic locking) whenever any of its holdings or items are created, updated or deleted. ([MODINVSTOR-1186](https://folio-org.atlassian.net/browse/MODINVSTOR-1186))
30 changes: 28 additions & 2 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
@@ -53,6 +53,21 @@
}
]
},
{
"id": "instance-date-types",
"version": "1.0",
"handlers": [
{
"methods": ["GET"],
"pathPattern": "/instance-date-types",
"permissionsRequired": ["inventory-storage.instance-date-types.collection.get"]
}, {
"methods": ["PATCH"],
"pathPattern": "/instance-date-types/{id}",
"permissionsRequired": ["inventory-storage.instance-date-types.item.patch"]
}
]
},
{
"id": "item-storage-batch-sync",
"version": "1.0",
@@ -2458,7 +2473,16 @@
"displayName": "inventory storage - submit migration job",
"description": "submit migration instance job"
},

{
"permissionName": "inventory-storage.instance-date-types.collection.get",
"displayName": "inventory storage - get list of instance-date-types",
"description": "get list of instance-date-types"
},
{
"permissionName": "inventory-storage.instance-date-types.item.patch",
"displayName": "inventory storage - patch instance-date-type",
"description": "patch instance-date-type"
},
{
"permissionName": "inventory-storage.all",
"displayName": "inventory storage module - all permissions",
@@ -2687,7 +2711,9 @@
"inventory-storage.migration.job.item.delete",
"inventory-storage.migration.job.post",
"inventory-storage.migration.job.item.get",
"inventory-storage.migration.item.get"
"inventory-storage.migration.item.get",
"inventory-storage.instance-date-types.collection.get",
"inventory-storage.instance-date-types.item.patch"
]
}
],
3 changes: 3 additions & 0 deletions ramls/examples/instance-date-types/instanceDateTypePatch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "new name"
}
25 changes: 25 additions & 0 deletions ramls/examples/instance-date-types/instanceDateTypes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"instanceDateTypes": [
{
"id": "c0b423e1-a885-4c09-a965-4d6979a97e53",
"name": "Detailed date",
"code": "e",
"displayFormat": {
"delimiter": ",",
"keepDelimiter": true
},
"source": "folio"
},
{
"id": "2a0915ff-7246-463b-96a4-4473cd027c6b",
"name": "Range of years of bulk of collection",
"code": "k",
"displayFormat": {
"delimiter": "-",
"keepDelimiter": false
},
"source": "folio"
}
],
"totalRecords": 2
}
84 changes: 84 additions & 0 deletions ramls/instance-date-type.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#%RAML 1.0
title: Inventory Storage Instance Date Type API
version: v1.0
protocols: [ HTTP, HTTPS ]
baseUri: http://localhost

traits:
pageable: !include raml-util/traits/pageable.raml
searchable: !include raml-util/traits/searchable.raml
validate: !include raml-util/traits/validation.raml

types:
instanceDateTypes: !include instance-date-types/instanceDateTypes.json
instanceDateTypePatch: !include instance-date-types/instanceDateTypePatch.json
errors: !include raml-util/schemas/errors.schema

/instance-date-types:
displayName: Instances Date Types API
get:
description: Retrieve a list of instances date type items.
is: [
searchable: {description: "with valid searchable fields", example: "code=a"},
pageable
]
responses:
200:
description: "Returns a list of instances date type items"
body:
application/json:
type: instanceDateTypes
example:
strict: false
value: examples/instance-date-types/instanceDateTypes.json
400:
description: "Bad request, e.g. malformed request body or query parameter. Details of the error (e.g. name of the parameter or line/character number with malformed data) provided in the response."
body:
text/plain:
example: "unable to list instances date type -- malformed parameter 'query', syntax error at column 6"
401:
description: "Not authorized to perform requested action"
body:
text/plain:
example: "unable to list instances date type -- unauthorized"
500:
description: "Internal server error, e.g. due to misconfiguration"
body:
text/plain:
example: "internal server error, contact administrator"
/{id}:
patch:
description: "Update Instances Date Type item with given id"
is: [ validate ]
body:
application/json:
type: instanceDateTypePatch
example:
strict: false
value: examples/instance-date-types/instanceDateTypePatch.json
responses:
204:
description: "Update accepted"
400:
description: "Bad request, e.g. malformed request body or query parameter. Details of the error (e.g. name of the parameter or line/character number with malformed data) provided in the response."
body:
text/plain:
example: |
"unable to list instances date type -- malformed parameter 'query', syntax error at column 6"
401:
description: "Not authorized to perform requested action"
body:
text/plain:
example: |
"unable to list instances date type -- unauthorized"
404:
description: "Item with a given ID not found"
body:
text/plain:
example: |
"instances date type not found"
500:
description: "Internal server error, e.g. due to misconfiguration"
body:
text/plain:
example: "internal server error, contact administrator"
59 changes: 59 additions & 0 deletions ramls/instance-date-types/instanceDateType.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "An instance date type that indicates the type of dates given in Date 1 and Date 2",
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Unique ID of the instance date type; a UUID",
"readonly": true
},
"name": {
"type": "string",
"description": "Name of the instance date type",
"readonly": true
},
"code": {
"type": "string",
"description": "Code of the instance date type",
"maxLength": 1,
"readonly": true
},
"displayFormat": {
"type": "object",
"description": "Describes how to format Date 1 and Date 2",
"properties": {
"delimiter": {
"type": "string",
"description": "Delimiter that will be used to format Date 1 and Date 2",
"example": ",",
"readonly": true
},
"keepDelimiter": {
"type": "boolean",
"description": "Define if formated date string should keep delimiter if one of dates is not exist",
"example": false,
"readonly": true
}
},
"readonly": true,
"additionalProperties": false
},
"source": {
"type": "string",
"description": "label indicating where the instance date type entry originates from, i.e. 'folio' or 'local'",
"enum": [
"folio",
"local"
],
"readonly": true
},
"metadata": {
"type": "object",
"$ref": "../raml-util/schemas/metadata.schema",
"readonly": true
}
},
"additionalProperties": false
}

13 changes: 13 additions & 0 deletions ramls/instance-date-types/instanceDateTypePatch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Object that represents patch operation for instance date type",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Name of the instance date type"
}
},
"additionalProperties": false
}

19 changes: 19 additions & 0 deletions ramls/instance-date-types/instanceDateTypes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "A collection of instance date types",
"type": "object",
"properties": {
"instanceDateTypes": {
"description": "List of instance date types",
"type": "array",
"items": {
"type": "object",
"$ref": "instanceDateType.json"
}
},
"totalRecords": {
"description": "Estimated or exact total number of records",
"type": "integer"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "42dac21e-3c81-4cb1-9f16-9e50c81bacc4",
"name": "Continuing resource ceased publication",
"code": "d",
"displayFormat": {
"delimiter": "-",
"keepDelimiter": true
},
"source": "folio"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "0750f52b-3bfc-458d-9307-e9afc8bcdffa",
"name": "Continuing resource currently published",
"code": "c",
"displayFormat": {
"delimiter": "-",
"keepDelimiter": true
},
"source": "folio"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "5a1a1adb-de71-45e6-ba94-1c0838969f04",
"name": "Continuing resource status unknown",
"code": "e",
"displayFormat": {
"delimiter": "-",
"keepDelimiter": true
},
"source": "folio"
}
10 changes: 10 additions & 0 deletions reference-data/instance-date-types/date-of-distribution.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "5f84208a-0aa6-4694-a58f-5310b654f012",
"name": "Date of distribution/release/issue and production/recording session when different",
"code": "p",
"displayFormat": {
"delimiter": ",",
"keepDelimiter": false
},
"source": "folio"
}
10 changes: 10 additions & 0 deletions reference-data/instance-date-types/dates-unknown.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "e77bb7ed-2e53-4c62-8b06-5907b8934ba7",
"name": "Dates unknown",
"code": "n",
"displayFormat": {
"delimiter": ",",
"keepDelimiter": false
},
"source": "folio"
}
10 changes: 10 additions & 0 deletions reference-data/instance-date-types/detailed-date.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "9669a463-5971-42dc-9eee-046bbd678fb1",
"name": "Detailed date",
"code": "e",
"displayFormat": {
"delimiter": ",",
"keepDelimiter": false
},
"source": "folio"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "6de732c5-c29b-4a10-9db0-0729ca960f12",
"name": "Inclusive dates of collection",
"code": "i",
"displayFormat": {
"delimiter": "-",
"keepDelimiter": true
},
"source": "folio"
}
10 changes: 10 additions & 0 deletions reference-data/instance-date-types/multiple-dates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "8fa6d067-41ff-4362-96a0-96b16ddce267",
"name": "Multiple dates",
"code": "m",
"displayFormat": {
"delimiter": ",",
"keepDelimiter": false
},
"source": "folio"
}
10 changes: 10 additions & 0 deletions reference-data/instance-date-types/no-attempt-to-code.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "6f8cd9a8-26ac-4df6-8709-62fe2c0d04f8",
"name": "No attempt to code",
"code": "|",
"displayFormat": {
"delimiter": ",",
"keepDelimiter": false
},
"source": "folio"
}
10 changes: 10 additions & 0 deletions reference-data/instance-date-types/no-dates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "77a09c3c-37bd-4ad3-aae4-9d86fc1b33d8",
"name": "No dates given; BC date involved",
"code": "b",
"displayFormat": {
"delimiter": ",",
"keepDelimiter": false
},
"source": "folio"
}
10 changes: 10 additions & 0 deletions reference-data/instance-date-types/publication-date.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "3a4296bf-504b-451b-9355-5806f8d88253",
"name": "Publication date and copyright date",
"code": "t",
"displayFormat": {
"delimiter": ",",
"keepDelimiter": false
},
"source": "folio"
}
10 changes: 10 additions & 0 deletions reference-data/instance-date-types/questionable-date.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "4afa7d3d-e6f5-4134-9ab5-32ad377d2432",
"name": "Questionable date",
"code": "q",
"displayFormat": {
"delimiter": ",",
"keepDelimiter": false
},
"source": "folio"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "ccc293d5-9e88-4222-ac04-d058351ddb7b",
"name": "Range of years of bulk of collection",
"code": "k",
"displayFormat": {
"delimiter": "-",
"keepDelimiter": true
},
"source": "folio"
}
10 changes: 10 additions & 0 deletions reference-data/instance-date-types/reissue-date.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "47622598-61eb-4348-899a-1208275c3882",
"name": "Reprint/reissue date and original date",
"code": "r",
"displayFormat": {
"delimiter": ",",
"keepDelimiter": false
},
"source": "folio"
}
10 changes: 10 additions & 0 deletions reference-data/instance-date-types/single-known-date.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id": "24a506e8-2a92-4ecc-bd09-ff849321fd5a",
"name": "Single known date/probable date",
"code": "s",
"displayFormat": {
"delimiter": ",",
"keepDelimiter": false
},
"source": "folio"
}
12 changes: 12 additions & 0 deletions src/main/java/org/folio/persist/InstanceDateTypeRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.folio.persist;

import org.folio.rest.jaxrs.model.InstanceDateType;
import org.folio.rest.persist.PostgresClient;

public class InstanceDateTypeRepository extends AbstractRepository<InstanceDateType> {

public InstanceDateTypeRepository(PostgresClient postgresClient, String tableName,
Class<InstanceDateType> recordType) {
super(postgresClient, tableName, recordType);
}
}
38 changes: 38 additions & 0 deletions src/main/java/org/folio/rest/impl/InstanceDateTypeApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.folio.rest.impl;

import static io.vertx.core.Future.succeededFuture;
import static org.folio.rest.support.EndpointFailureHandler.handleFailure;

import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.Handler;
import java.util.Map;
import javax.ws.rs.core.Response;
import org.folio.rest.annotations.Validate;
import org.folio.rest.jaxrs.model.InstanceDateTypePatch;
import org.folio.rest.jaxrs.resource.InstanceDateTypes;
import org.folio.services.instance.InstanceDateTypeService;

public class InstanceDateTypeApi implements InstanceDateTypes {

@Validate
@Override
public void getInstanceDateTypes(String query, String totalRecords, int offset, int limit,
Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler,
Context vertxContext) {
new InstanceDateTypeService(vertxContext, okapiHeaders)
.getInstanceDateTypes(query, offset, limit)
.onSuccess(response -> asyncResultHandler.handle(succeededFuture(response)))
.onFailure(handleFailure(asyncResultHandler));
}

@Validate
@Override
public void patchInstanceDateTypesById(String id, InstanceDateTypePatch entity, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
new InstanceDateTypeService(vertxContext, okapiHeaders)
.patchInstanceDateTypes(id, entity)
.onSuccess(response -> asyncResultHandler.handle(succeededFuture(response)))
.onFailure(handleFailure(asyncResultHandler));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.folio.services.instance;

import static org.folio.rest.persist.PgUtil.postgresClient;

import io.vertx.core.Context;
import io.vertx.core.Future;
import java.util.Map;
import javax.ws.rs.core.Response;
import org.folio.persist.InstanceDateTypeRepository;
import org.folio.rest.jaxrs.model.InstanceDateType;
import org.folio.rest.jaxrs.model.InstanceDateTypePatch;
import org.folio.rest.jaxrs.model.InstanceDateTypes;
import org.folio.rest.jaxrs.resource.InstanceDateTypes.GetInstanceDateTypesResponse;
import org.folio.rest.jaxrs.resource.InstanceDateTypes.PatchInstanceDateTypesByIdResponse;
import org.folio.rest.persist.PgUtil;

public class InstanceDateTypeService {

public static final String INSTANCE_DATE_TYPE_TABLE = "instance_date_type";

private final Context vertxContext;
private final Map<String, String> okapiHeaders;
private final InstanceDateTypeRepository repository;

public InstanceDateTypeService(Context vertxContext, Map<String, String> okapiHeaders) {

this.vertxContext = vertxContext;
this.okapiHeaders = okapiHeaders;

final var postgresClient = postgresClient(vertxContext, okapiHeaders);
this.repository = new InstanceDateTypeRepository(postgresClient, INSTANCE_DATE_TYPE_TABLE, InstanceDateType.class);
}

public Future<Response> getInstanceDateTypes(String query, int offset, int limit) {
return PgUtil.get(INSTANCE_DATE_TYPE_TABLE, InstanceDateType.class, InstanceDateTypes.class, query,
"exact", offset, limit, okapiHeaders, vertxContext, GetInstanceDateTypesResponse.class);
}

public Future<Response> patchInstanceDateTypes(String id, InstanceDateTypePatch entity) {
return repository.getById(id)
.compose(instanceDateType -> PgUtil.put(INSTANCE_DATE_TYPE_TABLE, instanceDateType.withName(entity.getName()),
id, okapiHeaders, vertxContext, PatchInstanceDateTypesByIdResponse.class));
}
}
18 changes: 18 additions & 0 deletions src/main/resources/templates/db_scripts/addInstanceDateTypes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
INSERT INTO ${myuniversity}_${mymodule}.instance_date_type (id, jsonb)
VALUES
('42dac21e-3c81-4cb1-9f16-9e50c81bacc4', '{"id":"42dac21e-3c81-4cb1-9f16-9e50c81bacc4","name":"Continuing resource ceased publication","code":"d","displayFormat":{"delimiter":"-","keepDelimiter":true},"source":"folio"}'),
('0750f52b-3bfc-458d-9307-e9afc8bcdffa', '{"id":"0750f52b-3bfc-458d-9307-e9afc8bcdffa","name":"Continuing resource currently published","code":"c","displayFormat":{"delimiter":"-","keepDelimiter":true},"source":"folio"}'),
('5a1a1adb-de71-45e6-ba94-1c0838969f04', '{"id":"5a1a1adb-de71-45e6-ba94-1c0838969f04","name":"Continuing resource status unknown","code":"e","displayFormat":{"delimiter":"-","keepDelimiter":true},"source":"folio"}'),
('5f84208a-0aa6-4694-a58f-5310b654f012', '{"id":"5f84208a-0aa6-4694-a58f-5310b654f012","name":"Date of distribution/release/issue and production/recording session when different","code":"p","displayFormat":{"delimiter":",","keepDelimiter":false},"source":"folio"}'),
('e77bb7ed-2e53-4c62-8b06-5907b8934ba7', '{"id":"e77bb7ed-2e53-4c62-8b06-5907b8934ba7","name":"Dates unknown","code":"n","displayFormat":{"delimiter":",","keepDelimiter":false},"source":"folio"}'),
('9669a463-5971-42dc-9eee-046bbd678fb1', '{"id":"9669a463-5971-42dc-9eee-046bbd678fb1","name":"Detailed date","code":"e","displayFormat":{"delimiter":",","keepDelimiter":false},"source":"folio"}'),
('6de732c5-c29b-4a10-9db0-0729ca960f12', '{"id":"6de732c5-c29b-4a10-9db0-0729ca960f12","name":"Inclusive dates of collection","code":"i","displayFormat":{"delimiter":"-","keepDelimiter":true},"source":"folio"}'),
('8fa6d067-41ff-4362-96a0-96b16ddce267', '{"id":"8fa6d067-41ff-4362-96a0-96b16ddce267","name":"Multiple dates","code":"m","displayFormat":{"delimiter":",","keepDelimiter":false},"source":"folio"}'),
('6f8cd9a8-26ac-4df6-8709-62fe2c0d04f8', '{"id":"6f8cd9a8-26ac-4df6-8709-62fe2c0d04f8","name":"No attempt to code","code":"|","displayFormat":{"delimiter":",","keepDelimiter":false},"source":"folio"}'),
('77a09c3c-37bd-4ad3-aae4-9d86fc1b33d8', '{"id":"77a09c3c-37bd-4ad3-aae4-9d86fc1b33d8","name":"No dates given; BC date involved","code":"b","displayFormat":{"delimiter":",","keepDelimiter":false},"source":"folio"}'),
('3a4296bf-504b-451b-9355-5806f8d88253', '{"id":"3a4296bf-504b-451b-9355-5806f8d88253","name":"Publication date and copyright date","code":"t","displayFormat":{"delimiter":",","keepDelimiter":false},"source":"folio"}'),
('4afa7d3d-e6f5-4134-9ab5-32ad377d2432', '{"id":"4afa7d3d-e6f5-4134-9ab5-32ad377d2432","name":"Questionable date","code":"q","displayFormat":{"delimiter":",","keepDelimiter":false},"source":"folio"}'),
('ccc293d5-9e88-4222-ac04-d058351ddb7b', '{"id":"ccc293d5-9e88-4222-ac04-d058351ddb7b","name":"Range of years of bulk of collection","code":"k","displayFormat":{"delimiter":"-","keepDelimiter":true},"source":"folio"}'),
('47622598-61eb-4348-899a-1208275c3882', '{"id":"47622598-61eb-4348-899a-1208275c3882","name":"Reprint/reissue date and original date","code":"r","displayFormat":{"delimiter":",","keepDelimiter":false},"source":"folio"}'),
('24a506e8-2a92-4ecc-bd09-ff849321fd5a', '{"id":"24a506e8-2a92-4ecc-bd09-ff849321fd5a","name":"Single known date/probable date","code":"s","displayFormat":{"delimiter":",","keepDelimiter":false},"source":"folio"}')
ON CONFLICT (id) DO UPDATE SET jsonb=EXCLUDED.jsonb;
10 changes: 10 additions & 0 deletions src/main/resources/templates/db_scripts/schema.json
Original file line number Diff line number Diff line change
@@ -865,6 +865,11 @@
"withMetadata": false,
"withAuditing": false
},
{
"tableName": "instance_date_type",
"withMetadata": true,
"withAuditing": false
},
{
"tableName": "authority_source_file",
"mode": "delete",
@@ -1171,6 +1176,11 @@
"run": "after",
"snippetPath": "updateIdentifierTypeCanceledLCCN.sql",
"fromModuleVersion": "27.2.0"
},
{
"run": "after",
"snippetPath": "addInstanceDateTypes.sql",
"fromModuleVersion": "27.2.0"
}
]
}
4 changes: 4 additions & 0 deletions src/test/java/org/folio/rest/impl/BaseIntegrationTest.java
Original file line number Diff line number Diff line change
@@ -68,6 +68,10 @@ protected static Future<TestResponse> doPut(HttpClient client, String requestUri
return doRequest(client, HttpMethod.PUT, requestUri, body);
}

protected static Future<TestResponse> doPatch(HttpClient client, String requestUri, JsonObject body) {
return doRequest(client, HttpMethod.PATCH, requestUri, body);
}

protected static Future<TestResponse> doDelete(HttpClient client, String requestUri) {
return doRequest(client, HttpMethod.DELETE, requestUri, null);
}
144 changes: 144 additions & 0 deletions src/test/java/org/folio/rest/impl/InstanceDateTypesIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package org.folio.rest.impl;

import static org.assertj.core.api.Assertions.assertThat;
import static org.folio.HttpStatus.HTTP_NO_CONTENT;
import static org.folio.utility.RestUtility.TENANT_ID;

import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient;
import io.vertx.junit5.VertxTestContext;
import java.util.List;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import org.folio.rest.jaxrs.model.DisplayFormat;
import org.folio.rest.jaxrs.model.InstanceDateType;
import org.folio.rest.jaxrs.model.InstanceDateTypePatch;
import org.folio.rest.jaxrs.model.InstanceDateTypes;
import org.folio.rest.jaxrs.model.Metadata;
import org.folio.rest.persist.PostgresClient;
import org.folio.rest.persist.cql.CQLWrapper;
import org.folio.services.instance.InstanceDateTypeService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class InstanceDateTypesIT extends BaseReferenceDataIntegrationTest<InstanceDateType, InstanceDateTypes> {

@Override
protected String referenceTable() {
return InstanceDateTypeService.INSTANCE_DATE_TYPE_TABLE;
}

@Override
protected String resourceUrl() {
return "/instance-date-types";
}

@Override
protected Class<InstanceDateType> targetClass() {
return InstanceDateType.class;
}

@Override
protected Class<InstanceDateTypes> collectionClass() {
return InstanceDateTypes.class;
}

@Override
protected InstanceDateType sampleRecord() {
return new InstanceDateType()
.withId(UUID.randomUUID().toString())
.withName("name")
.withCode("c")
.withDisplayFormat(new DisplayFormat().withDelimiter(",").withKeepDelimiter(false))
.withSource(InstanceDateType.Source.FOLIO);
}

@Override
protected Function<InstanceDateTypes, List<InstanceDateType>> collectionRecordsExtractor() {
return InstanceDateTypes::getInstanceDateTypes;
}

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

@Override
protected Function<InstanceDateType, String> idExtractor() {
return InstanceDateType::getId;
}

@Override
protected Function<InstanceDateType, Metadata> metadataExtractor() {
return InstanceDateType::getMetadata;
}

@Override
protected UnaryOperator<InstanceDateType> recordModifyingFunction() {
return instanceDateType -> instanceDateType.withName("updated");
}

@Override
protected List<String> queries() {
return List.of("code==c");
}

@Override
void getCollection_shouldReturn200AndEmptyCollection(Vertx vertx, VertxTestContext ctx) {
Assertions.assertTrue(true);
}

@Override
void get_shouldReturn200AndRecordById(Vertx vertx, VertxTestContext ctx) {
Assertions.assertTrue(true);
}

@Override
void post_shouldReturn201AndCreatedRecord(Vertx vertx, VertxTestContext ctx) {
Assertions.assertTrue(true);
}

@Override
void put_shouldReturn204AndRecordIsUpdated(Vertx vertx, VertxTestContext ctx) {
Assertions.assertTrue(true);
}

@Override
void delete_shouldReturn204AndRecordIsDeleted(Vertx vertx, VertxTestContext ctx) {
Assertions.assertTrue(true);
}

@BeforeEach
void setUp(Vertx vertx, VertxTestContext ctx) {
var postgresClient = PostgresClient.getInstance(vertx, TENANT_ID);
postgresClient.delete(referenceTable(), (CQLWrapper) null)
.onComplete(event -> ctx.completeNow());
}

@Test
void patch_shouldReturn204AndRecordIsUpdated(Vertx vertx, VertxTestContext ctx) {
HttpClient client = vertx.createHttpClient();

var postgresClient = PostgresClient.getInstance(vertx, TENANT_ID);

var newRecord = sampleRecord();

postgresClient.save(referenceTable(), newRecord)
.compose(id -> {
var updatedRecord = new InstanceDateTypePatch().withName("Updated");
return doPatch(client, resourceUrlById(id), pojo2JsonObject(updatedRecord))
.onComplete(verifyStatus(ctx, HTTP_NO_CONTENT))
.compose(r -> postgresClient.getById(referenceTable(), id, targetClass())
.onComplete(ctx.succeeding(dbRecord -> ctx.verify(() -> {
verifyRecordHasSameId(dbRecord, id, "Verify updated record exists in database");

assertThat(dbRecord)
.extracting(InstanceDateType::getName)
.isEqualTo(updatedRecord.getName());
ctx.completeNow();
}))));
});
}
}

0 comments on commit 9baaa1e

Please sign in to comment.