Skip to content

Commit

Permalink
Merge branch 'master' into MODTLR-64
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-barannyk authored Nov 16, 2024
2 parents 7096a98 + e68e659 commit 80f497c
Show file tree
Hide file tree
Showing 13 changed files with 585 additions and 389 deletions.
31 changes: 31 additions & 0 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@
}
]
},
{
"id": "ecs-request-external",
"version": "1.0",
"handlers": [
{
"methods": ["POST"],
"pathPattern": "/tlr/create-ecs-request-external",
"permissionsRequired": ["tlr.ecs-request-external.post"],
"modulePermissions": [
"circulation.requests.instances.item.post",
"circulation.requests.item.post",
"circulation-item.item.get",
"circulation-item.collection.get",
"circulation-item.item.post",
"circulation-item.item.put",
"search.instances.collection.get",
"users.item.get",
"users.collection.get",
"users.item.post",
"inventory-storage.service-points.item.get",
"inventory-storage.service-points.collection.get",
"inventory-storage.service-points.item.post"
]
}
]
},
{
"id": "ecs-tlr-allowed-service-points",
"version": "1.0",
Expand Down Expand Up @@ -205,6 +231,11 @@
"permissionName": "tlr.staff-slips.pick-slips.get",
"displayName": "ecs-tlr - pick slips",
"description": "Get pick slips"
},
{
"permissionName": "tlr.ecs-request-external.post",
"displayName": "ecs-request-external - create ECS request external",
"description": "Create ECS request external"
}
],
"requires": [
Expand Down
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,33 @@
</configOptions>
</configuration>
</execution>
<execution>
<id>ecs-request-external</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/swagger.api/ecs-request-external.yaml</inputSpec>
<output>${project.build.directory}/generated-sources</output>
<generatorName>spring</generatorName>
<modelPackage>${project.groupId}.domain.dto</modelPackage>
<apiPackage>${project.groupId}.rest.resource</apiPackage>
<generateApis>true</generateApis>
<generateApiTests>true</generateApiTests>
<generateApiDocumentation>true</generateApiDocumentation>
<generateModels>true</generateModels>
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>true</generateSupportingFiles>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<generateModelDocumentation>true</generateModelDocumentation>
<configOptions>
<dateLibrary>java</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<useSpringBoot3>true</useSpringBoot3>
<useTags>true</useTags>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
29 changes: 9 additions & 20 deletions src/main/java/org/folio/client/feign/CirculationClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,19 @@ public interface CirculationClient {
Request createRequest(Request request);

@GetMapping("/requests/allowed-service-points")
AllowedServicePointsResponse allowedServicePointsWithStubItem(
@RequestParam("patronGroupId") String patronGroupId, @RequestParam("instanceId") String instanceId,
@RequestParam("operation") String operation, @RequestParam("useStubItem") boolean useStubItem);

@GetMapping("/requests/allowed-service-points")
AllowedServicePointsResponse allowedServicePointsWithStubItem(
@RequestParam("operation") String operation, @RequestParam("requestId") String requestId,
@RequestParam("useStubItem") boolean useStubItem);

@GetMapping("/requests/allowed-service-points")
AllowedServicePointsResponse allowedRoutingServicePoints(
@RequestParam("patronGroupId") String patronGroupId, @RequestParam("instanceId") String instanceId,
AllowedServicePointsResponse allowedServicePointsByInstance(
@RequestParam("patronGroupId") String patronGroupId,
@RequestParam("operation") String operation,
@RequestParam("ecsRequestRouting") boolean ecsRequestRouting);
@RequestParam("instanceId") String instanceId);

@GetMapping("/requests/allowed-service-points")
AllowedServicePointsResponse allowedRoutingServicePoints(
@RequestParam("operation") String operation, @RequestParam("requestId") String requestId,
@RequestParam("ecsRequestRouting") boolean ecsRequestRouting);

@GetMapping("/requests/allowed-service-points")
AllowedServicePointsResponse allowedRoutingServicePoints(
AllowedServicePointsResponse allowedServicePointsByItem(
@RequestParam("patronGroupId") String patronGroupId,
@RequestParam("operation") String operation,
@RequestParam("ecsRequestRouting") boolean ecsRequestRouting,
@RequestParam("itemId") String itemId);

@GetMapping("/requests/allowed-service-points")
AllowedServicePointsResponse allowedServicePoints(
@RequestParam("operation") String operation,
@RequestParam("requestId") String requestId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.folio.domain.dto.AllowedServicePointsRequest;
Expand Down Expand Up @@ -38,20 +36,15 @@ public ResponseEntity<AllowedServicePointsResponse> getAllowedServicePoints(Stri
AllowedServicePointsRequest request = new AllowedServicePointsRequest(
operation, requesterId, instanceId, requestId, itemId);

if (validateAllowedServicePointsRequest(request)) {
var allowedServicePointsService = getAllowedServicePointsService(request);
var response = allowedServicePointsService.getAllowedServicePoints(request);
return ResponseEntity.status(OK).body(response);
} else {
if (!validateAllowedServicePointsRequest(request)) {
return ResponseEntity.status(UNPROCESSABLE_ENTITY).build();
}
}

private AllowedServicePointsService getAllowedServicePointsService(
AllowedServicePointsRequest request) {
return request.isForTitleLevelRequest()
var allowedServicePointsService = request.isForTitleLevelRequest()
? allowedServicePointsForTitleLevelRequestService
: allowedServicePointsForItemLevelRequestService;

return ResponseEntity.status(OK).body(allowedServicePointsService
.getAllowedServicePoints(request));
}

private static boolean validateAllowedServicePointsRequest(AllowedServicePointsRequest request) {
Expand All @@ -63,8 +56,6 @@ private static boolean validateAllowedServicePointsRequest(AllowedServicePointsR

boolean allowedCombinationOfParametersDetected = false;

List<String> errors = new ArrayList<>();

if (operation == CREATE && requesterId != null && instanceId != null &&
itemId == null && requestId == null) {

Expand All @@ -87,13 +78,8 @@ private static boolean validateAllowedServicePointsRequest(AllowedServicePointsR
}

if (!allowedCombinationOfParametersDetected) {
String errorMessage = "Invalid combination of query parameters";
errors.add(errorMessage);
}

if (!errors.isEmpty()) {
String errorMessage = String.join(" ", errors);
log.error("validateRequest:: allowed service points request failed: {}", errorMessage);
log.error("validateRequest:: allowed service points request failed: " +
"Invalid combination of query parameters");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.folio.controller;

import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.springframework.http.HttpStatus.CREATED;

import org.folio.domain.dto.EcsRequestExternal;
import org.folio.domain.dto.EcsTlr;
import org.folio.domain.mapper.ExternalEcsRequestMapper;
import org.folio.exception.RequestCreatingException;
import org.folio.rest.resource.EcsRequestExternalApi;
import org.folio.service.EcsTlrService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import lombok.AllArgsConstructor;
import lombok.extern.log4j.Log4j2;

@RestController
@Log4j2
@AllArgsConstructor
public class EcsRequestExternalController implements EcsRequestExternalApi {

private static final EcsTlr.RequestTypeEnum[] ORDERED_REQUEST_TYPES = {
EcsTlr.RequestTypeEnum.PAGE,
EcsTlr.RequestTypeEnum.RECALL,
EcsTlr.RequestTypeEnum.HOLD
};

private final EcsTlrService ecsTlrService;
private final ExternalEcsRequestMapper externalEcsRequestMapper;

@Override
public ResponseEntity<EcsTlr> postEcsRequestExternal(EcsRequestExternal ecsRequestExternal) {
log.info("postEcsRequestExternal:: creating external ECS request, instance {}, " +
"item {}, requester {}", ecsRequestExternal.getInstanceId(),
ecsRequestExternal.getItemId(), ecsRequestExternal.getRequesterId());

EcsTlr ecsTlrDto = externalEcsRequestMapper.mapEcsRequestExternalToEcsTlr(ecsRequestExternal);

for (EcsTlr.RequestTypeEnum requestType: ORDERED_REQUEST_TYPES) {
EcsTlr ecsTlr;
try {
ecsTlr = ecsTlrService.create(ecsTlrDto.requestType(requestType));
} catch (RequestCreatingException e) {
log.warn("postEcsRequestExternal:: failed to create ECS request, message: {}, cause: {}",
e.getMessage(), e.getCause());
ecsTlr = null;
}

if (ecsTlr != null) {
log.info("postEcsRequestExternal:: created ECS request {}, request type is {}",
ecsTlr.getId(), requestType);
return ResponseEntity.status(CREATED).body(ecsTlr);
}
}

log.warn("postEcsRequestExternal:: failed to create external ECS request");
return ResponseEntity.status(BAD_REQUEST).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.folio.domain.mapper;

import org.folio.domain.dto.EcsRequestExternal;
import org.folio.domain.dto.EcsTlr;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.NullValueCheckStrategy;

@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
public interface ExternalEcsRequestMapper {

@Mapping(target = "requestLevel", qualifiedByName = "ExternalEcsRequestToEcsTlrRequestLevel")
@Mapping(target = "fulfillmentPreference", qualifiedByName = "ExternalEcsRequestToEcsTlrFulfillmentPreference")
EcsTlr mapEcsRequestExternalToEcsTlr(EcsRequestExternal ecsRequestExternal);

@Named("ExternalEcsRequestToEcsTlrRequestLevel")
default EcsTlr.RequestLevelEnum mapExternalEcsRequestToEcsTlrRequestLevel(
EcsRequestExternal.RequestLevelEnum ecsRequestExternalRequestLevel) {

return ecsRequestExternalRequestLevel != null
? EcsTlr.RequestLevelEnum.fromValue(ecsRequestExternalRequestLevel.getValue())
: null;
}

@Named("ExternalEcsRequestToEcsTlrFulfillmentPreference")
default EcsTlr.FulfillmentPreferenceEnum mapExternalEcsRequestToEcsTlrFulfillmentPreference(
EcsRequestExternal.FulfillmentPreferenceEnum fulfillmentPreference) {
return fulfillmentPreference != null
? EcsTlr.FulfillmentPreferenceEnum.fromValue(fulfillmentPreference.getValue())
: null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ protected Collection<String> getLendingTenants(AllowedServicePointsRequest reque
}

@Override
protected AllowedServicePointsResponse getAllowedServicePointsFromLendingTenant(
protected AllowedServicePointsResponse getAllowedServicePointsFromTenant(
AllowedServicePointsRequest request, String patronGroupId, String tenantId) {

log.info("getAllowedServicePointsFromLendingTenant:: parameters: request: {}, " +
log.info("getAllowedServicePointsFromTenant:: parameters: request: {}, " +
"patronGroupId: {}, tenantId: {}", request, patronGroupId, tenantId);

return executionService.executeSystemUserScoped(tenantId,
() -> circulationClient.allowedRoutingServicePoints(patronGroupId,
request.getOperation().getValue(), true, request.getItemId()));
() -> circulationClient.allowedServicePointsByItem(patronGroupId,
request.getOperation().getValue(), request.getItemId()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ protected Collection<String> getLendingTenants(AllowedServicePointsRequest reque
}

@Override
protected AllowedServicePointsResponse getAllowedServicePointsFromLendingTenant(
protected AllowedServicePointsResponse getAllowedServicePointsFromTenant(
AllowedServicePointsRequest request, String patronGroupId, String tenantId) {

return executionService.executeSystemUserScoped(tenantId,
() -> circulationClient.allowedRoutingServicePoints(patronGroupId, request.getInstanceId(),
request.getOperation().getValue(), true));
() -> circulationClient.allowedServicePointsByInstance(patronGroupId,
request.getOperation().getValue(), request.getInstanceId()));
}

}
Loading

0 comments on commit 80f497c

Please sign in to comment.