Package org.drools.command

Examples of org.drools.command.KnowledgeContextResolveFromContextCommand


        List cmds = new ArrayList();
        cmds.add(new InsertObjectCommand(new String("Hi!"), "handle"));
                                                                                                                
        BatchExecutionCommand batchCmd = CommandFactory.newBatchExecution(cmds, "kresults");
        ExecuteCommand execCmd = new ExecuteCommand(batchCmd,true);
        KnowledgeContextResolveFromContextCommand resolveFromContextCommand = new KnowledgeContextResolveFromContextCommand(execCmd,  
                                                                                        null,null,"ksession","localResults");
        ExecutionResults results = (ExecutionResults)commandService.execute(resolveFromContextCommand);
       
        assertNotNull(results);
       
        assertNotNull(results.getFactHandle("handle"));
       
        assertTrue(((DefaultFactHandle)results.getFactHandle("handle")).isDisconnected());
       
       
       
        cmds = new ArrayList();
        cmds.add(new InsertObjectCommand(new String("Hi!"), "handle"));
        batchCmd = CommandFactory.newBatchExecution(cmds, "kresults");
        execCmd = new ExecuteCommand(batchCmd);
        resolveFromContextCommand = new KnowledgeContextResolveFromContextCommand(execCmd,  
                                                                                        null,null,"ksession","localResults");
        results = (ExecutionResults)commandService.execute(resolveFromContextCommand);
       
        assertNotNull(results);
       
View Full Code Here


       
        BatchExecutionCommand batchCmd = CommandFactory.newBatchExecution(cmds, "kresults");
        ExecuteCommand execCmd = new ExecuteCommand(batchCmd,true);
       
       
        KnowledgeContextResolveFromContextCommand resolveFromContextCommand = new KnowledgeContextResolveFromContextCommand(execCmd,
                null, null, "ksession", "localResults");
        ExecutionResults results = (ExecutionResults) commandService.execute(resolveFromContextCommand);

        // I'm not expecting any results here
        assertNotNull(results);

        GetVariableCommand getVariableCmd = new GetVariableCommand("query123", "__TEMP__");
        resolveFromContextCommand = new KnowledgeContextResolveFromContextCommand(getVariableCmd,
                null, null, "ksession", "localResults");
        NativeQueryResults queryResults = (NativeQueryResults) commandService.execute(resolveFromContextCommand);

        assertNotNull(queryResults);
View Full Code Here

        commandService = new DefaultCommandService(kContext);
       
        QueryCommand queryCommand = new QueryCommand("out", "myQuery", new Object[]{});
        SetVariableCommandFromCommand setVariableCmd = new SetVariableCommandFromCommand("__TEMP__", "query123", queryCommand);
       
        KnowledgeContextResolveFromContextCommand resolveFromContextCommand = new KnowledgeContextResolveFromContextCommand(setVariableCmd,
                null, null, "ksession", "localResults");
        ExecutionResults results = (ExecutionResults) commandService.execute(resolveFromContextCommand);

        // I'm not expecting any results here
        assertNull(results);

        GetVariableCommand getVariableCmd = new GetVariableCommand("query123", "__TEMP__");
        resolveFromContextCommand = new KnowledgeContextResolveFromContextCommand(getVariableCmd,
                null, null, "ksession", "localResults");
        NativeQueryResults queryResults = (NativeQueryResults) commandService.execute(resolveFromContextCommand);

        assertNotNull(queryResults);
View Full Code Here

        cmds.add( new SetVariableCommand( "path1",
                                          "kbuilder",
                                          new NewKnowledgeBuilderCommand( null ) ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBuilderAddCommand( ResourceFactory.newByteArrayResource( str.getBytes() ),
                                                                                                 ResourceType.DRL,
                                                                                                 null ),
                                                                 "kbuilder",
                                                                 null,
                                                                 null, null ) );

        cmds.add( new SetVariableCommand( "path1",
                                          "kbase",
                                          new NewKnowledgeBaseCommand( null ) ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 null, null ) );

        KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
        ksessionConf.setOption( ClockTypeOption.get( "pseudo" ) );

        cmds.add( new SetVariableCommand( "path1",
                                          "ksession",
                                          new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionCommand( ksessionConf ),
                                                                                         "kbuilder",
                                                                                         "kbase",
                                                                                         null, null ) ) );

        List list = new ArrayList();

        cmds.add( new KnowledgeContextResolveFromContextCommand( new SetGlobalCommand( "list",
                                                                                       list ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        steps.add( new StepImpl( path,
                                 cmds,
                                 0 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "darth",
                                                                                                      97 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 2000 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "yoda",
                                                                                                      98 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 4000 ) );

        cmds = new ArrayList<Command>();

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check List size",
                                                                                   2,
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "size()" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "darth",
                                                                                               97 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 0 )" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "yoda",
                                                                                               98 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 1 )" ),
                                                                 "kbuilder",
View Full Code Here

        cmds.add( new SetVariableCommand( "ROOT",
                                          "kbuilder",
                                          new NewKnowledgeBuilderCommand( null ) ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBuilderAddCommand( ResourceFactory.newByteArrayResource( str.getBytes() ),
                                                                                                 ResourceType.DRL,
                                                                                                 null ),
                                                                 "kbuilder",
                                                                 null,
                                                                 null, null ) );

        cmds.add( new SetVariableCommand( "ROOT",
                                          "kbase",
                                          new NewKnowledgeBaseCommand( null ) ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 null, null ) );

        KnowledgeSessionConfiguration ksessionConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
        ksessionConf.setOption( ClockTypeOption.get( "pseudo" ) );

        cmds.add( new SetVariableCommand( "ROOT",
                                          "ksession",
                                          new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionCommand( ksessionConf ),
                                                                                         "kbuilder",
                                                                                         "kbase",
                                                                                         null, null ) ) );

        List list = new ArrayList();

        cmds.add( new KnowledgeContextResolveFromContextCommand( new SetGlobalCommand( "list",
                                                                                       list ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        steps.add( new StepImpl( path,
                                 cmds,
                                 0 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "darth",
                                                                                                      97 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 2000 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "yoda",
                                                                                                      98 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 4000 ) );

        path.setSteps( steps );

        simulation.getPaths().put( "path1",
                                   path );

        path = new PathImpl( simulation,
                             "path2" );

        steps = new ArrayList<Step>();

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "bobba",
                                                                                                      77 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 1500 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "luke",
                                                                                                      30 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 2200 ) );

        cmds = new ArrayList<Command>();
        cmds.add( new KnowledgeContextResolveFromContextCommand( new InsertObjectCommand( new Person( "ben",
                                                                                                      150 ) ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        cmds.add( new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand(),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );
        steps.add( new StepImpl( path,
                                 cmds,
                                 4500 ) );

        cmds = new ArrayList<Command>();

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check List size",
                                                                                   5,
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "size()" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "bobba",
                                                                                               77 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 0 )" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "darth",
                                                                                               97 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 1 )" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "luke",
                                                                                               30 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 2 )" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "yoda",
                                                                                               98 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 3 )" ),
                                                                 "kbuilder",
                                                                 "kbase",
                                                                 "ksession", null ) );

        cmds.add( new KnowledgeContextResolveFromContextCommand( new AssertEquals( "Check Person",
                                                                                   new Person( "ben",
                                                                                               150 ),
                                                                                   new GetGlobalCommand( "list" ),
                                                                                   "get( 4 )" ),
                                                                 "kbuilder",
View Full Code Here

        String kuilderInstanceId = ((CollectionClient<KnowledgePackage>) kpackages).getParentInstanceId();
        Message msg = new Message( messageSession.getSessionId(),
                                   messageSession.counter.incrementAndGet(),
                                   false,
                                   new KnowledgeContextResolveFromContextCommand( new KnowledgeBaseAddKnowledgePackagesCommand(),
                                                                                  kuilderInstanceId,
                                                                                  instanceId,
                                                                                  null,
                                                                                  kresultsId ) );
       
View Full Code Here

        Message msg = new Message( messageSession.getSessionId(),
                                   messageSession.counter.incrementAndGet(),
                                   false,
                                   new SetVariableCommand( "__TEMP__",
                                                           localId,
                                                           new KnowledgeContextResolveFromContextCommand( new NewStatefulKnowledgeSessionCommand( null ),
                                                                                                          null,
                                                                                                          instanceId,
                                                                                                          null,
                                                                                                          kresultsId ) ) );
View Full Code Here

  public void completeWorkItem(long id, Map<String, Object> results) {
    String kresultsId = "kresults_" + messageSession.getSessionId();
        Message msg = new Message( messageSession.getSessionId(),
                                   messageSession.counter.incrementAndGet(),
                                   true,
                                   new KnowledgeContextResolveFromContextCommand( new CompleteWorkItemCommand(id, results),
                                                                                  null,
                                                                                  null,
                                                                                  instanceId,
                                                                                  kresultsId ) );
        try {
View Full Code Here

        String kresultsId = "kresults_" + messageSession.getSessionId();

        Message msg = new Message( messageSession.getSessionId(),
                                   messageSession.counter.incrementAndGet(),
                                   false,
                                   new KnowledgeContextResolveFromContextCommand( new FireAllRulesCommand( commandId ),
                                                                                  null,
                                                                                  null,
                                                                                  instanceId,
                                                                                  kresultsId ) );
        try {
View Full Code Here

        String kresultsId = "kresults_" + messageSession.getSessionId();

        Message msg = new Message( messageSession.getSessionId(),
                                   messageSession.counter.incrementAndGet(),
                                   false,
                                   new KnowledgeContextResolveFromContextCommand( new ExecuteCommand( commandId,
                                                                                                      command ),
                                                                                  null,
                                                                                  null,
                                                                                  instanceId,
                                                                                  kresultsId ) );
View Full Code Here

TOP

Related Classes of org.drools.command.KnowledgeContextResolveFromContextCommand

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.