ProcessInstance createProcessInstance ( Long processId , String ownerType , Long ownerId , String secondaryOwnerType , Long secondaryOwnerId , String masterRequestId , Map < String , String > parameters , String label , String template ) throws ProcessException , DataAccessException { ProcessInstance pi = null ; try { Process processVO ; if ( OwnerType . MAIN_PROCESS_INSTANCE . equals ( ownerType ) ) { ProcessInstance parentPi = getDataAccess ( ) . getProcessInstance ( ownerId ) ; Process parentProcdef = ProcessCache . getProcess ( parentPi . getProcessId ( ) ) ; processVO = parentProcdef . getSubProcessVO ( processId ) ; pi = new ProcessInstance ( parentPi . getProcessId ( ) , processVO . getName ( ) ) ; String comment = processId . toString ( ) ; if ( parentPi . getProcessInstDefId ( ) > 0L ) // Indicates instance definition comment += "|HasInstanceDef|" + parentPi . getProcessInstDefId ( ) ; pi . setComment ( comment ) ; } else { if ( uniqueMasterRequestId && ! ( OwnerType . PROCESS_INSTANCE . equals ( ownerType ) || OwnerType . ERROR . equals ( ownerType ) ) ) { // Check for uniqueness of master request id before creating top level process instance, if enabled List < ProcessInstance > list = edao . getProcessInstancesByMasterRequestId ( masterRequestId ) ; if ( list != null && list . size ( ) > 0 ) { String msg = "Could not launch process instance for " + ( label != null ? label : template ) + " because Master Request ID " + masterRequestId + " is not unique" ; logger . error ( msg ) ; throw new ProcessException ( msg ) ; } } processVO = ProcessCache . getProcess ( processId ) ; pi = new ProcessInstance ( processId , processVO . getName ( ) ) ; } pi . setOwner ( ownerType ) ; pi . setOwnerId ( ownerId ) ; pi . setSecondaryOwner ( secondaryOwnerType ) ; pi . setSecondaryOwnerId ( secondaryOwnerId ) ; pi . setMasterRequestId ( masterRequestId ) ; pi . setStatusCode ( WorkStatus . STATUS_PENDING_PROCESS ) ; if ( label != null ) pi . setComment ( label ) ; if ( template != null ) pi . setTemplate ( template ) ; edao . createProcessInstance ( pi ) ; createVariableInstancesFromEventMessage ( pi , parameters ) ; } catch ( SQLException e ) { if ( pi != null && pi . getId ( ) != null && pi . getId ( ) > 0L ) try { edao . setProcessInstanceStatus ( pi . getId ( ) , WorkStatus . STATUS_FAILED ) ; } catch ( SQLException ex ) { logger . severeException ( "Exception while updating process status to 'Failed'" , ex ) ; } throw new DataAccessException ( - 1 , e . getMessage ( ) , e ) ; } return pi ; }
Create a process instance . The status is PENDING_PROCESS