Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-86

DSL string is having semi-colon added to //

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 5.5.1.Final, 6.0.0.Alpha9
    • 5.5.0.Final
    • None
    • Hide
      package droolssemicolon;
      
      import org.drools.KnowledgeBase;
      import org.drools.KnowledgeBaseFactory;
      import org.drools.builder.KnowledgeBuilder;
      import org.drools.builder.KnowledgeBuilderFactory;
      import org.drools.builder.ResourceType;
      import org.drools.io.ResourceFactory;
      import org.drools.runtime.StatefulKnowledgeSession;
      
      /**
       *
       * @author rambridg
       */
      public class Main {
      
          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              Main m = new Main();
              m.work();
          }
      
          public void work() {
      
              String str = "";
              str += "package droolssemicolon \n";
              str += "rule rule1 \n";
              str += "    dialect \"mvel\" \n";
              str += "when \n";
              str += "    Have a item \n";
              str += "then \n";
              str += "    setout 123 \n";
              str += "end \n";
      
              String dsl = "[when]Have a item=i : String()\n"
                      + "[then]setout {val}=String me=\"http://onefineday.{val}\";System.out.println(me)\n ";
      
              KnowledgeBase mykbase = KnowledgeBaseFactory.newKnowledgeBase();
              KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
              kbuilder.add(ResourceFactory.newByteArrayResource(dsl.getBytes()), ResourceType.DSL);
              kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DSLR);
      
              if (kbuilder.hasErrors()) {
                  throw new RuntimeException(kbuilder.getErrors().toString());
              }
      
              mykbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
              StatefulKnowledgeSession ksession = mykbase.newStatefulKnowledgeSession();
      
              String i="test";
              ksession.insert(i);
      
              ksession.fireAllRules();
          }
      }
      
      Show
      package droolssemicolon; import org.drools.KnowledgeBase; import org.drools.KnowledgeBaseFactory; import org.drools.builder.KnowledgeBuilder; import org.drools.builder.KnowledgeBuilderFactory; import org.drools.builder.ResourceType; import org.drools.io.ResourceFactory; import org.drools.runtime.StatefulKnowledgeSession; /** * * @author rambridg */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { Main m = new Main(); m.work(); } public void work() { String str = ""; str += "package droolssemicolon \n"; str += "rule rule1 \n"; str += " dialect \"mvel\" \n"; str += "when \n"; str += " Have a item \n"; str += "then \n"; str += " setout 123 \n"; str += "end \n"; String dsl = "[when]Have a item=i : String()\n" + "[then]setout {val}=String me=\"http://onefineday.{val}\";System.out.println(me)\n "; KnowledgeBase mykbase = KnowledgeBaseFactory.newKnowledgeBase(); KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); kbuilder.add(ResourceFactory.newByteArrayResource(dsl.getBytes()), ResourceType.DSL); kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DSLR); if (kbuilder.hasErrors()) { throw new RuntimeException(kbuilder.getErrors().toString()); } mykbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); StatefulKnowledgeSession ksession = mykbase.newStatefulKnowledgeSession(); String i="test"; ksession.insert(i); ksession.fireAllRules(); } }

      If the DSL has a statement like:
      "[then]setout

      {val}=String me=\"http://onefineday.{val}

      \";System.out.println(me)\n ";

      and a rule has: setout 123
      the result is http:;//onefineday.123
      notice the http:; <- semi colon added by drools

              mfusco@redhat.com Mario Fusco
              richardambridge_jira Richard Ambridge (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: