ProductMapperImpl.java

package org.openwms.wms.inventory;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.processing.Generated;
import org.openwms.wms.CycleAvoidingMappingContext;
import org.openwms.wms.inventory.api.ProductVO;
import org.openwms.wms.inventory.api.StackingRuleVO;
import org.openwms.wms.inventory.api.UomRelationVO;
import org.openwms.wms.inventory.events.ProductMO;
import org.openwms.wms.location.impl.LocationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor"
)
@Component
public class ProductMapperImpl extends ProductMapper {

    private final DimensionMapper dimensionMapper;
    private final LocationMapper locationMapper;

    @Autowired
    public ProductMapperImpl(DimensionMapper dimensionMapper, LocationMapper locationMapper) {

        this.dimensionMapper = dimensionMapper;
        this.locationMapper = locationMapper;
    }

    @Override
    public ProductMO convertToMO(Product entity) {
        if ( entity == null ) {
            return null;
        }

        ProductMO productMO = new ProductMO();

        if ( entity.hasPersistentKey() ) {
            productMO.setpKey( entity.getPersistentKey() );
        }
        productMO.setSku( entity.getSku() );
        productMO.setLabel( entity.getLabel() );
        productMO.setAccountId( entity.getAccountId() );
        productMO.setBaseUnit( entity.getBaseUnit() );
        productMO.setOverbookingAllowed( entity.isOverbookingAllowed() );
        productMO.setDescription( entity.getDescription() );
        productMO.setClassification( entity.getClassification() );
        productMO.setGroup( entity.getGroup() );
        productMO.setStockZone( entity.getStockZone() );
        productMO.setUnits( uomRelationListToStringList( entity.getUnits() ) );
        Map<String, String> map = entity.getDetails();
        if ( map != null ) {
            productMO.setDetails( new LinkedHashMap<String, String>( map ) );
        }

        return productMO;
    }

    @Override
    public UomRelationVO convert(UomRelation eo, CycleAvoidingMappingContext ctx) {
        UomRelationVO target = ctx.getMappedInstance( eo, UomRelationVO.class );
        if ( target != null ) {
            return target;
        }

        if ( eo == null ) {
            return null;
        }

        UomRelationVO uomRelationVO = new UomRelationVO();

        ctx.storeMappedInstance( eo, uomRelationVO );

        if ( eo.hasPersistentKey() ) {
            uomRelationVO.setpKey( eo.getPersistentKey() );
        }
        uomRelationVO.setQuantity( eo.getUnit() );
        uomRelationVO.setDescription( eo.getDescription() );
        uomRelationVO.setProduct( convert( eo.getProduct(), ctx ) );
        uomRelationVO.setLabel( eo.getLabel() );
        uomRelationVO.setCode( eo.getCode() );
        uomRelationVO.setDimension( dimensionMapper.convert( eo.getDimension() ) );
        Map<String, String> map = eo.getDetails();
        if ( map != null ) {
            uomRelationVO.setDetails( new LinkedHashMap<String, String>( map ) );
        }

        return uomRelationVO;
    }

    @Override
    public List<Product> convertVO(List<ProductVO> vos) {
        if ( vos == null ) {
            return null;
        }

        List<Product> list = new ArrayList<Product>( vos.size() );
        for ( ProductVO productVO : vos ) {
            list.add( convertVO( productVO ) );
        }

        return list;
    }

    @Override
    public ProductVO convert(Product entity, CycleAvoidingMappingContext cycleAvoidingMappingContext) {
        ProductVO target = cycleAvoidingMappingContext.getMappedInstance( entity, ProductVO.class );
        if ( target != null ) {
            return target;
        }

        if ( entity == null ) {
            return null;
        }

        ProductVO.Builder productVO = ProductVO.newBuilder();

        cycleAvoidingMappingContext.storeMappedInstance( entity, productVO );

        if ( entity.hasPersistentKey() ) {
            productVO.pKey( entity.getPersistentKey() );
        }
        productVO.units( uomRelationListToUomRelationVOList( entity.getUnits(), cycleAvoidingMappingContext ) );
        productVO.stackingRules( productStackingRuleListToStackingRuleVOList( entity.getStackingRules(), cycleAvoidingMappingContext ) );
        productVO.sku( entity.getSku() );
        productVO.label( entity.getLabel() );
        productVO.accountId( entity.getAccountId() );
        productVO.baseUnit( entity.getBaseUnit() );
        productVO.overbookingAllowed( entity.isOverbookingAllowed() );
        productVO.description( entity.getDescription() );
        productVO.availabilityState( entity.getAvailabilityState() );
        productVO.classification( entity.getClassification() );
        productVO.group( entity.getGroup() );
        productVO.stockZone( entity.getStockZone() );
        productVO.dimension( dimensionMapper.convert( entity.getDimension() ) );
        productVO.netWeight( entity.getNetWeight() );
        productVO.preferableStorageLocation( locationMapper.convertToVO( entity.getPreferableStorageLocation() ) );
        Map<String, String> map = entity.getDetails();
        if ( map != null ) {
            productVO.details( new LinkedHashMap<String, String>( map ) );
        }

        return productVO.build();
    }

    @Override
    public List<ProductVO> convert(List<Product> entities, CycleAvoidingMappingContext cycleAvoidingMappingContext) {
        List<ProductVO> target = cycleAvoidingMappingContext.getMappedInstance( entities, List.class );
        if ( target != null ) {
            return target;
        }

        if ( entities == null ) {
            return null;
        }

        List<ProductVO> list = new ArrayList<ProductVO>( entities.size() );
        cycleAvoidingMappingContext.storeMappedInstance( entities, list );

        for ( Product product : entities ) {
            list.add( convert( product, cycleAvoidingMappingContext ) );
        }

        return list;
    }

    protected List<String> uomRelationListToStringList(List<UomRelation> list) {
        if ( list == null ) {
            return null;
        }

        List<String> list1 = new ArrayList<String>( list.size() );
        for ( UomRelation uomRelation : list ) {
            list1.add( convertTo( uomRelation ) );
        }

        return list1;
    }

    protected List<UomRelationVO> uomRelationListToUomRelationVOList(List<UomRelation> list, CycleAvoidingMappingContext cycleAvoidingMappingContext) {
        List<UomRelationVO> target = cycleAvoidingMappingContext.getMappedInstance( list, List.class );
        if ( target != null ) {
            return target;
        }

        if ( list == null ) {
            return null;
        }

        List<UomRelationVO> list1 = new ArrayList<UomRelationVO>( list.size() );
        cycleAvoidingMappingContext.storeMappedInstance( list, list1 );

        for ( UomRelation uomRelation : list ) {
            list1.add( convert( uomRelation, cycleAvoidingMappingContext ) );
        }

        return list1;
    }

    protected StackingRuleVO productStackingRuleToStackingRuleVO(ProductStackingRule productStackingRule, CycleAvoidingMappingContext cycleAvoidingMappingContext) {
        StackingRuleVO target = cycleAvoidingMappingContext.getMappedInstance( productStackingRule, StackingRuleVO.class );
        if ( target != null ) {
            return target;
        }

        if ( productStackingRule == null ) {
            return null;
        }

        StackingRuleVO stackingRuleVO = new StackingRuleVO();

        cycleAvoidingMappingContext.storeMappedInstance( productStackingRule, stackingRuleVO );

        stackingRuleVO.setNoProducts( productStackingRule.getNoProducts() );
        stackingRuleVO.setAllowedProduct( convert( productStackingRule.getAllowedProduct(), cycleAvoidingMappingContext ) );

        return stackingRuleVO;
    }

    protected List<StackingRuleVO> productStackingRuleListToStackingRuleVOList(List<ProductStackingRule> list, CycleAvoidingMappingContext cycleAvoidingMappingContext) {
        List<StackingRuleVO> target = cycleAvoidingMappingContext.getMappedInstance( list, List.class );
        if ( target != null ) {
            return target;
        }

        if ( list == null ) {
            return null;
        }

        List<StackingRuleVO> list1 = new ArrayList<StackingRuleVO>( list.size() );
        cycleAvoidingMappingContext.storeMappedInstance( list, list1 );

        for ( ProductStackingRule productStackingRule : list ) {
            list1.add( productStackingRuleToStackingRuleVO( productStackingRule, cycleAvoidingMappingContext ) );
        }

        return list1;
    }
}