AbstractReservation.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.inventory;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import org.ameba.integration.jpa.ApplicationEntity;
import org.ameba.integration.jpa.BaseEntity;
import org.hibernate.envers.AuditOverride;
import org.hibernate.envers.Audited;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Objects;
import static org.openwms.wms.api.TimeProvider.DATE_TIME_WITH_TIMEZONE;
/**
* A AbstractReservation.
*
* @author Heiko Scherrer
*/
@Audited
@AuditOverride(forClass = ApplicationEntity.class)
@AuditOverride(forClass = BaseEntity.class)
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public abstract class AbstractReservation extends ApplicationEntity implements Serializable {
/** An arbitrary field to store User, PickOrderPositionSplit etc. */
@Column(name = "C_RESERVED_BY")
private String reservedBy;
@DateTimeFormat(pattern = DATE_TIME_WITH_TIMEZONE)
@Column(name = "C_RESERVED_AT", columnDefinition = "timestamp(0)")
private ZonedDateTime reservedAt;
/** Dear JPA... */
protected AbstractReservation() { }
public AbstractReservation(String reservedBy) {
this.reservedBy = reservedBy;
this.reservedAt = ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault());
}
public String getReservedBy() {
return reservedBy;
}
public void setReservedBy(String reservedBy) {
this.reservedBy = reservedBy;
if (reservedBy != null) {
this.reservedAt = ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault());
}
}
public ZonedDateTime getReservedAt() {
return reservedAt;
}
@Override
public String toString() {
return "AbstractReservation{" +
"reservedBy='" + reservedBy + '\'' +
", reservedAt=" + reservedAt +
'}';
}
/**
* {@inheritDoc}
*
* All fields.
*/
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof AbstractReservation)) return false;
if (!super.equals(o)) return false;
var that = (AbstractReservation) o;
return Objects.equals(reservedBy, that.reservedBy) && Objects.equals(reservedAt, that.reservedAt);
}
/**
* {@inheritDoc}
*
* All fields.
*/
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), reservedBy, reservedAt);
}
}