ShippingOrderPositionVO.java

/*
 * Copyright 2005-2025 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.shipping.api;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.openwms.core.units.api.Measurable;

import java.io.Serializable;
import java.util.Objects;
import java.util.StringJoiner;

/**
 * A ShippingOrderPositionVO.
 *
 * @author Heiko Scherrer
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class ShippingOrderPositionVO extends BaseShippingOrderPositionVO<ShippingOrderPositionVO> implements Serializable {

    /** The ordered product, must not be {@code null}. */
    @NotNull(message = "{owms.wms.shp.sku}", groups = ValidationGroups.Create.class)
    @JsonProperty("product")
    private ProductVO product;
    /** Quantity ordered, must not be {@code null}. */
    @Valid
    @NotNull(message = "{owms.wms.shp.qtyOrdered}", groups = ValidationGroups.Create.class)
    @JsonProperty("qtyOrdered")
    private Measurable<?, ?, ?> qtyOrdered;
    /** Quantity for crossdocking. */
    @JsonProperty("qtyCrossdock")
    private Measurable<?, ?, ?> qtyCrossdock;
    /** The quantity that has been allocated. */
    @JsonProperty("qtyAllocated")
    private Measurable<?,?,?> qtyAllocated;

    /*~-------------------- methods --------------------*/

    /**
     * {@inheritDoc}
     *
     * All fields.
     */
    @Override
    public String toString() {
        return new StringJoiner(", ", ShippingOrderPositionVO.class.getSimpleName() + "[", "]")
                .add("product=" + product)
                .add("qtyOrdered=" + qtyOrdered)
                .add("qtyCrossdock=" + qtyCrossdock)
                .add("qtyAllocated=" + qtyAllocated)
                .toString();
    }

    /**
     * {@inheritDoc}
     *
     * All fields.
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ShippingOrderPositionVO that)) return false;
        if (!super.equals(o)) return false;
        return Objects.equals(product, that.product) && Objects.equals(qtyOrdered, that.qtyOrdered) && Objects.equals(qtyCrossdock, that.qtyCrossdock) && Objects.equals(qtyAllocated, that.qtyAllocated);
    }

    /**
     * {@inheritDoc}
     *
     * All fields.
     */
    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), product, qtyOrdered, qtyCrossdock, qtyAllocated);
    }

    /*~-------------------- accessors --------------------*/
    public ProductVO getProduct() {
        return product;
    }

    public void setProduct(ProductVO product) {
        this.product = product;
    }

    public Measurable<?, ?, ?> getQtyOrdered() {
        return qtyOrdered;
    }

    public void setQtyOrdered(@Valid @NotNull(message = "{owms.wms.shp.qtyOrdered}", groups = ValidationGroups.Create.class) Measurable<?, ?, ?> qtyOrdered) {
        this.qtyOrdered = qtyOrdered;
    }

    public Measurable<?, ?, ?> getQtyCrossdock() {
        return qtyCrossdock;
    }

    public void setQtyCrossdock(Measurable<?, ?, ?> qtyCrossdock) {
        this.qtyCrossdock = qtyCrossdock;
    }

    public Measurable<?, ?, ?> getQtyAllocated() {
        return qtyAllocated;
    }

    public void setQtyAllocated(Measurable<?, ?, ?> qtyAllocated) {
        this.qtyAllocated = qtyAllocated;
    }
}