public Context getProcessInstanceByCorrelationKey(CorrelationKey correlationKey, EntityManager em) { Query processInstancesForEvent = em.createNamedQuery( "GetProcessInstanceIdByCorrelation" ); processInstancesForEvent.setParameter( "ckey", correlationKey.toExternalForm()); try { return ProcessInstanceIdContext.get((Long) processInstancesForEvent.getSingleResult()); } catch (NonUniqueResultException e) { return null; } catch (NoResultException e) { return null; } }
/** * This method has been made "static"ally available so that * non-JAXB code does not have to (unnecesarily) instantiate * an instance fo this class. * * @param key A {@link CorrelationKey} * @return A {@link String} equivalent of the key */ public static String marshalCorrelationKey( CorrelationKey key ) { if( key == null ) { return ""; } StringBuffer result = new StringBuffer(); if( ! key.getProperties().isEmpty() ) { Iterator<CorrelationProperty<?>> iter = key.getProperties().iterator(); CorrelationProperty<?> prop = iter.next(); if( prop != null ) { result.append(prop.getValue().toString()); } while( iter.hasNext() ) { prop = iter.next(); if( prop != null ) { result.append(":").append(prop.getValue().toString()); } } } return result.toString(); }
= (org.drools.core.command.runtime.process.GetProcessInstanceByCorrelationKeyCommand) serviceReq.getCommands().get(0); List<CorrelationProperty<?>> corrProps = realGpicbckCmd.getCorrelationKey().getProperties(); assertEquals( "Number of correlation properties in request", 2, corrProps.size()); assertEquals( "Correlation property value in request", corrPropVal1, corrProps.get(0).getValue());
@Override public ProcessInstanceLogQueryBuilder correlationKey(CorrelationKey... correlationKeys) { String[] correlationKeysExternal = new String[correlationKeys.length]; for (int i = 0; i < correlationKeys.length; i++) { correlationKeysExternal[i] = correlationKeys[i].toExternalForm(); } addObjectParameter(CORRELATION_KEY_LIST, "correlation key", correlationKeysExternal); return this; }
/** * With regards to locking, the method is not always called during a transaction, which means * that including logic to lock the query will cause exceptions and is not feasible. * </p> * However, this is not an issue: see the {@link #getProcessInstancesWaitingForEvent(String)} documentation * for more information. The same logic applies to this method. * </p> */ public Long getProcessInstanceByCorrelationKey(CorrelationKey correlationKey) { Query processInstancesForEvent = getEntityManager().createNamedQuery( "GetProcessInstanceIdByCorrelation" ); processInstancesForEvent.setParameter( "ckey", correlationKey.toExternalForm()); try { return (Long) processInstancesForEvent.getSingleResult(); } catch (NonUniqueResultException e) { return null; } catch (NoResultException e) { return null; } }
public String getCorrelationKey() { if (correlationKey == null && getMetaData().get("CorrelationKey") != null) { this.correlationKey = ((CorrelationKey) getMetaData().get("CorrelationKey")).toExternalForm(); } return correlationKey; }
@Override public AuditEvent buildEvent(ProcessStartedEvent pse) { ProcessInstanceImpl pi = (ProcessInstanceImpl) pse.getProcessInstance(); ProcessInstanceLog log = new ProcessInstanceLog(pi.getId(), pi.getProcessId()); log.setExternalId(""+((KieSession) pse.getKieRuntime()).getIdentifier()); log.setProcessName(pi.getProcess().getName()); log.setProcessVersion(pi.getProcess().getVersion()); log.setStatus(ProcessInstance.STATE_ACTIVE); log.setProcessInstanceDescription( pi.getDescription() ); log.setProcessType(((WorkflowProcess)pi.getProcess()).getProcessType()); log.setSlaCompliance(pi.getSlaCompliance()); log.setSlaDueDate(pi.getSlaDueDate()); // store correlation key in its external form CorrelationKey correlationKey = (CorrelationKey) pi.getMetaData().get("CorrelationKey"); if (correlationKey != null) { log.setCorrelationKey(correlationKey.toExternalForm()); } long parentProcessInstanceId = (Long) pi.getMetaData().getOrDefault("ParentProcessInstanceId", -1L); log.setParentProcessInstanceId( parentProcessInstanceId ); return log; }
public Context getProcessInstanceByCorrelationKey(CorrelationKey correlationKey, EntityManager em) { Query processInstancesForEvent = em.createNamedQuery( "GetProcessInstanceIdByCorrelation" ); processInstancesForEvent.setParameter( "ckey", correlationKey.toExternalForm()); try { return ProcessInstanceIdContext.get((Long) processInstancesForEvent.getSingleResult()); } catch (NonUniqueResultException e) { return null; } catch (NoResultException e) { return null; } }
public String getCorrelationKey() { if (correlationKey == null && getMetaData().get("CorrelationKey") != null) { this.correlationKey = ((CorrelationKey) getMetaData().get("CorrelationKey")).toExternalForm(); } return correlationKey; }
@Override public ProcessInstance findProcessInstanceByCorrelationKey(CorrelationKey correlationKey) { ProcessInstance result = null; if (config.isRest()) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CORRELATION_KEY, correlationKey.toExternalForm()); result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_INSTANCE_BY_CORRELATION_KEY_GET_URI, valuesMap), ProcessInstance.class); } else { CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstanceByCorrelationKey", new Object[]{correlationKey.toExternalForm()}))); ServiceResponse<ProcessInstance> response = (ServiceResponse<ProcessInstance>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } return response.getResult(); } return result; }
@Override public List<ProcessInstance> findProcessInstancesByCorrelationKey(CorrelationKey correlationKey, Integer page, Integer pageSize, String sort, boolean sortOrder) { ProcessInstanceList result = null; if (config.isRest()) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CORRELATION_KEY, correlationKey.toExternalForm()); String queryString = getPagingQueryString("?sort=" + sort + "&sortOrder=" + sortOrder, page, pageSize); result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), QUERY_URI + "/" + PROCESS_INSTANCES_BY_CORRELATION_KEY_GET_URI, valuesMap) + queryString, ProcessInstanceList.class); } else { CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("QueryService", "getProcessInstancesByCorrelationKey", new Object[]{correlationKey.toExternalForm(), page, pageSize, sort, sortOrder}))); ServiceResponse<ProcessInstanceList> response = (ServiceResponse<ProcessInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } result = response.getResult(); } if (result != null && result.getProcessInstances() != null) { return Arrays.asList(result.getProcessInstances()); } return Collections.emptyList(); }
@Override public Long startProcess(String containerId, String processId, CorrelationKey correlationKey, Map<String, Object> variables) { Object result = null; if( config.isRest() ) { Map<String, Object> valuesMap = new HashMap<String, Object>(); valuesMap.put(CONTAINER_ID, containerId); valuesMap.put(PROCESS_ID, processId); valuesMap.put(CORRELATION_KEY, correlationKey.toExternalForm()); result = makeHttpPostRequestAndCreateCustomResponse( build(loadBalancer.getUrl(), PROCESS_URI + "/" + START_PROCESS_WITH_CORRELATION_KEY_POST_URI, valuesMap), variables, Object.class); } else { CommandScript script = new CommandScript( Collections.singletonList( (KieServerCommand) new DescriptorCommand( "ProcessService", "startProcessWithCorrelation", serialize(safeMap(variables)), marshaller.getFormat().getType(), new Object[]{containerId, processId, correlationKey.toExternalForm()}) ) ); ServiceResponse<String> response = (ServiceResponse<String>) executeJmsCommand( script, DescriptorCommand.class.getName(), "BPM", containerId ).getResponses().get(0); throwExceptionOnFailure(response); if (shouldReturnWithNullResponse(response)) { return null; } result = deserialize(response.getResult(), Object.class); } if (result instanceof Wrapped) { return (Long) ((Wrapped) result).unwrap(); } return ((Number) result).longValue(); }