-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat(instance-date-types): implement instance-date-types endpoint (#1049
Showing
30 changed files
with
653 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
ramls/examples/instance-date-types/instanceDateTypePatch.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "new name" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
reference-data/instance-date-types/continuing-resource-ceased-publication.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
10 changes: 10 additions & 0 deletions
10
reference-data/instance-date-types/continuing-resource-currently-published.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
10 changes: 10 additions & 0 deletions
10
reference-data/instance-date-types/continuing-resource-status-unknown.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
reference-data/instance-date-types/date-of-distribution.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
10 changes: 10 additions & 0 deletions
10
reference-data/instance-date-types/inclusive-dates-of-collection.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
reference-data/instance-date-types/no-attempt-to-code.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
10 changes: 10 additions & 0 deletions
10
reference-data/instance-date-types/range-of-years-of-bulk-of-collection.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
src/main/java/org/folio/persist/InstanceDateTypeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
38
src/main/java/org/folio/rest/impl/InstanceDateTypeApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/folio/services/instance/InstanceDateTypeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
18
src/main/resources/templates/db_scripts/addInstanceDateTypes.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
src/test/java/org/folio/rest/impl/InstanceDateTypesIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
})))); | ||
}); | ||
} | ||
} |