Skip to content

Commit

Permalink
Use data structures instead of simple types wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
openwms committed Mar 28, 2023
1 parent c425433 commit fb0453a
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 46 deletions.
48 changes: 18 additions & 30 deletions src/main/java/org/openwms/wms/receiving/api/TUCaptureRequestVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.openwms.wms.receiving.ValidationGroups;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
Expand All @@ -30,10 +31,10 @@
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class TUCaptureRequestVO extends CaptureRequestVO implements Serializable {

/** The business key of the actual captured {@code TransportUnit} where the goods are placed on. */
@JsonProperty("transportUnitBK")
@NotBlank(groups = {ValidationGroups.CreateBlindTUReceipt.class, ValidationGroups.CreateExpectedTUReceipt.class})
private String transportUnitId;
/** The actual captured {@code TransportUnit} where the goods are located on. */
@JsonProperty("transportUnit")
@NotNull(groups = {ValidationGroups.CreateBlindTUReceipt.class, ValidationGroups.CreateExpectedTUReceipt.class})
private TransportUnitVO transportUnit;

/** The unique identifier if the {@code LoadUnit} where the goods are stored in. */
@JsonProperty("loadUnitLabel")
Expand All @@ -49,22 +50,17 @@ public class TUCaptureRequestVO extends CaptureRequestVO implements Serializable
@NotBlank(groups = ValidationGroups.CreateExpectedTUReceipt.class)
private String expectedTransportUnitBK;

/** The ERP code of the actual {@code Location} where the goods were received. */
@JsonProperty("actualLocationErpCode")
@NotBlank(groups = {ValidationGroups.CreateBlindTUReceipt.class, ValidationGroups.CreateExpectedTUReceipt.class})
private String actualLocationErpCode;
/** The {@code Location} where the captured {@code TransportUnit} is located on. */
@JsonProperty("actualLocation")
@NotNull(groups = {ValidationGroups.CreateBlindTUReceipt.class, ValidationGroups.CreateExpectedTUReceipt.class})
private LocationVO actualLocation;

/** The type of {@code TransportUnit} in case it needs to be created (optional). */
@JsonProperty("transportUnitType")
@NotBlank(groups = ValidationGroups.CreateBlindTUReceipt.class)
private String transportUnitType;

public String getTransportUnitId() {
return transportUnitId;
public TransportUnitVO getTransportUnit() {
return transportUnit;
}

public void setTransportUnitId(String transportUnitId) {
this.transportUnitId = transportUnitId;
public void setTransportUnit(TransportUnitVO transportUnit) {
this.transportUnit = transportUnit;
}

public String getLoadUnitLabel() {
Expand All @@ -91,23 +87,15 @@ public void setExpectedTransportUnitBK(String expectedTransportUnitBK) {
this.expectedTransportUnitBK = expectedTransportUnitBK;
}

public String getActualLocationErpCode() {
return actualLocationErpCode;
}

public void setActualLocationErpCode(String actualLocationErpCode) {
this.actualLocationErpCode = actualLocationErpCode;
}

public boolean hasTransportUnitType() {
return transportUnitType != null && !transportUnitType.isEmpty();
return transportUnit != null && transportUnit.getTransportUnitType() != null && !transportUnit.getTransportUnitType().isEmpty();
}

public String getTransportUnitType() {
return transportUnitType;
public LocationVO getActualLocation() {
return actualLocation;
}

public void setTransportUnitType(String transportUnitType) {
this.transportUnitType = transportUnitType;
public void setActualLocation(LocationVO actualLocation) {
this.actualLocation = actualLocation;
}
}
52 changes: 52 additions & 0 deletions src/main/java/org/openwms/wms/receiving/api/TransportUnitVO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.api;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.ameba.http.AbstractBase;

import java.io.Serializable;

/**
* A TransportUnitVO.
*
* @author Heiko Scherrer
*/
public class TransportUnitVO extends AbstractBase<LocationVO> implements Serializable {

@JsonProperty("transportUnitBK")
private String transportUnitId;

/** The type of {@code TransportUnit} in case it needs to be created (optional). */
@JsonProperty("transportUnitType")
private String transportUnitType;

public String getTransportUnitId() {
return transportUnitId;
}

public void setTransportUnitId(String transportUnitId) {
this.transportUnitId = transportUnitId;
}

public String getTransportUnitType() {
return transportUnitType;
}

public void setTransportUnitType(String transportUnitType) {
this.transportUnitType = transportUnitType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ public Optional<ReceivingOrder> capture(Optional<String> pKey, @NotNull TUCaptur
if (!request.hasTransportUnitType()) {
throw new CapturingException(translator, TU_TYPE_NOT_GIVEN, new String[0]);
}
var locationOpt = locationApi.findByErpCodeOpt(request.getActualLocationErpCode());
var locationOpt = locationApi.findByErpCodeOpt(request.getActualLocation().getErpCode());
var location = locationOpt.map(locationVO -> LocationVO.of(locationVO.getLocationId()))
.orElseGet(LocationVO::new); // Handle Locations without locationId later
location.setErpCode(request.getActualLocationErpCode());
var tu = new TransportUnitVO(request.getTransportUnitId(), location, request.getTransportUnitType());
location.setErpCode(request.getActualLocation().getErpCode());
var tu = new TransportUnitVO(request.getTransportUnit().getTransportUnitId(), location, request.getTransportUnit().getTransportUnitType());
transportUnitApi.createTU(tu);
return Optional.empty();
}

private Optional<ReceivingOrder> handleExpectedReceipt(String pKey, TUCaptureRequestVO request) {
var receivingOrder = getOrder(pKey);
final var transportUnitBK = request.getTransportUnitId();
final var actualLocationErpCode = request.getActualLocationErpCode();
final var transportUnitBK = request.getTransportUnit().getTransportUnitId();
final var actualLocationErpCode = request.getActualLocation().getErpCode();
Optional<ReceivingTransportUnitOrderPosition> openPosition = receivingOrder.getPositions().stream()
.filter(p -> p.getState() == CREATED || p.getState() == PROCESSING)
.filter(ReceivingTransportUnitOrderPosition.class::isInstance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openwms.wms.receiving.api.QuantityCaptureRequestVO;
import org.openwms.wms.receiving.api.ReceivingOrderVO;
import org.openwms.wms.receiving.api.TUCaptureRequestVO;
import org.openwms.wms.receiving.api.TransportUnitVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.restdocs.RestDocumentationContextProvider;
Expand Down Expand Up @@ -335,11 +336,14 @@ void setUp(RestDocumentationContextProvider restDocumentation) {
@Rollback
@Test void shall_do_a_TUCapture_with_unexpected_TU() throws Exception {
var vo = new TUCaptureRequestVO();
vo.setTransportUnitId("00000000000000004711"); // The captured TU
var tu = new TransportUnitVO();
var actualLocation = new LocationVO("WE01"); // Where the goods have been captured
tu.setTransportUnitId("00000000000000004711"); // The captured TU
vo.setTransportUnit(tu);
vo.setExpectedTransportUnitBK("00000000000000004712"); // The expected TU
vo.setLoadUnitLabel("1"); // The LU id of the captured TU
vo.setLoadUnitType("EURO"); // The LU type
vo.setActualLocationErpCode("WE01"); // Where the goods have been captured
vo.setActualLocation(actualLocation);
mockMvc
.perform(
post("/v1/receiving-orders/{pKey}/capture", ORDER1_PKEY)
Expand All @@ -355,11 +359,14 @@ void setUp(RestDocumentationContextProvider restDocumentation) {
@Rollback
@Test void shall_do_a_TUCapture_with_expected_TU() throws Exception {
var vo = new TUCaptureRequestVO();
vo.setTransportUnitId("00000000000000004712"); // The captured TU
var tu = new TransportUnitVO();
tu.setTransportUnitId("00000000000000004712"); // The captured TU
var loc = new LocationVO("WE01"); // Where the goods have been captured
vo.setTransportUnit(tu);
vo.setActualLocation(loc);
vo.setExpectedTransportUnitBK("00000000000000004712"); // The expected TU
vo.setLoadUnitLabel("1"); // The LU id of the captured TU
vo.setLoadUnitType("EURO"); // The LU type
vo.setActualLocationErpCode("WE01"); // Where the goods have been captured
mockMvc
.perform(
post("/v1/receiving-orders/{pKey}/capture", ORDER1_PKEY)
Expand All @@ -375,9 +382,12 @@ void setUp(RestDocumentationContextProvider restDocumentation) {
@Rollback
@Test void shall_do_a_BlindReceipt_with_TU() throws Exception {
var vo = new TUCaptureRequestVO();
vo.setTransportUnitId("00000000000000004712"); // The captured TU
vo.setTransportUnitType("FP"); // The TU-Type of the captured TU
vo.setActualLocationErpCode("WE01"); // Where the goods have been captured
var tu = new TransportUnitVO();
tu.setTransportUnitId("00000000000000004712"); // The captured TU
tu.setTransportUnitType("FP"); // The TU-Type of the captured TU
var loc = new LocationVO("WE01"); // Where the goods have been captured
vo.setTransportUnit(tu);
vo.setActualLocation(loc);
mockMvc
.perform(
post("/v1/capture")
Expand All @@ -389,9 +399,10 @@ void setUp(RestDocumentationContextProvider restDocumentation) {
requestFields(
fieldWithPath("[]").description("Accepts multiple capture requests"),
fieldWithPath("[].@class").description("The type of capturing"),
fieldWithPath("[].transportUnitBK").description("The business key of the actual captured TransportUnit where the goods are placed on"),
fieldWithPath("[].actualLocationErpCode").description("The business key of the Location"),
fieldWithPath("[].transportUnitType").description("The type of TransportUnit in case it needs to be created")
fieldWithPath("[].transportUnit").description("The actual captured TransportUnit where the goods are placed on"),
fieldWithPath("[].transportUnit.*").ignored(),
fieldWithPath("[].actualLocation").description("The Location where the TransportUnit is placed on"),
fieldWithPath("[].actualLocation.*").ignored()
)
))
.andExpect(status().isNoContent())
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<logger name="org.junit" level="OFF"/>
<logger name="org.openwms" level="DEBUG"/>

<logger name="PRESENTATION_LAYER_EXCEPTION" level="OFF" additivity="false">
<logger name="PRESENTATION_LAYER_EXCEPTION" level="ERROR" additivity="false">
<appender-ref ref="STDOUT"/>
</logger>
<logger name="SERVICE_LAYER_EXCEPTION" level="OFF" additivity="false">
Expand Down

0 comments on commit fb0453a

Please sign in to comment.