Search in sources :

Example 1 with ProcessServicesClient

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

the class LibraryClient method returnLoan.

boolean returnLoan(Loan loan) {
    ReturnRequest returnRequest = new ReturnRequest();
    returnRequest.setLoan(loan);
    ReturnResponse returnResponse;
    if (appcfg.getKieSession() != null) {
        KieSession kieSession = appcfg.getKieSession();
        WorkflowProcessInstance procinst = (WorkflowProcessInstance) kieSession.getProcessInstance(loan.getId());
        procinst.signalEvent("ReturnSignal", returnRequest);
        returnResponse = (ReturnResponse) procinst.getVariable("returnResponse");
    } else {
        ProcessServicesClient procserv = appcfg.getProcessServicesClient();
        procserv.signalProcessInstance("rhpam-kieserver-library", loan.getId(), "ReturnSignal", returnRequest);
        // returnResponse = (ReturnResponse)procserv.getProcessInstanceVariable("rhpam-kieserver-library", loan.getId(), "returnResponse");
        returnResponse = new ReturnResponse();
        returnResponse.setAcknowledged(true);
    }
    return returnResponse != null ? returnResponse.isAcknowledged() : false;
}
Also used : KieSession(org.kie.api.runtime.KieSession) ReturnRequest(org.openshift.quickstarts.rhpam.kieserver.library.types.ReturnRequest) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) ReturnResponse(org.openshift.quickstarts.rhpam.kieserver.library.types.ReturnResponse)

Example 2 with ProcessServicesClient

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

the class LibraryClient method attemptLoan.

Loan attemptLoan(String isbn) {
    Map<String, Object> parameters = new HashMap<String, Object>();
    LoanRequest loanRequest = new LoanRequest();
    loanRequest.setIsbn(isbn);
    parameters.put("loanRequest", loanRequest);
    LoanResponse loanResponse;
    if (appcfg.getKieSession() != null) {
        KieSession kieSession = appcfg.getKieSession();
        WorkflowProcessInstance procinst = (WorkflowProcessInstance) kieSession.startProcess("LibraryProcess", parameters);
        loanResponse = (LoanResponse) procinst.getVariable("loanResponse");
    } else {
        ProcessServicesClient procserv = appcfg.getProcessServicesClient();
        Long pid = procserv.startProcess("rhpam-kieserver-library", "LibraryProcess", parameters);
        loanResponse = (LoanResponse) procserv.getProcessInstanceVariable("rhpam-kieserver-library", pid, "loanResponse");
    }
    return loanResponse != null ? loanResponse.getLoan() : null;
}
Also used : LoanResponse(org.openshift.quickstarts.rhpam.kieserver.library.types.LoanResponse) HashMap(java.util.HashMap) KieSession(org.kie.api.runtime.KieSession) LoanRequest(org.openshift.quickstarts.rhpam.kieserver.library.types.LoanRequest) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) ProcessServicesClient(org.kie.server.client.ProcessServicesClient)

Example 3 with ProcessServicesClient

use of org.kie.server.client.ProcessServicesClient 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 4 with ProcessServicesClient

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

the class KieServerRestUtils method getProcessServicesClient.

public static ProcessServicesClient getProcessServicesClient(String username, String password) {
    KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(BASE_URL, username, password);
    List<String> capabilities = new ArrayList<String>();
    capabilities.add(KieServerConstants.CAPABILITY_BPM);
    config.setCapabilities(capabilities);
    config.setMarshallingFormat(MarshallingFormat.JSON);
    KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
    ProcessServicesClient processServiceClient = client.getServicesClient(ProcessServicesClient.class);
    return processServiceClient;
}
Also used : ArrayList(java.util.ArrayList) KieServicesConfiguration(org.kie.server.client.KieServicesConfiguration) KieServicesClient(org.kie.server.client.KieServicesClient) ProcessServicesClient(org.kie.server.client.ProcessServicesClient)

Example 5 with ProcessServicesClient

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

the class DemoTest method testRest.

public void testRest() throws Exception {
    KieServicesConfiguration config = KieServicesFactory.newRestConfiguration(BASE_URL, USERNAME, PASSWORD);
    List<String> capabilities = new ArrayList<String>();
    capabilities.add(KieServerConstants.CAPABILITY_BPM);
    config.setCapabilities(capabilities);
    config.setMarshallingFormat(MarshallingFormat.JSON);
    KieServicesClient client = KieServicesFactory.newKieServicesClient(config);
    ProcessServicesClient processServiceClient = client.getServicesClient(ProcessServicesClient.class);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("processVar1", "AAA1");
    params.put("processVar2", "BBB2");
    long processInstanceId = processServiceClient.startProcess(CONTAINER_ID, "project1.helloProcess", params);
    System.out.println("startProcess() : processInstanceId = " + processInstanceId);
    UserTaskServicesClient userTaskServiceClient = client.getServicesClient(UserTaskServicesClient.class);
    List<TaskSummary> taskList = userTaskServiceClient.findTasksAssignedAsPotentialOwner(USERNAME, 0, 100);
    for (TaskSummary taskSummary : taskList) {
        System.out.println("taskSummary.getId() = " + taskSummary.getId() + ", staus = " + taskSummary.getStatus());
        long taskId = taskSummary.getId();
        if (taskSummary.getStatus().equals("Reserved")) {
            userTaskServiceClient.startTask(CONTAINER_ID, taskId, USERNAME);
        }
        userTaskServiceClient.completeTask(CONTAINER_ID, taskId, USERNAME, null);
    }
}
Also used : HashMap(java.util.HashMap) UserTaskServicesClient(org.kie.server.client.UserTaskServicesClient) ArrayList(java.util.ArrayList) KieServicesConfiguration(org.kie.server.client.KieServicesConfiguration) KieServicesClient(org.kie.server.client.KieServicesClient) ProcessServicesClient(org.kie.server.client.ProcessServicesClient) TaskSummary(org.kie.server.api.model.instance.TaskSummary)

Aggregations

ProcessServicesClient (org.kie.server.client.ProcessServicesClient)21 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)7 KieServicesClient (org.kie.server.client.KieServicesClient)7 QueryServicesClient (org.kie.server.client.QueryServicesClient)7 ProcessDefinition (org.kie.server.api.model.definition.ProcessDefinition)6 KieServicesConfiguration (org.kie.server.client.KieServicesConfiguration)6 TaskSummary (org.kie.server.api.model.instance.TaskSummary)5 UserTaskServicesClient (org.kie.server.client.UserTaskServicesClient)5 ArrayList (java.util.ArrayList)4 KieSession (org.kie.api.runtime.KieSession)2 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)2 RuleServicesClient (org.kie.server.client.RuleServicesClient)2 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 HashSet (java.util.HashSet)1 RecordTooLargeException (org.apache.kafka.common.errors.RecordTooLargeException)1 BatchExecutionCommandImpl (org.drools.core.command.runtime.BatchExecutionCommandImpl)1 FireAllRulesCommand (org.drools.core.command.runtime.rule.FireAllRulesCommand)1