Skip to content

Commit

Permalink
CIRCSTORE-515 Create CRUD API for storing circulation settings (#467)
Browse files Browse the repository at this point in the history
* CIRCSTORE-509: Create CRUD API for storing circulation settings (#466)

* CIRCSTORE-509 Create CRUD API for storing circulation settings

* CIRCSTORE-509 Create CRUD API for storing circulation settings

* CIRCSTORE-509 Create CRUD API for storing circulation settings

* CIRCSTORE-509 Create CRUD API for storing circulation settings

* CIRCSTORE-509 Create CRUD API for storing circulation settings

* CIRCSTORE-509 Create CRUD API for storing circulation settings

* CIRCSTORE-509 Create CRUD API for storing circulation settings

* CIRCSTORE-509 Create CRUD API for storing circulation settings

* CIRCSTORE-509 Create CRUD API for storing circulation settings

* CIRCSTORE-509 Create CRUD API for storing circulation settings

* CIRCSTORE-509 Create CRUD API for storing circulation settings

* CIRCSTORE-509 Fix formatting

Co-authored-by: OleksandrVidinieiev <[email protected]>

---------

Co-authored-by: Alexander Kurash <[email protected]>
Co-authored-by: OleksandrVidinieiev <[email protected]>

* CIRCSTORE-515 Remove context config

* CIRCSTORE-515 Remove RunWith

* CIRCSTORE-515 Add test to the suite

---------

Co-authored-by: Magzhan <[email protected]>
Co-authored-by: OleksandrVidinieiev <[email protected]>
  • Loading branch information
3 people authored Jun 19, 2024
1 parent 418597e commit a204ae1
Show file tree
Hide file tree
Showing 18 changed files with 517 additions and 4 deletions.
70 changes: 69 additions & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,44 @@
}
]
},
{
"id": "circulation-settings-storage",
"version": "1.0",
"handlers": [
{
"methods": ["GET"],
"pathPattern": "/circulation-settings-storage/circulation-settings",
"permissionsRequired": [
"circulation-storage.circulation-settings.collection.get"
]
},
{
"methods": ["GET"],
"pathPattern": "/circulation-settings-storage/circulation-settings/{id}",
"permissionsRequired": [
"circulation-storage.circulation-settings.item.get"
]
}, {
"methods": ["PUT"],
"pathPattern": "/circulation-settings-storage/circulation-settings/{id}",
"permissionsRequired": [
"circulation-storage.circulation-settings.item.put"
]
}, {
"methods": ["POST"],
"pathPattern": "/circulation-settings-storage/circulation-settings",
"permissionsRequired": [
"circulation-storage.circulation-settings.item.post"
]
}, {
"methods": ["DELETE"],
"pathPattern": "/circulation-settings-storage/circulation-settings/{id}",
"permissionsRequired": [
"circulation-storage.circulation-settings.item.delete"
]
}
]
},
{
"id": "loan-policy-storage",
"version": "2.3",
Expand Down Expand Up @@ -974,6 +1012,31 @@
"displayName": "Circulation storage - get expired session patron ids collection",
"description": "Get expired session patron ids collection from storage"
},
{
"permissionName": "circulation-storage.circulation-settings.collection.get",
"displayName": "Circulation storage - get circulation settings collection",
"description": "Get circulation settings collection from storage"
},
{
"permissionName": "circulation-storage.circulation-settings.item.get",
"displayName": "Circulation storage - get circulation setting by id",
"description": "Get circulation setting by id from storage"
},
{
"permissionName": "circulation-storage.circulation-settings.item.post",
"displayName": "Circulation storage - create circulation setting",
"description": "Create circulation setting in storage"
},
{
"permissionName": "circulation-storage.circulation-settings.item.put",
"displayName": "Circulation storage - update circulation setting by id",
"description": "Update circulation setting by id"
},
{
"permissionName": "circulation-storage.circulation-settings.item.delete",
"displayName": "Circulation storage - delete circulation setting by id",
"description": "Delete circulation setting by id"
},
{
"permissionName": "circulation-storage.all",
"displayName": "Circulation storage module - all permissions",
Expand Down Expand Up @@ -1065,7 +1128,12 @@
"checkout-lock-storage.checkout-locks.item.post",
"checkout-lock-storage.checkout-locks.item.delete",
"checkout-lock-storage.checkout-locks.item.get",
"checkout-lock-storage.checkout-locks.collection.get"
"checkout-lock-storage.checkout-locks.collection.get",
"circulation-storage.circulation-settings.collection.get",
"circulation-storage.circulation-settings.item.get",
"circulation-storage.circulation-settings.item.post",
"circulation-storage.circulation-settings.item.put",
"circulation-storage.circulation-settings.item.delete"
]
},
{
Expand Down
33 changes: 33 additions & 0 deletions ramls/circulation-setting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Circulation Setting Schema",
"description": "Circulation setting",
"type": "object",
"properties": {
"id": {
"description": "ID of the circulation setting",
"type": "string",
"$ref": "raml-util/schemas/uuid.schema"
},
"name": {
"description": "Circulation setting name",
"type": "string"
},
"value": {
"description": "Circulation setting",
"type": "object",
"additionalProperties": true
},
"metadata": {
"description": "Metadata about creation and changes, provided by the server (client should not provide)",
"type": "object",
"$ref": "raml-util/schemas/metadata.schema"
}
},
"additionalProperties": false,
"required": [
"id",
"name",
"value"
]
}
106 changes: 106 additions & 0 deletions ramls/circulation-settings-storage.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#%RAML 1.0
title: Circulation Settings Storage
version: v1.0
protocols: [ HTTP, HTTPS ]
baseUri: http://localhost:9130

documentation:
- title: Circulation Settings Storage API
content: <b>Storage for circulation settings</b>

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

types:
circulation-setting: !include circulation-setting.json
circulation-settings: !include circulation-settings.json
errors: !include raml-util/schemas/errors.schema
parameters: !include raml-util/schemas/parameters.schema

resourceTypes:
collection: !include raml-util/rtypes/collection.raml
collection-item: !include raml-util/rtypes/item-collection.raml

/circulation-settings-storage:
/circulation-settings:
type:
collection:
exampleCollection: !include examples/circulation-settings.json
exampleItem: !include examples/circulation-setting.json
schemaCollection: circulation-settings
schemaItem: circulation-setting
post:
is: [validate]
description: Create a new circulation setting
body:
application/json:
type: circulation-setting
responses:
201:
description: "Circulation setting has been created"
body:
application/json:
type: circulation-setting
500:
description: "Internal server error"
body:
text/plain:
example: "Internal server error"
get:
is: [validate, pageable, searchable: { description: "with valid searchable fields", example: "id=497f6eca-6276-4993-bfeb-98cbbbba8f79" }]
description: Get all circulation settings
responses:
200:
description: "Circulation settings successfully retreived"
body:
application/json:
type: circulation-settings
500:
description: "Internal server error"
body:
text/plain:
example: "Internal server error"
/{circulationSettingsId}:
type:
collection-item:
exampleItem: !include examples/circulation-setting.json
schema: circulation-setting
get:
responses:
200:
description: "Circulation setting successfully retreived"
body:
application/json:
type: circulation-setting
500:
description: "Internal server error"
body:
text/plain:
example: "Internal server error"
put:
is: [ validate ]
body:
application/json:
type: circulation-setting
responses:
204:
description: "Circulation settings have been saved."
500:
description: "Internal server error"
body:
text/plain:
example: "Internal server error"
delete:
is: [ validate ]
responses:
204:
description: "Circulation settings deleted"
500:
description: "Internal server error"
body:
text/plain:
example: "Internal server error"

23 changes: 23 additions & 0 deletions ramls/circulation-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Collection of Circulation settings",
"type": "object",
"properties": {
"circulationSettings": {
"description": "List of circulation settings",
"id": "circulationSettings",
"type": "array",
"items": {
"type": "object",
"$ref": "circulation-setting.json"
}
},
"totalRecords": {
"type": "integer"
}
},
"required": [
"circulationSettings",
"totalRecords"
]
}
7 changes: 7 additions & 0 deletions ramls/examples/circulation-setting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f09",
"name": "Sample settings",
"value": {
"org.folio.circulation.settings": "true"
}
}
12 changes: 12 additions & 0 deletions ramls/examples/circulation-settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"circulationSettings": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f09",
"name": "Sample settings",
"value": {
"org.folio.circulation.settings": "true"
}
}
],
"totalRecords": 1
}
22 changes: 22 additions & 0 deletions src/main/java/org/folio/persist/CirculationSettingsRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.folio.persist;

import static org.folio.rest.persist.PgUtil.postgresClient;
import static org.folio.support.ModuleConstants.CIRCULATION_SETTINGS_TABLE;

import java.util.Map;

import org.folio.rest.jaxrs.model.CirculationSetting;

import io.vertx.core.Context;

public class CirculationSettingsRepository
extends AbstractRepository<CirculationSetting> {

public CirculationSettingsRepository(Context context, Map<String,
String> okapiHeaders) {

super(postgresClient(context, okapiHeaders), CIRCULATION_SETTINGS_TABLE,
CirculationSetting.class);
}

}
67 changes: 67 additions & 0 deletions src/main/java/org/folio/rest/impl/CirculationSettingsAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.folio.rest.impl;

import java.util.Map;

import javax.ws.rs.core.Response;

import org.folio.rest.jaxrs.model.CirculationSetting;
import org.folio.rest.jaxrs.resource.CirculationSettingsStorage;
import org.folio.service.CirculationSettingsService;

import io.vertx.core.AsyncResult;
import io.vertx.core.Context;
import io.vertx.core.Handler;

public class CirculationSettingsAPI implements CirculationSettingsStorage {

@Override
public void postCirculationSettingsStorageCirculationSettings(String lang,
CirculationSetting circulationSettings, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {

new CirculationSettingsService(vertxContext, okapiHeaders)
.create(circulationSettings)
.onComplete(asyncResultHandler);
}

@Override
public void getCirculationSettingsStorageCirculationSettings(int offset,
int limit, String query, String lang, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {

new CirculationSettingsService(vertxContext, okapiHeaders)
.getAll(offset, limit, query)
.onComplete(asyncResultHandler);
}

@Override
public void getCirculationSettingsStorageCirculationSettingsByCirculationSettingsId(
String circulationSettingsId, String lang, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {

new CirculationSettingsService(vertxContext, okapiHeaders)
.findById(circulationSettingsId)
.onComplete(asyncResultHandler);
}

@Override
public void putCirculationSettingsStorageCirculationSettingsByCirculationSettingsId(
String circulationSettingsId, String lang, CirculationSetting entity,
Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler,
Context vertxContext) {

new CirculationSettingsService(vertxContext, okapiHeaders)
.update(circulationSettingsId, entity)
.onComplete(asyncResultHandler);
}

@Override
public void deleteCirculationSettingsStorageCirculationSettingsByCirculationSettingsId(
String circulationSettingsId, String lang, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {

new CirculationSettingsService(vertxContext, okapiHeaders)
.delete(circulationSettingsId)
.onComplete(asyncResultHandler);
}
}
4 changes: 3 additions & 1 deletion src/main/java/org/folio/rest/impl/TenantRefAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ Future<Integer> loadData(TenantAttributes attributes, String tenantId,
.add("cancellation-reason-storage/cancellation-reasons")
.withKey(SAMPLE_KEY).withLead(SAMPLE_LEAD)
.add("loans", "loan-storage/loans")
.add("requests", "request-storage/requests");
.add("requests", "request-storage/requests")
.add("circulation-settings-storage/circulation-settings");


tl.perform(attributes, headers, vertx, res -> {
if (res.failed()) {
Expand Down
Loading

0 comments on commit a204ae1

Please sign in to comment.