BPMN Projects import is working now, first part, it is just importing project that doesn't exist in db.
This commit is contained in:
@@ -149,7 +149,7 @@ class Process extends BaseProcess
|
|||||||
* $aData['PRO_UID'] the process id
|
* $aData['PRO_UID'] the process id
|
||||||
* $aData['USR_UID'] the userid
|
* $aData['USR_UID'] the userid
|
||||||
* $aData['PRO_CATEGORY'] the id category
|
* $aData['PRO_CATEGORY'] the id category
|
||||||
* @return void
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function create ($aData, $generateUid = true)
|
public function create ($aData, $generateUid = true)
|
||||||
|
|||||||
@@ -29,7 +29,18 @@ $ext = pathinfo($_FILES["PROCESS_FILENAME"]["name"], PATHINFO_EXTENSION);
|
|||||||
if ($ext == "pmx") {
|
if ($ext == "pmx") {
|
||||||
$importer = new \ProcessMaker\Importer\XmlImporter();
|
$importer = new \ProcessMaker\Importer\XmlImporter();
|
||||||
$importer->setSourceFromGlobals("PROCESS_FILENAME");
|
$importer->setSourceFromGlobals("PROCESS_FILENAME");
|
||||||
$importer->import();
|
$data = array("usr_uid" => $_SESSION['USER_LOGGED']);
|
||||||
|
$res = $importer->import($data);
|
||||||
|
$result = array(
|
||||||
|
"success" => true,
|
||||||
|
"catchMessage" => "",
|
||||||
|
"ExistProcessInDatabase" => 0,
|
||||||
|
"ExistGroupsInDatabase" => 0,
|
||||||
|
"sNewProUid" => $res[0]["new_uid"],
|
||||||
|
"project_type" => "bpmn"
|
||||||
|
);
|
||||||
|
|
||||||
|
echo json_encode($result);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,10 +75,10 @@ abstract class Exporter
|
|||||||
$bpmnStruct["DATA"] = array();
|
$bpmnStruct["DATA"] = array();
|
||||||
$bpmnStruct["DIAGRAM"] = \BpmnDiagram::getAll($this->prjUid);
|
$bpmnStruct["DIAGRAM"] = \BpmnDiagram::getAll($this->prjUid);
|
||||||
$bpmnStruct["DOCUMENTATION"] = array();
|
$bpmnStruct["DOCUMENTATION"] = array();
|
||||||
$bpmnStruct["BPMN_EVENT"] = \BpmnEvent::getAll($this->prjUid);
|
$bpmnStruct["EVENT"] = \BpmnEvent::getAll($this->prjUid);
|
||||||
$bpmnStruct["EXTENSION"] = array();
|
$bpmnStruct["EXTENSION"] = array();
|
||||||
$bpmnStruct["FLOW"] = \BpmnFlow::getAll($this->prjUid, null, null, "", CASE_UPPER, false);
|
$bpmnStruct["FLOW"] = \BpmnFlow::getAll($this->prjUid, null, null, "", CASE_UPPER, false);
|
||||||
$bpmnStruct["BPMN_GATEWAY"] = \BpmnGateway::getAll($this->prjUid);
|
$bpmnStruct["GATEWAY"] = \BpmnGateway::getAll($this->prjUid);
|
||||||
$bpmnStruct["LANE"] = array();
|
$bpmnStruct["LANE"] = array();
|
||||||
$bpmnStruct["LANESET"] = array();
|
$bpmnStruct["LANESET"] = array();
|
||||||
$bpmnStruct["PARTICIPANT"] = array();
|
$bpmnStruct["PARTICIPANT"] = array();
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace ProcessMaker\Importer;
|
namespace ProcessMaker\Importer;
|
||||||
|
|
||||||
|
use ProcessMaker\Project\Adapter;
|
||||||
|
|
||||||
class XmlImporter extends Importer
|
class XmlImporter extends Importer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -63,7 +65,7 @@ class XmlImporter extends Importer
|
|||||||
$tablesNodeList = $definition->getElementsByTagName("table");
|
$tablesNodeList = $definition->getElementsByTagName("table");
|
||||||
|
|
||||||
foreach ($tablesNodeList as $tableNode) {
|
foreach ($tablesNodeList as $tableNode) {
|
||||||
$tableName = strtoupper($tableNode->getAttribute("name"));
|
$tableName = $tableNode->getAttribute("name"); //strtoupper($tableNode->getAttribute("name"));
|
||||||
$tables[$defClass][$tableName] = array();
|
$tables[$defClass][$tableName] = array();
|
||||||
/** @var \DOMElement[] $recordsNodeList */
|
/** @var \DOMElement[] $recordsNodeList */
|
||||||
$recordsNodeList = $tableNode->getElementsByTagName("record");
|
$recordsNodeList = $tableNode->getElementsByTagName("record");
|
||||||
@@ -77,7 +79,8 @@ class XmlImporter extends Importer
|
|||||||
|
|
||||||
foreach ($recordsNode->childNodes as $columnNode) {
|
foreach ($recordsNode->childNodes as $columnNode) {
|
||||||
if ($columnNode->nodeName == "#text") continue;
|
if ($columnNode->nodeName == "#text") continue;
|
||||||
$columns[strtoupper($columnNode->nodeName)] = self::getNodeText($columnNode);;
|
//$columns[strtoupper($columnNode->nodeName)] = self::getNodeText($columnNode);;
|
||||||
|
$columns[$columnNode->nodeName] = self::getNodeText($columnNode);;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tables[$defClass][$tableName][] = $columns;
|
$tables[$defClass][$tableName][] = $columns;
|
||||||
@@ -109,17 +112,31 @@ class XmlImporter extends Importer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print_r($tables);
|
//print_r($tables);
|
||||||
print_r($wfFiles);
|
//print_r($wfFiles);
|
||||||
|
return $tables;
|
||||||
|
|
||||||
// load workflow definition
|
|
||||||
// load workflow files
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function import()
|
public function import($data = array())
|
||||||
{
|
{
|
||||||
$this->load();
|
$tables = $this->load();
|
||||||
|
|
||||||
|
// Build BPMN project struct
|
||||||
|
$project = $tables["BPMN"]["PROJECT"][0];
|
||||||
|
$diagram = $tables["BPMN"]["DIAGRAM"][0];
|
||||||
|
$diagram["activities"] = $tables["BPMN"]["ACTIVITY"];
|
||||||
|
$diagram["artifacts"] = array();
|
||||||
|
$diagram["events"] = $tables["BPMN"]["EVENT"];
|
||||||
|
$diagram["flows"] = $tables["BPMN"]["FLOW"];
|
||||||
|
$diagram["gateways"] = $tables["BPMN"]["GATEWAY"];
|
||||||
|
$diagram["lanes"] = array();
|
||||||
|
$diagram["laneset"] = array();
|
||||||
|
$project["diagrams"] = array($diagram);
|
||||||
|
$project["prj_author"] = isset($data["usr_uid"])? $data["usr_uid"]: "00000000000000000000000000000001";
|
||||||
|
$project["process"] = $tables["BPMN"]["PROCESS"][0];
|
||||||
|
$result = Adapter\BpmnWorkflow::createFromStruct($project);
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function getNodeText($node)
|
private static function getNodeText($node)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
namespace ProcessMaker\Project\Adapter;
|
namespace ProcessMaker\Project\Adapter;
|
||||||
|
|
||||||
use ProcessMaker\Project;
|
use ProcessMaker\Project;
|
||||||
use ProcessMaker\Util\Common;
|
use ProcessMaker\Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BpmnWorkflow
|
* Class BpmnWorkflow
|
||||||
@@ -69,7 +69,9 @@ class BpmnWorkflow extends Project\Bpmn
|
|||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$prjUid = $this->getUid();
|
$prjUid = $this->getUid();
|
||||||
$this->remove();
|
//$this->remove();
|
||||||
|
$bpmnProject = Project\Bpmn::load($prjUid);
|
||||||
|
$bpmnProject->remove();
|
||||||
|
|
||||||
throw new \RuntimeException(sprintf(
|
throw new \RuntimeException(sprintf(
|
||||||
"Can't create Bpmn Project with prj_uid: %s, workflow creation fails." . PHP_EOL . $e->getMessage()
|
"Can't create Bpmn Project with prj_uid: %s, workflow creation fails." . PHP_EOL . $e->getMessage()
|
||||||
@@ -401,4 +403,308 @@ class BpmnWorkflow extends Project\Bpmn
|
|||||||
$this->wp->remove();
|
$this->wp->remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
public static function createFromStruct($projectData)
|
||||||
|
{
|
||||||
|
$bwp = new self;
|
||||||
|
$result = array();
|
||||||
|
|
||||||
|
// if (array_key_exists("prj_uid", $projectData)) {
|
||||||
|
// $result[0]["old_uid"] = $projectData["prj_uid"];
|
||||||
|
// } else {
|
||||||
|
// $result[0]["old_uid"] = "";
|
||||||
|
// }
|
||||||
|
|
||||||
|
//$projectData["prj_uid"] = Util\Common::generateUID();
|
||||||
|
$result[0]["new_uid"] = $projectData["prj_uid"];
|
||||||
|
$result[0]["old_uid"] = "";
|
||||||
|
$result[0]["object"] = "project";
|
||||||
|
|
||||||
|
$bwp->create(array(
|
||||||
|
"PRJ_UID" => $projectData["prj_uid"],
|
||||||
|
"PRJ_AUTHOR" => $projectData["prj_author"]
|
||||||
|
));
|
||||||
|
$bwp->addDiagram(array_change_key_case($projectData["diagrams"][0], CASE_UPPER));
|
||||||
|
$bwp->addProcess(array_change_key_case($projectData["process"], CASE_UPPER));
|
||||||
|
|
||||||
|
$result = array_merge($result, self::updateFromStruct($bwp->prjUid, $projectData));
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compose and return a Project struct
|
||||||
|
*
|
||||||
|
* Example struct return:
|
||||||
|
* array(
|
||||||
|
* "prj_uid" => "25111170353317e324d6e23073851309",
|
||||||
|
* "prj_name" => "example project",
|
||||||
|
* "prj_description" => "project desc.",
|
||||||
|
* ...
|
||||||
|
* "diagrams" => array(
|
||||||
|
* array(
|
||||||
|
* "dia_uid" => "94208559153317e325f1c24068030751",
|
||||||
|
* "dia_name" => "Example Diagram",
|
||||||
|
* ...
|
||||||
|
* "activities" => array(...),
|
||||||
|
* "events" => array(...),
|
||||||
|
* "gateways" => array(...),
|
||||||
|
* "flows" => array(...),
|
||||||
|
* "artifacts" => array(...),
|
||||||
|
* "laneset" => array(...),
|
||||||
|
* "lanes" => array(...)
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* @param $prjUid
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function getStruct($prjUid)
|
||||||
|
{
|
||||||
|
$bwp = BpmnWorkflow::load($prjUid);
|
||||||
|
|
||||||
|
$project = array_change_key_case($bwp->getProject(), CASE_LOWER);
|
||||||
|
$diagram = $bwp->getDiagram();
|
||||||
|
$process = $bwp->getProcess();
|
||||||
|
$diagram["pro_uid"] = $process["PRO_UID"];
|
||||||
|
|
||||||
|
$configList = array("changeCaseTo" => CASE_LOWER);
|
||||||
|
|
||||||
|
if (! is_null($diagram)) {
|
||||||
|
$diagram = array_change_key_case($diagram, CASE_LOWER);
|
||||||
|
$diagram["activities"] = $bwp->getActivities($configList);
|
||||||
|
$diagram["events"] = $bwp->getEvents($configList);
|
||||||
|
$diagram["gateways"] = $bwp->getGateways($configList);
|
||||||
|
$diagram["flows"] = $bwp->getFlows($configList);
|
||||||
|
$diagram["artifacts"] = $bwp->getArtifacts($configList);
|
||||||
|
$diagram["laneset"] = $bwp->getLanesets($configList);
|
||||||
|
$diagram["lanes"] = $bwp->getLanes($configList);
|
||||||
|
$project["diagrams"][] = $diagram;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $project;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update project from a struct defined.
|
||||||
|
*
|
||||||
|
* This function make add, update or delete of elements of a project
|
||||||
|
* Actions is based on a diff from project save in Db and the given structure as param, by the following criteria.
|
||||||
|
*
|
||||||
|
* 1. Elements that are on the struct, but they are not in the Db will be created on Db
|
||||||
|
* 2. Elements that are on the struct and they are found in db, will be compared, if they have been modified then will be updated on Db
|
||||||
|
* 3. Elements found in Db but they are not present on the struct will be considered deleted, so they will be deleted from Db.
|
||||||
|
*
|
||||||
|
* Example Struct:
|
||||||
|
* array(
|
||||||
|
* "prj_uid" => "25111170353317e324d6e23073851309",
|
||||||
|
* "prj_name" => "example project",
|
||||||
|
* "prj_description" => "project desc.",
|
||||||
|
* ...
|
||||||
|
* "diagrams" => array(
|
||||||
|
* array(
|
||||||
|
* "dia_uid" => "94208559153317e325f1c24068030751",
|
||||||
|
* "dia_name" => "Example Diagram",
|
||||||
|
* ...
|
||||||
|
* "activities" => array(...),
|
||||||
|
* "events" => array(...),
|
||||||
|
* "gateways" => array(...),
|
||||||
|
* "flows" => array(...),
|
||||||
|
* "artifacts" => array(...),
|
||||||
|
* "laneset" => array(...),
|
||||||
|
* "lanes" => array(...)
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
* )
|
||||||
|
*
|
||||||
|
* Notes:
|
||||||
|
* 1. All elements keys are in lowercase
|
||||||
|
* 2. the "diagrams" element is an array of arrays
|
||||||
|
*
|
||||||
|
* @param $prjUid
|
||||||
|
* @param $projectData
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function updateFromStruct($prjUid, $projectData)
|
||||||
|
{
|
||||||
|
$diagram = isset($projectData["diagrams"]) && isset($projectData["diagrams"][0]) ? $projectData["diagrams"][0] : array();
|
||||||
|
$result = array();
|
||||||
|
$bwp = BpmnWorkflow::load($prjUid);
|
||||||
|
//var_dump($bwp->getUid()); die;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Diagram's Activities Handling
|
||||||
|
*/
|
||||||
|
$whiteList = array();
|
||||||
|
foreach ($diagram["activities"] as $i => $activityData) {
|
||||||
|
$activityData = array_change_key_case($activityData, CASE_UPPER);
|
||||||
|
unset($activityData["_EXTENDED"], $activityData["BOU_ELEMENT_ID"]);
|
||||||
|
$activityData = Util\ArrayUtil::boolToIntValues($activityData);
|
||||||
|
|
||||||
|
$activity = $bwp->getActivity($activityData["ACT_UID"]);
|
||||||
|
if (is_null($activity)) {
|
||||||
|
$oldActUid = $activityData["ACT_UID"];
|
||||||
|
$activityData["ACT_UID"] = Util\Common::generateUID();
|
||||||
|
$bwp->addActivity($activityData);
|
||||||
|
$result[] = array("object" => "activity", "new_uid" => $activityData["ACT_UID"], "old_uid" => $oldActUid);
|
||||||
|
} elseif (! $bwp->isEquals($activity, $activityData)) {
|
||||||
|
$bwp->updateActivity($activityData["ACT_UID"], $activityData);
|
||||||
|
} else {
|
||||||
|
Util\Logger::log("Update Activity ({$activityData["ACT_UID"]}) Skipped - No changes required");
|
||||||
|
}
|
||||||
|
|
||||||
|
$diagram["activities"][$i] = $activityData;
|
||||||
|
$whiteList[] = $activityData["ACT_UID"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$activities = $bwp->getActivities();
|
||||||
|
|
||||||
|
// looking for removed elements
|
||||||
|
foreach ($activities as $activityData) {
|
||||||
|
if (! in_array($activityData["ACT_UID"], $whiteList)) {
|
||||||
|
$bwp->removeActivity($activityData["ACT_UID"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Diagram's Gateways Handling
|
||||||
|
*/
|
||||||
|
$whiteList = array();
|
||||||
|
//print_r($diagram);
|
||||||
|
foreach ($diagram["gateways"] as $i => $gatewayData) {
|
||||||
|
$gatewayData = array_change_key_case($gatewayData, CASE_UPPER);
|
||||||
|
unset($gatewayData["_EXTENDED"]);
|
||||||
|
|
||||||
|
$gateway = $bwp->getGateway($gatewayData["GAT_UID"]);
|
||||||
|
if (is_null($gateway)) {
|
||||||
|
$oldActUid = $gatewayData["GAT_UID"];
|
||||||
|
$gatewayData["GAT_UID"] = Util\Common::generateUID();
|
||||||
|
$bwp->addGateway($gatewayData);
|
||||||
|
$result[] = array("object" => "gateway", "new_uid" => $gatewayData["GAT_UID"], "old_uid" => $oldActUid);
|
||||||
|
} elseif (! $bwp->isEquals($gateway, $gatewayData)) {
|
||||||
|
$bwp->updateGateway($gatewayData["GAT_UID"], $gatewayData);
|
||||||
|
} else {
|
||||||
|
Util\Logger::log("Update Gateway ({$gatewayData["GAT_UID"]}) Skipped - No changes required");
|
||||||
|
}
|
||||||
|
|
||||||
|
$diagram["gateways"][$i] = $gatewayData;
|
||||||
|
$whiteList[] = $gatewayData["GAT_UID"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$gateways = $bwp->getGateways();
|
||||||
|
|
||||||
|
// looking for removed elements
|
||||||
|
foreach ($gateways as $gatewayData) {
|
||||||
|
if (! in_array($gatewayData["GAT_UID"], $whiteList)) {
|
||||||
|
$bwp->removeGateway($gatewayData["GAT_UID"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Diagram's Events Handling
|
||||||
|
*/
|
||||||
|
$whiteList = array();
|
||||||
|
foreach ($diagram["events"] as $i => $eventData) {
|
||||||
|
$eventData = array_change_key_case($eventData, CASE_UPPER);
|
||||||
|
unset($eventData["_EXTENDED"]);
|
||||||
|
if (array_key_exists("EVN_CANCEL_ACTIVITY", $eventData)) {
|
||||||
|
$eventData["EVN_CANCEL_ACTIVITY"] = $eventData["EVN_CANCEL_ACTIVITY"] ? 1 : 0;
|
||||||
|
}
|
||||||
|
if (array_key_exists("EVN_WAIT_FOR_COMPLETION", $eventData)) {
|
||||||
|
$eventData["EVN_WAIT_FOR_COMPLETION"] = $eventData["EVN_WAIT_FOR_COMPLETION"] ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$event = $bwp->getEvent($eventData["EVN_UID"]);
|
||||||
|
if (is_null($event)) {
|
||||||
|
$oldActUid = $eventData["EVN_UID"];
|
||||||
|
$eventData["EVN_UID"] = Util\Common::generateUID();
|
||||||
|
$bwp->addEvent($eventData);
|
||||||
|
$result[] = array("object" => "event", "new_uid" => $eventData["EVN_UID"], "old_uid" => $oldActUid);
|
||||||
|
} elseif (! $bwp->isEquals($event, $eventData)) {
|
||||||
|
$bwp->updateEvent($eventData["EVN_UID"], $eventData);
|
||||||
|
} else {
|
||||||
|
Util\Logger::log("Update Event ({$eventData["EVN_UID"]}) Skipped - No changes required");
|
||||||
|
}
|
||||||
|
|
||||||
|
$diagram["events"][$i] = $eventData;
|
||||||
|
$whiteList[] = $eventData["EVN_UID"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$events = $bwp->getEvents();
|
||||||
|
|
||||||
|
// looking for removed elements
|
||||||
|
foreach ($events as $eventData) {
|
||||||
|
if (! in_array($eventData["EVN_UID"], $whiteList)) {
|
||||||
|
// If it is not in the white list so, then remove them
|
||||||
|
$bwp->removeEvent($eventData["EVN_UID"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Diagram's Flows Handling
|
||||||
|
*/
|
||||||
|
$whiteList = array();
|
||||||
|
|
||||||
|
foreach ($diagram["flows"] as $i => $flowData) {
|
||||||
|
$flowData = array_change_key_case($flowData, CASE_UPPER);
|
||||||
|
|
||||||
|
// if it is a new flow record
|
||||||
|
if (! \BpmnFlow::exists($flowData["FLO_UID"])) {
|
||||||
|
$oldFloUid = $flowData["FLO_UID"];
|
||||||
|
$flowData["FLO_UID"] = Util\Common::generateUID();
|
||||||
|
|
||||||
|
$mappedUid = self::mapUid($flowData["FLO_ELEMENT_ORIGIN"], $result);
|
||||||
|
if ($mappedUid !== false) {
|
||||||
|
$flowData["FLO_ELEMENT_ORIGIN"] = $mappedUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mappedUid = self::mapUid($flowData["FLO_ELEMENT_DEST"], $result);
|
||||||
|
if ($mappedUid !== false) {
|
||||||
|
$flowData["FLO_ELEMENT_DEST"] = $mappedUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
$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) {
|
||||||
|
$flow = $bwp->getFlow($flowData["FLO_UID"]);
|
||||||
|
if (is_null($flow)) {
|
||||||
|
$bwp->addFlow($flowData, $diagram["flows"]);
|
||||||
|
} elseif (! $bwp->isEquals($flow, $flowData)) {
|
||||||
|
$bwp->updateFlow($flowData["FLO_UID"], $flowData, $diagram["flows"]);
|
||||||
|
} else {
|
||||||
|
Util\Logger::log("Update Flow ({$flowData["FLO_UID"]}) Skipped - No changes required");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$flows = $bwp->getFlows();
|
||||||
|
|
||||||
|
// looking for removed elements
|
||||||
|
foreach ($flows as $flowData) {
|
||||||
|
if (! in_array($flowData["FLO_UID"], $whiteList)) {
|
||||||
|
$bwp->removeFlow($flowData["FLO_UID"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$bwp->mapBpmnFlowsToWorkflowRoutes();
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function mapUid($oldUid, $list)
|
||||||
|
{
|
||||||
|
foreach ($list as $item) {
|
||||||
|
if ($item["old_uid"] == $oldUid) {
|
||||||
|
return $item["new_uid"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -175,6 +175,11 @@ class Bpmn extends Handler
|
|||||||
return $this->prjUid;
|
return $this->prjUid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $retType
|
||||||
|
* @return array|Project
|
||||||
|
* @throws \RuntimeException
|
||||||
|
*/
|
||||||
public function getProject($retType = "array")
|
public function getProject($retType = "array")
|
||||||
{
|
{
|
||||||
if (empty($this->project)) {
|
if (empty($this->project)) {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ namespace Services\Api\ProcessMaker;
|
|||||||
|
|
||||||
use Luracast\Restler\RestException;
|
use Luracast\Restler\RestException;
|
||||||
use ProcessMaker\Services\Api;
|
use ProcessMaker\Services\Api;
|
||||||
use ProcessMaker\Adapter\Bpmn\Model as BpmnModel;
|
|
||||||
use \ProcessMaker\Project\Adapter;
|
use \ProcessMaker\Project\Adapter;
|
||||||
use \ProcessMaker\Util;
|
use \ProcessMaker\Util;
|
||||||
|
|
||||||
@@ -35,29 +34,7 @@ class Project extends Api
|
|||||||
public function get($prjUid)
|
public function get($prjUid)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$bwp = Adapter\BpmnWorkflow::load($prjUid);
|
return Adapter\BpmnWorkflow::getStruct($prjUid);
|
||||||
|
|
||||||
$project = array_change_key_case($bwp->getProject(), CASE_LOWER);
|
|
||||||
$diagram = $bwp->getDiagram();
|
|
||||||
$process = $bwp->getProcess();
|
|
||||||
$diagram["pro_uid"] = $process["PRO_UID"];
|
|
||||||
|
|
||||||
$configList = array("changeCaseTo" => CASE_LOWER);
|
|
||||||
|
|
||||||
if (! is_null($diagram)) {
|
|
||||||
$diagram = array_change_key_case($diagram, CASE_LOWER);
|
|
||||||
$diagram["activities"] = $bwp->getActivities($configList);
|
|
||||||
$diagram["events"] = $bwp->getEvents($configList);
|
|
||||||
$diagram["gateways"] = $bwp->getGateways($configList);
|
|
||||||
$diagram["flows"] = $bwp->getFlows($configList);
|
|
||||||
$diagram["artifacts"] = $bwp->getArtifacts($configList);
|
|
||||||
$diagram["laneset"] = $bwp->getLanesets($configList);
|
|
||||||
$diagram["lanes"] = $bwp->getLanes($configList);
|
|
||||||
|
|
||||||
$project["diagrams"][] = $diagram;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $project;
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -69,28 +46,7 @@ class Project extends Api
|
|||||||
public function post($request_data)
|
public function post($request_data)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// NEED REFACTOR
|
//TODO
|
||||||
// $config = array();
|
|
||||||
// $config['project'] = array('replace_uids' => true);
|
|
||||||
//
|
|
||||||
// $bpmnModel = new BpmnModel();
|
|
||||||
// $result = $bpmnModel->createProject($request_data, $config['project']['replace_uids']);
|
|
||||||
//
|
|
||||||
// if (array_key_exists('prj_uid', $result)) {
|
|
||||||
// $prjUid = $result['prj_uid'];
|
|
||||||
// } else {
|
|
||||||
// $prjUid = $result[0]['new_uid'];
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// $wfProcess = Workflow::loadFromBpmnProject($prjUid);
|
|
||||||
//
|
|
||||||
// $process = new \BusinessModel\Process();
|
|
||||||
// $userUid = $this->getUserId();
|
|
||||||
// $data = array('process' => $wfProcess);
|
|
||||||
//
|
|
||||||
// $process->createProcess($userUid, $data);
|
|
||||||
|
|
||||||
// return $result;
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// TODO in case that $process->createProcess($userUid, $data); fails maybe the BPMN project was created successfully
|
// TODO in case that $process->createProcess($userUid, $data); fails maybe the BPMN project was created successfully
|
||||||
// so, we need remove it or change the creation order.
|
// so, we need remove it or change the creation order.
|
||||||
@@ -102,173 +58,7 @@ class Project extends Api
|
|||||||
public function put($prjUid, $request_data)
|
public function put($prjUid, $request_data)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$projectData = $request_data;
|
return Adapter\BpmnWorkflow::updateFromStruct($prjUid, $request_data);
|
||||||
$diagram = isset($projectData["diagrams"]) && isset($projectData["diagrams"][0]) ? $projectData["diagrams"][0] : array();
|
|
||||||
$result = array();
|
|
||||||
$bwp = Adapter\BpmnWorkflow::load($prjUid);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Diagram's Activities Handling
|
|
||||||
*/
|
|
||||||
$whiteList = array();
|
|
||||||
foreach ($diagram["activities"] as $i => $activityData) {
|
|
||||||
$activityData = array_change_key_case($activityData, CASE_UPPER);
|
|
||||||
unset($activityData["_EXTENDED"], $activityData["BOU_ELEMENT_ID"]);
|
|
||||||
$activityData = Util\ArrayUtil::boolToIntValues($activityData);
|
|
||||||
|
|
||||||
$activity = $bwp->getActivity($activityData["ACT_UID"]);
|
|
||||||
if (is_null($activity)) {
|
|
||||||
$oldActUid = $activityData["ACT_UID"];
|
|
||||||
$activityData["ACT_UID"] = Util\Common::generateUID();
|
|
||||||
$bwp->addActivity($activityData);
|
|
||||||
$result[] = array("object" => "activity", "new_uid" => $activityData["ACT_UID"], "old_uid" => $oldActUid);
|
|
||||||
} elseif (! $bwp->isEquals($activity, $activityData)) {
|
|
||||||
$bwp->updateActivity($activityData["ACT_UID"], $activityData);
|
|
||||||
} else {
|
|
||||||
Util\Logger::log("Update Activity ({$activityData["ACT_UID"]}) Skipped - No changes required");
|
|
||||||
}
|
|
||||||
|
|
||||||
$diagram["activities"][$i] = $activityData;
|
|
||||||
$whiteList[] = $activityData["ACT_UID"];
|
|
||||||
}
|
|
||||||
|
|
||||||
$activities = $bwp->getActivities();
|
|
||||||
|
|
||||||
// looking for removed elements
|
|
||||||
foreach ($activities as $activityData) {
|
|
||||||
if (! in_array($activityData["ACT_UID"], $whiteList)) {
|
|
||||||
$bwp->removeActivity($activityData["ACT_UID"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Diagram's Gateways Handling
|
|
||||||
*/
|
|
||||||
$whiteList = array();
|
|
||||||
foreach ($diagram["gateways"] as $i => $gatewayData) {
|
|
||||||
$gatewayData = array_change_key_case($gatewayData, CASE_UPPER);
|
|
||||||
unset($gatewayData["_EXTENDED"]);
|
|
||||||
|
|
||||||
$gateway = $bwp->getGateway($gatewayData["GAT_UID"]);
|
|
||||||
if (is_null($gateway)) {
|
|
||||||
$oldActUid = $gatewayData["GAT_UID"];
|
|
||||||
$gatewayData["GAT_UID"] = Util\Common::generateUID();
|
|
||||||
$bwp->addGateway($gatewayData);
|
|
||||||
$result[] = array("object" => "gateway", "new_uid" => $gatewayData["GAT_UID"], "old_uid" => $oldActUid);
|
|
||||||
} elseif (! $bwp->isEquals($gateway, $gatewayData)) {
|
|
||||||
$bwp->updateGateway($gatewayData["GAT_UID"], $gatewayData);
|
|
||||||
} else {
|
|
||||||
Util\Logger::log("Update Gateway ({$gatewayData["GAT_UID"]}) Skipped - No changes required");
|
|
||||||
}
|
|
||||||
|
|
||||||
$diagram["gateways"][$i] = $gatewayData;
|
|
||||||
$whiteList[] = $gatewayData["GAT_UID"];
|
|
||||||
}
|
|
||||||
|
|
||||||
$gateways = $bwp->getGateways();
|
|
||||||
|
|
||||||
// looking for removed elements
|
|
||||||
foreach ($gateways as $gatewayData) {
|
|
||||||
if (! in_array($gatewayData["GAT_UID"], $whiteList)) {
|
|
||||||
$bwp->removeGateway($gatewayData["GAT_UID"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Diagram's Events Handling
|
|
||||||
*/
|
|
||||||
$whiteList = array();
|
|
||||||
foreach ($diagram["events"] as $i => $eventData) {
|
|
||||||
$eventData = array_change_key_case($eventData, CASE_UPPER);
|
|
||||||
unset($eventData["_EXTENDED"]);
|
|
||||||
if (array_key_exists("EVN_CANCEL_ACTIVITY", $eventData)) {
|
|
||||||
$eventData["EVN_CANCEL_ACTIVITY"] = $eventData["EVN_CANCEL_ACTIVITY"] ? 1 : 0;
|
|
||||||
}
|
|
||||||
if (array_key_exists("EVN_WAIT_FOR_COMPLETION", $eventData)) {
|
|
||||||
$eventData["EVN_WAIT_FOR_COMPLETION"] = $eventData["EVN_WAIT_FOR_COMPLETION"] ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$event = $bwp->getEvent($eventData["EVN_UID"]);
|
|
||||||
if (is_null($event)) {
|
|
||||||
$oldActUid = $eventData["EVN_UID"];
|
|
||||||
$eventData["EVN_UID"] = Util\Common::generateUID();
|
|
||||||
$bwp->addEvent($eventData);
|
|
||||||
$result[] = array("object" => "event", "new_uid" => $eventData["EVN_UID"], "old_uid" => $oldActUid);
|
|
||||||
} elseif (! $bwp->isEquals($event, $eventData)) {
|
|
||||||
$bwp->updateEvent($eventData["EVN_UID"], $eventData);
|
|
||||||
} else {
|
|
||||||
Util\Logger::log("Update Event ({$eventData["EVN_UID"]}) Skipped - No changes required");
|
|
||||||
}
|
|
||||||
|
|
||||||
$diagram["events"][$i] = $eventData;
|
|
||||||
$whiteList[] = $eventData["EVN_UID"];
|
|
||||||
}
|
|
||||||
|
|
||||||
$events = $bwp->getEvents();
|
|
||||||
|
|
||||||
// looking for removed elements
|
|
||||||
foreach ($events as $eventData) {
|
|
||||||
if (! in_array($eventData["EVN_UID"], $whiteList)) {
|
|
||||||
// If it is not in the white list so, then remove them
|
|
||||||
$bwp->removeEvent($eventData["EVN_UID"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Diagram's Flows Handling
|
|
||||||
*/
|
|
||||||
$whiteList = array();
|
|
||||||
|
|
||||||
foreach ($diagram["flows"] as $i => $flowData) {
|
|
||||||
$flowData = array_change_key_case($flowData, CASE_UPPER);
|
|
||||||
|
|
||||||
// if it is a new flow record
|
|
||||||
if (! \BpmnFlow::exists($flowData["FLO_UID"])) {
|
|
||||||
$oldFloUid = $flowData["FLO_UID"];
|
|
||||||
$flowData["FLO_UID"] = Util\Common::generateUID();
|
|
||||||
|
|
||||||
$mappedUid = self::mapUid($flowData["FLO_ELEMENT_ORIGIN"], $result);
|
|
||||||
if ($mappedUid !== false) {
|
|
||||||
$flowData["FLO_ELEMENT_ORIGIN"] = $mappedUid;
|
|
||||||
}
|
|
||||||
|
|
||||||
$mappedUid = self::mapUid($flowData["FLO_ELEMENT_DEST"], $result);
|
|
||||||
if ($mappedUid !== false) {
|
|
||||||
$flowData["FLO_ELEMENT_DEST"] = $mappedUid;
|
|
||||||
}
|
|
||||||
|
|
||||||
$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) {
|
|
||||||
$flow = $bwp->getFlow($flowData["FLO_UID"]);
|
|
||||||
if (is_null($flow)) {
|
|
||||||
$bwp->addFlow($flowData, $diagram["flows"]);
|
|
||||||
} elseif (! $bwp->isEquals($flow, $flowData)) {
|
|
||||||
$bwp->updateFlow($flowData["FLO_UID"], $flowData, $diagram["flows"]);
|
|
||||||
} else {
|
|
||||||
Util\Logger::log("Update Flow ({$flowData["FLO_UID"]}) Skipped - No changes required");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$flows = $bwp->getFlows();
|
|
||||||
|
|
||||||
// looking for removed elements
|
|
||||||
foreach ($flows as $flowData) {
|
|
||||||
if (! in_array($flowData["FLO_UID"], $whiteList)) {
|
|
||||||
$bwp->removeFlow($flowData["FLO_UID"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$bwp->mapBpmnFlowsToWorkflowRoutes();
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -277,10 +67,7 @@ class Project extends Api
|
|||||||
public function delete($prjUid)
|
public function delete($prjUid)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$process = new \BusinessModel\Process();
|
// TODO
|
||||||
$process->deleteProcess($prjUid);
|
|
||||||
|
|
||||||
BpmnModel::deleteProject($prjUid);
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -385,17 +172,6 @@ class Project extends Api
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function mapUid($oldUid, $list)
|
|
||||||
{
|
|
||||||
foreach ($list as $item) {
|
|
||||||
if ($item["old_uid"] == $oldUid) {
|
|
||||||
return $item["new_uid"];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @url GET /:prj_uid/variables
|
* @url GET /:prj_uid/variables
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1086,7 +1086,11 @@ importProcess = function()
|
|||||||
if (resp_.ExistProcessInDatabase == "0") {
|
if (resp_.ExistProcessInDatabase == "0") {
|
||||||
if (resp_.ExistGroupsInDatabase == "0") {
|
if (resp_.ExistGroupsInDatabase == "0") {
|
||||||
var sNewProUid = resp_.sNewProUid;
|
var sNewProUid = resp_.sNewProUid;
|
||||||
window.location.href = "processes_Map?PRO_UID=" + sNewProUid;
|
if (resp_.project_type && resp_.project_type == "bpmn") {
|
||||||
|
window.location.href = "../designer?prj_uid=" + sNewProUid;
|
||||||
|
} else {
|
||||||
|
window.location.href = "processes_Map?PRO_UID=" + sNewProUid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
importProcessGlobal.sNewProUid = resp_.sNewProUid;
|
importProcessGlobal.sNewProUid = resp_.sNewProUid;
|
||||||
|
|||||||
Reference in New Issue
Block a user