PackagingUnitDecorator.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 org.ameba.annotation.Public;
import org.openwms.values.Message;
import org.openwms.wms.CycleAvoidingMappingContext;
import org.openwms.wms.inventory.api.PackagingUnitVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

/**
 * A PackagingUnitDecorator.
 *
 * @author Heiko Scherrer
 */
@Public
public abstract class PackagingUnitDecorator implements PackagingUnitMapper {

    protected PackagingUnitMapper delegate;

    @Autowired
    @Qualifier("delegate")
    public void setDelegate(PackagingUnitMapper delegate) {
        this.delegate = delegate;
    }

    @Override
    public PackagingUnit convertVO(PackagingUnitVO vo, CycleAvoidingMappingContext cycleAvoidingMappingContext) {
        if (vo == null) {
            return null;
        }
        PackagingUnit entity;
        if (vo.pKey != null && !vo.pKey.isEmpty()) {
            throw new IllegalArgumentException("Currently not supported to converted existing PackagingUnitVO to PackagingUnit classes");
        } else {
            entity = delegate.convertVO(vo, cycleAvoidingMappingContext);
            if (vo.loadUnit != null) {
                // TODO [openwms]: 17.07.21
                // Implement LoadUnitMapper accordingly and set the loadUnit
            }
            if (vo.message != null && !vo.message.isEmpty()) {
                entity.setMessage(new Message(vo.message));
            }
        }
        entity.validate();
        return entity;
    }
}