-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/MODTLR-64' into MODTLR-64
- Loading branch information
Showing
13 changed files
with
585 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/org/folio/controller/EcsRequestExternalController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/folio/domain/mapper/ExternalEcsRequestMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.