LocationMapperImpl.java

package org.openwms.common.location;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.processing.Generated;
import org.openwms.common.account.Account;
import org.openwms.common.account.AccountMapper;
import org.openwms.common.location.api.LocationVO;
import org.openwms.common.location.api.messages.LocationMO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

    private final AccountMapper accountMapper;
    private final LocationTypeMapper locationTypeMapper;
    private final LocationGroupMapper locationGroupMapper;

    @Autowired
    public LocationMapperImpl(AccountMapper accountMapper, LocationTypeMapper locationTypeMapper, LocationGroupMapper locationGroupMapper) {

        this.accountMapper = accountMapper;
        this.locationTypeMapper = locationTypeMapper;
        this.locationGroupMapper = locationGroupMapper;
    }

    @Override
    public Location convertVO(LocationVO vo) {
        if ( vo == null ) {
            return null;
        }

        LocationType locationType = null;
        Account account = null;
        LocationGroup locationGroup = null;
        String erpCode = null;
        String plcCode = null;
        Integer sortOrder = null;
        String stockZone = null;

        locationType = locationTypeMapper.convertFromString( vo.getType() );
        if ( vo.getAccountId() != null ) {
            account = accountMapper.convertFromId( vo.getAccountId() );
        }
        locationGroup = locationGroupMapper.convertFromName( vo.getLocationGroupName() );
        erpCode = vo.getErpCode();
        plcCode = vo.getPlcCode();
        sortOrder = vo.getSortOrder();
        stockZone = vo.getStockZone();

        LocationPK locationId = org.openwms.common.location.LocationPK.fromString(vo.getLocationId());

        Location location = new Location( locationId, account, locationGroup, locationType, erpCode, plcCode, sortOrder, stockZone );

        location.setPersistentKey( vo.getpKey() );
        if ( vo.getPlcState() != null ) {
            location.setPlcState( vo.getPlcState() );
        }

        return location;
    }

    @Override
    public LocationVO convertToVO(Location eo) {
        if ( eo == null ) {
            return null;
        }

        String locationId = eo.getLocationId().toString();

        LocationVO locationVO = new LocationVO( locationId );

        if ( eo.hasPersistentKey() ) {
            locationVO.setpKey( eo.getPersistentKey() );
        }
        locationVO.setAccountId( eoAccountIdentifier( eo ) );
        locationVO.setType( eoLocationTypeType( eo ) );
        locationVO.setLocationGroupName( eoLocationGroupName( eo ) );
        locationVO.setIncomingActive( eo.isInfeedActive() );
        locationVO.setOutgoingActive( eo.isOutfeedActive() );
        locationVO.setOl( eo.getOl() );
        locationVO.setLastModifiedDt( eo.getLastModifiedDt() );
        locationVO.setErpCode( eo.getErpCode() );
        locationVO.setPlcCode( eo.getPlcCode() );
        locationVO.setSortOrder( eo.getSortOrder() );
        locationVO.setPlcState( eo.getPlcState() );
        locationVO.setStockZone( eo.getStockZone() );
        locationVO.setCreateDt( eo.getCreateDt() );

        return locationVO;
    }

    @Override
    public List<LocationVO> convertToVO(List<Location> eo) {
        if ( eo == null ) {
            return null;
        }

        List<LocationVO> list = new ArrayList<LocationVO>( eo.size() );
        for ( Location location : eo ) {
            list.add( convertToVO( location ) );
        }

        return list;
    }

    @Override
    public LocationMO convertToMO(Location eo) {
        if ( eo == null ) {
            return null;
        }

        String pKey = null;
        String accountId = null;
        Boolean incomingActive = null;
        Boolean outgoingActive = null;
        String locationGroupName = null;
        String plcCode = null;
        String erpCode = null;
        Integer plcState = null;

        if ( eo.hasPersistentKey() ) {
            pKey = eo.getPersistentKey();
        }
        accountId = eoAccountIdentifier( eo );
        incomingActive = eo.isInfeedActive();
        outgoingActive = eo.isOutfeedActive();
        locationGroupName = eoLocationGroupName( eo );
        plcCode = eo.getPlcCode();
        erpCode = eo.getErpCode();
        plcState = eo.getPlcState();

        String id = eo.getLocationId().toString();

        LocationMO locationMO = new LocationMO( pKey, accountId, id, plcCode, erpCode, locationGroupName, incomingActive, outgoingActive, plcState );

        return locationMO;
    }

    private String eoAccountIdentifier(Location location) {
        if ( location == null ) {
            return null;
        }
        Account account = location.getAccount();
        if ( account == null ) {
            return null;
        }
        String identifier = account.getIdentifier();
        if ( identifier == null ) {
            return null;
        }
        return identifier;
    }

    private String eoLocationTypeType(Location location) {
        if ( location == null ) {
            return null;
        }
        LocationType locationType = location.getLocationType();
        if ( locationType == null ) {
            return null;
        }
        String type = locationType.getType();
        if ( type == null ) {
            return null;
        }
        return type;
    }

    private String eoLocationGroupName(Location location) {
        if ( location == null ) {
            return null;
        }
        LocationGroup locationGroup = location.getLocationGroup();
        if ( locationGroup == null ) {
            return null;
        }
        String name = locationGroup.getName();
        if ( name == null ) {
            return null;
        }
        return name;
    }
}