AllocationMapperImpl.java

package org.openwms.wms.inventory.allocation;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.processing.Generated;
import org.openwms.wms.inventory.LoadUnit;
import org.openwms.wms.inventory.Product;
import org.openwms.wms.inventory.allocation.api.AllocationVO;
import org.openwms.wms.location.Location;
import org.openwms.wms.transport.TransportUnit;
import org.openwms.wms.transport.barcode.Barcode;
import org.springframework.stereotype.Component;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor"
)
@Component
public class AllocationMapperImpl implements AllocationMapper {

    @Override
    public AllocationVO convert(Allocation entity) {
        if ( entity == null ) {
            return null;
        }

        AllocationVO.Builder allocationVO = AllocationVO.newBuilder();

        allocationVO.transportUnitBK( entityTransportUnitTransportUnitBKValue( entity ) );
        String physicalPosition = entityLoadUnitPhysicalPosition( entity );
        if ( entity.hasLoadUnit() ) {
            allocationVO.loadUnitPosition( physicalPosition );
        }
        allocationVO.sku( entityProductSku( entity ) );
        allocationVO.actualErpCode( entityActualLocationErpCode( entity ) );
        allocationVO.qtyAllocated( entity.getQtyAvailable() );
        allocationVO.reservationId( entity.getReservationId() );

        return allocationVO.build();
    }

    @Override
    public List<AllocationVO> convert(List<Allocation> entities) {
        if ( entities == null ) {
            return null;
        }

        List<AllocationVO> list = new ArrayList<AllocationVO>( entities.size() );
        for ( Allocation allocation : entities ) {
            list.add( convert( allocation ) );
        }

        return list;
    }

    private String entityTransportUnitTransportUnitBKValue(Allocation allocation) {
        TransportUnit transportUnit = allocation.getTransportUnit();
        if ( transportUnit == null ) {
            return null;
        }
        Barcode transportUnitBK = transportUnit.getTransportUnitBK();
        if ( transportUnitBK == null ) {
            return null;
        }
        return transportUnitBK.getValue();
    }

    private String entityLoadUnitPhysicalPosition(Allocation allocation) {
        if ( !allocation.hasLoadUnit() ) {
            return null;
        }
        LoadUnit loadUnit = allocation.getLoadUnit();
        return loadUnit.getPhysicalPosition();
    }

    private String entityProductSku(Allocation allocation) {
        Product product = allocation.getProduct();
        if ( product == null ) {
            return null;
        }
        return product.getSku();
    }

    private String entityActualLocationErpCode(Allocation allocation) {
        Location actualLocation = allocation.getActualLocation();
        if ( actualLocation == null ) {
            return null;
        }
        if ( actualLocation == null || !actualLocation.hasErpCode() ) {
            return null;
        }
        return actualLocation.getErpCode();
    }
}