Merged in victorsl/processmaker (pull request #164)

ProcessMaker-MA "Web Entry (Fixes)"
This commit is contained in:
erik ao
2014-02-10 09:22:28 -04:00
4 changed files with 173 additions and 77 deletions

View File

@@ -364,6 +364,40 @@ class Process
}
}
/**
* Verify if doesn't exist 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
*/
public function throwExceptionIfNotExistsTask($processUid, $taskUid, $fieldNameForException)
{
try {
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\TaskPeer::TAS_UID);
if ($processUid != "") {
$criteria->add(\TaskPeer::PRO_UID, $processUid, \Criteria::EQUAL);
}
$criteria->add(\TaskPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
$rsCriteria = \TaskPeer::doSelectRS($criteria);
if (!$rsCriteria->next()) {
$msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $taskUid), "The activity 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
*
@@ -1433,14 +1467,10 @@ class Process
$arrayWebEntry = array();
//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
$webEntry = new \BusinessModel\WebEntry();
$webEntry->setFormatFieldNameInUppercase($this->formatFieldNameInUppercase);
$webEntry->setArrayFieldNameForException($this->arrayFieldNameForException);
$arrayWebEntryData = $webEntry->getData($processUid);

View File

@@ -3,6 +3,89 @@ namespace BusinessModel;
class WebEntry
{
private $arrayFieldDefinition = array(
"TAS_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "taskUid"),
"DYN_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "dynaFormUid"),
"METHOD" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array("WS", "HTML"), "fieldNameAux" => "method"),
"INPUT_DOCUMENT_ACCESS" => array("type" => "int", "required" => true, "empty" => false, "defaultValues" => array(0, 1), "fieldNameAux" => "inputDocumentAccess"),
"USR_USERNAME" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userUsername"),
"USR_PASSWORD" => array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userPassword")
);
private $formatFieldNameInUppercase = true;
private $arrayFieldNameForException = array(
"processUid" => "PRO_UID"
);
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
foreach ($this->arrayFieldDefinition as $key => $value) {
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
}
} catch (\Exception $e) {
throw $e;
}
}
/**
* 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;
}
}
/**
* Sanitizes a filename
*
@@ -58,6 +141,20 @@ class WebEntry
try {
$arrayData = array();
//Verify data
$process = new \BusinessModel\Process();
$process->throwExceptionIfNoExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
if ($taskUid != "") {
$process->throwExceptionIfNotExistsTask($processUid, $taskUid, $this->arrayFieldNameForException["taskUid"]);
}
if ($dynaFormUid != "") {
$process->throwExceptionIfNotExistsDynaForm($processUid, $dynaFormUid, $this->arrayFieldNameForException["dynaFormUid"]);
}
//Get data
$webEntryPath = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP . "public" . PATH_SEP . $processUid;
if (is_dir($webEntryPath)) {
@@ -150,6 +247,7 @@ class WebEntry
}
}
//Return
return $arrayData;
} catch (\Exception $e) {
throw $e;
@@ -170,37 +268,21 @@ class WebEntry
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
//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["TAS_UID"])) {
throw (new \Exception(str_replace(array("{0}"), array(strtolower("TAS_UID")), "The \"{0}\" attribute is not defined")));
}
if (!isset($arrayData["DYN_UID"])) {
throw (new \Exception(str_replace(array("{0}"), array(strtolower("DYN_UID")), "The \"{0}\" attribute is not defined")));
}
if (!isset($arrayData["METHOD"])) {
throw (new \Exception(str_replace(array("{0}"), array(strtolower("METHOD")), "The \"{0}\" attribute is not defined")));
}
if (!isset($arrayData["INPUT_DOCUMENT_ACCESS"])) {
throw (new \Exception(str_replace(array("{0}"), array(strtolower("INPUT_DOCUMENT_ACCESS")), "The \"{0}\" attribute is not defined")));
}
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true);
$projectUser = new \BusinessModel\ProjectUser();
if ($arrayData["METHOD"] == "WS") {
if (!isset($arrayData["USR_USERNAME"])) {
throw (new \Exception(str_replace(array("{0}"), array(strtolower("USR_USERNAME")), "The \"{0}\" attribute is not defined")));
throw (new \Exception(str_replace(array("{0}"), array($this->arrayFieldNameForException["userUsername"]), "The \"{0}\" attribute is not defined")));
}
if (!isset($arrayData["USR_PASSWORD"])) {
throw (new \Exception(str_replace(array("{0}"), array(strtolower("USR_PASSWORD")), "The \"{0}\" attribute is not defined")));
throw (new \Exception(str_replace(array("{0}"), array($this->arrayFieldNameForException["userPassword"]), "The \"{0}\" attribute is not defined")));
}
$loginData = $projectUser->userLogin($arrayData["USR_USERNAME"], $arrayData["USR_PASSWORD"]);
@@ -210,11 +292,10 @@ class WebEntry
}
}
$task = new \Task();
$process->throwExceptionIfNotExistsTask($processUid, $arrayData["TAS_UID"], $this->arrayFieldNameForException["taskUid"]);
$process->throwExceptionIfNotExistsDynaForm($processUid, $arrayData["DYN_UID"], $this->arrayFieldNameForException["dynaFormUid"]);
if (!$task->taskExists($arrayData["TAS_UID"])) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayData["TAS_UID"], "TASK"), "The UID \"{0}\" doesn't exist in table {1}")));
}
$task = new \Task();
$arrayTaskData = $task->load($arrayData["TAS_UID"]);
@@ -226,18 +307,16 @@ class WebEntry
throw (new \Exception(str_replace(array("{0}"), array($arrayTaskData["TAS_TITLE"]), "Web Entry only works with tasks which have \"Cyclical Assignment\", the task \"{0}\" doesn't have a valid assignment type. Please change the Assignment Rules")));
}
$task = new \Tasks();
if ($arrayData["METHOD"] == "WS") {
$task = new \Tasks();
if ($task->assignUsertoTask($arrayData["TAS_UID"]) == 0) {
throw (new \Exception(str_replace(array("{0}"), array($arrayTaskData["TAS_TITLE"]), "The task \"{0}\" doesn't have users")));
if ($task->assignUsertoTask($arrayData["TAS_UID"]) == 0) {
throw (new \Exception(str_replace(array("{0}"), array($arrayTaskData["TAS_TITLE"]), "The task \"{0}\" doesn't have users")));
}
}
$dynaForm = new \Dynaform();
if (!$dynaForm->dynaformExists($arrayData["DYN_UID"])) {
throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayData["DYN_UID"], "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}")));
}
$arrayDynaFormData = $dynaForm->Load($arrayData["DYN_UID"]);
$step = new \BusinessModel\Step();
@@ -387,7 +466,7 @@ class WebEntry
//Data
$url = $http . $_SERVER["HTTP_HOST"] . "/sys" . SYS_SYS . "/" . SYS_LANG . "/" . SYS_SKIN . "/" . $processUid . "/" . $dynTitle . ".php";
$arrayDataAux = array("url" => $url);
$arrayDataAux = array("URL" => $url);
break;
case "HTML":
global $G_FORM;
@@ -433,14 +512,18 @@ class WebEntry
//Data
$html = str_replace("</body>", "</form></body>", str_replace("</form>", "", $template->getOutputContent()));
$arrayDataAux = array("html" => $html);
$arrayDataAux = array("HTML" => $html);
break;
}
//Return
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
$arrayData = array_merge($arrayData, $arrayDataAux);
return array_merge($arrayData, $arrayDataAux);
if (!$this->formatFieldNameInUppercase) {
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
}
return $arrayData;
} catch (\Exception $e) {
throw $e;
}
@@ -459,12 +542,7 @@ class WebEntry
{
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
$arrayWebEntryData = $this->getData($processUid, "UID", $taskUid, $dynaFormUid);
if (count($arrayWebEntryData) == 0) {
@@ -492,11 +570,11 @@ class WebEntry
{
try {
return array(
"tas_uid" => $record["taskUid"],
"tas_title" => $record["taskTitle"],
"dyn_uid" => $record["dynaFormUid"],
"dyn_title" => $record["dynaFormTitle"],
"url" => $record["url"]
$this->getFieldNameByFormatFieldName("TAS_UID") => $record["taskUid"],
$this->getFieldNameByFormatFieldName("TAS_TITLE") => $record["taskTitle"],
$this->getFieldNameByFormatFieldName("DYN_UID") => $record["dynaFormUid"],
$this->getFieldNameByFormatFieldName("DYN_TITLE") => $record["dynaFormTitle"],
$this->getFieldNameByFormatFieldName("URL") => $record["url"]
);
} catch (\Exception $e) {
throw $e;
@@ -516,19 +594,13 @@ class WebEntry
{
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
$arrayWebEntryData = $this->getData($processUid, "UID", $taskUid, $dynaFormUid);
if (count($arrayWebEntryData) == 0) {
throw (new \Exception("The Web Entry doesn't exist"));
}
//Get data
//Return
return $this->getWebEntryDataFromRecord($arrayWebEntryData[$taskUid . "/" . $dynaFormUid]);
} catch (\Exception $e) {

View File

@@ -334,6 +334,8 @@ class Project extends Api
{
try {
$process = new \BusinessModel\Process();
$process->setFormatFieldNameInUppercase(false);
$process->setArrayFieldNameForException(array("processUid" => "prj_uid"));
$response = $process->getWebEntries($prj_uid);

View File

@@ -22,6 +22,8 @@ class WebEntry extends Api
{
try {
$webEntry = new \BusinessModel\WebEntry();
$webEntry->setFormatFieldNameInUppercase(false);
$webEntry->setArrayFieldNameForException(array("processUid" => "prj_uid"));
$response = $webEntry->getWebEntry($prj_uid, $tas_uid, $dyn_uid);
@@ -34,29 +36,17 @@ class WebEntry extends Api
/**
* @url POST /:prj_uid/web-entry
*
* @param string $prj_uid {@min 32}{@max 32}
* @param string $prj_uid {@min 32}{@max 32}
* @param array $request_data
* @param string $tas_uid {@from body}{@min 32}{@max 32}{@required true}
* @param string $dyn_uid {@from body}{@min 32}{@max 32}{@required true}
* @param string $method {@from body}{@choice WS,HTML}{@required true}
* @param int $input_document_access {@from body}{@choice 0,1}{@required true}
* @param string $usr_username {@from body}
* @param string $usr_password {@from body}
*
* @status 201
*/
public function doPostWebEntry(
$prj_uid,
$request_data,
$tas_uid = "00000000000000000000000000000000",
$dyn_uid = "00000000000000000000000000000000",
$method = "WS",
$input_document_access = 0,
$usr_username = "",
$usr_password = ""
) {
public function doPostWebEntry($prj_uid, $request_data)
{
try {
$webEntry = new \BusinessModel\WebEntry();
$webEntry->setFormatFieldNameInUppercase(false);
$webEntry->setArrayFieldNameForException(array("processUid" => "prj_uid"));
$arrayData = $webEntry->create($prj_uid, $request_data);
@@ -79,6 +69,8 @@ class WebEntry extends Api
{
try {
$webEntry = new \BusinessModel\WebEntry();
$webEntry->setFormatFieldNameInUppercase(false);
$webEntry->setArrayFieldNameForException(array("processUid" => "prj_uid"));
$webEntry->delete($prj_uid, $tas_uid, $dyn_uid);
} catch (\Exception $e) {