You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by mb...@apache.org on 2017/12/15 20:43:18 UTC
svn commit: r1818333 -
/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/promo/PromoServices.java
Author: mbrohl
Date: Fri Dec 15 20:43:18 2017
New Revision: 1818333
URL: http://svn.apache.org/viewvc?rev=1818333&view=rev
Log:
Improved: General refactoring and code improvements, package
org.apache.ofbiz.product.promo.
(OFBIZ-10081)
Thanks Dennis Balkir for reporting and providing the patches.
Modified:
ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/promo/PromoServices.java
Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/promo/PromoServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/promo/PromoServices.java?rev=1818333&r1=1818332&r2=1818333&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/promo/PromoServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/promo/PromoServices.java Fri Dec 15 20:43:18 2017
@@ -131,7 +131,7 @@ public class PromoServices {
Locale locale = (Locale) context.get("locale");
Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
- List<EntityCondition> condList = new LinkedList<EntityCondition>();
+ List<EntityCondition> condList = new LinkedList<>();
if (UtilValidate.isEmpty(productStoreId)) {
condList.add(EntityCondition.makeCondition("productStoreId", EntityOperator.EQUALS, productStoreId));
}
@@ -148,7 +148,7 @@ public class PromoServices {
}
} catch (GenericEntityException e) {
Debug.logError(e, "Error removing expired ProductStorePromo records: " + e.toString(), module);
- return ServiceUtil.returnError(UtilProperties.getMessage(resource,
+ return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"ProductPromoCodeCannotBeRemoved", UtilMisc.toMap("errorString", e.toString()), locale));
}
@@ -162,7 +162,7 @@ public class PromoServices {
// check the uploaded file
ByteBuffer fileBytes = (ByteBuffer) context.get("uploadedFile");
if (fileBytes == null) {
- return ServiceUtil.returnError(UtilProperties.getMessage(resource,
+ return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"ProductPromoCodeImportUploadedFileNotValid", locale));
}
@@ -182,7 +182,7 @@ public class PromoServices {
// read the bytes into a reader
BufferedReader reader = new BufferedReader(new StringReader(file));
- List<Object> errors = new LinkedList<Object>();
+ List<Object> errors = new LinkedList<>();
int lines = 0;
String line;
@@ -193,7 +193,7 @@ public class PromoServices {
if (line.length() > 0 && !line.startsWith("#")) {
if (line.length() <= 20) {
// valid promo code
- Map<String, Object> inContext = new HashMap<String, Object>();
+ Map<String, Object> inContext = new HashMap<>();
inContext.putAll(invokeCtx);
inContext.put("productPromoCodeId", line);
Map<String, Object> result = dispatcher.runSync("createProductPromoCode", inContext);
@@ -207,10 +207,7 @@ public class PromoServices {
++lines;
}
}
- } catch (IOException e) {
- Debug.logError(e, module);
- return ServiceUtil.returnError(e.getMessage());
- } catch (GenericServiceException e) {
+ } catch (IOException | GenericServiceException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
} finally {
@@ -225,7 +222,7 @@ public class PromoServices {
if (errors.size() > 0) {
return ServiceUtil.returnError(errors);
} else if (lines == 0) {
- return ServiceUtil.returnError(UtilProperties.getMessage(resource,
+ return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"ProductPromoCodeImportEmptyFile", locale));
}
@@ -245,10 +242,10 @@ public class PromoServices {
}
byte[] wrapper = bytebufferwrapper.array();
-
+
// read the bytes into a reader
BufferedReader reader = new BufferedReader(new StringReader(new String(wrapper, UtilIO.getUtf8())));
- List<Object> errors = new LinkedList<Object>();
+ List<Object> errors = new LinkedList<>();
int lines = 0;
String line;
@@ -270,10 +267,7 @@ public class PromoServices {
++lines;
}
}
- } catch (IOException e) {
- Debug.logError(e, module);
- return ServiceUtil.returnError(e.getMessage());
- } catch (GenericServiceException e) {
+ } catch (IOException | GenericServiceException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
} finally {
@@ -288,7 +282,7 @@ public class PromoServices {
if (errors.size() > 0) {
return ServiceUtil.returnError(errors);
} else if (lines == 0) {
- return ServiceUtil.returnError(UtilProperties.getMessage(resource,
+ return ServiceUtil.returnError(UtilProperties.getMessage(resource,
"ProductPromoCodeImportEmptyFile", locale));
}