diff --git a/workflow/engine/classes/model/BpmnFlow.php b/workflow/engine/classes/model/BpmnFlow.php index 78e9f2a60..f7e95f39c 100644 --- a/workflow/engine/classes/model/BpmnFlow.php +++ b/workflow/engine/classes/model/BpmnFlow.php @@ -33,7 +33,7 @@ class BpmnFlow extends BaseBpmnFlow while ($rs->next()) { $flow = $rs->getRow(); $flow["FLO_STATE"] = @json_decode($flow["FLO_STATE"]); - $flow["FLO_IS_INMEDIATE"] = $flow["FLO_IS_INMEDIATE"] == 1 ? true : false; + //$flow["FLO_IS_INMEDIATE"] = $flow["FLO_IS_INMEDIATE"] == 1 ? true : false; $flow = $changeCaseTo !== CASE_UPPER ? array_change_key_case($flow, CASE_LOWER) : $flow; $flows[] = $flow; diff --git a/workflow/engine/src/ProcessMaker/Adapter/Bpmn/Model.php b/workflow/engine/src/ProcessMaker/Adapter/Bpmn/Model.php index b74fe0c20..76ddda987 100644 --- a/workflow/engine/src/ProcessMaker/Adapter/Bpmn/Model.php +++ b/workflow/engine/src/ProcessMaker/Adapter/Bpmn/Model.php @@ -392,8 +392,8 @@ class Model $lanes = self::getBpmnCollectionBy('Lane', LanePeer::PRJ_UID, $prjUid, true); //$activities = self::getBpmnCollectionBy('Activity', ActivityPeer::PRJ_UID, $prjUid, true); - //$activities = Activity::getAll($prjUid, null, null, null, 'object', CASE_LOWER); - $activities = Activity::getAll(array('prjUid' => $prjUid, 'changeCaseTo' => CASE_LOWER)); + $activities = Activity::getAll($prjUid, null, null, null, 'object', CASE_LOWER); + //$activities = Activity::getAll(array('prjUid' => $prjUid, 'changeCaseTo' => CASE_LOWER)); //print_r($activities); die; $events = self::getBpmnCollectionBy('Event', EventPeer::PRJ_UID, $prjUid, true); diff --git a/workflow/engine/src/ProcessMaker/Project/Adapter/BpmnWorkflow.php b/workflow/engine/src/ProcessMaker/Project/Adapter/BpmnWorkflow.php index 687ec4242..58a96f851 100644 --- a/workflow/engine/src/ProcessMaker/Project/Adapter/BpmnWorkflow.php +++ b/workflow/engine/src/ProcessMaker/Project/Adapter/BpmnWorkflow.php @@ -141,4 +141,105 @@ class BpmnWorkflow extends Project\Bpmn parent::removeActivity($actUid); $this->wp->removeTask($actUid); } + + public function addFlow($data) + { + parent::addFlow($data); + + $fromUid = $data['FLO_ELEMENT_ORIGIN']; + + if ($data['FLO_TYPE'] != 'SEQUENCE') { + throw new \LogicException(sprintf( + "Unsupported flow type: %s, ProcessMaker only support type '', Given: '%s'", + 'SEQUENCE', $data['FLO_TYPE'] + )); + } + + switch ($data['FLO_ELEMENT_DEST_TYPE']) { + case 'bpmnActivity': + // the most easy case, when the flow is connecting a activity with another activity + /*$data = array( + 'ROU_UID' => $data['FLO_UID'], //Hash::generateUID(), + 'PRO_UID' => $this->getUid(), + 'TAS_UID' => $fromUid, + 'ROU_NEXT_TASK' => $data['FLO_ELEMENT_DEST'], + 'ROU_TYPE' => 'SEQUENTIAL' + );*/ + $this->wp->addRoute($fromUid, $data['FLO_ELEMENT_DEST'], 'SEQUENTIAL'); + break; + case 'bpmnGateway': + $gatUid = $data['FLO_ELEMENT_DEST']; + // if it is a gateway it can fork one or more routes + $gatFlows = BpmnModel::getBpmnCollectionBy('Flow', \BpmnFlowPeer::FLO_ELEMENT_ORIGIN, $gatUid); + + foreach ($gatFlows as $gatFlow) { + switch ($gatFlow['FLO_ELEMENT_DEST_TYPE']) { + case 'bpmnActivity': + // getting gateway properties + $gateway = BpmnModel::getBpmnObjectBy('Gateway', \BpmnGatewayPeer::GAT_UID, $gatUid); + + switch ($gateway['GAT_TYPE']) { + case 'SELECTION': + $routeType = 'SELECT'; + break; + case 'EVALUATION': + $routeType = 'EVALUATE'; + break; + case 'PARALLEL': + $routeType = 'PARALLEL'; + break; + case 'PARALLEL_EVALUATION': + $routeType = 'PARALLEL-BY-EVALUATION'; + break; + case 'PARALLEL_JOIN': + $routeType = 'SEC-JOIN'; + break; + default: + throw new \LogicException(sprintf("Unsupported Gateway type: %s", $gateway['GAT_TYPE'])); + } + + $routes[] = array( + 'ROU_UID' => $gatFlow['FLO_UID'], //Hash::generateUID(), + 'PRO_UID' => $this->getUid(), + 'TAS_UID' => $fromUid, + 'ROU_NEXT_TASK' => $gatFlow['FLO_ELEMENT_DEST'], + 'ROU_TYPE' => $routeType, + '_action' => 'CREATE' + ); + break; + default: + // for processmaker is only allowed flows between "gateway -> activity" + // any another flow is considered invalid + throw new \LogicException(sprintf( + "For ProcessMaker is only allowed flows between \"gateway -> activity\" " . PHP_EOL . + "Given: bpmnGateway -> " . $gatFlow['FLO_ELEMENT_DEST_TYPE'] + )); + } + } + break; + case 'bpmnEvent': + $evnUid = $data['FLO_ELEMENT_DEST']; + $event = BpmnModel::getBpmnObjectBy('Event', \BpmnEventPeer::EVN_UID, $evnUid); + + switch ($event['EVN_TYPE']) { + case 'END': + $routeType = 'SEQUENTIAL'; + $routes[] = array( + 'ROU_UID' => $data['FLO_UID'], //Hash::generateUID(), + 'PRO_UID' => $this->getUid(), + 'TAS_UID' => $fromUid, + 'ROU_NEXT_TASK' => '-1', + 'ROU_TYPE' => $routeType, + '_action' => 'CREATE' + ); + break; + default: + throw new \LogicException("Invalid connection to Event object type"); + } + + break; + } + + + } } \ No newline at end of file diff --git a/workflow/engine/src/ProcessMaker/Project/Workflow.php b/workflow/engine/src/ProcessMaker/Project/Workflow.php index d5894801e..4b691482f 100644 --- a/workflow/engine/src/ProcessMaker/Project/Workflow.php +++ b/workflow/engine/src/ProcessMaker/Project/Workflow.php @@ -225,56 +225,63 @@ class Workflow extends Handler public function addRoute($fromTasUid, $toTasUid, $type, $delete = null) { + try { + self::log("Add Route from task: $fromTasUid -> to task: $toTasUid ($type)"); + /*switch ($type) { + case 0: + $sType = 'SEQUENTIAL'; + break; + case 1: + $sType = 'SELECT'; + break; + case 2: + $sType = 'EVALUATE'; + break; + case 3: + $sType = 'PARALLEL'; + break; + case 4: + $sType = 'PARALLEL-BY-EVALUATION'; + break; + case 5: + $sType = 'SEC-JOIN'; + break; + case 8: + $sType = 'DISCRIMINATOR'; + break; + default: + throw new \Exception("Invalid type code, given: $type, expected: integer [1...8]"); + } + }*/ - /*switch ($type) { - case 0: - $sType = 'SEQUENTIAL'; - break; - case 1: - $sType = 'SELECT'; - break; - case 2: - $sType = 'EVALUATE'; - break; - case 3: - $sType = 'PARALLEL'; - break; - case 4: - $sType = 'PARALLEL-BY-EVALUATION'; - break; - case 5: - $sType = 'SEC-JOIN'; - break; - case 8: - $sType = 'DISCRIMINATOR'; - break; - default: - throw new \Exception("Invalid type code, given: $type, expected: integer [1...8]"); + $validTypes = array("SEQUENTIAL", "SELECT", "EVALUATE", "PARALLEL", "PARALLEL-BY-EVALUATION", "SEC-JOIN", "DISCRIMINATOR"); + + if (! in_array($type, $validTypes)) { + throw new \Exception("Invalid Route type, given: $type, expected: [".implode(",", $validTypes)."]"); } - }*/ - $validTypes = array("SEQUENTIAL", "SELECT", "EVALUATE", "PARALLEL", "PARALLEL-BY-EVALUATION", "SEC-JOIN", "DISCRIMINATOR"); - - if (! in_array($type, $validTypes)) { - throw new \Exception("Invalid Route type, given: $type, expected: [".implode(",", $validTypes)."]"); - } - - //if ($type != 0 && $type != 5 && $type != 8) { - if ($type != 'SEQUENTIAL' && $type != 'SEC-JOIN' && $type != 'DISCRIMINATOR') { - if ($this->getNumberOfRoutes($this->proUid, $fromTasUid, $toTasUid, $type) > 0) { - // die(); ???? - throw new \RuntimeException("Unexpected behaviour"); + //if ($type != 0 && $type != 5 && $type != 8) { + if ($type != 'SEQUENTIAL' && $type != 'SEC-JOIN' && $type != 'DISCRIMINATOR') { + if ($this->getNumberOfRoutes($this->proUid, $fromTasUid, $toTasUid, $type) > 0) { + // die(); ???? + throw new \RuntimeException("Unexpected behaviour"); + } + //unset($aRow); } - //unset($aRow); - } - //if ($delete || $type == 0 || $type == 5 || $type == 8) { - if ($delete || $type == 'SEQUENTIAL' || $type == 'SEC-JOIN' || $type == 'DISCRIMINATOR') { - $oTasks = new Tasks(); + //if ($delete || $type == 0 || $type == 5 || $type == 8) { + if ($delete || $type == 'SEQUENTIAL' || $type == 'SEC-JOIN' || $type == 'DISCRIMINATOR') { + $oTasks = new Tasks(); - $oTasks->deleteAllRoutesOfTask($this->proUid, $fromTasUid); - //$oTasks->deleteAllGatewayOfTask($this->proUid, $fromTasUid); + $oTasks->deleteAllRoutesOfTask($this->proUid, $fromTasUid); + //$oTasks->deleteAllGatewayOfTask($this->proUid, $fromTasUid); + } + + return $this->saveNewPattern($this->proUid, $fromTasUid, $toTasUid, $type, $delete); + + } catch (\Exception $e) { + self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString()); + throw $e; } - return $this->saveNewPattern($this->proUid, $fromTasUid, $toTasUid, $type, $delete); } public function updateRoute($rouUid, $routeData) diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project.php b/workflow/engine/src/Services/Api/ProcessMaker/Project.php index bf70923fa..c250123fb 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project.php @@ -35,15 +35,20 @@ class Project extends Api public function get($prjUid) { try { + //return \ProcessMaker\Adapter\Bpmn\Model::loadProject($prjUid); + $bwp = \ProcessMaker\Project\Adapter\BpmnWorkflow::load($prjUid); $project = array_change_key_case($bwp->getProject(), CASE_LOWER); $diagram = $bwp->getDiagram(); + $process = $bwp->getProcess(); + $diagram["pro_uid"] = $process["PRO_UID"]; if (! is_null($diagram)) { $diagram = array_change_key_case($diagram, CASE_LOWER); $diagram["activities"] = $bwp->getActivities(array("changeCaseTo" => CASE_LOWER)); $diagram["events"] = $bwp->getEvents(); + $diagram["gateways"] = $bwp->getGateways(); $diagram["flows"] = $bwp->getFlows(); $diagram["artifacts"] = $bwp->getArtifacts(); $diagram["laneset"] = $bwp->getLanesets();