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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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-05 14:09:48 -04:00
|
|
|
$projects = new \StdClass(); //TODO
|
2014-01-28 17:01:26 -04:00
|
|
|
|
2014-02-05 12:33:36 -04:00
|
|
|
return $projects;
|
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-01-23 21:29:03 -04:00
|
|
|
$config = array();
|
|
|
|
|
$config['project'] = array('replace_uids' => true);
|
|
|
|
|
|
2013-12-05 20:41:21 -04:00
|
|
|
$bpmnModel = new BpmnModel();
|
2014-01-23 21:29:03 -04:00
|
|
|
$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'];
|
|
|
|
|
}
|
2013-12-10 20:36:51 -04:00
|
|
|
|
2014-01-23 21:29:03 -04:00
|
|
|
$wfProcess = Workflow::loadFromBpmnProject($prjUid);
|
2013-12-10 20:36:51 -04:00
|
|
|
|
2013-12-09 10:42:01 -04:00
|
|
|
$process = new \BusinessModel\Process();
|
|
|
|
|
$userUid = $this->getUserId();
|
|
|
|
|
$data = array('process' => $wfProcess);
|
2014-01-23 21:29:03 -04:00
|
|
|
|
2013-12-09 10:42:01 -04:00
|
|
|
$process->createProcess($userUid, $data);
|
2013-12-05 20:41:21 -04:00
|
|
|
|
2014-01-23 21:29:03 -04:00
|
|
|
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-01-17 13:37:15 -04:00
|
|
|
|
2014-01-28 17:01:26 -04:00
|
|
|
$result = BpmnModel::updateProject($prjUid, $request_data);
|
2013-12-23 17:17:01 -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
|
|
|
/**
|
|
|
|
|
* @url GET /:projectUid/dynaforms
|
|
|
|
|
*/
|
|
|
|
|
public function doGetDynaForms($projectUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$process = new \BusinessModel\Process();
|
|
|
|
|
|
|
|
|
|
$response = $process->getDynaForms($projectUid);
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 12:57:02 -04:00
|
|
|
/**
|
|
|
|
|
* @url GET /:projectUid/input-documents
|
2014-01-17 15:20:11 -04:00
|
|
|
*
|
|
|
|
|
* @param string $projectUid {@min 32}{@max 32}
|
2013-12-13 12:57:02 -04:00
|
|
|
*/
|
|
|
|
|
public function doGetInputDocuments($projectUid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$process = new \BusinessModel\Process();
|
|
|
|
|
|
|
|
|
|
$response = $process->getInputDocuments($projectUid);
|
|
|
|
|
|
|
|
|
|
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-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()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-05 23:01:02 -04:00
|
|
|
}
|
2013-12-13 12:57:02 -04:00
|
|
|
|