Advertisement
LaCaraDeLaVerga

Untitled

Nov 22nd, 2019
736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.86 KB | None | 0 0
  1. package ar.com.bbva.suip.suipbackoffice.mapper;
  2.  
  3. import javax.annotation.PostConstruct;
  4.  
  5. import org.slf4j.Logger;
  6. import org.slf4j.LoggerFactory;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Component;
  9.  
  10. import ar.com.bbva.model.suipportalmodel.model.Comercio;
  11. import ar.com.bbva.model.suipportalmodel.model.Contribuyente;
  12. import ar.com.bbva.model.suipportalmodel.model.Rubro;
  13. import ar.com.bbva.model.suipportalmodel.model.Sucursal;
  14. import ar.com.bbva.suip.suipbackoffice.dto.ComercioDTO;
  15. import ar.com.bbva.suip.suipbackoffice.dto.ContribuyenteDTO;
  16. import ar.com.bbva.suip.suipbackoffice.dto.RubroDTO;
  17. import ar.com.bbva.suip.suipbackoffice.dto.SucursalDTO;
  18. import ma.glasnost.orika.CustomMapper;
  19. import ma.glasnost.orika.MapperFactory;
  20. import ma.glasnost.orika.MappingContext;
  21.  
  22. @Component
  23. public class BackofficeMapper {
  24.  
  25.     static Logger logger = LoggerFactory.getLogger(BackofficeMapper.class);
  26.    
  27.     @Autowired
  28.     Mapper mapper;
  29.    
  30.     @Autowired
  31.     MapperFactory mapperFactory;
  32.    
  33.     @PostConstruct
  34.     public void initialize() {
  35.        
  36.         logger.info("Backoffice mapper initialize");
  37.        
  38.         mapperFactory.classMap(Comercio.class, ComercioDTO.class).customize(new CustomMapper<Comercio, ComercioDTO>() {
  39.            
  40.             @Override
  41.             public void mapAtoB(Comercio a, ComercioDTO b, MappingContext context) {
  42.                
  43.                
  44.                 if(a.getContribuyente() != null ) {
  45.                     b.setContribuyente(mapper.map(a.getContribuyente(), ContribuyenteDTO.class));
  46.                 }
  47.  
  48.                 if (a.getRubros() != null && !a.getRubros().isEmpty()) {
  49.                     b.setRubros(mapper.mapList(a.getRubros(), RubroDTO.class));
  50.                 }
  51.                
  52.                 b.setId(a.getId());
  53.                 b.setNombre(a.getNombre());
  54.                 b.setNoConvocable(a.getNoConvocable());
  55.                 b.setId_logo(a.getIdLogo());
  56.                 b.setDescripcion(a.getDescripcion());
  57.                 b.setPublicado(a.getPublicado());
  58.                 b.setDescripcionVista(a.getDescripcionVista());
  59.                 b.setAdquirienteNulo(a.getAdquirenteNulo());
  60.                 b.setModificoDescripcion(a.getModificoDescripcion());
  61.                 b.setActividad(a.getActividad());
  62.             }
  63.         });
  64.  
  65.         mapperFactory.classMap(Sucursal.class, SucursalDTO.class).customize(new CustomMapper<Sucursal, SucursalDTO>() {
  66.            
  67.             @Override
  68.             public void mapAtoB(Sucursal a, SucursalDTO b, MappingContext context) {
  69.                
  70.             b.setId(a.getId());
  71.             b.setFechaCierre(a.getFechaCierre());
  72.             b.setNombre(a.getNombre());
  73.             b.setTelefono1(a.getTelefono1());
  74.             b.setTelefono2(a.getTelefono2());
  75.             b.setVentaTelefonica(a.getVentaTelefonica());
  76.             b.setWebsiteVenta(a.getVentaTelefonica());
  77.             b.setFechaCierre(a.getFechaCierre());
  78.             b.setWebsiteVenta(a.getWebsiteVenta());
  79.            
  80.            
  81.             }
  82.            
  83.         });
  84.        
  85.         mapperFactory.classMap(Rubro.class, RubroDTO.class).customize(new CustomMapper<Rubro, RubroDTO>() {
  86.            
  87.             @Override
  88.             public void mapAtoB(Rubro a, RubroDTO b, MappingContext context) {
  89.                
  90.                 b.setId(a.getId());
  91.                 b.setNombre(a.getNombre());
  92.                
  93.                 if(a.getSubRubros() != null && !a.getSubRubros().isEmpty()) {
  94.                     b.setSubRubros(mapper.mapList(a.getSubRubros(), RubroDTO.class));
  95.                 }
  96.                
  97.             }
  98.            
  99.         });
  100.        
  101.        
  102.     mapperFactory.classMap(Contribuyente.class, ContribuyenteDTO.class).customize(new CustomMapper<Contribuyente, ContribuyenteDTO>() {
  103.            
  104.             @Override
  105.             public void mapAtoB(Contribuyente a, ContribuyenteDTO b, MappingContext context) {
  106.                
  107.                 b.setId(a.getId());
  108.                 b.setCuit(a.getCuit());
  109.                 b.setRazonSocial(a.getRazonSocial());
  110.                 b.setEmail(a.getEmail());
  111.                 b.setDomicilioLegal(a.getDomicilioLegal());
  112.                 b.setNombreFirmante(a.getNombreFirmante());
  113.                 b.setCargoFirmante(a.getCargoFirmante());
  114.                 b.setTieneAfranquiciados(a.getTieneFranquiciados());
  115.                 b.setCodigoActivacion(a.getCodigoActivacion());
  116.                 b.setFechaConfirmacionDatos(a.getFechaConfirmacionDatos());
  117.                 b.setCliente(a.getCliente());
  118.                 b.setAdquirente(a.getAdquirente());
  119.                    
  120.             }
  121.            
  122.         });
  123.        
  124.     }
  125.    
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement