private Map loadThirdSystemOrderToDB(List merchantOrdersDTOs) { Map sessionFactories = DAOSessionUtil.getSessionFactories(); AbstractIceleadsDAOFactory hibernateFactory = DAOFactory.getDAOFactory(sessionFactories).getIceleadsDAOFactory(); AbstractIceleadsStatDAOFactory hibernateStatFactory = DAOFactory.getDAOFactory(sessionFactories).getIceleadsStatDAOFactory(); IMerchantDAO merchantDAO = hibernateFactory.getMerchantDAO(); IMerchantCountryDAO merchantCountryDAO = hibernateFactory.getMerchantCountryDAO(); ICategoryDAO categoryDAO = hibernateFactory.getCategoryDAO(); IStatPixelStringDAO statPixelStringDAO = hibernateStatFactory.getStatPixelStringDAO(); IStatLeadsDetailDAO statLeadsDetailDAO = hibernateStatFactory.getStatLeadsDetailDAO(); IWarmStatLeadsDetailDAO warmStatLeadsDetailDAO = hibernateStatFactory.getWarmStatLeadsDetailDAO(); IColdStatLeadsDetailDAO coldStatLeadsDetailDAO = hibernateStatFactory.getColdStatLeadsDetailDAO(); IStatOrderDetailDAO statOrderDetailDAO = hibernateStatFactory.getOrderDetailDAO(); IWarmStatOrderDetailDAO warmStatOrderDetailDAO = hibernateStatFactory.getWarmOrderDetailDAO(); IColdStatOrderDetailDAO coldStatOrderDetailDAO = hibernateStatFactory.getColdOrderDetailDAO(); Map statisticsMap = new HashMap(); // for statistics only for (MerchantOrdersDTO merchantOrdersDTO : merchantOrdersDTOs) { MerchantDomain merchantDomain = merchantDAO.getByID(merchantOrdersDTO.getMerchantId()); logger.debug("OrderInjectorManager:loadThirdSystemOrderToDB: loading merchant [" + merchantDomain.getId() + "] name: [" + merchantDomain.getName() + "]"); List orders = merchantOrdersDTO.getOrders(); if (orders != null) { for (OrderDTO order : orders) { Boolean orderNotExist = Boolean.TRUE; List statOrders; List warmStatOrders; List coldStatOrders; // check this order in hot storage statOrders = statOrderDetailDAO.getListOrder(order.getOrderId(), order.getProductPrice(), order.getDate()); if (statOrders != null && !statOrders.isEmpty()) { orderNotExist = Boolean.FALSE; } // check this order in warm storage if (orderNotExist) { warmStatOrders = warmStatOrderDetailDAO.getListOrder(order.getOrderId(), order.getProductPrice(), order.getDate()); if (warmStatOrders != null && !warmStatOrders.isEmpty()) { orderNotExist = Boolean.FALSE; } } // check this order in cold storage if (orderNotExist) { coldStatOrders = coldStatOrderDetailDAO.getListOrder(order.getOrderId(), order.getProductPrice(), order.getDate()); if (coldStatOrders != null && !coldStatOrders.isEmpty()) { orderNotExist = Boolean.FALSE; } } // if we do not find this order in any storages lets add it if (orderNotExist) { String aSessionKey = order.getSession(); if (aSessionKey != null && !aSessionKey.isEmpty()) { String remoteIp = null; String userAgentValue = null; Integer affiliateId = null; String cid = null; String leadId = null; Integer coreProductRepositoryId = null; //try to found leads to get data for order StatLeadsDetailDomain statLeadsDetailDomain = statLeadsDetailDAO.getFirstStatLeadsDetailBySessionKey(aSessionKey); if (statLeadsDetailDomain == null) { WarmStatLeadsDetailDomain warmStatLeadsDetailDomain = warmStatLeadsDetailDAO.getFirstStatLeadsDetailBySessionKey(aSessionKey); if (warmStatLeadsDetailDomain == null) { ColdStatLeadsDetailDomain coldStatLeadsDetailDomain = coldStatLeadsDetailDAO.getFirstStatLeadsDetailBySessionKey(aSessionKey); if (coldStatLeadsDetailDomain == null) { continue; } else { remoteIp = coldStatLeadsDetailDomain.getRemoteIp(); userAgentValue = coldStatLeadsDetailDomain.getUserAgentValue(); affiliateId = coldStatLeadsDetailDomain.getAffiliateId(); cid = coldStatLeadsDetailDomain.getCid(); leadId = coldStatLeadsDetailDomain.getLeadId(); coreProductRepositoryId = coldStatLeadsDetailDomain.getCoreProductRepositoryId(); } } else { remoteIp = warmStatLeadsDetailDomain.getRemoteIp(); userAgentValue = warmStatLeadsDetailDomain.getUserAgentValue(); affiliateId = warmStatLeadsDetailDomain.getAffiliateId(); cid = warmStatLeadsDetailDomain.getCid(); leadId = warmStatLeadsDetailDomain.getLeadId(); coreProductRepositoryId = warmStatLeadsDetailDomain.getCoreProductRepositoryId(); } } else { remoteIp = statLeadsDetailDomain.getRemoteIp(); userAgentValue = statLeadsDetailDomain.getUserAgentValue(); affiliateId = statLeadsDetailDomain.getAffiliateId(); cid = statLeadsDetailDomain.getCid(); leadId = statLeadsDetailDomain.getLeadId(); coreProductRepositoryId = statLeadsDetailDomain.getCoreProductRepositoryId(); } // fill fields from third side Integer qty = order.getQty() != null ? order.getQty() : 1; BigDecimal productPriceScaled = order.getProductPrice(); // parse date from string Date date = order.getDate(); MerchantCountry merchantCountry = merchantCountryDAO.getByMerchant(merchantDomain); String pixelString = "http://" + SystemUtil.getInstance().getHost() + "/iceleads_rest/merch/" + merchantDomain.getId() + "/direct"; StatPixelStringDomain statPixelString = statPixelStringDAO.getStatPixelString(order.getOrderId()); if (statPixelString == null) { statPixelString = new StatPixelStringDomain(); statPixelString.setOrderId(order.getOrderId()); statPixelString.setPixelString(pixelString); statPixelString.setCookie(""); statPixelString.setRemoteIp(remoteIp); statPixelString = statPixelStringDAO.saveOrUpdate(statPixelString); if (!statisticsMap.containsKey(order.getMerchantId())) statisticsMap.put(order.getMerchantId(), new AtomicInteger(1)); else statisticsMap.get(order.getMerchantId()).incrementAndGet(); } StatOrderDetailDomain starOrderDetailDomain = new StatOrderDetailDomain(); starOrderDetailDomain.setAffiliateId(affiliateId); starOrderDetailDomain.setCurrency(merchantDomain.getCurrency()); starOrderDetailDomain.setMerchantId(merchantDomain.getId()); starOrderDetailDomain.setRefCountryId(merchantCountry.getRefCountry().getId()); // starOrderDetailDomain.setCountryKey(merchantCountry.getRefCountry().getCountryKey()); starOrderDetailDomain.setStatPixelString(statPixelString); starOrderDetailDomain.setSessionKey(aSessionKey); starOrderDetailDomain.setRemoteIp(remoteIp); starOrderDetailDomain.setUserAgentValue(userAgentValue); starOrderDetailDomain.setCid(cid); starOrderDetailDomain.setLeadId(leadId); starOrderDetailDomain.setCoreProductRepositoryId(coreProductRepositoryId); starOrderDetailDomain.setOrderId(order.getOrderId()); starOrderDetailDomain.setDescription(order.getDescription()); starOrderDetailDomain.setMpn(order.getMpn()); starOrderDetailDomain.setVendorName(order.getVendor()); starOrderDetailDomain.setQty(qty); starOrderDetailDomain.setPrice(productPriceScaled); starOrderDetailDomain.setIpAgentMatched(Boolean.FALSE); starOrderDetailDomain.setDateIns(date); if (order.getCategory() != null && !order.getCategory().isEmpty()) { CategoryDomain category = categoryDAO.getCategory(order.getCategory()); if (category != null) { starOrderDetailDomain.setCategoryId(category.getId()); } } logger.debug("Load order " + starOrderDetailDomain); statOrderDetailDAO.saveOrUpdate(starOrderDetailDomain); } } } } } return statisticsMap; }