gpt4 book ai didi

java - ATG 创建组件并动态设置日志记录

转载 作者:行者123 更新时间:2023-11-30 07:12:59 26 4
gpt4 key购买 nike

我正在使用 ATG 9.4 并尝试修改我们的促销引擎,以便我们可以设置每个促销的过滤器属性,而不是直接在全局 QualifierService 上设置。

基本上,我所做的就是为 QualifierService 上可用的每个过滤器标志添加属性到 Item Discount 存储库项目。然后我对 ItemDiscountCalculator 进行了子类化并重写了priceItems()。我从 pPricingModel 读取标志,构造一个新的 Qualifier 对象,并将其放入带有键 ItemDiscountCalculator.EXTRA_PARAM_QUALIFIERSERVICE 的 pExtraParameters 映射中。然后我调用 super.priceItems()

这对于我想要做的事情 100% 完美 - 但是,当我构造新的 Qualifier 时,我使用 setLoggingXXX 方法来反射(reflect)全局 QualifierService 上的任何级别,但是这些新对象没有记录.

我认为这与用 Nucleus 注册对象以及它使用的任何日志组件有关,但我无法找到注册它们所需的操作,或者至少允许 Qualifier 执行其操作自然伐木。

以下是相关代码行:

@Override
@SuppressWarnings("unchecked")
public void priceItems(List pPriceQuotes, List pItems, RepositoryItem pPricingModel, Locale pLocale, RepositoryItem pProfile, Order pOrder, Map pExtraParameters) throws PricingException {
if (isLoggingTrace())
logTrace("Entry - CustomItemDiscountCalculator.priceItems()");

Qualifier qualifierService = getQualifierService(pPricingModel);

if (pExtraParameters == null) {
pExtraParameters = new HashMap();
}

pExtraParameters.put(ItemDiscountCalculator.EXTRA_PARAM_QUALIFIERSERVICE, qualifierService);

super.priceItems(pPriceQuotes, pItems, pPricingModel, pLocale, pProfile, pOrder, pExtraParameters);

if (isLoggingTrace())
logTrace("Exit - CustomItemDiscountCalculator.priceItems()");
}

private Qualifier getQualifierService(RepositoryItem pPricingModel) {
if (isLoggingTrace())
logTrace("Entry - CustomItemDiscountCalculator.getQualifierService()");

Qualifier qualifierService = new Qualifier();

/* Get global component at /atg/commerce/pricing/QualifierService */
Qualifier defaultQualifierService = getQualifierService();

/* Shallow clone the global QualifierService component */
qualifierService.setPMDLCache(defaultQualifierService.getPMDLCache());
qualifierService.setClosenessQualifierItemDescriptorName(defaultQualifierService.getClosenessQualifierItemDescriptorName());
qualifierService.setExactlyPromotionLoopThrough(defaultQualifierService.isExactlyPromotionLoopThrough());
qualifierService.setLoggingDebug(defaultQualifierService.isLoggingDebug());
qualifierService.setLoggingError(defaultQualifierService.isLoggingError());
qualifierService.setLoggingInfo(defaultQualifierService.isLoggingInfo());
qualifierService.setLoggingTrace(defaultQualifierService.isLoggingTrace());
qualifierService.setLoggingWarning(defaultQualifierService.isLoggingWarning());
qualifierService.setNucleus(defaultQualifierService.getNucleus());
qualifierService.setPricingModelProperties(defaultQualifierService.getPricingModelProperties());
qualifierService.setPricingModelRepository(defaultQualifierService.getPricingModelRepository());
qualifierService.setServiceInfo(defaultQualifierService.getServiceInfo());

/* Set any promotion specific qualifier properties */
Boolean curFilterValue;
if (isLoggingDebug()) {
logDebug("Setting qualifier properties for promo: " + pPricingModel);
}

curFilterValue = (Boolean) pPricingModel.getPropertyValue("filterForQualifierDiscountedByAnyDiscountId");
qualifierService.setFilterForQualifierDiscountedByAnyDiscountId(curFilterValue);

// ... copy the rest of the QualifierService filters

if (isLoggingTrace())
logTrace("Exit - CustomItemDiscountCalculator.getQualifierService()");
return qualifierService;
}

最佳答案

LogListener[] logListeners = defaultQualifierService.getLogListeners();
for (LogListener[] logListener : logListeners) {
qualifierService.addLogListener(logListener);
}

关于java - ATG 创建组件并动态设置日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38880802/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com