diff --git a/src/main/java/org/folio/circulation/resources/CirculationSettingsResource.java b/src/main/java/org/folio/circulation/resources/CirculationSettingsResource.java index 579e523ae2..f23d0dc7bb 100644 --- a/src/main/java/org/folio/circulation/resources/CirculationSettingsResource.java +++ b/src/main/java/org/folio/circulation/resources/CirculationSettingsResource.java @@ -1,9 +1,11 @@ package org.folio.circulation.resources; import static org.folio.circulation.infrastructure.storage.CirculationSettingsRepository.RECORDS_PROPERTY_NAME; +import static org.folio.circulation.support.json.JsonPropertyFetcher.getProperty; import static org.folio.circulation.support.results.MappingFunctions.toFixedValue; import java.lang.invoke.MethodHandles; +import java.util.UUID; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -15,6 +17,7 @@ import org.folio.circulation.support.http.server.WebContext; import io.vertx.core.http.HttpClient; +import io.vertx.core.json.JsonObject; import io.vertx.ext.web.RoutingContext; public class CirculationSettingsResource extends CollectionResource { @@ -31,7 +34,9 @@ void create(RoutingContext routingContext) { final var circulationSettingsRepository = new CirculationSettingsRepository(clients); final var incomingRepresentation = routingContext.body().asJsonObject(); + setRandomIdIfMissing(incomingRepresentation); final var circulationSetting = CirculationSetting.from(incomingRepresentation); + log.debug("replace:: Creating circulation setting: {}", circulationSetting); circulationSettingsRepository.create(circulationSetting) .thenApply(r -> r.map(CirculationSetting::getRepresentation)) @@ -47,6 +52,7 @@ void replace(RoutingContext routingContext) { final var incomingRepresentation = routingContext.body().asJsonObject(); final var circulationSetting = CirculationSetting.from(incomingRepresentation); + log.debug("replace:: Replacing circulation setting : {}", circulationSetting); circulationSettingsRepository.update(circulationSetting) .thenApply(r -> r.map(CirculationSetting::getRepresentation)) @@ -75,8 +81,9 @@ void delete(RoutingContext routingContext) { final var clients = Clients.create(context, client); String id = routingContext.request().getParam("id"); + log.debug("delete:: Deleting circulation setting ID: {}", id); - clients.loansStorage().delete(id) + clients.circulationSettingsStorageClient().delete(id) .thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent))) .thenAccept(context::writeResultToHttpResponse); } @@ -106,4 +113,11 @@ void empty(RoutingContext routingContext) { .thenApply(r -> r.map(toFixedValue(NoContentResponse::noContent))) .thenAccept(context::writeResultToHttpResponse); } + + private void setRandomIdIfMissing(JsonObject representation) { + final var providedId = getProperty(representation, "id"); + if (providedId == null) { + representation.put("id", UUID.randomUUID().toString()); + } + } }