diff --git a/features/backend/process_variables/basic_sequence.feature b/features/backend/process_variables/basic_sequence.feature new file mode 100644 index 000000000..a805659e4 --- /dev/null +++ b/features/backend/process_variables/basic_sequence.feature @@ -0,0 +1,49 @@ +@ProcessMakerMichelangelo @RestAPI +Feature: Process Variables + Requirements: + a workspace with the process 14414793652a5d718b65590036026581 ("Sample Project #1") already loaded + there are three activities in the process + + Background: + Given that I have a valid access_token + + #GET /api/1.0/{workspace}/project/{prj_uid}/variables + # Get all variables of a Process + Scenario Outline: Get all variables of a Process + And I request "project/14414793652a5d718b65590036026581/variables" + And the content type is "application/json" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the type is "array" + And the "var_name" property in row equals "" + + Examples: + | i | var_name | + | 0 | SYS_LANG | + | 1 | SYS_SKIN | + | 2 | SYS_SYS | + + #GET /api/1.0/{workspace}/project/{prj_uid}/grid/variables + # Get grid variables of a Process + Scenario: Get grid variables of a Process + Given I request "project/14414793652a5d718b65590036026581/grid/variables" + And the content type is "application/json" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the type is "array" + And the json data is an empty array + + #GET /api/1.0/{workspace}/project/{prj_uid}/grid/{grid_uid}/variables + # Get all variables of a Grid + Scenario Outline: Get all variables of a Grid + Given I request "project/14414793652a5d718b65590036026581/grid/00000000000000000000000000000000/variables" + And the content type is "application/json" + Then the response status code should be + And the response charset is "UTF-8" + And the type is "object" + And the response status message should have the following text "" + + Examples: + | status_code | status_message | + | 400 | grid_uid | + diff --git a/workflow/engine/src/BusinessModel/DynaForm.php b/workflow/engine/src/BusinessModel/DynaForm.php index c9d6c80a6..4bd341d18 100644 --- a/workflow/engine/src/BusinessModel/DynaForm.php +++ b/workflow/engine/src/BusinessModel/DynaForm.php @@ -237,6 +237,32 @@ class DynaForm } } + /** + * Verify if not is grid DynaForm + * + * @param string $dynaFormUid Unique id of DynaForm + * @param string $fieldNameForException Field name for the exception + * + * return void Throw exception if not is grid DynaForm + */ + public function throwExceptionIfNotIsGridDynaForm($dynaFormUid, $fieldNameForException) + { + try { + //Load DynaForm + $dynaForm = new \Dynaform(); + + $arrayDynaFormData = $dynaForm->Load($dynaFormUid); + + if ($arrayDynaFormData["DYN_TYPE"] != "grid") { + $msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $dynaFormUid), "The DynaForm with {0}: {1}, not is grid"); + + throw (new \Exception($msg)); + } + } catch (\Exception $e) { + throw $e; + } + } + /** * Create DynaForm for a Process * diff --git a/workflow/engine/src/BusinessModel/Process.php b/workflow/engine/src/BusinessModel/Process.php index 52e74b84f..88bedf8e1 100644 --- a/workflow/engine/src/BusinessModel/Process.php +++ b/workflow/engine/src/BusinessModel/Process.php @@ -1569,6 +1569,7 @@ class Process $dynaForm = new \BusinessModel\DynaForm(); $dynaForm->throwExceptionIfNotExistsDynaForm($gridUid, $processUid, $this->arrayFieldNameForException["gridUid"]); + $dynaForm->throwExceptionIfNotIsGridDynaForm($gridUid, $this->arrayFieldNameForException["gridUid"]); //Get data $file = PATH_DYNAFORM . $processUid . PATH_SEP . $gridUid . ".xml"; diff --git a/workflow/engine/src/BusinessModel/WebEntry.php b/workflow/engine/src/BusinessModel/WebEntry.php index 00eca8340..95157a278 100644 --- a/workflow/engine/src/BusinessModel/WebEntry.php +++ b/workflow/engine/src/BusinessModel/WebEntry.php @@ -7,9 +7,12 @@ class WebEntry "TAS_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "taskUid"), "DYN_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "dynaFormUid"), "METHOD" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("WS", "HTML"), "fieldNameAux" => "method"), - "INPUT_DOCUMENT_ACCESS" => array("type" => "int", "required" => true, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "inputDocumentAccess"), - "USR_USERNAME" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userUsername"), - "USR_PASSWORD" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userPassword") + "INPUT_DOCUMENT_ACCESS" => array("type" => "int", "required" => true, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "inputDocumentAccess") + ); + + private $arrayUserFieldDefinition = array( + "USR_USERNAME" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userUsername"), + "USR_PASSWORD" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userPassword") ); private $formatFieldNameInUppercase = true; @@ -29,6 +32,10 @@ class WebEntry foreach ($this->arrayFieldDefinition as $key => $value) { $this->arrayFieldNameForException[$value["fieldNameAux"]] = $key; } + + foreach ($this->arrayUserFieldDefinition as $key => $value) { + $this->arrayFieldNameForException[$value["fieldNameAux"]] = $key; + } } catch (\Exception $e) { throw $e; } @@ -279,13 +286,7 @@ class WebEntry $projectUser = new \BusinessModel\ProjectUser(); if ($arrayData["METHOD"] == "WS") { - if (!isset($arrayData["USR_USERNAME"])) { - throw (new \Exception(str_replace(array("{0}"), array($this->arrayFieldNameForException["userUsername"]), "The \"{0}\" attribute is not defined"))); - } - - if (!isset($arrayData["USR_PASSWORD"])) { - throw (new \Exception(str_replace(array("{0}"), array($this->arrayFieldNameForException["userPassword"]), "The \"{0}\" attribute is not defined"))); - } + $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayUserFieldDefinition, $this->arrayFieldNameForException, true); $loginData = $projectUser->userLogin($arrayData["USR_USERNAME"], $arrayData["USR_PASSWORD"]); diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project.php b/workflow/engine/src/Services/Api/ProcessMaker/Project.php index e0bb9704a..6901bdfa2 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project.php @@ -425,9 +425,8 @@ class Project extends Api * @url GET /:prj_uid/grid/:grid_uid/variables * * @param string $prj_uid {@min 32}{@max 32} - * @param string $grid_uid */ - public function doGetGridVariablesByGridUid($prj_uid, $grid_uid = "") + public function doGetGridVariables($prj_uid, $grid_uid = "") { try { $process = new \BusinessModel\Process();