TransportUnitMapperImpl.java

package org.openwms.wms.transport;

import java.time.LocalDateTime;
import java.time.ZoneId;
import javax.annotation.processing.Generated;
import org.openwms.common.transport.api.messages.TransportUnitMO;
import org.openwms.common.transport.api.messages.TransportUnitTypeMO;
import org.openwms.wms.location.impl.LocationMapper;
import org.openwms.wms.transport.api.TransportUnitVO;
import org.openwms.wms.transport.barcode.Barcode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

    private final LocationMapper locationMapper;

    @Autowired
    public TransportUnitMapperImpl(LocationMapper locationMapper) {

        this.locationMapper = locationMapper;
    }

    @Override
    public TransportUnit convertMO(TransportUnitMO mo) {
        if ( mo == null ) {
            return null;
        }

        TransportUnit.Builder transportUnit = TransportUnit.newBuilder();

        transportUnit.transportUnitType( moTransportUnitTypeType( mo ) );
        transportUnit.foreignPKey( mo.getpKey() );
        transportUnit.pKey( mo.getpKey() );
        transportUnit.actualLocation( locationMapper.convertFromMO( mo.getActualLocation() ) );
        transportUnit.actualLocationDate( mo.getActualLocationDate() );
        transportUnit.state( mo.getState() );

        transportUnit.transportUnitBK( org.openwms.wms.transport.barcode.Barcode.of(mo.getBarcode()) );

        return transportUnit.build();
    }

    @Override
    public TransportUnit convertVO(TransportUnitVO vo) {
        if ( vo == null ) {
            return null;
        }

        TransportUnit.Builder transportUnit = TransportUnit.newBuilder();

        transportUnit.customerOrderId( vo.getCustomerOrderId() );
        transportUnit.pKey( vo.getpKey() );
        transportUnit.actualLocation( locationMapper.convertFromVO( vo.getActualLocation() ) );
        if ( vo.getActualLocationDate() != null ) {
            transportUnit.actualLocationDate( LocalDateTime.ofInstant( vo.getActualLocationDate().toInstant(), ZoneId.of( "UTC" ) ) );
        }
        transportUnit.target( vo.getTarget() );
        transportUnit.state( vo.getState() );
        transportUnit.transportUnitType( vo.getTransportUnitType() );
        transportUnit.length( vo.getLength() );
        transportUnit.width( vo.getWidth() );
        transportUnit.height( vo.getHeight() );
        transportUnit.reconciledBy( vo.getReconciledBy() );
        transportUnit.reconciledAt( vo.getReconciledAt() );

        transportUnit.transportUnitBK( org.openwms.wms.transport.barcode.Barcode.of(vo.getTransportUnitBK()) );

        return transportUnit.build();
    }

    @Override
    public TransportUnitVO convertVO(TransportUnit eo) {
        if ( eo == null ) {
            return null;
        }

        TransportUnitVO.Builder transportUnitVO = TransportUnitVO.builder();

        transportUnitVO.transportUnitBK( eoTransportUnitBKValue( eo ) );
        transportUnitVO.customerOrderId( eo.getCustomerOrderId() );
        transportUnitVO.actualLocation( locationMapper.convertToVO( eo.getActualLocation() ) );
        transportUnitVO.target( eo.getTarget() );
        transportUnitVO.transportUnitType( eo.getTransportUnitType() );
        transportUnitVO.length( eo.getLength() );
        transportUnitVO.width( eo.getWidth() );
        transportUnitVO.height( eo.getHeight() );
        transportUnitVO.reconciledBy( eo.getReconciledBy() );
        transportUnitVO.reconciledAt( eo.getReconciledAt() );

        return transportUnitVO.build();
    }

    private String moTransportUnitTypeType(TransportUnitMO transportUnitMO) {
        TransportUnitTypeMO transportUnitType = transportUnitMO.getTransportUnitType();
        if ( transportUnitType == null ) {
            return null;
        }
        return transportUnitType.getType();
    }

    private String eoTransportUnitBKValue(TransportUnit transportUnit) {
        Barcode transportUnitBK = transportUnit.getTransportUnitBK();
        if ( transportUnitBK == null ) {
            return null;
        }
        return transportUnitBK.getValue();
    }
}