From c3a9f9591b4e371735f53c3b6ce3848b6a3f446d Mon Sep 17 00:00:00 2001 From: Azizbek Khushvakov Date: Thu, 4 Apr 2024 16:57:18 +0500 Subject: [PATCH] [MODORSERS-1026] - Fix the setting api --- .../org/folio/service/RoutingListService.java | 19 ++++++++++++------- .../folio/service/RoutingListServiceTest.java | 5 ++++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/folio/service/RoutingListService.java b/src/main/java/org/folio/service/RoutingListService.java index 3e6b23d53..cf6ce1211 100644 --- a/src/main/java/org/folio/service/RoutingListService.java +++ b/src/main/java/org/folio/service/RoutingListService.java @@ -18,7 +18,7 @@ import org.apache.logging.log4j.Logger; import org.folio.models.TemplateProcessingRequest; import org.folio.models.UserCollection; -import org.folio.rest.acq.model.Setting; +import org.folio.rest.acq.model.SettingCollection; import org.folio.rest.core.RestClient; import org.folio.rest.core.models.RequestContext; import org.folio.rest.core.models.RequestEntry; @@ -102,21 +102,26 @@ private List fillUsersForContext(UserCollection private String getUserAddress(List addressList, String addressTypeId) { for (UserCollection.User.Personal.Address address : addressList) { - if (address.getAddressTypeId().equals(addressTypeId)) + if (address.getAddressTypeId().equals(addressTypeId)) { + log.info("getUserAddress:: Required address with addressTypeId={} is found", addressTypeId); return address.getAddressLine1(); + } } + log.warn("getUserAddress:: Required address is not found with addressTypId={}", addressTypeId); return ""; } private Future getAddressTypeId(RequestContext requestContext) { var requestEntry = new RequestEntry(ORDER_SETTINGS_ENDPOINT) .withQuery("key=" + ROUTING_USER_ADDRESS_TYPE_ID); - return restClient.get(requestEntry, Setting.class, requestContext) - .map(setting -> { - if (ObjectUtils.isEmpty(setting) || StringUtils.isBlank(setting.getValue())) { - throw new ResourceNotFoundException("Setting is not found for addressTypeId"); + return restClient.get(requestEntry, SettingCollection.class, requestContext) + .map(settingCollection -> { + var settings = settingCollection.getSettings(); + if (ObjectUtils.isEmpty(settings) || StringUtils.isBlank(settings.get(0).getValue())) { + log.error("getAddressTypeId:: Setting is not found with key={}", ROUTING_USER_ADDRESS_TYPE_ID); + throw new ResourceNotFoundException("Setting is not found with key={}", ROUTING_USER_ADDRESS_TYPE_ID); } - return setting.getValue(); + return settings.get(0).getValue(); }); } diff --git a/src/test/java/org/folio/service/RoutingListServiceTest.java b/src/test/java/org/folio/service/RoutingListServiceTest.java index 5014b6db8..f55759bc0 100644 --- a/src/test/java/org/folio/service/RoutingListServiceTest.java +++ b/src/test/java/org/folio/service/RoutingListServiceTest.java @@ -11,6 +11,7 @@ import static org.mockito.Mockito.doReturn; import java.io.IOException; +import java.util.List; import java.util.UUID; import io.vertx.core.Future; @@ -19,6 +20,7 @@ import io.vertx.junit5.VertxTestContext; import org.folio.models.UserCollection; import org.folio.rest.acq.model.Setting; +import org.folio.rest.acq.model.SettingCollection; import org.folio.rest.core.RestClient; import org.folio.rest.core.models.RequestContext; import org.folio.rest.core.models.RequestEntry; @@ -62,10 +64,11 @@ void processTemplate(VertxTestContext vertxTestContext) throws IOException { var setting = new Setting().withId(UUID.randomUUID().toString()) .withKey("routing-list") .withValue("1c4b225f-f669-4e9b-afcd-ebc0e273a34e"); + var settingCollection = new SettingCollection().withSettings(List.of(setting)); doReturn(succeededFuture(routingList)).when(restClient).get(any(RequestEntry.class), eq(RoutingList.class), any()); doReturn(succeededFuture(users)).when(userService).getUsersByIds(eq(routingList.getUserIds()), any()); - doReturn(succeededFuture(setting)).when(restClient).get(any(RequestEntry.class), eq(Setting.class), any()); + doReturn(succeededFuture(settingCollection)).when(restClient).get(any(RequestEntry.class), eq(SettingCollection.class), any()); doReturn(succeededFuture(new JsonObject())).when(restClient).postJsonObject(any(RequestEntry.class), eq(expectedTemplateRequest), any()); Future future = routingListService.processTemplateRequest(ROUTING_LIST_ID, requestContextMock);