Advertisement
Guest User

Untitled

a guest
May 25th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.66 KB | None | 0 0
  1. private Map<Integer, AtomicInteger> loadThirdSystemOrderToDB(List<MerchantOrdersDTO> merchantOrdersDTOs) {
  2.         Map sessionFactories = DAOSessionUtil.getSessionFactories();
  3.         AbstractIceleadsDAOFactory hibernateFactory = DAOFactory.getDAOFactory(sessionFactories).getIceleadsDAOFactory();
  4.         AbstractIceleadsStatDAOFactory hibernateStatFactory = DAOFactory.getDAOFactory(sessionFactories).getIceleadsStatDAOFactory();
  5.         IMerchantDAO merchantDAO = hibernateFactory.getMerchantDAO();
  6.         IMerchantCountryDAO merchantCountryDAO = hibernateFactory.getMerchantCountryDAO();
  7.         ICategoryDAO categoryDAO = hibernateFactory.getCategoryDAO();
  8.         IStatPixelStringDAO statPixelStringDAO = hibernateStatFactory.getStatPixelStringDAO();
  9.  
  10.         IStatLeadsDetailDAO statLeadsDetailDAO = hibernateStatFactory.getStatLeadsDetailDAO();
  11.         IWarmStatLeadsDetailDAO warmStatLeadsDetailDAO = hibernateStatFactory.getWarmStatLeadsDetailDAO();
  12.         IColdStatLeadsDetailDAO coldStatLeadsDetailDAO = hibernateStatFactory.getColdStatLeadsDetailDAO();
  13.  
  14.         IStatOrderDetailDAO statOrderDetailDAO = hibernateStatFactory.getOrderDetailDAO();
  15.         IWarmStatOrderDetailDAO warmStatOrderDetailDAO = hibernateStatFactory.getWarmOrderDetailDAO();
  16.         IColdStatOrderDetailDAO coldStatOrderDetailDAO = hibernateStatFactory.getColdOrderDetailDAO();
  17.  
  18.         Map<Integer, AtomicInteger> statisticsMap = new HashMap<Integer, AtomicInteger>(); // for statistics only
  19.  
  20.         for (MerchantOrdersDTO merchantOrdersDTO : merchantOrdersDTOs) {
  21.             MerchantDomain merchantDomain = merchantDAO.getByID(merchantOrdersDTO.getMerchantId());
  22.             logger.debug("OrderInjectorManager:loadThirdSystemOrderToDB: loading merchant [" + merchantDomain.getId() + "] name: [" + merchantDomain.getName() + "]");
  23.             List<OrderDTO> orders = merchantOrdersDTO.getOrders();
  24.             if (orders != null) {
  25.                 for (OrderDTO order : orders) {
  26.                     Boolean orderNotExist = Boolean.TRUE;
  27.  
  28.                     List<StatOrderDetailDomain> statOrders;
  29.                     List<WarmStatOrderDetailDomain> warmStatOrders;
  30.                     List<ColdStatOrderDetailDomain> coldStatOrders;
  31.  
  32.                     // check this order in hot storage
  33.                     statOrders = statOrderDetailDAO.getListOrder(order.getOrderId(), order.getProductPrice(), order.getDate());
  34.                     if (statOrders != null && !statOrders.isEmpty()) {
  35.                         orderNotExist = Boolean.FALSE;
  36.                     }
  37.  
  38.                     // check this order in warm storage
  39.                     if (orderNotExist) {
  40.                         warmStatOrders = warmStatOrderDetailDAO.getListOrder(order.getOrderId(), order.getProductPrice(), order.getDate());
  41.                         if (warmStatOrders != null && !warmStatOrders.isEmpty()) {
  42.                             orderNotExist = Boolean.FALSE;
  43.                         }
  44.                     }
  45.  
  46.                     // check this order in cold storage
  47.                     if (orderNotExist) {
  48.                         coldStatOrders = coldStatOrderDetailDAO.getListOrder(order.getOrderId(), order.getProductPrice(), order.getDate());
  49.                         if (coldStatOrders != null && !coldStatOrders.isEmpty()) {
  50.                             orderNotExist = Boolean.FALSE;
  51.                         }
  52.                     }
  53.  
  54.                     // if we do not find this order in any storages lets add it
  55.                     if (orderNotExist) {
  56.  
  57.                         String aSessionKey = order.getSession();
  58.                         if (aSessionKey != null && !aSessionKey.isEmpty()) {
  59.                             String remoteIp = null;
  60.                             String userAgentValue = null;
  61.                             Integer affiliateId = null;
  62.                             String cid = null;
  63.                             String leadId = null;
  64.                             Integer coreProductRepositoryId = null;
  65.                             //try to found leads to get data for order
  66.                             StatLeadsDetailDomain statLeadsDetailDomain = statLeadsDetailDAO.getFirstStatLeadsDetailBySessionKey(aSessionKey);
  67.                             if (statLeadsDetailDomain == null) {
  68.                                 WarmStatLeadsDetailDomain warmStatLeadsDetailDomain = warmStatLeadsDetailDAO.getFirstStatLeadsDetailBySessionKey(aSessionKey);
  69.                                 if (warmStatLeadsDetailDomain == null) {
  70.                                     ColdStatLeadsDetailDomain coldStatLeadsDetailDomain = coldStatLeadsDetailDAO.getFirstStatLeadsDetailBySessionKey(aSessionKey);
  71.                                     if (coldStatLeadsDetailDomain == null) {
  72.                                         continue;
  73.                                     } else {
  74.                                         remoteIp = coldStatLeadsDetailDomain.getRemoteIp();
  75.                                         userAgentValue = coldStatLeadsDetailDomain.getUserAgentValue();
  76.                                         affiliateId = coldStatLeadsDetailDomain.getAffiliateId();
  77.                                         cid = coldStatLeadsDetailDomain.getCid();
  78.                                         leadId = coldStatLeadsDetailDomain.getLeadId();
  79.                                         coreProductRepositoryId = coldStatLeadsDetailDomain.getCoreProductRepositoryId();
  80.                                     }
  81.                                 } else {
  82.                                     remoteIp = warmStatLeadsDetailDomain.getRemoteIp();
  83.                                     userAgentValue = warmStatLeadsDetailDomain.getUserAgentValue();
  84.                                     affiliateId = warmStatLeadsDetailDomain.getAffiliateId();
  85.                                     cid = warmStatLeadsDetailDomain.getCid();
  86.                                     leadId = warmStatLeadsDetailDomain.getLeadId();
  87.                                     coreProductRepositoryId = warmStatLeadsDetailDomain.getCoreProductRepositoryId();
  88.                                 }
  89.                             } else {
  90.                                 remoteIp = statLeadsDetailDomain.getRemoteIp();
  91.                                 userAgentValue = statLeadsDetailDomain.getUserAgentValue();
  92.                                 affiliateId = statLeadsDetailDomain.getAffiliateId();
  93.                                 cid = statLeadsDetailDomain.getCid();
  94.                                 leadId = statLeadsDetailDomain.getLeadId();
  95.                                 coreProductRepositoryId = statLeadsDetailDomain.getCoreProductRepositoryId();
  96.                             }
  97.  
  98.                             // fill fields from third side
  99.                             Integer qty = order.getQty() != null ? order.getQty() : 1;
  100.                             BigDecimal productPriceScaled = order.getProductPrice();
  101.                             // parse date from string
  102.  
  103.                             Date date = order.getDate();
  104.  
  105.                             MerchantCountry merchantCountry = merchantCountryDAO.getByMerchant(merchantDomain);
  106.                             String pixelString = "http://" + SystemUtil.getInstance().getHost() + "/iceleads_rest/merch/" + merchantDomain.getId() + "/direct";
  107.                             StatPixelStringDomain statPixelString = statPixelStringDAO.getStatPixelString(order.getOrderId());
  108.                             if (statPixelString == null) {
  109.                                 statPixelString = new StatPixelStringDomain();
  110.                                 statPixelString.setOrderId(order.getOrderId());
  111.                                 statPixelString.setPixelString(pixelString);
  112.                                 statPixelString.setCookie("");
  113.                                 statPixelString.setRemoteIp(remoteIp);
  114.                                 statPixelString = statPixelStringDAO.saveOrUpdate(statPixelString);
  115.                                 if (!statisticsMap.containsKey(order.getMerchantId()))
  116.                                     statisticsMap.put(order.getMerchantId(), new AtomicInteger(1));
  117.                                 else statisticsMap.get(order.getMerchantId()).incrementAndGet();
  118.                             }
  119.                             StatOrderDetailDomain starOrderDetailDomain = new StatOrderDetailDomain();
  120.                             starOrderDetailDomain.setAffiliateId(affiliateId);
  121.                             starOrderDetailDomain.setCurrency(merchantDomain.getCurrency());
  122.                             starOrderDetailDomain.setMerchantId(merchantDomain.getId());
  123.                             starOrderDetailDomain.setRefCountryId(merchantCountry.getRefCountry().getId());
  124. //                            starOrderDetailDomain.setCountryKey(merchantCountry.getRefCountry().getCountryKey());
  125.                             starOrderDetailDomain.setStatPixelString(statPixelString);
  126.                             starOrderDetailDomain.setSessionKey(aSessionKey);
  127.                             starOrderDetailDomain.setRemoteIp(remoteIp);
  128.                             starOrderDetailDomain.setUserAgentValue(userAgentValue);
  129.                             starOrderDetailDomain.setCid(cid);
  130.                             starOrderDetailDomain.setLeadId(leadId);
  131.                             starOrderDetailDomain.setCoreProductRepositoryId(coreProductRepositoryId);
  132.  
  133.                             starOrderDetailDomain.setOrderId(order.getOrderId());
  134.                             starOrderDetailDomain.setDescription(order.getDescription());
  135.                             starOrderDetailDomain.setMpn(order.getMpn());
  136.                             starOrderDetailDomain.setVendorName(order.getVendor());
  137.                             starOrderDetailDomain.setQty(qty);
  138.                             starOrderDetailDomain.setPrice(productPriceScaled);
  139.                             starOrderDetailDomain.setIpAgentMatched(Boolean.FALSE);
  140.                             starOrderDetailDomain.setDateIns(date);
  141.                             if (order.getCategory() != null && !order.getCategory().isEmpty()) {
  142.                                 CategoryDomain category = categoryDAO.getCategory(order.getCategory());
  143.                                 if (category != null) {
  144.                                     starOrderDetailDomain.setCategoryId(category.getId());
  145.                                 }
  146.                             }
  147.                             logger.debug("Load order " + starOrderDetailDomain);
  148.                             statOrderDetailDAO.saveOrUpdate(starOrderDetailDomain);
  149.  
  150.                         }
  151.                     }
  152.                 }
  153.             }
  154.         }
  155.         return statisticsMap;
  156.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement