Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductServices.java?rev=1818406&r1=1818405&r2=1818406&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductServices.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductServices.java Sat Dec 16 13:56:19 2017 @@ -88,13 +88,13 @@ public class ProductServices { Delegator delegator = dctx.getDelegator(); Locale locale = (Locale) context.get("locale"); Map<String, String> selectedFeatures = UtilGenerics.checkMap(context.get("selectedFeatures")); - List<GenericValue> products = new LinkedList<GenericValue>(); + List<GenericValue> products = new LinkedList<>(); // All the variants for this products are retrieved Map<String, Object> resVariants = prodFindAllVariants(dctx, context); List<GenericValue> variants = UtilGenerics.checkList(resVariants.get("assocProducts")); for (GenericValue oneVariant: variants) { // For every variant, all the standard features are retrieved - Map<String, String> feaContext = new HashMap<String, String>(); + Map<String, String> feaContext = new HashMap<>(); feaContext.put("productId", oneVariant.getString("productIdTo")); feaContext.put("type", "STANDARD_FEATURE"); Map<String, Object> resFeatures = prodGetFeatures(dctx, feaContext); @@ -145,7 +145,7 @@ public class ProductServices { } Locale locale = (Locale) context.get("locale"); String errMsg=null; - Set<String> featureSet = new LinkedHashSet<String>(); + Set<String> featureSet = new LinkedHashSet<>(); try { List<GenericValue> features = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", productFeatureApplTypeId).orderBy("sequenceNum", "productFeatureTypeId").cache(true).filterByDate().queryList(); @@ -178,22 +178,22 @@ public class ProductServices { Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); - Map<String, Object> result = new HashMap<String, Object>(); + Map<String, Object> result = new HashMap<>(); List<String> featureOrder = UtilMisc.makeListWritable(UtilGenerics.<String>checkCollection(context.get("featureOrder"))); if (UtilValidate.isEmpty(featureOrder)) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductFeatureTreeCannotFindFeaturesList", locale)); } List<GenericValue> variants = UtilGenerics.checkList(prodFindAllVariants(dctx, context).get("assocProducts")); - List<String> virtualVariant = new LinkedList<String>(); + List<String> virtualVariant = new LinkedList<>(); if (UtilValidate.isEmpty(variants)) { return ServiceUtil.returnSuccess(); } - List<String> items = new LinkedList<String>(); - List<GenericValue> outOfStockItems = new LinkedList<GenericValue>(); + List<String> items = new LinkedList<>(); + List<GenericValue> outOfStockItems = new LinkedList<>(); for (GenericValue variant: variants) { String productIdTo = variant.getString("productIdTo"); @@ -206,7 +206,7 @@ public class ProductServices { } catch (GenericEntityException e) { Debug.logError(e, module); Map<String, String> messageMap = UtilMisc.toMap("productIdTo", productIdTo, "errMessage", e.toString()); - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "productservices.error_finding_associated_variant_with_ID_error", messageMap, locale)); } if (productTo == null) { @@ -244,7 +244,7 @@ public class ProductServices { if (checkInventory) { Map<String, Object> invReqResult = dispatcher.runSync("isStoreInventoryAvailableOrNotRequired", UtilMisc.<String, Object>toMap("productStoreId", productStoreId, "productId", productIdTo, "quantity", BigDecimal.ONE)); if (ServiceUtil.isError(invReqResult)) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductFeatureTreeCannotCallIsStoreInventoryRequired", locale), null, null, invReqResult); } else if ("Y".equals(invReqResult.get("availableOrNotRequired"))) { items.add(productIdTo); @@ -262,7 +262,7 @@ public class ProductServices { } } catch (GenericServiceException e) { Debug.logError(e, "Error calling the isStoreInventoryRequired when building the variant product tree: " + e.toString(), module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductFeatureTreeCannotCallIsStoreInventoryRequired", locale)); } } @@ -275,16 +275,16 @@ public class ProductServices { selectableFeatures = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", productId, "productFeatureApplTypeId", "SELECTABLE_FEATURE").orderBy("sequenceNum").cache(true).filterByDate().queryList(); } catch (GenericEntityException e) { Debug.logError(e, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, + return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "productservices.empty_list_of_selectable_features_found", locale)); } - Map<String, List<String>> features = new HashMap<String, List<String>>(); + Map<String, List<String>> features = new HashMap<>(); for (GenericValue v: selectableFeatures) { String featureType = v.getString("productFeatureTypeId"); String feature = v.getString("description"); if (!features.containsKey(featureType)) { - List<String> featureList = new LinkedList<String>(); + List<String> featureList = new LinkedList<>(); featureList.add(feature); features.put(featureType, featureList); } else { @@ -303,7 +303,7 @@ public class ProductServices { } if (UtilValidate.isEmpty(tree)) { result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); - result.put(ModelService.ERROR_MESSAGE, UtilProperties.getMessage(resourceError, + result.put(ModelService.ERROR_MESSAGE, UtilProperties.getMessage(resourceError, "productservices.feature_grouping_came_back_empty", locale)); } else { result.put("variantTree", tree); @@ -334,7 +334,7 @@ public class ProductServices { // String type -- Type of feature (STANDARD_FEATURE, SELECTABLE_FEATURE) // String distinct -- Distinct feature (SIZE, COLOR) Delegator delegator = dctx.getDelegator(); - Map<String, Object> result = new HashMap<String, Object>(); + Map<String, Object> result = new HashMap<>(); String productId = (String) context.get("productId"); String distinct = (String) context.get("distinct"); String type = (String) context.get("type"); @@ -345,14 +345,18 @@ public class ProductServices { try { Map<String, String> fields = UtilMisc.toMap("productId", productId); - if (distinct != null) fields.put("productFeatureTypeId", distinct); - if (type != null) fields.put("productFeatureApplTypeId", type); + if (distinct != null) { + fields.put("productFeatureTypeId", distinct); + } + if (type != null) { + fields.put("productFeatureApplTypeId", type); + } features = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where(fields).orderBy("sequenceNum", "productFeatureTypeId").cache(true).queryList(); result.put("productFeatures", features); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); } catch (GenericEntityException e) { Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.toString()); - errMsg = UtilProperties.getMessage(resourceError, + errMsg = UtilProperties.getMessage(resourceError, "productservices.problem_reading_product_feature_entity", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -365,13 +369,13 @@ public class ProductServices { */ public static Map<String, Object> prodFindProduct(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); - Map<String, Object> result = new HashMap<String, Object>(); + Map<String, Object> result = new HashMap<>(); String productId = (String) context.get("productId"); Locale locale = (Locale) context.get("locale"); String errMsg = null; if (UtilValidate.isEmpty(productId)) { - errMsg = UtilProperties.getMessage(resourceError, + errMsg = UtilProperties.getMessage(resourceError, "productservices.invalid_productId_passed", locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -395,7 +399,7 @@ public class ProductServices { } catch (GenericEntityException e) { e.printStackTrace(); Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.getMessage()); - errMsg = UtilProperties.getMessage(resourceError, + errMsg = UtilProperties.getMessage(resourceError, "productservices.problems_reading_product_entity", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -408,9 +412,9 @@ public class ProductServices { * Finds associated products by product ID and association ID. */ public static Map<String, Object> prodFindAssociatedByType(DispatchContext dctx, Map<String, ? extends Object> context) { - // String type -- Type of association (ie PRODUCT_UPGRADE, PRODUCT_COMPLEMENT, PRODUCT_VARIANT) + // String type -- Type of association (ie PRODUCT_UPGRADE, PRODUCT_COMPLEMENT, PRODUCT_VARIANT) Delegator delegator = dctx.getDelegator(); - Map<String, Object> result = new HashMap<String, Object>(); + Map<String, Object> result = new HashMap<>(); String productId = (String) context.get("productId"); String productIdTo = (String) context.get("productIdTo"); String type = (String) context.get("type"); @@ -426,7 +430,7 @@ public class ProductServices { sortDescending = sortDescending == null ? Boolean.FALSE : sortDescending; if (productId == null && productIdTo == null) { - errMsg = UtilProperties.getMessage(resourceError, + errMsg = UtilProperties.getMessage(resourceError, "productservices.both_productId_and_productIdTo_cannot_be_null", locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -434,7 +438,7 @@ public class ProductServices { } if (productId != null && productIdTo != null) { - errMsg = UtilProperties.getMessage(resourceError, + errMsg = UtilProperties.getMessage(resourceError, "productservices.both_productId_and_productIdTo_cannot_be_defined", locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -448,7 +452,7 @@ public class ProductServices { product = EntityQuery.use(delegator).from("Product").where("productId", productId).cache().queryOne(); } catch (GenericEntityException e) { Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.getMessage()); - errMsg = UtilProperties.getMessage(resourceError, + errMsg = UtilProperties.getMessage(resourceError, "productservices.problems_reading_product_entity", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -456,7 +460,7 @@ public class ProductServices { } if (product == null) { - errMsg = UtilProperties.getMessage(resourceError, + errMsg = UtilProperties.getMessage(resourceError, "productservices.problems_getting_product_entity", locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -466,7 +470,7 @@ public class ProductServices { try { List<GenericValue> productAssocs = null; - List<String> orderBy = new LinkedList<String>(); + List<String> orderBy = new LinkedList<>(); if (sortDescending) { orderBy.add("sequenceNum DESC"); } else { @@ -506,7 +510,7 @@ public class ProductServices { result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); } catch (GenericEntityException e) { Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.getMessage()); - errMsg = UtilProperties.getMessage(resourceError, + errMsg = UtilProperties.getMessage(resourceError, "productservices.problems_product_association_relation_error", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -519,8 +523,8 @@ public class ProductServices { // Builds a product feature tree private static Map<String, Object> makeGroup(Delegator delegator, Map<String, List<String>> featureList, List<String> items, List<String> order, int index) throws IllegalArgumentException, IllegalStateException { - Map<String, List<String>> tempGroup = new HashMap<String, List<String>>(); - Map<String, Object> group = new LinkedHashMap<String, Object>(); + Map<String, List<String>> tempGroup = new HashMap<>(); + Map<String, Object> group = new LinkedHashMap<>(); String orderKey = order.get(index); if (featureList == null) { @@ -540,7 +544,9 @@ public class ProductServices { // Gather the necessary data // ------------------------------- - if (Debug.verboseOn()) Debug.logVerbose("ThisItem: " + thisItem, module); + if (Debug.verboseOn()) { + Debug.logVerbose("ThisItem: " + thisItem, module); + } List<GenericValue> features = null; try { @@ -554,7 +560,9 @@ public class ProductServices { } catch (GenericEntityException e) { throw new IllegalStateException("Problem reading relation: " + e.getMessage()); } - if (Debug.verboseOn()) Debug.logVerbose("Features: " + features, module); + if (Debug.verboseOn()) { + Debug.logVerbose("Features: " + features, module); + } // ------------------------------- for (GenericValue item: features) { @@ -563,8 +571,9 @@ public class ProductServices { if (tempGroup.containsKey(itemKey)) { List<String> itemList = tempGroup.get(itemKey); - if (!itemList.contains(thisItem)) + if (!itemList.contains(thisItem)) { itemList.add(thisItem); + } } else { List<String> itemList = UtilMisc.toList(thisItem); @@ -572,7 +581,9 @@ public class ProductServices { } } } - if (Debug.verboseOn()) Debug.logVerbose("TempGroup: " + tempGroup, module); + if (Debug.verboseOn()) { + Debug.logVerbose("TempGroup: " + tempGroup, module); + } // Loop through the feature list and order the keys in the tempGroup List<String> orderFeatureList = featureList.get(orderKey); @@ -582,11 +593,14 @@ public class ProductServices { } for (String featureStr: orderFeatureList) { - if (tempGroup.containsKey(featureStr)) + if (tempGroup.containsKey(featureStr)) { group.put(featureStr, tempGroup.get(featureStr)); + } } - if (Debug.verboseOn()) Debug.logVerbose("Group: " + group, module); + if (Debug.verboseOn()) { + Debug.logVerbose("Group: " + group, module); + } // no groups; no tree if (group.size() == 0) { @@ -612,8 +626,8 @@ public class ProductServices { // builds a variant sample (a single sku for a featureType) private static Map<String, GenericValue> makeVariantSample(Delegator delegator, Map<String, List<String>> featureList, List<String> items, String feature) { - Map<String, GenericValue> tempSample = new HashMap<String, GenericValue>(); - Map<String, GenericValue> sample = new LinkedHashMap<String, GenericValue>(); + Map<String, GenericValue> tempSample = new HashMap<>(); + Map<String, GenericValue> sample = new LinkedHashMap<>(); for (String productId: items) { List<GenericValue> features = null; @@ -642,8 +656,9 @@ public class ProductServices { // Sort the sample based on the feature list. List<String> features = featureList.get(feature); for (String f: features) { - if (tempSample.containsKey(f)) + if (tempSample.containsKey(f)) { sample.put(f, tempSample.get(f)); + } } return sample; @@ -651,7 +666,7 @@ public class ProductServices { public static Map<String, Object> quickAddVariant(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); - Map<String, Object> result = new HashMap<String, Object>(); + Map<String, Object> result = new HashMap<>(); Locale locale = (Locale) context.get("locale"); String errMsg=null; String productId = (String) context.get("productId"); @@ -664,7 +679,7 @@ public class ProductServices { GenericValue product = EntityQuery.use(delegator).from("Product").where("productId", productId).queryOne(); if (product == null) { Map<String, String> messageMap = UtilMisc.toMap("productId", productId); - errMsg = UtilProperties.getMessage(resourceError, + errMsg = UtilProperties.getMessage(resourceError, "productservices.product_not_found_with_ID", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -730,7 +745,7 @@ public class ProductServices { } catch (GenericEntityException e) { Debug.logError(e, "Entity error creating quick add variant data", module); Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.toString()); - errMsg = UtilProperties.getMessage(resourceError, + errMsg = UtilProperties.getMessage(resourceError, "productservices.entity_error_quick_add_variant_data", messageMap, locale); result.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_ERROR); result.put(ModelService.ERROR_MESSAGE, errMsg); @@ -754,7 +769,7 @@ public class ProductServices { String productFeatureIdTwo = (String) context.get("productFeatureIdTwo"); String productFeatureIdThree = (String) context.get("productFeatureIdThree"); Locale locale = (Locale) context.get("locale"); - + Map<String, Object> successResult = ServiceUtil.returnSuccess(); try { @@ -784,14 +799,14 @@ public class ProductServices { // separate variantProductIdsBag into a Set of variantProductIds //note: can be comma, tab, or white-space delimited - Set<String> prelimVariantProductIds = new HashSet<String>(); + Set<String> prelimVariantProductIds = new HashSet<>(); List<String> splitIds = Arrays.asList(variantProductIdsBag.split("[,\\p{Space}]")); Debug.logInfo("Variants: bag=" + variantProductIdsBag, module); Debug.logInfo("Variants: split=" + splitIds, module); prelimVariantProductIds.addAll(splitIds); //note: should support both direct productIds and GoodIdentification entries (what to do if more than one GoodID? Add all? - Map<String, GenericValue> variantProductsById = new HashMap<String, GenericValue>(); + Map<String, GenericValue> variantProductsById = new HashMap<>(); for (String variantProductId: prelimVariantProductIds) { if (UtilValidate.isEmpty(variantProductId)) { // not sure why this happens, but seems to from time to time with the split method @@ -806,7 +821,7 @@ public class ProductServices { List<GenericValue> goodIdentificationList = EntityQuery.use(delegator).from("GoodIdentification").where("idValue", variantProductId).queryList(); if (UtilValidate.isEmpty(goodIdentificationList)) { // whoops, nothing found... return error - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductVirtualVariantCreation", UtilMisc.toMap("variantProductId", variantProductId), locale)); } @@ -825,10 +840,10 @@ public class ProductServices { } // Attach productFeatureIdOne, Two, Three to the new virtual and all variant products as a standard feature - Set<String> featureProductIds = new HashSet<String>(); + Set<String> featureProductIds = new HashSet<>(); featureProductIds.add(productId); featureProductIds.addAll(variantProductsById.keySet()); - Set<String> productFeatureIds = new HashSet<String>(); + Set<String> productFeatureIds = new HashSet<>(); productFeatureIds.add(productFeatureIdOne); productFeatureIds.add(productFeatureIdTwo); productFeatureIds.add(productFeatureIdThree); @@ -929,8 +944,8 @@ public class ProductServices { return ServiceUtil.returnSuccess(); } - public static Map<String, Object> addAdditionalViewForProduct(DispatchContext dctx, Map<String, ? extends Object> context) - throws IOException, JDOMException { + public static Map<String, Object> addAdditionalViewForProduct(DispatchContext dctx, + Map<String, ? extends Object> context) { LocalDispatcher dispatcher = dctx.getDispatcher(); Delegator delegator = dctx.getDelegator(); @@ -940,7 +955,7 @@ public class ProductServices { Locale locale = (Locale) context.get("locale"); if (UtilValidate.isNotEmpty(context.get("_uploadedFile_fileName"))) { - Map<String, Object> imageContext = new HashMap<String, Object>(); + Map<String, Object> imageContext = new HashMap<>(); imageContext.putAll(context); imageContext.put("delegator", delegator); imageContext.put("tenantId",delegator.getDelegatorTenantId()); @@ -955,7 +970,7 @@ public class ProductServices { String viewType = "additional" + viewNumber; String id = productId; if (imageFilenameFormat.endsWith("${id}")) { - id = productId + "_View_" + viewNumber; + id = productId + "_View_" + viewNumber; viewType = "additional"; } String fileLocation = filenameExpander.expandString(UtilMisc.toMap("location", "products", "id", id, "viewtype", viewType, "sizetype", "original")); @@ -995,7 +1010,7 @@ public class ProductServices { // Images are ordered by productId (${location}/${id}/${viewtype}/${sizetype}) } else if (!filenameToUse.contains(productId)) { try { - File[] files = targetDir.listFiles(); + File[] files = targetDir.listFiles(); for (File file : files) { if (file.isFile()) { if (!file.delete()) { @@ -1010,7 +1025,7 @@ public class ProductServices { // Images aren't ordered by productId (${location}/${viewtype}/${sizetype}/${id}) } else { try { - File[] files = targetDir.listFiles(); + File[] files = targetDir.listFiles(); for (File file : files) { if (file.isFile() && file.getName().startsWith(productId + "_View_" + viewNumber)) { if (!file.delete()) { @@ -1034,11 +1049,11 @@ public class ProductServices { out.close(); } catch (FileNotFoundException e) { Debug.logError(e, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductImageViewUnableWriteFile", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale)); } catch (IOException e) { Debug.logError(e, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductImageViewUnableWriteBinaryData", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale)); } } catch (NullPointerException e) { @@ -1046,16 +1061,16 @@ public class ProductServices { } /* scale Image in different sizes */ - Map<String, Object> resultResize = new HashMap<String, Object>(); + Map<String, Object> resultResize = new HashMap<>(); try { resultResize.putAll(ScaleImage.scaleImageInAllSize(imageContext, filenameToUse, "additional", viewNumber)); } catch (IOException e) { Debug.logError(e, "Scale additional image in all different sizes is impossible : " + e.toString(), module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductImageViewScaleImpossible", UtilMisc.toMap("errorString", e.toString()), locale)); } catch (JDOMException e) { Debug.logError(e, "Errors occur in parsing ImageProperties.xml : " + e.toString(), module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductImageViewParsingError", UtilMisc.toMap("errorString", e.toString()), locale)); } @@ -1096,7 +1111,7 @@ public class ProductServices { return ServiceUtil.returnSuccess(); } - private static Map<String,Object> addImageResource( LocalDispatcher dispatcher, Delegator delegator, Map<String, ? extends Object> context, + private static Map<String,Object> addImageResource( LocalDispatcher dispatcher, Delegator delegator, Map<String, ? extends Object> context, String imageUrl, String productContentTypeId ) { GenericValue userLogin = (GenericValue) context.get("userLogin"); String productId = (String) context.get("productId"); @@ -1104,12 +1119,12 @@ public class ProductServices { if (UtilValidate.isNotEmpty(imageUrl) && imageUrl.length() > 0) { String contentId = (String) context.get("contentId"); - Map<String, Object> dataResourceCtx = new HashMap<String, Object>(); + Map<String, Object> dataResourceCtx = new HashMap<>(); dataResourceCtx.put("objectInfo", imageUrl); dataResourceCtx.put("dataResourceName", context.get("_uploadedFile_fileName")); dataResourceCtx.put("userLogin", userLogin); - Map<String, Object> productContentCtx = new HashMap<String, Object>(); + Map<String, Object> productContentCtx = new HashMap<>(); productContentCtx.put("productId", productId); productContentCtx.put("productContentTypeId", productContentTypeId); productContentCtx.put("fromDate", context.get("fromDate")); @@ -1153,7 +1168,7 @@ public class ProductServices { return ServiceUtil.returnError(e.getMessage()); } - Map<String, Object> contentCtx = new HashMap<String, Object>(); + Map<String, Object> contentCtx = new HashMap<>(); contentCtx.put("contentId", contentId); contentCtx.put("dataResourceId", dataResourceResult.get("dataResourceId")); contentCtx.put("userLogin", userLogin); @@ -1184,7 +1199,7 @@ public class ProductServices { return ServiceUtil.returnError(e.getMessage()); } - Map<String, Object> contentCtx = new HashMap<String, Object>(); + Map<String, Object> contentCtx = new HashMap<>(); contentCtx.put("contentTypeId", "DOCUMENT"); contentCtx.put("dataResourceId", dataResourceResult.get("dataResourceId")); contentCtx.put("userLogin", userLogin); @@ -1247,8 +1262,8 @@ public class ProductServices { return result; } - public static Map<String, Object> addImageForProductPromo(DispatchContext dctx, Map<String, ? extends Object> context) - throws IOException, JDOMException { + public static Map<String, Object> addImageForProductPromo(DispatchContext dctx, + Map<String, ? extends Object> context) { LocalDispatcher dispatcher = dctx.getDispatcher(); Delegator delegator = dctx.getDelegator(); GenericValue userLogin = (GenericValue) context.get("userLogin"); @@ -1259,7 +1274,7 @@ public class ProductServices { Locale locale = (Locale) context.get("locale"); if (UtilValidate.isNotEmpty(context.get("_uploadedFile_fileName"))) { - Map<String, Object> imageContext = new HashMap<String, Object>(); + Map<String, Object> imageContext = new HashMap<>(); imageContext.putAll(context); imageContext.put("tenantId",delegator.getDelegatorTenantId()); String imageFilenameFormat = EntityUtilProperties.getPropertyValue("catalog", "image.filename.format", delegator); @@ -1307,23 +1322,23 @@ public class ProductServices { out.close(); } catch (FileNotFoundException e) { Debug.logError(e, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductImageViewUnableWriteFile", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale)); } catch (IOException e) { Debug.logError(e, module); - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductImageViewUnableWriteBinaryData", UtilMisc.toMap("fileName", file.getAbsolutePath()), locale)); } String imageUrl = imageUrlPrefix + "/" + filePathPrefix + filenameToUse; if (UtilValidate.isNotEmpty(imageUrl) && imageUrl.length() > 0) { - Map<String, Object> dataResourceCtx = new HashMap<String, Object>(); + Map<String, Object> dataResourceCtx = new HashMap<>(); dataResourceCtx.put("objectInfo", imageUrl); dataResourceCtx.put("dataResourceName", context.get("_uploadedFile_fileName")); dataResourceCtx.put("userLogin", userLogin); - Map<String, Object> productPromoContentCtx = new HashMap<String, Object>(); + Map<String, Object> productPromoContentCtx = new HashMap<>(); productPromoContentCtx.put("productPromoId", productPromoId); productPromoContentCtx.put("productPromoContentTypeId", productPromoContentTypeId); productPromoContentCtx.put("fromDate", context.get("fromDate")); @@ -1367,7 +1382,7 @@ public class ProductServices { return ServiceUtil.returnError(e.getMessage()); } - Map<String, Object> contentCtx = new HashMap<String, Object>(); + Map<String, Object> contentCtx = new HashMap<>(); contentCtx.put("contentId", contentId); contentCtx.put("dataResourceId", dataResourceResult.get("dataResourceId")); contentCtx.put("userLogin", userLogin); @@ -1398,7 +1413,7 @@ public class ProductServices { return ServiceUtil.returnError(e.getMessage()); } - Map<String, Object> contentCtx = new HashMap<String, Object>(); + Map<String, Object> contentCtx = new HashMap<>(); contentCtx.put("contentTypeId", "DOCUMENT"); contentCtx.put("dataResourceId", dataResourceResult.get("dataResourceId")); contentCtx.put("userLogin", userLogin); @@ -1420,7 +1435,7 @@ public class ProductServices { } } } else { - Map<String, Object> productPromoContentCtx = new HashMap<String, Object>(); + Map<String, Object> productPromoContentCtx = new HashMap<>(); productPromoContentCtx.put("productPromoId", productPromoId); productPromoContentCtx.put("productPromoContentTypeId", productPromoContentTypeId); productPromoContentCtx.put("contentId", contentId); Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductUtilServices.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductUtilServices.java?rev=1818406&r1=1818405&r2=1818406&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductUtilServices.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductUtilServices.java Sat Dec 16 13:56:19 2017 @@ -243,8 +243,8 @@ public final class ProductUtilServices { dve.addAlias("PVA", "productIdToCount", "productIdTo", null, null, null, "count-distinct"); EntityCondition condition = EntityCondition.makeCondition(UtilMisc.toList( EntityCondition.makeCondition("productAssocTypeId", EntityOperator.EQUALS, "PRODUCT_VARIANT"), - EntityCondition.makeCondition(EntityCondition.makeCondition("salesDiscontinuationDate", EntityOperator.EQUALS, null), - EntityOperator.OR, + EntityCondition.makeCondition(EntityCondition.makeCondition("salesDiscontinuationDate", EntityOperator.EQUALS, null), + EntityOperator.OR, EntityCondition.makeCondition("salesDiscontinuationDate", EntityOperator.GREATER_THAN, nowTimestamp)) ), EntityOperator.AND); EntityCondition havingCond = EntityCondition.makeCondition("productIdToCount", EntityOperator.EQUALS, Long.valueOf(1)); @@ -253,7 +253,7 @@ public final class ProductUtilServices { .from(dve) .where(condition) .having(havingCond); - + try (EntityListIterator eliOne = eq.queryIterator()) { List<GenericValue> valueList = eliOne.getCompleteList(); @@ -319,12 +319,7 @@ public final class ProductUtilServices { Debug.logError(e, errMsg, module); return ServiceUtil.returnError(errMsg); } - } catch (GenericEntityException e) { - Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.toString()); - errMsg = UtilProperties.getMessage(resourceError,"productutilservices.entity_error_running_makeStandAloneFromSingleVariantVirtuals", messageMap, locale); - Debug.logError(e, errMsg, module); - return ServiceUtil.returnError(errMsg); - } catch (GenericServiceException e) { + } catch (GenericEntityException | GenericServiceException e) { Map<String, String> messageMap = UtilMisc.toMap("errMessage", e.toString()); errMsg = UtilProperties.getMessage(resourceError,"productutilservices.entity_error_running_makeStandAloneFromSingleVariantVirtuals", messageMap, locale); Debug.logError(e, errMsg, module); @@ -436,7 +431,7 @@ public final class ProductUtilServices { } if (test) { - return ServiceUtil.returnError(UtilProperties.getMessage(resource, + return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ProductMergeVirtualWithSingleVariant", locale)); } } catch (GenericEntityException e) { @@ -499,7 +494,7 @@ public final class ProductUtilServices { String errMsg = null; if (UtilValidate.isEmpty(pattern)) { - Map<String, Object> imageContext = new HashMap<String, Object>(); + Map<String, Object> imageContext = new HashMap<>(); imageContext.putAll(context); imageContext.put("tenantId",delegator.getDelegatorTenantId()); String imageFilenameFormat = EntityUtilProperties.getPropertyValue("catalog", "image.filename.format", delegator); @@ -599,7 +594,7 @@ public final class ProductUtilServices { boolean doSubCategories = !"N".equals(doSubCategoriesStr); Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); - Set<String> productFeatureTypeIdsToExclude = new HashSet<String>(); + Set<String> productFeatureTypeIdsToExclude = new HashSet<>(); String excludeProp = EntityUtilProperties.getPropertyValue("prodsearch", "attach.feature.type.exclude", delegator); if (UtilValidate.isNotEmpty(excludeProp)) { List<String> typeList = StringUtil.split(excludeProp, ","); @@ -640,20 +635,20 @@ public final class ProductUtilServices { List<GenericValue> subCategoryList = EntityQuery.use(delegator).from("ProductCategoryRollup").where("parentProductCategoryId", productCategoryId).queryList(); if (doSubCategories) { for (GenericValue productCategoryRollup: subCategoryList) { - attachProductFeaturesToCategory(productCategoryRollup.getString("productCategoryId"), productFeatureTypeIdsToInclude, productFeatureTypeIdsToExclude, + attachProductFeaturesToCategory(productCategoryRollup.getString("productCategoryId"), productFeatureTypeIdsToInclude, productFeatureTypeIdsToExclude, delegator, true, nowTimestamp); } } // now get all features for this category and make associated feature groups - Map<String, Set<String>> productFeatureIdByTypeIdSetMap = new HashMap<String, Set<String>>(); + Map<String, Set<String>> productFeatureIdByTypeIdSetMap = new HashMap<>(); List<GenericValue> productCategoryMemberList = EntityQuery.use(delegator).from("ProductCategoryMember").where("productCategoryId", productCategoryId).queryList(); for (GenericValue productCategoryMember: productCategoryMemberList) { String productId = productCategoryMember.getString("productId"); EntityCondition condition = EntityCondition.makeCondition(UtilMisc.toList( EntityCondition.makeCondition("productId", EntityOperator.EQUALS, productId), EntityCondition.makeCondition("fromDate", EntityOperator.LESS_THAN_EQUAL_TO, nowTimestamp), - EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), + EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN_EQUAL_TO, nowTimestamp)) ), EntityOperator.AND); @@ -670,7 +665,7 @@ public final class ProductUtilServices { } Set<String> productFeatureIdSet = productFeatureIdByTypeIdSetMap.get(productFeatureTypeId); if (productFeatureIdSet == null) { - productFeatureIdSet = new HashSet<String>(); + productFeatureIdSet = new HashSet<>(); productFeatureIdByTypeIdSetMap.put(productFeatureTypeId, productFeatureIdSet); } productFeatureIdSet.add(productFeatureId); Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductWorker.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductWorker.java?rev=1818406&r1=1818405&r2=1818406&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductWorker.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductWorker.java Sat Dec 16 13:56:19 2017 @@ -73,12 +73,10 @@ public final class ProductWorker { if (chargeShipping == null) { return true; - } else { - return chargeShipping.booleanValue(); } - } else { - throw new IllegalArgumentException(errMsg); + return chargeShipping.booleanValue(); } + throw new IllegalArgumentException(errMsg); } public static boolean isBillableToAddress(GenericValue product, GenericValue postalAddress) { @@ -149,12 +147,10 @@ public final class ProductWorker { if (taxable == null) { return true; - } else { - return taxable.booleanValue(); } - } else { - throw new IllegalArgumentException(errMsg); + return taxable.booleanValue(); } + throw new IllegalArgumentException(errMsg); } public static String getInstanceAggregatedId(Delegator delegator, String instanceProductId) throws GenericEntityException { @@ -200,9 +196,8 @@ public final class ProductWorker { GenericValue productAssoc = EntityUtil.getFirst(productAssocs); if (productAssoc != null) { return productAssoc.getString("productId"); - } else { - return null; } + return null; } public static List<GenericValue> getVariantVirtualAssocs(GenericValue variantProduct) throws GenericEntityException { @@ -237,12 +232,17 @@ public final class ProductWorker { // check to see if we got enough back... if (availableToPromise.compareTo(quantity) >= 0) { - if (Debug.infoOn()) Debug.logInfo("Inventory IS available in facility with id " + inventoryFacilityId + " for product id " + productId + "; desired quantity is " + quantity + ", available quantity is " + availableToPromise, module); + if (Debug.infoOn()) { + Debug.logInfo("Inventory IS available in facility with id " + inventoryFacilityId + " for product id " + productId + "; desired quantity is " + quantity + ", available quantity is " + availableToPromise, module); + } return true; - } else { - if (Debug.infoOn()) Debug.logInfo("Returning false because there is insufficient inventory available in facility with id " + inventoryFacilityId + " for product id " + productId + "; desired quantity is " + quantity + ", available quantity is " + availableToPromise, module); - return false; } + if (Debug.infoOn()) { + Debug.logInfo("Returning false because there is insufficient inventory available in facility with id " + + inventoryFacilityId + " for product id " + productId + "; desired quantity is " + quantity + + ", available quantity is " + availableToPromise, module); + } + return false; } /** @@ -278,7 +278,7 @@ public final class ProductWorker { */ public static Set<GenericValue> getVariantDistinguishingFeatures(GenericValue variantProduct) throws GenericEntityException { if (variantProduct == null) { - return new HashSet<GenericValue>(); + return new HashSet<>(); } if (!"Y".equals(variantProduct.getString("isVariant"))) { throw new IllegalArgumentException("Cannot get distinguishing features for a product that is not a variant (ie isVariant!=Y)."); @@ -287,7 +287,7 @@ public final class ProductWorker { String virtualProductId = getVariantVirtualId(variantProduct); // find all selectable features on the virtual product that are also standard features on the variant - Set<GenericValue> distFeatures = new HashSet<GenericValue>(); + Set<GenericValue> distFeatures = new HashSet<>(); List<GenericValue> variantDistinguishingFeatures = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", variantProduct.get("productId"), "productFeatureApplTypeId", "DISTINGUISHING_FEAT").cache(true).queryList(); @@ -299,7 +299,7 @@ public final class ProductWorker { List<GenericValue> virtualSelectableFeatures = EntityQuery.use(delegator).from("ProductFeatureAndAppl").where("productId", virtualProductId, "productFeatureApplTypeId", "SELECTABLE_FEATURE").cache(true).queryList(); - Set<String> virtualSelectableFeatureIds = new HashSet<String>(); + Set<String> virtualSelectableFeatureIds = new HashSet<>(); for (GenericValue virtualSelectableFeature: EntityUtil.filterByDate(virtualSelectableFeatures)) { virtualSelectableFeatureIds.add(virtualSelectableFeature.getString("productFeatureId")); } @@ -350,8 +350,6 @@ public final class ProductWorker { } } catch (GenericEntityException e) { Debug.logError(e, module); - } catch (Exception e) { - Debug.logError(e, module); } // finally fall back to the ID in square braces return "[" + alternativeOptionProductId + "]"; @@ -397,7 +395,7 @@ public final class ProductWorker { features = EntityUtil.orderBy(features, UtilMisc.toList("description")); } catch (GenericEntityException e) { Debug.logError(e, module); - features = new LinkedList<GenericValue>(); + features = new LinkedList<>(); } return features; } @@ -412,9 +410,8 @@ public final class ProductWorker { if (product != null) { return product.getString("virtualVariantMethodEnum"); - } else { - return null; } + return null; } /** @@ -426,7 +423,7 @@ public final class ProductWorker { if (product == null) { return null; } - List <List<Map<String,String>>> featureTypeFeatures = new LinkedList<List<Map<String,String>>>(); + List <List<Map<String,String>>> featureTypeFeatures = new LinkedList<>(); try { Delegator delegator = product.getDelegator(); List<GenericValue> featuresSorted = EntityQuery.use(delegator) @@ -436,13 +433,13 @@ public final class ProductWorker { .cache(true) .queryList(); String oldType = null; - List<Map<String,String>> featureList = new LinkedList<Map<String,String>>(); + List<Map<String,String>> featureList = new LinkedList<>(); for (GenericValue productFeatureAppl: featuresSorted) { if (oldType == null || !oldType.equals(productFeatureAppl.getString("productFeatureTypeId"))) { // use first entry for type and description if (oldType != null) { featureTypeFeatures.add(featureList); - featureList = new LinkedList<Map<String,String>>(); + featureList = new LinkedList<>(); } GenericValue productFeatureType = EntityQuery.use(delegator).from("ProductFeatureType").where("productFeatureTypeId", productFeatureAppl.getString("productFeatureTypeId")).queryOne(); featureList.add(UtilMisc.<String, String>toMap("productFeatureTypeId", productFeatureAppl.getString("productFeatureTypeId"), @@ -499,7 +496,7 @@ public final class ProductWorker { List<String> selectableTypes = EntityUtil.getFieldListFromEntityList(selectableFeatures, "productFeatureTypeId", true); // The standard features from the variant product List<GenericValue> standardFeatures = ProductWorker.getProductFeaturesByApplTypeId(variantProduct, "STANDARD_FEATURE"); - List<GenericValue> result = new LinkedList<GenericValue>(); + List<GenericValue> result = new LinkedList<>(); for (GenericValue standardFeature : standardFeatures) { // For each standard variant feature check it is also a virtual selectable feature and // if a feature of the same type hasn't already been added to the list @@ -512,7 +509,7 @@ public final class ProductWorker { } public static Map<String, List<GenericValue>> getOptionalProductFeatures(Delegator delegator, String productId) { - Map<String, List<GenericValue>> featureMap = new LinkedHashMap<String, List<GenericValue>>(); + Map<String, List<GenericValue>> featureMap = new LinkedHashMap<>(); List<GenericValue> productFeatureAppls = null; try { @@ -526,7 +523,7 @@ public final class ProductWorker { String featureType = appl.getString("productFeatureTypeId"); List<GenericValue> features = featureMap.get(featureType); if (features == null) { - features = new LinkedList<GenericValue>(); + features = new LinkedList<>(); } features.add(appl); featureMap.put(featureType, features); @@ -563,18 +560,24 @@ public final class ProductWorker { } public static List<GenericValue> filterOrderAdjustments(List<GenericValue> adjustments, boolean includeOther, boolean includeTax, boolean includeShipping, boolean forTax, boolean forShipping) { - List<GenericValue> newOrderAdjustmentsList = new LinkedList<GenericValue>(); + List<GenericValue> newOrderAdjustmentsList = new LinkedList<>(); if (UtilValidate.isNotEmpty(adjustments)) { for (GenericValue orderAdjustment: adjustments) { boolean includeAdjustment = false; if ("SALES_TAX".equals(orderAdjustment.getString("orderAdjustmentTypeId"))) { - if (includeTax) includeAdjustment = true; + if (includeTax) { + includeAdjustment = true; + } } else if ("SHIPPING_CHARGES".equals(orderAdjustment.getString("orderAdjustmentTypeId"))) { - if (includeShipping) includeAdjustment = true; + if (includeShipping) { + includeAdjustment = true; + } } else { - if (includeOther) includeAdjustment = true; + if (includeOther) { + includeAdjustment = true; + } } // default to yes, include for shipping; so only exclude if includeInShipping is N, or false; if Y or null or anything else it will be included @@ -695,7 +698,7 @@ public final class ProductWorker { if (product == null) { return null; } - List<GenericValue> categories = new LinkedList<GenericValue>(); + List<GenericValue> categories = new LinkedList<>(); try { List<GenericValue> categoryMembers = product.getRelated("ProductCategoryMember", null, null, false); categoryMembers = EntityUtil.filterByDate(categoryMembers); @@ -830,25 +833,24 @@ public final class ProductWorker { if (weight == null) { return null; - } else { - // attempt a conversion if necessary - if (desiredUomId != null && product.get("weightUomId") != null && !desiredUomId.equals(product.get("weightUomId"))) { - Map<String, Object> result = new HashMap<String, Object>(); - try { - result = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", weightUomId, "uomIdTo", desiredUomId, "originalValue", weight)); - } catch (GenericServiceException e) { - Debug.logError(e, module); - } + } + // attempt a conversion if necessary + if (desiredUomId != null && product.get("weightUomId") != null && !desiredUomId.equals(product.get("weightUomId"))) { + Map<String, Object> result = new HashMap<>(); + try { + result = dispatcher.runSync("convertUom", UtilMisc.<String, Object>toMap("uomId", weightUomId, "uomIdTo", desiredUomId, "originalValue", weight)); + } catch (GenericServiceException e) { + Debug.logError(e, module); + } - if (result.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_SUCCESS) && result.get("convertedValue") != null) { - weight = (BigDecimal) result.get("convertedValue"); - } else { - Debug.logError("Unsupported conversion from [" + weightUomId + "] to [" + desiredUomId + "]",module); - return null; - } + if (result.get(ModelService.RESPONSE_MESSAGE).equals(ModelService.RESPOND_SUCCESS) && result.get("convertedValue") != null) { + weight = (BigDecimal) result.get("convertedValue"); + } else { + Debug.logError("Unsupported conversion from [" + weightUomId + "] to [" + desiredUomId + "]", module); + return null; } - return weight; } + return weight; } @@ -870,7 +872,9 @@ public final class ProductWorker { String idToFind, String goodIdentificationTypeId, boolean searchProductFirst, boolean searchAllId) throws GenericEntityException { - if (Debug.verboseOn()) Debug.logVerbose("Analyze goodIdentification: entered id = " + idToFind + ", goodIdentificationTypeId = " + goodIdentificationTypeId, module); + if (Debug.verboseOn()) { + Debug.logVerbose("Analyze goodIdentification: entered id = " + idToFind + ", goodIdentificationTypeId = " + goodIdentificationTypeId, module); + } GenericValue product = null; List<GenericValue> productsFound = null; @@ -894,10 +898,15 @@ public final class ProductWorker { } if (product != null) { - if (UtilValidate.isNotEmpty(productsFound)) productsFound.add(product); - else productsFound = UtilMisc.toList(product); + if (UtilValidate.isNotEmpty(productsFound)) { + productsFound.add(product); + } else { + productsFound = UtilMisc.toList(product); + } + } + if (Debug.verboseOn()) { + Debug.logVerbose("Analyze goodIdentification: found product.productId = " + product + ", and list : " + productsFound, module); } - if (Debug.verboseOn()) Debug.logVerbose("Analyze goodIdentification: found product.productId = " + product + ", and list : " + productsFound, module); return productsFound; } @@ -981,7 +990,7 @@ public final class ProductWorker { } public static Set<String> getRefurbishedProductIdSet(String productId, Delegator delegator) throws GenericEntityException { - Set<String> productIdSet = new HashSet<String>(); + Set<String> productIdSet = new HashSet<>(); // find associated refurb items, we want serial number for main item or any refurb items too List<GenericValue> refubProductAssocs = EntityQuery.use(delegator).from("ProductAssoc").where("productId", productId, "productAssocTypeId", "PRODUCT_REFURB").filterByDate().queryList(); @@ -1139,13 +1148,13 @@ nextProd: return variantProductId; } - + public static boolean isAlternativePacking(Delegator delegator, String productId, String virtualVariantId) { boolean isAlternativePacking = false; if(productId != null || virtualVariantId != null){ List<GenericValue> alternativePackingProds = null; try { - List<EntityCondition> condList = new LinkedList<EntityCondition>(); + List<EntityCondition> condList = new LinkedList<>(); if (UtilValidate.isNotEmpty(productId)) { condList.add(EntityCondition.makeCondition("productIdTo", productId)); @@ -1155,14 +1164,16 @@ nextProd: } condList.add(EntityCondition.makeCondition("productAssocTypeId", "ALTERNATIVE_PACKAGE")); alternativePackingProds = EntityQuery.use(delegator).from("ProductAssoc").where(condList).cache(true).queryList(); - if(UtilValidate.isNotEmpty(alternativePackingProds)) isAlternativePacking = true; + if(UtilValidate.isNotEmpty(alternativePackingProds)) { + isAlternativePacking = true; + } } catch (GenericEntityException e) { Debug.logWarning(e, "Could not found alternative product: " + e.getMessage(), module); } } return isAlternativePacking; } - + public static String getOriginalProductId(Delegator delegator, String productId){ boolean isAlternativePacking = isAlternativePacking(delegator, null, productId); if (isAlternativePacking) { @@ -1172,17 +1183,15 @@ nextProd: } catch (GenericEntityException e) { Debug.logError(e, module); } - + if (productAssocs != null) { GenericValue productAssoc = EntityUtil.getFirst(productAssocs); return productAssoc.getString("productIdTo"); - } else { - return null; } - }else{ return null; } - + return null; + } /** * worker to test if product can be order with a decimal quantity @@ -1199,7 +1208,7 @@ nextProd: } String allowDecimalStore = EntityQuery.use(delegator).from("ProductStore").where("productStoreId", productStoreId).cache(true).queryOne().getString("orderDecimalQuantity"); String allowDecimalProduct = EntityQuery.use(delegator).from("Product").where("productId", productId).cache(true).queryOne().getString("orderDecimalQuantity"); - + if("N".equals(allowDecimalProduct) || (UtilValidate.isEmpty(allowDecimalProduct) && "N".equals(allowDecimalStore))){ return Boolean.FALSE; } @@ -1219,23 +1228,23 @@ nextProd: return false; } - // Method to filter-out out of stock products + // Method to filter-out out of stock products public static List<GenericValue> filterOutOfStockProducts (List<GenericValue> productsToFilter, LocalDispatcher dispatcher, Delegator delegator) throws GeneralException { - List<GenericValue> productsInStock = new ArrayList<GenericValue>(); + List<GenericValue> productsInStock = new ArrayList<>(); if (UtilValidate.isNotEmpty(productsToFilter)) { for (GenericValue genericRecord : productsToFilter) { String productId = genericRecord.getString("productId"); GenericValue product = null; product = EntityQuery.use(delegator).from("Product").where("productId", productId).cache(true).queryOne(); Boolean isMarketingPackage = EntityTypeUtil.hasParentType(delegator, "ProductType", "productTypeId", product.getString("productTypeId"), "parentTypeId", "MARKETING_PKG"); - + if ( UtilValidate.isNotEmpty(isMarketingPackage) && isMarketingPackage) { - Map<String, Object> resultOutput = new HashMap<String, Object>(); + Map<String, Object> resultOutput = new HashMap<>(); resultOutput = dispatcher.runSync("getMktgPackagesAvailable", UtilMisc.toMap("productId" ,productId)); Debug.logWarning("Error getting available marketing package.", module); - + BigDecimal availableInventory = (BigDecimal) resultOutput.get("availableToPromiseTotal"); - if(availableInventory.compareTo(BigDecimal.ZERO) > 0) { + if(availableInventory.compareTo(BigDecimal.ZERO) > 0) { productsInStock.add(genericRecord); } } else { |
Free forum by Nabble | Edit this page |