updates for adapter flows -> to -> route
This commit is contained in:
@@ -2,34 +2,52 @@
|
|||||||
"name": "processmaker/processmaker",
|
"name": "processmaker/processmaker",
|
||||||
"description": "BPM PHP Software",
|
"description": "BPM PHP Software",
|
||||||
"keywords": ["php bpm processmaker"],
|
"keywords": ["php bpm processmaker"],
|
||||||
"homepage": "http://www.processmaker.com",
|
"homepage": "http://processmaker.com",
|
||||||
"license": "AGPL-3.0",
|
"license": "GNU Affero General Public License version 3",
|
||||||
|
|
||||||
"repositories": [
|
"repositories": [
|
||||||
{
|
{
|
||||||
"packagist": false
|
"type": "package",
|
||||||
|
"package": {
|
||||||
|
"name": "jquery/jquery",
|
||||||
|
"version": "1.10.2",
|
||||||
|
"dist": {
|
||||||
|
"url": "http://code.jquery.com/jquery-1.10.2.min.js",
|
||||||
|
"type": "file"
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "composer",
|
"type": "package",
|
||||||
"url": "http://composer-public.colosa.net/"
|
"package": {
|
||||||
|
"name": "underscore/underscore",
|
||||||
|
"version": "1.5.2",
|
||||||
|
"dist": {
|
||||||
|
"url": "http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js",
|
||||||
|
"type": "file"
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "composer",
|
"type": "vcs",
|
||||||
"url": "http://composer.colosa.net/"
|
"url": "git@bitbucket.org:colosa/pmUI.git"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "vcs",
|
||||||
|
"url": "git@bitbucket.org:colosa/MichelangeloFE.git"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
"require": {
|
"require": {
|
||||||
"php":">=5.3.3",
|
|
||||||
"underscore/underscore": "1.5.2",
|
|
||||||
"jquery/jquery": "1.10.2",
|
|
||||||
"luracast/restler" : "v3.0.0",
|
"luracast/restler" : "v3.0.0",
|
||||||
"bshaffer/oauth2-server-php": "v1.0",
|
"bshaffer/oauth2-server-php": "v1.0",
|
||||||
"colosa/restclient": "0.1.7",
|
"jquery/jquery": "1.10.2",
|
||||||
|
"underscore/underscore": "1.5.2",
|
||||||
"colosa/pmUI": "dev-master",
|
"colosa/pmUI": "dev-master",
|
||||||
"colosa/MichelangeloFE": "dev-master"
|
"colosa/MichelangeloFE": "dev-master"
|
||||||
},
|
},
|
||||||
"require-dev":{
|
"require-dev":{
|
||||||
"guzzle/guzzle":"~3.1.1",
|
"guzzle/guzzle":"~3.1.1",
|
||||||
"behat/behat":"2.4.6@stable"
|
"behat/behat":"2.4.*@stable"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,21 @@ require_once 'classes/model/om/BaseBpmnFlow.php';
|
|||||||
*/
|
*/
|
||||||
class BpmnFlow extends BaseBpmnFlow
|
class BpmnFlow extends BaseBpmnFlow
|
||||||
{
|
{
|
||||||
|
public static function findOneBy($field, $value)
|
||||||
|
{
|
||||||
|
$rows = self::findAllBy($field, $value);
|
||||||
|
|
||||||
|
return empty($rows) ? null : $rows[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function findAllBy($field, $value)
|
||||||
|
{
|
||||||
|
$c = new Criteria('workflow');
|
||||||
|
$c->add($field, $value, Criteria::EQUAL);
|
||||||
|
|
||||||
|
return BpmnFlowPeer::doSelect($c);
|
||||||
|
}
|
||||||
|
|
||||||
public static function getAll($prjUid = null, $start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
public static function getAll($prjUid = null, $start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
||||||
{
|
{
|
||||||
//TODO implement $start, $limit and $filter
|
//TODO implement $start, $limit and $filter
|
||||||
|
|||||||
@@ -21,42 +21,107 @@ class BpmnGateway extends BaseBpmnGateway
|
|||||||
public function __construct($generateUid = true)
|
public function __construct($generateUid = true)
|
||||||
{
|
{
|
||||||
$this->bound = new BpmnBound();
|
$this->bound = new BpmnBound();
|
||||||
|
$this->setBoundDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBound()
|
||||||
|
{
|
||||||
|
return $this->bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setBoundDefaults()
|
||||||
|
{
|
||||||
$this->bound->setBouElementType(lcfirst(str_replace(__NAMESPACE__, '', __CLASS__)));
|
$this->bound->setBouElementType(lcfirst(str_replace(__NAMESPACE__, '', __CLASS__)));
|
||||||
$this->bound->setBouElement('pm_canvas');
|
$this->bound->setBouElement('pm_canvas');
|
||||||
$this->bound->setBouContainer('bpmnDiagram');
|
$this->bound->setBouContainer('bpmnDiagram');
|
||||||
|
|
||||||
|
$this->bound->setPrjUid($this->getPrjUid());
|
||||||
|
$this->bound->setElementUid($this->getGatUid());
|
||||||
|
|
||||||
|
$process = BpmnProcessPeer::retrieveByPK($this->getProUid());
|
||||||
|
|
||||||
|
if (is_object($process)) {
|
||||||
|
$this->bound->setDiaUid($process->getDiaUid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function findOneBy($field, $value)
|
||||||
|
{
|
||||||
|
$rows = self::findAllBy($field, $value);
|
||||||
|
|
||||||
|
return empty($rows) ? null : $rows[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function findAllBy($field, $value)
|
||||||
|
{
|
||||||
|
$c = new Criteria('workflow');
|
||||||
|
$c->add($field, $value, Criteria::EQUAL);
|
||||||
|
|
||||||
|
return BpmnGatewayPeer::doSelect($c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getAll($prjUid = null, $start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
||||||
|
{
|
||||||
|
$c = new Criteria('workflow');
|
||||||
|
$c->addSelectColumn("BPMN_GATEWAY.*");
|
||||||
|
$c->addSelectColumn("BPMN_BOUND.*");
|
||||||
|
$c->addJoin(BpmnGatewayPeer::GAT_UID, BpmnBoundPeer::ELEMENT_UID, Criteria::LEFT_JOIN);
|
||||||
|
|
||||||
|
if (! is_null($prjUid)) {
|
||||||
|
$c->add(BpmnGatewayPeer::PRJ_UID, $prjUid, Criteria::EQUAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
$rs = BpmnGatewayPeer::doSelectRS($c);
|
||||||
|
$rs->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||||
|
|
||||||
|
$activities = array();
|
||||||
|
|
||||||
|
while ($rs->next()) {
|
||||||
|
$activities[] = $changeCaseTo !== CASE_UPPER ? array_change_key_case($rs->getRow(), CASE_LOWER) : $rs->getRow();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $activities;
|
||||||
}
|
}
|
||||||
|
|
||||||
// OVERRIDES
|
// OVERRIDES
|
||||||
|
|
||||||
public function fromArray($data)
|
public function setActUid($actUid)
|
||||||
{
|
{
|
||||||
parent::fromArray($data, BasePeer::TYPE_FIELDNAME);
|
parent::setActUid($actUid);
|
||||||
|
$this->bound->setElementUid($this->getActUid());
|
||||||
|
}
|
||||||
|
|
||||||
// try resolve the related bound
|
public function setPrjUid($prjUid)
|
||||||
if (array_key_exists('BOU_UID', $data)) {
|
{
|
||||||
$bound = BpmnBoundPeer::retrieveByPK($data['BOU_UID']);
|
parent::setPrjUid($prjUid);
|
||||||
|
$this->bound->setPrjUid($this->getPrjUid());
|
||||||
|
}
|
||||||
|
|
||||||
if (is_object($bound)) {
|
public function setProUid($proUid)
|
||||||
$this->bound = $bound;
|
{
|
||||||
}
|
parent::setProUid($proUid);
|
||||||
}
|
|
||||||
|
|
||||||
$this->bound->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
$process = BpmnProcessPeer::retrieveByPK($this->getProUid());
|
||||||
|
$this->bound->setDiaUid($process->getDiaUid());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function save($con = null)
|
public function save($con = null)
|
||||||
{
|
{
|
||||||
parent::save($con);
|
parent::save($con);
|
||||||
|
|
||||||
if (is_object($this->bound) && get_class($this->bound) == 'BpmnBound') {
|
$this->setBoundDefaults();
|
||||||
$this->bound->save($con);
|
|
||||||
|
if ($this->bound->getBouUid() == "") {
|
||||||
|
$this->bound->setBouUid(\ProcessMaker\Util\Hash::generateUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->bound->save($con);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete($con = null)
|
public function delete($con = null)
|
||||||
{
|
{
|
||||||
// first, delete the related bound object
|
// first, delete the related bound object
|
||||||
if (! is_object($this->bound)) {
|
if (! is_object($this->bound) || $this->bound->getBouUid() == "") {
|
||||||
$this->bound = BpmnBound::findByElement('Gateway', $this->getActUid());
|
$this->bound = BpmnBound::findByElement('Gateway', $this->getActUid());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,14 +132,37 @@ class BpmnGateway extends BaseBpmnGateway
|
|||||||
parent::delete($con);
|
parent::delete($con);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toArray($keyType = BasePeer::TYPE_PHPNAME)
|
public function fromArray($data, $type = BasePeer::TYPE_FIELDNAME)
|
||||||
{
|
{
|
||||||
$data = parent::toArray($keyType);
|
parent::fromArray($data, $type);
|
||||||
|
|
||||||
if (is_object($this->bound) && get_class($this->bound) == 'BpmnBound') {
|
$bound = BpmnBound::findByElement('Gateway', $this->getGatUid());
|
||||||
$data = array_merge($data, $this->bound->toArray($keyType));
|
|
||||||
|
if (is_object($bound)) {
|
||||||
|
$this->bound = $bound;
|
||||||
|
} else {
|
||||||
|
$this->bound = new BpmnBound();
|
||||||
|
$this->bound->setBouUid(ProcessMaker\Util\Hash::generateUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->bound->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function toArray($type = BasePeer::TYPE_FIELDNAME)
|
||||||
|
{
|
||||||
|
$data = parent::toArray($type);
|
||||||
|
$bouUid = $this->bound->getBouUid();
|
||||||
|
|
||||||
|
if (empty($bouUid)) {
|
||||||
|
$bound = BpmnBound::findByElement('Gateway', $this->getGatUid());
|
||||||
|
|
||||||
|
if (is_object($bound)) {
|
||||||
|
$this->bound = $bound;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = array_merge($data, $this->bound->toArray($type));
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class BpmnGatewayMapBuilder
|
|||||||
|
|
||||||
$tMap->addColumn('GAT_TYPE', 'GatType', 'string', CreoleTypes::VARCHAR, true, 30);
|
$tMap->addColumn('GAT_TYPE', 'GatType', 'string', CreoleTypes::VARCHAR, true, 30);
|
||||||
|
|
||||||
$tMap->addColumn('GAT_DIRECTION', 'GatDirection', 'string', CreoleTypes::VARCHAR, true, 30);
|
$tMap->addColumn('GAT_DIRECTION', 'GatDirection', 'string', CreoleTypes::VARCHAR, false, 30);
|
||||||
|
|
||||||
$tMap->addColumn('GAT_INSTANTIATE', 'GatInstantiate', 'int', CreoleTypes::TINYINT, false, null);
|
$tMap->addColumn('GAT_INSTANTIATE', 'GatInstantiate', 'int', CreoleTypes::TINYINT, false, null);
|
||||||
|
|
||||||
|
|||||||
@@ -3367,7 +3367,7 @@
|
|||||||
<column name="PRO_UID" type="VARCHAR" size="32" required="false" default=""/>
|
<column name="PRO_UID" type="VARCHAR" size="32" required="false" default=""/>
|
||||||
<column name="GAT_NAME" type="VARCHAR" size="255" required="false"/>
|
<column name="GAT_NAME" type="VARCHAR" size="255" required="false"/>
|
||||||
<column name="GAT_TYPE" type="VARCHAR" size="30" required="true" default=""/>
|
<column name="GAT_TYPE" type="VARCHAR" size="30" required="true" default=""/>
|
||||||
<column name="GAT_DIRECTION" type="VARCHAR" size="30" required="true" default="UNSPECIFIED"/>
|
<column name="GAT_DIRECTION" type="VARCHAR" size="30" required="false" default="UNSPECIFIED"/>
|
||||||
<column name="GAT_INSTANTIATE" type="TINYINT" required="false" default="0"/>
|
<column name="GAT_INSTANTIATE" type="TINYINT" required="false" default="0"/>
|
||||||
<column name="GAT_EVENT_GATEWAT_TYPE" type="VARCHAR" size="20" required="false" default="NONE"/>
|
<column name="GAT_EVENT_GATEWAT_TYPE" type="VARCHAR" size="20" required="false" default="NONE"/>
|
||||||
<column name="GAT_ACTIVATION_COUNT" type="INTEGER" required="false" default="0"/>
|
<column name="GAT_ACTIVATION_COUNT" type="INTEGER" required="false" default="0"/>
|
||||||
|
|||||||
@@ -1894,7 +1894,7 @@ CREATE TABLE `BPMN_GATEWAY`
|
|||||||
`PRO_UID` VARCHAR(32) default '',
|
`PRO_UID` VARCHAR(32) default '',
|
||||||
`GAT_NAME` VARCHAR(255),
|
`GAT_NAME` VARCHAR(255),
|
||||||
`GAT_TYPE` VARCHAR(30) default '' NOT NULL,
|
`GAT_TYPE` VARCHAR(30) default '' NOT NULL,
|
||||||
`GAT_DIRECTION` VARCHAR(30) default 'UNSPECIFIED' NOT NULL,
|
`GAT_DIRECTION` VARCHAR(30) default 'UNSPECIFIED',
|
||||||
`GAT_INSTANTIATE` TINYINT default 0,
|
`GAT_INSTANTIATE` TINYINT default 0,
|
||||||
`GAT_EVENT_GATEWAT_TYPE` VARCHAR(20) default 'NONE',
|
`GAT_EVENT_GATEWAT_TYPE` VARCHAR(20) default 'NONE',
|
||||||
`GAT_ACTIVATION_COUNT` INTEGER default 0,
|
`GAT_ACTIVATION_COUNT` INTEGER default 0,
|
||||||
|
|||||||
@@ -142,10 +142,15 @@ class BpmnWorkflow extends Project\Bpmn
|
|||||||
$this->wp->removeTask($actUid);
|
$this->wp->removeTask($actUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addFlow($data)
|
public function addFlow($data, $flows, $gateways, $events)
|
||||||
{
|
{
|
||||||
parent::addFlow($data);
|
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'];
|
$fromUid = $data['FLO_ELEMENT_ORIGIN'];
|
||||||
|
|
||||||
if ($data['FLO_TYPE'] != 'SEQUENCE') {
|
if ($data['FLO_TYPE'] != 'SEQUENCE') {
|
||||||
@@ -170,13 +175,17 @@ class BpmnWorkflow extends Project\Bpmn
|
|||||||
case 'bpmnGateway':
|
case 'bpmnGateway':
|
||||||
$gatUid = $data['FLO_ELEMENT_DEST'];
|
$gatUid = $data['FLO_ELEMENT_DEST'];
|
||||||
// if it is a gateway it can fork one or more routes
|
// 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']) {
|
switch ($gatFlow['FLO_ELEMENT_DEST_TYPE']) {
|
||||||
case 'bpmnActivity':
|
case 'bpmnActivity':
|
||||||
// getting gateway properties
|
// 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']) {
|
switch ($gateway['GAT_TYPE']) {
|
||||||
case 'SELECTION':
|
case 'SELECTION':
|
||||||
@@ -198,14 +207,15 @@ class BpmnWorkflow extends Project\Bpmn
|
|||||||
throw new \LogicException(sprintf("Unsupported Gateway type: %s", $gateway['GAT_TYPE']));
|
throw new \LogicException(sprintf("Unsupported Gateway type: %s", $gateway['GAT_TYPE']));
|
||||||
}
|
}
|
||||||
|
|
||||||
$routes[] = array(
|
/*$routes[] = array(
|
||||||
'ROU_UID' => $gatFlow['FLO_UID'], //Hash::generateUID(),
|
'ROU_UID' => $gatFlow['FLO_UID'], //Hash::generateUID(),
|
||||||
'PRO_UID' => $this->getUid(),
|
'PRO_UID' => $this->getUid(),
|
||||||
'TAS_UID' => $fromUid,
|
'TAS_UID' => $fromUid,
|
||||||
'ROU_NEXT_TASK' => $gatFlow['FLO_ELEMENT_DEST'],
|
'ROU_NEXT_TASK' => $gatFlow['FLO_ELEMENT_DEST'],
|
||||||
'ROU_TYPE' => $routeType,
|
'ROU_TYPE' => $routeType
|
||||||
'_action' => 'CREATE'
|
);*/
|
||||||
);
|
|
||||||
|
$this->wp->addRoute($fromUid, $gatFlow['FLO_ELEMENT_DEST'], $routeType);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// for processmaker is only allowed flows between "gateway -> activity"
|
// 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']
|
"Given: bpmnGateway -> " . $gatFlow['FLO_ELEMENT_DEST_TYPE']
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
//}
|
||||||
break;
|
break;
|
||||||
case 'bpmnEvent':
|
case 'bpmnEvent':
|
||||||
$evnUid = $data['FLO_ELEMENT_DEST'];
|
$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()));
|
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 {
|
try {
|
||||||
self::log("Add Activity with data: ", $data);
|
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 = new Activity();
|
||||||
$activity->fromArray($data);
|
$activity->fromArray($data);
|
||||||
$activity->setPrjUid($this->getUid());
|
$activity->setPrjUid($this->getUid());
|
||||||
@@ -327,34 +327,37 @@ class Bpmn extends Handler
|
|||||||
// setting defaults
|
// setting defaults
|
||||||
$data['GAT_UID'] = array_key_exists('GAT_UID', $data) ? $data['GAT_UID'] : Hash::generateUID();
|
$data['GAT_UID'] = array_key_exists('GAT_UID', $data) ? $data['GAT_UID'] : Hash::generateUID();
|
||||||
|
|
||||||
$gateway = new Gateway();
|
try {
|
||||||
$gateway->fromArray($data);
|
self::log("Add Gateway with data: ", $data);
|
||||||
$gateway->setPrjUid($this->project->getPrjUid());
|
$gateway = new Gateway();
|
||||||
$gateway->setProUid($this->getProcess("object")->getProUid());
|
$gateway->fromArray($data);
|
||||||
$gateway->save();
|
$gateway->setPrjUid($this->getUid());
|
||||||
|
$gateway->setProUid($this->getProcess("object")->getProUid());
|
||||||
|
$gateway->save();
|
||||||
|
|
||||||
$this->gateways[$gateway->getGatUid()] = $gateway;
|
self::log("Add Gateway Success!");
|
||||||
}
|
} catch (\Exception $e) {
|
||||||
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||||
public function getGateway($gatUid)
|
throw $e;
|
||||||
{
|
|
||||||
if (empty($this->gateways) || ! array_key_exists($gatUid, $this->gateways)) {
|
|
||||||
$gateway = GatewayPeer::retrieveByPK($gatUid);
|
|
||||||
|
|
||||||
if (! is_object($gateway)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->gateways[$gatUid] = $gateway;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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')
|
public function getGateways($retType = 'array')
|
||||||
{
|
{
|
||||||
//return Activity::getAll($this->project->getPrjUid(), null, null, '', $retType);
|
return Gateway::getAll($this->getUid(), null, null, '', $retType);
|
||||||
return array();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addFlow($data)
|
public function addFlow($data)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use Luracast\Restler\RestException;
|
|||||||
use ProcessMaker\Services\Api;
|
use ProcessMaker\Services\Api;
|
||||||
use ProcessMaker\Adapter\Bpmn\Model as BpmnModel;
|
use ProcessMaker\Adapter\Bpmn\Model as BpmnModel;
|
||||||
use ProcessMaker\Util\Hash;
|
use ProcessMaker\Util\Hash;
|
||||||
|
use ProcessMaker\Util\Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Project
|
* Class Project
|
||||||
@@ -110,21 +111,12 @@ class Project extends Api
|
|||||||
|
|
||||||
$result = array();
|
$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
|
* Diagram's Activities Handling
|
||||||
*/
|
*/
|
||||||
$whiteList = array();
|
$whiteList = array();
|
||||||
foreach ($diagram["activities"] as $activityData) {
|
foreach ($diagram["activities"] as $i => $activityData) {
|
||||||
$activityData = array_change_key_case($activityData, CASE_UPPER);
|
$diagram["activities"][$i] = $activityData = array_change_key_case($activityData, CASE_UPPER);
|
||||||
|
|
||||||
// activity exists ?
|
// activity exists ?
|
||||||
if ($activity = $bwp->getActivity($activityData["ACT_UID"])) {
|
if ($activity = $bwp->getActivity($activityData["ACT_UID"])) {
|
||||||
@@ -135,12 +127,13 @@ class Project extends Api
|
|||||||
} else {
|
} else {
|
||||||
// if not exists then create it
|
// if not exists then create it
|
||||||
$oldActUid = $activityData["ACT_UID"];
|
$oldActUid = $activityData["ACT_UID"];
|
||||||
$actUid = Hash::generateUID();
|
$activityData["ACT_UID"] = Hash::generateUID();
|
||||||
$activityData["ACT_UID"] = $actUid;
|
$diagram["activities"][$i]["ACT_UID"] = $activityData["ACT_UID"];
|
||||||
|
|
||||||
$bwp->addActivity($activityData);
|
$bwp->addActivity($activityData);
|
||||||
|
|
||||||
$result[] = array("object" => "activity", "new_uid" => $actUid, "old_uid" => $oldActUid);
|
$result[] = array("object" => "activity", "new_uid" => $activityData["ACT_UID"], "old_uid" => $oldActUid);
|
||||||
$whiteList[] = $actUid;
|
$whiteList[] = $activityData["ACT_UID"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,26 +148,75 @@ class Project extends Api
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Diagram's Flows Handling
|
* Diagram's Gateways Handling
|
||||||
*/
|
*/
|
||||||
$whiteList = array();
|
$whiteList = array();
|
||||||
foreach ($diagram["flows"] as $flowData) {
|
foreach ($diagram["gateways"] as $i => $gatewayData) {
|
||||||
$flowData = array_change_key_case($flowData, CASE_UPPER);
|
$diagram["activities"][$i] = $gatewayData = array_change_key_case($gatewayData, CASE_UPPER);
|
||||||
|
|
||||||
// activity exists ?
|
// gateway exists ?
|
||||||
if ($activity = $bwp->getFlow($flowData["FLO_UID"])) {
|
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
|
// then update activity
|
||||||
//$bwp->updateFlow($activityData["FLO_UID"], $flowData);
|
//$bwp->updateFlow($activityData["FLO_UID"], $flowData);
|
||||||
|
|
||||||
//$whiteList[] = $activityData["FLO_UID"];
|
//$whiteList[] = $activityData["FLO_UID"];
|
||||||
} else {
|
} else {
|
||||||
// if not exists then create it
|
// 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()));
|
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