Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java?rev=757089&r1=757088&r2=757089&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/price/PriceServices.java Sat Mar 21 23:44:24 2009 @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -55,8 +55,8 @@ public class PriceServices { public static final String module = PriceServices.class.getName(); - public static final BigDecimal ONE_BASE = BigDecimal.ONE; - public static final BigDecimal PERCENT_SCALE = new BigDecimal("100.000"); + public static final BigDecimal ONE_BASE = BigDecimal.ONE; + public static final BigDecimal PERCENT_SCALE = new BigDecimal("100.000"); public static final int taxCalcScale = UtilNumber.getBigDecimalScale("salestax.calc.decimals"); public static final int taxFinalScale = UtilNumber.getBigDecimalScale("salestax.final.decimals"); @@ -96,7 +96,7 @@ String checkIncludeVat = (String) context.get("checkIncludeVat"); String surveyResponseId = (String) context.get("surveyResponseId"); Map<String, Object> customAttributes = UtilGenerics.checkMap(context.get("customAttributes")); - + String findAllQuantityPricesStr = (String) context.get("findAllQuantityPrices"); boolean findAllQuantityPrices = "Y".equals(findAllQuantityPricesStr); @@ -139,7 +139,7 @@ productStoreGroupId = "_NA_"; } } - + // if currencyUomId is null get from properties file, if nothing there assume USD (USD: American Dollar) for now String currencyUomId = (String) context.get("currencyUomId"); if (UtilValidate.isEmpty(currencyUomId)) { @@ -151,7 +151,7 @@ if (UtilValidate.isEmpty(productPricePurposeId)) { productPricePurposeId = "PURCHASE"; } - + // termUomId, for things like recurring prices specifies the term (time/frequency measure for example) of the recurrence // if this is empty it will simply not be used to constrain the selection String termUomId = (String) context.get("termUomId"); @@ -199,11 +199,11 @@ List<EntityCondition> productPriceEcList = FastList.newInstance(); productPriceEcList.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, productId)); - // this funny statement is for backward compatibility purposes; the productPricePurposeId is a new pk field on the ProductPrice entity and in order databases may not be populated, until the pk is updated and such; this will ease the transition somewhat + // this funny statement is for backward compatibility purposes; the productPricePurposeId is a new pk field on the ProductPrice entity and in order databases may not be populated, until the pk is updated and such; this will ease the transition somewhat if ("PURCHASE".equals(productPricePurposeId)) { productPriceEcList.add(EntityCondition.makeCondition( - EntityCondition.makeCondition("productPricePurposeId", EntityOperator.EQUALS, productPricePurposeId), - EntityOperator.OR, + EntityCondition.makeCondition("productPricePurposeId", EntityOperator.EQUALS, productPricePurposeId), + EntityOperator.OR, EntityCondition.makeCondition("productPricePurposeId", EntityOperator.EQUALS, null))); } else { productPriceEcList.add(EntityCondition.makeCondition("productPricePurposeId", EntityOperator.EQUALS, productPricePurposeId)); @@ -238,7 +238,7 @@ } // If there is an agreement between the company and the client, and there is - // a price for the product in it, it will override the default price of the + // a price for the product in it, it will override the default price of the // ProductPrice entity. if (UtilValidate.isNotEmpty(agreementId)) { try { @@ -551,7 +551,7 @@ result.put("isSale", Boolean.FALSE); result.put("orderItemPriceInfos", orderItemPriceInfos); - Map<String, Object> errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, + Map<String, Object> errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher); if (errorResult != null) return errorResult; } else { @@ -566,7 +566,7 @@ nonQuantityProductPriceRules = FastList.newInstance(); for (GenericValue productPriceRule: allProductPriceRules) { List<GenericValue> productPriceCondList = delegator.findByAndCache("ProductPriceCond", UtilMisc.toMap("productPriceRuleId", productPriceRule.get("productPriceRuleId"))); - + boolean foundQuantityInputParam = false; // only consider a rule if all conditions except the quantity condition are true boolean allExceptQuantTrue = true; @@ -579,44 +579,44 @@ } } } - + if (foundQuantityInputParam && allExceptQuantTrue) { quantityProductPriceRules.add(productPriceRule); } else { nonQuantityProductPriceRules.add(productPriceRule); } - } + } } if (findAllQuantityPrices) { List<Map<String, Object>> allQuantityPrices = FastList.newInstance(); - + // if findAllQuantityPrices then iterate through quantityProductPriceRules // foreach create an entry in the out list and eval that rule and all nonQuantityProductPriceRules rather than a single rule for (GenericValue quantityProductPriceRule: quantityProductPriceRules) { List<GenericValue> ruleListToUse = FastList.newInstance(); ruleListToUse.add(quantityProductPriceRule); ruleListToUse.addAll(nonQuantityProductPriceRules); - - Map<String, Object> quantCalcResults = calcPriceResultFromRules(ruleListToUse, listPrice, defaultPrice, promoPrice, - wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, - averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, + + Map<String, Object> quantCalcResults = calcPriceResultFromRules(ruleListToUse, listPrice, defaultPrice, promoPrice, + wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, + averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, null, currencyUomId, delegator, nowTimestamp); - Map<String, Object> quantErrorResult = addGeneralResults(quantCalcResults, competitivePriceValue, specialPromoPriceValue, productStore, + Map<String, Object> quantErrorResult = addGeneralResults(quantCalcResults, competitivePriceValue, specialPromoPriceValue, productStore, checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher); if (quantErrorResult != null) return quantErrorResult; - + // also add the quantityProductPriceRule to the Map so it can be used for quantity break information quantCalcResults.put("quantityProductPriceRule", quantityProductPriceRule); - + allQuantityPrices.add(quantCalcResults); } result.put("allQuantityPrices", allQuantityPrices); // use a quantity 1 to get the main price, then fill in the quantity break prices - Map<String, Object> calcResults = calcPriceResultFromRules(allProductPriceRules, listPrice, defaultPrice, promoPrice, - wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, - averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, + Map<String, Object> calcResults = calcPriceResultFromRules(allProductPriceRules, listPrice, defaultPrice, promoPrice, + wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, + averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, BigDecimal.ONE, currencyUomId, delegator, nowTimestamp); result.putAll(calcResults); // The orderItemPriceInfos out parameter requires a special treatment: @@ -628,13 +628,13 @@ } result.put("orderItemPriceInfos", orderItemPriceInfos); - Map<String, Object> errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, + Map<String, Object> errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher); if (errorResult != null) return errorResult; } else { - Map<String, Object> calcResults = calcPriceResultFromRules(allProductPriceRules, listPrice, defaultPrice, promoPrice, - wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, - averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, + Map<String, Object> calcResults = calcPriceResultFromRules(allProductPriceRules, listPrice, defaultPrice, promoPrice, + wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound, + averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, quantity, currencyUomId, delegator, nowTimestamp); result.putAll(calcResults); // The orderItemPriceInfos out parameter requires a special treatment: @@ -646,7 +646,7 @@ } result.put("orderItemPriceInfos", orderItemPriceInfos); - Map<String, Object> errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, + Map<String, Object> errorResult = addGeneralResults(result, competitivePriceValue, specialPromoPriceValue, productStore, checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher); if (errorResult != null) return errorResult; } @@ -659,8 +659,8 @@ // utilTimer.timerString("Finished price calc [productId=" + productId + "]", module); return result; } - - public static Map<String, Object> addGeneralResults(Map<String, Object> result, GenericValue competitivePriceValue, GenericValue specialPromoPriceValue, GenericValue productStore, + + public static Map<String, Object> addGeneralResults(Map<String, Object> result, GenericValue competitivePriceValue, GenericValue specialPromoPriceValue, GenericValue productStore, String checkIncludeVat, String currencyUomId, String productId, BigDecimal quantity, String partyId, LocalDispatcher dispatcher) { result.put("competitivePrice", competitivePriceValue != null ? competitivePriceValue.getBigDecimal("price") : null); result.put("specialPromoPrice", specialPromoPriceValue != null ? specialPromoPriceValue.getBigDecimal("price") : null); @@ -668,13 +668,13 @@ // okay, now we have the calculated price, see if we should add in tax and if so do it if ("Y".equals(checkIncludeVat) && productStore != null && "Y".equals(productStore.getString("showPricesWithVatTax"))) { - Map<String, Object> calcTaxForDisplayContext = UtilMisc.toMap("productStoreId", productStore.get("productStoreId"), - "productId", productId, "quantity", quantity, + Map<String, Object> calcTaxForDisplayContext = UtilMisc.toMap("productStoreId", productStore.get("productStoreId"), + "productId", productId, "quantity", quantity, "basePrice", (BigDecimal) result.get("price")); if (UtilValidate.isNotEmpty(partyId)) { calcTaxForDisplayContext.put("billToPartyId", partyId); } - + try { Map<String, Object> calcTaxForDisplayResult = dispatcher.runSync("calcTaxForDisplay", calcTaxForDisplayContext); if (ServiceUtil.isError(calcTaxForDisplayResult)) { @@ -689,12 +689,12 @@ if (result.get("listPrice") != null) { result.put("listPrice", ((BigDecimal) result.get("listPrice")).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding )); } - if (result.get("defaultPrice") != null) { + if (result.get("defaultPrice") != null) { result.put("defaultPrice", ((BigDecimal) result.get("defaultPrice")).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding )); } if (result.get("averageCost") != null) { result.put("averageCost", ((BigDecimal) result.get("averageCost")).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding )); - } + } if (result.get("promoPrice") != null) { result.put("promoPrice", ((BigDecimal) result.get("promoPrice")).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding )); } @@ -707,10 +707,10 @@ return ServiceUtil.returnError(errMsg); } } - + return null; } - + public static List<GenericValue> makeProducePriceRuleList(GenericDelegator delegator, boolean optimizeForLargeRuleSet, String productId, String virtualProductId, String prodCatalogId, String productStoreGroupId, String webSiteId, String partyId, String currencyUomId) throws GenericEntityException { List<GenericValue> productPriceRules = null; @@ -856,20 +856,20 @@ productPriceRules = delegator.findList("ProductPriceRule", null, null, null, null, true); if (productPriceRules == null) productPriceRules = FastList.newInstance(); } - + return productPriceRules; } - - public static Map<String, Object> calcPriceResultFromRules(List<GenericValue> productPriceRules, BigDecimal listPrice, BigDecimal defaultPrice, BigDecimal promoPrice, - BigDecimal wholesalePrice, GenericValue maximumPriceValue, GenericValue minimumPriceValue, boolean validPriceFound, - GenericValue averageCostValue, String productId, String virtualProductId, String prodCatalogId, String productStoreGroupId, + + public static Map<String, Object> calcPriceResultFromRules(List<GenericValue> productPriceRules, BigDecimal listPrice, BigDecimal defaultPrice, BigDecimal promoPrice, + BigDecimal wholesalePrice, GenericValue maximumPriceValue, GenericValue minimumPriceValue, boolean validPriceFound, + GenericValue averageCostValue, String productId, String virtualProductId, String prodCatalogId, String productStoreGroupId, String webSiteId, String partyId, BigDecimal quantity, String currencyUomId, GenericDelegator delegator, Timestamp nowTimestamp) throws GenericEntityException { - + Map<String, Object> calcResults = FastMap.newInstance(); List<GenericValue> orderItemPriceInfos = FastList.newInstance(); boolean isSale = false; - + // ========= go through each price rule by id and eval all conditions ========= // utilTimer.timerString("Before eval rules", module); int totalConds = 0; @@ -882,7 +882,7 @@ // calculate running sum based on listPrice and rules found BigDecimal price = listPrice; - + for (GenericValue productPriceRule: productPriceRules) { String productPriceRuleId = productPriceRule.getString("productPriceRuleId"); @@ -1102,7 +1102,7 @@ calcResults.put("orderItemPriceInfos", orderItemPriceInfos); calcResults.put("isSale", Boolean.valueOf(isSale)); calcResults.put("validPriceFound", Boolean.valueOf(validPriceFound)); - + return calcResults; } @@ -1143,7 +1143,7 @@ } } else if ("PRIP_PROD_FEAT_ID".equals(productPriceCond.getString("inputParamEnumId"))) { // NOTE: DEJ20070130 don't retry this condition with the virtualProductId as well; this breaks various things you might want to do with price rules, like have different pricing for a variant products with a certain distinguishing feature - + // if a ProductFeatureAppl exists for this productId and the specified productFeatureId String productFeatureId = productPriceCond.getString("condValue"); List<GenericValue> productFeatureAppls = delegator.findByAndCache("ProductFeatureAppl", @@ -1297,7 +1297,7 @@ String currencyUomId = (String)context.get("currencyUomId"); String partyId = (String)context.get("partyId"); BigDecimal quantity = (BigDecimal)context.get("quantity"); - + // a) Get the Price from the Agreement* data model // TODO: Implement this Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/KeywordIndex.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/KeywordIndex.java?rev=757089&r1=757088&r2=757089&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/KeywordIndex.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/KeywordIndex.java Sat Mar 21 23:44:24 2009 @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -44,7 +44,7 @@ * Does indexing in preparation for a keyword search. */ public class KeywordIndex { - + public static final String module = KeywordIndex.class.getName(); public static void forceIndexKeywords(GenericValue product) throws GenericEntityException { @@ -58,7 +58,7 @@ public static void indexKeywords(GenericValue product, boolean doAll) throws GenericEntityException { if (product == null) return; Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); - + if (!doAll) { if ("N".equals(product.getString("autoCreateKeywords"))) { return; @@ -67,12 +67,12 @@ return; } Timestamp salesDiscontinuationDate = product.getTimestamp("salesDiscontinuationDate"); - if (salesDiscontinuationDate != null && salesDiscontinuationDate.before(nowTimestamp) && + if (salesDiscontinuationDate != null && salesDiscontinuationDate.before(nowTimestamp) && "true".equals(UtilProperties.getPropertyValue("prodsearch", "index.ignore.discontinued.sales"))) { return; } } - + GenericDelegator delegator = product.getDelegator(); if (delegator == null) return; String productId = product.getString("productId"); @@ -83,7 +83,7 @@ String stopWordBagAnd = KeywordSearchUtil.getStopWordBagAnd(); boolean removeStems = KeywordSearchUtil.getRemoveStems(); Set<String> stemSet = KeywordSearchUtil.getStemSet(); - + Map<String, Long> keywords = new TreeMap<String, Long>(); List<String> strings = FastList.newInstance(); @@ -142,7 +142,7 @@ addWeightedKeywordSourceString(goodIdentification, "idValue", strings); } } - + // Variant Product IDs if ("Y".equals(product.getString("isVirtual"))) { if (!"0".equals(UtilProperties.getPropertyValue("prodsearch", "index.weight.Variant.Product.productId", "0"))) { @@ -161,7 +161,7 @@ } } } - + String productContentTypes = UtilProperties.getPropertyValue("prodsearch", "index.include.ProductContentTypes"); for (String productContentTypeId: productContentTypes.split(",")) { int weight = 1; @@ -171,11 +171,11 @@ } catch (Exception e) { Debug.logWarning("Could not parse weight number: " + e.toString(), module); } - + List<GenericValue> productContentAndInfos = delegator.findByAnd("ProductContentAndInfo", UtilMisc.toMap("productId", productId, "productContentTypeId", productContentTypeId), null); for (GenericValue productContentAndInfo: productContentAndInfos) { addWeightedDataResourceString(productContentAndInfo, weight, strings, delegator, product); - + List<GenericValue> alternateViews = productContentAndInfo.getRelated("ContentAssocDataResourceViewTo", UtilMisc.toMap("caContentAssocTypeId", "ALTERNATE_LOCALE"), UtilMisc.toList("-caFromDate")); alternateViews = EntityUtil.filterByDate(alternateViews, UtilDateTime.nowTimestamp(), "caFromDate", "caThruDate", true); for (GenericValue thisView: alternateViews) { @@ -183,7 +183,7 @@ } } } - + for (String str: strings) { // call process keywords method here KeywordSearchUtil.processKeywordsForIndex(str, keywords, separators, stopWordBagAnd, stopWordBagOr, removeStems, stemSet); @@ -205,7 +205,7 @@ delegator.storeAll(toBeStored); } } - + public static void addWeightedDataResourceString(GenericValue drView, int weight, List<String> strings, GenericDelegator delegator, GenericValue product) { Map<String, GenericValue> drContext = UtilMisc.toMap("product", product); try { Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java?rev=757089&r1=757088&r2=757089&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductContentWrapper.java Sat Mar 21 23:44:24 2009 @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -50,12 +50,12 @@ * Product Content Worker: gets product content to display */ public class ProductContentWrapper implements ContentWrapper { - + public static final String module = ProductContentWrapper.class.getName(); public static final String SEPARATOR = "::"; // cache key separator - + public static UtilCache<String, String> productContentCache = new UtilCache<String, String>("product.content.rendered", true); - + public static ProductContentWrapper makeProductContentWrapper(GenericValue product, HttpServletRequest request) { return new ProductContentWrapper(product, request); } @@ -64,21 +64,21 @@ protected GenericValue product; protected Locale locale; protected String mimeTypeId; - + public ProductContentWrapper(LocalDispatcher dispatcher, GenericValue product, Locale locale, String mimeTypeId) { this.dispatcher = dispatcher; this.product = product; this.locale = locale; this.mimeTypeId = mimeTypeId; } - + public ProductContentWrapper(GenericValue product, HttpServletRequest request) { this.dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); this.product = product; this.locale = UtilHttp.getLocale(request); this.mimeTypeId = "text/html"; } - + public StringUtil.StringWrapper get(String productContentTypeId) { if (this.product == null) { Debug.logWarning("Tried to get ProductContent for type [" + productContentTypeId + "] but the product field in the ProductContentWrapper is null", module); @@ -86,7 +86,7 @@ } return StringUtil.makeStringWrapper(getProductContentAsText(this.product, productContentTypeId, locale, mimeTypeId, this.product.getDelegator(), dispatcher)); } - + public static String getProductContentAsText(GenericValue product, String productContentTypeId, HttpServletRequest request) { LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); return getProductContentAsText(product, productContentTypeId, UtilHttp.getLocale(request), "text/html", product.getDelegator(), dispatcher); @@ -95,22 +95,22 @@ public static String getProductContentAsText(GenericValue product, String productContentTypeId, Locale locale, LocalDispatcher dispatcher) { return getProductContentAsText(product, productContentTypeId, locale, null, null, dispatcher); } - + public static String getProductContentAsText(GenericValue product, String productContentTypeId, Locale locale, String mimeTypeId, GenericDelegator delegator, LocalDispatcher dispatcher) { if (product == null) { return null; } - + String candidateFieldName = ModelUtil.dbNameToVarName(productContentTypeId); /* caching: there is one cache created, "product.content" Each product's content is cached with a key of * contentTypeId::locale::mimeType::productId, or whatever the SEPARATOR is defined above to be. - */ + */ String cacheKey = productContentTypeId + SEPARATOR + locale + SEPARATOR + mimeTypeId + SEPARATOR + product.get("productId"); try { if (productContentCache.get(cacheKey) != null) { return productContentCache.get(cacheKey); } - + Writer outWriter = new StringWriter(); getProductContentAsText(null, product, productContentTypeId, locale, mimeTypeId, delegator, dispatcher, outWriter); String outString = outWriter.toString(); @@ -133,16 +133,16 @@ return candidateOut == null? "" : candidateOut; } } - + public static void getProductContentAsText(String productId, GenericValue product, String productContentTypeId, Locale locale, String mimeTypeId, GenericDelegator delegator, LocalDispatcher dispatcher, Writer outWriter) throws GeneralException, IOException { if (productId == null && product != null) { productId = product.getString("productId"); } - + if (delegator == null && product != null) { delegator = product.getDelegator(); } - + if (UtilValidate.isEmpty(mimeTypeId)) { mimeTypeId = "text/html"; } @@ -150,8 +150,8 @@ if (delegator == null) { throw new GeneralRuntimeException("Unable to find a delegator to use!"); } - - String candidateFieldName = ModelUtil.dbNameToVarName(productContentTypeId); + + String candidateFieldName = ModelUtil.dbNameToVarName(productContentTypeId); ModelEntity productModel = delegator.getModelEntity("Product"); if (productModel.isField(candidateFieldName)) { if (product == null) { @@ -164,7 +164,7 @@ return; } else if ("Y".equals(product.getString("isVariant"))) { // look up the virtual product - GenericValue parent = ProductWorker.getParentProduct(productId, delegator); + GenericValue parent = ProductWorker.getParentProduct(productId, delegator); if (parent != null) { candidateValue = parent.getString(candidateFieldName); if (UtilValidate.isNotEmpty(candidateValue)) { @@ -175,7 +175,7 @@ } } } - + List<GenericValue> productContentList = delegator.findByAndCache("ProductContent", UtilMisc.toMap("productId", productId, "productContentTypeId", productContentTypeId), UtilMisc.toList("-fromDate")); productContentList = EntityUtil.filterByDate(productContentList); GenericValue productContent = EntityUtil.getFirst(productContentList); Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java?rev=757089&r1=757088&r2=757089&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java Sat Mar 21 23:44:24 2009 @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -135,7 +135,7 @@ //errMsg = UtilProperties.getMessage(resource,"productevents.could_not_create_keywords_write", UtilHttp.getLocale(request)); //request.setAttribute("_ERROR_MESSAGE_", errMsg); Debug.logWarning("[ProductEvents.updateAllKeywords] Could not create product-keyword (write error); message: " + e.getMessage(), module); - errProds++; + errProds++; } numProds++; if (numProds % 500 == 0) { @@ -437,25 +437,25 @@ product.set("productWidth", UtilParse.parseBigDecimalForEntity(request.getParameter("productWidth"))); product.set("productDepth", UtilParse.parseBigDecimalForEntity(request.getParameter("productDepth"))); product.set("weight", UtilParse.parseBigDecimalForEntity(request.getParameter("weight"))); - + // default unit settings for shipping parameters product.set("heightUomId", "LEN_in"); product.set("widthUomId", "LEN_in"); product.set("depthUomId", "LEN_in"); product.set("weightUomId", "WT_oz"); - + BigDecimal floz = UtilParse.parseBigDecimalForEntity(request.getParameter("~floz")); BigDecimal ml = UtilParse.parseBigDecimalForEntity(request.getParameter("~ml")); BigDecimal ntwt = UtilParse.parseBigDecimalForEntity(request.getParameter("~ntwt")); BigDecimal grams = UtilParse.parseBigDecimalForEntity(request.getParameter("~grams")); - + List<GenericValue> currentProductFeatureAndAppls = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE")), true); setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ozUS", "AMOUNT", floz); setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ml", "AMOUNT", ml); setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "WT_g", "AMOUNT", grams); setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "WT_oz", "AMOUNT", ntwt); product.store(); - + } catch (NumberFormatException nfe) { String errMsg = "Shipping Dimensions and Weights must be numbers."; request.setAttribute("_ERROR_MESSAGE_", errMsg); @@ -478,7 +478,7 @@ BigDecimal ml = UtilParse.parseBigDecimalForEntity(request.getParameter("~ml" + attribIdx)); BigDecimal ntwt = UtilParse.parseBigDecimalForEntity(request.getParameter("~ntwt" + attribIdx)); BigDecimal grams = UtilParse.parseBigDecimalForEntity(request.getParameter("~grams" + attribIdx)); - + List<GenericValue> currentProductFeatureAndAppls = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE")), true); setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ozUS", "AMOUNT", floz); setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ml", "AMOUNT", ml); @@ -528,10 +528,10 @@ */ private static void setOrCreateProdFeature(GenericDelegator delegator, String productId, List<GenericValue> currentProductFeatureAndAppls, String uomId, String productFeatureTypeId, BigDecimal numberSpecified) throws GenericEntityException { - + GenericValue productFeatureType = delegator.findByPrimaryKey("ProductFeatureType", UtilMisc.toMap("productFeatureTypeId", productFeatureTypeId)); GenericValue uom = delegator.findByPrimaryKey("Uom", UtilMisc.toMap("uomId", uomId)); - + Timestamp nowTimestamp = UtilDateTime.nowTimestamp(); // filter list of features to the one we'll be editing @@ -565,7 +565,7 @@ } prodFeature.set("numberSpecified", numberSpecified); prodFeature.set("description", numberSpecified.toString() + (uom == null ? "" : (" " + uom.getString("description")))); - + // if there is a productFeatureCategory with the same id as the productFeatureType, use that category. // otherwise, use a default category from the configuration if (delegator.findByPrimaryKey("ProductFeatureCategory", UtilMisc.toMap("productFeatureCategoryId", productFeatureTypeId)) == null) { @@ -591,7 +591,7 @@ String variantProductId = request.getParameter("productId0"); String useImagesProdId = request.getParameter("useImages"); String productFeatureTypeId = request.getParameter("productFeatureTypeId"); - + if (UtilValidate.isEmpty(productFeatureTypeId)) { String errMsg = "Error: please select a ProductFeature Type to add or update variant features."; request.setAttribute("_ERROR_MESSAGE_", errMsg); @@ -607,7 +607,7 @@ request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } - + // check for variantProductId - this will mean that we have multiple variants to update if (variantProductId != null) { // multiple products, so use a numeric suffix to get them all @@ -620,7 +620,7 @@ if ((description != null) && (description.trim().length() < 1)) { description = null; } - + Set<String> variantDescRemoveToRemoveOnVirtual = FastSet.newInstance(); checkUpdateFeatureApplByDescription(variantProductId, variantProduct, description, productFeatureTypeId, productFeatureType, "STANDARD_FEATURE", nowTimestamp, delegator, null, variantDescRemoveToRemoveOnVirtual); checkUpdateFeatureApplByDescription(productId, product, description, productFeatureTypeId, productFeatureType, "SELECTABLE_FEATURE", nowTimestamp, delegator, variantDescRemoveToRemoveOnVirtual, null); @@ -637,7 +637,7 @@ variantProductId = request.getParameter("productId" + attribIdx); } while (variantProductId != null); } - + TransactionUtil.commit(beganTransaction); } catch (GenericEntityException e) { String errMsg = "Error updating quick admin selectable feature settings: " + e.toString(); @@ -654,9 +654,9 @@ } return "success"; } - - protected static void checkUpdateFeatureApplByDescription(String productId, GenericValue product, String description, - String productFeatureTypeId, GenericValue productFeatureType, String productFeatureApplTypeId, + + protected static void checkUpdateFeatureApplByDescription(String productId, GenericValue product, String description, + String productFeatureTypeId, GenericValue productFeatureType, String productFeatureApplTypeId, Timestamp nowTimestamp, GenericDelegator delegator, Set<String> descriptionsToRemove, Set<String> descriptionsRemoved) throws GenericEntityException { if (productFeatureType == null) { return; @@ -665,7 +665,7 @@ GenericValue productFeatureAndAppl = null; Set<String> descriptionsForThisType = FastSet.newInstance(); - List<GenericValue> productFeatureAndApplList = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, + List<GenericValue> productFeatureAndApplList = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", productFeatureApplTypeId, "productFeatureTypeId", productFeatureTypeId)), true); if (productFeatureAndApplList.size() > 0) { Iterator<GenericValue> productFeatureAndApplIter = productFeatureAndApplList.iterator(); @@ -688,20 +688,20 @@ while (!foundFeatureOnVariant && variantIter.hasNext()) { GenericValue variant = variantIter.next(); // get the selectable features for the variant - List<GenericValue> variantProductFeatureAndAppls = variant.getRelated("ProductFeatureAndAppl", - UtilMisc.toMap("productFeatureTypeId", productFeatureTypeId, + List<GenericValue> variantProductFeatureAndAppls = variant.getRelated("ProductFeatureAndAppl", + UtilMisc.toMap("productFeatureTypeId", productFeatureTypeId, "productFeatureApplTypeId", "STANDARD_FEATURE", "description", description), null); if (variantProductFeatureAndAppls.size() > 0) { foundFeatureOnVariant = true; } } - + if (foundFeatureOnVariant) { // don't remove this one! continue; } } - + if (descriptionsRemoved != null) { descriptionsRemoved.add(productFeatureAndAppl.getString("description")); } @@ -709,15 +709,15 @@ continue; } } - + // we got here, is still a valid description associated with this product descriptionsForThisType.add(productFeatureAndAppl.getString("description")); } } - + if (description != null && (productFeatureAndAppl == 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) String productFeatureId = null; List<GenericValue> existingProductFeatureList = delegator.findByAnd("ProductFeature", UtilMisc.toMap("productFeatureTypeId", productFeatureTypeId, "description", description)); @@ -731,7 +731,7 @@ UtilMisc.toMap("productFeatureId", productFeatureId, "productFeatureTypeId", productFeatureTypeId, "description", description)); - + // if there is a productFeatureCategory with the same id as the productFeatureType, use that category. // otherwise, create a category for the feature type if (delegator.findByPrimaryKey("ProductFeatureCategory", UtilMisc.toMap("productFeatureCategoryId", productFeatureTypeId)) == null) { @@ -743,11 +743,11 @@ newProductFeature.set("productFeatureCategoryId", productFeatureTypeId); newProductFeature.create(); } - + // check to see if the productFeatureId is already attached to the virtual or variant, if not attach them... - List<GenericValue> specificProductFeatureApplList = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAppl", UtilMisc.toMap("productId", productId, + List<GenericValue> specificProductFeatureApplList = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", productFeatureApplTypeId, "productFeatureId", productFeatureId)), true); - + if (specificProductFeatureApplList.size() == 0) { delegator.create("ProductFeatureAppl", UtilMisc.toMap("productId", productId, @@ -800,7 +800,7 @@ //GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin"); String productId = request.getParameter("productId"); String productFeatureId = request.getParameter("productFeatureId"); - + if (UtilValidate.isEmpty(productId) || UtilValidate.isEmpty(productFeatureId)) { String errMsg = "Must specify both a productId [was:" + productId + "] and a productFeatureId [was:" + productFeatureId + "] to remove the feature from the product."; request.setAttribute("_ERROR_MESSAGE_", errMsg); @@ -935,7 +935,7 @@ if (localeStr == null && productStore.get("defaultLocaleString") != null) { localeStr = productStore.getString("defaultLocaleString"); } - + UtilHttp.setCurrencyUom(session, currencyStr); UtilHttp.setLocale(request, localeStr); @@ -943,10 +943,10 @@ return "success"; } - /** + /** * If ProductStore.requireCustomerRole == Y then the loggedin user must be associated with the store in the customer role. * This event method is called from the ProductEvents.storeCheckLogin and ProductEvents.storeLogin - * + * * @param request * @param response * @return String with response, maybe "success" or "error" if logged in user is not associated with the ProductStore in the CUSTOMER role. @@ -960,7 +960,7 @@ if ("Y".equals(productStore.getString("requireCustomerRole"))) { List<GenericValue> productStoreRoleList = null; try { - productStoreRoleList = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("productStoreId", productStore.get("productStoreId"), + productStoreRoleList = delegator.findByAnd("ProductStoreRole", UtilMisc.toMap("productStoreId", productStore.get("productStoreId"), "partyId", userLogin.get("partyId"), "roleTypeId", "CUSTOMER")); productStoreRoleList = EntityUtil.filterByDate(productStoreRoleList, true); } catch (GenericEntityException e) { @@ -994,7 +994,7 @@ return "error"; } String productStoreId = productStore.getString("productStoreId"); - + GenericValue productStoreEmail = null; try { productStoreEmail = delegator.findByPrimaryKey("ProductStoreEmailSetting", @@ -1015,7 +1015,7 @@ if (UtilValidate.isEmpty(bodyScreenLocation)) { bodyScreenLocation = defaultScreenLocation; } - + Map<String, Object> paramMap = UtilHttp.getParameterMap(request); paramMap.put("locale", UtilHttp.getLocale(request)); paramMap.put("userLogin", session.getAttribute("userLogin")); Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java?rev=757089&r1=757088&r2=757089&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearch.java Sat Mar 21 23:44:24 2009 @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -167,14 +167,14 @@ public List<Set<String>> includeCategoryIdOrSetAndList = FastList.newInstance(); public List<Set<String>> alwaysIncludeCategoryIdOrSetAndList = FastList.newInstance(); - + public Set<String> includeFeatureIds = FastSet.newInstance(); public Set<String> excludeFeatureIds = FastSet.newInstance(); public Set<String> alwaysIncludeFeatureIds = FastSet.newInstance(); public List<Set<String>> includeFeatureIdOrSetAndList = FastList.newInstance(); public List<Set<String>> alwaysIncludeFeatureIdOrSetAndList = FastList.newInstance(); - + public Set<String> includeFeatureCategoryIds = FastSet.newInstance(); public Set<String> excludeFeatureCategoryIds = FastSet.newInstance(); public Set<String> alwaysIncludeFeatureCategoryIds = FastSet.newInstance(); @@ -231,7 +231,7 @@ Debug.logError(e, "Error closing ProductSearch EntityListIterator"); } } - + long endMillis = System.currentTimeMillis(); double totalSeconds = ((double)endMillis - (double)startMillis)/1000.0; @@ -288,7 +288,7 @@ entityConditionList.add(EntityCondition.makeCondition(prefix + "Keyword", EntityOperator.LIKE, keyword)); //don't add an alias for this, will be part of a complex alias: dynamicViewEntity.addAlias(entityAlias, prefix + "RelevancyWeight", "relevancyWeight", null, null, null, null); - //needed when doingBothAndOr or will get an SQL error + //needed when doingBothAndOr or will get an SQL error if (doingBothAndOr) { dynamicViewEntity.addAlias(entityAlias, prefix + "RelevancyWeight", "relevancyWeight", null, null, Boolean.TRUE, null); } @@ -341,18 +341,18 @@ includeFeatureGroupIds.size() == 0 && excludeFeatureGroupIds.size() == 0 && alwaysIncludeFeatureGroupIds.size() == 0) { return; } - - // create new view members with logic: - // ((each Id = category includes AND Id IN feature includes) AND (Id NOT IN category excludes AND Id NOT IN feature excludes)) + + // create new view members with logic: + // ((each Id = category includes AND Id IN feature includes) AND (Id NOT IN category excludes AND Id NOT IN feature excludes)) // OR (each Id = category alwaysIncludes AND each Id = feature alwaysIncludes) List<EntityCondition> incExcCondList = FastList.newInstance(); EntityCondition incExcCond = null; - + List<EntityCondition> alwIncCondList = FastList.newInstance(); EntityCondition alwIncCond = null; - + EntityCondition topCond = null; - + if (includeCategoryIds.size() > 0) { for (String includeCategoryId: includeCategoryIds) { String categoryPrefix = "pcm" + this.index; @@ -429,7 +429,7 @@ incExcCondList.add(EntityCondition.makeCondition(otherFeaturePrefix + "ProductFeatureGroupId", EntityOperator.EQUALS, includeFeatureGroupId)); } } - + if (excludeCategoryIds.size() > 0) { List<EntityCondition> idExcludeCondList = FastList.newInstance(); idExcludeCondList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("thruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("thruDate", EntityOperator.GREATER_THAN, this.nowTimestamp))); @@ -464,12 +464,12 @@ EntityConditionValue subSelCond = new EntityConditionSubSelect("ProdFeaGrpAppAndProdFeaApp", "productId", EntityCondition.makeCondition(idExcludeCondList, EntityOperator.AND), true, delegator); incExcCondList.add(EntityCondition.makeCondition("mainProductId", EntityOperator.NOT_EQUAL, subSelCond)); } - + if (alwaysIncludeCategoryIds.size() > 0) { String categoryPrefix = "pcm" + this.index; String entityAlias = "PCM" + this.index; this.index++; - + this.dynamicViewEntity.addMemberEntity(entityAlias, "ProductCategoryMember"); this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "ProductCategoryId", "productCategoryId", null, null, null, null); this.dynamicViewEntity.addAlias(entityAlias, categoryPrefix + "FromDate", "fromDate", null, null, null, null); @@ -477,7 +477,7 @@ this.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); alwIncCondList.add(EntityCondition.makeCondition(EntityCondition.makeCondition(categoryPrefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition(categoryPrefix + "ThruDate", EntityOperator.GREATER_THAN, this.nowTimestamp))); alwIncCondList.add(EntityCondition.makeCondition(categoryPrefix + "FromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); - alwIncCondList.add(EntityCondition.makeCondition(categoryPrefix + "ProductCategoryId", EntityOperator.IN, alwaysIncludeCategoryIds)); + alwIncCondList.add(EntityCondition.makeCondition(categoryPrefix + "ProductCategoryId", EntityOperator.IN, alwaysIncludeCategoryIds)); } if (alwaysIncludeFeatureIds.size() > 0) { String featurePrefix = "pfa" + this.index; @@ -491,7 +491,7 @@ this.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); alwIncCondList.add(EntityCondition.makeCondition(EntityCondition.makeCondition(featurePrefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition(featurePrefix + "ThruDate", EntityOperator.GREATER_THAN, this.nowTimestamp))); alwIncCondList.add(EntityCondition.makeCondition(featurePrefix + "FromDate", EntityOperator.LESS_THAN, this.nowTimestamp)); - alwIncCondList.add(EntityCondition.makeCondition(featurePrefix + "ProductFeatureId", EntityOperator.IN, alwaysIncludeFeatureIds)); + alwIncCondList.add(EntityCondition.makeCondition(featurePrefix + "ProductFeatureId", EntityOperator.IN, alwaysIncludeFeatureIds)); } if (alwaysIncludeFeatureCategoryIds.size() > 0) { for (String alwaysIncludeFeatureCategoryId: alwaysIncludeFeatureCategoryIds) { @@ -620,18 +620,18 @@ } else if (alwIncCond != null) { topCond = alwIncCond; } - + this.entityConditionList.add(topCond); - + Debug.logInfo("topCond=" + topCond.makeWhereString(null, FastList.<EntityConditionParam>newInstance(), EntityConfigUtil.getDatasourceInfo(delegator.getEntityHelperName("Product"))), module); } - + public EntityListIterator doQuery(GenericDelegator delegator) { // handle the now assembled or and and keyword fixed lists this.finishKeywordConstraints(); this.finishCategoryAndFeatureConstraints(); - + if (resultSortOrder != null) { resultSortOrder.setSortOrder(this); } @@ -663,7 +663,7 @@ try { boolean hasResults = false; Object initialResult = null; - + /* this method has been replaced by the following to address issue with SAP DB and possibly other DBs if (resultOffset != null) { Debug.logInfo("Before relative, current index=" + eli.currentIndex(), module); @@ -685,7 +685,7 @@ hasResults = eli.relative(resultOffset.intValue() - 1); initialResult = null; } - + // get the first as the current one GenericValue searchResult = null; if (hasResults) { @@ -706,13 +706,13 @@ return productIds; } - + // init numRetreived to one since we have already grabbed the initial one int numRetreived = 1; int duplicatesFound = 0; Set<String> productIdSet = FastSet.newInstance(); - + productIds.add(searchResult.getString("mainProductId")); productIdSet.add(searchResult.getString("mainProductId")); @@ -725,7 +725,7 @@ } else { duplicatesFound++; } - + /* StringBuilder lineMsg = new StringBuilder("Got search result line: "); for (String fieldName: fieldsToSelect) { @@ -818,29 +818,29 @@ /** pretty print for log messages and even UI stuff */ public abstract String prettyPrintConstraint(GenericDelegator delegator, boolean detailed, Locale locale); } - + public static class CatalogConstraint extends ProductSearchConstraint { public static final String constraintName = "Catalog"; - protected String prodCatalogId; + protected String prodCatalogId; protected List<GenericValue> productCategories; - + public CatalogConstraint(String prodCatalogId, List<GenericValue> productCategories) { - this.prodCatalogId = prodCatalogId; - this.productCategories = productCategories; + this.prodCatalogId = prodCatalogId; + this.productCategories = productCategories; } - - public void addConstraint(ProductSearchContext productSearchContext) { + + public void addConstraint(ProductSearchContext productSearchContext) { List<String> productCategoryIds = FastList.newInstance(); for (GenericValue category: productCategories) { productCategoryIds.add(category.getString("productCategoryId")); - } - + } + // make index based values and increment String entityAlias = "PCM" + productSearchContext.index; String prefix = "pcm" + productSearchContext.index; productSearchContext.index++; - + productSearchContext.dynamicViewEntity.addMemberEntity(entityAlias, "ProductCategoryMember"); productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "ProductCategoryId", "productCategoryId", null, null, null, null); productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "FromDate", "fromDate", null, null, null, null); @@ -848,11 +848,11 @@ productSearchContext.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); productSearchContext.entityConditionList.add(EntityCondition.makeCondition(prefix + "ProductCategoryId", EntityOperator.IN, productCategoryIds)); productSearchContext.entityConditionList.add(EntityCondition.makeCondition(EntityCondition.makeCondition(prefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition(prefix + "ThruDate", EntityOperator.GREATER_THAN, productSearchContext.nowTimestamp))); productSearchContext.entityConditionList.add(EntityCondition.makeCondition(prefix + "FromDate", EntityOperator.LESS_THAN, productSearchContext.nowTimestamp)); - + // add in productSearchConstraint, don't worry about the productSearchResultId or constraintSeqId, those will be fill in later productSearchContext.productSearchConstraintList.add(productSearchContext.getDelegator().makeValue("ProductSearchConstraint", UtilMisc.toMap("constraintName", constraintName, "infoString", this.prodCatalogId))); } - + /** pretty print for log messages and even UI stuff */ public String prettyPrintConstraint(GenericDelegator delegator, boolean detailed, Locale locale) { GenericValue prodCatalog = null; @@ -861,18 +861,18 @@ } catch (GenericEntityException e) { Debug.logError(e, "Error finding ProdCatalog information for constraint pretty print", module); } - StringBuilder ppBuf = new StringBuilder(); + StringBuilder ppBuf = new StringBuilder(); ppBuf.append(UtilProperties.getMessage(resource, "ProductCatalog", locale)).append(": "); - if (prodCatalog != null) { + if (prodCatalog != null) { ppBuf.append(prodCatalog.getString("catalogName")); - } + } return ppBuf.toString(); } - + public boolean equals(Object obj) { ProductSearchConstraint psc = (ProductSearchConstraint) obj; if (psc instanceof CatalogConstraint) { - CatalogConstraint that = (CatalogConstraint) psc; + CatalogConstraint that = (CatalogConstraint) psc; if (this.prodCatalogId == null) { if (that.prodCatalogId != null) { return false; @@ -888,7 +888,7 @@ } } } - + public static class CategoryConstraint extends ProductSearchConstraint { public static final String constraintName = "Category"; protected String productCategoryId; @@ -897,8 +897,8 @@ protected Boolean exclude; /** - * - * @param productCategoryId + * + * @param productCategoryId * @param includeSubCategories * @param exclude This is a tri-state variable: null = Include, true = Exclude, false = AlwaysInclude */ @@ -925,7 +925,7 @@ } else if (exclude.equals(Boolean.FALSE)) { productSearchContext.alwaysIncludeCategoryIdOrSetAndList.add(productCategoryIdSet); } - + // add in productSearchConstraint, don't worry about the productSearchResultId or constraintSeqId, those will be fill in later productSearchContext.productSearchConstraintList.add(productSearchContext.getDelegator().makeValue("ProductSearchConstraint", UtilMisc.toMap("constraintName", constraintName, "infoString", this.productCategoryId, "includeSubCategories", this.includeSubCategories ? "Y" : "N"))); } @@ -938,7 +938,7 @@ } catch (GenericEntityException e) { Debug.logError(e, "Error finding ProductCategory information for constraint pretty print", module); } - StringBuilder ppBuf = new StringBuilder(); + StringBuilder ppBuf = new StringBuilder(); ppBuf.append(UtilProperties.getMessage(resource, "ProductCategory", locale)).append(": "); if (productCategory != null) { String catInfo = CategoryContentWrapper.getProductCategoryContentAsText(productCategory, "CATEGORY_NAME", locale, null); @@ -988,7 +988,7 @@ protected Boolean exclude; /** - * + * * @param productFeatureId * @param exclude This is a tri-state variable: null = Include, true = Exclude, false = AlwaysInclude */ @@ -1021,7 +1021,7 @@ Debug.logError(e, "Error finding ProductFeature and Type information for constraint pretty print", module); } StringBuilder ppBuf = new StringBuilder(); - if (productFeatureType == null) { + if (productFeatureType == null) { ppBuf.append(UtilProperties.getMessage(resource, "ProductFeature", locale)).append(": "); ppBuf.append("[").append(this.productFeatureId).append("]"); } else { @@ -1059,7 +1059,7 @@ } } - + public static class FeatureCategoryConstraint extends ProductSearchConstraint { public static final String constraintName = "FeatureCategory"; protected String productFeatureCategoryId; @@ -1067,7 +1067,7 @@ protected Boolean exclude; /** - * + * * @param productFeatureCategoryId * @param exclude This is a tri-state variable: null = Include, true = Exclude, false = AlwaysInclude */ @@ -1098,15 +1098,15 @@ Debug.logError(e, "Error finding ProductFeatureCategory and Type information for constraint pretty print", module); } StringBuilder ppBuf = new StringBuilder(); - if (productFeatureCategory != null) { + if (productFeatureCategory != null) { ppBuf.append(UtilProperties.getMessage(resource, "ProductFeatureCategory", locale)).append(": "); if (productFeatureCategory.get("description") != null) { - ppBuf.append(productFeatureCategory.get("description")); + ppBuf.append(productFeatureCategory.get("description")); } else { ppBuf.append("[").append(this.productFeatureCategoryId).append("]"); } - - } + + } if (this.exclude != null) { if (Boolean.TRUE.equals(this.exclude)) { ppBuf.append(" (Exclude)"); @@ -1144,7 +1144,7 @@ protected Boolean exclude; /** - * + * * @param productFeatureGroupId * @param exclude This is a tri-state variable: null = Include, true = Exclude, false = AlwaysInclude */ @@ -1178,11 +1178,11 @@ if (productFeatureGroup != null) { ppBuf.append(UtilProperties.getMessage(resource, "ProductFeatureGroup", locale)).append(": "); if (productFeatureGroup.get("description") != null) { - ppBuf.append(productFeatureGroup.get("description")); + ppBuf.append(productFeatureGroup.get("description")); } else { ppBuf.append("[").append(this.productFeatureGroupId).append("]"); } - } + } if (this.exclude != null) { if (Boolean.TRUE.equals(this.exclude)) { ppBuf.append(" (Exclude)"); @@ -1213,7 +1213,7 @@ } } - + public static class FeatureSetConstraint extends ProductSearchConstraint { public static final String constraintName = "Feature Set"; protected Set<String> productFeatureIdSet; @@ -1221,7 +1221,7 @@ protected Boolean exclude; /** - * + * * @param productFeatureIdSet * @param exclude This is a tri-state variable: null = Include, true = Exclude, false = AlwaysInclude */ @@ -1249,7 +1249,7 @@ } featureIdInfo.append(featureId); } - + productSearchContext.productSearchConstraintList.add(productSearchContext.getDelegator().makeValue("ProductSearchConstraint", UtilMisc.toMap("constraintName", constraintName, "infoString", featureIdInfo.toString()))); } @@ -1275,12 +1275,12 @@ } else { infoOut.append(productFeature.getString("description")); } - + } } catch (GenericEntityException e) { Debug.logError(e, "Error finding ProductFeature and Type information for constraint pretty print", module); } - + return infoOut.toString(); } @@ -1385,7 +1385,7 @@ StringBuilder ppBuf = new StringBuilder(); ppBuf.append(UtilProperties.getMessage(resource, "ProductKeywords", locale)).append(": \""); ppBuf.append(this.keywordsString).append("\", ").append(UtilProperties.getMessage(resource, "ProductKeywordWhere", locale)).append(" "); - ppBuf.append(isAnd ? UtilProperties.getMessage(resource, "ProductKeywordAllWordsMatch", locale) : UtilProperties.getMessage(resource, "ProductKeywordAnyWordMatches", locale)); + ppBuf.append(isAnd ? UtilProperties.getMessage(resource, "ProductKeywordAllWordsMatch", locale) : UtilProperties.getMessage(resource, "ProductKeywordAnyWordMatches", locale)); return ppBuf.toString(); } @@ -1545,7 +1545,7 @@ productSearchContext.index++; productSearchContext.dynamicViewEntity.addMemberEntity(entityAlias, "ProductPrice"); - + productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "ProductPriceTypeId", "productPriceTypeId", null, null, null, null); productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "ProductPricePurposeId", "productPricePurposeId", null, null, null, null); productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "CurrencyUomId", "currencyUomId", null, null, null, null); @@ -1555,7 +1555,7 @@ productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "Price", "price", null, null, null, null); productSearchContext.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); - + productSearchContext.entityConditionList.add(EntityCondition.makeCondition(prefix + "ProductPriceTypeId", EntityOperator.EQUALS, "LIST_PRICE")); productSearchContext.entityConditionList.add(EntityCondition.makeCondition(prefix + "ProductPricePurposeId", EntityOperator.EQUALS, "PURCHASE")); productSearchContext.entityConditionList.add(EntityCondition.makeCondition(prefix + "CurrencyUomId", EntityOperator.EQUALS, currencyUomId)); @@ -1570,7 +1570,7 @@ } // add in productSearchConstraint, don't worry about the productSearchResultId or constraintSeqId, those will be fill in later - productSearchContext.productSearchConstraintList.add(productSearchContext.getDelegator().makeValue("ProductSearchConstraint", + productSearchContext.productSearchConstraintList.add(productSearchContext.getDelegator().makeValue("ProductSearchConstraint", UtilMisc.toMap("constraintName", constraintName, "infoString", "low [" + this.lowPrice + "] high [" + this.highPrice + "] currency [" + this.currencyUomId + "]"))); } @@ -1582,7 +1582,7 @@ StringBuilder msgBuf = new StringBuilder(); msgBuf.append(UtilProperties.getMessage(resource, "ProductListPriceRange", locale)); msgBuf.append(": "); - + // NOTE: at this point we know that only one or none are null if (this.lowPrice == null) { msgBuf.append(UtilProperties.getMessage(resourceCommon, "CommonLessThan", locale)); @@ -1731,7 +1731,7 @@ } } } - + public static class GoodIdentificationConstraint extends ProductSearchConstraint { public static final String constraintName = "GoodIdentification"; protected String goodIdentificationTypeId; @@ -1745,50 +1745,50 @@ } public void addConstraint(ProductSearchContext productSearchContext) { - if (UtilValidate.isNotEmpty(goodIdentificationTypeId) || - UtilValidate.isNotEmpty(goodIdentificationValue) || + if (UtilValidate.isNotEmpty(goodIdentificationTypeId) || + UtilValidate.isNotEmpty(goodIdentificationValue) || UtilValidate.isNotEmpty(include)) { - + // make index based values and increment String entityAlias = "GI" + productSearchContext.index; String prefix = "gi" + productSearchContext.index; productSearchContext.index++; - + EntityComparisonOperator operator = EntityOperator.EQUALS; - + if (UtilValidate.isNotEmpty(include) && include == Boolean.FALSE) { operator = EntityOperator.NOT_EQUAL; } - + productSearchContext.dynamicViewEntity.addMemberEntity(entityAlias, "GoodIdentification"); - + if (UtilValidate.isNotEmpty(goodIdentificationTypeId)) { productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "GoodIdentificationTypeId", "goodIdentificationTypeId", null, null, null, null); productSearchContext.entityConditionList.add(EntityCondition.makeCondition(prefix + "GoodIdentificationTypeId", operator, goodIdentificationTypeId)); } - + if (UtilValidate.isNotEmpty(goodIdentificationValue)) { productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "GoodIdentificationValue", "idValue", null, null, null, null); productSearchContext.entityConditionList.add(EntityCondition.makeCondition(prefix + "GoodIdentificationValue", operator, goodIdentificationValue)); } - + productSearchContext.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); - - productSearchContext.productSearchConstraintList.add(productSearchContext.getDelegator().makeValue("ProductSearchConstraint", + + productSearchContext.productSearchConstraintList.add(productSearchContext.getDelegator().makeValue("ProductSearchConstraint", UtilMisc.toMap("constraintName", constraintName, "infoString", "goodIdentificationTypeId [" + this.goodIdentificationTypeId + "] goodIdentificationValue [" + this.goodIdentificationValue + "] include [" + this.include + "]"))); } } public String prettyPrintConstraint(GenericDelegator delegator, boolean detailed, Locale locale) { if (UtilValidate.isEmpty(goodIdentificationTypeId) && - UtilValidate.isEmpty(goodIdentificationValue) && + UtilValidate.isEmpty(goodIdentificationValue) && UtilValidate.isEmpty(include)) { return null; } - + StringBuilder msgBuf = new StringBuilder(); - + if (UtilValidate.isNotEmpty(include) && include == Boolean.FALSE) { msgBuf.append(UtilProperties.getMessage(resourceCommon, "CommonExclude", locale)); msgBuf.append(" "); @@ -1796,14 +1796,14 @@ msgBuf.append(UtilProperties.getMessage(resourceCommon, "CommonInclude", locale)); msgBuf.append(" "); } - + if (UtilValidate.isNotEmpty(goodIdentificationTypeId)) { msgBuf.append(UtilProperties.getMessage(resource, "ProductIdType", locale)); msgBuf.append(": "); msgBuf.append(goodIdentificationTypeId); msgBuf.append(" "); } - + if (UtilValidate.isNotEmpty(goodIdentificationValue)) { msgBuf.append(UtilProperties.getMessage(resource, "ProductIdValue", locale)); msgBuf.append(" "); @@ -1948,13 +1948,13 @@ productSearchContext.dynamicViewEntity.addAlias("SPPRC", "sortFromDate", "fromDate", null, null, null, null); productSearchContext.dynamicViewEntity.addAlias("SPPRC", "sortThruDate", "thruDate", null, null, null, null); productSearchContext.dynamicViewEntity.addAlias("SPPRC", "sortPrice", "price", null, null, null, null); - + productSearchContext.entityConditionList.add(EntityCondition.makeCondition("sortProductPriceTypeId", EntityOperator.EQUALS, this.productPriceTypeId)); productSearchContext.entityConditionList.add(EntityCondition.makeCondition("sortCurrencyUomId", EntityOperator.EQUALS, this.currencyUomId)); productSearchContext.entityConditionList.add(EntityCondition.makeCondition("sortProductStoreGroupId", EntityOperator.EQUALS, this.productStoreGroupId)); productSearchContext.entityConditionList.add(EntityCondition.makeCondition("sortFromDate", EntityOperator.LESS_THAN_EQUAL_TO, productSearchContext.nowTimestamp)); productSearchContext.entityConditionList.add(EntityCondition.makeCondition( - EntityCondition.makeCondition("sortThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, + EntityCondition.makeCondition("sortThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("sortThruDate", EntityOperator.GREATER_THAN_EQUAL_TO, productSearchContext.nowTimestamp))); if (ascending) { @@ -1980,14 +1980,14 @@ } if (priceTypeName == null) { priceTypeName = UtilProperties.getMessage(resource, "ProductPrice", locale) + " ("; - if (this.ascending) { + if (this.ascending) { priceTypeName += UtilProperties.getMessage(resource, "ProductLowToHigh", locale)+")"; } else { - priceTypeName += UtilProperties.getMessage(resource, "ProductHighToLow", locale)+")"; + priceTypeName += UtilProperties.getMessage(resource, "ProductHighToLow", locale)+")"; } } - - return priceTypeName; + + return priceTypeName; } public boolean isAscending() { Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java?rev=757089&r1=757088&r2=757089&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductSearchEvents.java Sat Mar 21 23:44:24 2009 @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -329,7 +329,7 @@ } } catch (GenericTransactionException e) { String errorMsg = UtilProperties.getMessage(resource, "productSearchEvents.error_getting_results", locale) + " : " + e.toString(); - request.setAttribute("_ERROR_MESSAGE_", errorMsg); + request.setAttribute("_ERROR_MESSAGE_", errorMsg); Debug.logError(e, errorMsg, module); return "error"; } @@ -379,7 +379,7 @@ } } catch (GenericTransactionException e) { String errorMsg = UtilProperties.getMessage(resource, "productSearchEvents.error_getting_results", locale) + " : " + e.toString(); - request.setAttribute("_ERROR_MESSAGE_", errorMsg); + request.setAttribute("_ERROR_MESSAGE_", errorMsg); Debug.logError(e, errorMsg, module); return "error"; } @@ -412,11 +412,11 @@ Map<String, Object> productMap = FastMap.newInstance(); String productId = searchResultView.getString("mainProductId"); productMap.put("productId", productId); - + List<GenericValue> productFeaturesCustomRaw = delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureTypeId", "HAZMAT") ); List<GenericValue> productFeaturesCustom = EntityUtil.filterByDate(productFeaturesCustomRaw); productMap.put("productFeatureCustom", EntityUtil.getFirst(productFeaturesCustom)); - + List<GenericValue> productCategoriesRaw = delegator.findByAnd("ProductCategoryAndMember", UtilMisc.toMap("productId", productId)); List<GenericValue> productCategories = EntityUtil.filterByDate(productCategoriesRaw); productMap.put("productCategories", productCategories); |
Free forum by Nabble | Edit this page |