Skip to content

Commit

Permalink
[MODORSERS-1026] - Fix the setting api
Browse files Browse the repository at this point in the history
  • Loading branch information
azizbekxm committed Apr 4, 2024
1 parent adfc40c commit c3a9f95
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/main/java/org/folio/service/RoutingListService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,21 +102,26 @@ private List<TemplateProcessingRequest.User> fillUsersForContext(UserCollection

private String getUserAddress(List<UserCollection.User.Personal.Address> 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<String> 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();
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/test/java/org/folio/service/RoutingListServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<JsonObject> future = routingListService.processTemplateRequest(ROUTING_LIST_ID, requestContextMock);
Expand Down

0 comments on commit c3a9f95

Please sign in to comment.