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->setAPIVersion($version);
$rest->addAuthenticationClass('Api\\OAuth2\\Server', '');
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 $userId;
const SYSTEM_EXCEPTION_STATUS = 500;
public function __costruct()
{
self::$workspace = null;

View File

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

View File

@@ -25,14 +25,14 @@ class Process
if ($type != "SEQUENTIAL" && $type != "SEC-JOIN" && $type != "DISCRIMINATOR") {
if ($processMap->getNumberOfRoutes($processUid, $taskUid, $nextTaskUid, $type) > 0) {
//die();
throw (new Exception());
throw (new \Exception());
}
//unset($aRow);
}
if ($delete || $type == "SEQUENTIAL" || $type == "SEC-JOIN" || $type == "DISCRIMINATOR") {
//G::LoadClass("tasks");
//\G::LoadClass("tasks");
$tasks = new \Tasks();
@@ -56,7 +56,7 @@ class Process
public function defineProcess($option, $arrayDefineProcessData)
{
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
@@ -70,19 +70,19 @@ class Process
switch ($option) {
case "CREATE":
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"]) == "") {
throw (new Exception("Process title data do not exist"));
throw (new \Exception("Process title data do not exist"));
}
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"])) {
throw (new Exception("Process category data do not exist"));
throw (new \Exception("Process category data do not exist"));
}
break;
case "UPDATE":
@@ -98,7 +98,7 @@ class Process
}
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 ();
@@ -500,7 +500,7 @@ class Process
}
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>
<div align="center">
<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="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="hidden" name="authorize" id="authorize" value="1">
</div>
</span>