Skip to content

Commit

Permalink
Merge branch 'master' into ecs-tlr-feature
Browse files Browse the repository at this point in the history
# Conflicts:
#	descriptors/ModuleDescriptor-template.json
#	src/main/java/org/folio/circulation/support/Clients.java
#	src/test/java/api/support/http/InterfaceUrls.java
#	src/test/java/api/support/http/ResourceClient.java
  • Loading branch information
alexanderkurash committed Jun 21, 2024
2 parents 3f6bd4f + ef4e221 commit 5cff758
Show file tree
Hide file tree
Showing 26 changed files with 839 additions and 4 deletions.
88 changes: 86 additions & 2 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,61 @@
}
]
},
{
"id": "circulation-settings",
"version": "1.0",
"handlers": [
{
"methods": [
"GET"
],
"pathPattern": "/circulation/settings",
"permissionsRequired": [
"circulation.settings.collection.get"
],
"modulePermissions": [
"circulation-storage.circulation-settings.collection.get"
]
},
{
"methods": ["GET"],
"pathPattern": "/circulation/settings/{id}",
"permissionsRequired": [
"circulation.settings.item.get"
],
"modulePermissions": [
"circulation-storage.circulation-settings.item.get"
]
}, {
"methods": ["PUT"],
"pathPattern": "/circulation/settings/{id}",
"permissionsRequired": [
"circulation.settings.item.put"
],
"modulePermissions": [
"circulation-storage.circulation-settings.item.put"
]
}, {
"methods": ["POST"],
"pathPattern": "/circulation/settings",
"permissionsRequired": [
"circulation.settings.item.post"
],
"modulePermissions": [
"circulation-storage.circulation-settings.item.post"
]
}, {
"methods": ["DELETE"],
"pathPattern": "/circulation/settings/{id}",
"permissionsRequired": [
"circulation.settings.item.delete"
],
"modulePermissions": [
"circulation-storage.circulation-settings.item.delete"
]
}
]
},
{
"id": "_timer",
"version": "1.0",
Expand Down Expand Up @@ -1148,7 +1203,7 @@
"requires": [
{
"id": "loan-storage",
"version": "7.1"
"version": "7.3"
},
{
"id": "circulation-rules-storage",
Expand All @@ -1164,7 +1219,7 @@
},
{
"id": "holdings-storage",
"version": "1.3 2.0 3.0 4.0 5.0 6.0"
"version": "1.3 2.0 3.0 4.0 5.0 6.0 7.0"
},
{
"id": "request-storage",
Expand Down Expand Up @@ -1277,6 +1332,10 @@
{
"id": "settings",
"version": "1.0"
},
{
"id": "circulation-settings-storage",
"version": "1.0"
}
],
"optional": [
Expand Down Expand Up @@ -1541,6 +1600,31 @@
"displayName": "circulation - get items by instance",
"description": "get items by instance"
},
{
"permissionName": "circulation.settings.collection.get",
"displayName": "circulation - get circulation settings",
"description": "get a collection of circulation settings"
},
{
"permissionName": "circulation.settings.item.get",
"displayName": "circulation - get an individual circulation setting",
"description": "get an individual circulation setting by ID"
},
{
"permissionName": "circulation.settings.item.put",
"displayName": "circulation - update circulation setting",
"description": "update circulation setting by ID"
},
{
"permissionName": "circulation.settings.item.post",
"displayName": "circulation - create circulation setting",
"description": "create a new circulation setting"
},
{
"permissionName": "circulation.settings.item.delete",
"displayName": "circulation - delete circulation setting",
"description": "delete circulation setting by ID"
},
{
"permissionName": "circulation.all",
"displayName": "circulation - all permissions",
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"
]
}
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"
]
}
105 changes: 105 additions & 0 deletions ramls/circulation-settings.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#%RAML 1.0
title: Circulation Settings
version: v1.0
protocols: [ HTTP, HTTPS ]
baseUri: http://localhost:9130

documentation:
- title: Circulation Settings API
content: <b>API 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:
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"
/{circulationSettingId}:
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"

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
}
4 changes: 4 additions & 0 deletions ramls/loan.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@
"type": "string",
"format": "date-time"
},
"isDcb": {
"description": "Indicates whether or not this loan is associated for DCB use case",
"type": "boolean"
},
"metadata": {
"description": "Metadata about creation and changes to loan, provided by the server (client should not provide)",
"type": "object",
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/folio/circulation/CirculationVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.folio.circulation.resources.CheckInByBarcodeResource;
import org.folio.circulation.resources.CheckOutByBarcodeResource;
import org.folio.circulation.resources.CirculationRulesResource;
import org.folio.circulation.resources.CirculationSettingsResource;
import org.folio.circulation.resources.ClaimItemReturnedResource;
import org.folio.circulation.resources.DeclareClaimedReturnedItemAsMissingResource;
import org.folio.circulation.resources.DeclareLostResource;
Expand Down Expand Up @@ -152,6 +153,7 @@ public void start(Promise<Void> startFuture) {
// Handlers
new LoanRelatedFeeFineClosedHandlerResource(client).register(router);
new FeeFineBalanceChangedHandlerResource(client).register(router);
new CirculationSettingsResource(client).register(router);

server.requestHandler(router)
.listen(config().getInteger("port"), result -> {
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/org/folio/circulation/domain/CirculationSetting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.folio.circulation.domain;

import static lombok.AccessLevel.PRIVATE;
import static org.folio.circulation.support.json.JsonPropertyFetcher.getObjectProperty;
import static org.folio.circulation.support.json.JsonPropertyFetcher.getProperty;

import java.lang.invoke.MethodHandles;
import java.util.Set;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import io.vertx.core.json.JsonObject;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

@AllArgsConstructor(access = PRIVATE)
@ToString(onlyExplicitlyIncluded = true)
public class CirculationSetting {
private static final Logger log = LogManager.getLogger(MethodHandles.lookup().lookupClass());

public static final String ID_FIELD = "id";
public static final String NAME_FIELD = "name";
public static final String VALUE_FIELD = "value";
public static final String METADATA_FIELD = "metadata";

@ToString.Include
@Getter
private final JsonObject representation;

@Getter
private final String id;

@Getter
private final String name;

@Getter
private final JsonObject value;

public static CirculationSetting from(JsonObject representation) {
final var id = getProperty(representation, ID_FIELD);
final var name = getProperty(representation, NAME_FIELD);
final var value = getObjectProperty(representation, VALUE_FIELD);

if (id == null || name == null || value == null || !containsOnlyKnownFields(representation)) {
log.warn("from:: Circulation setting JSON is invalid: {}", representation);
return null;
}

return new CirculationSetting(representation, id, name, value);
}

private static boolean containsOnlyKnownFields(JsonObject representation) {
return Set.of(ID_FIELD, NAME_FIELD, VALUE_FIELD, METADATA_FIELD)
.containsAll(representation.fieldNames());
}
}
Loading

0 comments on commit 5cff758

Please sign in to comment.