diff --git a/gulliver/system/class.bootstrap.php b/gulliver/system/class.bootstrap.php index 388acf6ff..3e1ffea57 100644 --- a/gulliver/system/class.bootstrap.php +++ b/gulliver/system/class.bootstrap.php @@ -1108,6 +1108,7 @@ class Bootstrap $rest = new Luracast\Restler\Restler(); $rest->setAPIVersion($version); + $rest->addAuthenticationClass('Api\\OAuth2\\Server', ''); diff --git a/workflow/engine/classes/class.api.php b/workflow/engine/classes/class.api.php index e2b6588b8..2129ffb15 100644 --- a/workflow/engine/classes/class.api.php +++ b/workflow/engine/classes/class.api.php @@ -6,6 +6,8 @@ class Api private static $workspace; private static $userId; + const SYSTEM_EXCEPTION_STATUS = 500; + public function __costruct() { self::$workspace = null; diff --git a/workflow/engine/services/api/processmaker/Process.php b/workflow/engine/services/api/processmaker/Process.php index d51f2869d..e2aa373b4 100644 --- a/workflow/engine/services/api/processmaker/Process.php +++ b/workflow/engine/services/api/processmaker/Process.php @@ -1,12 +1,18 @@ 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(); diff --git a/workflow/engine/src/BusinessModel/Process.php b/workflow/engine/src/BusinessModel/Process.php index 335c9f9d2..e163d804c 100644 --- a/workflow/engine/src/BusinessModel/Process.php +++ b/workflow/engine/src/BusinessModel/Process.php @@ -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")); } } diff --git a/workflow/engine/templates/oauth2/authorize.php b/workflow/engine/templates/oauth2/authorize.php index 716a44b00..9e2704d27 100644 --- a/workflow/engine/templates/oauth2/authorize.php +++ b/workflow/engine/templates/oauth2/authorize.php @@ -79,8 +79,8 @@ $response = array(
- - + +