RouteMapperImpl.java

package org.openwms.tms.routing.ui.impl;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.processing.Generated;
import org.openwms.tms.routing.LocationEO;
import org.openwms.tms.routing.RouteImpl;
import org.openwms.tms.routing.ui.api.RouteVO;
import org.springframework.stereotype.Component;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor"
)
@Component
class RouteMapperImpl extends RouteMapper {

    @Override
    public RouteImpl convertVO(RouteVO vo) {
        if ( vo == null ) {
            return null;
        }

        String routeId = null;

        routeId = vo.getName();

        RouteImpl routeImpl = new RouteImpl( routeId );

        routeImpl.setPersistentKey( vo.getKey() );
        routeImpl.setDescription( vo.getDescription() );
        routeImpl.setSourceLocationGroupName( vo.getSourceLocationGroupName() );
        routeImpl.setTargetLocationGroupName( vo.getTargetLocationGroupName() );
        if ( vo.getEnabled() != null ) {
            routeImpl.setEnabled( vo.getEnabled() );
        }

        routeImpl.setSourceLocation( vo.hasSourceLocationName() ? srv.findByLocationId(vo.getSourceLocationName()).orElseThrow() : null );
        routeImpl.setTargetLocation( vo.hasTargetLocationName() ? srv.findByLocationId(vo.getTargetLocationName()).orElseThrow() : null );

        return routeImpl;
    }

    @Override
    public RouteVO convertEO(RouteImpl eo) {
        if ( eo == null ) {
            return null;
        }

        RouteVO routeVO = new RouteVO();

        if ( eo.hasPersistentKey() ) {
            routeVO.setKey( eo.getPersistentKey() );
        }
        routeVO.setName( eo.getRouteId() );
        String locationId = eoSourceLocationLocationId( eo );
        if ( eo.hasSourceLocation() ) {
            routeVO.setSourceLocationName( locationId );
        }
        String locationId1 = eoTargetLocationLocationId( eo );
        if ( eo.hasTargetLocation() ) {
            routeVO.setTargetLocationName( locationId1 );
        }
        routeVO.setOl( eo.getOl() );
        routeVO.setCreateDt( eo.getCreateDt() );
        routeVO.setLastModifiedDt( eo.getLastModifiedDt() );
        routeVO.setDescription( eo.getDescription() );
        routeVO.setSourceLocationGroupName( eo.getSourceLocationGroupName() );
        routeVO.setTargetLocationGroupName( eo.getTargetLocationGroupName() );
        routeVO.setEnabled( eo.isEnabled() );

        return routeVO;
    }

    @Override
    public List<RouteVO> convertEO(List<RouteImpl> eos) {
        if ( eos == null ) {
            return null;
        }

        List<RouteVO> list = new ArrayList<RouteVO>( eos.size() );
        for ( RouteImpl routeImpl : eos ) {
            list.add( convertEO( routeImpl ) );
        }

        return list;
    }

    @Override
    public RouteImpl copy(RouteVO vo, RouteImpl target) {
        if ( vo == null ) {
            return target;
        }

        target.setPersistentKey( vo.getKey() );
        target.setRouteId( vo.getName() );
        target.setDescription( vo.getDescription() );
        target.setSourceLocationGroupName( vo.getSourceLocationGroupName() );
        target.setTargetLocationGroupName( vo.getTargetLocationGroupName() );
        if ( vo.getEnabled() != null ) {
            target.setEnabled( vo.getEnabled() );
        }

        target.setSourceLocation( vo.hasSourceLocationName() ? srv.findByLocationId(vo.getSourceLocationName()).orElseThrow() : null );
        target.setTargetLocation( vo.hasTargetLocationName() ? srv.findByLocationId(vo.getTargetLocationName()).orElseThrow() : null );

        return target;
    }

    private String eoSourceLocationLocationId(RouteImpl routeImpl) {
        if ( !routeImpl.hasSourceLocation() ) {
            return null;
        }
        LocationEO sourceLocation = routeImpl.getSourceLocation();
        return sourceLocation.getLocationId();
    }

    private String eoTargetLocationLocationId(RouteImpl routeImpl) {
        if ( !routeImpl.hasTargetLocation() ) {
            return null;
        }
        LocationEO targetLocation = routeImpl.getTargetLocation();
        return targetLocation.getLocationId();
    }
}