Skip to content

Commit

Permalink
code polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
openwms committed Apr 2, 2023
1 parent 107303c commit b687126
Show file tree
Hide file tree
Showing 28 changed files with 95 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +37,7 @@ public enum Type {
private Type type;
private String transportUnitId;

@NotEmpty
@NotBlank
private String messageText;
private String messageNumber;
private Date messageOccurred;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/openwms/wms/receiving/api/LocationVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,7 +32,7 @@
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class LocationVO extends AbstractBase<LocationVO> implements Serializable {

@NotEmpty
@NotBlank
@JsonProperty("erpCode")
private String erpCode;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/openwms/wms/receiving/api/ProductVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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. */
Expand All @@ -54,7 +54,7 @@ public class ProductVO implements Serializable {
ProductVO() {
}

public ProductVO(@NotEmpty String sku) {
public ProductVO(@NotBlank String sku) {
this.sku = sku;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,7 +71,7 @@ public void sortPositions() {
}
}

public ReceivingOrderVO(@NotEmpty String orderId) {
public ReceivingOrderVO(@NotBlank String orderId) {
this.orderId = orderId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,20 +36,20 @@ 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
ReceivingTransportUnitOrderPositionVO() {}

@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;
Expand All @@ -59,15 +59,15 @@ 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;
}

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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ class QuantityCaptureOnLocationRequestCapturer extends AbstractCapturer implemen
*/
@Measured
@Override
public Optional<ReceivingOrder> capture(Optional<String> pKey, @NotNull QuantityCaptureOnLocationRequestVO request) {
public Optional<ReceivingOrder> 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)
Expand All @@ -102,14 +102,13 @@ private Supplier<NotFoundException> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ class QuantityCaptureRequestCapturer extends AbstractCapturer implements Receivi
*/
@Override
@Measured
public Optional<ReceivingOrder> capture(Optional<String> pKey, @NotNull QuantityCaptureRequestVO request) {
if (pKey.isPresent()) {
public Optional<ReceivingOrder> 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));
Expand Down Expand Up @@ -102,7 +102,7 @@ private Optional<ReceivingOrder> 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");
Expand All @@ -119,21 +119,20 @@ private Optional<ReceivingOrder> 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)
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ public interface ReceivingOrderCapturer<T extends CaptureRequestVO> 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<ReceivingOrder> capture(Optional<String> pKey, @NotNull T request);
Optional<ReceivingOrder> capture(String pKey, @NotNull T request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author Heiko Scherrer
*/
public interface ReceivingOrderRepository extends JpaRepository<ReceivingOrder, Long> {
interface ReceivingOrderRepository extends JpaRepository<ReceivingOrder, Long> {

Optional<ReceivingOrder> findBypKey(String pKey);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit b687126

Please sign in to comment.