|
Author: mrisaliti
Date: Fri Jan 7 22:05:52 2011 New Revision: 1056531 URL: http://svn.apache.org/viewvc?rev=1056531&view=rev Log: Internationalization of ServiceUtil.returnSuccess, ServiceUtil.returnFailure, ServiceUtil.returnError (OFBIZ-4091) Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java ofbiz/trunk/applications/product/src/org/ofbiz/product/promo/PromoServices.java Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java?rev=1056531&r1=1056530&r2=1056531&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/feature/ProductFeatureServices.java Fri Jan 7 22:05:52 2011 @@ -20,6 +20,7 @@ package org.ofbiz.product.feature; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -30,6 +31,7 @@ import javolution.util.FastSet; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; @@ -61,6 +63,7 @@ public class ProductFeatureServices { public static Map<String, Object> getProductFeaturesByType(DispatchContext dctx, Map<String, ? extends Object> context) { Map<String, Object> results = FastMap.newInstance(); Delegator delegator = dctx.getDelegator(); + Locale locale = (Locale) context.get("locale"); /* because we might need to search either for product features or for product features of a product, the search code has to be generic. * we will determine which entity and field to search on based on what the user has supplied us with. @@ -85,7 +88,7 @@ public class ProductFeatureServices { } if (valueToSearch == null) { - return ServiceUtil.returnError("This service requires a productId, a productFeatureGroupId, or a productFeatureCategoryId to run."); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductFeatureByType", locale)); } try { @@ -299,6 +302,7 @@ public class ProductFeatureServices { List<GenericValue> productFeatures = UtilGenerics.checkList(context.get("productFeatures")); String productCategoryId = (String) context.get("productCategoryId"); + Locale locale = (Locale) context.get("locale"); // get all the product members of the product category Map<String, Object> result; @@ -337,7 +341,7 @@ public class ProductFeatureServices { } if (products.size() == 0) { - return ServiceUtil.returnError("No products which fit your requirements were found."); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductCategoryNoVariants", locale)); } else { results = ServiceUtil.returnSuccess(); results.put("products", products); Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java?rev=1056531&r1=1056530&r2=1056531&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java Fri Jan 7 22:05:52 2011 @@ -22,6 +22,7 @@ import java.math.BigDecimal; import java.sql.Timestamp; import java.util.Collection; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.TreeSet; @@ -53,6 +54,7 @@ import org.ofbiz.service.ServiceUtil; public class PriceServices { public static final String module = PriceServices.class.getName(); + public static final String resource = "ProductUiLabels"; public static final BigDecimal ONE_BASE = BigDecimal.ONE; public static final BigDecimal PERCENT_SCALE = new BigDecimal("100.000"); @@ -101,14 +103,16 @@ public class PriceServices { String productStoreId = (String) context.get("productStoreId"); String productStoreGroupId = (String) context.get("productStoreGroupId"); + Locale locale = (Locale) context.get("locale"); + GenericValue productStore = null; try { // we have a productStoreId, if the corresponding ProductStore.primaryStoreGroupId is not empty, use that productStore = delegator.findByPrimaryKeyCache("ProductStore", UtilMisc.toMap("productStoreId", productStoreId)); } catch (GenericEntityException e) { - String errMsg = "Error getting product store info from the database while calculating price" + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); + Debug.logError(e, "Error getting product store info from the database while calculating price" + e.toString(), module); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPriceCannotRetrieveProductStore", UtilMisc.toMap("errorString", e.toString()) , locale)); } if (UtilValidate.isEmpty(productStoreGroupId)) { if (productStore != null) { @@ -125,9 +129,9 @@ public class PriceServices { } } } catch (GenericEntityException e) { - String errMsg = "Error getting product store info from the database while calculating price" + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); + Debug.logError(e, "Error getting product store info from the database while calculating price" + e.toString(), module); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPriceCannotRetrieveProductStore", UtilMisc.toMap("errorString", e.toString()) , locale)); } } @@ -159,9 +163,9 @@ public class PriceServices { try { virtualProductId = ProductWorker.getVariantVirtualId(product); } catch (GenericEntityException e) { - String errMsg = "Error getting virtual product id from the database while calculating price" + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); + Debug.logError(e, "Error getting virtual product id from the database while calculating price" + e.toString(), module); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPriceCannotRetrieveVirtualProductId", UtilMisc.toMap("errorString", e.toString()) , locale)); } } @@ -245,9 +249,9 @@ public class PriceServices { defaultPriceValue = agreementPriceValue; } } catch (GenericEntityException e) { - String errMsg = "Error getting agreement info from the database while calculating price" + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); + Debug.logError(e, "Error getting agreement info from the database while calculating price" + e.toString(), module); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPriceCannotRetrieveAgreementInfo", UtilMisc.toMap("errorString", e.toString()) , locale)); } } @@ -549,7 +553,7 @@ public class PriceServices { result.put("orderItemPriceInfos", orderItemPriceInfos); Map<String, Object> errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, - checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher); + checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher, locale); if (errorResult != null) return errorResult; } else { try { @@ -599,9 +603,9 @@ public class PriceServices { Map<String, Object> quantCalcResults = calcPriceResultFromRules(ruleListToUse, listPrice, defaultPrice, promoPrice, wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, - webSiteId, partyId, null, currencyUomId, delegator, nowTimestamp); + webSiteId, partyId, null, currencyUomId, delegator, nowTimestamp, locale); Map<String, Object> quantErrorResult = addGeneralResults(quantCalcResults, competitivePriceValue, specialPromoPriceValue, productStore, - checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher); + checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher, locale); if (quantErrorResult != null) return quantErrorResult; // also add the quantityProductPriceRule to the Map so it can be used for quantity break information @@ -615,7 +619,7 @@ public class PriceServices { Map<String, Object> calcResults = calcPriceResultFromRules(allProductPriceRules, listPrice, defaultPrice, promoPrice, wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, - webSiteId, partyId, BigDecimal.ONE, currencyUomId, delegator, nowTimestamp); + webSiteId, partyId, BigDecimal.ONE, currencyUomId, delegator, nowTimestamp, locale); result.putAll(calcResults); // The orderItemPriceInfos out parameter requires a special treatment: // the list of OrderItemPriceInfos generated by the price rule is appended to @@ -627,13 +631,13 @@ public class PriceServices { result.put("orderItemPriceInfos", orderItemPriceInfos); Map<String, Object> errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, - checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher); + checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher, locale); if (errorResult != null) return errorResult; } else { Map<String, Object> calcResults = calcPriceResultFromRules(allProductPriceRules, listPrice, defaultPrice, promoPrice, wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, - webSiteId, partyId, quantity, currencyUomId, delegator, nowTimestamp); + webSiteId, partyId, quantity, currencyUomId, delegator, nowTimestamp, locale); result.putAll(calcResults); // The orderItemPriceInfos out parameter requires a special treatment: // the list of OrderItemPriceInfos generated by the price rule is appended to @@ -645,12 +649,13 @@ public class PriceServices { result.put("orderItemPriceInfos", orderItemPriceInfos); Map<String, Object> errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, - checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher); + checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher, locale); if (errorResult != null) return errorResult; } } catch (GenericEntityException e) { Debug.logError(e, "Error getting rules from the database while calculating price", module); - return ServiceUtil.returnError("Error getting rules from the database while calculating price: " + e.toString()); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPriceCannotRetrievePriceRules", UtilMisc.toMap("errorString", e.toString()) , locale)); } } @@ -659,7 +664,7 @@ public class PriceServices { } public static Map<String, Object> addGeneralResults(Map<String, Object> result, GenericValue competitivePriceValue, GenericValue specialPromoPriceValue, GenericValue productStore, - String checkIncludeVat, String currencyUomId, String productId, BigDecimal quantity, String partyId, LocalDispatcher dispatcher) { + String checkIncludeVat, String currencyUomId, String productId, BigDecimal quantity, String partyId, LocalDispatcher dispatcher, Locale locale) { result.put("competitivePrice", competitivePriceValue != null ? competitivePriceValue.getBigDecimal("price") : null); result.put("specialPromoPrice", specialPromoPriceValue != null ? specialPromoPriceValue.getBigDecimal("price") : null); result.put("currencyUsed", currencyUomId); @@ -676,7 +681,8 @@ public class PriceServices { try { Map<String, Object> calcTaxForDisplayResult = dispatcher.runSync("calcTaxForDisplay", calcTaxForDisplayContext); if (ServiceUtil.isError(calcTaxForDisplayResult)) { - return ServiceUtil.returnError("Error calculating VAT tax (with calcTaxForDisplay service)", null, null, calcTaxForDisplayResult); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPriceCannotCalculateVatTax", locale), null, null, calcTaxForDisplayResult); } // taxTotal, taxPercentage, priceWithTax result.put("price", calcTaxForDisplayResult.get("priceWithTax")); @@ -700,9 +706,9 @@ public class PriceServices { result.put("competitivePrice", ((BigDecimal) result.get("competitivePrice")).multiply(taxMultiplier).setScale(taxFinalScale, taxRounding)); } } catch (GenericServiceException e) { - String errMsg = "Error calculating VAT tax (with calcTaxForDisplay service): " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); + Debug.logError(e, "Error calculating VAT tax (with calcTaxForDisplay service): " + e.toString(), module); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPriceCannotCalculateVatTax", locale)); } } @@ -861,7 +867,8 @@ public class PriceServices { public static Map<String, Object> calcPriceResultFromRules(List<GenericValue> productPriceRules, BigDecimal listPrice, BigDecimal defaultPrice, BigDecimal promoPrice, BigDecimal wholesalePrice, GenericValue maximumPriceValue, GenericValue minimumPriceValue, boolean validPriceFound, GenericValue averageCostValue, String productId, String virtualProductId, String prodCatalogId, String productStoreGroupId, - String webSiteId, String partyId, BigDecimal quantity, String currencyUomId, Delegator delegator, Timestamp nowTimestamp) throws GenericEntityException { + String webSiteId, String partyId, BigDecimal quantity, String currencyUomId, Delegator delegator, Timestamp nowTimestamp, + Locale locale) throws GenericEntityException { Map<String, Object> calcResults = FastMap.newInstance(); @@ -1025,8 +1032,10 @@ public class PriceServices { // add a orderItemPriceInfo element too, without orderId or orderItemId StringBuilder priceInfoDescription = new StringBuilder(); + priceInfoDescription.append(condsDescription.toString()); - priceInfoDescription.append("[type:"); + priceInfoDescription.append("["); + priceInfoDescription.append(UtilProperties.getMessage(resource, "ProductPriceConditionType", locale)); priceInfoDescription.append(productPriceAction.getString("productPriceActionTypeId")); priceInfoDescription.append("]"); @@ -1305,6 +1314,7 @@ public class PriceServices { String currencyUomId = (String)context.get("currencyUomId"); String partyId = (String)context.get("partyId"); BigDecimal quantity = (BigDecimal)context.get("quantity"); + Locale locale = (Locale)context.get("locale"); // a) Get the Price from the Agreement* data model // TODO: Implement this @@ -1333,10 +1343,11 @@ public class PriceServices { } // add a orderItemPriceInfo element too, without orderId or orderItemId StringBuilder priceInfoDescription = new StringBuilder(); - priceInfoDescription.append("SupplierProduct "); - priceInfoDescription.append("[minimumOrderQuantity:"); + priceInfoDescription.append(UtilProperties.getMessage(resource, "ProductSupplier", locale)); + priceInfoDescription.append(" ["); + priceInfoDescription.append(UtilProperties.getMessage(resource, "ProductSupplierMinimumOrderQuantity", locale)); priceInfoDescription.append(productSupplier.getBigDecimal("minimumOrderQuantity")); - priceInfoDescription.append(", lastPrice: "); + priceInfoDescription.append(UtilProperties.getMessage(resource, "ProductSupplierLastPrice", locale)); priceInfoDescription.append(productSupplier.getBigDecimal("lastPrice")); priceInfoDescription.append("]"); GenericValue orderItemPriceInfo = delegator.makeValue("OrderItemPriceInfo"); Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/promo/PromoServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/promo/PromoServices.java?rev=1056531&r1=1056530&r2=1056531&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/promo/PromoServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/promo/PromoServices.java Fri Jan 7 22:05:52 2011 @@ -25,6 +25,7 @@ import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.sql.Timestamp; import java.util.List; +import java.util.Locale; import java.util.Map; import javolution.util.FastList; @@ -33,6 +34,7 @@ import javolution.util.FastMap; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilProperties; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.Delegator; import org.ofbiz.entity.GenericEntityException; @@ -52,11 +54,13 @@ import org.ofbiz.service.ServiceUtil; public class PromoServices { public final static String module = PromoServices.class.getName(); - + public static final String resource = "ProductUiLabels"; + public static Map<String, Object> createProductPromoCodeSet(DispatchContext dctx, Map<String, ? extends Object> context) { //Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); Long quantity = (Long) context.get("quantity"); + Locale locale = (Locale) context.get("locale"); //Long useLimitPerCode = (Long) context.get("useLimitPerCode"); //Long useLimitPerCustomer = (Long) context.get("useLimitPerCustomer"); //GenericValue promoItem = null; @@ -68,11 +72,13 @@ public class PromoServices { try { createProductPromoCodeMap = dispatcher.runSync("createProductPromoCode", dctx.makeValidContext("createProductPromoCode", "IN", context)); } catch (GenericServiceException err) { - return ServiceUtil.returnError("Could not create a bank of promo codes", null, null, createProductPromoCodeMap); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPromoCodeCannotBeCreated", locale), null, null, createProductPromoCodeMap); } if (ServiceUtil.isError(createProductPromoCodeMap)) { // what to do here? try again? - return ServiceUtil.returnError("Could not create a bank of promo codes", null, null, createProductPromoCodeMap); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPromoCodeCannotBeCreated", locale), null, null, createProductPromoCodeMap); } bankOfNumbers.append((String) createProductPromoCodeMap.get("productPromoCodeId")); bankOfNumbers.append("<br/>"); @@ -84,6 +90,7 @@ public class PromoServices { public static Map<String, Object> purgeOldStoreAutoPromos(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); String productStoreId = (String) context.get("productStoreId"); + Locale locale = (Locale) context.get("locale"); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); List<EntityCondition> condList = FastList.newInstance(); @@ -105,9 +112,9 @@ public class PromoServices { } eli.close(); } catch (GenericEntityException e) { - String errMsg = "Error removing expired ProductStorePromo records: " + e.toString(); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); + Debug.logError(e, "Error removing expired ProductStorePromo records: " + e.toString(), module); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPromoCodeCannotBeRemoved", UtilMisc.toMap("errorString", e.toString()), locale)); } return ServiceUtil.returnSuccess(); @@ -115,11 +122,13 @@ public class PromoServices { public static Map<String, Object> importPromoCodesFromFile(DispatchContext dctx, Map<String, ? extends Object> context) { LocalDispatcher dispatcher = dctx.getDispatcher(); + Locale locale = (Locale) context.get("locale"); // check the uploaded file ByteBuffer fileBytes = (ByteBuffer) context.get("uploadedFile"); if (fileBytes == null) { - return ServiceUtil.returnError("Uploaded file not valid or corrupted"); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPromoCodeImportUploadedFileNotValid", locale)); } String encoding = System.getProperty("file.encoding"); @@ -158,7 +167,7 @@ public class PromoServices { } } else { // not valid ignore and notify - errors.add(line + ": is not a valid promo code; must be between 1 and 20 characters"); + errors.add(line + UtilProperties.getMessage(resource, "ProductPromoCodeInvalidCode", locale)); } ++lines; } @@ -181,7 +190,8 @@ public class PromoServices { if (errors.size() > 0) { return ServiceUtil.returnError(errors); } else if (lines == 0) { - return ServiceUtil.returnError("Empty file; nothing to do"); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPromoCodeImportEmptyFile", locale)); } return ServiceUtil.returnSuccess(); @@ -189,13 +199,14 @@ public class PromoServices { public static Map<String, Object> importPromoCodeEmailsFromFile(DispatchContext dctx, Map<String, ? extends Object> context) { LocalDispatcher dispatcher = dctx.getDispatcher(); - String productPromoCodeId = (String) context.get("productPromoCodeId"); byte[] wrapper = (byte[]) context.get("uploadedFile"); GenericValue userLogin = (GenericValue) context.get("userLogin"); + Locale locale = (Locale) context.get("locale"); if (wrapper == null) { - return ServiceUtil.returnError("Uploaded file not valid or corrupted"); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPromoCodeImportUploadedFileNotValid", locale)); } // read the bytes into a reader @@ -240,7 +251,8 @@ public class PromoServices { if (errors.size() > 0) { return ServiceUtil.returnError(errors); } else if (lines == 0) { - return ServiceUtil.returnError("Empty file; nothing to do"); + return ServiceUtil.returnError(UtilProperties.getMessage(resource, + "ProductPromoCodeImportEmptyFile", locale)); } return ServiceUtil.returnSuccess(); |
| Free forum by Nabble | Edit this page |
