updates to enable save flow connections between activity->activity and activity->gateway
This commit is contained in:
@@ -57,6 +57,19 @@ class BpmnFlow extends BaseBpmnFlow
|
|||||||
return $flows;
|
return $flows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function exists($floUid)
|
||||||
|
{
|
||||||
|
$c = new Criteria('workflow');
|
||||||
|
$c->add(BpmnFlowPeer::FLO_UID, $floUid);
|
||||||
|
|
||||||
|
return BpmnFlowPeer::doCount($c) > 0 ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fromArray($data, $type = BasePeer::TYPE_FIELDNAME)
|
||||||
|
{
|
||||||
|
parent::fromArray($data, $type);
|
||||||
|
}
|
||||||
|
|
||||||
public function toArray($type = BasePeer::TYPE_FIELDNAME)
|
public function toArray($type = BasePeer::TYPE_FIELDNAME)
|
||||||
{
|
{
|
||||||
return parent::toArray($type);
|
return parent::toArray($type);
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ class BpmnGateway extends BaseBpmnGateway
|
|||||||
{
|
{
|
||||||
// first, delete the related bound object
|
// first, delete the related bound object
|
||||||
if (! is_object($this->bound) || $this->bound->getBouUid() == "") {
|
if (! is_object($this->bound) || $this->bound->getBouUid() == "") {
|
||||||
$this->bound = BpmnBound::findByElement('Gateway', $this->getActUid());
|
$this->bound = BpmnBound::findByElement('Gateway', $this->getGatUid());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_object($this->bound)) {
|
if (is_object($this->bound)) {
|
||||||
|
|||||||
@@ -147,7 +147,10 @@ class BpmnWorkflow extends Project\Bpmn
|
|||||||
parent::addFlow($data);
|
parent::addFlow($data);
|
||||||
|
|
||||||
$routeData = self::mapBpmnFlowsToWorkflowRoute($data, $flows, $gateways, $events);
|
$routeData = self::mapBpmnFlowsToWorkflowRoute($data, $flows, $gateways, $events);
|
||||||
$this->wp->addRoute($routeData["from"], $routeData["to"], $routeData["type"]);
|
|
||||||
|
if ($routeData !== null) {
|
||||||
|
$this->wp->addRoute($routeData["from"], $routeData["to"], $routeData["type"]);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -258,6 +261,12 @@ class BpmnWorkflow extends Project\Bpmn
|
|||||||
{
|
{
|
||||||
$fromUid = $flow['FLO_ELEMENT_ORIGIN'];
|
$fromUid = $flow['FLO_ELEMENT_ORIGIN'];
|
||||||
|
|
||||||
|
if ($flow['FLO_ELEMENT_ORIGIN_TYPE'] != "bpmnActivity") {
|
||||||
|
// skip flows that comes from a element that is not an Activity
|
||||||
|
self::log("Skip map FlowsToWorkflowRoute for -> flow with FLO_UID: {$flow['FLO_UID']}, that have FLO_ELEMENT_ORIGIN: {$flow['FLO_ELEMENT_ORIGIN_TYPE']}:$fromUid");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if ($flow['FLO_TYPE'] != 'SEQUENCE') {
|
if ($flow['FLO_TYPE'] != 'SEQUENCE') {
|
||||||
throw new \LogicException(sprintf(
|
throw new \LogicException(sprintf(
|
||||||
"Unsupported flow type: %s, ProcessMaker only support type '', Given: '%s'",
|
"Unsupported flow type: %s, ProcessMaker only support type '', Given: '%s'",
|
||||||
@@ -275,8 +284,6 @@ class BpmnWorkflow extends Project\Bpmn
|
|||||||
// 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 = self::findInArray($gatUid, "FLO_ELEMENT_ORIGIN", $flows);
|
$gatFlow = self::findInArray($gatUid, "FLO_ELEMENT_ORIGIN", $flows);
|
||||||
self::log($gatUid, "FLO_ELEMENT_ORIGIN", $flows);
|
|
||||||
self::log("==============111===================>", $gatFlow);
|
|
||||||
|
|
||||||
//foreach ($gatFlows as $gatFlow) {
|
//foreach ($gatFlows as $gatFlow) {
|
||||||
switch ($gatFlow['FLO_ELEMENT_DEST_TYPE']) {
|
switch ($gatFlow['FLO_ELEMENT_DEST_TYPE']) {
|
||||||
@@ -284,7 +291,6 @@ class BpmnWorkflow extends Project\Bpmn
|
|||||||
// getting gateway properties
|
// getting gateway properties
|
||||||
//$gateway = BpmnModel::getBpmnObjectBy('Gateway', \BpmnGatewayPeer::GAT_UID, $gatUid);
|
//$gateway = BpmnModel::getBpmnObjectBy('Gateway', \BpmnGatewayPeer::GAT_UID, $gatUid);
|
||||||
$gateway = self::findInArray($gatUid, "GAT_UID", $gateways);
|
$gateway = self::findInArray($gatUid, "GAT_UID", $gateways);
|
||||||
self::log("==============222===================>", $gateway);
|
|
||||||
|
|
||||||
switch ($gateway['GAT_TYPE']) {
|
switch ($gateway['GAT_TYPE']) {
|
||||||
case 'SELECTION':
|
case 'SELECTION':
|
||||||
|
|||||||
@@ -344,6 +344,23 @@ class Bpmn extends Handler
|
|||||||
return $gateway->getGatUid();
|
return $gateway->getGatUid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updateGateway($gatUid, $data)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
self::log("Update Gateway: $gatUid", "With data: ", $data);
|
||||||
|
|
||||||
|
$gateway = GatewayPeer::retrieveByPk($gatUid);
|
||||||
|
|
||||||
|
$gateway->fromArray($data);
|
||||||
|
$gateway->save();
|
||||||
|
|
||||||
|
self::log("Update Gateway Success!");
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getGateway($gatUid, $retType = 'array')
|
public function getGateway($gatUid, $retType = 'array')
|
||||||
{
|
{
|
||||||
$gateway = GatewayPeer::retrieveByPK($gatUid);
|
$gateway = GatewayPeer::retrieveByPK($gatUid);
|
||||||
@@ -355,20 +372,41 @@ class Bpmn extends Handler
|
|||||||
return $gateway;
|
return $gateway;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getGateways($retType = 'array')
|
public function getGateways($start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
||||||
{
|
{
|
||||||
return Gateway::getAll($this->getUid(), null, null, '', $retType);
|
if (is_array($start)) {
|
||||||
|
extract($start);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Gateway::getAll($this->getUid(), null, null, '', $changeCaseTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeGateway($gatUid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
self::log("Remove Gateway: $gatUid");
|
||||||
|
|
||||||
|
$gateway = GatewayPeer::retrieveByPK($gatUid);
|
||||||
|
$gateway->delete();
|
||||||
|
|
||||||
|
self::log("Remove Gateway Success!");
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addFlow($data)
|
public function addFlow($data)
|
||||||
{
|
{
|
||||||
|
self::log("Add Flow with data: ", $data);
|
||||||
|
|
||||||
// setting defaults
|
// setting defaults
|
||||||
$data['FLO_UID'] = array_key_exists('FLO_UID', $data) ? $data['FLO_UID'] : Hash::generateUID();
|
$data['FLO_UID'] = array_key_exists('FLO_UID', $data) ? $data['FLO_UID'] : Hash::generateUID();
|
||||||
$data['FLO_STATE'] = is_array($data['FLO_STATE']) ? json_encode($data['FLO_STATE']) : $data['FLO_STATE'];
|
if (array_key_exists('FLO_STATE', $data)) {
|
||||||
|
$data['FLO_STATE'] = is_array($data['FLO_STATE']) ? json_encode($data['FLO_STATE']) : $data['FLO_STATE'];
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
self::log("Add Flow with data: ", $data);
|
|
||||||
|
|
||||||
$flow = new Flow();
|
$flow = new Flow();
|
||||||
$flow->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
$flow->fromArray($data, BasePeer::TYPE_FIELDNAME);
|
||||||
$flow->setPrjUid($this->getUid());
|
$flow->setPrjUid($this->getUid());
|
||||||
@@ -382,6 +420,26 @@ class Bpmn extends Handler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updateFlow($floUid, $data)
|
||||||
|
{
|
||||||
|
self::log("Update Flow: $floUid", "With data: ", $data);
|
||||||
|
|
||||||
|
// setting defaults
|
||||||
|
if (array_key_exists('FLO_STATE', $data)) {
|
||||||
|
$data['FLO_STATE'] = is_array($data['FLO_STATE']) ? json_encode($data['FLO_STATE']) : $data['FLO_STATE'];
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$flow = FlowPeer::retrieveByPk($floUid);
|
||||||
|
$flow->fromArray($data);
|
||||||
|
$flow->save();
|
||||||
|
|
||||||
|
self::log("Update Flow Success!");
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getFlow($floUid, $retType = 'array')
|
public function getFlow($floUid, $retType = 'array')
|
||||||
{
|
{
|
||||||
$flow = FlowPeer::retrieveByPK($floUid);
|
$flow = FlowPeer::retrieveByPK($floUid);
|
||||||
@@ -393,9 +451,28 @@ class Bpmn extends Handler
|
|||||||
return $flow;
|
return $flow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFlows($retType = 'array')
|
public function getFlows($start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
||||||
{
|
{
|
||||||
return Flow::getAll($this->getUid(), null, null, '', $retType);
|
if (is_array($start)) {
|
||||||
|
extract($start);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Flow::getAll($this->getUid(), null, null, '', $changeCaseTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeFlow($floUid)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
self::log("Remove Flow: $floUid");
|
||||||
|
|
||||||
|
$flow = FlowPeer::retrieveByPK($floUid);
|
||||||
|
$flow->delete();
|
||||||
|
|
||||||
|
self::log("Remove Flow Success!");
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addArtifact($data)
|
public function addArtifact($data)
|
||||||
|
|||||||
@@ -275,6 +275,7 @@ class Workflow extends Handler
|
|||||||
$oTasks->deleteAllRoutesOfTask($this->proUid, $fromTasUid);
|
$oTasks->deleteAllRoutesOfTask($this->proUid, $fromTasUid);
|
||||||
//$oTasks->deleteAllGatewayOfTask($this->proUid, $fromTasUid);
|
//$oTasks->deleteAllGatewayOfTask($this->proUid, $fromTasUid);
|
||||||
}
|
}
|
||||||
|
self::log("Add Route Success!");
|
||||||
|
|
||||||
return $this->saveNewPattern($this->proUid, $fromTasUid, $toTasUid, $type, $delete);
|
return $this->saveNewPattern($this->proUid, $fromTasUid, $toTasUid, $type, $delete);
|
||||||
|
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ class Project extends Api
|
|||||||
$diagram = array_change_key_case($diagram, CASE_LOWER);
|
$diagram = array_change_key_case($diagram, CASE_LOWER);
|
||||||
$diagram["activities"] = $bwp->getActivities(array("changeCaseTo" => CASE_LOWER));
|
$diagram["activities"] = $bwp->getActivities(array("changeCaseTo" => CASE_LOWER));
|
||||||
$diagram["events"] = $bwp->getEvents();
|
$diagram["events"] = $bwp->getEvents();
|
||||||
$diagram["gateways"] = $bwp->getGateways();
|
$diagram["gateways"] = $bwp->getGateways(array("changeCaseTo" => CASE_LOWER));
|
||||||
$diagram["flows"] = $bwp->getFlows();
|
$diagram["flows"] = $bwp->getFlows(array("changeCaseTo" => CASE_LOWER));
|
||||||
$diagram["artifacts"] = $bwp->getArtifacts();
|
$diagram["artifacts"] = $bwp->getArtifacts();
|
||||||
$diagram["laneset"] = $bwp->getLanesets();
|
$diagram["laneset"] = $bwp->getLanesets();
|
||||||
$diagram["lanes"] = $bwp->getLanes();
|
$diagram["lanes"] = $bwp->getLanes();
|
||||||
@@ -152,7 +152,7 @@ class Project extends Api
|
|||||||
*/
|
*/
|
||||||
$whiteList = array();
|
$whiteList = array();
|
||||||
foreach ($diagram["gateways"] as $i => $gatewayData) {
|
foreach ($diagram["gateways"] as $i => $gatewayData) {
|
||||||
$diagram["activities"][$i] = $gatewayData = array_change_key_case($gatewayData, CASE_UPPER);
|
$diagram["gateways"][$i] = $gatewayData = array_change_key_case($gatewayData, CASE_UPPER);
|
||||||
|
|
||||||
// gateway exists ?
|
// gateway exists ?
|
||||||
if ($gateway = $bwp->getGateway($gatewayData["GAT_UID"])) {
|
if ($gateway = $bwp->getGateway($gatewayData["GAT_UID"])) {
|
||||||
@@ -164,7 +164,8 @@ class Project extends Api
|
|||||||
// if not exists then create it
|
// if not exists then create it
|
||||||
$oldActUid = $gatewayData["GAT_UID"];
|
$oldActUid = $gatewayData["GAT_UID"];
|
||||||
$gatewayData["GAT_UID"] = Hash::generateUID();
|
$gatewayData["GAT_UID"] = Hash::generateUID();
|
||||||
$diagram["activities"][$i]["ACT_UID"] = $gatewayData["GAT_UID"];
|
Logger::log(" ==> updating gateway UID {$gatewayData["GAT_UID"]}->$oldActUid");
|
||||||
|
$diagram["gateways"][$i]["GAT_UID"] = $gatewayData["GAT_UID"];
|
||||||
|
|
||||||
$bwp->addGateway($gatewayData);
|
$bwp->addGateway($gatewayData);
|
||||||
|
|
||||||
@@ -173,53 +174,61 @@ class Project extends Api
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$activities = $bwp->getActivities();
|
$gateways = $bwp->getGateways();
|
||||||
|
|
||||||
// looking for removed elements
|
// looking for removed elements
|
||||||
foreach ($activities as $activityData) {
|
foreach ($gateways as $gatewayData) {
|
||||||
if (! in_array($activityData["ACT_UID"], $whiteList)) {
|
if (! in_array($gatewayData["GAT_UID"], $whiteList)) {
|
||||||
// If it is not in the white list so, then remove them
|
// If it is not in the white list so, then remove them
|
||||||
$bwp->removeActivity($activityData["ACT_UID"]);
|
$bwp->removeGateway($gatewayData["GAT_UID"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Diagram's Flows Handling
|
* Diagram's Flows Handling
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
$whiteList = array();
|
$whiteList = array();
|
||||||
|
|
||||||
foreach ($diagram["flows"] as $i => $flowData) {
|
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);
|
$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"];
|
// if it is a new flow record
|
||||||
$result[] = array("object" => "flow", "new_uid" => $diagram["flows"][$i]["FLO_UID"], "old_uid" => $oldFloUid);
|
if (! \BpmnFlow::exists($flowData["FLO_UID"])) {
|
||||||
|
$oldFloUid = $flowData["FLO_UID"];
|
||||||
|
$flowData["FLO_UID"] = Hash::generateUID();
|
||||||
|
|
||||||
|
$flowData["FLO_ELEMENT_ORIGIN"] = self::mapUid($flowData["FLO_ELEMENT_ORIGIN"], $result);
|
||||||
|
$flowData["FLO_ELEMENT_DEST"] = self::mapUid($flowData["FLO_ELEMENT_DEST"], $result);
|
||||||
|
|
||||||
|
$result[] = array("object" => "flow", "new_uid" => $flowData["FLO_UID"], "old_uid" => $oldFloUid);
|
||||||
|
$diagram["flows"][$i] = $flowData;
|
||||||
|
}
|
||||||
|
|
||||||
|
$whiteList[] = $flowData["FLO_UID"];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($diagram["flows"] as $flowData) {
|
foreach ($diagram["flows"] as $flowData) {
|
||||||
|
|
||||||
// flow exists ?
|
// flow exists ?
|
||||||
if ($flow = $bwp->getFlow($flowData["FLO_UID"])) {
|
if (\BpmnFlow::exists($flowData["FLO_UID"])) {
|
||||||
// then update activity
|
// then update activity
|
||||||
//$bwp->updateFlow($activityData["FLO_UID"], $flowData);
|
$bwp->updateFlow($flowData["FLO_UID"], $flowData);
|
||||||
|
|
||||||
//$whiteList[] = $activityData["FLO_UID"];
|
|
||||||
} else {
|
} else {
|
||||||
// if not exists then create it
|
// if not exists then create it
|
||||||
|
|
||||||
|
|
||||||
//$bwp->addFlow($flowData);
|
|
||||||
$bwp->addFlow($flowData, $diagram["flows"], $diagram["gateways"], $diagram["events"]);
|
$bwp->addFlow($flowData, $diagram["flows"], $diagram["gateways"], $diagram["events"]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$flows = $bwp->getFlows();
|
||||||
|
|
||||||
|
// looking for removed elements
|
||||||
|
foreach ($flows as $flowData) {
|
||||||
|
if (! in_array($flowData["FLO_UID"], $whiteList)) {
|
||||||
|
// If it is not in the white list so, then remove them
|
||||||
|
$bwp->removeFlow($flowData["FLO_UID"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -342,6 +351,8 @@ class Project extends Api
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new \Exception("oldUid: $oldUid not found in list:".print_r($list, true));
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user