Se agregan validaciones para process variables

This commit is contained in:
Daniel Rojas
2014-06-30 16:31:27 -04:00
parent 7651eb58dc
commit 13689911da
2 changed files with 39 additions and 62 deletions

View File

@@ -3,38 +3,6 @@ namespace ProcessMaker\BusinessModel;
class Variable class Variable
{ {
private $arrayFieldDefinition = array(
"VAR_NAME" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varName"),
"VAR_FIELD_TYPE" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varFieldType"),
"VAR_FIELD_SIZE" => array("type" => "int", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varFieldSize"),
"VAR_LABEL" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varLabel"),
"VAR_DBCONNECTION" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varDbconnection"),
"VAR_SQL" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varSql"),
"VAR_NULL" => array("type" => "int", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varNull"),
"VAR_DEFAULT" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varDefault"),
"VAR_ACCEPTED_VALUES" => array("type" => "string", "required" => false, "empty" => true, "defaultValues" => array(), "fieldNameAux" => "varAcceptedValues")
);
private $arrayFieldNameForException = array(
"processUid" => "PRO_UID"
);
/**
* Constructor of the class
*
* return void
*/
public function __construct()
{
try {
foreach ($this->arrayFieldDefinition as $key => $value) {
$this->arrayFieldNameForException[$value["fieldNameAux"]] = $key;
}
} catch (\Exception $e) {
throw $e;
}
}
/** /**
* Create Variable for a Process * Create Variable for a Process
* *
@@ -47,13 +15,14 @@ class Variable
{ {
try { try {
//Verify data //Verify data
$process = new \ProcessMaker\BusinessModel\Process(); Validator::proUid($processUid, '$prj_uid');
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
$arrayData = array_change_key_case($arrayData, CASE_UPPER); $arrayData = array_change_key_case($arrayData, CASE_UPPER);
$this->existsName($processUid, $arrayData["VAR_NAME"]); $this->existsName($processUid, $arrayData["VAR_NAME"]);
$this->throwExceptionFieldDefinition($arrayData);
//Create //Create
$cnn = \Propel::getConnection("workflow"); $cnn = \Propel::getConnection("workflow");
try { try {
@@ -121,12 +90,10 @@ class Variable
{ {
try { try {
//Verify data //Verify data
$process = new \ProcessMaker\BusinessModel\Process(); Validator::proUid($processUid, '$prj_uid');
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
$this->throwExceptionIfNotExistsVariable($variableUid);
$arrayData = array_change_key_case($arrayData, CASE_UPPER); $arrayData = array_change_key_case($arrayData, CASE_UPPER);
$this->throwExceptionFieldDefinition($arrayData);
$this->existsName($processUid, $arrayData["VAR_NAME"]); $this->existsName($processUid, $arrayData["VAR_NAME"]);
//Update //Update
$cnn = \Propel::getConnection("workflow"); $cnn = \Propel::getConnection("workflow");
@@ -183,9 +150,7 @@ class Variable
{ {
try { try {
//Verify data //Verify data
$process = new \ProcessMaker\BusinessModel\Process(); Validator::proUid($processUid, '$prj_uid');
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
$this->throwExceptionIfNotExistsVariable($variableUid); $this->throwExceptionIfNotExistsVariable($variableUid);
@@ -211,16 +176,12 @@ class Variable
public function getVariable($processUid, $variableUid) public function getVariable($processUid, $variableUid)
{ {
try { try {
//Verify data //Verify data
$process = new \ProcessMaker\BusinessModel\Process(); Validator::proUid($processUid, '$prj_uid');
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
$this->throwExceptionIfNotExistsVariable($variableUid); $this->throwExceptionIfNotExistsVariable($variableUid);
//Get data //Get data
$criteria = new \Criteria("workflow"); $criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID); $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID);
@@ -279,12 +240,9 @@ class Variable
{ {
try { try {
//Verify data //Verify data
$process = new \ProcessMaker\BusinessModel\Process(); Validator::proUid($processUid, '$prj_uid');
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
//Get data //Get data
$criteria = new \Criteria("workflow"); $criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID); $criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID);
@@ -331,19 +289,40 @@ class Variable
} }
/** /**
* Verify if does not exist the variable in table PROCESS_VARIABLES * Verify field definition
* *
* @param string $variableUid Unique id of variable * @param array $aData Unique id of Variable to exclude
* *
* return void Throw exception if does not exist the variable in table PROCESS_VARIABLES
*/ */
public function throwExceptionIfNotExistsVariable($variableUid) public function throwExceptionFieldDefinition($aData)
{ {
try { try {
$obj = \ProcessVariablesPeer::retrieveByPK($variableUid); if (isset($aData["VAR_NAME"])) {
Validator::isString($aData['VAR_NAME'], '$var_name');
if (is_null($obj)) { }
throw new \Exception('var_uid: '.$variableUid. ' '.\G::LoadTranslation("ID_DOES_NOT_EXIST")); if (isset($aData["VAR_FIELD_TYPE"])) {
Validator::isString($aData['VAR_FIELD_TYPE'], '$var_field_type');
}
if (isset($aData["VAR_FIELD_SIZE"])) {
Validator::isInteger($aData["VAR_FIELD_SIZE"], '$var_field_size');
}
if (isset($aData["VAR_LABEL"])) {
Validator::isString($aData['VAR_LABEL'], '$var_label');
}
if (isset($aData["VAR_DBCONNECTION"])) {
Validator::isString($aData['VAR_DBCONNECTION'], '$var_dbconnection');
}
if (isset($aData["VAR_SQL"])) {
Validator::isString($aData['VAR_SQL'], '$var_sql');
}
if (isset($aData["VAR_NULL"])) {
Validator::isInteger($aData['VAR_NULL'], '$var_null');
}
if (isset($aData["VAR_DEFAULT"])) {
Validator::isString($aData['VAR_DEFAULT'], '$var_default');
}
if (isset($aData["VAR_ACCEPTED_VALUES"])) {
Validator::isString($aData['VAR_ACCEPTED_VALUES'], '$var_accepted_values');
} }
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;
@@ -375,7 +354,5 @@ class Variable
throw $e; throw $e;
} }
} }
} }

View File

@@ -55,7 +55,7 @@ class Variable extends Api
* *
* @status 201 * @status 201
*/ */
public function doPostVariable($prj_uid, array $request_data) public function doPostVariable($prj_uid, $request_data)
{ {
try { try {
$request_data = (array)($request_data); $request_data = (array)($request_data);