org.kie.api.builder.Message类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(13.4k)|赞(0)|评价(0)|浏览(277)

本文整理了Java中org.kie.api.builder.Message类的一些代码示例,展示了Message类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message类的具体详情如下:
包路径:org.kie.api.builder.Message
类名称:Message

Message介绍

[英]A Message generated by the building process of a KieModule
[中]由模块的构建过程生成的消息

代码示例

代码示例来源:origin: kiegroup/jbpm

protected InternalKieModule createKieJar(KieServices ks, ReleaseId releaseId, List<String> resources ) {
   
  KieFileSystem kfs = createKieFileSystemWithKProject(ks);
  kfs.writePomXML( getPom(releaseId) );
  
  for (String resource : resources) {
    kfs.write("src/main/resources/rules/" + resource, ResourceFactory.newClassPathResource(resource));
  }
  KieBuilder kieBuilder = ks.newKieBuilder(kfs);
  if (!kieBuilder.buildAll().getResults().getMessages().isEmpty()) {
    for (Message message : kieBuilder.buildAll().getResults().getMessages()) {
      logger.error("Error Message: ({}) {}", message.getPath(), message.getText());
    }
    throw new RuntimeException(
        "There are errors builing the package, please check your knowledge assets!");
  }
  
  return ( InternalKieModule ) kieBuilder.getKieModule();
}

代码示例来源:origin: org.drools/drools-compiler

@Test
public void testDSLExpansion_MessageImplNPE() throws Exception {
  final KieServices ks = KieServices.Factory.get();
  final ReleaseId releaseId = ks.newReleaseId( "org.kie", "dsl-test", "1.0" );
  final KieModuleModel kproj = ks.newKieModuleModel();
  final KieFileSystem kfs = ks.newKieFileSystem();
  kfs.writeKModuleXML( kproj.toXML() )
      .writePomXML( generatePomXml( releaseId ) )
      .write( "src/main/resources/KBase1/test-dsl.dsl", createDSL() )
      .write( "src/main/resources/KBase1/test-rule.dslr", createDRL() );
  final KieBuilder kieBuilder = ks.newKieBuilder( kfs );
  final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
  if ( !messages.isEmpty() ) {
    for ( final Message m : messages ) {
      System.out.println( m.getText() );
    }
  }
  assertTrue( messages.isEmpty() );
}

代码示例来源:origin: org.drools/drools-reteoo

public static byte[] createKJar(KieServices ks,
                ReleaseId releaseId,
                String pom,
                String... drls) {
  KieFileSystem kfs = ks.newKieFileSystem();
  if( pom != null ) {
    kfs.write("pom.xml", pom);
  } else {
    kfs.generateAndWritePomXML(releaseId);
  }
  for (int i = 0; i < drls.length; i++) {
    if (drls[i] != null) {
      kfs.write("src/main/resources/r" + i + ".drl", drls[i]);
    }
  }
  KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
  if( kb.getResults().hasMessages( org.kie.api.builder.Message.Level.ERROR ) ) {
    for( org.kie.api.builder.Message result : kb.getResults().getMessages() ) {
      System.out.println(result.getText());
    }
    return null;
  }
  InternalKieModule kieModule = (InternalKieModule) ks.getRepository()
                            .getKieModule(releaseId);
  byte[] jar = kieModule.getBytes();
  return jar;
}

代码示例来源:origin: org.drools/drools-compiler

public static byte[] buildKJar(KieServices ks, KieFileSystem kfs, ReleaseId releaseId) {
  KieBuilder kb = ks.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) ks.getRepository()
      .getKieModule(releaseId);
  byte[] jar = kieModule.getBytes();
  return jar;
}

代码示例来源:origin: wyh-spring-ecosystem-student/spring-boot-student

/**
 * 加载KieContainer容器
 */
public static KieContainer loadKieContainer() throws RuntimeException {
  //通过kmodule.xml 找到规则文件,这个文件默认放在resources/META-INF文件夹
  log.info("准备创建 KieContainer");
  if (kieContainer == null) {
    log.info("首次创建:KieContainer");
    // 设置drools的日期格式
    System.setProperty("drools.dateformat", "yyyy-MM-dd HH:mm:ss");
    //线程安全
    synchronized (DroolsUtil.class) {
      if (kieContainer == null) {
        // 创建Container
        kieContainer = kieServices.getKieClasspathContainer();
        // 检查规则文件是否有错
        Results results = kieContainer.verify();
        if (results.hasMessages(Message.Level.ERROR)) {
          StringBuffer sb = new StringBuffer();
          for (Message mes : results.getMessages()) {
            sb.append("解析错误的规则:").append(mes.getPath()).append(" 错误位置:").append(mes.getLine()).append(";");
          }
          throw new RuntimeException(sb.toString());
        }
      }
    }
  }
  log.info("KieContainer创建完毕");
  return kieContainer;
}

代码示例来源:origin: secbr/drools

protected static KieSession getKieSessionByDrl(String drlContent) {
  KieHelper kieHelper = new KieHelper();
  kieHelper.addContent(drlContent, ResourceType.DRL);
  Results verify = kieHelper.verify();
  boolean hasMessages = verify.hasMessages(Message.Level.WARNING, Message.Level.ERROR);
  if (hasMessages) {
    List<Message> messages = verify.getMessages(Message.Level.WARNING, Message.Level.ERROR);
    for (Message message : messages) {
      System.out.println("ERROR : " + message.getText());
    }
    throw new RuntimeException("verify has errors!");
  }
  return kieHelper.build().newKieSession();
}

代码示例来源:origin: deepu105/drools-demo

private static String prettyBuildMessage(Message msg) {
  return "Message: {"
    + "id="+ msg.getId()
    + ", level=" + msg.getLevel()
    + ", path=" + msg.getPath()
    + ", line=" + msg.getLine()
    + ", column=" + msg.getColumn()
    + ", text=\"" + msg.getText() + "\""
    + "}";
}

代码示例来源:origin: org.kie/kie-dmn-core

@Test
public void testAPIUsage() {
  // DROOLS-3335 Broken DMN resource should inhibit KJAR and report KieBuilder message
  final KieServices ks = KieServices.Factory.get();
  final KieContainer kieContainer = DMNRuntimeUtil.getKieContainerIgnoringErrors(ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.0"),
                                          ks.getResources().newClassPathResource("incomplete_expression.dmn", this.getClass()),
                                          ks.getResources().newClassPathResource("duff.drl", this.getClass()));
  Results verify = kieContainer.verify();
  List<Message> kie_messages = verify.getMessages();
  kie_messages.forEach(m -> LOG.info("{}", m));
  assertThat(kie_messages.size(), is(3));
  assertThat(kie_messages.stream().filter(m -> m.getPath().equals("duff.drl")).count(), is(2L));
  List<DMNMessage> dmnMessages = kie_messages.stream()
                        .filter(DMNMessage.class::isInstance)
                        .map(DMNMessage.class::cast)
                        .collect(Collectors.toList());
  assertThat(dmnMessages.size(), is(1));
  DMNMessage dmnMessage = dmnMessages.get(0);
  assertThat(dmnMessage.getSourceId(), is("_c990c3b2-e322-4ef9-931d-79bcdac99686"));
  assertThat(dmnMessage.getMessageType(), is(DMNMessageType.ERR_COMPILING_FEEL));
  assertThat(dmnMessage.getPath(), is("incomplete_expression.dmn"));
}

代码示例来源:origin: secbr/drools

public static void main(String[] args) {
    KieServices kieServices = KieServices.Factory.get();

    KieContainer container = kieServices.getKieClasspathContainer();

    Results results = container.verify();
    List<Message> messages = results.getMessages();
    System.out.println("messages size:" + messages.size());
    for (Message msg : messages) {
      System.out.println("level:" + msg.getLevel() + ";text=" + msg.getText());
    }

    Collection<String> kieBaseNames = container.getKieBaseNames();
    for(String kieBaseName : kieBaseNames){
      System.out.println("kieBaseName----" + kieBaseName);
      Collection<String> kieSessionNamesInKieBase = container.getKieSessionNamesInKieBase(kieBaseName);
      for(String kieSession : kieSessionNamesInKieBase){
        System.out.println("kieSession-----" + kieSession);
      }
    }

  }
}

代码示例来源:origin: stackoverflow.com

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();

代码示例来源:origin: org.kie.guvnor/guvnor-commons-builder

public IncrementalBuildResults addResource( final Path resource ) {
  //Check a full build has been performed
  if ( !isBuilt() ) {
    throw new IllegalStateException( "A full build needs to be performed before any incremental operations." );
  }
  //Add new resource
  final String destinationPath = resource.toUri().toString().substring( projectPrefix.length() + 1 );
  final InputStream is = ioService.newInputStream( resource );
  final BufferedInputStream bis = new BufferedInputStream( is );
  kieFileSystem.write( destinationPath,
             KieServices.Factory.get().getResources().newInputStreamResource( bis ) );
  handles.put( destinationPath,
         paths.convert( resource ) );
  //Incremental build
  final IncrementalResults incrementalResults = ( (InternalKieBuilder) kieBuilder ).createFileSet( destinationPath ).build();
  //Messages from incremental build
  final IncrementalBuildResults results = convertMessages( incrementalResults );
  //Tidy-up removed message handles
  for ( Message message : incrementalResults.getRemovedMessages() ) {
    handles.remove( RESOURCE_PATH + "/" + message.getPath() );
  }
  return results;
}

代码示例来源:origin: org.kie.server/kie-server-services-common

public boolean verify(KieContainer container) {
  boolean verified = true;
  try {
    Results results = container.verify();
    for (Message message : results.getMessages()) {
      Level level = message.getLevel();
      switch (level) {
        case INFO:
          logger.info(message.toString());
          break;
        case WARNING:
          logger.warn(message.toString());
          break;
        case ERROR:
          logger.error(message.toString());
          verified = false;
          break;
      }
    }
  } catch (Throwable t) {
    logger.error(t.getMessage(), t);
    verified = false;
  }
  return verified;
}

代码示例来源:origin: stackoverflow.com

if(logger.isDebugEnable()) {
  for(Message mess:list) {
     logger.debug("mess:" + mess.getText());
  }
}

代码示例来源:origin: stackoverflow.com

mFirebaseAdapter = new FirebaseRecyclerAdapter<Message, MessageViewHolder>(
     Message.class,
     R.layout.item_message,
     MessageViewHolder.class,
     mFirebaseDatabaseReference.child(MESSAGES_CHILD)) {
   @Override
   protected void populateViewHolder(final MessageViewHolder viewHolder, Message friendlyMessage, int position) {
     viewHolder.messageTextView.setText(friendlyMessage.getText());
     viewHolder.messengerTextView.setText(friendlyMessage.getName());
     if (friendlyMessage.getPhotoUrl() == null) {
       viewHolder.messengerImageView.setImageDrawable(ContextCompat.getDrawable(MessageActivity.this,
           R.drawable.profilepic_placeholder));
     } else {
       Glide.with(MessageActivity.this)
           .load(friendlyMessage.getPhotoUrl())
           .into(viewHolder.messengerImageView);
     }
   }
 };

代码示例来源:origin: stackoverflow.com

SimpleDateFormat ru = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", new Locale("ru"));
  ru.setTimeZone(TimeZone.getTimeZone("GMT+03:00"));
  Date jud = ru.parse(mLastMessage.getDate());
  String targetFormat = new SimpleDateFormat("d MMMM, HH:mm", new Locale("ru")).format(jud);
  final long milliseconds = jud.getTime();
holder.message.setText(Helpers.stringLimit(Helpers.stripLineBreaks(mLastMessage.getText(), " "), 50));
  if(mLastMessage.getSender_type().equals(Constants.CLIENT_TYPE)) {
    holder.setClientWaiting();
  } else {

代码示例来源:origin: stackoverflow.com

holder.textView.setText(m.getText());
  previousTs = pm.getTimeStamp();
setTimeTextVisibility(m.getTimeStamp(), previousTs, holder.timeText);

代码示例来源:origin: stackoverflow.com

public void onUpdateReceived(Update update) {
  Message message = update.getMessage();
  Long chatId = message.getChatId();
  String input = message.getText();
  if ("/recommendPizza".equals(input)) {
    SendMessage request = new SendMessage();

代码示例来源:origin: org.kie.guvnor/guvnor-commons-builder

public IncrementalBuildResults deleteResource( final Path resource ) {
  //Check a full build has been performed
  if ( !isBuilt() ) {
    throw new IllegalStateException( "A full build needs to be performed before any incremental operations." );
  }
  //Delete resource
  final String destinationPath = resource.toUri().toString().substring( projectPrefix.length() + 1 );
  kieFileSystem.delete( destinationPath );
  //Incremental build
  final IncrementalResults incrementalResults = ( (InternalKieBuilder) kieBuilder ).createFileSet( destinationPath ).build();
  //Messages from incremental build
  final IncrementalBuildResults results = convertMessages( incrementalResults );
  //Tidy-up removed message handles
  for ( Message message : incrementalResults.getRemovedMessages() ) {
    handles.remove( RESOURCE_PATH + "/" + message.getPath() );
  }
  return results;
}

代码示例来源:origin: org.kie.workbench.services/kie-wb-common-services-backend

private void buildIncrementally(final IncrementalBuildResults results,
                final String... destinationPath) {
  try {
    final IncrementalResults incrementalResults = ((InternalKieBuilder) kieBuilder).createFileSet(destinationPath).build();
    results.addAllAddedMessages(convertMessages(incrementalResults.getAddedMessages(),
                          handles));
    results.addAllRemovedMessages(convertMessages(incrementalResults.getRemovedMessages(),
                           handles));
    //Tidy-up removed message handles
    for (Message message : incrementalResults.getRemovedMessages()) {
      handles.remove(Handles.RESOURCE_PATH + "/" + getBaseFileName(message.getPath()));
    }
  } catch (LinkageError e) {
    final String msg = MessageFormat.format(ERROR_CLASS_NOT_FOUND,
                        e.getLocalizedMessage());
    logger.warn(msg);
    results.addAddedMessage(makeWarningMessage(msg));
  } catch (Throwable e) {
    final String msg = e.getLocalizedMessage();
    logger.error(msg,
           e);
    results.addAddedMessage(makeErrorMessage(msg));
  }
}

代码示例来源:origin: org.drools/drools-compiler

@Test
public void testDSLExpansion_NoExpansion() throws Exception {
  final KieServices ks = KieServices.Factory.get();
  final ReleaseId releaseId = ks.newReleaseId( "org.kie", "dsl-test", "1.0" );
  final KieModuleModel kproj = ks.newKieModuleModel();
  final KieFileSystem kfs = ks.newKieFileSystem();
  kfs.writeKModuleXML( kproj.toXML() )
      .writePomXML( generatePomXml( releaseId ) )
      .write( "src/main/resources/KBase1/test-dsl.dsl", createDSL() )
      .write( "src/main/resources/KBase1/test-rule.drl", createDRL() );
  final KieBuilder kieBuilder = ks.newKieBuilder( kfs );
  final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
  if ( !messages.isEmpty() ) {
    for ( final Message m : messages ) {
      System.out.println( m.getText() );
    }
  }
  assertFalse( messages.isEmpty() );
}

相关文章