List of usage examples for java.util StringTokenizer equals
public boolean equals(Object obj)
From source file:com.salesmanager.core.service.shipping.ShippingService.java
/** * Will update current user shipping zones and costs define in Merchant * Configuration for beinng domestic. This method will remove all configured * costs and zones that are not domestic from an existing configuration *///from ww w. j a va2 s .c o m @Transactional public void updateShippingZonesAndCostsForDomestic(int merchantId, int countryId) throws MerchantException { // Get countries and costs MerchantConfiguration countriescosts = merchantConfigurationDao .findByKey(ShippingConstants.MODULE_SHIPPING_INDIC_COUNTRIES_COSTS, merchantId); // Get the current user country (national) Map countries = RefCache.getCountriesMap(); Country currentcountry = (Country) countries.get(countryId); java.util.Date dt = new java.util.Date(); if (countriescosts != null) {// countries and cost are defined String value1 = countriescosts.getConfigurationValue1(); String value2 = countriescosts.getConfigurationValue2(); StringTokenizer st = new StringTokenizer(value1, "|"); int pos = 0; boolean foundcountry = false; // Take care of changing the country while (st.hasMoreTokens() && !foundcountry) { String token = st.nextToken(); StringTokenizer subst = new StringTokenizer(token, ";"); if (subst.hasMoreTokens()) { while (subst.hasMoreTokens() && !foundcountry) { String subtoken = subst.nextToken(); if (subtoken.equals(currentcountry.getCountryIsoCode2())) { foundcountry = true; break; } } } else { if (subst.equals(currentcountry.getCountryIsoCode2())) { foundcountry = true; break; } } if (!foundcountry) pos++; } // Take care of changing the price if (value2 != null) { if (foundcountry) { // - overwrite domestic price in MODULE_SHIPPING_ZONES_COST int cpos = 0; StringTokenizer cvtk = new StringTokenizer(value2, "|"); String costtokenvalue = null; while (cvtk.hasMoreTokens()) { costtokenvalue = cvtk.nextToken(); if (cpos == pos) { break; } cpos++; } // overwrite everything with if (costtokenvalue != null) { countriescosts.setConfigurationValue1(new StringBuffer() .append(currentcountry.getCountryIsoCode2()).append("|*|*|*|*").toString()); countriescosts.setConfigurationValue2(costtokenvalue); countriescosts.setLastModified(new java.util.Date(new Date().getTime())); merchantConfigurationDao.saveOrUpdate(countriescosts); } } else {// no country found countriescosts.setConfigurationValue1(new StringBuffer() .append(currentcountry.getCountryIsoCode2()).append("|*|*|*|*").toString()); countriescosts.setLastModified(new java.util.Date(new Date().getTime())); countriescosts.setConfigurationValue2("5:0;10:0;99:0|*|*|*|*"); merchantConfigurationDao.saveOrUpdate(countriescosts); } } else {// No price yet defined countriescosts.setConfigurationValue1(new StringBuffer().append(currentcountry.getCountryIsoCode2()) .append("|*|*|*|*").toString()); countriescosts.setConfigurationValue2("5:0;10:0;99:0|*|*|*|*"); countriescosts.setLastModified(new java.util.Date(new Date().getTime())); countriescosts.setConfigurationModule(""); countriescosts.setMerchantId(merchantId); countriescosts.setConfigurationKey(ShippingConstants.MODULE_SHIPPING_INDIC_COUNTRIES_COSTS); merchantConfigurationDao.saveOrUpdate(countriescosts); } } else {// First time you come in merchantConfigurationDao.deleteLike("SHP_ZONES_", merchantId); MerchantConfiguration zones = new MerchantConfiguration(); zones.setConfigurationValue1( new StringBuffer().append(currentcountry.getCountryIsoCode2()).append("|*|*|*|*").toString()); zones.setConfigurationValue2("5:0;10:0;99:0|*|*|*|*"); zones.setMerchantId(merchantId); zones.setConfigurationKey(ShippingConstants.MODULE_SHIPPING_INDIC_COUNTRIES_COSTS); zones.setConfigurationModule(""); zones.setDateAdded(new java.util.Date(dt.getTime())); zones.setLastModified(new java.util.Date(dt.getTime())); merchantConfigurationDao.persist(zones); } // Add or update MerchantConfiguration for shipping domestic MerchantConfiguration conf = merchantConfigurationDao .findByKey(ShippingConstants.MODULE_SHIPPING_ZONES_SHIPPING, merchantId); if (conf != null && !conf.getConfigurationValue().equals(ShippingConstants.DOMESTIC_SHIPPING)) {// already // configured conf.setConfigurationValue(ShippingConstants.DOMESTIC_SHIPPING); conf.setLastModified(new java.util.Date(dt.getTime())); } else { conf = new MerchantConfiguration(); conf.setConfigurationModule(""); conf.setConfigurationKey(ShippingConstants.MODULE_SHIPPING_ZONES_SHIPPING); conf.setConfigurationValue(ShippingConstants.DOMESTIC_SHIPPING); conf.setDateAdded(new java.util.Date(dt.getTime())); conf.setMerchantId(merchantId); conf.setLastModified(new java.util.Date(dt.getTime())); } merchantConfigurationDao.saveOrUpdate(conf); }