From 13689911daf328065a96bb80415ac4889dae4b60 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Mon, 30 Jun 2014 16:31:27 -0400 Subject: [PATCH 1/3] Se agregan validaciones para process variables --- .../ProcessMaker/BusinessModel/Variable.php | 99 +++++++------------ .../Services/Api/Project/Variable.php | 2 +- 2 files changed, 39 insertions(+), 62 deletions(-) diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/Variable.php b/workflow/engine/src/ProcessMaker/BusinessModel/Variable.php index a599c5275..90a3237e8 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/Variable.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/Variable.php @@ -3,38 +3,6 @@ namespace ProcessMaker\BusinessModel; class Variable { - private $arrayFieldDefinition = array( - "VAR_NAME" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varName"), - "VAR_FIELD_TYPE" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varFieldType"), - "VAR_FIELD_SIZE" => array("type" => "int", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varFieldSize"), - "VAR_LABEL" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varLabel"), - "VAR_DBCONNECTION" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varDbconnection"), - "VAR_SQL" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varSql"), - "VAR_NULL" => array("type" => "int", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varNull"), - "VAR_DEFAULT" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varDefault"), - "VAR_ACCEPTED_VALUES" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varAcceptedValues") - ); - - private $arrayFieldNameForException = array( - "processUid" => "PRO_UID" - ); - - /** - * Constructor of the class - * - * return void - */ - public function __construct() - { - try { - foreach ($this->arrayFieldDefinition as $key => $value) { - $this->arrayFieldNameForException[$value["fieldNameAux"]] = $key; - } - } catch (\Exception $e) { - throw $e; - } - } - /** * Create Variable for a Process * @@ -47,13 +15,14 @@ class Variable { try { //Verify data - $process = new \ProcessMaker\BusinessModel\Process(); - $process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]); + Validator::proUid($processUid, '$prj_uid'); $arrayData = array_change_key_case($arrayData, CASE_UPPER); $this->existsName($processUid, $arrayData["VAR_NAME"]); + $this->throwExceptionFieldDefinition($arrayData); + //Create $cnn = \Propel::getConnection("workflow"); try { @@ -121,12 +90,10 @@ class Variable { try { //Verify data - $process = new \ProcessMaker\BusinessModel\Process(); - $process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]); - - $this->throwExceptionIfNotExistsVariable($variableUid); - + Validator::proUid($processUid, '$prj_uid'); $arrayData = array_change_key_case($arrayData, CASE_UPPER); + + $this->throwExceptionFieldDefinition($arrayData); $this->existsName($processUid, $arrayData["VAR_NAME"]); //Update $cnn = \Propel::getConnection("workflow"); @@ -183,9 +150,7 @@ class Variable { try { //Verify data - $process = new \ProcessMaker\BusinessModel\Process(); - - $process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]); + Validator::proUid($processUid, '$prj_uid'); $this->throwExceptionIfNotExistsVariable($variableUid); @@ -211,16 +176,12 @@ class Variable public function getVariable($processUid, $variableUid) { try { - //Verify data - $process = new \ProcessMaker\BusinessModel\Process(); - - $process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]); + Validator::proUid($processUid, '$prj_uid'); $this->throwExceptionIfNotExistsVariable($variableUid); //Get data - $criteria = new \Criteria("workflow"); $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID); @@ -279,12 +240,9 @@ class Variable { try { //Verify data - $process = new \ProcessMaker\BusinessModel\Process(); - - $process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]); + Validator::proUid($processUid, '$prj_uid'); //Get data - $criteria = new \Criteria("workflow"); $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID); @@ -331,19 +289,40 @@ class Variable } /** - * Verify if does not exist the variable in table PROCESS_VARIABLES + * Verify field definition * - * @param string $variableUid Unique id of variable + * @param array $aData Unique id of Variable to exclude * - * return void Throw exception if does not exist the variable in table PROCESS_VARIABLES */ - public function throwExceptionIfNotExistsVariable($variableUid) + public function throwExceptionFieldDefinition($aData) { try { - $obj = \ProcessVariablesPeer::retrieveByPK($variableUid); - - if (is_null($obj)) { - throw new \Exception('var_uid: '.$variableUid. ' '.\G::LoadTranslation("ID_DOES_NOT_EXIST")); + if (isset($aData["VAR_NAME"])) { + Validator::isString($aData['VAR_NAME'], '$var_name'); + } + if (isset($aData["VAR_FIELD_TYPE"])) { + Validator::isString($aData['VAR_FIELD_TYPE'], '$var_field_type'); + } + if (isset($aData["VAR_FIELD_SIZE"])) { + Validator::isInteger($aData["VAR_FIELD_SIZE"], '$var_field_size'); + } + if (isset($aData["VAR_LABEL"])) { + Validator::isString($aData['VAR_LABEL'], '$var_label'); + } + if (isset($aData["VAR_DBCONNECTION"])) { + Validator::isString($aData['VAR_DBCONNECTION'], '$var_dbconnection'); + } + if (isset($aData["VAR_SQL"])) { + Validator::isString($aData['VAR_SQL'], '$var_sql'); + } + if (isset($aData["VAR_NULL"])) { + Validator::isInteger($aData['VAR_NULL'], '$var_null'); + } + if (isset($aData["VAR_DEFAULT"])) { + Validator::isString($aData['VAR_DEFAULT'], '$var_default'); + } + if (isset($aData["VAR_ACCEPTED_VALUES"])) { + Validator::isString($aData['VAR_ACCEPTED_VALUES'], '$var_accepted_values'); } } catch (\Exception $e) { throw $e; @@ -375,7 +354,5 @@ class Variable throw $e; } } - - } diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Project/Variable.php b/workflow/engine/src/ProcessMaker/Services/Api/Project/Variable.php index 9d8ec55a9..ff8ad5e94 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Project/Variable.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Project/Variable.php @@ -55,7 +55,7 @@ class Variable extends Api * * @status 201 */ - public function doPostVariable($prj_uid, array $request_data) + public function doPostVariable($prj_uid, $request_data) { try { $request_data = (array)($request_data); From e2751ab73ef03ea0743c7af0fd5480e29db13dda Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Mon, 30 Jun 2014 17:12:36 -0400 Subject: [PATCH 2/3] BEHAT basico de process varibles --- .../basic_sequence_variables.feature | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 features/backend/projects/variables/basic_sequence_variables.feature diff --git a/features/backend/projects/variables/basic_sequence_variables.feature b/features/backend/projects/variables/basic_sequence_variables.feature new file mode 100644 index 000000000..5a413cf46 --- /dev/null +++ b/features/backend/projects/variables/basic_sequence_variables.feature @@ -0,0 +1,104 @@ +@ProcessMakerMichelangelo @RestAPI +Feature: Process variables Resources + #GET /api/1.0/{workspace}/project/{prj_uid}/process-variables + # Get a List of process variables + Scenario: Get a List of process variables + Given that I have a valid access_token + And I request "project/14414793652a5d718b65590036026581/process-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 + + #POST /api/1.0/{workspace}/project/{prj_uid}/process-variable + # Create a process variable + # Normal creation of a process variable + Scenario: Create "My variable" for a Project (Normal creation of a process variable) + Given that I have a valid access_token + And POST this data: + """ + { + "var_name": "My Variable", + "var_field_type": "text_field", + "var_field_size": 12, + "var_label": "Nombre:", + "var_dbconnection": "", + "var_sql": "", + "var_null": 0, + "var_default": "", + "var_accepted_values": "" + } + """ + And I request "project/14414793652a5d718b65590036026581/process-variable" + And the content type is "application/json" + Then the response status code should be 201 + And the response charset is "UTF-8" + And the type is "object" + And store "var_uid" in session array as variable "variable1" + + #PUT /api/1.0/{workspace}/project/{prj_uid}/process-variable/{var_uid} + # Update a process variable + Scenario: Update a process variable + Given that I have a valid access_token + And PUT this data: + """ + { + "var_name": "My Variable Modify", + "var_field_type": "text_field", + "var_field_size": 1, + "var_label": "Nombre modificado:", + "var_dbconnection": "", + "var_sql": "", + "var_null": 0, + "var_default": "", + "var_accepted_values": "" + } + """ + And that I want to update a resource with the key "variable1" stored in session array + And I request "project/14414793652a5d718b65590036026581/process-variable" + And the content type is "application/json" + Then the response status code should be 200 + + #GET /api/1.0/{workspace}/project/{prj_uid}/process-variables + # Get a List of process variables + Scenario: Get a List of process variables + Given that I have a valid access_token + And I request "project/14414793652a5d718b65590036026581/process-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" + + #GET /api/1.0/{workspace}/project/{prj_uid}/process-variable/{var_uid} + # Get a single process variable + Scenario: Get a single process variable + Given that I have a valid access_token + And that I want to get a resource with the key "variable1" stored in session array + And I request "project/14414793652a5d718b65590036026581/process-variable" + 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 "object" + + #DELETE /api/1.0/{workspace}/project/{prj_uid}/process-variable/{var_uid} + # Delete a process variable + Scenario: Delete a previously created process variable + Given that I have a valid access_token + And that I want to delete a resource with the key "variable1" stored in session array + And I request "project/14414793652a5d718b65590036026581/process-variable" + And the content type is "application/json" + Then the response status code should be 200 + And the response charset is "UTF-8" + + #GET /api/1.0/{workspace}/project/{prj_uid}/process-variables + # Get a List of process variables + Scenario: Get a List of process variables + Given that I have a valid access_token + And I request "project/14414793652a5d718b65590036026581/process-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 + From 0f159a42659e660414dbe8a58f8f87e2c99dda07 Mon Sep 17 00:00:00 2001 From: Daniel Rojas Date: Tue, 1 Jul 2014 09:36:57 -0400 Subject: [PATCH 3/3] Fix Dynaform en el campo dyn_version --- workflow/engine/classes/model/Dynaform.php | 4 +++- .../engine/src/ProcessMaker/BusinessModel/DynaForm.php | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/workflow/engine/classes/model/Dynaform.php b/workflow/engine/classes/model/Dynaform.php index d48fbec92..6c7a2cf65 100755 --- a/workflow/engine/classes/model/Dynaform.php +++ b/workflow/engine/classes/model/Dynaform.php @@ -173,7 +173,9 @@ class Dynaform extends BaseDynaform if (isset($aData["DYN_CONTENT"])) { $this->setDynContent($aData["DYN_CONTENT"]); } - $this->setDynVersion( $aData['DYN_VERSION'] ); + if (isset($aData["DYN_VERSION"])) { + $this->setDynVersion( $aData['DYN_VERSION'] ); + } if ($this->validate()) { $con->begin(); $res = $this->save(); diff --git a/workflow/engine/src/ProcessMaker/BusinessModel/DynaForm.php b/workflow/engine/src/ProcessMaker/BusinessModel/DynaForm.php index 70f1b9f15..4e22170c5 100644 --- a/workflow/engine/src/ProcessMaker/BusinessModel/DynaForm.php +++ b/workflow/engine/src/ProcessMaker/BusinessModel/DynaForm.php @@ -365,6 +365,10 @@ class DynaForm //Create $dynaForm = new \Dynaform(); + if (isset($arrayData["DYN_VERSION"])) { + $arrayData["DYN_VERSION"] = 1; + } + $arrayData["PRO_UID"] = $processUid; $dynaFormUid = $dynaForm->create($arrayData); @@ -953,6 +957,10 @@ class DynaForm $record["DYN_DESCRIPTION"] = \Content::load("DYN_DESCRIPTION", "", $record["DYN_UID"], SYS_LANG); } + if ($record["DYN_VERSION"] == 0) { + $record["DYN_VERSION"] = 1; + } + return array( $this->getFieldNameByFormatFieldName("DYN_UID") => $record["DYN_UID"], $this->getFieldNameByFormatFieldName("DYN_TITLE") => $record["DYN_TITLE"],