Search in sources :

Example 1 with RuleServicesClient

use of org.kie.server.client.RuleServicesClient in project rhpam-7-openshift-image by jboss-container-images.

the class HelloRulesClient method runRemote.

private void runRemote(HelloRulesCallback callback, KieServicesConfiguration config) {
    MarshallingFormat marshallingFormat = getMarshallingFormat();
    config.setMarshallingFormat(marshallingFormat);
    if (MarshallingFormat.JAXB.equals(marshallingFormat)) {
        Set<Class<?>> classes = new HashSet<Class<?>>();
        classes.add(Greeting.class);
        classes.add(Person.class);
        config.addExtraClasses(classes);
    }
    RuleServicesClient client = KieServicesFactory.newKieServicesClient(config).getServicesClient(RuleServicesClient.class);
    BatchExecutionCommand batch = createBatch();
    ServiceResponse<ExecutionResults> response = client.executeCommandsWithResults("rhpam-kieserver-decisions", batch);
    ExecutionResults execResults = response.getResult();
    handleResults(callback, execResults);
}
Also used : MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) ExecutionResults(org.kie.api.runtime.ExecutionResults) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) RuleServicesClient(org.kie.server.client.RuleServicesClient) HashSet(java.util.HashSet)

Example 2 with RuleServicesClient

use of org.kie.server.client.RuleServicesClient in project rhpam-7-openshift-image by jboss-container-images.

the class LibraryClient method runRemote.

private void runRemote(PrintWriter out, KieServicesConfiguration kiecfg) throws Exception {
    appcfg.setKieSession(null);
    MarshallingFormat marshallingFormat = appcfg.getMarshallingFormat();
    out.println(String.format("Using %s MarshallingFormat.%s", marshallingFormat.getType(), marshallingFormat.name()));
    kiecfg.setMarshallingFormat(marshallingFormat);
    if (MarshallingFormat.JAXB.equals(marshallingFormat)) {
        Set<Class<?>> classes = new HashSet<Class<?>>();
        classes.add(Book.class);
        classes.add(Loan.class);
        classes.add(LoanRequest.class);
        classes.add(LoanResponse.class);
        classes.add(ReturnRequest.class);
        classes.add(ReturnResponse.class);
        classes.add(Suggestion.class);
        classes.add(SuggestionRequest.class);
        classes.add(SuggestionResponse.class);
        kiecfg.addExtraClasses(classes);
    }
    KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(kiecfg);
    RuleServicesClient ruleServicesClient = kieServicesClient.getServicesClient(RuleServicesClient.class);
    ProcessServicesClient processServicesClient = kieServicesClient.getServicesClient(ProcessServicesClient.class);
    appcfg.setRuleServicesClient(ruleServicesClient);
    appcfg.setProcessServicesClient(processServicesClient);
    runApp(out);
}
Also used : MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) KieServicesClient(org.kie.server.client.KieServicesClient) RuleServicesClient(org.kie.server.client.RuleServicesClient) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) HashSet(java.util.HashSet)

Example 3 with RuleServicesClient

use of org.kie.server.client.RuleServicesClient in project kiegroup-examples by tkobayas.

the class StatelessTest method testRule.

@Test
public void testRule() {
    KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(BASE_URL, USERNAME, PASSWORD);
    HashSet<Class<?>> classes = new HashSet<Class<?>>();
    classes.add(Person.class);
    config.addExtraClasses(classes);
    config.setMarshallingFormat(MarshallingFormat.JSON);
    KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
    RuleServicesClient ruleClient = client.getServicesClient(RuleServicesClient.class);
    List<Command<?>> commands = new ArrayList<Command<?>>();
    KieCommands commandsFactory = KieServices.Factory.get().getCommands();
    commands.add(commandsFactory.newInsert(Integer.valueOf(10), "fact-10"));
    commands.add(commandsFactory.newFireAllRules("fire-result"));
    BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands, KSESSION_NAME);
    ServiceResponse<ExecutionResults> response = ruleClient.executeCommandsWithResults(CONTAINER_ID, batchExecution);
    System.out.println("-----------------------------------");
    System.out.println(response);
// No need to dispose stateless ksession
}
Also used : KieCommands(org.kie.api.command.KieCommands) ExecutionResults(org.kie.api.runtime.ExecutionResults) ArrayList(java.util.ArrayList) KieServicesConfiguration(org.kie.server.client.KieServicesConfiguration) KieServicesClient(org.kie.server.client.KieServicesClient) RuleServicesClient(org.kie.server.client.RuleServicesClient) Command(org.kie.api.command.Command) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with RuleServicesClient

use of org.kie.server.client.RuleServicesClient in project kiegroup-examples by tkobayas.

the class StatelessTestInteger method testRule.

@Test
public void testRule() {
    KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(BASE_URL, USERNAME, PASSWORD);
    HashSet<Class<?>> classes = new HashSet<Class<?>>();
    classes.add(Person.class);
    config.addExtraClasses(classes);
    config.setMarshallingFormat(MarshallingFormat.JSON);
    KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
    RuleServicesClient ruleClient = client.getServicesClient(RuleServicesClient.class);
    List<Command<?>> commands = new ArrayList<Command<?>>();
    KieCommands commandsFactory = KieServices.Factory.get().getCommands();
    commands.add(commandsFactory.newInsert(Integer.valueOf(10), "fact-10"));
    commands.add(commandsFactory.newFireAllRules("fire-result"));
    BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands, KSESSION_NAME);
    ServiceResponse<ExecutionResults> response = ruleClient.executeCommandsWithResults(CONTAINER_ID, batchExecution);
    System.out.println("-----------------------------------");
    System.out.println(response);
// No need to dispose stateless ksession
}
Also used : KieCommands(org.kie.api.command.KieCommands) ExecutionResults(org.kie.api.runtime.ExecutionResults) ArrayList(java.util.ArrayList) KieServicesConfiguration(org.kie.server.client.KieServicesConfiguration) KieServicesClient(org.kie.server.client.KieServicesClient) RuleServicesClient(org.kie.server.client.RuleServicesClient) Command(org.kie.api.command.Command) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with RuleServicesClient

use of org.kie.server.client.RuleServicesClient in project kiegroup-examples by tkobayas.

the class StatelessTestOrig method testRule.

@Test
public void testRule() {
    KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(BASE_URL, USERNAME, PASSWORD);
    HashSet<Class<?>> classes = new HashSet<Class<?>>();
    classes.add(Person.class);
    config.addExtraClasses(classes);
    KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
    RuleServicesClient ruleClient = client.getServicesClient(RuleServicesClient.class);
    List<Command<?>> commands = new ArrayList<Command<?>>();
    KieCommands commandsFactory = KieServices.Factory.get().getCommands();
    Person person = new Person("John", 36);
    commands.add(commandsFactory.newSetGlobal(GLOBAL_IDENTIFIER, new ArrayList<>()));
    commands.add(commandsFactory.newInsert(person, "fact-" + person.getName()));
    commands.add(commandsFactory.newFireAllRules("fire-result"));
    commands.add(commandsFactory.newGetGlobal(GLOBAL_IDENTIFIER));
    BatchExecutionCommand batchExecution = commandsFactory.newBatchExecution(commands, KSESSION_NAME);
    ServiceResponse<ExecutionResults> response = ruleClient.executeCommandsWithResults(CONTAINER_ID, batchExecution);
    System.out.println("-----------------------------------");
    System.out.println(response);
    List<Object> results = (List<Object>) response.getResult().getValue(GLOBAL_IDENTIFIER);
    System.out.println("results = " + results);
// No need to dispose stateless ksession
}
Also used : KieCommands(org.kie.api.command.KieCommands) ExecutionResults(org.kie.api.runtime.ExecutionResults) ArrayList(java.util.ArrayList) KieServicesConfiguration(org.kie.server.client.KieServicesConfiguration) KieServicesClient(org.kie.server.client.KieServicesClient) RuleServicesClient(org.kie.server.client.RuleServicesClient) Command(org.kie.api.command.Command) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) BatchExecutionCommand(org.kie.api.command.BatchExecutionCommand) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

RuleServicesClient (org.kie.server.client.RuleServicesClient)30 ArrayList (java.util.ArrayList)25 ExecutionResults (org.kie.api.runtime.ExecutionResults)24 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)23 Command (org.kie.api.command.Command)23 KieCommands (org.kie.api.command.KieCommands)22 KieServicesClient (org.kie.server.client.KieServicesClient)18 KieServicesConfiguration (org.kie.server.client.KieServicesConfiguration)17 HashSet (java.util.HashSet)16 Test (org.junit.Test)10 List (java.util.List)9 HashMap (java.util.HashMap)2 MarshallingFormat (org.kie.server.api.marshalling.MarshallingFormat)2 ProcessServicesClient (org.kie.server.client.ProcessServicesClient)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Map (java.util.Map)1 BatchExecutionCommandImpl (org.drools.core.command.runtime.BatchExecutionCommandImpl)1 FireAllRulesCommand (org.drools.core.command.runtime.rule.FireAllRulesCommand)1