Adding flow listener to save route conditions into workflow project from bpmn flows

This commit is contained in:
Erik Amaru Ortiz
2014-02-26 17:38:07 -04:00
parent 4a9474cd69
commit a368fa0066
2 changed files with 120 additions and 115 deletions

View File

@@ -368,8 +368,9 @@ class BpmnWorkflow extends Project\Bpmn
default: default:
throw new \LogicException(sprintf("Unsupported Gateway type: %s", $gateway['GAT_TYPE'])); throw new \LogicException(sprintf("Unsupported Gateway type: %s", $gateway['GAT_TYPE']));
} }
$condition = array_key_exists('FLO_CONDITION', $gatewayFlow) ? $gatewayFlow["FLO_CONDITION"] : '';
$this->wp->addRoute($activity["ACT_UID"], $gatewayFlow['FLO_ELEMENT_DEST'], $routeType); $this->wp->addRoute($activity["ACT_UID"], $gatewayFlow['FLO_ELEMENT_DEST'], $routeType, $condition);
break; break;
default: default:
// for processmaker is only allowed flows between "gateway -> activity" // for processmaker is only allowed flows between "gateway -> activity"
@@ -386,115 +387,115 @@ class BpmnWorkflow extends Project\Bpmn
} }
} }
public static function mapBpmnFlowsToWorkflowRoute2($flow, $flows, $gateways, $events) // public static function mapBpmnFlowsToWorkflowRoute2($flow, $flows, $gateways, $events)
{ // {
$fromUid = $flow['FLO_ELEMENT_ORIGIN']; // $fromUid = $flow['FLO_ELEMENT_ORIGIN'];
$result = array(); // $result = array();
//
if ($flow['FLO_ELEMENT_ORIGIN_TYPE'] != "bpmnActivity") { // if ($flow['FLO_ELEMENT_ORIGIN_TYPE'] != "bpmnActivity") {
// skip flows that comes from a element that is not an Activity // // 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"); // 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; // 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'",
'SEQUENCE', $flow['FLO_TYPE'] // 'SEQUENCE', $flow['FLO_TYPE']
)); // ));
} // }
//
switch ($flow['FLO_ELEMENT_DEST_TYPE']) { // switch ($flow['FLO_ELEMENT_DEST_TYPE']) {
case 'bpmnActivity': // case 'bpmnActivity':
// the most easy case, when the flow is connecting a activity with another activity // // 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'); // $result[] = array("from" => $fromUid, "to" => $flow['FLO_ELEMENT_DEST'], "type" => 'SEQUENTIAL');
break; // break;
case 'bpmnGateway': // case 'bpmnGateway':
$gatUid = $flow['FLO_ELEMENT_DEST']; // $gatUid = $flow['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 = self::findInArray($gatUid, "FLO_ELEMENT_ORIGIN", $flows); // $gatFlows = self::findInArray($gatUid, "FLO_ELEMENT_ORIGIN", $flows);
//
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
$gateways = self::findInArray($gatUid, "GAT_UID", $gateways); // $gateways = self::findInArray($gatUid, "GAT_UID", $gateways);
//
if (! empty($gateways)) { // if (! empty($gateways)) {
$gateway = $gateways[0]; // $gateway = $gateways[0];
$routeType = ""; // $routeType = "";
//
switch ($gateway['GAT_TYPE']) { // switch ($gateway['GAT_TYPE']) {
case self::BPMN_GATEWAY_COMPLEX: // case self::BPMN_GATEWAY_COMPLEX:
$routeType = 'SELECT'; // $routeType = 'SELECT';
break; // break;
case self::BPMN_GATEWAY_EXCLUSIVE: // case self::BPMN_GATEWAY_EXCLUSIVE:
$routeType = 'EVALUATE'; // $routeType = 'EVALUATE';
break; // break;
case self::BPMN_GATEWAY_INCLUSIVE: // case self::BPMN_GATEWAY_INCLUSIVE:
switch ($gateway['GAT_DIRECTION']) { // switch ($gateway['GAT_DIRECTION']) {
case "DIVERGING": // case "DIVERGING":
$routeType = 'PARALLEL-BY-EVALUATION'; // $routeType = 'PARALLEL-BY-EVALUATION';
break; // break;
case "CONVERGING": // case "CONVERGING":
$routeType = 'SEC-JOIN'; // $routeType = 'SEC-JOIN';
break; // break;
default: // default:
throw new \LogicException(sprintf("Unsupported Gateway direction: %s", $gateway['GAT_DIRECTION'])); // throw new \LogicException(sprintf("Unsupported Gateway direction: %s", $gateway['GAT_DIRECTION']));
} // }
break; // break;
case self::BPMN_GATEWAY_PARALLEL: // case self::BPMN_GATEWAY_PARALLEL:
switch ($gateway['GAT_DIRECTION']) { // switch ($gateway['GAT_DIRECTION']) {
case "DIVERGING": // case "DIVERGING":
$routeType = 'PARALLEL'; // $routeType = 'PARALLEL';
break; // break;
case "CONVERGING": // case "CONVERGING":
$routeType = 'SEC-JOIN'; // $routeType = 'SEC-JOIN';
break; // break;
default: // default:
throw new \LogicException(sprintf("Unsupported Gateway direction: %s", $gateway['GAT_DIRECTION'])); // throw new \LogicException(sprintf("Unsupported Gateway direction: %s", $gateway['GAT_DIRECTION']));
} // }
break; // break;
default: // default:
throw new \LogicException(sprintf("Unsupported Gateway type: %s", $gateway['GAT_TYPE'])); // throw new \LogicException(sprintf("Unsupported Gateway type: %s", $gateway['GAT_TYPE']));
} // }
//
$result[] = array("from" => $fromUid, "to" => $gatFlow['FLO_ELEMENT_DEST'], "type" => $routeType); // $result[] = array("from" => $fromUid, "to" => $gatFlow['FLO_ELEMENT_DEST'], "type" => $routeType);
} // }
break; // break;
default: // default:
// for processmaker is only allowed flows between "gateway -> activity" // // for processmaker is only allowed flows between "gateway -> activity"
// any another flow is considered invalid // // any another flow is considered invalid
throw new \LogicException(sprintf( // throw new \LogicException(sprintf(
"For ProcessMaker is only allowed flows between \"gateway -> activity\" " . PHP_EOL . // "For ProcessMaker is only allowed flows between \"gateway -> activity\" " . PHP_EOL .
"Given: bpmnGateway -> " . $gatFlow['FLO_ELEMENT_DEST_TYPE'] // "Given: bpmnGateway -> " . $gatFlow['FLO_ELEMENT_DEST_TYPE']
)); // ));
} // }
} // }
break; // break;
case 'bpmnEvent': // case 'bpmnEvent':
$evnUid = $flow['FLO_ELEMENT_DEST']; // $evnUid = $flow['FLO_ELEMENT_DEST'];
$events = self::findInArray($evnUid, "EVN_UID", $events); // $events = self::findInArray($evnUid, "EVN_UID", $events);
//
//
if (! empty($events)) { // if (! empty($events)) {
$event = $events[0]; // $event = $events[0];
//
switch ($event['EVN_TYPE']) { // switch ($event['EVN_TYPE']) {
case 'END': // case 'END':
$routeType = 'SEQUENTIAL'; // $routeType = 'SEQUENTIAL';
$result[] = array("from" => $fromUid, "to" => "-1", "type" => $routeType); // $result[] = array("from" => $fromUid, "to" => "-1", "type" => $routeType);
break; // break;
default: // default:
throw new \LogicException("Invalid connection to Event object type"); // throw new \LogicException("Invalid connection to Event object type");
} // }
} // }
break; // break;
} // }
//
return empty($result) ? null : $result; // return empty($result) ? null : $result;
} // }
public function remove() public function remove()
{ {

View File

@@ -269,7 +269,7 @@ class Workflow extends Handler
} }
} }
public function addRoute($fromTasUid, $toTasUid, $type, $delete = null) public function addRoute($fromTasUid, $toTasUid, $type, $condition = "")
{ {
try { try {
self::log("Add Route from task: $fromTasUid -> to task: $toTasUid ($type)"); self::log("Add Route from task: $fromTasUid -> to task: $toTasUid ($type)");
@@ -291,7 +291,7 @@ class Workflow extends Handler
//$oTasks->deleteAllRoutesOfTask($this->proUid, $fromTasUid); //$oTasks->deleteAllRoutesOfTask($this->proUid, $fromTasUid);
//} //}
$result = $this->saveNewPattern($this->proUid, $fromTasUid, $toTasUid, $type, $delete); $result = $this->saveNewPattern($this->proUid, $fromTasUid, $toTasUid, $type, $condition);
self::log("Add Route Success! - ROU_UID: ", $result); self::log("Add Route Success! - ROU_UID: ", $result);
return $result; return $result;
@@ -362,9 +362,9 @@ class Workflow extends Handler
return $route->load($rouUid); return $route->load($rouUid);
} }
public function getRoutes() public function getRoutes($start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
{ {
return Route::getAll($proUid = null, $start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER); return Route::getAll($this->getUid(), $start, $limit, $filter, $changeCaseTo);
} }
@@ -392,7 +392,7 @@ class Workflow extends Handler
} }
} }
private function saveNewPattern($sProcessUID = '', $sTaskUID = '', $sNextTask = '', $sType = '', $sDelete = '') private function saveNewPattern($sProcessUID = '', $sTaskUID = '', $sNextTask = '', $sType = '', $condition = '')
{ {
try { try {
$oCriteria = new Criteria('workflow'); $oCriteria = new Criteria('workflow');
@@ -413,6 +413,10 @@ class Workflow extends Handler
$aFields['ROU_TYPE'] = $sType; $aFields['ROU_TYPE'] = $sType;
$aFields['ROU_CASE'] = (int) $aRow['ROUTE_NUMBER'] + 1; $aFields['ROU_CASE'] = (int) $aRow['ROUTE_NUMBER'] + 1;
if(! empty($condition)) {
$aFields['ROU_CONDITION'] = $condition;
}
//$sGatewayUID = $aRow['GATEWAY_UID']; //$sGatewayUID = $aRow['GATEWAY_UID'];
//if ($sDelete && $sGatewayUID != '') { //if ($sDelete && $sGatewayUID != '') {