More Update for BpmnWorkflow Adapter class, now start and end tasks are updating successfully on Workflow Layer

This commit is contained in:
Erik Amaru Ortiz
2014-02-12 17:01:19 -04:00
parent 813bfae124
commit 79ee31b761
9 changed files with 143 additions and 91 deletions

View File

@@ -48,7 +48,6 @@
},
"require-dev":{
"guzzle/guzzle":"~3.1.1",
"behat/behat":"2.4.*@stable",
"lisachenko/go-aop-php": "*"
"behat/behat":"2.4.*@stable"
}
}

View File

@@ -3095,7 +3095,10 @@ class Bootstrap
);
}
require_once PATH_TRUNK . 'vendor' . PATH_SEP . "autoload.php";
//require_once PATH_TRUNK . 'vendor' . PATH_SEP . "autoload.php";
$loader = require PATH_TRUNK . 'vendor' . PATH_SEP . "autoload.php";
$loader->add('', PATH_HOME . 'engine/src/');
}
public static function parseIniFile($filename)

View File

@@ -3294,7 +3294,7 @@ class G
*
* @author Erik A.O. <erik@colosa.com>
*/
public function json_encode($Json)
public static function json_encode($Json)
{
if ( function_exists('json_encode') ) {
return json_encode($Json);

View File

@@ -16,6 +16,11 @@ require_once 'classes/model/om/BaseBpmnFlow.php';
*/
class BpmnFlow extends BaseBpmnFlow
{
/**
* @param $field string coming from \BpmnFlowPeer::<FIELD_NAME>
* @param $value string
* @return \BpmnFlow|null
*/
public static function findOneBy($field, $value)
{
$rows = self::findAllBy($field, $value);

View File

@@ -213,5 +213,30 @@ class Route extends BaseRoute
}
return $value;
}
/**
* @param $field
* @param null $value
* @return \Route|null
*/
public static function findOneBy($field, $value = null)
{
$rows = self::findAllBy($field, $value);
return empty($rows) ? null : $rows[0];
}
public static function findAllBy($field, $value = null)
{
$field = is_array($field) ? $field : array($field => $value);
$c = new Criteria('workflow');
foreach ($field as $key => $value) {
$c->add($key, $value, Criteria::EQUAL);
}
return RoutePeer::doSelect($c);
}
}

View File

@@ -38,24 +38,28 @@ if ($access != 1) {
break;
}
}
G::LoadClass( 'processMap' );
$oProcessMap = new ProcessMap();
//G::LoadClass( 'processMap' );
//$oProcessMap = new ProcessMap();
$UIDS = explode( ',', $_POST['PRO_UIDS'] );
$uids = explode(',', $_POST['PRO_UIDS']);
try {
foreach ($UIDS as $UID) {
$oProcessMap->deleteProcess($UID);
//ProcessMaker\Adapter\Bpmn\Model::deleteProject($UID);
foreach ($uids as $uid) {
//$oProcessMap->deleteProcess($uid);
ProcessMaker\Project\Workflow::removeIfExists($uid);
ProcessMaker\Project\Bpmn::removeIfExists($uid);
}
$resp = new StdClass();
$resp->status = 0;
$resp->msg = 'All process was deleted successfully';
echo G::json_encode( $resp );
echo G::json_encode($resp);
} catch (Exception $e) {
$resp->status = 1;
$resp->msg = $e->getMessage();
echo G::json_encode( $resp );
echo G::json_encode($resp);
}

View File

@@ -163,12 +163,8 @@ class BpmnWorkflow extends Project\Bpmn
switch ($event && $event->getEvnType()) {
case "START":
self::log("Setting Task:" . $data["FLO_ELEMENT_DEST"] . " as STARTING TASK");
// then set that activity/task as "Start Task"
$this->wp->updateTask($data["FLO_ELEMENT_DEST"], array("TAS_START" => "TRUE"));
self::log("Setting as \"Stating Task\" Success!");
$this->wp->setStartTask($data["FLO_ELEMENT_DEST"]);
break;
}
break;
@@ -177,6 +173,10 @@ class BpmnWorkflow extends Project\Bpmn
}
}
public function removeFlow($floUid)
{
parent::removeFlow($floUid);
}
public function addEvent($data)
{
@@ -189,32 +189,27 @@ class BpmnWorkflow extends Project\Bpmn
public function removeEvent($evnUid)
{
$flow = \BpmnFlowPeer::retrieveByPK($evnUid);
$event = \BpmnEventPeer::retrieveByPK($evnUid);
if (! is_null($flow)) {
$data = $flow->toArray();
// 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":
self::log("Unset Task:" . $data["FLO_ELEMENT_DEST"] . " as NOT STARTING TASK");
// then set that activity/task as "Start Task"
$this->wp->updateTask($data["FLO_ELEMENT_DEST"], array("TAS_START" => "FALSE"));
self::log("Unset as \"Stating Task\" Success!");
break;
}
break;
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;
}
}
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;
}
parent::removeEvent($evnUid);

View File

@@ -86,12 +86,14 @@ class Bpmn extends Handler
// setting defaults
$data['PRJ_UID'] = array_key_exists('PRJ_UID', $data) ? $data['PRJ_UID'] : Hash::generateUID();
self::log("Create Project with data: ", $data);
$this->project = new Project();
$this->project->fromArray($data, BasePeer::TYPE_FIELDNAME);
$this->project->setPrjCreateDate(date("Y-m-d H:i:s"));
$this->project->save();
$this->prjUid = $this->project->getPrjUid();
self::log("Create Project Success!");
}
public function update()
@@ -106,11 +108,20 @@ class Bpmn extends Handler
* 2. Remove Project related objects
*/
$activities = $this->getActivities();
foreach ($activities as $activity) {
self::log("Remove Project With Uid: {$this->prjUid}");
foreach ($this->getActivities() as $activity) {
$this->removeActivity($activity["ACT_UID"]);
}
foreach ($this->getGateways() as $gateway) {
$this->removeGateway($gateway["GAT_UID"]);
}
foreach ($this->getEvents() as $event) {
$this->removeEvent($event["EVN_UID"]);
}
foreach ($this->getFlows() as $flow) {
$this->removeFlow($flow["FLO_UID"]);
}
if ($process = $this->getProcess("object")) {
$process->delete();
}
@@ -120,6 +131,19 @@ class Bpmn extends Handler
if ($project = $this->getProject("object")) {
$project->delete();
}
self::log("Remove Project Success!");
}
public static function removeIfExists($prjUid)
{
$project = ProjectPeer::retrieveByPK($prjUid);
if ($project) {
$me = new self();
$me->prjUid = $project->getPrjUid();
$me->project = $project;
$me->remove();
}
}
public static function getList($start = null, $limit = null, $filter = "", $changeCaseTo = CASE_UPPER)

View File

@@ -54,15 +54,15 @@ class Workflow extends Handler
public function create($data)
{
// setting defaults
$data['PRO_UID'] = array_key_exists('PRO_UID', $data) ? $data['PRO_UID'] : Hash::generateUID();
$data['USR_UID'] = array_key_exists('PRO_CREATE_USER', $data) ? $data['PRO_CREATE_USER'] : null;
$data['PRO_TITLE'] = array_key_exists('PRO_TITLE', $data) ? trim($data['PRO_TITLE']) : "";
$data['PRO_CATEGORY'] = array_key_exists('PRO_CATEGORY', $data) ? $data['PRO_CATEGORY'] : "";
try {
self::log("===> Executing -> ".__METHOD__, "Create Process with data:", $data);
// setting defaults
$data['PRO_UID'] = array_key_exists('PRO_UID', $data) ? $data['PRO_UID'] : Hash::generateUID();
$data['USR_UID'] = array_key_exists('PRO_CREATE_USER', $data) ? $data['PRO_CREATE_USER'] : null;
$data['PRO_TITLE'] = array_key_exists('PRO_TITLE', $data) ? trim($data['PRO_TITLE']) : "";
$data['PRO_CATEGORY'] = array_key_exists('PRO_CATEGORY', $data) ? $data['PRO_CATEGORY'] : "";
//validate if process with specified name already exists
if (Process::existsByProTitle($data["PRO_TITLE"])) {
throw new Exception\ProjectAlreadyExists($this, $data["PRO_TITLE"]);
@@ -111,6 +111,17 @@ class Workflow extends Handler
}
}
public static function removeIfExists($proUid)
{
$process = \ProcessPeer::retrieveByPK($proUid);
if ($process) {
$me = new self();
$me->proUid = $process->getProUid();
$me->remove();
}
}
public static function getList($start = null, $limit = null, $filter = "", $changeCaseTo = CASE_UPPER)
{
//return Project::getAll($start, $limit, $filter, $changeCaseTo);
@@ -211,16 +222,33 @@ class Workflow extends Handler
return $tasks->getAllTasks($this->proUid);
}
public function setStartTask($tasUid)
public function setStartTask($tasUid, $value = true)
{
$value = $value ? "TRUE" : "FALSE";
self::log("Setting Start Task with Uid: $tasUid: $value");
$task = \TaskPeer::retrieveByPK($tasUid);
$task->setTasStart("TRUE");
$task->setTasStart($value);
$task->save();
self::log("Setting Start Task -> $value, Success!");
}
public function setEndTask($tasUid)
public function setEndTask($tasUid, $value = true)
{
$this->addSequentialRoute($tasUid, "-1", "SEQUENTIAL", true);
self::log("Setting End Task with Uid: $tasUid: " . ($value ? "TRUE" : "FALSE"));
if ($value) {
$this->addSequentialRoute($tasUid, "-1");
} else {
$route = \Route::findOneBy(array(
\RoutePeer::TAS_UID => $tasUid,
\RoutePeer::ROU_NEXT_TASK => "-1"
));
if (! is_null($route)) {
$this->removeRoute($route->getRouUid());
}
}
self::log("Setting End Task -> ".($value ? "TRUE" : "FALSE").", Success!");
}
public function addSequentialRoute($fromTasUid, $toTasUid, $delete = null)
@@ -239,32 +267,6 @@ class Workflow extends Handler
{
try {
self::log("Add Route from task: $fromTasUid -> to task: $toTasUid ($type)");
/*switch ($type) {
case 0:
$sType = 'SEQUENTIAL';
break;
case 1:
$sType = 'SELECT';
break;
case 2:
$sType = 'EVALUATE';
break;
case 3:
$sType = 'PARALLEL';
break;
case 4:
$sType = 'PARALLEL-BY-EVALUATION';
break;
case 5:
$sType = 'SEC-JOIN';
break;
case 8:
$sType = 'DISCRIMINATOR';
break;
default:
throw new \Exception("Invalid type code, given: $type, expected: integer [1...8]");
}
}*/
$validTypes = array("SEQUENTIAL", "SELECT", "EVALUATE", "PARALLEL", "PARALLEL-BY-EVALUATION", "SEC-JOIN", "DISCRIMINATOR");
@@ -272,21 +274,16 @@ class Workflow extends Handler
throw new \Exception("Invalid Route type, given: $type, expected: [".implode(",", $validTypes)."]");
}
//if ($type != 0 && $type != 5 && $type != 8) {
if ($type != 'SEQUENTIAL' && $type != 'SEC-JOIN' && $type != 'DISCRIMINATOR') {
if ($this->getNumberOfRoutes($this->proUid, $fromTasUid, $toTasUid, $type) > 0) {
// die(); ????
throw new \RuntimeException("Unexpected behaviour");
throw new \LogicException("Unexpected behaviour");
}
//unset($aRow);
}
//if ($delete || $type == 0 || $type == 5 || $type == 8) {
if ($delete || $type == 'SEQUENTIAL' || $type == 'SEC-JOIN' || $type == 'DISCRIMINATOR') {
//$oTasks = new Tasks();
//$oTasks->deleteAllRoutesOfTask($this->proUid, $fromTasUid);
//$oTasks->deleteAllGatewayOfTask($this->proUid, $fromTasUid);
}
//if ($delete || $type == 'SEQUENTIAL' || $type == 'SEC-JOIN' || $type == 'DISCRIMINATOR') {
$oTasks = new Tasks();
$oTasks->deleteAllRoutesOfTask($this->proUid, $fromTasUid);
//}
$result = $this->saveNewPattern($this->proUid, $fromTasUid, $toTasUid, $type, $delete);
self::log("Add Route Success! -> ", $result);