2013-12-05 20:41:21 -04:00
|
|
|
<?php
|
2014-04-02 17:02:02 -04:00
|
|
|
namespace ProcessMaker\Services\Api;
|
2013-12-05 20:41:21 -04:00
|
|
|
|
|
|
|
|
use Luracast\Restler\RestException;
|
|
|
|
|
use ProcessMaker\Services\Api;
|
2014-02-20 10:50:52 -04:00
|
|
|
use \ProcessMaker\Project\Adapter;
|
|
|
|
|
use \ProcessMaker\Util;
|
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-04-24 16:05:42 -04:00
|
|
|
/**
|
|
|
|
|
* @url GET
|
|
|
|
|
*/
|
|
|
|
|
public function doGetProjects()
|
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-20 10:50:52 -04:00
|
|
|
$projects = Adapter\BpmnWorkflow::getList($start, $limit, $filter, CASE_LOWER);
|
2014-02-05 14:09:48 -04:00
|
|
|
|
|
|
|
|
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-04-24 16:05:42 -04:00
|
|
|
/**
|
|
|
|
|
* @url GET /:prj_uid
|
|
|
|
|
*
|
|
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
|
|
|
|
*/
|
|
|
|
|
public function doGetProject($prj_uid)
|
2014-01-28 17:01:26 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-04-24 16:05:42 -04:00
|
|
|
return Adapter\BpmnWorkflow::getStruct($prj_uid);
|
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
|
|
|
/**
|
2014-05-07 15:55:51 -04:00
|
|
|
* Post Project
|
|
|
|
|
*
|
|
|
|
|
* @param string $prj_name
|
|
|
|
|
* @param array $request_data
|
|
|
|
|
*
|
|
|
|
|
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
|
|
|
|
* @copyright Colosa - Bolivia
|
|
|
|
|
*
|
|
|
|
|
* @url POST
|
2013-12-17 11:24:37 -04:00
|
|
|
* @status 201
|
|
|
|
|
*/
|
2014-05-07 16:49:58 -04:00
|
|
|
public function post($prj_name, $request_data)
|
2013-12-05 20:41:21 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-05-14 15:56:05 -04:00
|
|
|
if (!isset($request_data['prj_author'])) {
|
|
|
|
|
$request_data['prj_author'] = $this->getUserId();
|
|
|
|
|
}
|
2014-04-25 11:38:53 -04:00
|
|
|
return Adapter\BpmnWorkflow::createFromStruct($request_data);
|
2013-12-05 20:41:21 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-25 14:47:00 -04:00
|
|
|
/**
|
|
|
|
|
* @url PUT /:prj_uid
|
|
|
|
|
*
|
|
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
|
|
|
|
*/
|
|
|
|
|
public function doPutProject($prj_uid, $request_data)
|
2013-12-23 17:17:01 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-04-25 14:47:00 -04:00
|
|
|
return Adapter\BpmnWorkflow::updateFromStruct($prj_uid, $request_data);
|
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-04-25 11:38:53 -04:00
|
|
|
/**
|
|
|
|
|
* @param string $prj_uid {@min 1}{@max 32}
|
|
|
|
|
* @url DELETE /:prj_uid
|
|
|
|
|
*/
|
|
|
|
|
public function delete($prj_uid)
|
2014-01-24 17:55:42 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-04-25 11:38:53 -04:00
|
|
|
$oBpmnWf = Adapter\BpmnWorkflow::load($prj_uid);
|
|
|
|
|
$oBpmnWf->remove();
|
2014-01-24 17:55:42 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-28 12:57:55 -04:00
|
|
|
/**
|
|
|
|
|
* @url GET /:prj_uid/export
|
|
|
|
|
*
|
|
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
|
|
|
|
*/
|
|
|
|
|
public function export($prj_uid)
|
|
|
|
|
{
|
|
|
|
|
$exporter = new \ProcessMaker\Exporter\XmlExporter($prj_uid);
|
|
|
|
|
|
|
|
|
|
$outputDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "files" . PATH_SEP . "output" . PATH_SEP;
|
|
|
|
|
$version = \ProcessMaker\Util\Common::getLastVersion($outputDir . $exporter->getProjectName() . "-*.pmx") + 1;
|
|
|
|
|
$outputFilename = $outputDir . sprintf("%s-%s.%s", $exporter->getProjectName(), $version, "pmx");
|
|
|
|
|
|
2014-05-07 09:24:46 -04:00
|
|
|
$exporter->setMetadata("export_version", $version);
|
2014-03-28 12:57:55 -04:00
|
|
|
$exporter->saveExport($outputFilename);
|
|
|
|
|
|
|
|
|
|
$httpStream = new \ProcessMaker\Util\IO\HttpStream();
|
|
|
|
|
$fileExtension = pathinfo($outputFilename, PATHINFO_EXTENSION);
|
|
|
|
|
|
|
|
|
|
$httpStream->loadFromFile($outputFilename);
|
2014-05-09 16:49:31 -04:00
|
|
|
$httpStream->setHeader("Content-Type", "application/xml; charset=UTF-8");
|
2014-03-28 12:57:55 -04:00
|
|
|
$httpStream->send();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-05 12:19:20 -04:00
|
|
|
/**
|
|
|
|
|
* @url POST /import
|
|
|
|
|
*
|
|
|
|
|
* @param array $request_data
|
|
|
|
|
*
|
|
|
|
|
* @status 201
|
|
|
|
|
*/
|
2014-05-16 11:22:53 -04:00
|
|
|
public function doPostImport(array $request_data, $option = null, $option_group = null)
|
2014-05-05 12:19:20 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$importer = new \ProcessMaker\Importer\XmlImporter();
|
|
|
|
|
|
2014-05-12 15:24:19 -04:00
|
|
|
$importer->setSaveDir(PATH_DOCUMENT . "input");
|
2014-05-05 12:19:20 -04:00
|
|
|
$importer->setData("usr_uid", $this->getUserId());
|
|
|
|
|
|
2014-05-16 11:22:53 -04:00
|
|
|
$arrayData = $importer->importPostFile(
|
|
|
|
|
$request_data,
|
|
|
|
|
$option,
|
|
|
|
|
$option_group,
|
|
|
|
|
array("projectFile" => "project_file", "option" => "option", "optionGroup" => "option_group")
|
|
|
|
|
);
|
2014-05-05 12:19:20 -04:00
|
|
|
|
|
|
|
|
$response = $arrayData;
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
} 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 {
|
2014-04-02 17:02:02 -04:00
|
|
|
$process = new \ProcessMaker\BusinessModel\Process();
|
2014-02-04 17:34:29 -04:00
|
|
|
$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 {
|
2014-04-02 17:02:02 -04:00
|
|
|
$process = new \ProcessMaker\BusinessModel\Process();
|
2014-02-04 17:34:29 -04:00
|
|
|
$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()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 17:18:48 -04:00
|
|
|
/**
|
|
|
|
|
* @url POST /process/:pro_uid/generate-bpmn
|
|
|
|
|
*
|
|
|
|
|
* @param string $pro_uid {@min 32}{@max 32}
|
|
|
|
|
*
|
|
|
|
|
* @status 201
|
|
|
|
|
*/
|
|
|
|
|
public function doPostProcessGenerateBpmn($pro_uid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$workflowBpmn = new \ProcessMaker\Project\Adapter\WorkflowBpmn();
|
|
|
|
|
|
|
|
|
|
$projectUid = $workflowBpmn->generateBpmn($pro_uid, "pro_uid");
|
|
|
|
|
|
|
|
|
|
$arrayData = array_change_key_case(array("PRJ_UID" => $projectUid), CASE_LOWER);
|
|
|
|
|
|
|
|
|
|
$response = $arrayData;
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
} 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 {
|
2014-04-02 17:02:02 -04:00
|
|
|
$process = new \ProcessMaker\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 {
|
2014-04-02 17:02:02 -04:00
|
|
|
$process = new \ProcessMaker\BusinessModel\Process();
|
2014-02-12 12:32:04 -04:00
|
|
|
$process->setFormatFieldNameInUppercase(false);
|
|
|
|
|
$process->setArrayFieldNameForException(array("processUid" => "prj_uid"));
|
2013-12-13 12:57:02 -04:00
|
|
|
|
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-02-13 17:18:17 -04:00
|
|
|
/**
|
|
|
|
|
* @url GET /:prj_uid/variables
|
|
|
|
|
*
|
|
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
|
|
|
|
*/
|
|
|
|
|
public function doGetVariables($prj_uid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2014-04-02 17:02:02 -04:00
|
|
|
$process = new \ProcessMaker\BusinessModel\Process();
|
2014-02-13 17:18:17 -04:00
|
|
|
$process->setFormatFieldNameInUppercase(false);
|
|
|
|
|
$process->setArrayFieldNameForException(array("processUid" => "prj_uid"));
|
|
|
|
|
|
|
|
|
|
$response = $process->getVariables("ALL", $prj_uid);
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @url GET /:prj_uid/grid/variables
|
|
|
|
|
* @url GET /:prj_uid/grid/:grid_uid/variables
|
|
|
|
|
*
|
|
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
2014-02-20 17:16:00 -04:00
|
|
|
* @param string $grid_uid
|
2014-02-13 17:18:17 -04:00
|
|
|
*/
|
2014-02-14 11:53:49 -04:00
|
|
|
public function doGetGridVariables($prj_uid, $grid_uid = "")
|
2014-02-13 17:18:17 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-04-02 17:02:02 -04:00
|
|
|
$process = new \ProcessMaker\BusinessModel\Process();
|
2014-02-13 17:18:17 -04:00
|
|
|
$process->setFormatFieldNameInUppercase(false);
|
|
|
|
|
$process->setArrayFieldNameForException(array("processUid" => "prj_uid"));
|
|
|
|
|
|
|
|
|
|
$response = ($grid_uid == "")? $process->getVariables("GRID", $prj_uid) : $process->getVariables("GRIDVARS", $prj_uid, $grid_uid);
|
|
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-20 17:16:00 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @url GET /:prj_uid/trigger-wizards
|
|
|
|
|
*
|
|
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
|
|
|
|
*/
|
|
|
|
|
public function doGetTriggerWizards($prj_uid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
2014-04-02 17:02:02 -04:00
|
|
|
$process = new \ProcessMaker\BusinessModel\Process();
|
2014-02-20 17:16:00 -04:00
|
|
|
$process->setFormatFieldNameInUppercase(false);
|
|
|
|
|
$process->setArrayFieldNameForException(array("processUid" => "prj_uid", "libraryName" => "lib_name", "methodName" => "fn_name"));
|
|
|
|
|
|
|
|
|
|
$response = $process->getLibraries($prj_uid);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|