TransportUnitEvent.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.transport.events;
import org.openwms.core.event.RootApplicationEvent;
import org.openwms.wms.transport.TransportUnit;
import java.io.Serializable;
/**
* A TransportUnitEvent.
*
* @author Heiko Scherrer
*/
public final class TransportUnitEvent extends RootApplicationEvent implements Serializable {
private final TransportUnitEventType type;
private String transportUnitBK;
private String actualLocation;
private TransportUnitEvent(TransportUnit source, TransportUnitEventType type) {
super(source);
this.type = type;
}
/**
* Factory method to create a TransportUnitEvent from a given TransportUnit instance.
*
* @param tu The TransportUnit instance must not be {@literal null}
* @param type The type of event
* @return The event instance
*/
public static TransportUnitEvent of(TransportUnit tu, TransportUnitEventType type) {
var transportUnitEvent = new TransportUnitEvent(tu, type);
if (tu.getTransportUnitBK() != null) {
transportUnitEvent.transportUnitBK = tu.getTransportUnitBK().getValue();
}
if (tu.getActualLocation() != null) {
transportUnitEvent.actualLocation = tu.getActualLocation().toString();
}
return transportUnitEvent;
}
public enum TransportUnitEventType {
REQUEST, MOVED, CREATED;
}
@Override
public TransportUnit getSource() {
return (TransportUnit) super.getSource();
}
public TransportUnitEventType getType() {
return type;
}
public String getTransportUnitBK() {
return transportUnitBK;
}
public String getActualLocation() {
return actualLocation;
}
}