Reservation.java

  1. /*
  2.  * Copyright 2005-2025 the original author or authors.
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  * http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package org.openwms.wms.inventory;

  17. import jakarta.persistence.AttributeOverride;
  18. import jakarta.persistence.Column;
  19. import jakarta.persistence.Entity;
  20. import jakarta.persistence.FetchType;
  21. import jakarta.persistence.ForeignKey;
  22. import jakarta.persistence.JoinColumn;
  23. import jakarta.persistence.ManyToOne;
  24. import jakarta.persistence.Table;
  25. import org.ameba.integration.jpa.ApplicationEntity;
  26. import org.ameba.integration.jpa.BaseEntity;
  27. import org.hibernate.annotations.CompositeType;
  28. import org.hibernate.envers.AuditOverride;
  29. import org.hibernate.envers.Audited;
  30. import org.openwms.core.units.UnitConstants;
  31. import org.openwms.core.units.api.Measurable;
  32. import org.openwms.core.units.persistence.UnitUserType;

  33. import java.io.Serializable;
  34. import java.util.Objects;

  35. /**
  36.  * A Reservation.
  37.  *
  38.  * @author Heiko Scherrer
  39.  */
  40. @Audited
  41. @AuditOverride(forClass = ApplicationEntity.class)
  42. @AuditOverride(forClass = BaseEntity.class)
  43. @Entity
  44. @Table(name = "WMS_INV_RESERVATION")
  45. public class Reservation extends AbstractReservation implements Serializable {

  46.     /** The {@code PackagingUnit} instance, the {@code Reservation} belongs to. */
  47.     @ManyToOne(fetch = FetchType.LAZY)
  48.     @JoinColumn(name = "C_PACKAGING_UNIT_PK", referencedColumnName = "C_PK", nullable = false, foreignKey = @ForeignKey(name = "FK_PURESERVATION_PK"))
  49.     private PackagingUnit packagingUnit;

  50.     /** The reserved quantity of this PackagingUnit. */
  51.     @CompositeType(UnitUserType.class)
  52.     @AttributeOverride(name = "unitType", column = @Column(name = "C_QTY_TYPE_RESERVED"))
  53.     @AttributeOverride(name = "magnitude", column = @Column(name = "C_QTY_RESERVED", length = UnitConstants.QUANTITY_LENGTH))
  54.     private Measurable<?,?,?> quantityReserved;

  55.     /** Dear JPA... */
  56.     protected Reservation() { }

  57.     public Reservation(Measurable quantityReserved, String reservedBy) {
  58.         super(reservedBy);
  59.         this.quantityReserved = quantityReserved;
  60.     }

  61.     public PackagingUnit getPackagingUnit() {
  62.         return packagingUnit;
  63.     }

  64.     public void setPackagingUnit(PackagingUnit packagingUnit) {
  65.         this.packagingUnit = packagingUnit;
  66.     }

  67.     public Measurable getQuantityReserved() {
  68.         return quantityReserved;
  69.     }

  70.     public void setQuantityReserved(Measurable quantityReserved) {
  71.         this.quantityReserved = quantityReserved;
  72.     }

  73.     @Override
  74.     public String toString() {
  75.         return "Reservation{quantityReserved=" + quantityReserved+"}";
  76.     }

  77.     /**
  78.      * {@inheritDoc}
  79.      *
  80.      * All fields.
  81.      */
  82.     @Override
  83.     public boolean equals(Object o) {
  84.         if (this == o) return true;
  85.         if (!(o instanceof Reservation)) return false;
  86.         if (!super.equals(o)) return false;
  87.         Reservation that = (Reservation) o;
  88.         return Objects.equals(packagingUnit, that.packagingUnit) && Objects.equals(quantityReserved, that.quantityReserved);
  89.     }

  90.     /**
  91.      * {@inheritDoc}
  92.      *
  93.      * All fields.
  94.      */
  95.     @Override
  96.     public int hashCode() {
  97.         return Objects.hash(super.hashCode(), packagingUnit, quantityReserved);
  98.     }
  99. }