String sql = "from ShippingMethod where siteId = :siteId order by shippingMethodId";
Query query = em.createQuery(sql);
query.setParameter("siteId", Constants.SITE_SYSTEM);
Iterator<?> iterator = query.getResultList().iterator();
while (iterator.hasNext()) {
ShippingMethod master = (ShippingMethod) iterator.next();
ShippingMethod shippingMethod = new ShippingMethod();
shippingMethod.setSite(site);
shippingMethod.setSeqNum(master.getSeqNum());
shippingMethod.setPublished(master.getPublished());
shippingMethod.setRecUpdateBy(userId);
shippingMethod.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
shippingMethod.setRecCreateBy(userId);
shippingMethod.setRecCreateDatetime(new Date(System.currentTimeMillis()));
for (ShippingMethodLanguage language : master.getShippingMethodLanguages()) {
ShippingMethodLanguage shippingMethodLanguage = new ShippingMethodLanguage();
shippingMethodLanguage.setShippingMethodName(language.getShippingMethodName());
shippingMethodLanguage.setRecUpdateBy(userId);
shippingMethodLanguage.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
shippingMethodLanguage.setRecCreateBy(userId);
shippingMethodLanguage.setRecCreateDatetime(new Date(System.currentTimeMillis()));
em.persist(shippingMethodLanguage);
if (language.getShippingMethodLangId().equals(master.getShippingMethodLanguage().getShippingMethodLangId())) {
shippingMethod.setShippingMethodLanguage(shippingMethodLanguage);
}
shippingMethod.getShippingMethodLanguages().add(shippingMethodLanguage);
}
if (master.getShippingMethodRegions() != null) {
Iterator<?> it = master.getShippingMethodRegions().iterator();
while (it.hasNext()) {
ShippingMethodRegion m_shippingMethodRegion = (ShippingMethodRegion) it.next();
ShippingMethodRegion shippingMethodRegion = new ShippingMethodRegion();
shippingMethodRegion.setPublished(m_shippingMethodRegion.getPublished());
shippingMethodRegion.setRecUpdateBy(userId);
shippingMethodRegion.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
shippingMethodRegion.setRecCreateBy(userId);
shippingMethodRegion.setRecCreateDatetime(new Date(System.currentTimeMillis()));
shippingMethodRegion.setShippingMethod(shippingMethod);
ShippingRegion shippingRegion = getShippingRegion(m_shippingMethodRegion.getShippingRegion().getShippingRegionName());
shippingMethodRegion.setShippingRegion(shippingRegion);
if (m_shippingMethodRegion.getShippingMethodRegionTypes() != null) {
Iterator<?> it1 = m_shippingMethodRegion.getShippingMethodRegionTypes().iterator();
while (it1.hasNext()) {
ShippingMethodRegionType m_shippingMethodRegionType = (ShippingMethodRegionType) it1.next();
ShippingMethodRegionType shippingMethodRegionType = new ShippingMethodRegionType();
shippingMethodRegionType.setPublished(m_shippingMethodRegionType.getPublished());
shippingMethodRegionType.setRecUpdateBy(userId);
shippingMethodRegionType.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
shippingMethodRegionType.setRecCreateBy(userId);
shippingMethodRegionType.setRecCreateDatetime(new Date(System.currentTimeMillis()));
shippingMethodRegionType.setShippingRegion(shippingRegion);
shippingMethodRegionType.setShippingMethod(shippingMethod);
shippingMethodRegionType.setShippingType(getShippingType(m_shippingMethodRegionType.getShippingType().getShippingTypeName()));
ShippingRate m_shippingRate = m_shippingMethodRegionType.getShippingRate();
ShippingRate shippingRate = new ShippingRate();
PropertyUtils.copyProperties(shippingRate, m_shippingRate);
shippingRate.setPublished(m_shippingRate.getPublished());
shippingRate.setRecUpdateBy(userId);
shippingRate.setRecUpdateDatetime(new Date(System.currentTimeMillis()));
shippingRate.setRecCreateBy(userId);
shippingRate.setRecCreateDatetime(new Date(System.currentTimeMillis()));
shippingMethodRegionType.setShippingRate(shippingRate);
em.persist(shippingRate);
em.persist(shippingMethodRegionType);
shippingMethodRegion.getShippingMethodRegionTypes().add(shippingMethodRegionType);
}
}
shippingMethod.getShippingMethodRegions().add(shippingMethodRegion);
}
}
em.persist(shippingMethod);
}
}