Updating Unit Tests for BpmnWorkflow Adapter, and some Bpmn->Workflow logic
This commit is contained in:
@@ -3,6 +3,7 @@ namespace ProcessMaker\Project\Adapter;
|
||||
|
||||
use ProcessMaker\Project;
|
||||
use ProcessMaker\Util\Hash;
|
||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||
|
||||
/**
|
||||
* Class BpmnWorkflow
|
||||
@@ -105,7 +106,8 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
{
|
||||
$taskData = array();
|
||||
|
||||
$taskData["TAS_UID"] = parent::addActivity($data);
|
||||
$actUid = parent::addActivity($data);
|
||||
$taskData["TAS_UID"] = $actUid;
|
||||
|
||||
if (array_key_exists("ACT_NAME", $data)) {
|
||||
$taskData["TAS_TITLE"] = $data["ACT_NAME"];
|
||||
@@ -118,6 +120,8 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
}
|
||||
|
||||
$this->wp->addTask($taskData);
|
||||
|
||||
return $actUid;
|
||||
}
|
||||
|
||||
public function updateActivity($actUid, $data)
|
||||
@@ -145,55 +149,47 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
$this->wp->removeTask($actUid);
|
||||
}
|
||||
|
||||
public function addFlow($data, $diagram)
|
||||
{
|
||||
$flows = $diagram["flows"];
|
||||
$gateways = $diagram["gateways"];
|
||||
$events = $diagram["events"];
|
||||
|
||||
parent::addFlow($data);
|
||||
// public function addFlow($data)
|
||||
// {
|
||||
// parent::addFlow($data);
|
||||
|
||||
// to add a workflow route
|
||||
// - activity -> activity ==> route
|
||||
// - activity -> gateway -> activity ==> selection, evaluation, parallel or parallel by evaluation route
|
||||
$routes = self::mapBpmnFlowsToWorkflowRoute($data, $flows, $gateways, $events);
|
||||
// $routes = self::mapBpmnFlowsToWorkflowRoute($data, $flows);
|
||||
//
|
||||
// if ($routes !== null) {
|
||||
// foreach ($routes as $routeData) {
|
||||
// $this->wp->addRoute($routeData["from"], $routeData["to"], $routeData["type"]);
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// // to add start event->activity as initial or end task
|
||||
// switch ($data["FLO_ELEMENT_ORIGIN_TYPE"]) {
|
||||
// case "bpmnEvent":
|
||||
// switch ($data["FLO_ELEMENT_DEST_TYPE"]) {
|
||||
// case "bpmnActivity":
|
||||
// $event = \BpmnEventPeer::retrieveByPK($data["FLO_ELEMENT_ORIGIN"]);
|
||||
//
|
||||
// switch ($event && $event->getEvnType()) {
|
||||
// case "START":
|
||||
// // then set that activity/task as "Start Task"
|
||||
// $this->wp->setStartTask($data["FLO_ELEMENT_DEST"]);
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
|
||||
if ($routes !== null) {
|
||||
foreach ($routes as $routeData) {
|
||||
$this->wp->addRoute($routeData["from"], $routeData["to"], $routeData["type"]);
|
||||
}
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// to add start event->activity as initial or end task
|
||||
switch ($data["FLO_ELEMENT_ORIGIN_TYPE"]) {
|
||||
case "bpmnEvent":
|
||||
switch ($data["FLO_ELEMENT_DEST_TYPE"]) {
|
||||
case "bpmnActivity":
|
||||
$event = \BpmnEventPeer::retrieveByPK($data["FLO_ELEMENT_ORIGIN"]);
|
||||
|
||||
switch ($event && $event->getEvnType()) {
|
||||
case "START":
|
||||
// then set that activity/task as "Start Task"
|
||||
$this->wp->setStartTask($data["FLO_ELEMENT_DEST"]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function updateFlow($floUid, $data)
|
||||
{
|
||||
if (! self::isModified("flow", $floUid, $data)) {
|
||||
self::log("Update Flow: $floUid (No Changes)");
|
||||
return false;
|
||||
}
|
||||
|
||||
parent::updateFlow($floUid, $data);
|
||||
}
|
||||
// public function updateFlow($floUid, $data, $flows)
|
||||
// {
|
||||
// parent::updateFlow($floUid, $data);
|
||||
// }
|
||||
|
||||
public function removeFlow($floUid)
|
||||
{
|
||||
@@ -224,7 +220,20 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
$this->wp->setEndTask($activity->getActUid(), false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch ($flow->getFloElementOriginType()) {
|
||||
case "bpmnActivity":
|
||||
switch ($flow->getFloElementDestType()) {
|
||||
// activity->activity
|
||||
case "bpmnActivity":
|
||||
$this->wp->removeRouteFromTo($flow->getFloElementOrigin(), $flow->getFloElementDest());
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Complete for other routes, activity->activity, activity->gateway and viceversa
|
||||
}
|
||||
|
||||
public function addEvent($data)
|
||||
@@ -236,35 +245,102 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
parent::addEvent($data);
|
||||
}
|
||||
|
||||
public function removeEvent($evnUid)
|
||||
public function mapBpmnFlowsToWorkflowRoutes()
|
||||
{
|
||||
// $event = \BpmnEventPeer::retrieveByPK($evnUid);
|
||||
//
|
||||
// switch ($event->getEvnType()) {
|
||||
// case "START":
|
||||
// $flow = \BpmnFlow::findOneBy(\BpmnFlowPeer::FLO_ELEMENT_ORIGIN, $event->getEvnUid());
|
||||
// if (! is_null($flow) && $flow->getFloElementDestType() == "bpmnActivity") {
|
||||
// $activity = \BpmnActivityPeer::retrieveByPK($flow->getFloElementDest());
|
||||
// if (! is_null($activity)) {
|
||||
// $this->wp->setStartTask($activity->getActUid(), false);
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// case "END":
|
||||
// $flow = \BpmnFlow::findOneBy(\BpmnFlowPeer::FLO_ELEMENT_DEST, $event->getEvnUid());
|
||||
// if (! is_null($flow) && $flow->getFloElementOriginType() == "bpmnActivity") {
|
||||
// $activity = \BpmnActivityPeer::retrieveByPK($flow->getFloElementOrigin());
|
||||
// if (! is_null($activity)) {
|
||||
// $this->wp->setEndTask($activity->getActUid(), false);
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
$activities = $this->getActivities();
|
||||
|
||||
parent::removeEvent($evnUid);
|
||||
foreach ($activities as $activity) {
|
||||
|
||||
$flows = \BpmnFlow::findAllBy(array(
|
||||
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $activity["ACT_UID"],
|
||||
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => "bpmnActivity"
|
||||
));
|
||||
|
||||
//
|
||||
foreach ($flows as $flow) {
|
||||
switch ($flow->getFloElementDestType()) {
|
||||
case "bpmnActivity":
|
||||
// (activity -> activity)
|
||||
$this->wp->addRoute($activity["ACT_UID"], $flow->getFloElementDest(), "SEQUENTIAL");
|
||||
break;
|
||||
|
||||
case "bpmnGateway":
|
||||
// (activity -> gateway)
|
||||
// we must find the related flows: gateway -> <object>
|
||||
$gatUid = $flow->getFloElementDest();
|
||||
$gatewayFlows = \BpmnFlow::findAllBy(array(
|
||||
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN => $gatUid,
|
||||
\BpmnFlowPeer::FLO_ELEMENT_ORIGIN_TYPE => "bpmnGateway"
|
||||
));
|
||||
|
||||
foreach ($gatewayFlows as $gatewayFlow) {
|
||||
$gatewayFlow = $gatewayFlow->toArray();
|
||||
|
||||
switch ($gatewayFlow['FLO_ELEMENT_DEST_TYPE']) {
|
||||
case 'bpmnActivity':
|
||||
// (gateway -> activity)
|
||||
$gateway = \BpmnGateway::findOneBy(\BpmnGatewayPeer::GAT_UID, $gatUid)->toArray();
|
||||
|
||||
switch ($gateway["GAT_TYPE"]) {
|
||||
//case 'SELECTION':
|
||||
case self::BPMN_GATEWAY_COMPLEX:
|
||||
$routeType = "SELECT";
|
||||
break;
|
||||
//case 'EVALUATION':
|
||||
case self::BPMN_GATEWAY_EXCLUSIVE:
|
||||
$routeType = "EVALUATE";
|
||||
break;
|
||||
//case 'PARALLEL':
|
||||
case self::BPMN_GATEWAY_PARALLEL:
|
||||
if ($gateway["GAT_DIRECTION"] == "DIVERGING") {
|
||||
$routeType = "PARALLEL";
|
||||
} elseif ($gateway["GAT_DIRECTION"] == "CONVERGING") {
|
||||
$routeType = "SEC-JOIN";
|
||||
} else {
|
||||
throw new \LogicException(sprintf(
|
||||
"Invalid Gateway direction, accepted values: [%s|%s], given: %s.",
|
||||
"DIVERGING", "CONVERGING", $gateway["GAT_DIRECTION"]
|
||||
));
|
||||
}
|
||||
break;
|
||||
//case 'PARALLEL_EVALUATION':
|
||||
case self::BPMN_GATEWAY_INCLUSIVE:
|
||||
if ($gateway["GAT_DIRECTION"] == "DIVERGING") {
|
||||
$routeType = "PARALLEL-BY-EVALUATION";
|
||||
} elseif ($gateway["GAT_DIRECTION"] == "CONVERGING") {
|
||||
$routeType = "SEC-JOIN";
|
||||
} else {
|
||||
throw new \LogicException(sprintf(
|
||||
"Invalid Gateway direction, accepted values: [%s|%s], given: %s.",
|
||||
"DIVERGING", "CONVERGING", $gateway["GAT_DIRECTION"]
|
||||
));
|
||||
}
|
||||
break;
|
||||
// case 'PARALLEL_JOIN':
|
||||
// $routeType = 'SEC-JOIN';
|
||||
// break;
|
||||
default:
|
||||
throw new \LogicException(sprintf("Unsupported Gateway type: %s", $gateway['GAT_TYPE']));
|
||||
}
|
||||
|
||||
$this->wp->addRoute($activity["ACT_UID"], $gatewayFlow['FLO_ELEMENT_DEST'], $routeType);
|
||||
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 -> " . $gatewayFlow['FLO_ELEMENT_DEST_TYPE']
|
||||
));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function mapBpmnFlowsToWorkflowRoute($flow, $flows, $gateways, $events)
|
||||
public static function mapBpmnFlowsToWorkflowRoute2($flow, $flows, $gateways, $events)
|
||||
{
|
||||
$fromUid = $flow['FLO_ELEMENT_ORIGIN'];
|
||||
$result = array();
|
||||
@@ -387,11 +463,6 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
return $result;
|
||||
}
|
||||
|
||||
// public function getActivities()
|
||||
// {
|
||||
// return parent::getActivities();
|
||||
// }
|
||||
|
||||
public function remove()
|
||||
{
|
||||
parent::remove();
|
||||
|
||||
@@ -325,6 +325,7 @@ class Bpmn extends Handler
|
||||
|
||||
$activity = ActivityPeer::retrieveByPK($actUid);
|
||||
$activity->delete();
|
||||
//TODO if the activity was removed, the related flows to that activity must be removed
|
||||
|
||||
self::log("Remove Activity Success!");
|
||||
} catch (\Exception $e) {
|
||||
@@ -438,7 +439,6 @@ class Bpmn extends Handler
|
||||
$gateway->setPrjUid($this->getUid());
|
||||
$gateway->setProUid($this->getProcess("object")->getProUid());
|
||||
$gateway->save();
|
||||
|
||||
self::log("Add Gateway Success!");
|
||||
} catch (\Exception $e) {
|
||||
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||
@@ -518,13 +518,48 @@ class Bpmn extends Handler
|
||||
}
|
||||
|
||||
try {
|
||||
switch ($data["FLO_ELEMENT_ORIGIN_TYPE"]) {
|
||||
case "bpmnActivity": $class = "BpmnActivity"; break;
|
||||
case "bpmnGateway": $class = "BpmnGateway"; break;
|
||||
case "bpmnEvent": $class = "BpmnEvent"; break;
|
||||
default:
|
||||
throw new \RuntimeException(sprintf("Invalid Object type, accepted types: [%s|%s|%s], given %s.",
|
||||
"BpmnActivity", "BpmnBpmnGateway", "BpmnEvent", $data["FLO_ELEMENT_ORIGIN_TYPE"]
|
||||
));
|
||||
}
|
||||
|
||||
// Validate origin object exists
|
||||
if (! $class::exists($data["FLO_ELEMENT_ORIGIN"])) {
|
||||
throw new \RuntimeException(sprintf("Reference not found, the %s with UID: %s, does not exist!",
|
||||
ucfirst($data["FLO_ELEMENT_ORIGIN_TYPE"]), $data["FLO_ELEMENT_ORIGIN"]
|
||||
));
|
||||
}
|
||||
|
||||
switch ($data["FLO_ELEMENT_DEST_TYPE"]) {
|
||||
case "bpmnActivity": $class = "BpmnActivity"; break;
|
||||
case "bpmnGateway": $class = "BpmnGateway"; break;
|
||||
case "bpmnEvent": $class = "BpmnEvent"; break;
|
||||
default:
|
||||
throw new \RuntimeException(sprintf("Invalid Object type, accepted types: [%s|%s|%s], given %s.",
|
||||
"BpmnActivity", "BpmnBpmnGateway", "BpmnEvent", $data["FLO_ELEMENT_DEST_TYPE"]
|
||||
));
|
||||
}
|
||||
|
||||
// Validate origin object exists
|
||||
if (! $class::exists($data["FLO_ELEMENT_DEST"])) {
|
||||
throw new \RuntimeException(sprintf("Reference not found, the %s with UID: %s, does not exist!",
|
||||
ucfirst($data["FLO_ELEMENT_DEST_TYPE"]), $data["FLO_ELEMENT_DEST"]
|
||||
));
|
||||
}
|
||||
|
||||
$flow = new Flow();
|
||||
$flow->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
||||
$flow->setPrjUid($this->getUid());
|
||||
$flow->setDiaUid($this->getDiagram("object")->getDiaUid());
|
||||
$flow->save();
|
||||
|
||||
self::log("Add Flow Success!");
|
||||
|
||||
return $flow->getFloUid();
|
||||
} catch (\Exception $e) {
|
||||
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||
throw $e;
|
||||
|
||||
@@ -325,6 +325,24 @@ class Workflow extends Handler
|
||||
}
|
||||
}
|
||||
|
||||
public function removeRouteFromTo($fromTasUid, $toTasUid)
|
||||
{
|
||||
try {
|
||||
self::log("Remove Route from $fromTasUid -> to $toTasUid");
|
||||
|
||||
$route = Route::findOneBy(array(
|
||||
RoutePeer::TAS_UID => $fromTasUid,
|
||||
RoutePeer::ROU_NEXT_TASK => $toTasUid
|
||||
));
|
||||
|
||||
$route->delete();
|
||||
self::log("Remove Route Success!");
|
||||
} catch (\Exception $e) {
|
||||
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function getRoute($rouUid)
|
||||
{
|
||||
$route = new Route();
|
||||
@@ -332,6 +350,11 @@ class Workflow extends Handler
|
||||
return $route->load($rouUid);
|
||||
}
|
||||
|
||||
public function getRoutes()
|
||||
{
|
||||
return Route::getAll($proUid = null, $start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************************
|
||||
* Migrated Methods from class.processMap.php class *
|
||||
|
||||
Reference in New Issue
Block a user