updates for adapter flows -> to -> route
This commit is contained in:
@@ -142,10 +142,15 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
$this->wp->removeTask($actUid);
|
||||
}
|
||||
|
||||
public function addFlow($data)
|
||||
public function addFlow($data, $flows, $gateways, $events)
|
||||
{
|
||||
parent::addFlow($data);
|
||||
|
||||
$routeData = self::mapBpmnFlowsToWorkflowRoute($data, $flows, $gateways, $events);
|
||||
$this->wp->addRoute($routeData["from"], $routeData["to"], $routeData["type"]);
|
||||
|
||||
return;
|
||||
|
||||
$fromUid = $data['FLO_ELEMENT_ORIGIN'];
|
||||
|
||||
if ($data['FLO_TYPE'] != 'SEQUENCE') {
|
||||
@@ -170,13 +175,17 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
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);
|
||||
//$gatFlows = BpmnModel::getBpmnCollectionBy('Flow', \BpmnFlowPeer::FLO_ELEMENT_ORIGIN, $gatUid);
|
||||
$gatFlow = \BpmnFlow::findOneBy(\BpmnFlowPeer::FLO_ELEMENT_ORIGIN, $gatUid)->toArray();;
|
||||
self::log("=================================>", $gatFlow);
|
||||
|
||||
foreach ($gatFlows as $gatFlow) {
|
||||
//foreach ($gatFlows as $gatFlow) {
|
||||
switch ($gatFlow['FLO_ELEMENT_DEST_TYPE']) {
|
||||
case 'bpmnActivity':
|
||||
// getting gateway properties
|
||||
$gateway = BpmnModel::getBpmnObjectBy('Gateway', \BpmnGatewayPeer::GAT_UID, $gatUid);
|
||||
//$gateway = BpmnModel::getBpmnObjectBy('Gateway', \BpmnGatewayPeer::GAT_UID, $gatUid);
|
||||
$gateway = \BpmnGateway::findOneBy(\BpmnGatewayPeer::GAT_UID, $gatUid)->toArray();
|
||||
|
||||
|
||||
switch ($gateway['GAT_TYPE']) {
|
||||
case 'SELECTION':
|
||||
@@ -198,14 +207,15 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
throw new \LogicException(sprintf("Unsupported Gateway type: %s", $gateway['GAT_TYPE']));
|
||||
}
|
||||
|
||||
$routes[] = array(
|
||||
/*$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'
|
||||
);
|
||||
'ROU_TYPE' => $routeType
|
||||
);*/
|
||||
|
||||
$this->wp->addRoute($fromUid, $gatFlow['FLO_ELEMENT_DEST'], $routeType);
|
||||
break;
|
||||
default:
|
||||
// for processmaker is only allowed flows between "gateway -> activity"
|
||||
@@ -215,7 +225,7 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
"Given: bpmnGateway -> " . $gatFlow['FLO_ELEMENT_DEST_TYPE']
|
||||
));
|
||||
}
|
||||
}
|
||||
//}
|
||||
break;
|
||||
case 'bpmnEvent':
|
||||
$evnUid = $data['FLO_ELEMENT_DEST'];
|
||||
@@ -242,4 +252,122 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function mapBpmnFlowsToWorkflowRoute($flow, $flows, $gateways, $events)
|
||||
{
|
||||
$fromUid = $flow['FLO_ELEMENT_ORIGIN'];
|
||||
|
||||
if ($flow['FLO_TYPE'] != 'SEQUENCE') {
|
||||
throw new \LogicException(sprintf(
|
||||
"Unsupported flow type: %s, ProcessMaker only support type '', Given: '%s'",
|
||||
'SEQUENCE', $flow['FLO_TYPE']
|
||||
));
|
||||
}
|
||||
|
||||
switch ($flow['FLO_ELEMENT_DEST_TYPE']) {
|
||||
case 'bpmnActivity':
|
||||
// the most easy case, when the flow is connecting a activity with another activity
|
||||
$result = array("from" => $fromUid, "to" => $flow['FLO_ELEMENT_DEST'], "type" => 'SEQUENTIAL');
|
||||
break;
|
||||
case 'bpmnGateway':
|
||||
$gatUid = $flow['FLO_ELEMENT_DEST'];
|
||||
// if it is a gateway it can fork one or more routes
|
||||
//$gatFlows = BpmnModel::getBpmnCollectionBy('Flow', \BpmnFlowPeer::FLO_ELEMENT_ORIGIN, $gatUid);
|
||||
$gatFlow = self::findInArray($gatUid, "FLO_ELEMENT_ORIGIN", $flows);
|
||||
self::log($gatUid, "FLO_ELEMENT_ORIGIN", $flows);
|
||||
self::log("==============111===================>", $gatFlow);
|
||||
|
||||
//foreach ($gatFlows as $gatFlow) {
|
||||
switch ($gatFlow['FLO_ELEMENT_DEST_TYPE']) {
|
||||
case 'bpmnActivity':
|
||||
// getting gateway properties
|
||||
//$gateway = BpmnModel::getBpmnObjectBy('Gateway', \BpmnGatewayPeer::GAT_UID, $gatUid);
|
||||
$gateway = self::findInArray($gatUid, "GAT_UID", $gateways);
|
||||
self::log("==============222===================>", $gateway);
|
||||
|
||||
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
|
||||
);*/
|
||||
|
||||
//$this->wp->addRoute($fromUid, $gatFlow['FLO_ELEMENT_DEST'], $routeType);
|
||||
$result = array("from" => $fromUid, "to" => $gatFlow['FLO_ELEMENT_DEST'], "type" => $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 -> " . $gatFlow['FLO_ELEMENT_DEST_TYPE']
|
||||
));
|
||||
}
|
||||
//}
|
||||
break;
|
||||
case 'bpmnEvent':
|
||||
$evnUid = $flow['FLO_ELEMENT_DEST'];
|
||||
//$event = BpmnModel::getBpmnObjectBy('Event', \BpmnEventPeer::EVN_UID, $evnUid);
|
||||
$event = self::findInArray($evnUid, "EVN_UID", $events);
|
||||
|
||||
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'
|
||||
);*/
|
||||
$result = array("from" => $fromUid, "to" => "-1", "type" => $routeType);
|
||||
break;
|
||||
default:
|
||||
throw new \LogicException("Invalid connection to Event object type");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
protected static function findInArray($value, $key, $list)
|
||||
{
|
||||
foreach ($list as $item) {
|
||||
if (! array_key_exists($key, $item)) {
|
||||
throw new \Exception("Error: key: $key does not exist in array: " . print_r($item, true));
|
||||
}
|
||||
if ($item[$key] == $value) {
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -210,12 +210,12 @@ class Bpmn extends Handler
|
||||
throw new \Exception(sprintf("Error: There is not an initialized diagram for Project with prj_uid: %s.", $this->getUid()));
|
||||
}
|
||||
|
||||
// setting defaults
|
||||
$data['ACT_UID'] = array_key_exists('ACT_UID', $data) ? $data['ACT_UID'] : Hash::generateUID();;
|
||||
|
||||
try {
|
||||
self::log("Add Activity with data: ", $data);
|
||||
|
||||
// setting defaults
|
||||
$data['ACT_UID'] = array_key_exists('ACT_UID', $data) ? $data['ACT_UID'] : Hash::generateUID();;
|
||||
|
||||
$activity = new Activity();
|
||||
$activity->fromArray($data);
|
||||
$activity->setPrjUid($this->getUid());
|
||||
@@ -327,34 +327,37 @@ class Bpmn extends Handler
|
||||
// setting defaults
|
||||
$data['GAT_UID'] = array_key_exists('GAT_UID', $data) ? $data['GAT_UID'] : Hash::generateUID();
|
||||
|
||||
$gateway = new Gateway();
|
||||
$gateway->fromArray($data);
|
||||
$gateway->setPrjUid($this->project->getPrjUid());
|
||||
$gateway->setProUid($this->getProcess("object")->getProUid());
|
||||
$gateway->save();
|
||||
try {
|
||||
self::log("Add Gateway with data: ", $data);
|
||||
$gateway = new Gateway();
|
||||
$gateway->fromArray($data);
|
||||
$gateway->setPrjUid($this->getUid());
|
||||
$gateway->setProUid($this->getProcess("object")->getProUid());
|
||||
$gateway->save();
|
||||
|
||||
$this->gateways[$gateway->getGatUid()] = $gateway;
|
||||
}
|
||||
|
||||
public function getGateway($gatUid)
|
||||
{
|
||||
if (empty($this->gateways) || ! array_key_exists($gatUid, $this->gateways)) {
|
||||
$gateway = GatewayPeer::retrieveByPK($gatUid);
|
||||
|
||||
if (! is_object($gateway)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->gateways[$gatUid] = $gateway;
|
||||
self::log("Add Gateway Success!");
|
||||
} catch (\Exception $e) {
|
||||
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->gateways[$gatUid];
|
||||
return $gateway->getGatUid();
|
||||
}
|
||||
|
||||
public function getGateway($gatUid, $retType = 'array')
|
||||
{
|
||||
$gateway = GatewayPeer::retrieveByPK($gatUid);
|
||||
|
||||
if ($retType != "object" && ! empty($gateway)) {
|
||||
$gateway = $gateway->toArray();
|
||||
}
|
||||
|
||||
return $gateway;
|
||||
}
|
||||
|
||||
public function getGateways($retType = 'array')
|
||||
{
|
||||
//return Activity::getAll($this->project->getPrjUid(), null, null, '', $retType);
|
||||
return array();
|
||||
return Gateway::getAll($this->getUid(), null, null, '', $retType);
|
||||
}
|
||||
|
||||
public function addFlow($data)
|
||||
|
||||
@@ -5,6 +5,7 @@ use Luracast\Restler\RestException;
|
||||
use ProcessMaker\Services\Api;
|
||||
use ProcessMaker\Adapter\Bpmn\Model as BpmnModel;
|
||||
use ProcessMaker\Util\Hash;
|
||||
use ProcessMaker\Util\Logger;
|
||||
|
||||
/**
|
||||
* Class Project
|
||||
@@ -110,21 +111,12 @@ class Project extends Api
|
||||
|
||||
$result = array();
|
||||
|
||||
$diagramElements = array(
|
||||
'activities' => 'act_uid',
|
||||
'events' => 'evn_uid',
|
||||
'flows' => 'flo_uid',
|
||||
'artifacts' => 'art_uid',
|
||||
'laneset' => 'lns_uid',
|
||||
'lanes' => 'lan_uid'
|
||||
);
|
||||
|
||||
/*
|
||||
* Diagram's Activities Handling
|
||||
*/
|
||||
$whiteList = array();
|
||||
foreach ($diagram["activities"] as $activityData) {
|
||||
$activityData = array_change_key_case($activityData, CASE_UPPER);
|
||||
foreach ($diagram["activities"] as $i => $activityData) {
|
||||
$diagram["activities"][$i] = $activityData = array_change_key_case($activityData, CASE_UPPER);
|
||||
|
||||
// activity exists ?
|
||||
if ($activity = $bwp->getActivity($activityData["ACT_UID"])) {
|
||||
@@ -135,12 +127,13 @@ class Project extends Api
|
||||
} else {
|
||||
// if not exists then create it
|
||||
$oldActUid = $activityData["ACT_UID"];
|
||||
$actUid = Hash::generateUID();
|
||||
$activityData["ACT_UID"] = $actUid;
|
||||
$activityData["ACT_UID"] = Hash::generateUID();
|
||||
$diagram["activities"][$i]["ACT_UID"] = $activityData["ACT_UID"];
|
||||
|
||||
$bwp->addActivity($activityData);
|
||||
|
||||
$result[] = array("object" => "activity", "new_uid" => $actUid, "old_uid" => $oldActUid);
|
||||
$whiteList[] = $actUid;
|
||||
$result[] = array("object" => "activity", "new_uid" => $activityData["ACT_UID"], "old_uid" => $oldActUid);
|
||||
$whiteList[] = $activityData["ACT_UID"];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,26 +148,75 @@ class Project extends Api
|
||||
}
|
||||
|
||||
/*
|
||||
* Diagram's Flows Handling
|
||||
* Diagram's Gateways Handling
|
||||
*/
|
||||
$whiteList = array();
|
||||
foreach ($diagram["flows"] as $flowData) {
|
||||
$flowData = array_change_key_case($flowData, CASE_UPPER);
|
||||
foreach ($diagram["gateways"] as $i => $gatewayData) {
|
||||
$diagram["activities"][$i] = $gatewayData = array_change_key_case($gatewayData, CASE_UPPER);
|
||||
|
||||
// activity exists ?
|
||||
if ($activity = $bwp->getFlow($flowData["FLO_UID"])) {
|
||||
// gateway exists ?
|
||||
if ($gateway = $bwp->getGateway($gatewayData["GAT_UID"])) {
|
||||
// then update activity
|
||||
$bwp->updateGateway($gatewayData["GAT_UID"], $gatewayData);
|
||||
|
||||
$whiteList[] = $gatewayData["GAT_UID"];
|
||||
} else {
|
||||
// if not exists then create it
|
||||
$oldActUid = $gatewayData["GAT_UID"];
|
||||
$gatewayData["GAT_UID"] = Hash::generateUID();
|
||||
$diagram["activities"][$i]["ACT_UID"] = $gatewayData["GAT_UID"];
|
||||
|
||||
$bwp->addGateway($gatewayData);
|
||||
|
||||
$result[] = array("object" => "gateway", "new_uid" => $gatewayData["GAT_UID"], "old_uid" => $oldActUid);
|
||||
$whiteList[] = $gatewayData["GAT_UID"];
|
||||
}
|
||||
}
|
||||
|
||||
$activities = $bwp->getActivities();
|
||||
|
||||
// looking for removed elements
|
||||
foreach ($activities as $activityData) {
|
||||
if (! in_array($activityData["ACT_UID"], $whiteList)) {
|
||||
// If it is not in the white list so, then remove them
|
||||
$bwp->removeActivity($activityData["ACT_UID"]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Diagram's Flows Handling
|
||||
*/
|
||||
|
||||
|
||||
$whiteList = array();
|
||||
foreach ($diagram["flows"] as $i => $flowData) {
|
||||
//TODO, for test, assuming that all flows are new
|
||||
$diagram["flows"][$i] = $flowData = array_change_key_case($flowData, CASE_UPPER);
|
||||
$oldFloUid = $diagram["flows"][$i]["FLO_UID"];
|
||||
$diagram["flows"][$i]["FLO_UID"] = Hash::generateUID();
|
||||
Logger::log($flowData["FLO_ELEMENT_ORIGIN"], $result);
|
||||
$diagram["flows"][$i]["FLO_ELEMENT_ORIGIN"] = self::mapUid($flowData["FLO_ELEMENT_ORIGIN"], $result);
|
||||
$diagram["flows"][$i]["FLO_ELEMENT_DEST"] = self::mapUid($flowData["FLO_ELEMENT_DEST"], $result);
|
||||
|
||||
$whiteList[] = $diagram["flows"][$i]["FLO_UID"];
|
||||
$result[] = array("object" => "flow", "new_uid" => $diagram["flows"][$i]["FLO_UID"], "old_uid" => $oldFloUid);
|
||||
}
|
||||
foreach ($diagram["flows"] as $flowData) {
|
||||
|
||||
// flow exists ?
|
||||
if ($flow = $bwp->getFlow($flowData["FLO_UID"])) {
|
||||
// then update activity
|
||||
//$bwp->updateFlow($activityData["FLO_UID"], $flowData);
|
||||
|
||||
//$whiteList[] = $activityData["FLO_UID"];
|
||||
} else {
|
||||
// if not exists then create it
|
||||
$oldFloUid = $flowData["FLO_UID"];
|
||||
$flowData["FLO_UID"] = Hash::generateUID();
|
||||
$bwp->addFlow($flowData);
|
||||
|
||||
$result[] = array("object" => "flow", "new_uid" => $flowData["FLO_UID"], "old_uid" => $oldFloUid);
|
||||
$whiteList[] = $flowData["FLO_UID"];
|
||||
|
||||
//$bwp->addFlow($flowData);
|
||||
$bwp->addFlow($flowData, $diagram["flows"], $diagram["gateways"], $diagram["events"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,5 +333,16 @@ class Project extends Api
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
protected static function mapUid($oldUid, $list)
|
||||
{
|
||||
foreach ($list as $item) {
|
||||
if ($item["old_uid"] == $oldUid) {
|
||||
return $item["new_uid"];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user