Updating /project endpint, now is working GET /projects/{prj_uid} and /projects methods (only is loading diagram's activities)
This commit is contained in:
@@ -4,7 +4,10 @@ namespace ProcessMaker\Project\Adapter;
|
|||||||
use ProcessMaker\Project;
|
use ProcessMaker\Project;
|
||||||
use ProcessMaker\Util\Hash;
|
use ProcessMaker\Util\Hash;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class BpmnWorkflow
|
||||||
|
* @package ProcessMaker\Project\Adapter
|
||||||
|
*/
|
||||||
class BpmnWorkflow extends Project\Bpmn
|
class BpmnWorkflow extends Project\Bpmn
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -35,8 +35,12 @@ class WorkflowBpmn extends Project\Workflow
|
|||||||
$bpData["PRJ_AUTHOR"] = $data["USR_UID"];
|
$bpData["PRJ_AUTHOR"] = $data["USR_UID"];
|
||||||
}
|
}
|
||||||
|
|
||||||
$wp = new Project\Bpmn();
|
$bp = new Project\Bpmn();
|
||||||
$wp->create($bpData);
|
$bp->create($bpData);
|
||||||
|
|
||||||
|
// At this time we will add a default diagram and process
|
||||||
|
$bp->addDiagram();
|
||||||
|
$bp->addProcess();
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$prjUid = $this->getUid();
|
$prjUid = $this->getUid();
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ class Bpmn extends Handler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $retType == "array" ? $this->diagram->toArray() : $this->diagram;
|
return ($retType == "array" && is_object($this->diagram)) ? $this->diagram->toArray() : $this->diagram;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addProcess($data = array())
|
public function addProcess($data = array())
|
||||||
@@ -233,9 +233,13 @@ class Bpmn extends Handler
|
|||||||
return $activity;
|
return $activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getActivities()
|
public function getActivities($start = null, $limit = null, $filter = '', $changeCaseTo = CASE_UPPER)
|
||||||
{
|
{
|
||||||
return Activity::getAll($this->getUid());
|
if (is_array($start)) {
|
||||||
|
extract($start);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Activity::getAll($this->getUid(), $start, $limit, $filter, $changeCaseTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateActivity($actUid, $data)
|
public function updateActivity($actUid, $data)
|
||||||
@@ -285,9 +289,10 @@ class Bpmn extends Handler
|
|||||||
return $this->events[$evnUid];
|
return $this->events[$evnUid];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEvents($retType)
|
public function getEvents($retType = "array")
|
||||||
{
|
{
|
||||||
return Event::getAll($this->project->getPrjUid(), null, null, '', 'object');
|
//return Event::getAll($this->project->getPrjUid(), null, null, '', 'object');
|
||||||
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addGateway($data)
|
public function addGateway($data)
|
||||||
@@ -321,7 +326,8 @@ class Bpmn extends Handler
|
|||||||
|
|
||||||
public function getGateways($retType = 'array')
|
public function getGateways($retType = 'array')
|
||||||
{
|
{
|
||||||
return Activity::getAll($this->project->getPrjUid(), null, null, '', $retType);
|
//return Activity::getAll($this->project->getPrjUid(), null, null, '', $retType);
|
||||||
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addFlow($data)
|
public function addFlow($data)
|
||||||
@@ -354,7 +360,8 @@ class Bpmn extends Handler
|
|||||||
|
|
||||||
public function getFlows($retType = 'array')
|
public function getFlows($retType = 'array')
|
||||||
{
|
{
|
||||||
return Activity::getAll($this->project->getPrjUid(), null, null, '', $retType);
|
//return Activity::getAll($this->project->getPrjUid(), null, null, '', $retType);
|
||||||
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addArtifact($data)
|
public function addArtifact($data)
|
||||||
@@ -370,6 +377,7 @@ class Bpmn extends Handler
|
|||||||
public function getArtifacts()
|
public function getArtifacts()
|
||||||
{
|
{
|
||||||
// TODO: Implement update() method.
|
// TODO: Implement update() method.
|
||||||
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addLane($data)
|
public function addLane($data)
|
||||||
@@ -385,6 +393,7 @@ class Bpmn extends Handler
|
|||||||
public function getLanes()
|
public function getLanes()
|
||||||
{
|
{
|
||||||
// TODO: Implement update() method.
|
// TODO: Implement update() method.
|
||||||
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addLaneset($data)
|
public function addLaneset($data)
|
||||||
@@ -400,5 +409,107 @@ class Bpmn extends Handler
|
|||||||
public function getLanesets()
|
public function getLanesets()
|
||||||
{
|
{
|
||||||
// TODO: Implement update() method.
|
// TODO: Implement update() method.
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Others functions/methods
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static function getDiffFromProjects($updatedProject)
|
||||||
|
{
|
||||||
|
// preparing target project
|
||||||
|
$diagramElements = array(
|
||||||
|
'act_uid' => 'activities',
|
||||||
|
'evn_uid' => 'events',
|
||||||
|
'flo_uid' => 'flows',
|
||||||
|
'art_uid' => 'artifacts',
|
||||||
|
'lns_uid' => 'laneset',
|
||||||
|
'lan_uid' => 'lanes'
|
||||||
|
);
|
||||||
|
|
||||||
|
// Getting Differences
|
||||||
|
$newRecords = array();
|
||||||
|
$newRecordsUids = array();
|
||||||
|
$deletedRecords = array();
|
||||||
|
$updatedRecords = array();
|
||||||
|
|
||||||
|
// Get new records
|
||||||
|
foreach ($diagramElements as $key => $element) {
|
||||||
|
if (! array_key_exists($element, $updatedProject['diagrams'][0])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*print_r($savedProject['diagrams'][0][$element]);
|
||||||
|
print_r($updatedProject['diagrams'][0][$element]);
|
||||||
|
var_dump($key);*/
|
||||||
|
|
||||||
|
$arrayDiff = self::arrayDiff(
|
||||||
|
$savedProject['diagrams'][0][$element],
|
||||||
|
$updatedProject['diagrams'][0][$element],
|
||||||
|
$key
|
||||||
|
);
|
||||||
|
|
||||||
|
if (! empty($arrayDiff)) {
|
||||||
|
$newRecordsUids[$element] = $arrayDiff;
|
||||||
|
|
||||||
|
foreach ($updatedProject['diagrams'][0][$element] as $item) {
|
||||||
|
if (in_array($item[$key], $newRecordsUids[$element])) {
|
||||||
|
$newRecords[$element][] = $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get deleted records
|
||||||
|
foreach ($diagramElements as $key => $element) {
|
||||||
|
if (! array_key_exists($element, $updatedProject['diagrams'][0])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$arrayDiff = self::arrayDiff(
|
||||||
|
$updatedProject['diagrams'][0][$element],
|
||||||
|
$savedProject['diagrams'][0][$element],
|
||||||
|
$key
|
||||||
|
);
|
||||||
|
|
||||||
|
if (! empty($arrayDiff)) {
|
||||||
|
$deletedRecords[$element] = $arrayDiff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get updated records
|
||||||
|
$checksum = array();
|
||||||
|
foreach ($diagramElements as $key => $element) {
|
||||||
|
$checksum[$element] = self::getArrayChecksum($savedProject['diagrams'][0][$element], $key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($diagramElements as $key => $element) {
|
||||||
|
if (! array_key_exists($element, $updatedProject['diagrams'][0])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($updatedProject['diagrams'][0][$element] as $item) {
|
||||||
|
if ((array_key_exists($element, $newRecordsUids) && in_array($item[$key], $newRecordsUids[$element])) ||
|
||||||
|
(array_key_exists($element, $deletedRecords) && in_array($item[$key], $deletedRecords[$element]))
|
||||||
|
) {
|
||||||
|
// skip new or deleted records
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (self::getChecksum($item) !== $checksum[$element][$item[$key]]) {
|
||||||
|
$updatedRecords[$element][] = $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$diff = array(
|
||||||
|
'new' => $newRecords,
|
||||||
|
'deleted' => $deletedRecords,
|
||||||
|
'updated' => $updatedRecords
|
||||||
|
);
|
||||||
|
|
||||||
|
return $diff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,26 @@ abstract class Handler
|
|||||||
//public abstract function update();
|
//public abstract function update();
|
||||||
public abstract function remove();
|
public abstract function remove();
|
||||||
|
|
||||||
|
protected static function diffArrayByKey($key, $list, $targetList)
|
||||||
|
{
|
||||||
|
$uid = array();
|
||||||
|
$diff = array();
|
||||||
|
|
||||||
|
foreach ($list as $item) {
|
||||||
|
if (array_key_exists($key, $item)) {
|
||||||
|
$uid[] = $item[$key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($targetList as $item) {
|
||||||
|
if (! in_array($item[$key], $uid)) {
|
||||||
|
$diff[] = $item[$key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $diff;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log in ProcessMaker Standard Output if debug mode is enabled.
|
* Log in ProcessMaker Standard Output if debug mode is enabled.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -34,9 +34,24 @@ class Project extends Api
|
|||||||
public function get($prjUid)
|
public function get($prjUid)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$projects = new \StdClass(); //TODO
|
$bwp = \ProcessMaker\Project\Adapter\BpmnWorkflow::load($prjUid);
|
||||||
|
|
||||||
return $projects;
|
$project = array_change_key_case($bwp->getProject(), CASE_LOWER);
|
||||||
|
$diagram = $bwp->getDiagram();
|
||||||
|
|
||||||
|
if (! is_null($diagram)) {
|
||||||
|
$diagram = array_change_key_case($diagram, CASE_LOWER);
|
||||||
|
$diagram["activities"] = $bwp->getActivities(array("changeCaseTo" => CASE_LOWER));
|
||||||
|
$diagram["events"] = $bwp->getEvents();
|
||||||
|
$diagram["flows"] = $bwp->getFlows();
|
||||||
|
$diagram["artifacts"] = $bwp->getArtifacts();
|
||||||
|
$diagram["laneset"] = $bwp->getLanesets();
|
||||||
|
$diagram["lanes"] = $bwp->getLanes();
|
||||||
|
|
||||||
|
$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());
|
||||||
}
|
}
|
||||||
@@ -48,27 +63,28 @@ class Project extends Api
|
|||||||
public function post($request_data)
|
public function post($request_data)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$config = array();
|
// NEED REFACTOR
|
||||||
$config['project'] = array('replace_uids' => true);
|
// $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);
|
||||||
|
|
||||||
$bpmnModel = new BpmnModel();
|
// return $result;
|
||||||
$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.
|
||||||
@@ -81,7 +97,8 @@ class Project extends Api
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$result = BpmnModel::updateProject($prjUid, $request_data);
|
//$result = BpmnModel::updateProject($prjUid, $request_data);
|
||||||
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|||||||
@@ -69,5 +69,21 @@ class BpmnWorkflowTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($project["PRJ_NAME"], $process["PRO_TITLE"]);
|
$this->assertEquals($project["PRJ_NAME"], $process["PRO_TITLE"]);
|
||||||
$this->assertEquals($project["PRJ_DESCRIPTION"], $process["PRO_DESCRIPTION"]);
|
$this->assertEquals($project["PRJ_DESCRIPTION"], $process["PRO_DESCRIPTION"]);
|
||||||
$this->assertEquals($project["PRJ_AUTHOR"], $process["PRO_CREATE_USER"]);
|
$this->assertEquals($project["PRJ_AUTHOR"], $process["PRO_CREATE_USER"]);
|
||||||
|
|
||||||
|
$bwap->addDiagram();
|
||||||
|
$bwap->addProcess();
|
||||||
|
|
||||||
|
// Save to DB
|
||||||
|
$bwap->addActivity(array(
|
||||||
|
"ACT_NAME" => "Activity #1",
|
||||||
|
"BOU_X" => "50",
|
||||||
|
"BOU_Y" => "50"
|
||||||
|
));
|
||||||
|
|
||||||
|
$bwap->addActivity(array(
|
||||||
|
"ACT_NAME" => "Activity #2",
|
||||||
|
"BOU_X" => "250",
|
||||||
|
"BOU_Y" => "250"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user