diff --git a/features/backend/dynaforms/main_tests_dynaform.feature b/features/backend/dynaforms/main_tests_dynaform.feature index dc95a5641..8281c4cbc 100644 --- a/features/backend/dynaforms/main_tests_dynaform.feature +++ b/features/backend/dynaforms/main_tests_dynaform.feature @@ -91,14 +91,6 @@ Feature: Dynaform Main Tests { "fld_name": "", "pro_variable": "" - }, - { - "fld_name": "", - "pro_variable": "" - }, - { - "fld_name": "" } ] } @@ -113,9 +105,9 @@ Feature: Dynaform Main Tests Examples: - | test_description | project | dyn_title | dyn_description | dyn_type | dyn_uid_number | tab_uid | fld_name_01 | pro_variable_01 | fld_name_02 | pro_variable_02 | fld_name_03 | pro_variable_03 | - | create dynaform pmtable 1 | 14414793652a5d718b65590036026581 | Dynaform - pmtable 1 | dyn from pmtable1 | xmlform | 7 | 65193158852cc1a93a5a535084878044 | DYN_UID | @#APPLICATION | DYN_TITLE | @#TITLE | DYN_DESCRIPTION | @#DESCRIPTION | - | create dynaform pmtable 2 | 42445320652cd534acb3824056962285 | Dynaform - pmtable2 | dyn from pmtable2 | xmlform | 8 | 65193158852cc1a93a5a535084878044 | DYN_UID | @#APPLICATION | DYN_TITLE | @#TITLE | DYN_DESCRIPTION | @#DESCRIPTION | + | test_description | project | dyn_title | dyn_description | dyn_type | dyn_uid_number | tab_uid | fld_name_01 | pro_variable_01 | + | create dynaform pmtable 1 | 14414793652a5d718b65590036026581 | Dynaform - pmtable 1 | dyn from pmtable1 | xmlform | 7 | 65193158852cc1a93a5a535084878044 | DYN_UID | @#APPLICATION | + | create dynaform pmtable 2 | 42445320652cd534acb3824056962285 | Dynaform - pmtable2 | dyn from pmtable2 | xmlform | 8 | 65193158852cc1a93a5a535084878044 | DYN_UID | @#APPLICATION | Scenario Outline: Get a List DynaForms of a Project list when there are 9 records, total in both projects @@ -214,4 +206,4 @@ Feature: Dynaform Main Tests | project | records | | 14414793652a5d718b65590036026581 | 0 | - | 42445320652cd534acb3824056962285 | 1 | \ No newline at end of file + | 42445320652cd534acb3824056962285 | 1 | diff --git a/features/backend/dynaforms/negative_tests_dynaform.feature b/features/backend/dynaforms/negative_tests_dynaform.feature index 8d855049e..218b189ad 100644 --- a/features/backend/dynaforms/negative_tests_dynaform.feature +++ b/features/backend/dynaforms/negative_tests_dynaform.feature @@ -48,8 +48,8 @@ Scenario Outline: Normal Dynaform creation for a project with bad parameters (ne Examples: | test_description | project | dyn_title | dyn_description | dyn_type | copy_prj_uid | copy_dyn_uid | error_code | error_message | - | invalid copy_prj_uid | 14414793652a5d718b65590036026581 | Dynaform - Copy 1 | dyn copy | xmlform | 42445320652cd0000000000000000085 | 70070685552cd53605650f7062918505 | 400 | copy_prj_uid | - | invalid copy_dyn_uid | 42445320652cd534acb3824056962285 | Dynaform - Copy 2 | dyn copy | xmlform | 14414793652a5d718b65590036026581 | 70070685500000000000000000000000 | 400 | copy_dyn_uid | + | invalid copy_prj_uid | 14414793652a5d718b65590036026581 | Dynaform - Copy 1 | dyn copy | xmlform | 42445320652cd0000000000000000085 | 70070685552cd53605650f7062918505 | 400 | copy_import.prj_uid | + | invalid copy_dyn_uid | 42445320652cd534acb3824056962285 | Dynaform - Copy 2 | dyn copy | xmlform | 14414793652a5d718b65590036026581 | 70070685500000000000000000000000 | 400 | copy_import.dyn_uid | Scenario Outline: Create dynaform based on a PMTable for a project with bad parameters (negative tests) @@ -87,4 +87,4 @@ Scenario Outline: Normal Dynaform creation for a project with bad parameters (ne | test_description | project | dyn_title | dyn_description | dyn_type | tab_uid | fld_name_01 | pro_variable_01 | fld_name_02 | pro_variable_02 | fld_name_03 | pro_variable_03 | error_code | error_message | | invalid tab_uid | 14414793652a5d718b65590036026581 | Dynaform - pmtable 1 | dyn from pmtable | xmlform | 65193158852cc1a00000000000000000 | DYN_UID | @#APPLICATION | DYN_TITLE | @#TITLE | DYN_DESCRIPTION | @#DESCRIPTION | 400 | tab_uid | - | invalid fld_name_01 | 42445320652cd534acb3824056962285 | Dynaform - pmtable 2 | dyn from pmtable | xmlform | 65193158852cc1a93a5a535084878044 | DYN_INPUT | @#APPLICATION | DYN_TITLE | @#TITLE | DYN_DESCRIPTION | @#DESCRIPTION | 400 | fld_name_01 | \ No newline at end of file + | invalid fld_name_01 | 42445320652cd534acb3824056962285 | Dynaform - pmtable 2 | dyn from pmtable | xmlform | 65193158852cc1a93a5a535084878044 | DYN_INPUT | @#APPLICATION | DYN_TITLE | @#TITLE | DYN_DESCRIPTION | @#DESCRIPTION | 400 | fld_name | diff --git a/workflow/engine/classes/model/Step.php b/workflow/engine/classes/model/Step.php index 1984b7d67..78f0b90b0 100755 --- a/workflow/engine/classes/model/Step.php +++ b/workflow/engine/classes/model/Step.php @@ -374,7 +374,7 @@ class Step extends BaseStep while ($oDataset->next()) { $aRow1 = $oDataset->getRow(); //print_r($aRow1); - $dynHandler = new dynaFormHandler( PATH_DYNAFORM . $_POST['PRO_UID'] . "/" . $aRow1['DYN_UID'] . ".xml" ); + $dynHandler = new dynaFormHandler(PATH_DYNAFORM . $sproUid . PATH_SEP . $aRow1["DYN_UID"] . ".xml"); $dynFields = $dynHandler->getFields(); $sxmlgrid = ''; $sType = ''; diff --git a/workflow/engine/src/BusinessModel/DynaForm.php b/workflow/engine/src/BusinessModel/DynaForm.php index 9304347f8..c50886f35 100644 --- a/workflow/engine/src/BusinessModel/DynaForm.php +++ b/workflow/engine/src/BusinessModel/DynaForm.php @@ -3,28 +3,30 @@ namespace BusinessModel; class DynaForm { + private $arrayFieldDefinition = array( + "DYN_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "dynaFormUid"), + + "DYN_TITLE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "dynaFormTitle"), + "DYN_DESCRIPTION" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "dynaFormDescription"), + "DYN_TYPE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("xmlform", "grid"), "fieldNameAux" => "dynaFormType") + ); + + private $formatFieldNameInUppercase = true; + + private $arrayFieldNameForException = array( + "processUid" => "PRO_UID" + ); + /** - * Get data of unique ids of a DynaForm (Unique id of Process) + * Constructor of the class * - * @param string $dynaFormUid Unique id of DynaForm - * - * return array + * return void */ - public function getDataUids($dynaFormUid) + public function __construct() { try { - $criteria = new \Criteria("workflow"); - - $criteria->addSelectColumn(\DynaformPeer::PRO_UID); - $criteria->add(\DynaformPeer::DYN_UID, $dynaFormUid, \Criteria::EQUAL); - - $rsCriteria = \DynaformPeer::doSelectRS($criteria); - $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); - - if ($rsCriteria->next()) { - return $rsCriteria->getRow(); - } else { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($dynaFormUid, "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}"))); + foreach ($this->arrayFieldDefinition as $key => $value) { + $this->arrayFieldNameForException[$value["fieldNameAux"]] = $key; } } catch (\Exception $e) { throw $e; @@ -32,15 +34,67 @@ class DynaForm } /** - * Verify if the title exists in the DynaForms of Process + * Set the format of the fields name (uppercase, lowercase) * - * @param string $processUid Unique id of Process - * @param string $title Title + * @param bool $flag Value that set the format + * + * return void + */ + public function setFormatFieldNameInUppercase($flag) + { + try { + $this->formatFieldNameInUppercase = $flag; + + $this->setArrayFieldNameForException($this->arrayFieldNameForException); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Set exception messages for fields + * + * @param array $arrayData Data with the fields + * + * return void + */ + public function setArrayFieldNameForException($arrayData) + { + try { + foreach ($arrayData as $key => $value) { + $this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value); + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get the name of the field according to the format + * + * @param string $fieldName Field name + * + * return string Return the field name according the format + */ + public function getFieldNameByFormatFieldName($fieldName) + { + try { + return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Verify if exists the title of a DynaForm + * + * @param string $processUid Unique id of Process + * @param string $dynaFormTitle Title * @param string $dynaFormUidExclude Unique id of DynaForm to exclude * - * return bool Return true if the title exists in the DynaForms of Process, false otherwise + * return bool Return true if exists the title of a DynaForm, false otherwise */ - public function titleExists($processUid, $title, $dynaFormUidExclude = "") + public function existsTitle($processUid, $dynaFormTitle, $dynaFormUidExclude = "") { try { $delimiter = \DBAdapter::getStringDelimiter(); @@ -63,37 +117,7 @@ class DynaForm $criteria->add(\DynaformPeer::DYN_UID, $dynaFormUidExclude, \Criteria::NOT_EQUAL); } - $criteria->add("CT.CON_VALUE", $title, \Criteria::EQUAL); - - $rsCriteria = \DynaformPeer::doSelectRS($criteria); - $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); - - if ($rsCriteria->next()) { - return true; - } else { - return false; - } - } catch (\Exception $e) { - throw $e; - } - } - - /** - * Verify if a DynaForm belongs to Process - * - * @param string $dynaFormUid Unique id of DynaForm - * @param string $processUid Unique id of Process - * - * return bool Return true if a DynaForm belongs to Process, false otherwise - */ - public function dynaFormBelongsProcess($dynaFormUid, $processUid) - { - try { - $criteria = new \Criteria("workflow"); - - $criteria->addSelectColumn(\DynaformPeer::DYN_UID); - $criteria->add(\DynaformPeer::DYN_UID, $dynaFormUid, \Criteria::EQUAL); - $criteria->add(\DynaformPeer::PRO_UID, $processUid, \Criteria::EQUAL); + $criteria->add("CT.CON_VALUE", $dynaFormTitle, \Criteria::EQUAL); $rsCriteria = \DynaformPeer::doSelectRS($criteria); $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); @@ -158,24 +182,23 @@ class DynaForm } /** - * Get data from a request data + * Verify if exists the title of a DynaForm * - * @param object $requestData Request data + * @param string $processUid Unique id of Process + * @param string $dynaFormTitle Title + * @param string $fieldNameForException Field name for the exception + * @param string $dynaFormUidExclude Unique id of DynaForm to exclude * - * return array Return an array with data of request data + * return void Throw exception if exists the title of a DynaForm */ - public function getArrayDataFromRequestData($requestData) + public function throwExceptionIfExistsTitle($processUid, $dynaFormTitle, $fieldNameForException, $dynaFormUidExclude = "") { try { - $arrayData = array(); + if ($this->existsTitle($processUid, $dynaFormTitle, $dynaFormUidExclude)) { + $msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $dynaFormTitle), "The DynaForm title with {0}: \"{1}\", already exists"); - $requestData = (array)($requestData); - - foreach ($requestData as $key => $value) { - $arrayData[$key] = $value; + throw (new \Exception($msg)); } - - return $arrayData; } catch (\Exception $e) { throw $e; } @@ -199,15 +222,13 @@ class DynaForm unset($arrayData["PMTABLE"]); //Verify data - $process = new \Process(); + $process = new \BusinessModel\Process(); - if (!$process->exists($processUid)) { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}"))); - } + $process->throwExceptionIfNoExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]); - if (isset($arrayData["DYN_TITLE"]) && $this->titleExists($processUid, $arrayData["DYN_TITLE"])) { - throw (new \Exception(\G::LoadTranslation("ID_EXIST_DYNAFORM"))); - } + $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true); + + $this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"]); //Create $dynaForm = new \Dynaform(); @@ -219,11 +240,13 @@ class DynaForm //Return unset($arrayData["PRO_UID"]); - $arrayData = array_change_key_case($arrayData, CASE_LOWER); + $arrayData = array_merge(array("DYN_UID" => $dynaFormUid), $arrayData); - unset($arrayData["dyn_uid"]); + if (!$this->formatFieldNameInUppercase) { + $arrayData = array_change_key_case($arrayData, CASE_LOWER); + } - return array_merge(array("dyn_uid" => $dynaFormUid), $arrayData); + return $arrayData; } catch (\Exception $e) { throw $e; } @@ -242,20 +265,23 @@ class DynaForm try { $arrayData = array_change_key_case($arrayData, CASE_UPPER); - //Uids - $arrayDataUid = $this->getDataUids($dynaFormUid); - - $processUid = $arrayDataUid["PRO_UID"]; - //Verify data + $process = new \BusinessModel\Process(); + + $process->throwExceptionIfNotExistsDynaForm("", $dynaFormUid, $this->arrayFieldNameForException["dynaFormUid"]); + + //Load DynaForm $dynaForm = new \Dynaform(); - if (!$dynaForm->dynaformExists($dynaFormUid)) { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($dynaFormUid, "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}"))); - } + $arrayDynaFormData = $dynaForm->Load($dynaFormUid); - if (isset($arrayData["DYN_TITLE"]) && $this->titleExists($processUid, $arrayData["DYN_TITLE"], $dynaFormUid)) { - throw (new \Exception(\G::LoadTranslation("ID_EXIST_DYNAFORM"))); + $processUid = $arrayDynaFormData["PRO_UID"]; + + //Verify data + $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, false); + + if (isset($arrayData["DYN_TITLE"])) { + $this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"], $dynaFormUid); } //Update @@ -266,7 +292,11 @@ class DynaForm //Return unset($arrayData["DYN_UID"]); - return array_change_key_case($arrayData, CASE_LOWER); + if (!$this->formatFieldNameInUppercase) { + $arrayData = array_change_key_case($arrayData, CASE_LOWER); + } + + return $arrayData; } catch (\Exception $e) { throw $e; } @@ -282,18 +312,19 @@ class DynaForm public function delete($dynaFormUid) { try { - //Uids - $arrayDataUid = $this->getDataUids($dynaFormUid); - - $processUid = $arrayDataUid["PRO_UID"]; - //Verify data + $process = new \BusinessModel\Process(); + + $process->throwExceptionIfNotExistsDynaForm("", $dynaFormUid, $this->arrayFieldNameForException["dynaFormUid"]); + + //Load DynaForm $dynaForm = new \Dynaform(); - if (!$dynaForm->dynaformExists($dynaFormUid)) { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($dynaFormUid, "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}"))); - } + $arrayDynaFormData = $dynaForm->Load($dynaFormUid); + $processUid = $arrayDynaFormData["PRO_UID"]; + + //Verify data if ($this->dynaFormAssignedStep($dynaFormUid, $processUid)) { throw (new \Exception("You cannot delete this Dynaform while it is assigned to a step")); } @@ -335,47 +366,56 @@ class DynaForm try { $arrayData = \G::array_change_key_case2($arrayData, CASE_UPPER); + unset($arrayData["DYN_UID"]); + unset($arrayData["PMTABLE"]); + //Verify data + $process = new \BusinessModel\Process(); + + $process->throwExceptionIfNoExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]); + + $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true); + + if (!isset($arrayData["COPY_IMPORT"])) { + throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("COPY_IMPORT")), "The \"{0}\" attribute is not defined"))); + } + if (!isset($arrayData["COPY_IMPORT"]["PRJ_UID"])) { - throw (new \Exception(str_replace(array("{0}"), array("PRJ_UID"), "For the creation the DynaForm, the attribute \"{0}\" doesn't exist"))); + throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("COPY_IMPORT.PRJ_UID")), "The \"{0}\" attribute is not defined"))); + } + + $arrayData["COPY_IMPORT"]["PRJ_UID"] = trim($arrayData["COPY_IMPORT"]["PRJ_UID"]); + + if ($arrayData["COPY_IMPORT"]["PRJ_UID"] == "") { + throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("COPY_IMPORT.PRJ_UID")), "The \"{0}\" attribute is empty"))); } if (!isset($arrayData["COPY_IMPORT"]["DYN_UID"])) { - throw (new \Exception(str_replace(array("{0}"), array("DYN_UID"), "For the creation the DynaForm, the attribute \"{0}\" doesn't exist"))); + throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("COPY_IMPORT.DYN_UID")), "The \"{0}\" attribute is not defined"))); } + $arrayData["COPY_IMPORT"]["DYN_UID"] = trim($arrayData["COPY_IMPORT"]["DYN_UID"]); + + if ($arrayData["COPY_IMPORT"]["DYN_UID"] == "") { + throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("COPY_IMPORT.DYN_UID")), "The \"{0}\" attribute is empty"))); + } + + $this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"]); + //Copy/Import Uids $processUidCopyImport = $arrayData["COPY_IMPORT"]["PRJ_UID"]; $dynaFormUidCopyImport = $arrayData["COPY_IMPORT"]["DYN_UID"]; - unset($arrayData["COPY_IMPORT"]); - //Verify data - $process = new \Process(); + $process->throwExceptionIfNoExistsProcess($processUidCopyImport, $this->getFieldNameByFormatFieldName("COPY_IMPORT.PRJ_UID")); - if (!$process->exists($processUid)) { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}"))); - } - - if (!$process->exists($processUidCopyImport)) { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUidCopyImport, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}"))); - } - - $dynaForm = new \Dynaform(); - - if (!$dynaForm->dynaformExists($dynaFormUidCopyImport)) { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($dynaFormUidCopyImport, "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}"))); - } - - if (!$this->dynaFormBelongsProcess($dynaFormUidCopyImport, $processUidCopyImport)) { - throw (new \Exception("The DynaForm for Copy/Import doesn't belongs to the Process")); - } + $process->throwExceptionIfNotExistsDynaForm($processUidCopyImport, $dynaFormUidCopyImport, $this->getFieldNameByFormatFieldName("COPY_IMPORT.DYN_UID")); //Copy/Import //Create $arrayData = $this->create($processUid, $arrayData); - $dynaFormUid = $arrayData["dyn_uid"]; + $dynaFormUid = $arrayData[$this->getFieldNameByFormatFieldName("DYN_UID")]; //Copy files of the DynaForm $umaskOld = umask(0); @@ -533,35 +573,100 @@ class DynaForm unset($arrayData["COPY_IMPORT"]); //Verify data + $process = new \BusinessModel\Process(); + + $process->throwExceptionIfNoExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]); + + $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true); + + if ($arrayData["DYN_TYPE"] == "grid") { + throw (new \Exception(str_replace(array("{0}"), array($this->arrayFieldNameForException["dynaFormType"]), "Invalid value specified for \"{0}\""))); + } + + if (!isset($arrayData["PMTABLE"])) { + throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("PMTABLE")), "The \"{0}\" attribute is not defined"))); + } + if (!isset($arrayData["PMTABLE"]["TAB_UID"])) { - throw (new \Exception(str_replace(array("{0}"), array("TAB_UID"), "For the creation the DynaForm, the attribute \"{0}\" doesn't exist"))); + throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("PMTABLE.TAB_UID")), "The \"{0}\" attribute is not defined"))); + } + + $arrayData["PMTABLE"]["TAB_UID"] = trim($arrayData["PMTABLE"]["TAB_UID"]); + + if ($arrayData["PMTABLE"]["TAB_UID"] == "") { + throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("PMTABLE.TAB_UID")), "The \"{0}\" attribute is empty"))); } if (!isset($arrayData["PMTABLE"]["FIELDS"])) { - throw (new \Exception(str_replace(array("{0}"), array("FIELDS"), "For the creation the DynaForm, the attribute \"{0}\" doesn't exist"))); + throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("PMTABLE.FIELDS")), "The \"{0}\" attribute is not defined"))); } if (count($arrayData["PMTABLE"]["FIELDS"]) == 0) { - throw (new \Exception(str_replace(array("{0}"), array("FIELDS"), "For the creation the DynaForm, the attribute \"{0}\" is empty"))); + throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("PMTABLE.FIELDS")), "The \"{0}\" attribute is empty"))); } - //Verify data - $process = new \Process(); + $this->throwExceptionIfExistsTitle($processUid, $arrayData["DYN_TITLE"], $this->arrayFieldNameForException["dynaFormTitle"]); - if (!$process->exists($processUid)) { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}"))); + $process->throwExceptionIfNotExistsPmTable($arrayData["PMTABLE"]["TAB_UID"], $this->getFieldNameByFormatFieldName("PMTABLE.TAB_UID")); + + //Validate PMTABLE.FIELDS + //Valid Keys + $flagValidFieldKey = 1; + + foreach ($arrayData["PMTABLE"]["FIELDS"] as $key => $value) { + if (!isset($value["FLD_NAME"]) || !isset($value["PRO_VARIABLE"])) { + $flagValidFieldKey = 0; + break; + } } - if (isset($arrayData["DYN_TITLE"]) && $this->titleExists($processUid, $arrayData["DYN_TITLE"])) { - throw (new \Exception(\G::LoadTranslation("ID_EXIST_DYNAFORM"))); + if ($flagValidFieldKey == 0) { + throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName("PMTABLE.FIELDS")), "The attribute {0}, has an element invalid (incorrect keys)"))); } - if (isset($arrayData["DYN_TYPE"]) && $arrayData["DYN_TYPE"] == "grid") { - throw (new \Exception(str_replace(array("{0}"), array("DYN_TYPE"), "For the creation the DynaForm, the attribute \"{0}\" is invalid"))); + //Is Primary Key + $arrayFieldPk = $process->getPmTablePrimaryKeyFields($arrayData["PMTABLE"]["TAB_UID"], $this->getFieldNameByFormatFieldName("PMTABLE.TAB_UID")); + $flagValidFieldPk = 1; + $invalidFieldPk = ""; + + $arrayFieldPkAux = array(); + + foreach ($arrayData["PMTABLE"]["FIELDS"] as $key => $value) { + $arrayFieldPkAux[] = $value["FLD_NAME"]; + + if (!in_array($value["FLD_NAME"], $arrayFieldPk)) { + $flagValidFieldPk = 0; + $invalidFieldPk = $value["FLD_NAME"]; + break; + } } - if (is_null(\AdditionalTablesPeer::retrieveByPK($arrayData["PMTABLE"]["TAB_UID"]))) { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayData["PMTABLE"]["TAB_UID"], "ADDITIONAL_TABLES"), "The UID \"{0}\" doesn't exist in table {1}"))); + if ($flagValidFieldPk == 0) { + throw (new \Exception(str_replace(array("{0}", "{1}"), array($this->getFieldNameByFormatFieldName("PMTABLE.FIELDS.FLD_NAME"), $invalidFieldPk), "The field {0}: {1}, is not an primary key field of the PM Table"))); + } + + //All Primary Keys + $flagAllFieldPk = 1; + $missingFieldPk = ""; + + foreach ($arrayFieldPk as $key => $value) { + if (!in_array($value, $arrayFieldPkAux)) { + $flagAllFieldPk = 0; + $missingFieldPk = $value; + break; + } + } + + if ($flagAllFieldPk == 0) { + throw (new \Exception(str_replace(array("{0}", "{1}"), array($missingFieldPk, $this->getFieldNameByFormatFieldName("PMTABLE.FIELDS")), "The primary key field {0} of the PM Table, is missing in the attribute {1}"))); + } + + //Total of Primary Keys + $n1 = count($arrayFieldPk); + $n2 = count($arrayFieldPkAux); + + if ($n1 != $n2) { + throw (new \Exception(str_replace(array("{0}", "{1}", "{2}"), array($n1, $this->getFieldNameByFormatFieldName("PMTABLE.FIELDS"), $n2), "The total primary key fields of the PM Table is {0}, the attribute {1} has {2} primary keys"))); } //Set data @@ -585,11 +690,13 @@ class DynaForm unset($arrayData["PRO_UID"]); unset($arrayData["FIELDS"]); - $arrayData = \G::array_change_key_case2($arrayData, CASE_LOWER); + $arrayData = array_merge(array("DYN_UID" => $dynaFormUid), $arrayData); - unset($arrayData["dyn_uid"]); + if (!$this->formatFieldNameInUppercase) { + $arrayData = array_change_key_case($arrayData, CASE_LOWER); + } - return array_merge(array("dyn_uid" => $dynaFormUid), $arrayData); + return $arrayData; } catch (\Exception $e) { throw $e; } @@ -606,22 +713,24 @@ class DynaForm public function defineCreate($processUid, $arrayData) { try { + $arrayData = array_change_key_case($arrayData, CASE_UPPER); + $option = "NORMAL"; //Validate data $count = 0; $msgMethod = ""; - if (isset($arrayData["copy_import"])) { + if (isset($arrayData["COPY_IMPORT"])) { $count = $count + 1; - $msgMethod = (($msgMethod != "")? ", " : "") . $msgMethod . "COPY_IMPORT"; + $msgMethod = $msgMethod . (($msgMethod != "")? ", " : "") . "COPY_IMPORT"; $option = "COPY_IMPORT"; } - if (isset($arrayData["pmtable"])) { + if (isset($arrayData["PMTABLE"])) { $count = $count + 1; - $msgMethod = (($msgMethod != "")? ", " : "") . $msgMethod . "PMTABLE"; + $msgMethod = $msgMethod . (($msgMethod != "")? ", " : "") . "PMTABLE"; $option = "PMTABLE"; } @@ -645,7 +754,7 @@ class DynaForm //Return return $arrayDataAux; } else { - throw (new \Exception(str_replace(array("{0}"), array($msgMethod), "It is trying to create a DynaForm by \"{0}\", please send only one attribute for creation"))); + throw (new \Exception(str_replace(array("{0}"), array($this->getFieldNameByFormatFieldName($msgMethod)), "It is trying to create a DynaForm by \"{0}\", please send only one attribute for creation"))); } } catch (\Exception $e) { throw $e; @@ -695,7 +804,7 @@ class DynaForm * * @param array $record Record * - * return array Return an array with data of a DynaForm + * return array Return an array with data DynaForm */ public function getDynaFormDataFromRecord($record) { @@ -711,10 +820,10 @@ class DynaForm } return array( - "dyn_uid" => $record["DYN_UID"], - "dyn_title" => $record["DYN_TITLE"], - "dyn_description" => $record["DYN_DESCRIPTION"] . "", - "dyn_type" => $record["DYN_TYPE"] . "" + $this->getFieldNameByFormatFieldName("DYN_UID") => $record["DYN_UID"], + $this->getFieldNameByFormatFieldName("DYN_TITLE") => $record["DYN_TITLE"], + $this->getFieldNameByFormatFieldName("DYN_DESCRIPTION") => $record["DYN_DESCRIPTION"] . "", + $this->getFieldNameByFormatFieldName("DYN_TYPE") => $record["DYN_TYPE"] . "" ); } catch (\Exception $e) { throw $e; @@ -732,11 +841,9 @@ class DynaForm { try { //Verify data - $dynaForm = new \Dynaform(); + $process = new \BusinessModel\Process(); - if (!$dynaForm->dynaformExists($dynaFormUid)) { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($dynaFormUid, "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}"))); - } + $process->throwExceptionIfNotExistsDynaForm("", $dynaFormUid, $this->arrayFieldNameForException["dynaFormUid"]); //Get data $criteria = $this->getDynaFormCriteria(); @@ -750,6 +857,7 @@ class DynaForm $row = $rsCriteria->getRow(); + //Return return $this->getDynaFormDataFromRecord($row); } catch (\Exception $e) { throw $e; diff --git a/workflow/engine/src/BusinessModel/Process.php b/workflow/engine/src/BusinessModel/Process.php index 92daefc17..0be89187c 100644 --- a/workflow/engine/src/BusinessModel/Process.php +++ b/workflow/engine/src/BusinessModel/Process.php @@ -4,40 +4,58 @@ namespace BusinessModel; class Process { private $arrayFieldDefinition = array( - "processUid" => array("fieldName" => "PRO_UID", "type" => "string", "required" => false, "empty" => false, "defaultValues" => array()), + "PRO_UID" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "processUid"), - "processTitle" => array("fieldName" => "PRO_TITLE", "type" => "string", "required" => true, "empty" => false, "defaultValues" => array()), - "processDescription" => array("fieldName" => "PRO_DESCRIPTION", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), - "processParent" => array("fieldName" => "PRO_PARENT", "type" => "string", "required" => true, "empty" => false, "defaultValues" => array()), - "processTime" => array("fieldName" => "PRO_TIME", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(1)), - "processTimeunit" => array("fieldName" => "PRO_TIMEUNIT", "type" => "string", "required" => false, "empty" => false, "defaultValues" => array("DAYS")), - "processStatus" => array("fieldName" => "PRO_STATUS", "type" => "string", "required" => true, "empty" => false, "defaultValues" => array("ACTIVE", "INACTIVE")), - "processTypeDay" => array("fieldName" => "PRO_TYPE_DAY", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), - "processType" => array("fieldName" => "PRO_TYPE", "type" => "string", "required" => false, "empty" => false, "defaultValues" => array("NORMAL")), - "processAssignment" => array("fieldName" => "PRO_ASSIGNMENT", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), - "processShowMap" => array("fieldName" => "PRO_SHOW_MAP", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), - "processShowMessage" => array("fieldName" => "PRO_SHOW_MESSAGE", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), - "processSubprocess" => array("fieldName" => "PRO_SUBPROCESS", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), - "processTriDeleted" => array("fieldName" => "PRO_TRI_DELETED", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), - "processTriCanceled" => array("fieldName" => "PRO_TRI_CANCELED", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), - "processTriPaused" => array("fieldName" => "PRO_TRI_PAUSED", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), - "processTriReassigned" => array("fieldName" => "PRO_TRI_REASSIGNED", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), - "processShowDelegate" => array("fieldName" => "PRO_SHOW_DELEGATE", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), - "processShowDynaform" => array("fieldName" => "PRO_SHOW_DYNAFORM", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), - "processCategory" => array("fieldName" => "PRO_CATEGORY", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), - "processSubCategory" => array("fieldName" => "PRO_SUB_CATEGORY", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), - "processIndustry" => array("fieldName" => "PRO_INDUSTRY", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0)), - "processUpdateDate" => array("fieldName" => "PRO_UPDATE_DATE", "type" => "datetime", "required" => false, "empty" => true, "defaultValues" => array()), - "processCreateDate" => array("fieldName" => "PRO_CREATE_DATE", "type" => "datetime", "required" => false, "empty" => true, "defaultValues" => array()), - "processCreateUser" => array("fieldName" => "PRO_CREATE_USER", "type" => "string", "required" => true, "empty" => true, "defaultValues" => array()), - "processDebug" => array("fieldName" => "PRO_DEBUG", "type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1)), - "processDerivationScreenTpl" => array("fieldName" => "PRO_DERIVATION_SCREEN_TPL", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), - "processSummaryDynaform" => array("fieldName" => "PRO_SUMMARY_DYNAFORM", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()), - "processCalendar" => array("fieldName" => "PRO_CALENDAR", "type" => "string", "required" => false, "empty" => true, "defaultValues" => array()) + "PRO_TITLE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "processTitle"), + "PRO_DESCRIPTION" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processDescription"), + "PRO_PARENT" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "processParent"), + "PRO_TIME" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(1), "fieldNameAux" => "processTime"), + "PRO_TIMEUNIT" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array("DAYS"), "fieldNameAux" => "processTimeunit"), + "PRO_STATUS" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("ACTIVE", "INACTIVE"), "fieldNameAux" => "processStatus"), + "PRO_TYPE_DAY" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processTypeDay"), + "PRO_TYPE" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array("NORMAL"), "fieldNameAux" => "processType"), + "PRO_ASSIGNMENT" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processAssignment"), + "PRO_SHOW_MAP" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processShowMap"), + "PRO_SHOW_MESSAGE" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processShowMessage"), + "PRO_SUBPROCESS" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processSubprocess"), + "PRO_TRI_DELETED" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processTriDeleted"), + "PRO_TRI_CANCELED" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processTriCanceled"), + "PRO_TRI_PAUSED" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processTriPaused"), + "PRO_TRI_REASSIGNED" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processTriReassigned"), + "PRO_SHOW_DELEGATE" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processShowDelegate"), + "PRO_SHOW_DYNAFORM" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processShowDynaform"), + "PRO_CATEGORY" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processCategory"), + "PRO_SUB_CATEGORY" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processSubCategory"), + "PRO_INDUSTRY" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0), "fieldNameAux" => "processIndustry"), + "PRO_UPDATE_DATE" => array("type" => "datetime", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processUpdateDate"), + "PRO_CREATE_DATE" => array("type" => "datetime", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processCreateDate"), + "PRO_CREATE_USER" => array("type" => "string", "required" => true, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processCreateUser"), + "PRO_DEBUG" => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "processDebug"), + "PRO_DERIVATION_SCREEN_TPL" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processDerivationScreenTpl"), + "PRO_SUMMARY_DYNAFORM" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processSummaryDynaform"), + "PRO_CALENDAR" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "processCalendar") ); + private $formatFieldNameInUppercase = true; + private $arrayFieldNameForException = array(); + /** + * 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; + } + } + /** * Set the format of the fields name (uppercase, lowercase) * @@ -50,9 +68,7 @@ class Process try { $this->formatFieldNameInUppercase = $flag; - foreach ($this->arrayFieldDefinition as $key => $value) { - $this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value["fieldName"]); - } + $this->setArrayFieldNameForException($this->arrayFieldNameForException); } catch (\Exception $e) { throw $e; } @@ -68,10 +84,6 @@ class Process public function setArrayFieldNameForException($arrayData) { try { - foreach ($this->arrayFieldDefinition as $key => $value) { - $this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value["fieldName"]); - } - foreach ($arrayData as $key => $value) { $this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value); } @@ -155,75 +167,58 @@ class Process try { if ($flagValidateRequired) { foreach ($arrayFieldDefinition as $key => $value) { - $fldAlias = $key; - $arrayFldDefinition = $value; + $fieldName = $key; - if ($arrayFldDefinition["required"]) { - if (!isset($arrayData[$arrayFldDefinition["fieldName"]])) { - $field = (isset($arrayFieldNameForException[$fldAlias]))? $arrayFieldNameForException[$fldAlias] : ""; + $fieldNameAux = (isset($arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]]))? $arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]] : ""; - throw (new \Exception(str_replace(array("{0}"), array($field), "The \"{0}\" attribute is not defined"))); - } + if ($arrayFieldDefinition[$fieldName]["required"] && !isset($arrayData[$fieldName])) { + throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "The \"{0}\" attribute is not defined"))); } } } - foreach ($arrayData as $key1 => $value1) { - $fieldName = $key1; - $fieldValue = $value1; + foreach ($arrayData as $key => $value) { + $fieldName = $key; + $fieldValue = $value; - foreach ($arrayFieldDefinition as $key2 => $value2) { - $fldAlias = $key2; - $arrayFldDefinition = $value2; + if (isset($arrayFieldDefinition[$fieldName])) { + $fieldNameAux = (isset($arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]]))? $arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]] : ""; - if ($arrayFldDefinition["fieldName"] == $fieldName) { - //empty - if (!$arrayFldDefinition["empty"] && trim($fieldValue) . "" == "") { - $field = (isset($arrayFieldNameForException[$fldAlias]))? $arrayFieldNameForException[$fldAlias] : ""; + //empty + if (!$arrayFieldDefinition[$fieldName]["empty"] && trim($fieldValue) . "" == "") { + throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "The \"{0}\" attribute is empty"))); + } - throw (new \Exception(str_replace(array("{0}"), array($field), "The \"{0}\" attribute is empty"))); + //defaultValues + if (count($arrayFieldDefinition[$fieldName]["defaultValues"]) > 0 && !in_array($fieldValue, $arrayFieldDefinition[$fieldName]["defaultValues"])) { + throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "Invalid value specified for \"{0}\""))); + } + + //type + if ($arrayFieldDefinition[$fieldName]["empty"] && $fieldValue . "" == "") { + // + } else { + $eregDate = "[1-9]\d{3}\-(?:0[1-9]|1[012])\-(?:[0][1-9]|[12][0-9]|3[01])"; + $eregHour = "(?:[0-1]\d|2[0-3])\:(?:[0-5]\d)\:(?:[0-5]\d)"; + $eregDatetime = $eregDate . "\s" . $eregHour; + + switch ($arrayFieldDefinition[$fieldName]["type"]) { + case "date": + if (!preg_match("/^" . $eregDate . "$/", $fieldValue)) { + throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "Invalid value specified for \"{0}\""))); + } + break; + case "hour": + if (!preg_match("/^" . $eregHour . "$/", $fieldValue)) { + throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "Invalid value specified for \"{0}\""))); + } + break; + case "datetime": + if (!preg_match("/^" . $eregDatetime . "$/", $fieldValue)) { + throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "Invalid value specified for \"{0}\""))); + } + break; } - - //defaultValues - if (count($arrayFldDefinition["defaultValues"]) > 0 && !in_array($fieldValue, $arrayFldDefinition["defaultValues"])) { - $field = (isset($arrayFieldNameForException[$fldAlias]))? $arrayFieldNameForException[$fldAlias] : ""; - - throw (new \Exception(str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\""))); - } - - //type - if ($arrayFldDefinition["empty"] && $fieldValue . "" == "") { - // - } else { - $eregDate = "[1-9]\d{3}\-(?:0[1-9]|1[012])\-(?:[0][1-9]|[12][0-9]|3[01])"; - $eregHour = "(?:[0-1]\d|2[0-3])\:(?:[0-5]\d)\:(?:[0-5]\d)"; - $eregDatetime = $eregDate . "\s" . $eregHour; - - switch ($arrayFldDefinition["type"]) { - case "date": - if (!preg_match("/^" . $eregDate . "$/", $fieldValue)) { - $field = (isset($arrayFieldNameForException[$fldAlias]))? $arrayFieldNameForException[$fldAlias] : ""; - - throw (new \Exception(str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\""))); - } - break; - case "hour": - if (!preg_match("/^" . $eregHour . "$/", $fieldValue)) { - $field = (isset($arrayFieldNameForException[$fldAlias]))? $arrayFieldNameForException[$fldAlias] : ""; - - throw (new \Exception(str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\""))); - } - break; - case "datetime": - if (!preg_match("/^" . $eregDatetime . "$/", $fieldValue)) { - $field = (isset($arrayFieldNameForException[$fldAlias]))? $arrayFieldNameForException[$fldAlias] : ""; - - throw (new \Exception(str_replace(array("{0}"), array($field), "Invalid value specified for \"{0}\""))); - } - break; - } - } - break; } } } @@ -346,6 +341,29 @@ class Process } } + /** + * Verify if doesn't exist the PM Table in table ADDITIONAL_TABLES + * + * @param string $additionalTableUid Unique id of PM Table + * @param string $fieldNameForException Field name for the exception + * + * return void Throw exception if doesn't exist the PM Table in table ADDITIONAL_TABLES + */ + public function throwExceptionIfNotExistsPmTable($additionalTableUid, $fieldNameForException) + { + try { + $obj = \AdditionalTablesPeer::retrieveByPK($additionalTableUid); + + if (!(is_object($obj) && get_class($obj) == "AdditionalTables")) { + $msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $additionalTableUid), "The PM Table with {0}: {1}, does not exist"); + + throw (new \Exception($msg)); + } + } catch (\Exception $e) { + throw $e; + } + } + /** * Verify if doesn't exist the DynaForm in table DYNAFORM * @@ -361,7 +379,11 @@ class Process $criteria = new \Criteria("workflow"); $criteria->addSelectColumn(\DynaformPeer::DYN_UID); - $criteria->add(\DynaformPeer::PRO_UID, $processUid, \Criteria::EQUAL); + + if ($processUid != "") { + $criteria->add(\DynaformPeer::PRO_UID, $processUid, \Criteria::EQUAL); + } + $criteria->add(\DynaformPeer::DYN_UID, $dynaFormUid, \Criteria::EQUAL); $rsCriteria = \DynaformPeer::doSelectRS($criteria); @@ -425,7 +447,11 @@ class Process $criteria = new \Criteria("workflow"); $criteria->addSelectColumn(\TriggersPeer::TRI_UID); - $criteria->add(\TriggersPeer::PRO_UID, $processUid, \Criteria::EQUAL); + + if ($processUid != "") { + $criteria->add(\TriggersPeer::PRO_UID, $processUid, \Criteria::EQUAL); + } + $criteria->add(\TriggersPeer::TRI_UID, $triggerUid, \Criteria::EQUAL); $rsCriteria = \TriggersPeer::doSelectRS($criteria); @@ -1321,17 +1347,15 @@ class Process public function getDynaForms($processUid) { try { - //Verify data - $process = new \Process(); - - if (!$process->exists($processUid)) { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}"))); - } - - //Get data $arrayDynaForm = array(); + //Verify data + $this->throwExceptionIfNoExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]); + + //Get data $dynaForm = new \BusinessModel\DynaForm(); + $dynaForm->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase); + $dynaForm->setArrayFieldNameForException($this->arrayFieldNameForException); $criteria = $dynaForm->getDynaFormCriteria(); @@ -1347,6 +1371,7 @@ class Process $arrayDynaForm[] = $dynaForm->getDynaFormDataFromRecord($row); } + //Return return $arrayDynaForm; } catch (\Exception $e) { throw $e; @@ -1431,5 +1456,41 @@ class Process throw $e; } } + + /** + * Get field names which are primary key in a PM Table + * + * @param string $additionalTableUid Unique id of PM Table + * @param string $fieldNameForException Field name for the exception + * + * return array Return data with the primary keys + */ + public function getPmTablePrimaryKeyFields($additionalTableUid, $fieldNameForException) + { + try { + $arrayFieldPk = array(); + + //Verify data + $this->throwExceptionIfNotExistsPmTable($additionalTableUid, $fieldNameForException); + + //Get data + //Load AdditionalTable + $additionalTable = new \AdditionalTables(); + + $arrayAdditionalTableData = $additionalTable->load($additionalTableUid, true); + + foreach ($arrayAdditionalTableData["FIELDS"] as $key => $value) { + if ($value["FLD_KEY"] == 1) { + //Primary Key + $arrayFieldPk[] = $value["FLD_NAME"]; + } + } + + //Return + return $arrayFieldPk; + } catch (\Exception $e) { + throw $e; + } + } } diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project.php b/workflow/engine/src/Services/Api/ProcessMaker/Project.php index 9266ef17c..2995b4c4f 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project.php @@ -204,14 +204,18 @@ class Project extends Api } /** - * @url GET /:projectUid/dynaforms + * @url GET /:prj_uid/dynaforms + * + * @param string $prj_uid {@min 32}{@max 32} */ - public function doGetDynaForms($projectUid) + public function doGetDynaForms($prj_uid) { try { $process = new \BusinessModel\Process(); + $process->setFormatFieldNameInUppercase(false); + $process->setArrayFieldNameForException(array("processUid" => "prj_uid")); - $response = $process->getDynaForms($projectUid); + $response = $process->getDynaForms($prj_uid); return $response; } catch (\Exception $e) { @@ -220,16 +224,16 @@ class Project extends Api } /** - * @url GET /:projectUid/input-documents + * @url GET /:prj_uid/input-documents * - * @param string $projectUid {@min 32}{@max 32} + * @param string $prj_uid {@min 32}{@max 32} */ - public function doGetInputDocuments($projectUid) + public function doGetInputDocuments($prj_uid) { try { $process = new \BusinessModel\Process(); - $response = $process->getInputDocuments($projectUid); + $response = $process->getInputDocuments($prj_uid); return $response; } catch (\Exception $e) { diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/DynaForm.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/DynaForm.php index c31608972..0a9ccce94 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project/DynaForm.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project/DynaForm.php @@ -12,14 +12,18 @@ use \Luracast\Restler\RestException; class DynaForm extends Api { /** - * @url GET /:projectUid/dynaform/:dynaFormUid + * @url GET /:prj_uid/dynaform/:dyn_uid + * + * @param string $dyn_uid {@min 32}{@max 32} + * @param string $prj_uid {@min 32}{@max 32} */ - public function doGetDynaForm($dynaFormUid, $projectUid) + public function doGetDynaForm($dyn_uid, $prj_uid) { try { $dynaForm = new \BusinessModel\DynaForm(); + $dynaForm->setFormatFieldNameInUppercase(false); - $response = $dynaForm->getDynaForm($dynaFormUid); + $response = $dynaForm->getDynaForm($dyn_uid); return $response; } catch (\Exception $e) { @@ -28,21 +32,21 @@ class DynaForm extends Api } /** - * @url POST /:projectUid/dynaform + * @url POST /:prj_uid/dynaform * - * @param string $projectUid - * @param DynaFormPostStructure $request_data + * @param string $prj_uid {@min 32}{@max 32} + * @param array $request_data * * @status 201 */ - public function doPostDynaForm($projectUid, DynaFormPostStructure $request_data = null) + public function doPostDynaForm($prj_uid, $request_data) { try { $dynaForm = new \BusinessModel\DynaForm(); + $dynaForm->setFormatFieldNameInUppercase(false); + $dynaForm->setArrayFieldNameForException(array("processUid" => "prj_uid")); - $arrayData = $dynaForm->getArrayDataFromRequestData($request_data); - - $arrayData = $dynaForm->defineCreate($projectUid, $arrayData); + $arrayData = $dynaForm->defineCreate($prj_uid, $request_data); $response = $arrayData; @@ -53,83 +57,40 @@ class DynaForm extends Api } /** - * @url PUT /:projectUid/dynaform/:dynaFormUid + * @url PUT /:prj_uid/dynaform/:dyn_uid * - * @param string $dynaFormUid - * @param string $projectUid - * @param DynaFormPutStructure $request_data + * @param string $dyn_uid {@min 32}{@max 32} + * @param string $prj_uid {@min 32}{@max 32} + * @param array $request_data */ - public function doPutDynaForm($dynaFormUid, $projectUid, DynaFormPutStructure $request_data = null) + public function doPutDynaForm($dyn_uid, $prj_uid, $request_data) { try { $dynaForm = new \BusinessModel\DynaForm(); + $dynaForm->setFormatFieldNameInUppercase(false); - $arrayData = $dynaForm->getArrayDataFromRequestData($request_data); - - $arrayData = $dynaForm->update($dynaFormUid, $arrayData); + $arrayData = $dynaForm->update($dyn_uid, $request_data); } catch (\Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } } /** - * @url DELETE /:projectUid/dynaform/:dynaFormUid + * @url DELETE /:prj_uid/dynaform/:dyn_uid + * + * @param string $dyn_uid {@min 32}{@max 32} + * @param string $prj_uid {@min 32}{@max 32} */ - public function doDeleteDynaForm($dynaFormUid, $projectUid) + public function doDeleteDynaForm($dyn_uid, $prj_uid) { try { $dynaForm = new \BusinessModel\DynaForm(); + $dynaForm->setFormatFieldNameInUppercase(false); - $dynaForm->delete($dynaFormUid); + $dynaForm->delete($dyn_uid); } catch (\Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } } } -class DynaFormPostStructure -{ - /** - * @var string {@from body}{@required true} - */ - public $dyn_title; - - /** - * @var string {@from body} - */ - public $dyn_description; - - /** - * @var string {@from body}{@choice xmlform,grid}{@required true} - */ - public $dyn_type; - - /** - * @var array {@from body}{@type associative} - */ - public $copy_import; - - /** - * @var array {@from body}{@type associative} - */ - public $pmtable; -} - -class DynaFormPutStructure -{ - /** - * @var string {@from body} - */ - public $dyn_title; - - /** - * @var string {@from body} - */ - public $dyn_description; - - /** - * @var string {@from body}{@choice xmlform,grid}{@required true} - */ - public $dyn_type; -} -