Search in sources :

Example 11 with WorkItemManager

use of org.drools.core.process.instance.WorkItemManager in project jbpm by kiegroup.

the class ProcessServiceImpl method completeWorkItem.

@Override
public void completeWorkItem(String deploymentId, Long processInstanceId, Long id, Map<String, Object> results) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    results = process(results, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
    try {
        KieSession ksession = engine.getKieSession();
        WorkItem workItem = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItem(id);
        if (workItem == null) {
            throw new WorkItemNotFoundException("Work item with id " + id + " was not found");
        }
        ksession.getWorkItemManager().completeWorkItem(id, results);
    } catch (SessionNotFoundException e) {
        throw new ProcessInstanceNotFoundException("Process instance with id " + processInstanceId + " was not found", e);
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) WorkItemNotFoundException(org.jbpm.services.api.WorkItemNotFoundException) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) WorkItem(org.kie.api.runtime.process.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager) SessionNotFoundException(org.kie.internal.runtime.manager.SessionNotFoundException)

Example 12 with WorkItemManager

use of org.drools.core.process.instance.WorkItemManager in project jbpm by kiegroup.

the class RestGeoCodeApiCallWorkItemHandlerTest method FIXMEtestYahooGeoCode.

@Test
@Ignore
public void FIXMEtestYahooGeoCode() throws Exception {
    RestGeoCodeApiCallWorkItemHandler handler = new RestGeoCodeApiCallWorkItemHandler();
    Map<String, Object> queryParams = new HashMap<String, Object>();
    queryParams.put("URL", "http://local.yahooapis.com/");
    queryParams.put("Service", "MapsService/V1/");
    queryParams.put("Method", "geocode?");
    queryParams.put("appid", "TIpNDenV34Fwcw_x32k1eX6AlQzq4wajFEFvG501Pwc6w9jKEfy2vGnkIn.r5qSQqVvyhPPaTFo-");
    // Real parameters
    queryParams.put("street", "701+First+Ave");
    queryParams.put("city", "Sunnyvale");
    queryParams.put("state", "CA");
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setParameters(queryParams);
    WorkItemManager manager = new DefaultWorkItemManager(null);
    handler.executeWorkItem(workItem, manager);
    assertEquals(HttpURLConnection.HTTP_OK, handler.getHttpResponseCode());
    assertEquals(1, handler.getResults().size());
    assertEquals("US", ((ResultGeoCodeApi) handler.getResults().get(0)).getCountry());
}
Also used : DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) HashMap(java.util.HashMap) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) DefaultWorkItemManager(org.drools.core.process.instance.impl.DefaultWorkItemManager) WorkItemManager(org.drools.core.process.instance.WorkItemManager) Ignore(org.junit.Ignore) AbstractBaseTest(org.jbpm.test.AbstractBaseTest) Test(org.junit.Test)

Example 13 with WorkItemManager

use of org.drools.core.process.instance.WorkItemManager in project drools by kiegroup.

the class GetWorkItemIdsCommand method execute.

public List<Long> execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    Set<WorkItem> workItems = ((WorkItemManager) ksession.getWorkItemManager()).getWorkItems();
    List<Long> workItemIds = new ArrayList<Long>(workItems.size());
    for (WorkItem workItem : workItems) {
        workItemIds.add(workItem.getId());
    }
    if (this.outIdentifier != null) {
        ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, workItemIds);
    }
    return workItemIds;
}
Also used : ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.kie.internal.command.RegistryContext) WorkItem(org.drools.core.process.instance.WorkItem) WorkItemManager(org.drools.core.process.instance.WorkItemManager)

Aggregations

WorkItemManager (org.drools.core.process.instance.WorkItemManager)13 KieSession (org.kie.api.runtime.KieSession)8 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)6 WorkItem (org.drools.core.process.instance.WorkItem)4 Test (org.junit.Test)4 WorkItem (org.kie.api.runtime.process.WorkItem)4 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)3 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)3 WorkItemNotFoundException (org.jbpm.services.api.WorkItemNotFoundException)3 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)3 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)3 SessionNotFoundException (org.kie.internal.runtime.manager.SessionNotFoundException)3 HashMap (java.util.HashMap)2 WorkItemHandlerNotFoundException (org.drools.core.WorkItemHandlerNotFoundException)2 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)2 ProcessInstance (org.jbpm.process.instance.ProcessInstance)2 NodeInstance (org.kie.api.runtime.process.NodeInstance)2 TaskService (org.kie.api.task.TaskService)2