ProcessMaker-MA "Trigger Wizard (endpoints)"

- Se han implementado los siguientes Endpoints:
    GET  /api/1.0/{workspace}/project/{prj_uid}/trigger-wizard/{lib_name}/{fn_name}/{tri_uid}
    POST /api/1.0/{workspace}/project/{prj_uid}/trigger-wizard/{lib_name}/{fn_name}
    PUT  /api/1.0/{workspace}/project/{prj_uid}/trigger-wizard/{lib_name}/{fn_name}/{tri_uid}
This commit is contained in:
Victor Saisa Lopez
2014-02-26 11:58:56 -04:00
parent 262ae332d3
commit c25a13ba11
4 changed files with 610 additions and 120 deletions

View File

@@ -178,6 +178,9 @@ class Process
}
}
$arrayType1 = array("int", "integer", "float", "real", "double", "bool", "boolean", "string", "date", "hour", "datetime");
$arrayType2 = array("array", "object");
foreach ($arrayData as $key => $value) {
$fieldName = $key;
$fieldValue = $value;
@@ -185,41 +188,63 @@ class Process
if (isset($arrayFieldDefinition[$fieldName])) {
$fieldNameAux = (isset($arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]]))? $arrayFieldNameForException[$arrayFieldDefinition[$fieldName]["fieldNameAux"]] : "";
//empty
if (!$arrayFieldDefinition[$fieldName]["empty"] && trim($fieldValue) . "" == "") {
throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "The \"{0}\" attribute is empty")));
}
$arrayFieldDefinition[$fieldName]["type"] = strtolower($arrayFieldDefinition[$fieldName]["type"]);
//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}\"")));
}
$optionType = 0;
$optionType = ($optionType == 0 && in_array($arrayFieldDefinition[$fieldName]["type"], $arrayType1))? 1 : $optionType;
$optionType = ($optionType == 0 && in_array($arrayFieldDefinition[$fieldName]["type"], $arrayType2))? 2 : $optionType;
//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 ($optionType) {
case 1:
//empty
if (!$arrayFieldDefinition[$fieldName]["empty"] && trim($fieldValue) . "" == "") {
throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "The \"{0}\" attribute is empty")));
}
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}\"")));
//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;
}
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;
}
}
break;
case 2:
//type
switch ($arrayFieldDefinition[$fieldName]["type"]) {
case "array":
if (!is_array($fieldValue)) {
if (!preg_match("/^\s*array\s*\(.*\)\s*$/", $fieldValue)) {
throw (new \Exception(str_replace(array("{0}"), array($fieldNameAux), "The \"{0}\" attribute is not array")));
}
}
break;
}
break;
}
}
}

View File

@@ -259,7 +259,7 @@ class Trigger
public function throwExceptionIfExistsTitle($processUid, $triggerTitle, $fieldNameForException, $triggerUidExclude = "")
{
try {
if ($this->verifyNameTrigger($processUid, $triggerTitle, $triggerUidExclude)) {
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));

File diff suppressed because it is too large Load Diff

View File

@@ -11,6 +11,14 @@ use \Luracast\Restler\RestException;
*/
class TriggerWizard extends Api
{
private $formatFieldNameInUppercase = false;
private $arrayFieldNameForException = array(
"processUid" => "prj_uid",
"libraryName" => "lib_name",
"methodName" => "fn_name"
);
/**
* @url GET /:prj_uid/trigger-wizard/:lib_name
* @url GET /:prj_uid/trigger-wizard/:lib_name/:fn_name
@@ -23,8 +31,8 @@ class TriggerWizard extends Api
{
try {
$triggerWizard = new \BusinessModel\TriggerWizard();
$triggerWizard->setFormatFieldNameInUppercase(false);
$triggerWizard->setArrayFieldNameForException(array("processUid" => "prj_uid", "libraryName" => "lib_name", "methodName" => "fn_name"));
$triggerWizard->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
$triggerWizard->setArrayFieldNameForException($this->arrayFieldNameForException);
$response = ($fn_name == "")? $triggerWizard->getLibrary($lib_name) : $triggerWizard->getMethod($lib_name, $fn_name);
@@ -46,8 +54,8 @@ class TriggerWizard extends Api
{
try {
$triggerWizard = new \BusinessModel\TriggerWizard();
$triggerWizard->setFormatFieldNameInUppercase(false);
$triggerWizard->setArrayFieldNameForException(array("processUid" => "prj_uid", "libraryName" => "lib_name", "methodName" => "fn_name"));
$triggerWizard->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
$triggerWizard->setArrayFieldNameForException($this->arrayFieldNameForException);
$response = $triggerWizard->getTrigger($lib_name, $fn_name, $tri_uid);
@@ -57,37 +65,53 @@ class TriggerWizard extends Api
}
}
///**
// * @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()));
// }
//}
/**
* @url POST /:prj_uid/trigger-wizard/:lib_name/:fn_name
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $lib_name
* @param string $fn_name
* @param array $request_data
*
* @status 201
*/
public function doPostTriggerWizard($prj_uid, $lib_name, $fn_name, $request_data)
{
try {
$triggerWizard = new \BusinessModel\TriggerWizard();
$triggerWizard->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
$triggerWizard->setArrayFieldNameForException($this->arrayFieldNameForException);
$arrayData = $triggerWizard->create($lib_name, $fn_name, $prj_uid, $request_data);
$response = $arrayData;
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @url PUT /: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}
* @param array $request_data
*/
public function doPutTriggerWizard($prj_uid, $lib_name, $fn_name, $tri_uid, $request_data)
{
try {
$triggerWizard = new \BusinessModel\TriggerWizard();
$triggerWizard->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
$triggerWizard->setArrayFieldNameForException($this->arrayFieldNameForException);
$arrayData = $triggerWizard->update($lib_name, $fn_name, $tri_uid, $request_data);
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
}