From b6871265631fffca49e330e63a31257e2bb7673e Mon Sep 17 00:00:00 2001 From: Heiko Scherrer Date: Sun, 2 Apr 2023 11:00:21 +0200 Subject: [PATCH] code polishing --- .../api/commands/MessageCommand.java | 6 ++-- .../api/messages/TransportUnitMO.java | 8 ++--- .../openwms/wms/receiving/api/LocationVO.java | 4 +-- .../openwms/wms/receiving/api/ProductVO.java | 6 ++-- .../wms/receiving/api/ReceivingOrderVO.java | 3 +- ...ReceivingTransportUnitOrderPositionVO.java | 14 ++++---- .../wms/receiving/events/CacheJanitor.java | 2 +- .../wms/receiving/impl/AbstractCapturer.java | 4 +-- .../impl/BaseReceivingOrderPosition.java | 1 - .../wms/receiving/impl/OrderProcessor.java | 4 +-- .../PartialCompletionDeniedException.java | 36 ------------------- ...ntityCaptureOnLocationRequestCapturer.java | 9 +++-- .../impl/QuantityCaptureRequestCapturer.java | 25 +++++++------ .../impl/ReceivingOrderCapturer.java | 2 +- .../impl/ReceivingOrderCreatedEvent.java | 2 +- .../impl/ReceivingOrderPosition.java | 1 - .../impl/ReceivingOrderRepository.java | 2 +- .../receiving/impl/ReceivingOrderUpdater.java | 7 ++++ .../receiving/impl/ReceivingServiceImpl.java | 13 +++---- .../ReceivingTransportUnitOrderPosition.java | 6 ++++ .../receiving/{ => impl}/ServiceProvider.java | 14 ++++++-- .../receiving/impl/ServiceProviderImpl.java | 8 ++++- .../impl/TUCaptureRequestCapturer.java | 10 +++--- .../ReceivingOrderDetailsUpdater.java | 2 +- .../wms/receiving/inventory/Product.java | 8 ++--- .../spi/wms/location/LocationApi.java | 2 +- .../spi/wms/transport/TransportUnitVO.java | 2 +- .../receiving/transport/TransportUnit.java | 8 ++--- 28 files changed, 95 insertions(+), 114 deletions(-) delete mode 100644 src/main/java/org/openwms/wms/receiving/impl/PartialCompletionDeniedException.java rename src/main/java/org/openwms/wms/receiving/{ => impl}/ServiceProvider.java (71%) diff --git a/src/main/java/org/openwms/common/transport/api/commands/MessageCommand.java b/src/main/java/org/openwms/common/transport/api/commands/MessageCommand.java index 78c0e80ba..24fc218ff 100644 --- a/src/main/java/org/openwms/common/transport/api/commands/MessageCommand.java +++ b/src/main/java/org/openwms/common/transport/api/commands/MessageCommand.java @@ -15,7 +15,7 @@ */ package org.openwms.common.transport.api.commands; -import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.beans.ConstructorProperties; import java.io.Serializable; @@ -37,7 +37,7 @@ public enum Type { private Type type; private String transportUnitId; - @NotEmpty + @NotBlank private String messageText; private String messageNumber; private Date messageOccurred; @@ -119,7 +119,7 @@ public Builder withTransportUnitId(String val) { return this; } - public Builder withMessageText(@NotEmpty String val) { + public Builder withMessageText(@NotBlank String val) { messageText = val; return this; } diff --git a/src/main/java/org/openwms/common/transport/api/messages/TransportUnitMO.java b/src/main/java/org/openwms/common/transport/api/messages/TransportUnitMO.java index eb22e8c7d..3f0d4cc36 100644 --- a/src/main/java/org/openwms/common/transport/api/messages/TransportUnitMO.java +++ b/src/main/java/org/openwms/common/transport/api/messages/TransportUnitMO.java @@ -19,7 +19,7 @@ import org.openwms.common.transport.api.ValidationGroups; import javax.validation.Valid; -import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Date; @@ -33,14 +33,14 @@ public class TransportUnitMO implements Serializable { /** The persistent key of TransportUnit. */ - @NotEmpty(groups = { + @NotBlank(groups = { ValidationGroups.TransportUnit.Create.class, ValidationGroups.TransportUnit.Request.class, ValidationGroups.TransportUnit.Remove.class }) private String pKey; /** The business key of the TransportUnit. */ - @NotEmpty(groups = { + @NotBlank(groups = { ValidationGroups.TransportUnit.ChangeTarget.class, ValidationGroups.TransportUnit.Create.class, ValidationGroups.TransportUnit.Modified.class @@ -59,7 +59,7 @@ public class TransportUnitMO implements Serializable { /** The plcCode of the TransportUnit. */ private String plcCode; /** The targetLocation of the TransportUnit. */ - @NotEmpty(groups = ValidationGroups.TransportUnit.ChangeTarget.class) + @NotNull(groups = ValidationGroups.TransportUnit.ChangeTarget.class) private LocationMO targetLocation; /** The transportUnitType of the TransportUnit. */ @Valid diff --git a/src/main/java/org/openwms/wms/receiving/api/LocationVO.java b/src/main/java/org/openwms/wms/receiving/api/LocationVO.java index cc110003f..bb64d70e5 100644 --- a/src/main/java/org/openwms/wms/receiving/api/LocationVO.java +++ b/src/main/java/org/openwms/wms/receiving/api/LocationVO.java @@ -20,7 +20,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.ameba.http.AbstractBase; -import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotBlank; import java.io.Serializable; import java.util.Objects; @@ -32,7 +32,7 @@ @JsonInclude(JsonInclude.Include.NON_EMPTY) public class LocationVO extends AbstractBase implements Serializable { - @NotEmpty + @NotBlank @JsonProperty("erpCode") private String erpCode; diff --git a/src/main/java/org/openwms/wms/receiving/api/ProductVO.java b/src/main/java/org/openwms/wms/receiving/api/ProductVO.java index 408c8d5ff..d48fd232d 100644 --- a/src/main/java/org/openwms/wms/receiving/api/ProductVO.java +++ b/src/main/java/org/openwms/wms/receiving/api/ProductVO.java @@ -21,7 +21,7 @@ import org.openwms.core.units.api.Measurable; import org.openwms.wms.receiving.ValidationGroups; -import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotBlank; import java.io.Serializable; import java.util.Objects; @@ -34,7 +34,7 @@ public class ProductVO implements Serializable { /** The product id is part of the unique business key. */ - @NotEmpty(groups = ValidationGroups.Capture.class) + @NotBlank(groups = ValidationGroups.Capture.class) @JsonProperty("sku") private String sku; /** An identifying label of the Product. */ @@ -54,7 +54,7 @@ public class ProductVO implements Serializable { ProductVO() { } - public ProductVO(@NotEmpty String sku) { + public ProductVO(@NotBlank String sku) { this.sku = sku; } diff --git a/src/main/java/org/openwms/wms/receiving/api/ReceivingOrderVO.java b/src/main/java/org/openwms/wms/receiving/api/ReceivingOrderVO.java index 6a68459a8..a69aeb857 100644 --- a/src/main/java/org/openwms/wms/receiving/api/ReceivingOrderVO.java +++ b/src/main/java/org/openwms/wms/receiving/api/ReceivingOrderVO.java @@ -22,6 +22,7 @@ import org.ameba.http.AbstractBase; import javax.validation.Valid; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; import java.io.Serializable; import java.util.ArrayList; @@ -70,7 +71,7 @@ public void sortPositions() { } } - public ReceivingOrderVO(@NotEmpty String orderId) { + public ReceivingOrderVO(@NotBlank String orderId) { this.orderId = orderId; } diff --git a/src/main/java/org/openwms/wms/receiving/api/ReceivingTransportUnitOrderPositionVO.java b/src/main/java/org/openwms/wms/receiving/api/ReceivingTransportUnitOrderPositionVO.java index 36664f00b..242953731 100644 --- a/src/main/java/org/openwms/wms/receiving/api/ReceivingTransportUnitOrderPositionVO.java +++ b/src/main/java/org/openwms/wms/receiving/api/ReceivingTransportUnitOrderPositionVO.java @@ -20,7 +20,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.openwms.wms.receiving.ValidationGroups; -import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.beans.ConstructorProperties; import java.io.Serializable; @@ -36,11 +36,11 @@ public class ReceivingTransportUnitOrderPositionVO extends BaseReceivingOrderPos /** Expected receipts may also carry the unique identifier of the suppliers {@code TransportUnit}. */ @JsonProperty("transportUnitBK") - @NotEmpty(groups = ValidationGroups.CreateExpectedTUReceipt.class) + @NotBlank(groups = ValidationGroups.CreateExpectedTUReceipt.class) private String transportUnitBK; /** The name of the {@code TransportUnitType} the expected {@code TransportUnit} is of. */ @JsonProperty("transportUnitTypeName") - @NotEmpty(groups = ValidationGroups.CreateExpectedTUReceipt.class) + @NotBlank(groups = ValidationGroups.CreateExpectedTUReceipt.class) private String transportUnitTypeName; @JsonCreator @@ -48,8 +48,8 @@ public class ReceivingTransportUnitOrderPositionVO extends BaseReceivingOrderPos @ConstructorProperties({"positionId", "transportUnitBK", "transportUnitTypeName"}) public ReceivingTransportUnitOrderPositionVO(@NotNull Integer positionId, - @NotEmpty(groups = ValidationGroups.CreateExpectedTUReceipt.class) String transportUnitBK, - @NotEmpty(groups = ValidationGroups.CreateExpectedTUReceipt.class) String transportUnitTypeName) { + @NotBlank(groups = ValidationGroups.CreateExpectedTUReceipt.class) String transportUnitBK, + @NotBlank(groups = ValidationGroups.CreateExpectedTUReceipt.class) String transportUnitTypeName) { super(positionId); this.transportUnitBK = transportUnitBK; this.transportUnitTypeName = transportUnitTypeName; @@ -59,7 +59,7 @@ public String getTransportUnitBK() { return transportUnitBK; } - public void setTransportUnitBK(@NotEmpty(groups = ValidationGroups.CreateExpectedTUReceipt.class) String transportUnitBK) { + public void setTransportUnitBK(@NotBlank(groups = ValidationGroups.CreateExpectedTUReceipt.class) String transportUnitBK) { this.transportUnitBK = transportUnitBK; } @@ -67,7 +67,7 @@ public String getTransportUnitTypeName() { return transportUnitTypeName; } - public void setTransportUnitTypeName(@NotEmpty(groups = ValidationGroups.CreateExpectedTUReceipt.class) String transportUnitTypeName) { + public void setTransportUnitTypeName(@NotBlank(groups = ValidationGroups.CreateExpectedTUReceipt.class) String transportUnitTypeName) { this.transportUnitTypeName = transportUnitTypeName; } diff --git a/src/main/java/org/openwms/wms/receiving/events/CacheJanitor.java b/src/main/java/org/openwms/wms/receiving/events/CacheJanitor.java index 1e1e74073..3762dc76e 100644 --- a/src/main/java/org/openwms/wms/receiving/events/CacheJanitor.java +++ b/src/main/java/org/openwms/wms/receiving/events/CacheJanitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2022 the original author or authors. + * Copyright 2005-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/org/openwms/wms/receiving/impl/AbstractCapturer.java b/src/main/java/org/openwms/wms/receiving/impl/AbstractCapturer.java index b84607c1f..03fa9b654 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/AbstractCapturer.java +++ b/src/main/java/org/openwms/wms/receiving/impl/AbstractCapturer.java @@ -22,7 +22,7 @@ import org.openwms.wms.receiving.inventory.ProductService; import org.springframework.beans.factory.annotation.Value; -import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotBlank; import static org.openwms.wms.receiving.ReceivingMessages.RO_NOT_FOUND_BY_PKEY; @@ -54,7 +54,7 @@ protected Product getProduct(String sku) { )); } - protected ReceivingOrder getOrder(@NotEmpty String pKey) { + protected ReceivingOrder getOrder(@NotBlank String pKey) { return repository.findBypKey(pKey).orElseThrow(() -> new NotFoundException( translator, RO_NOT_FOUND_BY_PKEY, diff --git a/src/main/java/org/openwms/wms/receiving/impl/BaseReceivingOrderPosition.java b/src/main/java/org/openwms/wms/receiving/impl/BaseReceivingOrderPosition.java index 00a0a8a9d..8baebd518 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/BaseReceivingOrderPosition.java +++ b/src/main/java/org/openwms/wms/receiving/impl/BaseReceivingOrderPosition.java @@ -17,7 +17,6 @@ import org.ameba.integration.jpa.BaseEntity; import org.openwms.wms.order.OrderState; -import org.openwms.wms.receiving.ServiceProvider; import org.openwms.wms.receiving.api.events.ReceivingOrderPositionStateChangeEvent; import org.springframework.context.ApplicationEventPublisher; diff --git a/src/main/java/org/openwms/wms/receiving/impl/OrderProcessor.java b/src/main/java/org/openwms/wms/receiving/impl/OrderProcessor.java index f34ffa865..40f6fc769 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/OrderProcessor.java +++ b/src/main/java/org/openwms/wms/receiving/impl/OrderProcessor.java @@ -55,9 +55,7 @@ class OrderProcessor { @Transactional(propagation = Propagation.REQUIRES_NEW, noRollbackFor = {IllegalArgumentException.class, ProcessingException.class}) public void onCreate(ReceivingOrderCreatedEvent event) { var order = event.getSource(); - if (LOGGER.isInfoEnabled()) { - LOGGER.info("ReceivingOrder with orderId [{}] saved", order.getOrderId()); - } + LOGGER.info("ReceivingOrder with orderId [{}] created", order.getOrderId()); LOGGER.debug("Processing ReceivingOrder [{}]", order.getOrderId()); order.setOrderState(OrderState.PROCESSED); if (positionProcessor != null) { diff --git a/src/main/java/org/openwms/wms/receiving/impl/PartialCompletionDeniedException.java b/src/main/java/org/openwms/wms/receiving/impl/PartialCompletionDeniedException.java deleted file mode 100644 index f024764d4..000000000 --- a/src/main/java/org/openwms/wms/receiving/impl/PartialCompletionDeniedException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2005-2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.openwms.wms.receiving.impl; - -import org.ameba.exception.BusinessRuntimeException; -import org.ameba.i18n.Translator; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -import java.io.Serializable; - -/** - * A PartialCompletionDeniedException. - * - * @author Matjaž Smolej - */ -@ResponseStatus(HttpStatus.FORBIDDEN) -public class PartialCompletionDeniedException extends BusinessRuntimeException { - - public PartialCompletionDeniedException(Translator translator, String messageKey, Serializable[] data, Object... param) { - super(translator, messageKey, data, param); - } -} diff --git a/src/main/java/org/openwms/wms/receiving/impl/QuantityCaptureOnLocationRequestCapturer.java b/src/main/java/org/openwms/wms/receiving/impl/QuantityCaptureOnLocationRequestCapturer.java index a847edb7d..550fa70bf 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/QuantityCaptureOnLocationRequestCapturer.java +++ b/src/main/java/org/openwms/wms/receiving/impl/QuantityCaptureOnLocationRequestCapturer.java @@ -71,12 +71,12 @@ class QuantityCaptureOnLocationRequestCapturer extends AbstractCapturer implemen */ @Measured @Override - public Optional capture(Optional pKey, @NotNull QuantityCaptureOnLocationRequestVO request) { + public Optional capture(String pKey, @NotNull QuantityCaptureOnLocationRequestVO request) { var product = getProduct(request); - if (pKey.isPresent()) { + if (pKey != null) { ValidationUtil.validate(validator, request, ValidationGroups.CreateQuantityReceipt.class); return handleExpectedReceipt( - pKey.get(), + pKey, request.getQuantityReceived(), product, v -> createPackagingUnitsForDemand(request, product) @@ -102,14 +102,13 @@ private Supplier ifNotFound(QuantityCaptureOnLocationRequestV private void createPackagingUnitsForDemand(QuantityCaptureOnLocationRequestVO request, Product product) { final var erpCode = request.getActualLocation().getErpCode(); - final var details = request.getDetails(); final var quantityReceived = request.getQuantityReceived(); // multi packs var pu = request.hasUomRelation() ? new PackagingUnitVO(request.getUomRelation(), quantityReceived) : new PackagingUnitVO(ProductVO.newBuilder().sku(request.getProduct().getSku()).build(), quantityReceived); pu.setActualLocation(new LocationVO(erpCode)); - pu.setDetails(details); + pu.setDetails(request.getDetails()); pu.setSerialNumber(request.getSerialNumber()); pu.setLotId(request.getLotId()); pu.setProduct(ProductVO.newBuilder().sku(product.getSku()).build()); diff --git a/src/main/java/org/openwms/wms/receiving/impl/QuantityCaptureRequestCapturer.java b/src/main/java/org/openwms/wms/receiving/impl/QuantityCaptureRequestCapturer.java index ed18b09b6..0770dfc08 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/QuantityCaptureRequestCapturer.java +++ b/src/main/java/org/openwms/wms/receiving/impl/QuantityCaptureRequestCapturer.java @@ -66,11 +66,11 @@ class QuantityCaptureRequestCapturer extends AbstractCapturer implements Receivi */ @Override @Measured - public Optional capture(Optional pKey, @NotNull QuantityCaptureRequestVO request) { - if (pKey.isPresent()) { + public Optional capture(String pKey, @NotNull QuantityCaptureRequestVO request) { + if (pKey != null) { ValidationUtil.validate(validator, request, ValidationGroups.CreateQuantityReceipt.class); return handleExpectedReceipt( - pKey.get(), + pKey, request.getQuantityReceived(), getProduct(request.getProduct().getSku()), v -> createPackagingUnitsForDemand(request)); @@ -102,7 +102,7 @@ private Optional handleExpectedReceipt(String pKey, Measurable q ReceivingOrderPosition position; // Got an unexpected receipt. If this is configured to be okay we proceed otherwise throw if (openPosition.isEmpty()) { - if (openPositions.get(0).getProduct().getOverbookingAllowed()) { + if (Boolean.TRUE.equals(openPositions.get(0).getProduct().getOverbookingAllowed())) { position = openPositions.get(0); } else { LOGGER.error("Received a goods receipt but all ReceivingOrderPositions are already satisfied and unexpected receipts are not allowed"); @@ -119,21 +119,20 @@ private Optional handleExpectedReceipt(String pKey, Measurable q private void createPackagingUnitsForDemand(QuantityCaptureRequestVO request) { final var sku = request.getProduct().getSku(); - final var quantityReceived = request.getQuantityReceived(); - final var transportUnitId = request.getTransportUnit().getTransportUnitId(); - final var loadUnitPosition = request.getLoadUnitLabel(); - final var existingProduct = getProduct(sku); - final var details = request.getDetails(); - for (var i = 0; i < quantityReceived.getMagnitude().intValue(); i++) { + for (var i = 0; i < request.getQuantityReceived().getMagnitude().intValue(); i++) { // single packs var pu = new PackagingUnitVO( ProductVO.newBuilder().sku(sku).build(), - existingProduct.getBaseUnit() + getProduct(sku).getBaseUnit() ); - pu.setDetails(details); + pu.setDetails(request.getDetails()); pu.setSerialNumber(request.getSerialNumber()); pu.setLotId(request.getLotId()); - asyncPackagingUnitApi.create(new CreatePackagingUnitCommand(transportUnitId, loadUnitPosition, request.getLoadUnitType(), pu)); + asyncPackagingUnitApi.create(new CreatePackagingUnitCommand( + request.getTransportUnit().getTransportUnitId(), + request.getLoadUnitLabel(), + request.getLoadUnitType(), pu) + ); } } diff --git a/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderCapturer.java b/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderCapturer.java index 2942845ae..77395ef9e 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderCapturer.java +++ b/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderCapturer.java @@ -37,5 +37,5 @@ public interface ReceivingOrderCapturer extends Plug * @param request Particular capturing detail information used to perform the capturing process * @return The identified and updated ReceivingOrder instance, in case of {@literal Expected Receipt}s */ - Optional capture(Optional pKey, @NotNull T request); + Optional capture(String pKey, @NotNull T request); } \ No newline at end of file diff --git a/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderCreatedEvent.java b/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderCreatedEvent.java index e9a50fffe..8e52d6545 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderCreatedEvent.java +++ b/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderCreatedEvent.java @@ -18,7 +18,7 @@ import org.openwms.core.event.RootApplicationEvent; /** - * A ReceivingOrderCreatedEvent. + * A ReceivingOrderCreatedEvent is raised when a {@link ReceivingOrder} has been created. * * @author Heiko Scherrer */ diff --git a/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderPosition.java b/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderPosition.java index 27e708028..ff1d813a0 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderPosition.java +++ b/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderPosition.java @@ -20,7 +20,6 @@ import org.openwms.core.units.api.Measurable; import org.openwms.wms.order.OrderState; import org.openwms.wms.receiving.ReceivingMessages; -import org.openwms.wms.receiving.ServiceProvider; import org.openwms.wms.receiving.ValidationGroups; import org.openwms.wms.receiving.inventory.Product; diff --git a/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderRepository.java b/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderRepository.java index d4d1422f3..1be2aa3fb 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderRepository.java +++ b/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderRepository.java @@ -24,7 +24,7 @@ * * @author Heiko Scherrer */ -public interface ReceivingOrderRepository extends JpaRepository { +interface ReceivingOrderRepository extends JpaRepository { Optional findBypKey(String pKey); diff --git a/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderUpdater.java b/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderUpdater.java index 5e8ae4729..280f70b26 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderUpdater.java +++ b/src/main/java/org/openwms/wms/receiving/impl/ReceivingOrderUpdater.java @@ -31,6 +31,13 @@ enum Type { DETAILS_CHANGE } + /** + * Update parts of a {@link ReceivingOrder} instance. + * + * @param existingReceivingOrder The existing unmodified instance + * @param receivingOrder The instance with modified values to update + * @return The updated (not saved) instance + */ @NotNull ReceivingOrder update(@NotNull ReceivingOrder existingReceivingOrder, @Valid @NotNull ReceivingOrder receivingOrder); } \ No newline at end of file diff --git a/src/main/java/org/openwms/wms/receiving/impl/ReceivingServiceImpl.java b/src/main/java/org/openwms/wms/receiving/impl/ReceivingServiceImpl.java index 76d4c3df4..d606a7f7c 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/ReceivingServiceImpl.java +++ b/src/main/java/org/openwms/wms/receiving/impl/ReceivingServiceImpl.java @@ -23,7 +23,6 @@ import org.openwms.wms.order.OrderState; import org.openwms.wms.receiving.CycleAvoidingMappingContext; import org.openwms.wms.receiving.ReceivingMapper; -import org.openwms.wms.receiving.ServiceProvider; import org.openwms.wms.receiving.ValidationGroups; import org.openwms.wms.receiving.api.CaptureRequestVO; import org.openwms.wms.receiving.api.ReceivingOrderVO; @@ -37,7 +36,6 @@ import javax.validation.Valid; import javax.validation.Validator; import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.util.List; import java.util.Optional; @@ -140,12 +138,9 @@ private void assignOrderId(ReceivingOrder order) { for (T request : requests) { ro = capturers.getPluginFor(request) .orElseThrow(() -> new IllegalArgumentException("Type of CaptureRequestVO not supported")) - .capture(Optional.of(pKey), request); + .capture(pKey, request); } - if (ro.isEmpty()) { - return Optional.empty(); - } - return Optional.of(receivingMapper.convertToVO(repository.save(ro.get()), new CycleAvoidingMappingContext())); + return ro.map(receivingOrder -> receivingMapper.convertToVO(repository.save(receivingOrder), new CycleAvoidingMappingContext())); } /** @@ -157,7 +152,7 @@ public void captureBlindReceipts(@NotNull List requests) { for (T request : requests) { capturers.getPluginFor(request) .orElseThrow(() -> new IllegalArgumentException("Type of CaptureRequestVO not supported")) - .capture(Optional.empty(), request); + .capture(null, request); } } @@ -261,7 +256,7 @@ public Optional findByOrderId(@NotBlank String orderId) { return repository.save(order); } - private ReceivingOrder getOrder(@NotEmpty String pKey) { + private ReceivingOrder getOrder(String pKey) { return repository.findBypKey(pKey).orElseThrow(() -> new NotFoundException( serviceProvider.getTranslator(), RO_NOT_FOUND_BY_PKEY, diff --git a/src/main/java/org/openwms/wms/receiving/impl/ReceivingTransportUnitOrderPosition.java b/src/main/java/org/openwms/wms/receiving/impl/ReceivingTransportUnitOrderPosition.java index 42731fe56..71f074902 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/ReceivingTransportUnitOrderPosition.java +++ b/src/main/java/org/openwms/wms/receiving/impl/ReceivingTransportUnitOrderPosition.java @@ -54,6 +54,9 @@ public ReceivingTransportUnitOrderPosition(Integer posNo, String transportUnitBK this.transportUnitTypeName = transportUnitTypeName; } + /** + * {@inheritDoc} + */ @Override public void validateOnCreation(Validator validator, Class clazz) { if (clazz.isAssignableFrom(ValidationGroups.Create.class)) { @@ -62,6 +65,9 @@ public void validateOnCreation(Validator validator, Class clazz) { validator.validate(this, clazz); } + /** + * {@inheritDoc} + */ @Override public void accept(BaseReceivingOrderPositionVisitor visitor) { visitor.visit(this); diff --git a/src/main/java/org/openwms/wms/receiving/ServiceProvider.java b/src/main/java/org/openwms/wms/receiving/impl/ServiceProvider.java similarity index 71% rename from src/main/java/org/openwms/wms/receiving/ServiceProvider.java rename to src/main/java/org/openwms/wms/receiving/impl/ServiceProvider.java index 02fb927d2..b4aea1fcd 100644 --- a/src/main/java/org/openwms/wms/receiving/ServiceProvider.java +++ b/src/main/java/org/openwms/wms/receiving/impl/ServiceProvider.java @@ -13,19 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.openwms.wms.receiving; +package org.openwms.wms.receiving.impl; import org.ameba.i18n.Translator; import org.openwms.wms.receiving.inventory.ProductService; /** - * A ServiceProvider. + * A ServiceProvider provides access to injected Spring components for not managed classes. * * @author Heiko Scherrer */ public interface ServiceProvider { + /** + * Get a reference to the {@link ProductService}. + * + * @return Ihe instance + */ ProductService getProductService(); + /** + * Get a reference to the {@link Translator}. + * + * @return Ihe instance + */ Translator getTranslator(); } diff --git a/src/main/java/org/openwms/wms/receiving/impl/ServiceProviderImpl.java b/src/main/java/org/openwms/wms/receiving/impl/ServiceProviderImpl.java index 2a0a3cdaa..89860837b 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/ServiceProviderImpl.java +++ b/src/main/java/org/openwms/wms/receiving/impl/ServiceProviderImpl.java @@ -15,9 +15,9 @@ */ package org.openwms.wms.receiving.impl; +import org.ameba.annotation.Measured; import org.ameba.annotation.TxService; import org.ameba.i18n.Translator; -import org.openwms.wms.receiving.ServiceProvider; import org.openwms.wms.receiving.inventory.ProductService; /** @@ -36,11 +36,17 @@ class ServiceProviderImpl implements ServiceProvider { this.productService = productService; } + /** + * {@inheritDoc} + */ @Override public ProductService getProductService() { return productService; } + /** + * {@inheritDoc} + */ @Override public Translator getTranslator() { return translator; diff --git a/src/main/java/org/openwms/wms/receiving/impl/TUCaptureRequestCapturer.java b/src/main/java/org/openwms/wms/receiving/impl/TUCaptureRequestCapturer.java index 5da7e7cdc..267ae48b2 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/TUCaptureRequestCapturer.java +++ b/src/main/java/org/openwms/wms/receiving/impl/TUCaptureRequestCapturer.java @@ -69,11 +69,11 @@ class TUCaptureRequestCapturer extends AbstractCapturer implements ReceivingOrde */ @Override @Measured - public Optional capture(Optional pKey, @NotNull TUCaptureRequestVO request) { - if (pKey.isPresent()) { + public Optional capture(String pKey, @NotNull TUCaptureRequestVO request) { + if (pKey != null) { ValidationUtil.validate(validator, request, ValidationGroups.CreateExpectedTUReceipt.class); return handleExpectedReceipt( - pKey.get(), + pKey, request); } ValidationUtil.validate(validator, request, ValidationGroups.CreateBlindTUReceipt.class); @@ -81,9 +81,7 @@ public Optional capture(Optional pKey, @NotNull TUCaptur throw new CapturingException(translator, TU_TYPE_NOT_GIVEN, new String[0]); } var locationOpt = locationApi.findByErpCodeOpt(request.getActualLocation().getErpCode()); - var location = locationOpt.isPresent() - ? LocationVO.of(locationOpt.get().getLocationId()) - : new LocationVO(); // Handle Locations without locationId later + var location = locationOpt.map(locationVO -> LocationVO.of(locationVO.getLocationId())).orElseGet(LocationVO::new); // Handle Locations without locationId later location.setErpCode(request.getActualLocation().getErpCode()); var tu = new TransportUnitVO(request.getTransportUnit().getTransportUnitId(), location, request.getTransportUnit().getTransportUnitType()); transportUnitApi.createTU(tu); diff --git a/src/main/java/org/openwms/wms/receiving/impl/updaters/ReceivingOrderDetailsUpdater.java b/src/main/java/org/openwms/wms/receiving/impl/updaters/ReceivingOrderDetailsUpdater.java index 923e313ca..3bc1b3963 100644 --- a/src/main/java/org/openwms/wms/receiving/impl/updaters/ReceivingOrderDetailsUpdater.java +++ b/src/main/java/org/openwms/wms/receiving/impl/updaters/ReceivingOrderDetailsUpdater.java @@ -27,7 +27,7 @@ import javax.validation.constraints.NotNull; /** - * A ReceivingOrderDetailsUpdater. + * A ReceivingOrderDetailsUpdater is a {@link ReceivingOrderUpdater} strategy. * * @author Heiko Scherrer */ diff --git a/src/main/java/org/openwms/wms/receiving/inventory/Product.java b/src/main/java/org/openwms/wms/receiving/inventory/Product.java index 13f3b9370..59f0374eb 100644 --- a/src/main/java/org/openwms/wms/receiving/inventory/Product.java +++ b/src/main/java/org/openwms/wms/receiving/inventory/Product.java @@ -25,7 +25,7 @@ import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.UniqueConstraint; -import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Objects; @@ -46,12 +46,12 @@ public class Product extends ApplicationEntity implements Comparable, S /** The foreign persistent key of the {@code Product}. */ @Column(name = "C_FOREIGN_PID", nullable = false) - @NotEmpty + @NotBlank private String foreignPKey; /** The product id is part of the unique business key. */ @Column(name = "C_SKU") - @NotEmpty + @NotBlank private String sku; /** An identifying label of the Product. */ @@ -72,8 +72,8 @@ public class Product extends ApplicationEntity implements Comparable, S //@NotNull private Measurable baseUnit; - @NotNull @Column(name = "C_OVERBOOKING_ALLOWED", nullable = false) + @NotNull private Boolean overbookingAllowed; /** Dear JPA ... */ diff --git a/src/main/java/org/openwms/wms/receiving/spi/wms/location/LocationApi.java b/src/main/java/org/openwms/wms/receiving/spi/wms/location/LocationApi.java index 9a6defc5a..0ec2012b2 100644 --- a/src/main/java/org/openwms/wms/receiving/spi/wms/location/LocationApi.java +++ b/src/main/java/org/openwms/wms/receiving/spi/wms/location/LocationApi.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2022 the original author or authors. + * Copyright 2005-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/org/openwms/wms/receiving/spi/wms/transport/TransportUnitVO.java b/src/main/java/org/openwms/wms/receiving/spi/wms/transport/TransportUnitVO.java index 29244c1ba..80873f495 100644 --- a/src/main/java/org/openwms/wms/receiving/spi/wms/transport/TransportUnitVO.java +++ b/src/main/java/org/openwms/wms/receiving/spi/wms/transport/TransportUnitVO.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2022 the original author or authors. + * Copyright 2005-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/main/java/org/openwms/wms/receiving/transport/TransportUnit.java b/src/main/java/org/openwms/wms/receiving/transport/TransportUnit.java index c387bcb46..b45f1b37a 100644 --- a/src/main/java/org/openwms/wms/receiving/transport/TransportUnit.java +++ b/src/main/java/org/openwms/wms/receiving/transport/TransportUnit.java @@ -21,8 +21,7 @@ import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.UniqueConstraint; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; +import javax.validation.constraints.NotBlank; import java.io.Serializable; import java.util.Objects; @@ -40,16 +39,17 @@ public class TransportUnit extends ApplicationEntity implements Serializable { /** The foreign persistent key of the {@code TransportUnit}. */ @Column(name = "C_FOREIGN_PID", nullable = false) - @NotEmpty + @NotBlank private String foreignPKey; /** Unique natural key. */ @Column(name = "C_BARCODE", nullable = false) - @NotNull + @NotBlank private String barcode; /** The current {@code Location} of the {@code TransportUnit}. */ @Column(name = "C_ACTUAL_LOCATION", nullable = false) + @NotBlank private String actualLocation; /** Dear JPA... */