当前位置: 首页>>代码示例>>Java>>正文


Java Message类代码示例

本文整理汇总了Java中org.kie.api.builder.Message的典型用法代码示例。如果您正苦于以下问题:Java Message类的具体用法?Java Message怎么用?Java Message使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Message类属于org.kie.api.builder包,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createKJar

import org.kie.api.builder.Message; //导入依赖的package包/类
public static byte[] createKJar(ReleaseId releaseId, List<String> drls) {
    KieServices kieServices = KieServices.Factory.get();
    KieFileSystem kfs = kieServices.newKieFileSystem();
    kfs.generateAndWritePomXML(releaseId);
    drls.forEach(drl -> kfs.write("src/main/resources/" + drl.hashCode() + ".drl", drl));
    KieBuilder kb = kieServices.newKieBuilder(kfs).buildAll();
    if (kb.getResults().hasMessages(Message.Level.ERROR)) {
        for (Message result : kb.getResults().getMessages()) {
            System.out.println(result.getText());
        }
        return null;
    }
    InternalKieModule kieModule = (InternalKieModule) kieServices.getRepository().getKieModule(releaseId);
    byte[] jar = kieModule.getBytes();
    return jar;
}
 
开发者ID:barrykalok,项目名称:spring-boot-drools-example,代码行数:17,代码来源:RuleEngineUtil.java

示例2: loadContainerFromString

import org.kie.api.builder.Message; //导入依赖的package包/类
private  KieContainer loadContainerFromString(List<Rule> rules) {
    long startTime = System.currentTimeMillis();
    KieServices ks = KieServices.Factory.get();
    KieRepository kr = ks.getRepository();
    KieFileSystem kfs = ks.newKieFileSystem();

    for (Rule rule:rules) {
        String  drl=rule.getContent();
        kfs.write("src/main/resources/" + drl.hashCode() + ".drl", drl);
    }

    KieBuilder kb = ks.newKieBuilder(kfs);

    kb.buildAll();
    if (kb.getResults().hasMessages(Message.Level.ERROR)) {
        throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
    }
    long endTime = System.currentTimeMillis();
    System.out.println("Time to build rules : " + (endTime - startTime)  + " ms" );
    startTime = System.currentTimeMillis();
    KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
    endTime = System.currentTimeMillis();
    System.out.println("Time to load container: " + (endTime - startTime)  + " ms" );
    return kContainer;
}
 
开发者ID:ityouknow,项目名称:drools-examples,代码行数:26,代码来源:ReloadDroolsRulesService.java

示例3: logResults

import org.kie.api.builder.Message; //导入依赖的package包/类
public static void logResults(Results results) {
    for (Message result : results.getMessages()) {
        switch (result.getLevel()) {
            case ERROR:
                LOGGER.error(result.toString());
                break;
            case WARNING:
                LOGGER.warn(result.toString());
                break;
            case INFO:
                LOGGER.info(result.toString());
                break;
            default:
                LOGGER.warn(result.toString());
        }
    }
}
 
开发者ID:redhat-italy,项目名称:hacep,代码行数:18,代码来源:KieSessionUtils.java

示例4: updateToVersion

import org.kie.api.builder.Message; //导入依赖的package包/类
public boolean updateToVersion(String version) {
    checkStatus();
    if (StringUtils.isEmpty(version)) {
        throw new IllegalArgumentException("Update to version cannot accept an empty version");
    }
    ReleaseId releaseId = kieServices.newReleaseId(
            rulesConfiguration.getGroupId(),
            rulesConfiguration.getArtifactId(),
            version);
    Results results = kieContainer.updateToVersion(releaseId);
    this.releaseId = kieContainer.getReleaseId();
    KieSessionUtils.logResults(results);
    if (results.hasMessages(Message.Level.ERROR)) {
        LOGGER.error("Update to version {} aborted due to errors", version);
        return false;
    }
    LOGGER.info("Update to version {} completed", version);
    return true;
}
 
开发者ID:redhat-italy,项目名称:hacep,代码行数:20,代码来源:RulesManager.java

示例5: setup

import org.kie.api.builder.Message; //导入依赖的package包/类
@Before
public void setup() {
    KieServices kieServices = KieServices.Factory.get();

    KieContainer kContainer = kieServices.getKieClasspathContainer();
    Results verifyResults = kContainer.verify();
    for (Message m : verifyResults.getMessages()) {
        LOG.debug("Kie container message: {}", m);
    }

    KieBase kieBase = kContainer.getKieBase();
    LOG.debug("Created kieBase");

    for ( KiePackage kp : kieBase.getKiePackages() ) {
        for (Rule rule : kp.getRules()) {
            LOG.debug("kp " + kp + " rule " + rule.getName());
        }
    }

    session = kieBase.newKieSession();
    LOG.info(session.getGlobals().toString());
    Logger kieLogger = LoggerFactory.getLogger(this.getClass());
   // session.setGlobal("logger",kieLogger);
}
 
开发者ID:sabre1041,项目名称:iot-ocp,代码行数:25,代码来源:BaseTest.java

示例6: buildSession

import org.kie.api.builder.Message; //导入依赖的package包/类
/**
 * Load all .drl files
 *
 * if a rule does not compile an exception will be thrown indicating the problem
 *
 * @param path
 * @return - session containing all loaded rules
 * @throws Exception
 */
public KieSession buildSession() throws Exception {
  kieServices = KieServices.Factory.get();
  KieRepository kr = kieServices.getRepository();
  kfs = kieServices.newKieFileSystem();
  if(rules != null){
    loadFromList();
  }
  else{
    loadFromFiles();
  }
  kieBuilder = kieServices.newKieBuilder( kfs ).buildAll();
  Results results = kieBuilder.getResults();
  if( results.hasMessages( Message.Level.ERROR ) ){
      System.out.println( results.getMessages() );
      throw new IllegalStateException( results.getMessages() + "" );
  }
  kieContainer =
      kieServices.newKieContainer( kr.getDefaultReleaseId() );
  ksession = kieContainer.newKieSession();
  ksession.addEventListener(new RuleTracker());
  return ksession;
}
 
开发者ID:folio-org,项目名称:raml-module-builder,代码行数:32,代码来源:Rules.java

示例7: createKieContainer

import org.kie.api.builder.Message; //导入依赖的package包/类
private KieContainer createKieContainer(String... ruleFiles) {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);

    for (String ruleFile : ruleFiles) {
        InputStream ruleFileIs = DroolsTestSupport.class.getResourceAsStream("/" + ruleFile);
        Assert.assertNotNull("Can't open stream for rule file. Does it exist?", ruleFileIs);
        kfs.write(ks.getResources().newInputStreamResource(ruleFileIs).setSourcePath(ruleFile));
        try {
            ruleFileIs.close();
        } catch (IOException e) {
            throw new RuntimeException("InputStream of rule file could not be closed.");
        }
    }
    kieBuilder.buildAll();

    StringBuilder message = new StringBuilder();
    List<Message> messages = kieBuilder.getResults().getMessages();
    for (Message m : messages) {
        message.append(m.toString()).append("\n");
    }
    Assert.assertEquals(message.toString(), 0, messages.size());
    return ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
}
 
开发者ID:jeichler,项目名称:junit-drools,代码行数:26,代码来源:DroolsTestSupport.java

示例8: getKieSession

import org.kie.api.builder.Message; //导入依赖的package包/类
/** create empty knowledge base */
private KieSession getKieSession() {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    KieResources kieResources = ks.getResources();

    kfs.write(kieResources.newClassPathResource("getOlder.drl", getClass()).setResourceType(ResourceType.DRL));

    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();

    List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
    if (!errors.isEmpty()) {
        fail("" + errors);
    }

    return ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:18,代码来源:JsonQueryTest.java

示例9: registerKnowledgeRuntime

import org.kie.api.builder.Message; //导入依赖的package包/类
protected KieSession registerKnowledgeRuntime(String identifier, String rule) {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    KieResources kieResources = ks.getResources();

    if (rule != null && rule.length() > 0) {
        kfs.write("src/main/resources/rule.drl", rule);
    }

    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();

    List<Message> errors = kieBuilder.getResults().getMessages(Message.Level.ERROR);
    if (!errors.isEmpty()) {
        fail("" + errors);
    }

    KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();

    try {
        jndiContext.bind(identifier, ksession);
    } catch (NamingException e) {
        throw new RuntimeException(e);
    }

    return ksession;
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:27,代码来源:KieCamelTestSupport.java

示例10: convertMessage

import org.kie.api.builder.Message; //导入依赖的package包/类
static BuildMessage convertMessage(final Message message,
                                   Handles handles) {
    final BuildMessage m = new BuildMessage();
    switch (message.getLevel()) {
        case ERROR:
            m.setLevel(Level.ERROR);
            break;
        case WARNING:
            m.setLevel(Level.WARNING);
            break;
        case INFO:
            m.setLevel(Level.INFO);
            break;
    }

    m.setId(message.getId());
    m.setLine(message.getLine());
    m.setPath(convertPath(message.getPath(),
                          handles));
    m.setColumn(message.getColumn());
    m.setText(convertMessageText(message));
    return m;
}
 
开发者ID:kiegroup,项目名称:kie-wb-common,代码行数:24,代码来源:MessageConverter.java

示例11: drlSyntaxTest

import org.kie.api.builder.Message; //导入依赖的package包/类
@Test
public void drlSyntaxTest()
{
	  String str = "";
	    str += "package org.kie.test\n";
	    str += "global java.util.List list\n";
	    str += "rule rule1\n";
	    str += "when\n";
	    str += "  Integer(intValue > 0)\n";
	    str += "then\n";
	    str += "  list.add( 1 );\n";
	    str += "end\n";
	    str += "\n";
	    
	    Map<String,String> drls = new HashMap<String,String>();
	    drls.put("rule1", str);
	    
	KieHelper kieHelper = new KieHelper();
	for (String ruleId : drls.keySet()) {
	    kieHelper.addContent(drls.get(ruleId), ResourceType.DRL);
	}
	Results results = kieHelper.verify();
	for (Message message : results.getMessages()) {
	    log.error(">> Message ({}): {}", message.getLevel(), message.getText());
	}

	if (results.hasMessages(Message.Level.ERROR)) {
	    throw new IllegalStateException("There are errors in the KB.");
	}

	KieSession ksession = kieHelper.build().newKieSession();
}
 
开发者ID:genny-project,项目名称:rulesservice,代码行数:33,代码来源:KieTest.java

示例12: readFilenamesFromDirectory

import org.kie.api.builder.Message; //导入依赖的package包/类
private Boolean readFilenamesFromDirectory(String rootFilePath) {
	Boolean compileOk = true;
	final File folder = new File(rootFilePath);
	final File[] listOfFiles = folder.listFiles();

	for (int i = 0; i < listOfFiles.length; i++) {
		if (listOfFiles[i].isFile()) {
			System.out.println("File " + listOfFiles[i].getName());
			try {
				String ruleText = getFileAsText(listOfFiles[i]);
				KieHelper kieHelper = new KieHelper();
				kieHelper.addContent(ruleText, ResourceType.DRL);
				Results results = kieHelper.verify();
				for (Message message : results.getMessages()) {
					log.error(">> Message ({}): {}", message.getLevel(), message.getText());
					compileOk = false;
					assertTrue("Drools Compile Error in "+listOfFiles[i].getName(),false);
				}

			} catch (final IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		} else if (listOfFiles[i].isDirectory()) {
			System.out.println("Directory " + listOfFiles[i].getName());
			readFilenamesFromDirectory(rootFilePath+"/"+listOfFiles[i].getName());
		}
	}
	return compileOk;
}
 
开发者ID:genny-project,项目名称:rulesservice,代码行数:32,代码来源:RuleTest.java

示例13: addRuleSet

import org.kie.api.builder.Message; //导入依赖的package包/类
public void addRuleSet(String ruleSetName, File ruleSetDirectory) throws RuleExecutorException {
	// Create the in-memory File System and add the resources files  to it
	KieFileSystem kieFileSystem = kieServices.newKieFileSystem();

	try {
		final RuleLoader ruleLoader = new RuleLoader(kieFileSystem);
		Files.walkFileTree(ruleSetDirectory.toPath(), ruleLoader);
		int rulesLoaded = ruleLoader.getRulesLoaded();
		if (rulesLoaded == 0) {
			logger.warn("No rules loaded. Rules directory: {}", ruleSetDirectory.getAbsolutePath());
		} else {
			logger.info("{} rules loaded.", ruleLoader.getRulesLoaded());
			totalRulesLoaded += rulesLoaded;
		}
	} catch (IOException e) {
		throw new RuleExecutorException("Failed to load rule set " + ruleSetName, e);
	}

	// Create the builder for the resources of the File System
	KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);

	// Build the KieBases
	kieBuilder.buildAll();

	// Check for errors
	if (kieBuilder.getResults().hasMessages(Message.Level.ERROR)) {
		throw new RuleExecutorException(kieBuilder.getResults().toString());
	}

	// Get the Release ID (mvn style: groupId, artifactId,version)
	ReleaseId relId = kieBuilder.getKieModule().getReleaseId();

	// Create the Container, wrapping the KieModule with the given ReleaseId
	ruleSetContainers.put(ruleSetName, kieServices.newKieContainer(relId));
}
 
开发者ID:IHTSDO,项目名称:snomed-drools,代码行数:36,代码来源:RuleExecutor.java

示例14: assertBuildResults

import org.kie.api.builder.Message; //导入依赖的package包/类
private void assertBuildResults(Results results) {
    if (results.hasMessages(Message.Level.WARNING, Message.Level.ERROR)) {
        List<Message> messages = results.getMessages(Message.Level.WARNING, Message.Level.ERROR);
        for (Message message : messages) {
            System.out.printf("[%s] - %s[%s,%s]: %s", message.getLevel(), message.getPath(), message.getLine(), message.getColumn(), message.getText());
        }

        throw new IllegalStateException("Compilation errors were found. Check the logs.");
    }
}
 
开发者ID:Salaboy,项目名称:drools-workshop,代码行数:11,代码来源:PhreakInspector.java

示例15: DecisionTableKieBaseProvider

import org.kie.api.builder.Message; //导入依赖的package包/类
public DecisionTableKieBaseProvider() {
	KieServices kieServices = KieServices.Factory.get();
	KieRepository kieRepository = kieServices.getRepository();
	KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
	
	//addResource(kieFileSystem, "com.redhatbank.brms.tracktrace.model.SLACriteria.gdst");
	addResource(kieFileSystem, "org.acme.insurance.TestDS.xls");

	KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
	kieBuilder.buildAll();
	for (Message message : kieBuilder.getResults().getMessages()) {
		System.out.println(message);
	}
	kieContainer = kieServices.newKieContainer(kieRepository.getDefaultReleaseId());
}
 
开发者ID:anurag-saran,项目名称:sla-mgmt-brms,代码行数:16,代码来源:DecisionTableKieBaseProvider.java


注:本文中的org.kie.api.builder.Message类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。