Author: mbrohl
Date: Sat Dec 9 18:08:26 2017 New Revision: 1817650 URL: http://svn.apache.org/viewvc?rev=1817650&view=rev Log: Improved: Fixing defects reported by FindBugs, package org.apache.ofbiz.product.product. (OFBIZ-9807) Thanks Julian Leichert for reporting and providing the patch. Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/KeywordIndex.java ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductContentWrapper.java ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductEvents.java ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductPromoContentWrapper.java ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearch.java ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductServices.java Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/KeywordIndex.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/KeywordIndex.java?rev=1817650&r1=1817649&r2=1817650&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/KeywordIndex.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/KeywordIndex.java Sat Dec 9 18:08:26 2017 @@ -22,6 +22,7 @@ import java.io.IOException; import java.sql.Timestamp; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TreeMap; @@ -92,7 +93,7 @@ public class KeywordIndex { } catch (Exception e) { Debug.logWarning("Could not parse weight number: " + e.toString(), module); } - keywords.put(product.getString("productId").toLowerCase(), Long.valueOf(pidWeight)); + keywords.put(product.getString("productId").toLowerCase(Locale.getDefault()), Long.valueOf(pidWeight)); // Product fields - default is 0 if not found in the properties file if (!"0".equals(EntityUtilProperties.getPropertyValue("prodsearch", "index.weight.Product.productName", "0", delegator))) { @@ -227,7 +228,6 @@ public class KeywordIndex { int weight = 1; try { - Delegator delegator = value.getDelegator(); weight = EntityUtilProperties.getPropertyAsInteger("prodsearch", "index.weight." + value.getEntityName() + "." + fieldName, 1).intValue(); } catch (Exception e) { Debug.logWarning("Could not parse weight number: " + e.toString(), module); Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductContentWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductContentWrapper.java?rev=1817650&r1=1817649&r2=1817650&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductContentWrapper.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductContentWrapper.java Sat Dec 9 18:08:26 2017 @@ -124,9 +124,7 @@ public class ProductContentWrapper imple outString = outString == null? "" : outString; } outString = encoder.sanitize(outString, null); - if (productContentCache != null) { - productContentCache.put(cacheKey, outString); - } + productContentCache.put(cacheKey, outString); return outString; } catch (GeneralException e) { Debug.logError(e, "Error rendering ProductContent, inserting empty String", module); Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductEvents.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductEvents.java?rev=1817650&r1=1817649&r2=1817650&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductEvents.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductEvents.java Sat Dec 9 18:08:26 2017 @@ -669,7 +669,7 @@ public class ProductEvents { // remove productFeatureAppl IFF: productFeatureAppl != null && (description is empty/null || description is different than existing) if (productFeatureAppl != null && (description == null || !description.equals(productFeatureAndAppl.getString("description")))) { // if descriptionsToRemove is not null, only remove if description is in that set - if (descriptionsToRemove == null || (descriptionsToRemove != null && descriptionsToRemove.contains(productFeatureAndAppl.getString("description")))) { + if (descriptionsToRemove == null || descriptionsToRemove.contains(productFeatureAndAppl.getString("description"))) { // okay, almost there: before removing it if this is a virtual product check to make SURE this feature's description doesn't exist on any of the variants; wouldn't want to remove something we should have kept around... if ("Y".equals(product.getString("isVirtual"))) { boolean foundFeatureOnVariant = false; @@ -706,7 +706,7 @@ public class ProductEvents { } } - if (description != null && (productFeatureAndAppl == null || (productFeatureAndAppl != null && !descriptionsForThisType.contains(description)))) { + if (description != null && (productFeatureAndAppl == null || !descriptionsForThisType.contains(description))) { // need to add an appl, and possibly the feature // see if a feature exists with the type and description specified (if doesn't exist will create later) Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductPromoContentWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductPromoContentWrapper.java?rev=1817650&r1=1817649&r2=1817650&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductPromoContentWrapper.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductPromoContentWrapper.java Sat Dec 9 18:08:26 2017 @@ -129,9 +129,7 @@ public class ProductPromoContentWrapper outString = outString == null? "" : outString; } outString = encoder.sanitize(outString, null); - if (productPromoContentCache != null) { - productPromoContentCache.put(cacheKey, outString); - } + productPromoContentCache.put(cacheKey, outString); return outString; } catch (GeneralException e) { Debug.logError(e, "Error rendering ProductPromoContent, inserting empty String", module); Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearch.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearch.java?rev=1817650&r1=1817649&r2=1817650&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearch.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearch.java Sat Dec 9 18:08:26 2017 @@ -880,24 +880,43 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((prodCatalogId == null) ? 0 : prodCatalogId.hashCode()); + result = prime * result + ((productCategories == null) ? 0 : productCategories.hashCode()); + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof CatalogConstraint) { - CatalogConstraint that = (CatalogConstraint) psc; - if (this.prodCatalogId == null) { - if (that.prodCatalogId != null) { - return false; - } - } else { - if (!this.prodCatalogId.equals(that.prodCatalogId)) { - return false; - } - } + if (this == obj) { return true; - } else { + } + if (obj == null) { + return false; + } + if (!(obj instanceof CatalogConstraint)) { + return false; + } + CatalogConstraint other = (CatalogConstraint) obj; + if (prodCatalogId == null) { + if (other.prodCatalogId != null) { + return false; + } + } else if (!prodCatalogId.equals(other.prodCatalogId)) { + return false; + } + if (productCategories == null) { + if (other.productCategories != null) { + return false; + } + } else if (!productCategories.equals(other.productCategories)) { return false; } + return true; } + } @SuppressWarnings("serial") @@ -973,27 +992,47 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((exclude == null) ? 0 : exclude.hashCode()); + result = prime * result + (includeSubCategories ? 1231 : 1237); + result = prime * result + ((productCategoryId == null) ? 0 : productCategoryId.hashCode()); + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof CategoryConstraint) { - CategoryConstraint that = (CategoryConstraint) psc; - if (this.includeSubCategories != that.includeSubCategories) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof CategoryConstraint)) { + return false; + } + CategoryConstraint other = (CategoryConstraint) obj; + if (exclude == null) { + if (other.exclude != null) { return false; } - if (this.productCategoryId == null) { - if (that.productCategoryId != null) { - return false; - } - } else { - if (!this.productCategoryId.equals(that.productCategoryId)) { - return false; - } + } else if (!exclude.equals(other.exclude)) { + return false; + } + if (includeSubCategories != other.includeSubCategories) { + return false; + } + if (productCategoryId == null) { + if (other.productCategoryId != null) { + return false; } - return true; - } else { + } else if (!productCategoryId.equals(other.productCategoryId)) { return false; } + return true; } + } @SuppressWarnings("serial") @@ -1058,24 +1097,43 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((exclude == null) ? 0 : exclude.hashCode()); + result = prime * result + ((productFeatureId == null) ? 0 : productFeatureId.hashCode()); + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof FeatureConstraint) { - FeatureConstraint that = (FeatureConstraint) psc; - if (this.productFeatureId == null) { - if (that.productFeatureId != null) { - return false; - } - } else { - if (!this.productFeatureId.equals(that.productFeatureId)) { - return false; - } - } + if (this == obj) { return true; - } else { + } + if (obj == null) { return false; } + if (!(obj instanceof FeatureConstraint)) { + return false; + } + FeatureConstraint other = (FeatureConstraint) obj; + if (exclude == null) { + if (other.exclude != null) { + return false; + } + } else if (!exclude.equals(other.exclude)) { + return false; + } + if (productFeatureId == null) { + if (other.productFeatureId != null) { + return false; + } + } else if (!productFeatureId.equals(other.productFeatureId)) { + return false; + } + return true; } + } @@ -1140,24 +1198,43 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((exclude == null) ? 0 : exclude.hashCode()); + result = prime * result + ((productFeatureCategoryId == null) ? 0 : productFeatureCategoryId.hashCode()); + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof FeatureCategoryConstraint) { - FeatureCategoryConstraint that = (FeatureCategoryConstraint) psc; - if (this.productFeatureCategoryId == null) { - if (that.productFeatureCategoryId != null) { - return false; - } - } else { - if (!this.productFeatureCategoryId.equals(that.productFeatureCategoryId)) { - return false; - } - } + if (this == obj) { return true; - } else { + } + if (obj == null) { return false; } + if (!(obj instanceof FeatureCategoryConstraint)) { + return false; + } + FeatureCategoryConstraint other = (FeatureCategoryConstraint) obj; + if (exclude == null) { + if (other.exclude != null) { + return false; + } + } else if (!exclude.equals(other.exclude)) { + return false; + } + if (productFeatureCategoryId == null) { + if (other.productFeatureCategoryId != null) { + return false; + } + } else if (!productFeatureCategoryId.equals(other.productFeatureCategoryId)) { + return false; + } + return true; } + } @SuppressWarnings("serial") @@ -1220,24 +1297,43 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((exclude == null) ? 0 : exclude.hashCode()); + result = prime * result + ((productFeatureGroupId == null) ? 0 : productFeatureGroupId.hashCode()); + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof FeatureGroupConstraint) { - FeatureGroupConstraint that = (FeatureGroupConstraint) psc; - if (this.productFeatureGroupId == null) { - if (that.productFeatureGroupId != null) { - return false; - } - } else { - if (!this.productFeatureGroupId.equals(that.productFeatureGroupId)) { - return false; - } - } + if (this == obj) { return true; - } else { + } + if (obj == null) { + return false; + } + if (!(obj instanceof FeatureGroupConstraint)) { return false; } + FeatureGroupConstraint other = (FeatureGroupConstraint) obj; + if (exclude == null) { + if (other.exclude != null) { + return false; + } + } else if (!exclude.equals(other.exclude)) { + return false; + } + if (productFeatureGroupId == null) { + if (other.productFeatureGroupId != null) { + return false; + } + } else if (!productFeatureGroupId.equals(other.productFeatureGroupId)) { + return false; + } + return true; } + } @@ -1315,24 +1411,43 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((exclude == null) ? 0 : exclude.hashCode()); + result = prime * result + ((productFeatureIdSet == null) ? 0 : productFeatureIdSet.hashCode()); + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof FeatureSetConstraint) { - FeatureSetConstraint that = (FeatureSetConstraint) psc; - if (this.productFeatureIdSet == null) { - if (that.productFeatureIdSet != null) { - return false; - } - } else { - if (!this.productFeatureIdSet.equals(that.productFeatureIdSet)) { - return false; - } - } + if (this == obj) { return true; - } else { + } + if (obj == null) { + return false; + } + if (!(obj instanceof FeatureSetConstraint)) { + return false; + } + FeatureSetConstraint other = (FeatureSetConstraint) obj; + if (exclude == null) { + if (other.exclude != null) { + return false; + } + } else if (!exclude.equals(other.exclude)) { + return false; + } + if (productFeatureIdSet == null) { + if (other.productFeatureIdSet != null) { + return false; + } + } else if (!productFeatureIdSet.equals(other.productFeatureIdSet)) { return false; } + return true; } + } @SuppressWarnings("serial") @@ -1424,36 +1539,51 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (anyPrefix ? 1231 : 1237); + result = prime * result + (anySuffix ? 1231 : 1237); + result = prime * result + (isAnd ? 1231 : 1237); + result = prime * result + ((keywordsString == null) ? 0 : keywordsString.hashCode()); + result = prime * result + (removeStems ? 1231 : 1237); + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof KeywordConstraint) { - KeywordConstraint that = (KeywordConstraint) psc; - if (this.anyPrefix != that.anyPrefix) { - return false; - } - if (this.anySuffix != that.anySuffix) { - return false; - } - if (this.isAnd != that.isAnd) { - return false; - } - if (this.removeStems != that.removeStems) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof KeywordConstraint)) { + return false; + } + KeywordConstraint other = (KeywordConstraint) obj; + if (anyPrefix != other.anyPrefix) { + return false; + } + if (anySuffix != other.anySuffix) { + return false; + } + if (isAnd != other.isAnd) { + return false; + } + if (keywordsString == null) { + if (other.keywordsString != null) { return false; } - if (this.keywordsString == null) { - if (that.keywordsString != null) { - return false; - } - } else { - if (!this.keywordsString.equals(that.keywordsString)) { - return false; - } - } - return true; - } else { + } else if (!keywordsString.equals(other.keywordsString)) { return false; } + if (removeStems != other.removeStems) { + return false; + } + return true; } + } @SuppressWarnings("serial") @@ -1480,33 +1610,43 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((fromDate == null) ? 0 : fromDate.hashCode()); + result = prime * result + ((thruDate == null) ? 0 : thruDate.hashCode()); + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof LastUpdatedRangeConstraint) { - LastUpdatedRangeConstraint that = (LastUpdatedRangeConstraint) psc; - if (this.fromDate == null) { - if (that.fromDate != null) { - return false; - } - } else { - if (!this.fromDate.equals(that.fromDate)) { - return false; - } + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof LastUpdatedRangeConstraint)) { + return false; + } + LastUpdatedRangeConstraint other = (LastUpdatedRangeConstraint) obj; + if (fromDate == null) { + if (other.fromDate != null) { + return false; } - if (this.thruDate == null) { - if (that.thruDate != null) { - return false; - } - } else { - if (!this.thruDate.equals(that.thruDate)) { - return false; - } + } else if (!fromDate.equals(other.fromDate)) { + return false; + } + if (thruDate == null) { + if (other.thruDate != null) { + return false; } - return true; - } else { + } else if (!thruDate.equals(other.thruDate)) { return false; } + return true; } + } @SuppressWarnings("serial") @@ -1556,17 +1696,51 @@ public class ProductSearch { } @Override - public boolean equals(Object o) { - if (o instanceof StoreGroupPriceConstraint) { - StoreGroupPriceConstraint other = (StoreGroupPriceConstraint) o; - if (other.productStoreGroupId.equals(productStoreGroupId) && - other.productPriceTypeId.equals(productPriceTypeId) && - other.currencyUomId.equals(currencyUomId)) { - return true; + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((currencyUomId == null) ? 0 : currencyUomId.hashCode()); + result = prime * result + ((productPriceTypeId == null) ? 0 : productPriceTypeId.hashCode()); + result = prime * result + ((productStoreGroupId == null) ? 0 : productStoreGroupId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof StoreGroupPriceConstraint)) { + return false; + } + StoreGroupPriceConstraint other = (StoreGroupPriceConstraint) obj; + if (currencyUomId == null) { + if (other.currencyUomId != null) { + return false; } + } else if (!currencyUomId.equals(other.currencyUomId)) { + return false; } - return false; + if (productPriceTypeId == null) { + if (other.productPriceTypeId != null) { + return false; + } + } else if (!productPriceTypeId.equals(other.productPriceTypeId)) { + return false; + } + if (productStoreGroupId == null) { + if (other.productStoreGroupId != null) { + return false; + } + } else if (!productStoreGroupId.equals(other.productStoreGroupId)) { + return false; + } + return true; } + } @SuppressWarnings("serial") @@ -1647,33 +1821,51 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((currencyUomId == null) ? 0 : currencyUomId.hashCode()); + result = prime * result + ((highPrice == null) ? 0 : highPrice.hashCode()); + result = prime * result + ((lowPrice == null) ? 0 : lowPrice.hashCode()); + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof ListPriceRangeConstraint) { - ListPriceRangeConstraint that = (ListPriceRangeConstraint) psc; - if (this.lowPrice == null) { - if (that.lowPrice != null) { - return false; - } - } else { - if (this.lowPrice.compareTo(that.lowPrice) != 0) { - return false; - } + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof ListPriceRangeConstraint)) { + return false; + } + ListPriceRangeConstraint other = (ListPriceRangeConstraint) obj; + if (currencyUomId == null) { + if (other.currencyUomId != null) { + return false; } - if (this.highPrice == null) { - if (that.highPrice != null) { - return false; - } - } else { - if (this.highPrice.compareTo(that.highPrice) != 0) { - return false; - } + } else if (!currencyUomId.equals(other.currencyUomId)) { + return false; + } + if (highPrice == null) { + if (other.highPrice != null) { + return false; } - return true; - } else { + } else if (!highPrice.equals(other.highPrice)) { + return false; + } + if (lowPrice == null) { + if (other.lowPrice != null) { + return false; + } + } else if (!lowPrice.equals(other.lowPrice)) { return false; } + return true; } + } @SuppressWarnings("serial") @@ -1707,24 +1899,35 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((supplierPartyId == null) ? 0 : supplierPartyId.hashCode()); + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof SupplierConstraint) { - SupplierConstraint that = (SupplierConstraint) psc; - if (this.supplierPartyId == null) { - if (that.supplierPartyId != null) { - return false; - } - } else { - if (!this.supplierPartyId.equals(that.supplierPartyId)) { - return false; - } - } + if (this == obj) { return true; - } else { + } + if (obj == null) { return false; } + if (!(obj instanceof SupplierConstraint)) { + return false; + } + SupplierConstraint other = (SupplierConstraint) obj; + if (supplierPartyId == null) { + if (other.supplierPartyId != null) { + return false; + } + } else if (!supplierPartyId.equals(other.supplierPartyId)) { + return false; + } + return true; } + } @SuppressWarnings("serial") @@ -1749,13 +1952,25 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result; + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof ExcludeVariantsConstraint) { + if (this == obj) { return true; - } else { + } + if (obj == null) { + return false; + } + if (!(obj instanceof ExcludeVariantsConstraint)) { return false; } + return true; } } @@ -1781,13 +1996,25 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result; + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof AvailabilityDateConstraint) { + if (this == obj) { return true; - } else { + } + if (obj == null) { + return false; + } + if (!(obj instanceof AvailabilityDateConstraint)) { return false; } + return true; } } @@ -1818,7 +2045,7 @@ public class ProductSearch { EntityComparisonOperator<?,?> operator = EntityOperator.EQUALS; - if (UtilValidate.isNotEmpty(include) && include == Boolean.FALSE) { + if (UtilValidate.isNotEmpty(include) && !include) { operator = EntityOperator.NOT_EQUAL; } @@ -1851,7 +2078,7 @@ public class ProductSearch { StringBuilder msgBuf = new StringBuilder(); - if (UtilValidate.isNotEmpty(include) && include == Boolean.FALSE) { + if (UtilValidate.isNotEmpty(include) && !include) { msgBuf.append(UtilProperties.getMessage(resourceCommon, "CommonExclude", locale)); msgBuf.append(" "); } else { @@ -1875,13 +2102,25 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result; + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof GoodIdentificationConstraint) { + if (this == obj) { return true; - } else { + } + if(obj == null) { return false; } + if (!(obj instanceof GoodIdentificationConstraint)) { + return false; + } + return true; } } @@ -1909,24 +2148,43 @@ public class ProductSearch { } @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((keyword == null) ? 0 : keyword.hashCode()); + result = prime * result + ((productFieldName == null) ? 0 : productFieldName.hashCode()); + return result; + } + + @Override public boolean equals(Object obj) { - ProductSearchConstraint psc = (ProductSearchConstraint) obj; - if (psc instanceof ProductFieldConstraint) { - ProductFieldConstraint that = (ProductFieldConstraint) psc; - if (this.keyword == null) { - if (that.keyword != null) { - return false; - } - } else { - if (!this.keyword.equals(that.keyword)) { - return false; - } - } + if (this == obj) { return true; - } else { + } + if (obj == null) { + return false; + } + if (!(obj instanceof ProductFieldConstraint)) { return false; } + ProductFieldConstraint other = (ProductFieldConstraint) obj; + if (keyword == null) { + if (other.keyword != null) { + return false; + } + } else if (!keyword.equals(other.keyword)) { + return false; + } + if (productFieldName == null) { + if (other.productFieldName != null) { + return false; + } + } else if (!productFieldName.equals(other.productFieldName)) { + return false; + } + return true; } + } // ====================================================================== Modified: ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java?rev=1817650&r1=1817649&r2=1817650&view=diff ============================================================================== --- ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java (original) +++ ofbiz/ofbiz-framework/trunk/applications/product/src/main/java/org/apache/ofbiz/product/product/ProductSearchSession.java Sat Dec 9 18:08:26 2017 @@ -29,6 +29,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import javax.servlet.ServletContext; @@ -472,7 +473,6 @@ public class ProductSearchSession { public static String searchGetSortOrderString(boolean detailed, HttpServletRequest request) { Locale locale = UtilHttp.getLocale(request); ResultSortOrder resultSortOrder = ProductSearchOptions.getResultSortOrder(request); - if (resultSortOrder == null) return ""; return resultSortOrder.prettyPrintSortOrder(detailed, locale); } @@ -633,7 +633,8 @@ public class ProductSearchSession { } } - for (String parameterName: parameters.keySet()) { + for (Entry<String, Object> entry : parameters.entrySet()) { + String parameterName = entry.getKey(); if (parameterName.startsWith("SEARCH_FEAT") && !parameterName.startsWith("SEARCH_FEAT_EXC")) { String productFeatureId = (String) parameters.get(parameterName); if (UtilValidate.isNotEmpty(productFeatureId)) { @@ -744,12 +745,12 @@ public class ProductSearchSession { if (UtilValidate.isNotEmpty(parameters.get("LIST_PRICE_RANGE")) || UtilValidate.isNotEmpty(parameters.get("S_LPR"))) { String listPriceRangeStr = (String) parameters.get("LIST_PRICE_RANGE"); if (UtilValidate.isEmpty(listPriceRangeStr)) listPriceRangeStr = (String) parameters.get("S_LPR"); - int underscoreIndex = listPriceRangeStr.indexOf("_"); + int underscoreIndex = listPriceRangeStr.indexOf('_'); String listPriceLowStr; String listPriceHighStr; if (underscoreIndex >= 0) { - listPriceLowStr = listPriceRangeStr.substring(0, listPriceRangeStr.indexOf("_")); - listPriceHighStr = listPriceRangeStr.substring(listPriceRangeStr.indexOf("_") + 1); + listPriceLowStr = listPriceRangeStr.substring(0, listPriceRangeStr.indexOf('_')); + listPriceHighStr = listPriceRangeStr.substring(listPriceRangeStr.indexOf('_') + 1); } else { // no underscore: assume it is a low range with no high range, ie the ending underscore was left off listPriceLowStr = listPriceRangeStr; @@ -894,9 +895,7 @@ public class ProductSearchSession { } String pag = productSearchOptions.getPaging(); - if (paging != null) { - paging = pag; - } + paging = pag; lowIndex = viewIndex * viewSize; highIndex = (viewIndex + 1) * viewSize; @@ -916,7 +915,7 @@ public class ProductSearchSession { int addOnTopTotalListSize = 0; int addOnTopListSize = 0; - List<GenericValue> addOnTopProductCategoryMembers = new LinkedList<GenericValue>(); + List<GenericValue> addOnTopProductCategoryMembers; if (UtilValidate.isNotEmpty(addOnTopProdCategoryId)) { // always include the members of the addOnTopProdCategoryId Timestamp now = UtilDateTime.nowTimestamp(); @@ -1161,25 +1160,23 @@ public class ProductSearchSession { searchParamString.append(topProductCategoryId); } ResultSortOrder resultSortOrder = productSearchOptions.getResultSortOrder(); - if (resultSortOrder != null) { - if (resultSortOrder instanceof ProductSearch.SortKeywordRelevancy) { - searchParamString.append("&S_O=SKR"); - } else if (resultSortOrder instanceof ProductSearch.SortProductField) { - ProductSearch.SortProductField spf = (ProductSearch.SortProductField) resultSortOrder; - searchParamString.append("&S_O=SPF:"); - searchParamString.append(spf.fieldName); - } else if (resultSortOrder instanceof ProductSearch.SortProductPrice) { - ProductSearch.SortProductPrice spp = (ProductSearch.SortProductPrice) resultSortOrder; - searchParamString.append("&S_O=SPP:"); - searchParamString.append(spp.productPriceTypeId); - } else if (resultSortOrder instanceof ProductSearch.SortProductFeature) { - ProductSearch.SortProductFeature spf = (ProductSearch.SortProductFeature) resultSortOrder; - searchParamString.append("&S_O=SPFT:"); - searchParamString.append(spf.productFeatureTypeId); - } - searchParamString.append("&S_A="); - searchParamString.append(resultSortOrder.isAscending() ? "Y" : "N"); + if (resultSortOrder instanceof ProductSearch.SortKeywordRelevancy) { + searchParamString.append("&S_O=SKR"); + } else if (resultSortOrder instanceof ProductSearch.SortProductField) { + ProductSearch.SortProductField spf = (ProductSearch.SortProductField) resultSortOrder; + searchParamString.append("&S_O=SPF:"); + searchParamString.append(spf.fieldName); + } else if (resultSortOrder instanceof ProductSearch.SortProductPrice) { + ProductSearch.SortProductPrice spp = (ProductSearch.SortProductPrice) resultSortOrder; + searchParamString.append("&S_O=SPP:"); + searchParamString.append(spp.productPriceTypeId); + } else if (resultSortOrder instanceof ProductSearch.SortProductFeature) { + ProductSearch.SortProductFeature spf = (ProductSearch.SortProductFeature) resultSortOrder; + searchParamString.append("&S_O=SPFT:"); + searchParamString.append(spf.productFeatureTypeId); } + searchParamString.append("&S_A="); + searchParamString.append(resultSortOrder.isAscending() ? "Y" : "N"); return searchParamString.toString(); } 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=1817650&r1=1817649&r2=1817650&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 9 18:08:26 2017 @@ -34,6 +34,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import org.apache.ofbiz.base.util.Debug; @@ -420,9 +421,9 @@ public class ProductServices { boolean checkViewAllow = (cvaBool == null ? false : cvaBool); String prodCatalogId = (String) context.get("prodCatalogId"); Boolean bidirectional = (Boolean) context.get("bidirectional"); - bidirectional = bidirectional == null ? false : bidirectional; + bidirectional = bidirectional == null ? Boolean.FALSE : bidirectional; Boolean sortDescending = (Boolean) context.get("sortDescending"); - sortDescending = sortDescending == null ? false : sortDescending; + sortDescending = sortDescending == null ? Boolean.FALSE : sortDescending; if (productId == null && productIdTo == null) { errMsg = UtilProperties.getMessage(resourceError, @@ -597,7 +598,8 @@ public class ProductServices { } // loop through the keysets and get the sub-groups - for (String key: group.keySet()) { + for (Entry<String, Object> entry : group.entrySet()) { + String key = entry.getKey(); List<String> itemList = UtilGenerics.checkList(group.get(key)); if (UtilValidate.isNotEmpty(itemList)) { @@ -961,12 +963,12 @@ public class ProductServices { String fileLocation = filenameExpander.expandString(UtilMisc.toMap("location", "products", "id", id, "viewtype", viewType, "sizetype", "original")); String filePathPrefix = ""; String filenameToUse = fileLocation; - if (fileLocation.lastIndexOf("/") != -1) { - filePathPrefix = fileLocation.substring(0, fileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash - filenameToUse = fileLocation.substring(fileLocation.lastIndexOf("/") + 1); + if (fileLocation.lastIndexOf('/') != -1) { + filePathPrefix = fileLocation.substring(0, fileLocation.lastIndexOf('/') + 1); // adding 1 to include the trailing slash + filenameToUse = fileLocation.substring(fileLocation.lastIndexOf('/') + 1); } - List<GenericValue> fileExtension = new LinkedList<GenericValue>(); + List<GenericValue> fileExtension; try { fileExtension = EntityQuery.use(delegator).from("FileExtension").where("mimeTypeId", (String) context.get("_uploadedFile_contentType")).queryList(); } catch (GenericEntityException e) { @@ -997,7 +999,12 @@ public class ProductServices { try { File[] files = targetDir.listFiles(); for (File file : files) { - if (file.isFile()) file.delete(); + if (file.isFile()) { + if (!file.delete()) { + Debug.logError("File : " + file.getName() + ", couldn't be deleted", module); + } + } + } } catch (SecurityException e) { Debug.logError(e,module); @@ -1007,7 +1014,11 @@ public class ProductServices { try { File[] files = targetDir.listFiles(); for (File file : files) { - if (file.isFile() && file.getName().startsWith(productId + "_View_" + viewNumber)) file.delete(); + if (file.isFile() && file.getName().startsWith(productId + "_View_" + viewNumber)) { + if (!file.delete()) { + Debug.logError("File : " + file.getName() + ", couldn't be deleted", module); + } + } } } catch (SecurityException e) { Debug.logError(e,module); @@ -1065,9 +1076,9 @@ public class ProductServices { imageUrl = imageUrlMap.get(sizeType); if( UtilValidate.isNotEmpty(imageUrl)) { try { - GenericValue productContentType = EntityQuery.use(delegator).from("ProductContentType").where("productContentTypeId", "XTRA_IMG_" + viewNumber + "_" + sizeType.toUpperCase()).cache().queryOne(); + GenericValue productContentType = EntityQuery.use(delegator).from("ProductContentType").where("productContentTypeId", "XTRA_IMG_" + viewNumber + "_" + sizeType.toUpperCase(Locale.getDefault())).cache().queryOne(); if (UtilValidate.isNotEmpty(productContentType)) { - result = addImageResource(dispatcher, delegator, context, imageUrl, "XTRA_IMG_" + viewNumber + "_" + sizeType.toUpperCase()); + result = addImageResource(dispatcher, delegator, context, imageUrl, "XTRA_IMG_" + viewNumber + "_" + sizeType.toUpperCase(Locale.getDefault())); if( ServiceUtil.isError(result)) { Debug.logError(ServiceUtil.getErrorMessage(result), module); return result; @@ -1132,7 +1143,7 @@ public class ProductServices { } else { dataResourceCtx.put("dataResourceTypeId", "SHORT_TEXT"); dataResourceCtx.put("mimeTypeId", "text/html"); - Map<String, Object> dataResourceResult = new HashMap<String, Object>(); + Map<String, Object> dataResourceResult; try { dataResourceResult = dispatcher.runSync("createDataResource", dataResourceCtx); } catch (GenericServiceException e) { @@ -1163,7 +1174,7 @@ public class ProductServices { } else { dataResourceCtx.put("dataResourceTypeId", "SHORT_TEXT"); dataResourceCtx.put("mimeTypeId", "text/html"); - Map<String, Object> dataResourceResult = new HashMap<String, Object>(); + Map<String, Object> dataResourceResult; try { dataResourceResult = dispatcher.runSync("createDataResource", dataResourceCtx); } catch (GenericServiceException e) { @@ -1175,7 +1186,7 @@ public class ProductServices { contentCtx.put("contentTypeId", "DOCUMENT"); contentCtx.put("dataResourceId", dataResourceResult.get("dataResourceId")); contentCtx.put("userLogin", userLogin); - Map<String, Object> contentResult = new HashMap<String, Object>(); + Map<String, Object> contentResult; try { contentResult = dispatcher.runSync("createContent", contentCtx); } catch (GenericServiceException e) { @@ -1260,12 +1271,13 @@ public class ProductServices { String fileLocation = filenameExpander.expandString(UtilMisc.toMap("location", "products", "type", "promo", "id", id)); String filePathPrefix = ""; String filenameToUse = fileLocation; - if (fileLocation.lastIndexOf("/") != -1) { - filePathPrefix = fileLocation.substring(0, fileLocation.lastIndexOf("/") + 1); // adding 1 to include the trailing slash - filenameToUse = fileLocation.substring(fileLocation.lastIndexOf("/") + 1); + if (fileLocation.lastIndexOf('/') != -1) { + filePathPrefix = fileLocation.substring(0, fileLocation.lastIndexOf('/') + 1); // adding 1 to include + // the trailing slash + filenameToUse = fileLocation.substring(fileLocation.lastIndexOf('/') + 1); } - List<GenericValue> fileExtension = new LinkedList<GenericValue>(); + List<GenericValue> fileExtension; try { fileExtension = EntityQuery.use(delegator).from("FileExtension").where("mimeTypeId", EntityOperator.EQUALS, (String) context.get("_uploadedFile_contentType")).queryList(); } catch (GenericEntityException e) { @@ -1280,7 +1292,9 @@ public class ProductServices { File makeResourceDirectory = new File(imageServerPath + "/" + filePathPrefix); if (!makeResourceDirectory.exists()) { - makeResourceDirectory.mkdirs(); + if (!makeResourceDirectory.mkdirs()) { + Debug.logError("Directory :" + makeResourceDirectory.getPath() + ", couldn't be created", module); + } } File file = new File(imageServerPath + "/" + filePathPrefix + filenameToUse); @@ -1343,7 +1357,7 @@ public class ProductServices { } else { dataResourceCtx.put("dataResourceTypeId", "SHORT_TEXT"); dataResourceCtx.put("mimeTypeId", "text/html"); - Map<String, Object> dataResourceResult = new HashMap<String, Object>(); + Map<String, Object> dataResourceResult; try { dataResourceResult = dispatcher.runSync("createDataResource", dataResourceCtx); } catch (GenericServiceException e) { @@ -1374,7 +1388,7 @@ public class ProductServices { } else { dataResourceCtx.put("dataResourceTypeId", "SHORT_TEXT"); dataResourceCtx.put("mimeTypeId", "text/html"); - Map<String, Object> dataResourceResult = new HashMap<String, Object>(); + Map<String, Object> dataResourceResult; try { dataResourceResult = dispatcher.runSync("createDataResource", dataResourceCtx); } catch (GenericServiceException e) { @@ -1386,7 +1400,7 @@ public class ProductServices { contentCtx.put("contentTypeId", "DOCUMENT"); contentCtx.put("dataResourceId", dataResourceResult.get("dataResourceId")); contentCtx.put("userLogin", userLogin); - Map<String, Object> contentResult = new HashMap<String, Object>(); + Map<String, Object> contentResult; try { contentResult = dispatcher.runSync("createContent", contentCtx); } catch (GenericServiceException e) { |
Free forum by Nabble | Edit this page |