Skip to content

Commit

Permalink
MODORDERS-1145. Add Instance Title to Context for template request (#979
Browse files Browse the repository at this point in the history
)
  • Loading branch information
SerhiiNosko authored Jul 10, 2024
1 parent 04c6d42 commit 4362108
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/folio/models/TemplateProcessingRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,18 @@ public static class Context {
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private RoutingList routingList;
@JsonProperty
private String title;
@JsonProperty
private List<User> users;

public RoutingList getRoutingList() {
return routingList;
}

public String getTitle() {
return title;
}

public List<User> getUsers() {
return users;
}
Expand All @@ -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<User> users) {
this.users = users;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,7 +123,8 @@ private Future<Void> validateRoutingList(RoutingList rList, RequestContext reque
public Future<JsonObject> 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));
}

Expand All @@ -131,11 +133,11 @@ public Future<RoutingList> getRoutingListById(String routingListId, RequestConte
return restClient.get(requestEntry, RoutingList.class, requestContext);
}

private Future<TemplateProcessingRequest> getUsersAndCreateTemplate(RoutingList routingList, RequestContext requestContext) {
private Future<TemplateProcessingRequest> 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<String> getAddressTypeId(RequestContext requestContext) {
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"lang": "en",
"outputFormat": "text/html",
"context": {
"title": "Title",
"routingList": {
"name": "Mars expedition",
"notes": "Future note",
Expand Down

0 comments on commit 4362108

Please sign in to comment.