some updates on PM API

This commit is contained in:
Erik Amaru Ortiz
2013-11-07 12:37:16 -04:00
parent a8c9748aa3
commit 8e61053435
5 changed files with 59 additions and 72 deletions

View File

@@ -1109,6 +1109,7 @@ class Bootstrap
$rest = new Luracast\Restler\Restler(); $rest = new Luracast\Restler\Restler();
$rest->setAPIVersion($version); $rest->setAPIVersion($version);
$rest->addAuthenticationClass('Api\\OAuth2\\Server', ''); $rest->addAuthenticationClass('Api\\OAuth2\\Server', '');
list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, ''); list($host, $port) = strpos(DB_HOST, ':') !== false ? explode(':', DB_HOST) : array(DB_HOST, '');

View File

@@ -6,6 +6,8 @@ class Api
private static $workspace; private static $workspace;
private static $userId; private static $userId;
const SYSTEM_EXCEPTION_STATUS = 500;
public function __costruct() public function __costruct()
{ {
self::$workspace = null; self::$workspace = null;

View File

@@ -1,12 +1,18 @@
<?php <?php
namespace Services\Api\ProcessMaker; namespace Services\Api\ProcessMaker;
class Process extends \ProcessMaker\Api use \ProcessMaker\Api;
use \Luracast\Restler\RestException;
/**
* Process Api Controller
*
* @protected
*/
class Process extends Api
{ {
public function index($proTitle = "", $proCategory = "", $start = 0, $limit = 25) public function index($proTitle = "", $proCategory = "", $start = 0, $limit = 25)
{ {
$response = array();
try { try {
$arrayFilterData = array(); $arrayFilterData = array();
@@ -19,46 +25,19 @@ class Process extends \ProcessMaker\Api
} }
$process = new \BusinessModel\Process(); $process = new \BusinessModel\Process();
$data = $process->loadAllProcess($arrayFilterData, $start, $limit); $data = $process->loadAllProcess($arrayFilterData, $start, $limit);
//Response // Composing Response
$response["success"] = true; $response = array(
$response["message"] = "Processes loaded successfully"; 'processes' => $data['data'],
$response["data"] = $data; 'totalCount' => $data['totalCount']
} catch (Exception $e) { );
//Response
$response["success"] = false; return $response;
$response["message"] = $e->getMessage();
} catch (\Exception $e) {
throw new RestException(Api::SYSTEM_EXCEPTION_STATUS, $e->getMessage());
} }
return $response;
}
public function post($request_data = null)
{
define("SYS_LANG", $request_data["lang"]);
$response = array();
try {
$userUid = "00000000000000000000000000000001"; //$this->getUserId()
$process = new \BusinessModel\Process();
$data = $process->createProcess($userUid, $request_data);
//Response
$response["success"] = true;
$response["message"] = "Process saved successfully";
$response["data"] = $data;
} catch (Exception $e) {
//Response
$response["success"] = false;
$response["message"] = $e->getMessage();
}
return $response;
} }
public function get($processUid) public function get($processUid)
@@ -74,23 +53,35 @@ class Process extends \ProcessMaker\Api
$response["success"] = true; $response["success"] = true;
$response["message"] = "Process load successfully"; $response["message"] = "Process load successfully";
$response["data"] = $data; $response["data"] = $data;
} catch (Exception $e) { } catch (\Exception $e) {
//Response throw new RestException(Api::SYSTEM_EXCEPTION_STATUS, $e->getMessage());
$response["success"] = false;
$response["message"] = $e->getMessage();
} }
return $response; return $response;
} }
public function post($request_data = null)
{
defined('SYS_LANG') || define("SYS_LANG", $request_data["lang"]);
try {
$process = new \BusinessModel\Process();
$userUid = $this->getUserId();
return $process->createProcess($userUid, $request_data);
} catch (\Exception $e) {
throw new RestException(Api::SYSTEM_EXCEPTION_STATUS, $e->getMessage());
}
}
public function put($processUid, $request_data = null) public function put($processUid, $request_data = null)
{ {
$response = array(); $response = array();
try { try {
$userUid = "00000000000000000000000000000001";
$process = new \BusinessModel\Process(); $process = new \BusinessModel\Process();
$userUid = $this->getUserId();
$data = $process->updateProcess($processUid, $userUid, $request_data); $data = $process->updateProcess($processUid, $userUid, $request_data);
@@ -98,10 +89,8 @@ class Process extends \ProcessMaker\Api
$response["success"] = true; $response["success"] = true;
$response["message"] = "Process updated successfully"; $response["message"] = "Process updated successfully";
$response["data"] = $data; $response["data"] = $data;
} catch (Exception $e) { } catch (\Exception $e) {
//Response throw new RestException(Api::SYSTEM_EXCEPTION_STATUS, $e->getMessage());
$response["success"] = false;
$response["message"] = $e->getMessage();
} }
return $response; return $response;
@@ -119,19 +108,14 @@ class Process extends \ProcessMaker\Api
//Response //Response
$response["success"] = true; $response["success"] = true;
$response["message"] = "Process was deleted successfully"; $response["message"] = "Process was deleted successfully";
} catch (Exception $e) { } catch (\Exception $e) {
//Response throw new RestException(Api::SYSTEM_EXCEPTION_STATUS, $e->getMessage());
$response["success"] = false;
$response["message"] = $e->getMessage();
} }
return $response; return $response;
} }
/** /**
* @url GET /:processUid/activity/:activityUid * @url GET /:processUid/activity/:activityUid
*/ */
@@ -168,7 +152,7 @@ class Process extends \ProcessMaker\Api
$response["success"] = true; $response["success"] = true;
$response["message"] = "Properties loaded successfully"; $response["message"] = "Properties loaded successfully";
$response["data"] = array("activity" => $arrayData); $response["data"] = array("activity" => $arrayData);
} catch (Exception $e) { } catch (\Exception $e) {
//Response //Response
$response["success"] = false; $response["success"] = false;
$response["message"] = $e->getMessage(); $response["message"] = $e->getMessage();
@@ -202,7 +186,7 @@ class Process extends \ProcessMaker\Api
$response["success"] = true; $response["success"] = true;
$response["message"] = "Properties loaded successfully"; $response["message"] = "Properties loaded successfully";
$response["data"] = array("activity" => $arrayData); $response["data"] = array("activity" => $arrayData);
} catch (Exception $e) { } catch (\Exception $e) {
//Response //Response
$response["success"] = false; $response["success"] = false;
$response["message"] = $e->getMessage(); $response["message"] = $e->getMessage();
@@ -238,7 +222,7 @@ class Process extends \ProcessMaker\Api
$response["success"] = true; $response["success"] = true;
$response["message"] = "Extended loaded successfully"; $response["message"] = "Extended loaded successfully";
$response["data"] = array("activity" => $arrayData); $response["data"] = array("activity" => $arrayData);
} catch (Exception $e) { } catch (\Exception $e) {
//Response //Response
$response["success"] = false; $response["success"] = false;
$response["message"] = $e->getMessage(); $response["message"] = $e->getMessage();
@@ -263,7 +247,7 @@ class Process extends \ProcessMaker\Api
$response["success"] = true; $response["success"] = true;
$response["message"] = "Steps loaded successfully"; $response["message"] = "Steps loaded successfully";
$response["data"] = $data; $response["data"] = $data;
} catch (Exception $e) { } catch (\Exception $e) {
//Response //Response
$response["success"] = false; $response["success"] = false;
$response["message"] = $e->getMessage(); $response["message"] = $e->getMessage();

View File

@@ -25,14 +25,14 @@ class Process
if ($type != "SEQUENTIAL" && $type != "SEC-JOIN" && $type != "DISCRIMINATOR") { if ($type != "SEQUENTIAL" && $type != "SEC-JOIN" && $type != "DISCRIMINATOR") {
if ($processMap->getNumberOfRoutes($processUid, $taskUid, $nextTaskUid, $type) > 0) { if ($processMap->getNumberOfRoutes($processUid, $taskUid, $nextTaskUid, $type) > 0) {
//die(); //die();
throw (new Exception()); throw (new \Exception());
} }
//unset($aRow); //unset($aRow);
} }
if ($delete || $type == "SEQUENTIAL" || $type == "SEC-JOIN" || $type == "DISCRIMINATOR") { if ($delete || $type == "SEQUENTIAL" || $type == "SEC-JOIN" || $type == "DISCRIMINATOR") {
//G::LoadClass("tasks"); //\G::LoadClass("tasks");
$tasks = new \Tasks(); $tasks = new \Tasks();
@@ -56,7 +56,7 @@ class Process
public function defineProcess($option, $arrayDefineProcessData) public function defineProcess($option, $arrayDefineProcessData)
{ {
if (!isset($arrayDefineProcessData["process"]) || count($arrayDefineProcessData["process"]) == 0) { if (!isset($arrayDefineProcessData["process"]) || count($arrayDefineProcessData["process"]) == 0) {
throw (new Exception("Process data do not exist")); throw (new \Exception("Process data do not exist"));
} }
//Process //Process
@@ -70,19 +70,19 @@ class Process
switch ($option) { switch ($option) {
case "CREATE": case "CREATE":
if (!isset($arrayProcessData["USR_UID"]) || trim($arrayProcessData["USR_UID"]) == "") { if (!isset($arrayProcessData["USR_UID"]) || trim($arrayProcessData["USR_UID"]) == "") {
throw (new Exception("User data do not exist")); throw (new \Exception("User data do not exist"));
} }
if (!isset($arrayProcessData["PRO_TITLE"]) || trim($arrayProcessData["PRO_TITLE"]) == "") { if (!isset($arrayProcessData["PRO_TITLE"]) || trim($arrayProcessData["PRO_TITLE"]) == "") {
throw (new Exception("Process title data do not exist")); throw (new \Exception("Process title data do not exist"));
} }
if (!isset($arrayProcessData["PRO_DESCRIPTION"])) { if (!isset($arrayProcessData["PRO_DESCRIPTION"])) {
throw (new Exception("Process description data do not exist")); throw (new \Exception("Process description data do not exist"));
} }
if (!isset($arrayProcessData["PRO_CATEGORY"])) { if (!isset($arrayProcessData["PRO_CATEGORY"])) {
throw (new Exception("Process category data do not exist")); throw (new \Exception("Process category data do not exist"));
} }
break; break;
case "UPDATE": case "UPDATE":
@@ -98,7 +98,7 @@ class Process
} }
if (isset($arrayProcessData["PRO_TITLE"]) && $process->existsByProTitle($arrayProcessData["PRO_TITLE"])) { if (isset($arrayProcessData["PRO_TITLE"]) && $process->existsByProTitle($arrayProcessData["PRO_TITLE"])) {
throw (new Exception(G::LoadTranslation("ID_PROCESSTITLE_ALREADY_EXISTS", SYS_LANG, array("PRO_TITLE" => $arrayProcessData["PRO_TITLE"])))); throw (new \Exception(\G::LoadTranslation("ID_PROCESSTITLE_ALREADY_EXISTS", SYS_LANG, array("PRO_TITLE" => $arrayProcessData["PRO_TITLE"]))));
} }
$arrayProcessData["PRO_DYNAFORMS"] = array (); $arrayProcessData["PRO_DYNAFORMS"] = array ();
@@ -500,7 +500,7 @@ class Process
} }
if ($sum > 0) { if ($sum > 0) {
throw (new Exception("You can't delete the process, because it has $sum cases")); throw (new \Exception("You can't delete the process, because it has $sum cases"));
} }
} }

View File

@@ -79,8 +79,8 @@ $response = array(
</ul> </ul>
<div align="center"> <div align="center">
<input type="submit" value="Yes, I Authorize This Request" name="authorize" class="module_app_button___gray " value="1"> <input type="submit" value="Yes, I authorize this request" name="authorize" class="module_app_button___gray " value="1">
<input type="button" value="Reject this Request" name="reject_btn" id="reject_btn" class="module_app_button___gray " onclick="doSubmit()"> <input type="button" value="Reject this request" name="reject_btn" id="reject_btn" class="module_app_button___gray " onclick="doSubmit()">
<input type="hidden" name="authorize" id="authorize" value="1"> <input type="hidden" name="authorize" id="authorize" value="1">
</div> </div>
</span> </span>