Search in sources :

Example 1 with HelperUtils

use of org.folio.orders.utils.HelperUtils in project mod-orders by folio-org.

the class CheckinReceivePiecesHelper method checkIfAllItemsFound.

/**
 * Checks if all expected piece records found in the storage. If any is
 * missing, remove from piece reference to item and exclude piece from {@param piecesWithItems}
 *
 * @param expectedItemIds
 *          list of expected item id's
 * @param piecesWithItems
 *          map with item id as a key and piece record as a value
 * @param items
 *          found item records
 */
private void checkIfAllItemsFound(List<String> expectedItemIds, List<JsonObject> items, Map<String, Piece> piecesWithItems) {
    // Handle the case when for some reason some items are not found
    if (items.size() < expectedItemIds.size()) {
        List<String> foundItemIds = StreamEx.of(items).map(HelperUtils::extractId).toList();
        expectedItemIds.stream().filter(id -> !foundItemIds.contains(id)).forEach(itemId -> {
            Piece piece = piecesWithItems.get(itemId);
            piece.setItemId(null);
            piecesWithItems.remove(itemId);
        });
    }
}
Also used : ITEM_UPDATE_FAILED(org.folio.rest.core.exceptions.ErrorCodes.ITEM_UPDATE_FAILED) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ProcessingStatus(org.folio.rest.jaxrs.model.ProcessingStatus) Autowired(org.springframework.beans.factory.annotation.Autowired) HelperUtils.collectResultsOnSuccess(org.folio.orders.utils.HelperUtils.collectResultsOnSuccess) PoLine(org.folio.rest.jaxrs.model.PoLine) PIECE_NOT_FOUND(org.folio.rest.core.exceptions.ErrorCodes.PIECE_NOT_FOUND) StringUtils(org.apache.commons.lang3.StringUtils) Context(io.vertx.core.Context) PoLineCommonUtil(org.folio.orders.utils.PoLineCommonUtil) HelperUtils.convertIdsToCqlQuery(org.folio.orders.utils.HelperUtils.convertIdsToCqlQuery) ProtectionService(org.folio.service.ProtectionService) Map(java.util.Map) PIECE_ALREADY_RECEIVED(org.folio.rest.core.exceptions.ErrorCodes.PIECE_ALREADY_RECEIVED) JsonObject(io.vertx.core.json.JsonObject) FULLY_RECEIVED(org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.FULLY_RECEIVED) ReceiptStatus(org.folio.rest.jaxrs.model.PoLine.ReceiptStatus) HelperUtils.handlePutRequest(org.folio.orders.utils.HelperUtils.handlePutRequest) Location(org.folio.rest.jaxrs.model.Location) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Collection(java.util.Collection) AWAITING_RECEIPT(org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.AWAITING_RECEIPT) Set(java.util.Set) HelperUtils.handleGetRequest(org.folio.orders.utils.HelperUtils.handleGetRequest) Collectors(java.util.stream.Collectors) List(java.util.List) PIECE_POL_MISMATCH(org.folio.rest.core.exceptions.ErrorCodes.PIECE_POL_MISMATCH) Logger(org.apache.logging.log4j.Logger) Eresource(org.folio.rest.jaxrs.model.Eresource) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) PieceCollection(org.folio.rest.jaxrs.model.PieceCollection) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) StreamEx(one.util.streamex.StreamEx) Optional(java.util.Optional) USER_HAS_NO_PERMISSIONS(org.folio.rest.core.exceptions.ErrorCodes.USER_HAS_NO_PERMISSIONS) PIECES_STORAGE(org.folio.orders.utils.ResourcePathResolver.PIECES_STORAGE) PIECE_NOT_RETRIEVED(org.folio.rest.core.exceptions.ErrorCodes.PIECE_NOT_RETRIEVED) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) ArrayList(java.util.ArrayList) MAX_IDS_FOR_GET_RQ(org.folio.rest.RestConstants.MAX_IDS_FOR_GET_RQ) ITEM_HOLDINGS_RECORD_ID(org.folio.service.inventory.InventoryManager.ITEM_HOLDINGS_RECORD_ID) HashSet(java.util.HashSet) ReceivingResult(org.folio.rest.jaxrs.model.ReceivingResult) Title(org.folio.rest.jaxrs.model.Title) GET_PURCHASE_ORDERS(org.folio.helper.PurchaseOrderHelper.GET_PURCHASE_ORDERS) ResourcePathResolver.resourcesPath(org.folio.orders.utils.ResourcePathResolver.resourcesPath) TitlesService(org.folio.service.titles.TitlesService) PIECE_UPDATE_FAILED(org.folio.rest.core.exceptions.ErrorCodes.PIECE_UPDATE_FAILED) PieceCreateFlowInventoryManager(org.folio.service.pieces.flows.create.PieceCreateFlowInventoryManager) RequestContext(org.folio.rest.core.models.RequestContext) EMPTY(org.apache.commons.lang3.StringUtils.EMPTY) InventoryManager(org.folio.service.inventory.InventoryManager) ReceivingItemResult(org.folio.rest.jaxrs.model.ReceivingItemResult) Physical(org.folio.rest.jaxrs.model.Physical) Piece(org.folio.rest.jaxrs.model.Piece) HelperUtils(org.folio.orders.utils.HelperUtils) LOC_NOT_PROVIDED(org.folio.rest.core.exceptions.ErrorCodes.LOC_NOT_PROVIDED) EntryStream(one.util.streamex.EntryStream) PARTIALLY_RECEIVED(org.folio.rest.jaxrs.model.PoLine.ReceiptStatus.PARTIALLY_RECEIVED) Error(org.folio.rest.jaxrs.model.Error) ResourcePathResolver.resourceByIdPath(org.folio.orders.utils.ResourcePathResolver.resourceByIdPath) HelperUtils.buildQuery(org.folio.orders.utils.HelperUtils.buildQuery) PurchaseOrderCollection(org.folio.rest.jaxrs.model.PurchaseOrderCollection) ITEM_NOT_RETRIEVED(org.folio.rest.core.exceptions.ErrorCodes.ITEM_NOT_RETRIEVED) PurchaseOrderLineService(org.folio.service.orders.PurchaseOrderLineService) HelperUtils.encodeQuery(org.folio.orders.utils.HelperUtils.encodeQuery) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) Piece(org.folio.rest.jaxrs.model.Piece)

Example 2 with HelperUtils

use of org.folio.orders.utils.HelperUtils in project mod-orders by folio-org.

the class PurchaseOrderHelper method getCompositeOrder.

/**
 * Gets purchase order by id
 *
 * @param orderId purchase order uuid
 * @return completable future with {@link CompositePurchaseOrder} on success or an exception if processing fails
 */
public CompletableFuture<CompositePurchaseOrder> getCompositeOrder(String orderId, RequestContext requestContext) {
    CompletableFuture<CompositePurchaseOrder> future = new CompletableFuture<>();
    purchaseOrderStorageService.getPurchaseOrderByIdAsJson(orderId, requestContext).thenApply(HelperUtils::convertToCompositePurchaseOrder).thenAccept(compPO -> protectionService.isOperationRestricted(compPO.getAcqUnitIds(), ProtectedOperationType.READ, requestContext).thenAccept(ok -> purchaseOrderLineService.populateOrderLines(compPO, requestContext).thenCompose(compPOWithLines -> titlesService.fetchNonPackageTitles(compPOWithLines, requestContext)).thenAccept(linesIdTitles -> populateInstanceId(linesIdTitles, compPO.getCompositePoLines())).thenCompose(po -> combinedPopulateService.populate(new CompositeOrderRetrieveHolder(compPO), requestContext)).thenApply(CompositeOrderRetrieveHolder::getOrder).thenAccept(future::complete).exceptionally(t -> {
        logger.error("Failed to get lines for order with id={}", orderId, t.getCause());
        future.completeExceptionally(t);
        return null;
    })).exceptionally(t -> {
        logger.error("User with id={} is forbidden to view order with id={}", getCurrentUserId(requestContext), orderId, t.getCause());
        future.completeExceptionally(t);
        return null;
    })).exceptionally(t -> {
        logger.error("Failed to build composite purchase order with id={}", orderId, t.getCause());
        future.completeExceptionally(t);
        return null;
    });
    return future;
}
Also used : OrderInvoiceRelationService(org.folio.service.orders.OrderInvoiceRelationService) EN(org.folio.rest.RestConstants.EN) StringUtils(org.apache.commons.lang3.StringUtils) PoLineCommonUtil(org.folio.orders.utils.PoLineCommonUtil) HelperUtils.verifyProtectedFieldsChanged(org.folio.orders.utils.HelperUtils.verifyProtectedFieldsChanged) OpenCompositeOrderFlowValidator(org.folio.service.orders.flows.update.open.OpenCompositeOrderFlowValidator) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) ORDER_CONFIG_MODULE_NAME(org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME) TagService(org.folio.service.TagService) POProtectedFields.getFieldNamesForOpenOrder(org.folio.orders.utils.POProtectedFields.getFieldNamesForOpenOrder) OrderStatusTransitionUtil.isTransitionToOpen(org.folio.orders.utils.OrderStatusTransitionUtil.isTransitionToOpen) MISSING_ONGOING(org.folio.rest.core.exceptions.ErrorCodes.MISSING_ONGOING) HelperUtils.convertToCompositePurchaseOrder(org.folio.orders.utils.HelperUtils.convertToCompositePurchaseOrder) OrderStatusTransitionUtil.isOrderReopening(org.folio.orders.utils.OrderStatusTransitionUtil.isOrderReopening) UnOpenCompositeOrderManager(org.folio.service.orders.flows.update.unopen.UnOpenCompositeOrderManager) WORKFLOW_STATUS(org.folio.orders.utils.HelperUtils.WORKFLOW_STATUS) Set(java.util.Set) ErrorCodes(org.folio.rest.core.exceptions.ErrorCodes) OrderStatusTransitionUtil.isOrderClosing(org.folio.orders.utils.OrderStatusTransitionUtil.isOrderClosing) HelperUtils.handleGetRequest(org.folio.orders.utils.HelperUtils.handleGetRequest) ConfigurationEntriesService(org.folio.service.configuration.ConfigurationEntriesService) OPEN(org.folio.rest.jaxrs.model.CompositePurchaseOrder.WorkflowStatus.OPEN) CompletionStage(java.util.concurrent.CompletionStage) Logger(org.apache.logging.log4j.Logger) CREATE(org.folio.orders.utils.ProtectedOperationType.CREATE) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) MAX_REPEAT_ON_FAILURE(org.folio.helper.AbstractHelper.MAX_REPEAT_ON_FAILURE) USER_HAS_NO_UNOPEN_PERMISSIONS(org.folio.rest.core.exceptions.ErrorCodes.USER_HAS_NO_UNOPEN_PERMISSIONS) UPDATE(org.folio.orders.utils.ProtectedOperationType.UPDATE) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture) OrderStatusTransitionUtil.isTransitionToClosed(org.folio.orders.utils.OrderStatusTransitionUtil.isTransitionToClosed) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) MAX_IDS_FOR_GET_RQ(org.folio.rest.RestConstants.MAX_IDS_FOR_GET_RQ) ResourcePathResolver.resourcesPath(org.folio.orders.utils.ResourcePathResolver.resourcesPath) APPROVAL_REQUIRED_TO_OPEN(org.folio.rest.core.exceptions.ErrorCodes.APPROVAL_REQUIRED_TO_OPEN) PO_LINE_NUMBER(org.folio.orders.utils.ResourcePathResolver.PO_LINE_NUMBER) HelperUtils(org.folio.orders.utils.HelperUtils) OrderStatusTransitionUtil.isTransitionToApproved(org.folio.orders.utils.OrderStatusTransitionUtil.isTransitionToApproved) OrderStatusTransitionUtil.isTransitionToReopen(org.folio.orders.utils.OrderStatusTransitionUtil.isTransitionToReopen) OKAPI_USERID_HEADER(org.folio.rest.RestVerticle.OKAPI_USERID_HEADER) COMPOSITE_PO_LINES(org.folio.orders.utils.HelperUtils.COMPOSITE_PO_LINES) HelperUtils.combineCqlExpressions(org.folio.orders.utils.HelperUtils.combineCqlExpressions) JsonArray(io.vertx.core.json.JsonArray) OpenCompositeOrderManager(org.folio.service.orders.flows.update.open.OpenCompositeOrderManager) HelperUtils.changeOrderStatus(org.folio.orders.utils.HelperUtils.changeOrderStatus) OrderWorkflowType(org.folio.service.orders.OrderWorkflowType) AcqDesiredPermissions(org.folio.orders.utils.AcqDesiredPermissions) ReOpenCompositeOrderManager(org.folio.service.orders.flows.update.reopen.ReOpenCompositeOrderManager) REASON_CANCELLED(org.folio.orders.utils.HelperUtils.REASON_CANCELLED) Date(java.util.Date) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) PurchaseOrderStorageService(org.folio.service.orders.PurchaseOrderStorageService) HelperUtils.collectResultsOnSuccess(org.folio.orders.utils.HelperUtils.collectResultsOnSuccess) USER_HAS_NO_REOPEN_PERMISSIONS(org.folio.rest.core.exceptions.ErrorCodes.USER_HAS_NO_REOPEN_PERMISSIONS) PoLine(org.folio.rest.jaxrs.model.PoLine) CollectionUtils.isEmpty(org.apache.commons.collections4.CollectionUtils.isEmpty) ASSIGN(org.folio.orders.utils.AcqDesiredPermissions.ASSIGN) MANAGE(org.folio.orders.utils.AcqDesiredPermissions.MANAGE) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder) ReceiptStatus(org.folio.rest.jaxrs.model.CompositePoLine.ReceiptStatus) ProtectionService(org.folio.service.ProtectionService) ListUtils(org.apache.commons.collections4.ListUtils) ONGOING_NOT_ALLOWED(org.folio.rest.core.exceptions.ErrorCodes.ONGOING_NOT_ALLOWED) PurchaseOrder(org.folio.rest.jaxrs.model.PurchaseOrder) Collection(java.util.Collection) SEARCH_PARAMS(org.folio.helper.AbstractHelper.SEARCH_PARAMS) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) PaymentStatus(org.folio.rest.jaxrs.model.CompositePoLine.PaymentStatus) CompositePoLineValidationService(org.folio.service.orders.CompositePoLineValidationService) StreamEx(one.util.streamex.StreamEx) EncumbranceService(org.folio.service.finance.transaction.EncumbranceService) Optional(java.util.Optional) Parameter(org.folio.rest.jaxrs.model.Parameter) CompositeOrderDynamicDataPopulateService(org.folio.service.orders.CompositeOrderDynamicDataPopulateService) AcquisitionsUnitsService(org.folio.service.AcquisitionsUnitsService) ProtectedOperationType(org.folio.orders.utils.ProtectedOperationType) HttpException(org.folio.rest.core.exceptions.HttpException) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PENDING(org.folio.rest.jaxrs.model.CompositePurchaseOrder.WorkflowStatus.PENDING) USER_HAS_NO_ACQ_PERMISSIONS(org.folio.rest.core.exceptions.ErrorCodes.USER_HAS_NO_ACQ_PERMISSIONS) HashSet(java.util.HashSet) Title(org.folio.rest.jaxrs.model.Title) TitlesService(org.folio.service.titles.TitlesService) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) RequestContext(org.folio.rest.core.models.RequestContext) POProtectedFields.getFieldNames(org.folio.orders.utils.POProtectedFields.getFieldNames) HelperUtils.getPoLineLimit(org.folio.orders.utils.HelperUtils.getPoLineLimit) DELETE(org.folio.orders.utils.ProtectedOperationType.DELETE) EncumbranceWorkflowStrategyFactory(org.folio.service.finance.transaction.EncumbranceWorkflowStrategyFactory) InventoryManager(org.folio.service.inventory.InventoryManager) EncumbranceWorkflowStrategy(org.folio.service.finance.transaction.EncumbranceWorkflowStrategy) PURCHASE_ORDER_STORAGE(org.folio.orders.utils.ResourcePathResolver.PURCHASE_ORDER_STORAGE) Error(org.folio.rest.jaxrs.model.Error) Collectors.toList(java.util.stream.Collectors.toList) USER_HAS_NO_APPROVAL_PERMISSIONS(org.folio.rest.core.exceptions.ErrorCodes.USER_HAS_NO_APPROVAL_PERMISSIONS) HelperUtils.buildQuery(org.folio.orders.utils.HelperUtils.buildQuery) OrderStatusTransitionUtil.isTransitionToPending(org.folio.orders.utils.OrderStatusTransitionUtil.isTransitionToPending) PurchaseOrderCollection(org.folio.rest.jaxrs.model.PurchaseOrderCollection) HttpStatus(org.folio.HttpStatus) PurchaseOrderLineService(org.folio.service.orders.PurchaseOrderLineService) WorkflowStatus(org.folio.rest.jaxrs.model.CompositePurchaseOrder.WorkflowStatus) CompletableFutureRepeater(org.folio.completablefuture.CompletableFutureRepeater) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture) CompletableFuture(java.util.concurrent.CompletableFuture) HelperUtils(org.folio.orders.utils.HelperUtils) HelperUtils.convertToCompositePurchaseOrder(org.folio.orders.utils.HelperUtils.convertToCompositePurchaseOrder) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) CompositeOrderRetrieveHolder(org.folio.models.CompositeOrderRetrieveHolder)

Example 3 with HelperUtils

use of org.folio.orders.utils.HelperUtils in project mod-orders by folio-org.

the class RestClient method put.

public CompletableFuture<Void> put(RequestEntry requestEntry, JsonObject recordData, RequestContext requestContext) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    String endpoint = requestEntry.buildEndpoint();
    if (logger.isDebugEnabled()) {
        logger.debug("Sending 'PUT {}' with body: {}", endpoint, recordData.encodePrettily());
    }
    HttpClientInterface client = getHttpClient(requestContext.getHeaders());
    setDefaultHeaders(client);
    try {
        client.request(HttpMethod.PUT, recordData.toBuffer(), endpoint, requestContext.getHeaders()).thenAccept(HelperUtils::verifyResponse).thenAccept(avoid -> {
            client.closeClient();
            future.complete(null);
        }).exceptionally(t -> {
            client.closeClient();
            future.completeExceptionally(t.getCause());
            logger.error("'PUT {}' request failed. Request body: {}", endpoint, recordData.encodePrettily(), t.getCause());
            return null;
        });
    } catch (Exception e) {
        logger.error("'PUT {}' request failed. Request body: {}", endpoint, recordData.encodePrettily(), e);
        client.closeClient();
        future.completeExceptionally(e);
    }
    return future;
}
Also used : HelperUtils.verifyResponse(org.folio.orders.utils.HelperUtils.verifyResponse) ERROR_MESSAGE(org.folio.rest.RestConstants.ERROR_MESSAGE) HelperUtils(org.folio.orders.utils.HelperUtils) RequestEntry(org.folio.rest.core.models.RequestEntry) OKAPI_HEADER_TENANT(org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT) CompletableFuture(java.util.concurrent.CompletableFuture) StringUtils(org.apache.commons.lang3.StringUtils) TenantTool(org.folio.rest.tools.utils.TenantTool) HttpClientFactory(org.folio.rest.tools.client.HttpClientFactory) NOT_FOUND(org.folio.rest.RestConstants.NOT_FOUND) HelperUtils.verifyAndExtractBody(org.folio.orders.utils.HelperUtils.verifyAndExtractBody) Logger(org.apache.logging.log4j.Logger) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) HttpMethod(io.vertx.core.http.HttpMethod) Map(java.util.Map) RequestContext(org.folio.rest.core.models.RequestContext) JsonObject(io.vertx.core.json.JsonObject) Objects.nonNull(java.util.Objects.nonNull) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) RestConstants(org.folio.rest.RestConstants) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) CompletableFuture(java.util.concurrent.CompletableFuture) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) HelperUtils(org.folio.orders.utils.HelperUtils)

Example 4 with HelperUtils

use of org.folio.orders.utils.HelperUtils in project mod-orders by folio-org.

the class RestClient method post.

public <T> CompletableFuture<T> post(RequestEntry requestEntry, T entity, RequestContext requestContext, Class<T> responseType) {
    CompletableFuture<T> future = new CompletableFuture<>();
    String endpoint = requestEntry.buildEndpoint();
    JsonObject recordData = JsonObject.mapFrom(entity);
    if (logger.isDebugEnabled()) {
        logger.debug("Sending 'POST {}' with body: {}", endpoint, recordData.encodePrettily());
    }
    HttpClientInterface client = getHttpClient(requestContext.getHeaders());
    try {
        client.request(HttpMethod.POST, recordData.toBuffer(), endpoint, requestContext.getHeaders()).thenApply(HelperUtils::verifyAndExtractBody).thenAccept(body -> {
            client.closeClient();
            T responseEntity = body.mapTo(responseType);
            if (logger.isDebugEnabled()) {
                logger.debug("'POST {}' request successfully processed. Record with '{}' id has been created", endpoint, body);
            }
            future.complete(responseEntity);
        }).exceptionally(t -> {
            client.closeClient();
            logger.error("'POST {}' request failed. Request body: {}", endpoint, recordData.encodePrettily(), t.getCause());
            future.completeExceptionally(t.getCause());
            return null;
        });
    } catch (Exception e) {
        logger.error("'POST {}' request failed. Request body: {}", endpoint, recordData.encodePrettily(), e);
        client.closeClient();
        future.completeExceptionally(e);
    }
    return future;
}
Also used : HelperUtils.verifyResponse(org.folio.orders.utils.HelperUtils.verifyResponse) ERROR_MESSAGE(org.folio.rest.RestConstants.ERROR_MESSAGE) HelperUtils(org.folio.orders.utils.HelperUtils) RequestEntry(org.folio.rest.core.models.RequestEntry) OKAPI_HEADER_TENANT(org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT) CompletableFuture(java.util.concurrent.CompletableFuture) StringUtils(org.apache.commons.lang3.StringUtils) TenantTool(org.folio.rest.tools.utils.TenantTool) HttpClientFactory(org.folio.rest.tools.client.HttpClientFactory) NOT_FOUND(org.folio.rest.RestConstants.NOT_FOUND) HelperUtils.verifyAndExtractBody(org.folio.orders.utils.HelperUtils.verifyAndExtractBody) Logger(org.apache.logging.log4j.Logger) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) HttpMethod(io.vertx.core.http.HttpMethod) Map(java.util.Map) RequestContext(org.folio.rest.core.models.RequestContext) JsonObject(io.vertx.core.json.JsonObject) Objects.nonNull(java.util.Objects.nonNull) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) RestConstants(org.folio.rest.RestConstants) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) CompletableFuture(java.util.concurrent.CompletableFuture) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) HelperUtils(org.folio.orders.utils.HelperUtils) OKAPI_HEADER_TENANT(org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT) JsonObject(io.vertx.core.json.JsonObject)

Example 5 with HelperUtils

use of org.folio.orders.utils.HelperUtils in project mod-orders by folio-org.

the class AbstractHelper method handleUpdateRequest.

/**
 * A common method to update an entry in the storage
 *
 * @param endpoint   endpoint
 * @param recordData json to use for update operation
 */
protected CompletableFuture<Void> handleUpdateRequest(String endpoint, Object recordData) {
    CompletableFuture<Void> future = new CompletableFuture<>();
    try {
        JsonObject json = convertToJson(recordData);
        if (logger.isDebugEnabled()) {
            logger.debug(CALLING_ENDPOINT_WITH_BODY_MSG, HttpMethod.PUT, endpoint, json.encodePrettily());
        }
        httpClient.request(HttpMethod.PUT, json.toBuffer(), endpoint, okapiHeaders).thenApply(HelperUtils::verifyAndExtractBody).thenAccept(response -> {
            logger.debug("'PUT {}' request successfully processed", endpoint);
            future.complete(null);
        }).exceptionally(e -> {
            future.completeExceptionally(e);
            logger.error(EXCEPTION_CALLING_ENDPOINT_WITH_BODY_MSG, e, HttpMethod.PUT, endpoint, json.encodePrettily());
            return null;
        });
    } catch (Exception e) {
        logger.error(EXCEPTION_CALLING_ENDPOINT_WITH_BODY_MSG, e, HttpMethod.PUT, endpoint, recordData);
        future.completeExceptionally(e);
    }
    return future;
}
Also used : CONTENT_TYPE(javax.ws.rs.core.HttpHeaders.CONTENT_TYPE) GENERIC_ERROR_CODE(org.folio.rest.core.exceptions.ErrorCodes.GENERIC_ERROR_CODE) URISyntaxException(java.net.URISyntaxException) HttpException(org.folio.rest.core.exceptions.HttpException) Autowired(org.springframework.beans.factory.annotation.Autowired) OKAPI_HEADER_TENANT(org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT) CompletableFuture(java.util.concurrent.CompletableFuture) LOCATION(javax.ws.rs.core.HttpHeaders.LOCATION) Context(io.vertx.core.Context) SpringContextUtil(org.folio.spring.SpringContextUtil) Map(java.util.Map) RequestContext(org.folio.rest.core.models.RequestContext) JsonObject(io.vertx.core.json.JsonObject) URI(java.net.URI) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) ORDER_CONFIG_MODULE_NAME(org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME) Errors(org.folio.rest.jaxrs.model.Errors) INTERNAL_SERVER_ERROR(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR) HelperUtils(org.folio.orders.utils.HelperUtils) Message(io.vertx.core.eventbus.Message) HelperUtils.convertToJson(org.folio.orders.utils.HelperUtils.convertToJson) OKAPI_USERID_HEADER(org.folio.rest.RestVerticle.OKAPI_USERID_HEADER) TenantTool(org.folio.rest.tools.utils.TenantTool) HttpClientFactory(org.folio.rest.tools.client.HttpClientFactory) ConfigurationEntriesService(org.folio.service.configuration.ConfigurationEntriesService) Error(org.folio.rest.jaxrs.model.Error) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Response(javax.ws.rs.core.Response) HttpClientInterface(org.folio.rest.tools.client.interfaces.HttpClientInterface) HttpMethod(io.vertx.core.http.HttpMethod) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) CREATED(javax.ws.rs.core.Response.Status.CREATED) CompletableFuture(java.util.concurrent.CompletableFuture) HelperUtils(org.folio.orders.utils.HelperUtils) JsonObject(io.vertx.core.json.JsonObject) URISyntaxException(java.net.URISyntaxException) HttpException(org.folio.rest.core.exceptions.HttpException)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)6 Collections (java.util.Collections)6 Map (java.util.Map)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 LogManager (org.apache.logging.log4j.LogManager)6 Logger (org.apache.logging.log4j.Logger)6 HelperUtils (org.folio.orders.utils.HelperUtils)6 RequestContext (org.folio.rest.core.models.RequestContext)6 HttpClientInterface (org.folio.rest.tools.client.interfaces.HttpClientInterface)6 StringUtils (org.apache.commons.lang3.StringUtils)5 HttpMethod (io.vertx.core.http.HttpMethod)4 APPLICATION_JSON (javax.ws.rs.core.MediaType.APPLICATION_JSON)4 TEXT_PLAIN (javax.ws.rs.core.MediaType.TEXT_PLAIN)4 OKAPI_HEADER_TENANT (org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT)4 List (java.util.List)3 Objects.nonNull (java.util.Objects.nonNull)3 HelperUtils.verifyAndExtractBody (org.folio.orders.utils.HelperUtils.verifyAndExtractBody)3 HelperUtils.verifyResponse (org.folio.orders.utils.HelperUtils.verifyResponse)3 RestConstants (org.folio.rest.RestConstants)3 ERROR_MESSAGE (org.folio.rest.RestConstants.ERROR_MESSAGE)3