Merge branch 'master' of bitbucket.org:colosa/processmaker

Conflicts:
	workflow/engine/src/ProcessMaker/BusinessModel/Variable.php
This commit is contained in:
Victor Saisa Lopez
2014-07-01 10:00:27 -04:00
5 changed files with 154 additions and 61 deletions

View File

@@ -0,0 +1,104 @@
@ProcessMakerMichelangelo @RestAPI
Feature: Process variables Resources
#GET /api/1.0/{workspace}/project/{prj_uid}/process-variables
# Get a List of process variables
Scenario: Get a List of process variables
Given that I have a valid access_token
And I request "project/14414793652a5d718b65590036026581/process-variables"
And the content type is "application/json"
Then the response status code should be 200
And the response charset is "UTF-8"
And the type is "array"
And the json data is an empty array
#POST /api/1.0/{workspace}/project/{prj_uid}/process-variable
# Create a process variable
# Normal creation of a process variable
Scenario: Create "My variable" for a Project (Normal creation of a process variable)
Given that I have a valid access_token
And POST this data:
"""
{
"var_name": "My Variable",
"var_field_type": "text_field",
"var_field_size": 12,
"var_label": "Nombre:",
"var_dbconnection": "",
"var_sql": "",
"var_null": 0,
"var_default": "",
"var_accepted_values": ""
}
"""
And I request "project/14414793652a5d718b65590036026581/process-variable"
And the content type is "application/json"
Then the response status code should be 201
And the response charset is "UTF-8"
And the type is "object"
And store "var_uid" in session array as variable "variable1"
#PUT /api/1.0/{workspace}/project/{prj_uid}/process-variable/{var_uid}
# Update a process variable
Scenario: Update a process variable
Given that I have a valid access_token
And PUT this data:
"""
{
"var_name": "My Variable Modify",
"var_field_type": "text_field",
"var_field_size": 1,
"var_label": "Nombre modificado:",
"var_dbconnection": "",
"var_sql": "",
"var_null": 0,
"var_default": "",
"var_accepted_values": ""
}
"""
And that I want to update a resource with the key "variable1" stored in session array
And I request "project/14414793652a5d718b65590036026581/process-variable"
And the content type is "application/json"
Then the response status code should be 200
#GET /api/1.0/{workspace}/project/{prj_uid}/process-variables
# Get a List of process variables
Scenario: Get a List of process variables
Given that I have a valid access_token
And I request "project/14414793652a5d718b65590036026581/process-variables"
And the content type is "application/json"
Then the response status code should be 200
And the response charset is "UTF-8"
And the type is "array"
#GET /api/1.0/{workspace}/project/{prj_uid}/process-variable/{var_uid}
# Get a single process variable
Scenario: Get a single process variable
Given that I have a valid access_token
And that I want to get a resource with the key "variable1" stored in session array
And I request "project/14414793652a5d718b65590036026581/process-variable"
And the content type is "application/json"
Then the response status code should be 200
And the response charset is "UTF-8"
And the type is "object"
#DELETE /api/1.0/{workspace}/project/{prj_uid}/process-variable/{var_uid}
# Delete a process variable
Scenario: Delete a previously created process variable
Given that I have a valid access_token
And that I want to delete a resource with the key "variable1" stored in session array
And I request "project/14414793652a5d718b65590036026581/process-variable"
And the content type is "application/json"
Then the response status code should be 200
And the response charset is "UTF-8"
#GET /api/1.0/{workspace}/project/{prj_uid}/process-variables
# Get a List of process variables
Scenario: Get a List of process variables
Given that I have a valid access_token
And I request "project/14414793652a5d718b65590036026581/process-variables"
And the content type is "application/json"
Then the response status code should be 200
And the response charset is "UTF-8"
And the type is "array"
And the json data is an empty array

View File

@@ -173,7 +173,9 @@ class Dynaform extends BaseDynaform
if (isset($aData["DYN_CONTENT"])) { if (isset($aData["DYN_CONTENT"])) {
$this->setDynContent($aData["DYN_CONTENT"]); $this->setDynContent($aData["DYN_CONTENT"]);
} }
$this->setDynVersion( $aData['DYN_VERSION'] ); if (isset($aData["DYN_VERSION"])) {
$this->setDynVersion( $aData['DYN_VERSION'] );
}
if ($this->validate()) { if ($this->validate()) {
$con->begin(); $con->begin();
$res = $this->save(); $res = $this->save();

View File

@@ -365,6 +365,10 @@ class DynaForm
//Create //Create
$dynaForm = new \Dynaform(); $dynaForm = new \Dynaform();
if (isset($arrayData["DYN_VERSION"])) {
$arrayData["DYN_VERSION"] = 1;
}
$arrayData["PRO_UID"] = $processUid; $arrayData["PRO_UID"] = $processUid;
$dynaFormUid = $dynaForm->create($arrayData); $dynaFormUid = $dynaForm->create($arrayData);
@@ -953,6 +957,10 @@ class DynaForm
$record["DYN_DESCRIPTION"] = \Content::load("DYN_DESCRIPTION", "", $record["DYN_UID"], SYS_LANG); $record["DYN_DESCRIPTION"] = \Content::load("DYN_DESCRIPTION", "", $record["DYN_UID"], SYS_LANG);
} }
if ($record["DYN_VERSION"] == 0) {
$record["DYN_VERSION"] = 1;
}
return array( return array(
$this->getFieldNameByFormatFieldName("DYN_UID") => $record["DYN_UID"], $this->getFieldNameByFormatFieldName("DYN_UID") => $record["DYN_UID"],
$this->getFieldNameByFormatFieldName("DYN_TITLE") => $record["DYN_TITLE"], $this->getFieldNameByFormatFieldName("DYN_TITLE") => $record["DYN_TITLE"],

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;

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);