Merge branch 'master' of bitbucket.org:colosa/processmaker
Conflicts: workflow/engine/src/ProcessMaker/BusinessModel/Variable.php
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -173,7 +173,9 @@ class Dynaform extends BaseDynaform
|
||||
if (isset($aData["DYN_CONTENT"])) {
|
||||
$this->setDynContent($aData["DYN_CONTENT"]);
|
||||
}
|
||||
if (isset($aData["DYN_VERSION"])) {
|
||||
$this->setDynVersion( $aData['DYN_VERSION'] );
|
||||
}
|
||||
if ($this->validate()) {
|
||||
$con->begin();
|
||||
$res = $this->save();
|
||||
|
||||
@@ -365,6 +365,10 @@ class DynaForm
|
||||
//Create
|
||||
$dynaForm = new \Dynaform();
|
||||
|
||||
if (isset($arrayData["DYN_VERSION"])) {
|
||||
$arrayData["DYN_VERSION"] = 1;
|
||||
}
|
||||
|
||||
$arrayData["PRO_UID"] = $processUid;
|
||||
|
||||
$dynaFormUid = $dynaForm->create($arrayData);
|
||||
@@ -953,6 +957,10 @@ class DynaForm
|
||||
$record["DYN_DESCRIPTION"] = \Content::load("DYN_DESCRIPTION", "", $record["DYN_UID"], SYS_LANG);
|
||||
}
|
||||
|
||||
if ($record["DYN_VERSION"] == 0) {
|
||||
$record["DYN_VERSION"] = 1;
|
||||
}
|
||||
|
||||
return array(
|
||||
$this->getFieldNameByFormatFieldName("DYN_UID") => $record["DYN_UID"],
|
||||
$this->getFieldNameByFormatFieldName("DYN_TITLE") => $record["DYN_TITLE"],
|
||||
|
||||
@@ -3,38 +3,6 @@ namespace ProcessMaker\BusinessModel;
|
||||
|
||||
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
|
||||
*
|
||||
@@ -47,13 +15,14 @@ class Variable
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
|
||||
Validator::proUid($processUid, '$prj_uid');
|
||||
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
$this->existsName($processUid, $arrayData["VAR_NAME"]);
|
||||
|
||||
$this->throwExceptionFieldDefinition($arrayData);
|
||||
|
||||
//Create
|
||||
$cnn = \Propel::getConnection("workflow");
|
||||
try {
|
||||
@@ -121,12 +90,10 @@ class Variable
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
|
||||
|
||||
$this->throwExceptionIfNotExistsVariable($variableUid);
|
||||
|
||||
Validator::proUid($processUid, '$prj_uid');
|
||||
$arrayData = array_change_key_case($arrayData, CASE_UPPER);
|
||||
|
||||
$this->throwExceptionFieldDefinition($arrayData);
|
||||
$this->existsName($processUid, $arrayData["VAR_NAME"]);
|
||||
//Update
|
||||
$cnn = \Propel::getConnection("workflow");
|
||||
@@ -183,9 +150,7 @@ class Variable
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
|
||||
Validator::proUid($processUid, '$prj_uid');
|
||||
|
||||
$this->throwExceptionIfNotExistsVariable($variableUid);
|
||||
|
||||
@@ -211,16 +176,12 @@ class Variable
|
||||
public function getVariable($processUid, $variableUid)
|
||||
{
|
||||
try {
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
|
||||
Validator::proUid($processUid, '$prj_uid');
|
||||
|
||||
$this->throwExceptionIfNotExistsVariable($variableUid);
|
||||
|
||||
//Get data
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\ProcessVariablesPeer::VAR_UID);
|
||||
@@ -279,12 +240,9 @@ class Variable
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
|
||||
$process->throwExceptionIfNotExistsProcess($processUid, $this->arrayFieldNameForException["processUid"]);
|
||||
Validator::proUid($processUid, '$prj_uid');
|
||||
|
||||
//Get data
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$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 {
|
||||
$obj = \ProcessVariablesPeer::retrieveByPK($variableUid);
|
||||
|
||||
if (is_null($obj)) {
|
||||
throw new \Exception('var_uid: '.$variableUid. ' '.\G::LoadTranslation("ID_DOES_NOT_EXIST"));
|
||||
if (isset($aData["VAR_NAME"])) {
|
||||
Validator::isString($aData['VAR_NAME'], '$var_name');
|
||||
}
|
||||
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) {
|
||||
throw $e;
|
||||
|
||||
@@ -55,7 +55,7 @@ class Variable extends Api
|
||||
*
|
||||
* @status 201
|
||||
*/
|
||||
public function doPostVariable($prj_uid, array $request_data)
|
||||
public function doPostVariable($prj_uid, $request_data)
|
||||
{
|
||||
try {
|
||||
$request_data = (array)($request_data);
|
||||
|
||||
Reference in New Issue
Block a user