我正在使用 Drools 和 Liferay,当规则为真时,我试图在 BD 中插入用户,但 Drools 不允许我导入包。我没有 .drl 类,我传递一个字符串来执行流口水。这是我的代码:
代码流口水:
import com.liferay.portal.kernel.search.BooleanClause;
import com.liferay.portal.kernel.search.BooleanClauseOccur;
import com.liferay.portal.kernel.search.BooleanClauseFactoryUtil;
import com.liferay.portal.kernel.search.BooleanQuery;
import com.liferay.portal.kernel.search.BooleanQueryFactoryUtil;
import com.liferay.portal.kernel.search.Document;
import com.liferay.portal.kernel.search.Field;
import com.liferay.portal.kernel.search.Hits;
import com.liferay.portal.kernel.search.Indexer;
import com.liferay.portal.kernel.search.IndexerRegistryUtil;
import com.liferay.portal.kernel.search.SearchContext;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.KeyValuePair;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.Address;
import com.liferay.portal.model.Group;
import com.liferay.portal.model.Contact;
import com.liferay.portal.model.User;
import com.liferay.portal.service.AddressLocalServiceUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.asset.model.AssetEntry;
import com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil;
import com.liferay.portal.model.User;
import com.liferay.portal.security.auth.PrincipalThreadLocal;
import com.liferay.portal.security.permission.PermissionChecker;
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil;
import com.liferay.portal.security.permission.PermissionThreadLocal;
import com.liferay.portal.kernel.util.ObjectValuePair;
import com.liferay.portlet.expando.model.ExpandoBridge;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.segmentationPortlet.controller.prova;
rule "Initialize Rules"
salience 1000
when
user : User();
then
end
rule "Rule_1"
when
userRule_2: User(emailAddress == "test@liferay.com")
user: User();
then
prova p;
p.classification(user,"SegmentUser");
end
执行 Drools 的代码;//rule 是一个带有 Drools 代码的字符串。ThemeDisplay td = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); 用户用户 = td.getUser(); fact.add(new Fact ("user", user));
RulesResourceRetriever rulesResourceRetriever = new RulesResourceRetriever(new StringResourceRetriever(rule), String.valueOf(RulesLanguage. RulesEngineUtil.update(domainName, rulesResourceRetriever, PortalClassLoaderUtil.getClassLoader());
RulesEngineUtil.execute(domainName, facts, Query.createStandardQuery(), PortalClassLoaderUtil.getClassLoader());`
prova.java 代码:包 com.segmentationPortlet.controller;
import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.model.User;
import com.segmentationPortlet.model.UserRule;
import com.segmentationPortlet.service.UserRuleLocalServiceUtil;
import com.segmentationPortlet.service.persistence.UserRulePK;
public class prova {
public void classification(User user, String segmentValue) {
try {
UserRule ur = null ;
long id1 = CounterLocalServiceUtil.increment(UserRule.class.getName());
long id2 = CounterLocalServiceUtil.increment(UserRule.class.getName());
UserRulePK u = new UserRulePK(id1, id2);
ur= UserRuleLocalServiceUtil.createUserRule(u);
Long id = (long) 1234;
ur.setUserId(user.getUserId());
ur.setRuleId(id);
ur.setSegment(segmentValue);
UserRuleLocalServiceUtil.addUserRule(ur);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}`
当我尝试执行时出现此错误:
引起:com.liferay.portal.kernel.bi.rules.RulesEngineException:导入错误:'com.segmentationPortlet.controller.prova' 导入错误:'com.segmentationPortlet.controller.Classification.classification' 导入错误:'com.segmentationPortlet .controller.GetCustomAttribute.getCustomAttribute' [ function getCustomAttributegetCustomAttribute (line:53): 只能导入一个类型。com.segmentationPortlet.controller.prova 解析为一个包] [函数分类分类(line:35):只能导入一个类型。com.segmentationPortlet.controller.prova 解析为一个包] [ function getCustomAttributegetCustomAttribute (line:53): 只能导入一个类型。com.segmentationPortlet.controller.prova 解析为一个包]
关于如何解决问题的任何想法?
非常感谢。