本文整理汇总了Java中org.drools.builder.KnowledgeBuilder.hasErrors方法的典型用法代码示例。如果您正苦于以下问题:Java KnowledgeBuilder.hasErrors方法的具体用法?Java KnowledgeBuilder.hasErrors怎么用?Java KnowledgeBuilder.hasErrors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.drools.builder.KnowledgeBuilder
的用法示例。
在下文中一共展示了KnowledgeBuilder.hasErrors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addKnowledgePackages
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
private void addKnowledgePackages(KnowledgeBaseWrapper knowledgeBaseWrapper, DroolsRuleAddEvent droolsRuleAddEvent, String ruleName) {
String resourceType = droolsRuleAddEvent.getOriginalResourceType();
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(new PackageBuilderConfiguration(properties));
kbuilder.add(ResourceFactory.newByteArrayResource(droolsRuleAddEvent.getRuleBytes()), ResourceType.getResourceType(resourceType));
if(kbuilder.hasErrors()) {
for(KnowledgeBuilderError error : kbuilder.getErrors()) {
log.error(error.getMessage() + " on lines " + Arrays.toString(error.getLines()));
}
throw new IllegalArgumentException("Could not parse Rule: " + ruleName + " type: " + resourceType);
}
knowledgeBaseWrapper.getKnowledgeBase().addKnowledgePackages(kbuilder.getKnowledgePackages());
knowledgeBaseWrapper.setTotalRules(knowledgeBaseWrapper.getTotalRules() + 1);
}
示例2: getKnowlegeBase
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
private static KnowledgeBase getKnowlegeBase(List<EntityRuleDO> rules) {
if (rules == null || rules.size() == 0) {
return null;
}
StringBuilder sb = new StringBuilder();
for (EntityRuleDO entityRuleDO : rules) {
sb.append(entityRuleDO.getRule()).append("\n");
}
KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
config.setOption(EvaluatorOption.get("startsWith", new StartsWithEvaluatorDefinition()));
config.setOption(EvaluatorOption.get("endsWith", new EndsWithEvaluatorDefinition()));
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
kbuilder.add(ResourceFactory.newByteArrayResource(sb.toString().getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
throw new ServiceException("Problem building cross field validation rules: " + kbuilder.getErrors());
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
示例3: beforeClass
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() {
KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
config.setOption(EvaluatorOption.get("endsWith", new EndsWithEvaluatorDefinition()));
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
kbuilder.add(ResourceFactory.newClassPathResource("net/techreadiness/rules/ends-with.drl"), ResourceType.DRL);
if (kbuilder.hasErrors()) {
throw new ServiceException("Problem building cross field validation rules: " + kbuilder.getErrors());
}
knowlegeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowlegeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
}
示例4: beforeClass
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() {
KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
config.setOption(EvaluatorOption.get("startsWith", new StartsWithEvaluatorDefinition()));
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
kbuilder.add(ResourceFactory.newClassPathResource("net/techreadiness/rules/starts-with-map-reference.drl"),
ResourceType.DRL);
if (kbuilder.hasErrors()) {
throw new ServiceException("Problem building cross field validation rules.");
}
knowlegeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowlegeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
}
示例5: beforeClass
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() {
KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
config.setOption(EvaluatorOption.get("startsWith", new StartsWithEvaluatorDefinition()));
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
kbuilder.add(ResourceFactory.newClassPathResource("net/techreadiness/rules/starts-with-map.drl"), ResourceType.DRL);
if (kbuilder.hasErrors()) {
kbuilder.getErrors();
throw new ServiceException("Problem building cross field validation rules.");
}
knowlegeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowlegeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
}
示例6: beforeClass
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() {
KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
config.setOption(EvaluatorOption.get("endsWith", new EndsWithEvaluatorDefinition()));
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
kbuilder.add(ResourceFactory.newClassPathResource("net/techreadiness/rules/ends-with-map.drl"), ResourceType.DRL);
if (kbuilder.hasErrors()) {
KnowledgeBuilderErrors errors = kbuilder.getErrors();
throw new ServiceException("Problem building cross field validation rules: " + errors);
}
knowlegeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowlegeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
}
示例7: beforeClass
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() {
KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
config.setOption(EvaluatorOption.get("startsWith", new StartsWithEvaluatorDefinition()));
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
kbuilder.add(ResourceFactory.newClassPathResource("net/techreadiness/rules/starts-with.drl"), ResourceType.DRL);
if (kbuilder.hasErrors()) {
throw new ServiceException("Problem building cross field validation rules.");
}
knowlegeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowlegeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
}
示例8: beforeClass
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() {
KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
config.setOption(EvaluatorOption.get("endsWith", new EndsWithEvaluatorDefinition()));
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
kbuilder.add(ResourceFactory.newClassPathResource("net/techreadiness/rules/ends-with-map-reference.drl"),
ResourceType.DRL);
if (kbuilder.hasErrors()) {
kbuilder.getErrors();
throw new ServiceException("Problem building cross field validation rules.");
}
knowlegeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowlegeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
}
示例9: getKnowledgeBuilder
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
private static KnowledgeBuilder getKnowledgeBuilder(String rulePackagePath,
String droolsEngineName) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
changesetPath = "./";
createChangeSetInfo(rulePackagePath, droolsEngineName, true);
engineResource = ResourceFactory.newFileResource(changesetPath
+ droolsEngineName + ".xml");
kbuilder.add(engineResource, ResourceType.CHANGE_SET);
if (kbuilder.hasErrors()) {
startUpError = true;
Iterator<KnowledgeBuilderError> ite = kbuilder.getErrors()
.iterator();
while (ite.hasNext()) {
logger.error(ite.next().getMessage());
}
return null;
} else {
return kbuilder;
}
}
示例10: getKnowledgeBuilder
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
private static KnowledgeBuilder getKnowledgeBuilder(String rulePackagePath,
String droolsEngineName) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
changesetPath = "var/";
createChangeSetInfo(rulePackagePath, droolsEngineName, true);
engineResource = ResourceFactory.newFileResource(changesetPath
+ droolsEngineName + ".xml");
kbuilder.add(engineResource, ResourceType.CHANGE_SET);
if (kbuilder.hasErrors()) {
Iterator<KnowledgeBuilderError> ite = kbuilder.getErrors()
.iterator();
while (ite.hasNext()) {
log.error(ite.next().getMessage());
}
return null;
} else {
return kbuilder;
}
}
示例11: initSession
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
@Produces
@Named("node1")
public GridNode initSession() {
log.info("Creating drools kbase");
GridNode node = new GridNodeImpl();
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("testRule.drl"), ResourceType.DRL);
if (kbuilder.hasErrors()) {
if (kbuilder.getErrors().size() > 0) {
for (KnowledgeBuilderError kerror : kbuilder.getErrors()) {
log.error(kerror.getMessage());
}
throw new RuntimeException(kbuilder.getErrors().toString());
}
}
node.set("ksession1", kbuilder.newKnowledgeBase().newStatelessKnowledgeSession());
return node;
}
示例12: createKnowledgeBase
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
private KnowledgeBase createKnowledgeBase() {
log().debug("createKnowledgeBase: Creating Drools KnowledgeBase");
final Properties props = new Properties();
props.setProperty("drools.dialect.java.compiler.lnglevel", "1.6");
final PackageBuilderConfiguration conf = new PackageBuilderConfiguration(props);
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(conf);
// Use the rules file defined in the configuration file
// We will not throw an exception if the rules failed to be parsed
builder.add(ResourceFactory.newFileResource(m_configDao.getRulesFile()), ResourceType.DRL);
if( builder.hasErrors() ) {
log().error("Failed to create Drools KnowledgeBase: " + builder.getErrors().toString());
return null;
}
KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());
return knowledgeBase;
}
示例13: testDroolsFrameLoader
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
@Test
@Ignore
public void testDroolsFrameLoader() throws Exception {
// build the knowledge base
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newClassPathResource( "/gov/va/cpe/vpr/frames/HelloWorldAlert.drl", getClass()), ResourceType.DRL );
if ( kbuilder.hasErrors() ) {
fail(kbuilder.getErrors().toString());
}
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
// add it to the frame registry
FrameRegistry.DroolsFrameLoader loader = new DroolsFrameLoader(kbase);
List<IFrame> frames = loader.load();
assertEquals(1, frames.size());
assertTrue(frames.get(0) instanceof DroolsFrameAdapter);
DroolsFrameAdapter frame = (DroolsFrameAdapter) frames.get(0);
// create the patient, modify the name
PatientDemographics p = POMUtils.newInstance(PatientDemographics.class, PatientDemographicsImporter.class.getResourceAsStream("patient.json"));
p.setData("givenNames", "FOO");
p.setData("familyName", "BAR");
FrameRegistry registry = new FrameRegistry(loader);
FrameRunner runner = new FrameRunner(registry);
FrameJob job = runner.exec(new ArrayList<IFrameEvent<?>>(p.getEvents()));
assertEquals(2, job.getActions().size());
FrameAction action = job.getActions().get(1);
System.out.println(job.getActions());
assertTrue(action instanceof PatientAlert);
PatientAlert aa = (PatientAlert) action;
assertEquals("drools alert", aa.getTitle());
assertEquals(p.getSsn(), aa.getDescription());
}
示例14: buildKnowledgeSession
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
public final void buildKnowledgeSession() {
if (ksession == null) {
LOG.debug("Building Drools Knowledge Session");
// initialise the rules
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
// pickup the rules file from the classpath
// this will parse and compile in one step
LOG.info("Loading rules file " + rulesFileName);
kbuilder.add( ResourceFactory.newClassPathResource( rulesFileName, QaRecommendationServiceImpl.class ),
ResourceType.DRL );
// Check the builder for errors
if ( kbuilder.hasErrors() ) {
LOG.error(kbuilder.getErrors().toString());
throw new RuntimeException( "Unable to compile \"" + rulesFileName + "\"." );
}
// add the packages to a knowledgebase (deploy the knowledge packages).
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
// set the knowledge session
ksession = kbase.newStatefulKnowledgeSession();
// set the configured message formats and advice
ksession.setGlobal("globals", globals);
}
}
示例15: check
import org.drools.builder.KnowledgeBuilder; //导入方法依赖的package包/类
private static void check(KnowledgeBuilder builder) {
if (builder.hasErrors()) {
for (KnowledgeBuilderError error : builder.getErrors())
System.out.println(error.toString());
System.exit(-1);
}
}