2013-12-05 20:41:21 -04:00
|
|
|
<?php
|
|
|
|
|
namespace Services\Api\ProcessMaker;
|
|
|
|
|
|
|
|
|
|
use Luracast\Restler\RestException;
|
|
|
|
|
use ProcessMaker\Services\Api;
|
|
|
|
|
use ProcessMaker\Adapter\Bpmn\Model as BpmnModel;
|
2014-02-06 11:29:45 -04:00
|
|
|
use ProcessMaker\Util\Hash;
|
2014-02-07 08:41:11 -04:00
|
|
|
use ProcessMaker\Util\Logger;
|
2013-12-05 20:41:21 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class Project
|
|
|
|
|
*
|
|
|
|
|
* @package Services\Api\ProcessMaker
|
|
|
|
|
* @author Erik Amaru Ortiz <aortiz.erik@gmail.com, erik@colosa.com>
|
|
|
|
|
*
|
|
|
|
|
* @protected
|
|
|
|
|
*/
|
|
|
|
|
class Project extends Api
|
|
|
|
|
{
|
2014-01-25 06:10:24 -04:00
|
|
|
public function index()
|
2013-12-05 23:01:02 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-02-05 12:33:36 -04:00
|
|
|
$start = null;
|
|
|
|
|
$limit = null;
|
|
|
|
|
$filter = "";
|
2013-12-05 23:01:02 -04:00
|
|
|
|
2014-02-05 14:09:48 -04:00
|
|
|
$projects = \ProcessMaker\Project\Adapter\BpmnWorkflow::getList($start, $limit, $filter, CASE_LOWER);
|
|
|
|
|
|
|
|
|
|
return $projects;
|
|
|
|
|
|
2013-12-05 23:01:02 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-05 20:41:21 -04:00
|
|
|
|
2014-01-28 17:01:26 -04:00
|
|
|
public function get($prjUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2014-02-06 21:26:06 -04:00
|
|
|
//return \ProcessMaker\Adapter\Bpmn\Model::loadProject($prjUid);
|
|
|
|
|
|
2014-02-06 11:00:15 -04:00
|
|
|
$bwp = \ProcessMaker\Project\Adapter\BpmnWorkflow::load($prjUid);
|
2014-01-28 17:01:26 -04:00
|
|
|
|
2014-02-06 11:00:15 -04:00
|
|
|
$project = array_change_key_case($bwp->getProject(), CASE_LOWER);
|
|
|
|
|
$diagram = $bwp->getDiagram();
|
2014-02-06 21:26:06 -04:00
|
|
|
$process = $bwp->getProcess();
|
|
|
|
|
$diagram["pro_uid"] = $process["PRO_UID"];
|
2014-02-06 11:00:15 -04:00
|
|
|
|
|
|
|
|
if (! is_null($diagram)) {
|
|
|
|
|
$diagram = array_change_key_case($diagram, CASE_LOWER);
|
|
|
|
|
$diagram["activities"] = $bwp->getActivities(array("changeCaseTo" => CASE_LOWER));
|
|
|
|
|
$diagram["events"] = $bwp->getEvents();
|
2014-02-07 15:42:24 -04:00
|
|
|
$diagram["gateways"] = $bwp->getGateways(array("changeCaseTo" => CASE_LOWER));
|
|
|
|
|
$diagram["flows"] = $bwp->getFlows(array("changeCaseTo" => CASE_LOWER));
|
2014-02-06 11:00:15 -04:00
|
|
|
$diagram["artifacts"] = $bwp->getArtifacts();
|
|
|
|
|
$diagram["laneset"] = $bwp->getLanesets();
|
|
|
|
|
$diagram["lanes"] = $bwp->getLanes();
|
|
|
|
|
|
|
|
|
|
$project["diagrams"][] = $diagram;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $project;
|
2014-01-28 17:01:26 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-17 11:24:37 -04:00
|
|
|
/**
|
|
|
|
|
* @status 201
|
|
|
|
|
*/
|
2014-01-25 06:10:24 -04:00
|
|
|
public function post($request_data)
|
2013-12-05 20:41:21 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-02-06 11:00:15 -04:00
|
|
|
// NEED REFACTOR
|
|
|
|
|
// $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;
|
2013-12-05 20:41:21 -04:00
|
|
|
} catch (\Exception $e) {
|
2014-01-23 21:29:03 -04:00
|
|
|
// 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.
|
|
|
|
|
|
2013-12-05 20:41:21 -04:00
|
|
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-25 06:10:24 -04:00
|
|
|
public function put($prjUid, $request_data)
|
2013-12-23 17:17:01 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-02-06 11:29:45 -04:00
|
|
|
$projectData = $request_data;
|
|
|
|
|
$prjUid = $projectData["prj_uid"];
|
|
|
|
|
$diagram = isset($request_data["diagrams"]) && isset($request_data["diagrams"][0]) ? $request_data["diagrams"][0] : array();
|
|
|
|
|
|
|
|
|
|
$bwp = \ProcessMaker\Project\Adapter\BpmnWorkflow::load($prjUid);
|
|
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
|
|
2014-02-06 20:30:27 -04:00
|
|
|
/*
|
|
|
|
|
* Diagram's Activities Handling
|
|
|
|
|
*/
|
2014-02-06 12:10:35 -04:00
|
|
|
$whiteList = array();
|
2014-02-07 08:41:11 -04:00
|
|
|
foreach ($diagram["activities"] as $i => $activityData) {
|
2014-02-10 11:29:28 -04:00
|
|
|
$activityData = array_change_key_case($activityData, CASE_UPPER);
|
2014-02-06 11:29:45 -04:00
|
|
|
|
|
|
|
|
// activity exists ?
|
|
|
|
|
if ($activity = $bwp->getActivity($activityData["ACT_UID"])) {
|
|
|
|
|
// then update activity
|
|
|
|
|
$bwp->updateActivity($activityData["ACT_UID"], $activityData);
|
|
|
|
|
} else {
|
|
|
|
|
// if not exists then create it
|
|
|
|
|
$oldActUid = $activityData["ACT_UID"];
|
2014-02-07 08:41:11 -04:00
|
|
|
$activityData["ACT_UID"] = Hash::generateUID();
|
|
|
|
|
|
2014-02-06 11:29:45 -04:00
|
|
|
$bwp->addActivity($activityData);
|
|
|
|
|
|
2014-02-07 08:41:11 -04:00
|
|
|
$result[] = array("object" => "activity", "new_uid" => $activityData["ACT_UID"], "old_uid" => $oldActUid);
|
2014-02-10 11:29:28 -04:00
|
|
|
$diagram["activities"][$i] = $activityData;
|
2014-02-06 11:29:45 -04:00
|
|
|
}
|
2014-02-10 11:29:28 -04:00
|
|
|
|
|
|
|
|
$whiteList[] = $activityData["ACT_UID"];
|
2014-02-06 11:29:45 -04:00
|
|
|
}
|
2014-01-17 13:37:15 -04:00
|
|
|
|
2014-02-06 12:10:35 -04:00
|
|
|
$activities = $bwp->getActivities();
|
2014-02-06 11:00:15 -04:00
|
|
|
|
2014-02-06 12:10:35 -04:00
|
|
|
// looking for removed elements
|
|
|
|
|
foreach ($activities as $activityData) {
|
|
|
|
|
if (! in_array($activityData["ACT_UID"], $whiteList)) {
|
|
|
|
|
// If it is not in the white list so, then remove them
|
|
|
|
|
$bwp->removeActivity($activityData["ACT_UID"]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-23 17:17:01 -04:00
|
|
|
|
2014-02-10 11:29:28 -04:00
|
|
|
|
2014-02-07 08:41:11 -04:00
|
|
|
/*
|
|
|
|
|
* Diagram's Gateways Handling
|
|
|
|
|
*/
|
|
|
|
|
$whiteList = array();
|
|
|
|
|
foreach ($diagram["gateways"] as $i => $gatewayData) {
|
2014-02-10 11:29:28 -04:00
|
|
|
$gatewayData = array_change_key_case($gatewayData, CASE_UPPER);
|
2014-02-07 08:41:11 -04:00
|
|
|
|
|
|
|
|
// gateway exists ?
|
|
|
|
|
if ($gateway = $bwp->getGateway($gatewayData["GAT_UID"])) {
|
|
|
|
|
// then update activity
|
|
|
|
|
$bwp->updateGateway($gatewayData["GAT_UID"], $gatewayData);
|
|
|
|
|
} else {
|
|
|
|
|
// if not exists then create it
|
|
|
|
|
$oldActUid = $gatewayData["GAT_UID"];
|
|
|
|
|
$gatewayData["GAT_UID"] = Hash::generateUID();
|
|
|
|
|
|
|
|
|
|
$bwp->addGateway($gatewayData);
|
|
|
|
|
|
|
|
|
|
$result[] = array("object" => "gateway", "new_uid" => $gatewayData["GAT_UID"], "old_uid" => $oldActUid);
|
2014-02-10 11:29:28 -04:00
|
|
|
$diagram["gateways"][$i] = $gatewayData;
|
2014-02-07 08:41:11 -04:00
|
|
|
}
|
2014-02-10 11:29:28 -04:00
|
|
|
|
|
|
|
|
$whiteList[] = $gatewayData["GAT_UID"];
|
2014-02-07 08:41:11 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-07 15:42:24 -04:00
|
|
|
$gateways = $bwp->getGateways();
|
2014-02-07 08:41:11 -04:00
|
|
|
|
|
|
|
|
// looking for removed elements
|
2014-02-07 15:42:24 -04:00
|
|
|
foreach ($gateways as $gatewayData) {
|
|
|
|
|
if (! in_array($gatewayData["GAT_UID"], $whiteList)) {
|
2014-02-07 08:41:11 -04:00
|
|
|
// If it is not in the white list so, then remove them
|
2014-02-07 15:42:24 -04:00
|
|
|
$bwp->removeGateway($gatewayData["GAT_UID"]);
|
2014-02-07 08:41:11 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-02-06 20:30:27 -04:00
|
|
|
/*
|
|
|
|
|
* Diagram's Flows Handling
|
|
|
|
|
*/
|
|
|
|
|
$whiteList = array();
|
2014-02-07 15:42:24 -04:00
|
|
|
|
2014-02-07 08:41:11 -04:00
|
|
|
foreach ($diagram["flows"] as $i => $flowData) {
|
|
|
|
|
$diagram["flows"][$i] = $flowData = array_change_key_case($flowData, CASE_UPPER);
|
2014-02-07 15:42:24 -04:00
|
|
|
|
|
|
|
|
// if it is a new flow record
|
|
|
|
|
if (! \BpmnFlow::exists($flowData["FLO_UID"])) {
|
|
|
|
|
$oldFloUid = $flowData["FLO_UID"];
|
|
|
|
|
$flowData["FLO_UID"] = Hash::generateUID();
|
|
|
|
|
|
2014-02-10 11:29:28 -04:00
|
|
|
$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;
|
|
|
|
|
}
|
2014-02-07 15:42:24 -04:00
|
|
|
|
|
|
|
|
$result[] = array("object" => "flow", "new_uid" => $flowData["FLO_UID"], "old_uid" => $oldFloUid);
|
|
|
|
|
$diagram["flows"][$i] = $flowData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$whiteList[] = $flowData["FLO_UID"];
|
2014-02-07 08:41:11 -04:00
|
|
|
}
|
2014-02-06 20:30:27 -04:00
|
|
|
|
2014-02-07 15:42:24 -04:00
|
|
|
foreach ($diagram["flows"] as $flowData) {
|
2014-02-07 08:41:11 -04:00
|
|
|
// flow exists ?
|
2014-02-07 15:42:24 -04:00
|
|
|
if (\BpmnFlow::exists($flowData["FLO_UID"])) {
|
2014-02-06 20:30:27 -04:00
|
|
|
// then update activity
|
2014-02-07 15:42:24 -04:00
|
|
|
$bwp->updateFlow($flowData["FLO_UID"], $flowData);
|
2014-02-06 20:30:27 -04:00
|
|
|
} else {
|
|
|
|
|
// if not exists then create it
|
2014-02-07 15:42:24 -04:00
|
|
|
$bwp->addFlow($flowData, $diagram["flows"], $diagram["gateways"], $diagram["events"]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-06 20:30:27 -04:00
|
|
|
|
2014-02-07 15:42:24 -04:00
|
|
|
$flows = $bwp->getFlows();
|
2014-02-07 08:41:11 -04:00
|
|
|
|
2014-02-07 15:42:24 -04:00
|
|
|
// 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"]);
|
2014-02-06 20:30:27 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-01-28 17:01:26 -04:00
|
|
|
return $result;
|
2013-12-05 20:44:28 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
|
|
|
|
}
|
2013-12-05 20:41:21 -04:00
|
|
|
}
|
2013-12-13 12:57:02 -04:00
|
|
|
|
2014-01-24 17:55:42 -04:00
|
|
|
public function delete($prjUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$process = new \BusinessModel\Process();
|
|
|
|
|
$process->deleteProcess($prjUid);
|
|
|
|
|
|
|
|
|
|
BpmnModel::deleteProject($prjUid);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-04 17:34:29 -04:00
|
|
|
/**
|
|
|
|
|
* @url GET /:prj_uid/process
|
|
|
|
|
*
|
|
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
|
|
|
|
*/
|
|
|
|
|
public function doGetProcess($prj_uid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$process = new \BusinessModel\Process();
|
|
|
|
|
$process->setFormatFieldNameInUppercase(false);
|
|
|
|
|
$process->setArrayFieldNameForException(array("processUid" => "prj_uid"));
|
|
|
|
|
|
|
|
|
|
$response = $process->getProcess($prj_uid);
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @url PUT /:prj_uid/process
|
|
|
|
|
*
|
|
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
|
|
|
|
* @param array $request_data
|
|
|
|
|
*/
|
|
|
|
|
public function doPutProcess($prj_uid, $request_data)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$process = new \BusinessModel\Process();
|
|
|
|
|
$process->setFormatFieldNameInUppercase(false);
|
|
|
|
|
$process->setArrayFieldNameForException(array("processUid" => "prj_uid"));
|
|
|
|
|
|
|
|
|
|
$arrayData = $process->update($prj_uid, $request_data);
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-23 17:14:04 -04:00
|
|
|
/**
|
2014-02-06 15:35:49 -04:00
|
|
|
* @url GET /:prj_uid/dynaforms
|
|
|
|
|
*
|
|
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
2013-12-23 17:14:04 -04:00
|
|
|
*/
|
2014-02-06 15:35:49 -04:00
|
|
|
public function doGetDynaForms($prj_uid)
|
2013-12-23 17:14:04 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$process = new \BusinessModel\Process();
|
2014-02-06 15:35:49 -04:00
|
|
|
$process->setFormatFieldNameInUppercase(false);
|
|
|
|
|
$process->setArrayFieldNameForException(array("processUid" => "prj_uid"));
|
2013-12-23 17:14:04 -04:00
|
|
|
|
2014-02-06 15:35:49 -04:00
|
|
|
$response = $process->getDynaForms($prj_uid);
|
2013-12-23 17:14:04 -04:00
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 12:57:02 -04:00
|
|
|
/**
|
2014-02-06 15:35:49 -04:00
|
|
|
* @url GET /:prj_uid/input-documents
|
2014-01-17 15:20:11 -04:00
|
|
|
*
|
2014-02-06 15:35:49 -04:00
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
2013-12-13 12:57:02 -04:00
|
|
|
*/
|
2014-02-06 15:35:49 -04:00
|
|
|
public function doGetInputDocuments($prj_uid)
|
2013-12-13 12:57:02 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$process = new \BusinessModel\Process();
|
|
|
|
|
|
2014-02-06 15:35:49 -04:00
|
|
|
$response = $process->getInputDocuments($prj_uid);
|
2013-12-13 12:57:02 -04:00
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-22 17:18:33 -04:00
|
|
|
|
|
|
|
|
/**
|
2014-01-27 15:21:15 -04:00
|
|
|
* @url GET /:prj_uid/web-entries
|
2014-01-22 17:18:33 -04:00
|
|
|
*
|
2014-01-27 15:21:15 -04:00
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
2014-01-22 17:18:33 -04:00
|
|
|
*/
|
2014-01-27 15:21:15 -04:00
|
|
|
public function doGetWebEntries($prj_uid)
|
2014-01-22 17:18:33 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$process = new \BusinessModel\Process();
|
2014-02-07 14:52:35 -04:00
|
|
|
$process->setFormatFieldNameInUppercase(false);
|
|
|
|
|
$process->setArrayFieldNameForException(array("processUid" => "prj_uid"));
|
2014-01-22 17:18:33 -04:00
|
|
|
|
2014-01-27 15:21:15 -04:00
|
|
|
$response = $process->getWebEntries($prj_uid);
|
2014-01-22 17:18:33 -04:00
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-07 08:41:11 -04:00
|
|
|
|
|
|
|
|
protected static function mapUid($oldUid, $list)
|
|
|
|
|
{
|
|
|
|
|
foreach ($list as $item) {
|
|
|
|
|
if ($item["old_uid"] == $oldUid) {
|
|
|
|
|
return $item["new_uid"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-10 11:29:28 -04:00
|
|
|
return false;
|
2014-02-07 08:41:11 -04:00
|
|
|
}
|
2013-12-05 23:01:02 -04:00
|
|
|
}
|
2013-12-13 12:57:02 -04:00
|
|
|
|