📄 productsearch.java
字号:
public static class CategoryConstraint extends ProductSearchConstraint { public static final String constraintName = "Category"; protected String productCategoryId; protected boolean includeSubCategories; public CategoryConstraint(String productCategoryId, boolean includeSubCategories) { this.productCategoryId = productCategoryId; this.includeSubCategories = includeSubCategories; } public void addConstraint(ProductSearchContext productSearchContext) { List productCategoryIdList = null; if (includeSubCategories) { // find all sub-categories recursively, make a Set of productCategoryId Set productCategoryIdSet = new HashSet(); ProductSearch.getAllSubCategoryIds(productCategoryId, productCategoryIdSet, productSearchContext.getDelegator(), productSearchContext.nowTimestamp); productCategoryIdList = new ArrayList(productCategoryIdSet); } else { productCategoryIdList = UtilMisc.toList(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); productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "ThruDate", "thruDate", null, null, null, null); productSearchContext.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); productSearchContext.entityConditionList.add(new EntityExpr(prefix + "ProductCategoryId", EntityOperator.IN, productCategoryIdList)); productSearchContext.entityConditionList.add(new EntityExpr(new EntityExpr(prefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr(prefix + "ThruDate", EntityOperator.GREATER_THAN, productSearchContext.nowTimestamp))); productSearchContext.entityConditionList.add(new EntityExpr(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.productCategoryId, "includeSubCategories", this.includeSubCategories ? "Y" : "N"))); } /** pretty print for log messages and even UI stuff */ public String prettyPrintConstraint(GenericDelegator delegator, boolean detailed) { GenericValue productCategory = null; try { productCategory = delegator.findByPrimaryKeyCache("ProductCategory", UtilMisc.toMap("productCategoryId", productCategoryId)); } catch (GenericEntityException e) { Debug.logError(e, "Error finding ProductCategory information for constraint pretty print", module); } StringBuffer ppBuf = new StringBuffer(); ppBuf.append("Category: "); if (productCategory != null) { ppBuf.append(productCategory.getString("description")); } if (productCategory == null || detailed) { ppBuf.append(" ["); ppBuf.append(productCategoryId); ppBuf.append("]"); } if (includeSubCategories) { ppBuf.append(" (and all sub-categories)"); } return ppBuf.toString(); } public boolean equals(Object obj) { ProductSearchConstraint psc = (ProductSearchConstraint) obj; if (psc instanceof CategoryConstraint) { CategoryConstraint that = (CategoryConstraint) psc; if (this.includeSubCategories != that.includeSubCategories) { return false; } if (this.productCategoryId == null) { if (that.productCategoryId != null) { return false; } } else { if (!this.productCategoryId.equals(that.productCategoryId)) { return false; } } return true; } else { return false; } } } public static class FeatureConstraint extends ProductSearchConstraint { public static final String constraintName = "Feature"; protected String productFeatureId; public FeatureConstraint(String productFeatureId) { this.productFeatureId = productFeatureId; } public void addConstraint(ProductSearchContext productSearchContext) { // make index based values and increment String entityAlias = "PFA" + productSearchContext.index; String prefix = "pfa" + productSearchContext.index; productSearchContext.index++; productSearchContext.dynamicViewEntity.addMemberEntity(entityAlias, "ProductFeatureAppl"); productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "ProductFeatureId", "productFeatureId", null, null, null, null); productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "FromDate", "fromDate", null, null, null, null); productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "ThruDate", "thruDate", null, null, null, null); productSearchContext.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); productSearchContext.entityConditionList.add(new EntityExpr(prefix + "ProductFeatureId", EntityOperator.EQUALS, productFeatureId)); productSearchContext.entityConditionList.add(new EntityExpr(new EntityExpr(prefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr(prefix + "ThruDate", EntityOperator.GREATER_THAN, productSearchContext.nowTimestamp))); productSearchContext.entityConditionList.add(new EntityExpr(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.productFeatureId))); } public String prettyPrintConstraint(GenericDelegator delegator, boolean detailed) { GenericValue productFeature = null; GenericValue productFeatureType = null; try { productFeature = delegator.findByPrimaryKeyCache("ProductFeature", UtilMisc.toMap("productFeatureId", productFeatureId)); productFeatureType = productFeature == null ? null : productFeature.getRelatedOne("ProductFeatureType"); } catch (GenericEntityException e) { Debug.logError(e, "Error finding ProductFeature and Type information for constraint pretty print", module); } return (productFeatureType == null ? "Feature: " : productFeatureType.getString("description") + ": ") + (productFeature == null ? "[" + this.productFeatureId + "]" : productFeature.getString("description")); } 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; } } return true; } else { return false; } } } public static class FeatureSetConstraint extends ProductSearchConstraint { public static final String constraintName = "Feature Set"; protected Set productFeatureIdSet; public FeatureSetConstraint(Collection productFeatureIdSet) { this.productFeatureIdSet = new HashSet(productFeatureIdSet); } public void addConstraint(ProductSearchContext productSearchContext) { // make index based values and increment String entityAlias = "PFA" + productSearchContext.index; String prefix = "pfa" + productSearchContext.index; productSearchContext.index++; productSearchContext.dynamicViewEntity.addMemberEntity(entityAlias, "ProductFeatureAppl"); productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "ProductFeatureId", "productFeatureId", null, null, null, null); productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "FromDate", "fromDate", null, null, null, null); productSearchContext.dynamicViewEntity.addAlias(entityAlias, prefix + "ThruDate", "thruDate", null, null, null, null); productSearchContext.dynamicViewEntity.addViewLink("PROD", entityAlias, Boolean.FALSE, ModelKeyMap.makeKeyMapList("productId")); productSearchContext.entityConditionList.add(new EntityExpr(prefix + "ProductFeatureId", EntityOperator.IN, productFeatureIdSet)); productSearchContext.entityConditionList.add(new EntityExpr(new EntityExpr(prefix + "ThruDate", EntityOperator.EQUALS, null), EntityOperator.OR, new EntityExpr(prefix + "ThruDate", EntityOperator.GREATER_THAN, productSearchContext.nowTimestamp))); productSearchContext.entityConditionList.add(new EntityExpr(prefix + "FromDate", EntityOperator.LESS_THAN, productSearchContext.nowTimestamp)); // add in productSearchConstraint, don't worry about the productSearchResultId or constraintSeqId, those will be fill in later StringBuffer featureIdInfo = new StringBuffer(); Iterator featureIdIter = this.productFeatureIdSet.iterator(); while (featureIdIter.hasNext()) { String featureId = (String) featureIdIter.next(); featureIdInfo.append(featureId); if (featureIdIter.hasNext()) { featureIdInfo.append(","); } } productSearchContext.productSearchConstraintList.add(productSearchContext.getDelegator().makeValue("ProductSearchConstraint", UtilMisc.toMap("constraintName", constraintName, "infoString", featureIdInfo.toString()))); } public String prettyPrintConstraint(GenericDelegator delegator, boolean detailed) { StringBuffer infoOut = new StringBuffer(); try { Iterator featureIdIter = this.productFeatureIdSet.iterator(); while (featureIdIter.hasNext()) { String featureId = (String) featureIdIter.next(); GenericValue productFeature = delegator.findByPrimaryKeyCache("ProductFeature", UtilMisc.toMap("productFeatureId", featureId)); GenericValue productFeatureType = productFeature == null ? null : productFeature.getRelatedOneCache("ProductFeatureType"); if (productFeatureType == null) { infoOut.append("Feature: "); } else { infoOut.append(productFeatureType.getString("description")); infoOut.append(": "); } if (productFeature == null) { infoOut.append("["); infoOut.append(featureId); infoOut.append("]"); } else { infoOut.append(productFeature.getString("description")); } if (featureIdIter.hasNext()) { infoOut.append(", "); } } } catch (GenericEntityException e) { Debug.logError(e, "Error finding ProductFeature and Type information for constraint pretty print", module); } return infoOut.toString(); } public boolean equals(Object obj) { ProductSearchConstraint psc = (ProductSearchConstraint) obj; if (psc instanceof FeatureConstraint) { FeatureSetConstraint that = (FeatureSetConstraint) psc; if (this.productFeatureIdSet == null) { if (that.productFeatureIdSet != null) { return false; } } else { if (!this.productFeatureIdSet.equals(that.productFeatureIdSet)) { return false; } } return true; } else { return false; } } } public static class KeywordConstraint extends ProductSearchConstraint { public static final String constraintName = "Keyword"; protected String keywordsString; protected boolean anyPrefix; protected boolean anySuffix; protected boolean isAnd; protected boolean removeStems; public KeywordConstraint(String keywordsString, boolean anyPrefix, boolean anySuffix, Boolean removeStems, boolean isAnd) { this.keywordsString = keywordsString; this.anyPrefix = anyPrefix; this.anySuffix = anySuffix; this.isAnd = isAnd; if (removeStems != null) { this.removeStems = removeStems.booleanValue(); } else { this.removeStems = UtilProperties.propertyValueEquals("prodsearch", "remove.stems", "true"); } } public Set makeFullKeywordSet(GenericDelegator delegator) { Set keywordSet = KeywordSearch.makeKeywordSet(this.keywordsString, null, true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -