Search in sources :

Example 1 with SuspendProcessInstancesResponse

use of org.ow2.petals.components.flowable.generic._1.SuspendProcessInstancesResponse in project petals-se-flowable by petalslink.

the class SuspendProcessInstancesOperation method doExecute.

@Override
public SuspendProcessInstancesResponse doExecute(final SuspendProcessInstances incomingObject) throws Exception {
    final SuspendProcessInstancesResponse response = new SuspendProcessInstancesResponse();
    final List<ProcessInstanceIdentifier> results = response.getProcessInstanceIdentifier();
    for (final String processInstanceId : incomingObject.getProcessInstanceIdentifier()) {
        this.log.fine(String.format("Suspends process instance #%s.", processInstanceId));
        final ProcessInstanceIdentifier result = new ProcessInstanceIdentifier();
        result.setValue(processInstanceId);
        results.add(result);
        try {
            this.runtimeService.suspendProcessInstanceById(processInstanceId);
            result.setResult(AdjournmentResult.SUSPENDED);
        } catch (@SuppressWarnings("squid:S1166") final FlowableObjectNotFoundException e) {
            result.setResult(AdjournmentResult.NOT_FOUND);
        } catch (@SuppressWarnings("squid:S1166") final FlowableException e) {
            result.setResult(AdjournmentResult.ALREADY_SUSPENDED);
        }
    }
    return response;
}
Also used : FlowableObjectNotFoundException(org.flowable.common.engine.api.FlowableObjectNotFoundException) FlowableException(org.flowable.common.engine.api.FlowableException) SuspendProcessInstancesResponse(org.ow2.petals.components.flowable.generic._1.SuspendProcessInstancesResponse) ProcessInstanceIdentifier(org.ow2.petals.components.flowable.generic._1.SuspendProcessInstancesResponse.ProcessInstanceIdentifier)

Example 2 with SuspendProcessInstancesResponse

use of org.ow2.petals.components.flowable.generic._1.SuspendProcessInstancesResponse in project petals-se-flowable by petalslink.

the class ServiceProviderVacationProcessTest method tryToSuspendProcessInstance.

private final void tryToSuspendProcessInstance(final String processInstanceId, final FlowLogData processStartedBeginFlowLogData, final AdjournmentResult expectedResult) throws Exception {
    if (expectedResult == AdjournmentResult.SUSPENDED) {
        // Check at Flowable level that the process instance is suspended
        final List<org.flowable.engine.runtime.ProcessInstance> processInstances = this.flowableClient.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).list();
        assertNotNull(processInstances);
        assertEquals(1, processInstances.size());
        assertFalse(processInstances.get(0).isSuspended());
    }
    final SuspendProcessInstances suspendProcessInstancesReq = new SuspendProcessInstances();
    suspendProcessInstancesReq.getProcessInstanceIdentifier().add(processInstanceId);
    IN_MEMORY_LOG_HANDLER.clear();
    final RequestToProviderMessage requestM = new RequestToProviderMessage(COMPONENT_UNDER_TEST, NATIVE_PROCESSINSTANCES_SVC_CFG, ITG_OP_SUSPENDPROCESSINSTANCES, AbsItfOperation.MEPPatternConstants.IN_OUT.value(), toByteArray(suspendProcessInstancesReq));
    {
        final ResponseMessage suspendProcessInstancesRespMsg = COMPONENT.sendAndGetResponse(requestM);
        assertNotNull("No XML payload in response", suspendProcessInstancesRespMsg.getPayload());
        final Object suspendProcessInstancesRespObj = UNMARSHALLER.unmarshal(suspendProcessInstancesRespMsg.getPayload());
        assertTrue(suspendProcessInstancesRespObj instanceof SuspendProcessInstancesResponse);
        final SuspendProcessInstancesResponse suspendProcessInstancesResp = (SuspendProcessInstancesResponse) suspendProcessInstancesRespObj;
        assertNotNull(suspendProcessInstancesResp.getProcessInstanceIdentifier());
        assertEquals(1, suspendProcessInstancesResp.getProcessInstanceIdentifier().size());
        assertNotNull(suspendProcessInstancesResp.getProcessInstanceIdentifier().get(0));
        assertEquals(processInstanceId, suspendProcessInstancesResp.getProcessInstanceIdentifier().get(0).getValue());
        assertEquals(expectedResult, suspendProcessInstancesResp.getProcessInstanceIdentifier().get(0).getResult());
        COMPONENT.sendDoneStatus(suspendProcessInstancesRespMsg);
    }
    // Check MONIT traces about the process instance adjournment
    final List<LogRecord> monitLogs_suspendProcessInstance = IN_MEMORY_LOG_HANDLER.getAllRecords(Level.MONIT);
    assertEquals(2, monitLogs_suspendProcessInstance.size());
    final FlowLogData providerBegin_suspendProcessInstance = assertMonitProviderBeginLog(ITG_PROCESSINSTANCES_PORT_TYPE, ITG_PROCESSINSTANCES_SERVICE, COMPONENT_UNDER_TEST.getNativeEndpointName(ITG_PROCESSINSTANCES_SERVICE), ITG_OP_SUSPENDPROCESSINSTANCES, monitLogs_suspendProcessInstance.get(0));
    assertMonitProviderEndLog(providerBegin_suspendProcessInstance, monitLogs_suspendProcessInstance.get(1));
    assertMonitFlowInstanceIdNotEquals(processStartedBeginFlowLogData, providerBegin_suspendProcessInstance);
    if (expectedResult == AdjournmentResult.SUSPENDED) {
        // Check at Flowable level that the process instance is suspended
        final List<org.flowable.engine.runtime.ProcessInstance> processInstances = this.flowableClient.getRuntimeService().createProcessInstanceQuery().processInstanceId(processInstanceId).list();
        assertNotNull(processInstances);
        assertEquals(1, processInstances.size());
        assertTrue(processInstances.get(0).isSuspended());
    }
}
Also used : SuspendProcessInstances(org.ow2.petals.components.flowable.generic._1.SuspendProcessInstances) RequestToProviderMessage(org.ow2.petals.component.framework.junit.impl.message.RequestToProviderMessage) SuspendProcessInstancesResponse(org.ow2.petals.components.flowable.generic._1.SuspendProcessInstancesResponse) LogRecord(java.util.logging.LogRecord) ProcessInstance(org.ow2.petals.components.flowable.generic._1.ProcessInstance) ResponseMessage(org.ow2.petals.component.framework.junit.ResponseMessage) FlowLogData(org.ow2.petals.commons.log.FlowLogData)

Aggregations

SuspendProcessInstancesResponse (org.ow2.petals.components.flowable.generic._1.SuspendProcessInstancesResponse)2 LogRecord (java.util.logging.LogRecord)1 FlowableException (org.flowable.common.engine.api.FlowableException)1 FlowableObjectNotFoundException (org.flowable.common.engine.api.FlowableObjectNotFoundException)1 FlowLogData (org.ow2.petals.commons.log.FlowLogData)1 ResponseMessage (org.ow2.petals.component.framework.junit.ResponseMessage)1 RequestToProviderMessage (org.ow2.petals.component.framework.junit.impl.message.RequestToProviderMessage)1 ProcessInstance (org.ow2.petals.components.flowable.generic._1.ProcessInstance)1 SuspendProcessInstances (org.ow2.petals.components.flowable.generic._1.SuspendProcessInstances)1 ProcessInstanceIdentifier (org.ow2.petals.components.flowable.generic._1.SuspendProcessInstancesResponse.ProcessInstanceIdentifier)1