diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index d39067ad5..7ac5e5f30 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -1081,6 +1081,7 @@ "permissionsRequired": ["orders.routing-lists-template.item.get"], "modulePermissions": [ "orders-storage.routing-lists.item.get", + "orders-storage.po-lines.item.get", "orders-storage.settings.collection.get", "users.collection.get", "template-request.post" diff --git a/src/main/java/org/folio/models/TemplateProcessingRequest.java b/src/main/java/org/folio/models/TemplateProcessingRequest.java index 7646ecfc6..6ab43b02d 100644 --- a/src/main/java/org/folio/models/TemplateProcessingRequest.java +++ b/src/main/java/org/folio/models/TemplateProcessingRequest.java @@ -60,12 +60,18 @@ public static class Context { @JsonInclude(JsonInclude.Include.NON_EMPTY) private RoutingList routingList; @JsonProperty + private String title; + @JsonProperty private List users; public RoutingList getRoutingList() { return routingList; } + public String getTitle() { + return title; + } + public List getUsers() { return users; } @@ -75,6 +81,11 @@ public Context withRoutingList(RoutingList routingList) { return this; } + public Context withTitle(String title) { + this.title = title; + return this; + } + public Context withUsers(List users) { this.users = users; return this; diff --git a/src/main/java/org/folio/service/routinglists/RoutingListService.java b/src/main/java/org/folio/service/routinglists/RoutingListService.java index 3fb78381b..611165de2 100644 --- a/src/main/java/org/folio/service/routinglists/RoutingListService.java +++ b/src/main/java/org/folio/service/routinglists/RoutingListService.java @@ -31,6 +31,7 @@ import org.folio.rest.core.models.RequestEntry; import org.folio.rest.jaxrs.model.Error; import org.folio.rest.jaxrs.model.Errors; +import org.folio.rest.jaxrs.model.PoLine; import org.folio.rest.jaxrs.model.RoutingList; import org.folio.rest.jaxrs.model.RoutingListCollection; import org.folio.service.UserService; @@ -122,7 +123,8 @@ private Future validateRoutingList(RoutingList rList, RequestContext reque public Future processTemplateRequest(String routingListId, RequestContext requestContext) { logger.debug("processTemplateRequest: Tying to process template request for routingListId={}", routingListId); return getRoutingListById(routingListId, requestContext) - .compose(routingList -> getUsersAndCreateTemplate(routingList, requestContext)) + .compose(routingList -> poLineService.getOrderLineById(routingList.getPoLineId(), requestContext) + .compose(poLine -> getUsersAndCreateTemplate(routingList, poLine, requestContext))) .compose(templateProcessingRequest -> postTemplateRequest(templateProcessingRequest, requestContext)); } @@ -131,11 +133,11 @@ public Future getRoutingListById(String routingListId, RequestConte return restClient.get(requestEntry, RoutingList.class, requestContext); } - private Future getUsersAndCreateTemplate(RoutingList routingList, RequestContext requestContext) { + private Future getUsersAndCreateTemplate(RoutingList routingList, PoLine poLine, RequestContext requestContext) { return getAddressTypeId(requestContext) .compose(addressTypId -> userService.getUsersByIds(routingList.getUserIds(), requestContext) .map(users -> sortUsersOrder(routingList, users)) - .map(users -> createTemplateRequest(routingList, users, addressTypId))); + .map(users -> createTemplateRequest(routingList, poLine, users, addressTypId))); } private Future getAddressTypeId(RequestContext requestContext) { @@ -165,14 +167,16 @@ private UserCollection sortUsersOrder(RoutingList routingList, UserCollection us return userCollection; } - private TemplateProcessingRequest createTemplateRequest(RoutingList routingList, UserCollection users, String addressTypeId) { + private TemplateProcessingRequest createTemplateRequest(RoutingList routingList, PoLine poLine, + UserCollection users, String addressTypeId) { var templateRequest = createBaseTemplateRequest(); templateRequest.withContext(new TemplateProcessingRequest.Context() .withRoutingList(fillRoutingListForContext(routingList)) + .withTitle(poLine.getTitleOrPackage()) .withUsers(fillUsersForContext(users, addressTypeId))); - logger.info("createTemplateRequest:: TemplateProcessingRequest object created for routing list name: {}", - templateRequest.getContext().getRoutingList().getName()); + logger.info("createTemplateRequest:: TemplateProcessingRequest object created for routing list name: {} and title: {}", + templateRequest.getContext().getRoutingList().getName(), poLine.getTitleOrPackage()); return templateRequest; } diff --git a/src/test/java/org/folio/service/routinglists/RoutingListServiceTest.java b/src/test/java/org/folio/service/routinglists/RoutingListServiceTest.java index 672f386a2..327ce16c1 100644 --- a/src/test/java/org/folio/service/routinglists/RoutingListServiceTest.java +++ b/src/test/java/org/folio/service/routinglists/RoutingListServiceTest.java @@ -143,6 +143,7 @@ void processTemplate(VertxTestContext vertxTestContext) throws IOException { var settingCollection = new SettingCollection().withSettings(List.of(setting)); doReturn(succeededFuture(routingList)).when(restClient).get(any(RequestEntry.class), eq(RoutingList.class), any()); + doReturn(succeededFuture(samplePoLine)).when(poLineService).getOrderLineById(any(), any()); doReturn(succeededFuture(users)).when(userService).getUsersByIds(eq(routingList.getUserIds()), 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()); @@ -161,6 +162,7 @@ void throwErrorWhenSettingNotFound(VertxTestContext vertxTestContext) throws IOE var users = new JsonObject(getMockData(USERS_MOCK_DATA_PATH + "user_collection.json")).mapTo(UserCollection.class); doReturn(succeededFuture(routingList)).when(restClient).get(any(RequestEntry.class), eq(RoutingList.class), any()); + doReturn(succeededFuture(samplePoLine)).when(poLineService).getOrderLineById(any(), any()); doReturn(succeededFuture(users)).when(userService).getUsersByIds(eq(routingList.getUserIds()), any()); doReturn(succeededFuture(new SettingCollection().withSettings(new ArrayList<>()))) .when(restClient).get(any(RequestEntry.class), eq(SettingCollection.class), any()); diff --git a/src/test/resources/mockdata/routingLists/eee951de-ea49-400a-96e8-705ae5a1e1e8-expected-template-request.json b/src/test/resources/mockdata/routingLists/eee951de-ea49-400a-96e8-705ae5a1e1e8-expected-template-request.json index 4863165c3..fd45c6d59 100644 --- a/src/test/resources/mockdata/routingLists/eee951de-ea49-400a-96e8-705ae5a1e1e8-expected-template-request.json +++ b/src/test/resources/mockdata/routingLists/eee951de-ea49-400a-96e8-705ae5a1e1e8-expected-template-request.json @@ -3,6 +3,7 @@ "lang": "en", "outputFormat": "text/html", "context": { + "title": "Title", "routingList": { "name": "Mars expedition", "notes": "Future note",