diff --git a/workflow/engine/src/BusinessModel/DynaForm.php b/workflow/engine/src/BusinessModel/DynaForm.php index 4bd341d18..ed890114b 100644 --- a/workflow/engine/src/BusinessModel/DynaForm.php +++ b/workflow/engine/src/BusinessModel/DynaForm.php @@ -181,13 +181,13 @@ class DynaForm } /** - * Verify if doesn't exist the DynaForm in table DYNAFORM + * Verify if doesn't exists the DynaForm in table DYNAFORM * * @param string $dynaFormUid Unique id of DynaForm * @param string $processUid Unique id of Process * @param string $fieldNameForException Field name for the exception * - * return void Throw exception if doesn't exist the DynaForm in table DYNAFORM + * return void Throw exception if doesn't exists the DynaForm in table DYNAFORM */ public function throwExceptionIfNotExistsDynaForm($dynaFormUid, $processUid, $fieldNameForException) { diff --git a/workflow/engine/src/BusinessModel/Group.php b/workflow/engine/src/BusinessModel/Group.php index f335d6e23..f0a4eb67f 100644 --- a/workflow/engine/src/BusinessModel/Group.php +++ b/workflow/engine/src/BusinessModel/Group.php @@ -130,12 +130,12 @@ class Group } /** - * Verify if doesn't exist the Group in table GROUP + * Verify if doesn't exists the Group in table GROUP * * @param string $groupUid Unique id of Group * @param string $fieldNameForException Field name for the exception * - * return void Throw exception if doesn't exist the Group in table GROUP + * return void Throw exception if doesn't exists the Group in table GROUP */ public function throwExceptionIfNoExistsGroup($groupUid, $fieldNameForException) { diff --git a/workflow/engine/src/BusinessModel/InputDocument.php b/workflow/engine/src/BusinessModel/InputDocument.php index b7677e79e..820b11ac4 100644 --- a/workflow/engine/src/BusinessModel/InputDocument.php +++ b/workflow/engine/src/BusinessModel/InputDocument.php @@ -137,13 +137,13 @@ class InputDocument } /** - * Verify if doesn't exist the InputDocument in table INPUT_DOCUMENT + * Verify if doesn't exists the InputDocument in table INPUT_DOCUMENT * * @param string $inputDocumentUid Unique id of InputDocument * @param string $processUid Unique id of Process * @param string $fieldNameForException Field name for the exception * - * return void Throw exception if doesn't exist the InputDocument in table INPUT_DOCUMENT + * return void Throw exception if doesn't exists the InputDocument in table INPUT_DOCUMENT */ public function throwExceptionIfNotExistsInputDocument($inputDocumentUid, $processUid, $fieldNameForException) { diff --git a/workflow/engine/src/BusinessModel/Process.php b/workflow/engine/src/BusinessModel/Process.php index 88bedf8e1..dfbfb785d 100644 --- a/workflow/engine/src/BusinessModel/Process.php +++ b/workflow/engine/src/BusinessModel/Process.php @@ -252,12 +252,12 @@ class Process } /** - * Verify if doesn't exist the Process in table PROCESS + * Verify if doesn't exists the Process in table PROCESS * * @param string $processUid Unique id of Process * @param string $fieldNameForException Field name for the exception * - * return void Throw exception if doesn't exist the Process in table PROCESS + * return void Throw exception if doesn't exists the Process in table PROCESS */ public function throwExceptionIfNoExistsProcess($processUid, $fieldNameForException) { @@ -275,12 +275,12 @@ class Process } /** - * Verify if doesn't exist the User in table USERS + * Verify if doesn't exists the User in table USERS * * @param string $userUid Unique id of User * @param string $fieldNameForException Field name for the exception * - * return void Throw exception if doesn't exist the User in table USERS + * return void Throw exception if doesn't exists the User in table USERS */ public function throwExceptionIfNoExistsUser($userUid, $fieldNameForException) { @@ -320,12 +320,12 @@ class Process } /** - * Verify if doesn't exist the Calendar Definition in table CALENDAR_DEFINITION + * Verify if doesn't exists the Calendar Definition in table CALENDAR_DEFINITION * * @param string $calendarDefinitionUid Unique id of Calendar Definition * @param string $fieldNameForException Field name for the exception * - * return void Throw exception if doesn't exist the Calendar Definition in table CALENDAR_DEFINITION + * return void Throw exception if doesn't exists the Calendar Definition in table CALENDAR_DEFINITION */ public function throwExceptionIfNotExistsCalendarDefinition($calendarDefinitionUid, $fieldNameForException) { @@ -343,12 +343,12 @@ class Process } /** - * Verify if doesn't exist the Process Category in table PROCESS_CATEGORY + * Verify if doesn't exists the Process Category in table PROCESS_CATEGORY * * @param string $processCategoryUid Unique id of Process Category * @param string $fieldNameForException Field name for the exception * - * return void Throw exception if doesn't exist the Process Category in table PROCESS_CATEGORY + * return void Throw exception if doesn't exists the Process Category in table PROCESS_CATEGORY */ public function throwExceptionIfNotExistsProcessCategory($processCategoryUid, $fieldNameForException) { @@ -366,12 +366,12 @@ class Process } /** - * Verify if doesn't exist the PM Table in table ADDITIONAL_TABLES + * Verify if doesn't exists 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 + * return void Throw exception if doesn't exists the PM Table in table ADDITIONAL_TABLES */ public function throwExceptionIfNotExistsPmTable($additionalTableUid, $fieldNameForException) { @@ -389,13 +389,13 @@ class Process } /** - * Verify if doesn't exist the Task in table TASK + * Verify if doesn't exists the Task in table TASK * * @param string $processUid Unique id of Process * @param string $taskUid Unique id of Task * @param string $fieldNameForException Field name for the exception * - * return void Throw exception if doesn't exist the Task in table TASK + * return void Throw exception if doesn't exists the Task in table TASK */ public function throwExceptionIfNotExistsTask($processUid, $taskUid, $fieldNameForException) { @@ -423,13 +423,13 @@ class Process } /** - * Verify if doesn't exist the Template in Routing Screen Template + * Verify if doesn't exists the Template in Routing Screen Template * * @param string $processUid Unique id of Process * @param string $fileName Name template * @param string $fieldNameForException Field name for the exception * - * return void Throw exception if doesn't exist the Template in Routing Screen Template + * return void Throw exception if doesn't exists the Template in Routing Screen Template */ public function throwExceptionIfNotExistsRoutingScreenTemplate($processUid, $fileName, $fieldNameForException) { @@ -456,40 +456,6 @@ class Process } } - /** - * Verify if doesn't exist the Trigger in table TRIGGERS - * - * @param string $processUid Unique id of Process - * @param string $triggerUid Unique id of Trigger - * @param string $fieldNameForException Field name for the exception - * - * return void Throw exception if doesn't exist the Trigger in table TRIGGERS - */ - public function throwExceptionIfNotExistsTrigger($processUid, $triggerUid, $fieldNameForException) - { - try { - $criteria = new \Criteria("workflow"); - - $criteria->addSelectColumn(\TriggersPeer::TRI_UID); - - if ($processUid != "") { - $criteria->add(\TriggersPeer::PRO_UID, $processUid, \Criteria::EQUAL); - } - - $criteria->add(\TriggersPeer::TRI_UID, $triggerUid, \Criteria::EQUAL); - - $rsCriteria = \TriggersPeer::doSelectRS($criteria); - - if (!$rsCriteria->next()) { - $msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $triggerUid), "The trigger with {0}: {1}, does not exist"); - - throw (new \Exception($msg)); - } - } catch (\Exception $e) { - throw $e; - } - } - /** * Update Process * @@ -530,20 +496,22 @@ class Process $this->throwExceptionIfNotExistsRoutingScreenTemplate($processUid, $arrayData["PRO_DERIVATION_SCREEN_TPL"], $this->arrayFieldNameForException["processDerivationScreenTpl"]); } + $trigger = new \BusinessModel\Trigger(); + if (isset($arrayData["PRO_TRI_DELETED"]) && $arrayData["PRO_TRI_DELETED"] . "" != "") { - $this->throwExceptionIfNotExistsTrigger($processUid, $arrayData["PRO_TRI_DELETED"], $this->arrayFieldNameForException["processTriDeleted"]); + $trigger->throwExceptionIfNotExistsTrigger($arrayData["PRO_TRI_DELETED"], $processUid, $this->arrayFieldNameForException["processTriDeleted"]); } if (isset($arrayData["PRO_TRI_CANCELED"]) && $arrayData["PRO_TRI_CANCELED"] . "" != "") { - $this->throwExceptionIfNotExistsTrigger($processUid, $arrayData["PRO_TRI_CANCELED"], $this->arrayFieldNameForException["processTriCanceled"]); + $trigger->throwExceptionIfNotExistsTrigger($arrayData["PRO_TRI_CANCELED"], $processUid, $this->arrayFieldNameForException["processTriCanceled"]); } if (isset($arrayData["PRO_TRI_PAUSED"]) && $arrayData["PRO_TRI_PAUSED"] . "" != "") { - $this->throwExceptionIfNotExistsTrigger($processUid, $arrayData["PRO_TRI_PAUSED"], $this->arrayFieldNameForException["processTriPaused"]); + $trigger->throwExceptionIfNotExistsTrigger($arrayData["PRO_TRI_PAUSED"], $processUid, $this->arrayFieldNameForException["processTriPaused"]); } if (isset($arrayData["PRO_TRI_REASSIGNED"]) && $arrayData["PRO_TRI_REASSIGNED"] . "" != "") { - $this->throwExceptionIfNotExistsTrigger($processUid, $arrayData["PRO_TRI_REASSIGNED"], $this->arrayFieldNameForException["processTriReassigned"]); + $trigger->throwExceptionIfNotExistsTrigger($arrayData["PRO_TRI_REASSIGNED"], $processUid, $this->arrayFieldNameForException["processTriReassigned"]); } if (isset($arrayData["PRO_PARENT"])) { @@ -1615,5 +1583,43 @@ class Process throw $e; } } + + /** + * Get all Libraries + * + * @param string $processUid Unique id of Process + * + * return array Return an array with all Libraries + */ + public function getLibraries($processUid) + { + try { + $arrayLibrary = array(); + + //Verify data + $this->throwExceptionIfNoExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]); + + //Get data + \G::LoadClass("triggerLibrary"); + + $triggerWizard = new \BusinessModel\TriggerWizard(); + $triggerWizard->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase); + $triggerWizard->setArrayFieldNameForException($this->arrayFieldNameForException); + + $triggerLibrary = \triggerLibrary::getSingleton(); + $library = $triggerLibrary->getRegisteredClasses(); + + foreach ($library as $key => $value) { + $libraryName = (preg_match("/^class\.?(.*)\.pmFunctions\.php$/", $key, $arrayMatch))? ((isset($arrayMatch[1]) && $arrayMatch[1] != "")? $arrayMatch[1] : "pmFunctions") : $key; + + $arrayLibrary[] = $triggerWizard->getLibrary($libraryName); + } + + //Return + return $arrayLibrary; + } catch (\Exception $e) { + throw $e; + } + } } diff --git a/workflow/engine/src/BusinessModel/Trigger.php b/workflow/engine/src/BusinessModel/Trigger.php index 6f8cc98c2..c8b884c67 100644 --- a/workflow/engine/src/BusinessModel/Trigger.php +++ b/workflow/engine/src/BusinessModel/Trigger.php @@ -211,5 +211,62 @@ class Trigger } return true; } + + /** + * Verify if doesn't exists the Trigger in table TRIGGERS + * + * @param string $triggerUid Unique id of Trigger + * @param string $processUid Unique id of Process + * @param string $fieldNameForException Field name for the exception + * + * return void Throw exception if doesn't exists the Trigger in table TRIGGERS + */ + public function throwExceptionIfNotExistsTrigger($triggerUid, $processUid, $fieldNameForException) + { + try { + $criteria = new \Criteria("workflow"); + + $criteria->addSelectColumn(\TriggersPeer::TRI_UID); + + if ($processUid != "") { + $criteria->add(\TriggersPeer::PRO_UID, $processUid, \Criteria::EQUAL); + } + + $criteria->add(\TriggersPeer::TRI_UID, $triggerUid, \Criteria::EQUAL); + + $rsCriteria = \TriggersPeer::doSelectRS($criteria); + + if (!$rsCriteria->next()) { + $msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $triggerUid), "The trigger with {0}: {1}, does not exist"); + + throw (new \Exception($msg)); + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Verify if exists the title of a Trigger + * + * @param string $processUid Unique id of Process + * @param string $triggerTitle Title + * @param string $fieldNameForException Field name for the exception + * @param string $triggerUidExclude Unique id of Trigger to exclude + * + * return void Throw exception if exists the title of a Trigger + */ + public function throwExceptionIfExistsTitle($processUid, $triggerTitle, $fieldNameForException, $triggerUidExclude = "") + { + try { + if ($this->verifyNameTrigger($processUid, $triggerTitle, $triggerUidExclude)) { + $msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $triggerTitle), "The trigger title with {0}: \"{1}\", already exists"); + + throw (new \Exception($msg)); + } + } catch (\Exception $e) { + throw $e; + } + } } diff --git a/workflow/engine/src/BusinessModel/TriggerWizard.php b/workflow/engine/src/BusinessModel/TriggerWizard.php new file mode 100644 index 000000000..ca44a6ecc --- /dev/null +++ b/workflow/engine/src/BusinessModel/TriggerWizard.php @@ -0,0 +1,502 @@ + array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "triggerUid"), + + "TRI_TITLE" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "triggerTitle"), + "TRI_DESCRIPTION" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "triggerDescription"), + "TRI_TYPE" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array("SCRIPT"), "fieldNameAux" => "triggerType"), + "TRI_WEBBOT" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "triggerWebbot"), + "TRI_PARAM" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "triggerParam") + ); + + private $formatFieldNameInUppercase = true; + + private $arrayFieldNameForException = array( + "processUid" => "PRO_UID", + "libraryName" => "LIB_NAME", + "methodName" => "MTH_NAME" + ); + + private $library; + + /** + * Constructor of the class + * + * return void + */ + public function __construct() + { + try { + foreach ($this->arrayFieldDefinition as $key => $value) { + $this->arrayFieldNameForException[$value["fieldNameAux"]] = $key; + } + + //Library + \G::LoadClass("triggerLibrary"); + + $this->library = \triggerLibrary::getSingleton(); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Set the format of the fields name (uppercase, lowercase) + * + * @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 doesn't exists the name of the library + * + * @param string $libraryName Library name + * @param string $libraryFieldNameForException Field name for the exception + * + * return void Throw exception if doesn't exists the name of the library + */ + public function throwExceptionIfNotExistsLibrary($libraryName, $libraryFieldNameForException) + { + try { + $arrayLibrary = $this->library->getRegisteredClasses(); + + if (!isset($arrayLibrary[$this->libraryGetLibraryName($libraryName)])) { + $msg = str_replace(array("{0}", "{1}"), array($libraryFieldNameForException, $libraryName), "The library with {0}: \"{1}\", does not exist"); + + throw (new \Exception($msg)); + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Verify if doesn't exists the method in the library + * + * @param string $libraryName Library name + * @param string $methodName Method name + * @param string $libraryFieldNameForException Field name for the exception + * @param string $methodFieldNameForException Field name for the exception + * + * return void Throw exception if doesn't exists the method in the library + */ + public function throwExceptionIfNotExistsMethodInLibrary($libraryName, $methodName, $libraryFieldNameForException, $methodFieldNameForException) + { + try { + $this->throwExceptionIfNotExistsLibrary($libraryName, $libraryFieldNameForException); + + $library = $this->library->getLibraryDefinition($this->libraryGetLibraryName($libraryName)); + + if (!isset($library->methods[$methodName])) { + $msg = str_replace(array("{0}", "{1}"), array($methodFieldNameForException, $methodName), "The method with {0}: \"{1}\", does not exist in library"); + + throw (new \Exception($msg)); + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * + */ + public function throwExceptionIfLibraryAndMethodIsInvalidForTrigger($libraryName, $methodName, $triggerUid, $libraryFieldNameForException, $methodFieldNameForException, $triggerUidFieldNameForException) + { + try { + //Verify data + $this->throwExceptionIfNotExistsMethodInLibrary($libraryName, $methodName, $libraryFieldNameForException, $methodFieldNameForException); + + $trigger = new \BusinessModel\Trigger(); + + $trigger->throwExceptionIfNotExistsTrigger($triggerUid, "", $triggerUidFieldNameForException); + + //Get data + $trigger = new \Triggers(); + + $arrayTriggerData = $trigger->load($triggerUid); + + $triggerParam = unserialize($arrayTriggerData["TRI_PARAM"]); + + if ($arrayTriggerData["TRI_PARAM"] == "" || !isset($triggerParam["hash"])) { + $msg = str_replace(array("{0}", "{1}"), array($triggerUidFieldNameForException, $triggerUid), "The trigger with {0}: {1}, does not been created with the wizard"); + + throw (new \Exception($msg)); + } + + $arrayTriggerData["TRI_PARAM"] = $triggerParam; + + if (md5($arrayTriggerData["TRI_WEBBOT"]) != $arrayTriggerData["TRI_PARAM"]["hash"]) { + $msg = str_replace(array("{0}", "{1}"), array($triggerUidFieldNameForException, $triggerUid), "The trigger with {0}: {1}, has been modified manually, is invalid for the wizard"); + + throw (new \Exception($msg)); + } + + //PMFUNTION_NAME //createZimbraContacts + //LIBRARY_CLASS //class.pmZimbra.pmFunctions.php + + //VALIDATION - El wizard xxx con el metodo yyy, es invalido para el trigger ttttt + + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get the filename of the library + * + * @param string $libraryName Library name + * + * return string Return the filename of the library + */ + public function libraryGetLibraryName($libraryName) + { + try { + if (!preg_match("/\.pmFunctions\.php$/", $libraryName)) { + $libraryName = ($libraryName != "pmFunctions")? $libraryName . ".pmFunctions" : $libraryName; + $libraryName = "class." . $libraryName . ".php"; + } + + return $libraryName; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get all parameters of a method + * + * @param string $libraryName Library name + * @param string $methodName Method name + * + * return array Return an array with all parameters of a method + */ + public function methodGetParams($libraryName, $methodName) + { + try { + $arrayParam = array(); + + //Verify data + $this->throwExceptionIfNotExistsMethodInLibrary($libraryName, $methodName, $this->arrayFieldNameForException["libraryName"], $this->arrayFieldNameForException["methodName"]); + + //Get data + $library = $this->library->getLibraryDefinition($this->libraryGetLibraryName($libraryName)); + $method = $library->methods[$methodName]; + + $arrayParameter = array_keys($method->params); + + foreach ($arrayParameter as $key => $value) { + $strParam = $value; + + if ($strParam != "") { + $arrayp = explode("|", $strParam); + + //Get param + $arrayTypeAndMaxLength = array(); + + if (preg_match("/^\s*(.+)\s*[\{\[\(]\s*(\d+)\s*[\)\]\}].*$/", $arrayp[0], $arrayMatch)) { + $arrayTypeAndMaxLength = array("type" => $arrayMatch[1], "maxLength" => (int)($arrayMatch[2])); + } else { + $arrayTypeAndMaxLength = array("type" => trim($arrayp[0])); + } + + $arrayNameAndDefaultValue = array(); + + $arrayNameAndDefaultValue["name"] = ""; + + if (preg_match("/^\s*\\\$(\w+)(.*)$/", $arrayp[1], $arrayMatch)) { + $arrayNameAndDefaultValue["name"] = $arrayMatch[1]; + + $arrayp[1] = $arrayMatch[2]; + } + + if (preg_match("/^\s*=\s*(.*)$/", $arrayp[1], $arrayMatch)) { + $arrayNameAndDefaultValue["defaultValue"] = trim(trim($arrayMatch[1]), "\"'"); + } + + //Set param + $arrayData = array( + "name" => $arrayNameAndDefaultValue["name"], + "type" => $arrayTypeAndMaxLength["type"], + "label" => (isset($arrayp[2]))? trim($arrayp[2]) : $arrayNameAndDefaultValue["name"], + "description" => (isset($arrayp[3]))? trim($arrayp[3]) : "", + "required" => !isset($arrayNameAndDefaultValue["defaultValue"]) + ); + + if (isset($arrayNameAndDefaultValue["defaultValue"])) { + $arrayData["default_value"] = $arrayNameAndDefaultValue["defaultValue"]; + } + + if (isset($arrayTypeAndMaxLength["maxLength"])) { + $arrayData["max_length"] = $arrayTypeAndMaxLength["maxLength"]; + } + + $arrayParam[] = $arrayData; + } + } + + //Return + return $arrayParam; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get all parameters return of a method + * + * @param string $libraryName Library name + * @param string $methodName Method name + * + * return array Return an array with all parameters return of a method + */ + public function methodGetParamsReturn($libraryName, $methodName) + { + try { + $arrayParam = array(); + + //Verify data + $this->throwExceptionIfNotExistsMethodInLibrary($libraryName, $methodName, $this->arrayFieldNameForException["libraryName"], $this->arrayFieldNameForException["methodName"]); + + //Get data + $library = $this->library->getLibraryDefinition($this->libraryGetLibraryName($libraryName)); + $method = $library->methods[$methodName]; + + if (isset($method->info["return"]) && $method->info["return"] != "") { + $strParam = $method->info["return"]; + + $arrayp = explode("|", $strParam); + + if (isset($arrayp[0]) && isset($arrayp[1]) && trim(strtoupper($arrayp[0])) != strtoupper(\G::LoadTranslation("ID_NONE"))) { + $description = ""; + + if (isset($arrayp[3])) { + $description = (trim(strtoupper($arrayp[3])) == strtoupper(\G::LoadTranslation("ID_NONE")))? \G::LoadTranslation("ID_NOT_REQUIRED") : trim($arrayp[3]); + } else { + $description = $strParam; + } + + //Set param + $arrayParam[] = array( + "name" => "tri_answer", + "type" => trim($arrayp[0]), + "label" => \G::LoadTranslation("ID_TRIGGER_RETURN_LABEL"), + "description" => $description, + "required" => isset($arrayp[1]) //(trim($arrayp[1]) != "")? true : false + ); + } + } + + //Return + return $arrayParam; + } catch (\Exception $e) { + throw $e; + } + } + + ///** + // * + // */ + //public function create() + //{ + // try { + // // + // } catch (\Exception $e) { + // throw $e; + // } + //} + + ///** + // * + // */ + //public function update() + //{ + // try { + // // + // } catch (\Exception $e) { + // throw $e; + // } + //} + + /** + * Get Method of the Library + * + * @param string $libraryName Library name + * @param string $methodName Method name + * + * return array Return an array with the Method of the Library + */ + public function getMethod($libraryName, $methodName) + { + try { + $arrayMethod = array(); + + //Verify data + $arrayMethodParam = $this->methodGetParams($libraryName, $methodName); + $arrayMethodParamReturn = $this->methodGetParamsReturn($libraryName, $methodName); + + //Get data + $library = $this->library->getLibraryDefinition($this->libraryGetLibraryName($libraryName)); + $method = $library->methods[$methodName]; + + $arrayMethod[$this->getFieldNameByFormatFieldName("FN_NAME")] = $method->info["name"]; + $arrayMethod[$this->getFieldNameByFormatFieldName("FN_DESCRIPTION")] = trim(str_replace("*", "", implode("", $method->info["description"]))); + $arrayMethod[$this->getFieldNameByFormatFieldName("FN_LABEL")] = $method->info["label"]; + $arrayMethod[$this->getFieldNameByFormatFieldName("FN_LINK")] = (isset($method->info["link"]) && ($method->info["link"] != ""))? $method->info["link"] : ""; + + if ($this->formatFieldNameInUppercase) { + $arrayMethodParam = \G::array_change_key_case2($arrayMethodParam, CASE_UPPER); + $arrayMethodParamReturn = \G::array_change_key_case2($arrayMethodParamReturn, CASE_UPPER); + } + + $arrayMethod[$this->getFieldNameByFormatFieldName("FN_PARAMS")][$this->getFieldNameByFormatFieldName("INPUT")] = $arrayMethodParam; + $arrayMethod[$this->getFieldNameByFormatFieldName("FN_PARAMS")][$this->getFieldNameByFormatFieldName("OUTPUT")] = $arrayMethodParamReturn; + + //Return + return $arrayMethod; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get Library + * + * @param string $libraryName Library name + * + * return array Return an array with the Library + */ + public function getLibrary($libraryName) + { + try { + $arrayLibrary = array(); + + //Verify data + $this->throwExceptionIfNotExistsLibrary($libraryName, $this->arrayFieldNameForException["libraryName"]); + + //Get data + $library = $this->library->getLibraryDefinition($this->libraryGetLibraryName($libraryName)); + + $arrayLibrary[$this->getFieldNameByFormatFieldName("LIB_NAME")] = $libraryName; + $arrayLibrary[$this->getFieldNameByFormatFieldName("LIB_TITLE")] = trim($library->info["name"]); + $arrayLibrary[$this->getFieldNameByFormatFieldName("LIB_DESCRIPTION")] = trim(str_replace("*", "", implode("", $library->info["description"]))); + $arrayLibrary[$this->getFieldNameByFormatFieldName("LIB_ICON")] = (isset($library->info["icon"]) && trim($library->info["icon"]) != "")? trim($library->info["icon"]) : "/images/browse.gif"; + $arrayLibrary[$this->getFieldNameByFormatFieldName("LIB_CLASS_NAME")] = trim($library->info["className"]); + + $arrayMethod = array(); + + if (count($library->methods) > 0) { + ksort($library->methods, SORT_STRING); + + foreach ($library->methods as $key => $value) { + $methodName = $key; + + $arrayMethod[] = $this->getMethod($libraryName, $methodName); + } + } + + $arrayLibrary[$this->getFieldNameByFormatFieldName("LIB_FUNCTIONS")] = $arrayMethod; + + //Return + return $arrayLibrary; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get data of a Trigger + * + * @param string $libraryName Library name + * @param string $methodName Method name + * @param string $triggerUid Unique id of Trigger + * + * return array Return an array with data of a Trigger + */ + public function getTrigger($libraryName, $methodName, $triggerUid) + { + try { + //Verify data + $this->throwExceptionIfLibraryAndMethodIsInvalidForTrigger($libraryName, $methodName, $triggerUid, $this->arrayFieldNameForException["libraryName"], $this->arrayFieldNameForException["methodName"], $this->arrayFieldNameForException["triggerUid"]); + + //Get data + $trigger = new \Triggers(); + + $arrayTriggerData = $trigger->load($triggerUid); + + $arrayTriggerData["TRI_PARAM"] = unserialize($arrayTriggerData["TRI_PARAM"]); + + //PMFUNTION_NAME //createZimbraContacts + //LIBRARY_CLASS //class.pmZimbra.pmFunctions.php + + $arrayMethodParam = $this->methodGetParams($libraryName, $methodName); + $arrayMethodParamReturn = $this->methodGetParamsReturn($libraryName, $methodName); + + ////////////////// + //create atributtes!!!!!! + ////////////////// + + //Return + unset($arrayTriggerData["PRO_UID"]); + unset($arrayTriggerData["TRI_WEBBOT"]); + unset($arrayTriggerData["TRI_PARAM"]); + + if (!$this->formatFieldNameInUppercase) { + $arrayTriggerData = array_change_key_case($arrayTriggerData, CASE_LOWER); + } + + return $arrayTriggerData; + } 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 fc7e574a0..d7850c527 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project.php @@ -419,6 +419,7 @@ 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 doGetGridVariables($prj_uid, $grid_uid = "") { @@ -434,5 +435,25 @@ class Project extends Api throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } } + + /** + * @url GET /:prj_uid/trigger-wizards + * + * @param string $prj_uid {@min 32}{@max 32} + */ + public function doGetTriggerWizards($prj_uid) + { + try { + $process = new \BusinessModel\Process(); + $process->setFormatFieldNameInUppercase(false); + $process->setArrayFieldNameForException(array("processUid" => "prj_uid", "libraryName" => "lib_name", "methodName" => "fn_name")); + + $response = $process->getLibraries($prj_uid); + + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } } diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/TriggerWizard.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/TriggerWizard.php new file mode 100644 index 000000000..9efd2b518 --- /dev/null +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project/TriggerWizard.php @@ -0,0 +1,93 @@ +setFormatFieldNameInUppercase(false); + $triggerWizard->setArrayFieldNameForException(array("processUid" => "prj_uid", "libraryName" => "lib_name", "methodName" => "fn_name")); + + $response = ($fn_name == "")? $triggerWizard->getLibrary($lib_name) : $triggerWizard->getMethod($lib_name, $fn_name); + + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * @url GET /:prj_uid/trigger-wizard/:lib_name/:fn_name/:tri_uid + * + * @param string $prj_uid {@min 32}{@max 32} + * @param string $lib_name + * @param string $fn_name + * @param string $tri_uid {@min 32}{@max 32} + */ + public function doGetTriggerWizardTrigger($prj_uid, $lib_name, $fn_name, $tri_uid) + { + try { + $triggerWizard = new \BusinessModel\TriggerWizard(); + $triggerWizard->setFormatFieldNameInUppercase(false); + $triggerWizard->setArrayFieldNameForException(array("processUid" => "prj_uid", "libraryName" => "lib_name", "methodName" => "fn_name")); + + $response = $triggerWizard->getTrigger($lib_name, $fn_name, $tri_uid); + + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + ///** + // * @url POST /:prj_uid/dynaform + // * + // * @param string $prj_uid {@min 32}{@max 32} + // * @param array $request_data + // * + // * @status 201 + // */ + //public function doPostDynaForm($prj_uid, $request_data) + //{ + // try { + // return $response; + // } catch (\Exception $e) { + // throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + // } + //} + // + ///** + // * @url PUT /:prj_uid/dynaform/:dyn_uid + // * + // * @param string $dyn_uid {@min 32}{@max 32} + // * @param string $prj_uid {@min 32}{@max 32} + // * @param array $request_data + // */ + //public function doPutDynaForm($dyn_uid, $prj_uid, $request_data) + //{ + // try { + // // + // } catch (\Exception $e) { + // throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + // } + //} +} + diff --git a/workflow/engine/src/Services/api.ini b/workflow/engine/src/Services/api.ini index d1ba6170d..73371e62b 100644 --- a/workflow/engine/src/Services/api.ini +++ b/workflow/engine/src/Services/api.ini @@ -34,6 +34,7 @@ debug = 1 files-manager = "Services\Api\ProcessMaker\Project\FilesManager" report-Table = "Services\Api\ProcessMaker\Project\ReportTable" sub-process= "Services\Api\ProcessMaker\Project\SubProcess" + trigger-wizard = "Services\Api\ProcessMaker\Project\TriggerWizard" [alias: projects] project = "Services\Api\ProcessMaker\Project"