Merged in victorsl/processmaker (pull request #31)
ProcessMaker-MA "2170 Project Properties - Step resources (Validacion)"
This commit is contained in:
@@ -3,6 +3,100 @@ namespace BusinessModel;
|
||||
|
||||
class Step
|
||||
{
|
||||
/**
|
||||
* Checks if exists the record in table STEP
|
||||
*
|
||||
* @param string $taskUid Unique id of Task
|
||||
* @param string $type Type of Step (DYNAFORM, INPUT_DOCUMENT, OUTPUT_DOCUMENT)
|
||||
* @param string $objectUid Unique id of Object
|
||||
* @param int $position Position
|
||||
* @param string $stepUidExclude Unique id of Step to exclude
|
||||
*
|
||||
* return bool Return true if exists the record in table STEP, false otherwise
|
||||
*/
|
||||
public function existsRecord($taskUid, $type, $objectUid, $position = 0, $stepUidExclude = "")
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\StepPeer::STEP_UID);
|
||||
$criteria->add(\StepPeer::TAS_UID, $taskUid, \Criteria::EQUAL);
|
||||
|
||||
if ($stepUidExclude != "") {
|
||||
$criteria->add(\StepPeer::STEP_UID, $stepUidExclude, \Criteria::NOT_EQUAL);
|
||||
}
|
||||
|
||||
if ($type != "") {
|
||||
$criteria->add(\StepPeer::STEP_TYPE_OBJ, $type, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
if ($objectUid != "") {
|
||||
$criteria->add(\StepPeer::STEP_UID_OBJ, $objectUid, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
if ($position > 0) {
|
||||
$criteria->add(\StepPeer::STEP_POSITION, $position, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
$rsCriteria = \StepPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
if ($rsCriteria->next()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if exists the "Object UID" in the corresponding table
|
||||
*
|
||||
* @param string $type Type of Step (DYNAFORM, INPUT_DOCUMENT, OUTPUT_DOCUMENT)
|
||||
* @param string $objectUid Unique id of Object
|
||||
*
|
||||
* return strin Return empty string if $objectUid exists in the corresponding table, return string with data if $objectUid doesn't exist
|
||||
*/
|
||||
public function existsObjectUid($type, $objectUid)
|
||||
{
|
||||
try {
|
||||
$msg = "";
|
||||
|
||||
switch ($type) {
|
||||
case "DYNAFORM":
|
||||
$dynaform = new \Dynaform();
|
||||
|
||||
if (!$dynaform->dynaformExists($objectUid)) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($objectUid, "DYNAFORM"), "The UID \"{0}\" doesn't exist in table {1}");
|
||||
}
|
||||
break;
|
||||
case "INPUT_DOCUMENT":
|
||||
$inputdoc = new \InputDocument();
|
||||
|
||||
if (!$inputdoc->InputExists($objectUid)) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($objectUid, "INPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}");
|
||||
}
|
||||
break;
|
||||
case "OUTPUT_DOCUMENT":
|
||||
$outputdoc = new \OutputDocument();
|
||||
|
||||
if (!$outputdoc->OutputExists($objectUid)) {
|
||||
$msg = str_replace(array("{0}", "{1}"), array($objectUid, "OUTPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$msg = str_replace(array("{0}", "{1}"), array($objectUid, $type), "The UID \"{0}\" doesn't exist in table {1}");
|
||||
break;
|
||||
}
|
||||
|
||||
return $msg;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Step for a Task
|
||||
*
|
||||
@@ -10,11 +104,41 @@ class Step
|
||||
* @param string $processUid
|
||||
* @param array $arrayData
|
||||
*
|
||||
* return string Unique id of the new Step
|
||||
* return array Data of the Step created
|
||||
*/
|
||||
public function create($taskUid, $processUid, $arrayData)
|
||||
{
|
||||
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}")));
|
||||
}
|
||||
|
||||
$task = new \Task();
|
||||
|
||||
if (!$task->taskExists($taskUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($taskUid, "TASK"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
if (isset($arrayData["step_type_obj"]) && isset($arrayData["step_uid_obj"])) {
|
||||
$msg = $this->existsObjectUid($arrayData["step_type_obj"], $arrayData["step_uid_obj"]);
|
||||
|
||||
if ($msg != "") {
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
|
||||
if ($this->existsRecord($taskUid, $arrayData["step_type_obj"], $arrayData["step_uid_obj"])) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($taskUid . ", " . $arrayData["step_type_obj"] . ", " . $arrayData["step_uid_obj"], "STEP"), "The record \"{0}\", exists in table {1}")));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($arrayData["step_position"]) && $this->existsRecord($taskUid, "", "", $arrayData["step_position"])) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}", "{2}"), array($arrayData["step_position"], $taskUid . ", " . $arrayData["step_position"], "STEP"), "The \"{0}\" position for the record \"{1}\", exists in table {2}")));
|
||||
}
|
||||
|
||||
//Create
|
||||
$step = new \Step();
|
||||
|
||||
$stepUid = $step->create(array("PRO_UID" => $processUid, "TAS_UID" => $taskUid));
|
||||
@@ -23,9 +147,11 @@ class Step
|
||||
$arrayData["step_position"] = $step->getNextPosition($taskUid) - 1;
|
||||
}
|
||||
|
||||
$this->update($stepUid, $arrayData);
|
||||
$arrayData = $this->update($stepUid, $arrayData);
|
||||
|
||||
return $stepUid;
|
||||
$arrayData["step_uid"] = $stepUid;
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
@@ -37,11 +163,39 @@ class Step
|
||||
* @param string $stepUid
|
||||
* @param array $arrayData
|
||||
*
|
||||
* return void
|
||||
* return array Data of the Step updated
|
||||
*/
|
||||
public function update($stepUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$arrayDataUid = $this->getDataUids($stepUid);
|
||||
|
||||
$taskUid = $arrayDataUid["TAS_UID"];
|
||||
|
||||
//Verify data
|
||||
$step = new \Step();
|
||||
|
||||
if (!$step->StepExists($stepUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid, "STEP"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
if (isset($arrayData["step_type_obj"]) && isset($arrayData["step_uid_obj"])) {
|
||||
$msg = $this->existsObjectUid($arrayData["step_type_obj"], $arrayData["step_uid_obj"]);
|
||||
|
||||
if ($msg != "") {
|
||||
throw (new \Exception($msg));
|
||||
}
|
||||
|
||||
if ($this->existsRecord($taskUid, $arrayData["step_type_obj"], $arrayData["step_uid_obj"], 0, $stepUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($taskUid . ", " . $arrayData["step_type_obj"] . ", " . $arrayData["step_uid_obj"], "STEP"), "The record \"{0}\", exists in table {1}")));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($arrayData["step_position"]) && $this->existsRecord($taskUid, "", "", $arrayData["step_position"], $stepUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}", "{2}"), array($arrayData["step_position"], $taskUid . ", " . $arrayData["step_position"], "STEP"), "The \"{0}\" position for the record \"{1}\", exists in table {2}")));
|
||||
}
|
||||
|
||||
//Update
|
||||
$step = new \Step();
|
||||
|
||||
$arrayUpdateData = array();
|
||||
@@ -69,6 +223,8 @@ class Step
|
||||
}
|
||||
|
||||
$step->update($arrayUpdateData);
|
||||
|
||||
return array_change_key_case($arrayUpdateData, CASE_LOWER);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
@@ -84,6 +240,13 @@ class Step
|
||||
public function delete($stepUid)
|
||||
{
|
||||
try {
|
||||
//Verify data
|
||||
$step = new \Step();
|
||||
|
||||
if (!$step->StepExists($stepUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid, "STEP"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
//Get position
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
|
||||
@@ -3,17 +3,62 @@ namespace BusinessModel\Step;
|
||||
|
||||
class Trigger
|
||||
{
|
||||
/**
|
||||
* Checks if exists the record in table STEP_TRIGGER
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
* @param string $type Type (BEFORE, AFTER)
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
* @param int $position Position
|
||||
* @param string $triggerUidExclude Unique id of Trigger to exclude
|
||||
*
|
||||
* return bool Return true if exists the record in table STEP_TRIGGER, false otherwise
|
||||
*/
|
||||
public function existsRecord($stepUid, $type, $triggerUid, $position = 0, $triggerUidExclude = "")
|
||||
{
|
||||
try {
|
||||
$criteria = new \Criteria("workflow");
|
||||
|
||||
$criteria->addSelectColumn(\StepTriggerPeer::STEP_UID);
|
||||
$criteria->add(\StepTriggerPeer::STEP_UID, $stepUid, \Criteria::EQUAL);
|
||||
$criteria->add(\StepTriggerPeer::ST_TYPE, $type, \Criteria::EQUAL);
|
||||
|
||||
if ($triggerUid != "") {
|
||||
$criteria->add(\StepTriggerPeer::TRI_UID, $triggerUid, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
if ($position > 0) {
|
||||
$criteria->add(\StepTriggerPeer::ST_POSITION, $position, \Criteria::EQUAL);
|
||||
}
|
||||
|
||||
if ($triggerUidExclude != "") {
|
||||
$criteria->add(\StepTriggerPeer::TRI_UID, $triggerUidExclude, \Criteria::NOT_EQUAL);
|
||||
}
|
||||
|
||||
$rsCriteria = \StepTriggerPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
if ($rsCriteria->next()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign Trigger to a Step
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
* @param string $type Type (BEFORE, AFTER)
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return void
|
||||
* return array Data of the Trigger assigned to a Step
|
||||
*/
|
||||
public function create($stepUid, $triggerUid, $type, $arrayData)
|
||||
public function create($stepUid, $type, $triggerUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$step = new \BusinessModel\Step();
|
||||
@@ -22,6 +67,27 @@ class Trigger
|
||||
|
||||
$taskUid = $arrayDataUid["TAS_UID"];
|
||||
|
||||
//Verify data
|
||||
$step = new \Step();
|
||||
|
||||
if (!$step->StepExists($stepUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid, "STEP"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
$trigger = new \Triggers();
|
||||
|
||||
if (!$trigger->TriggerExists($triggerUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($triggerUid, "TRIGGERS"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
if ($this->existsRecord($stepUid, $type, $triggerUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid . ", " . $type . ", " . $triggerUid, "STEP_TRIGGER"), "The record \"{0}\", exists in table {1}")));
|
||||
}
|
||||
|
||||
if (isset($arrayData["st_position"]) && $this->existsRecord($stepUid, $type, "", $arrayData["st_position"])) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}", "{2}"), array($arrayData["st_position"], $stepUid . ", " . $type . ", " . $arrayData["st_position"], "STEP_TRIGGER"), "The \"{0}\" position for the record \"{1}\", exists in table {2}")));
|
||||
}
|
||||
|
||||
//Create
|
||||
$stepTrigger = new \StepTrigger();
|
||||
|
||||
@@ -31,7 +97,9 @@ class Trigger
|
||||
$arrayData["st_position"] = $stepTrigger->getNextPosition($stepUid, $type, $taskUid) - 1;
|
||||
}
|
||||
|
||||
$this->update($stepUid, $triggerUid, $type, $arrayData);
|
||||
$arrayData = $this->update($stepUid, $type, $triggerUid, $arrayData);
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
@@ -41,13 +109,13 @@ class Trigger
|
||||
* Update Trigger of a Step
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
* @param string $type Type (BEFORE, AFTER)
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
* @param array $arrayData Data
|
||||
*
|
||||
* return void
|
||||
* return array Data updated of the Trigger assigned to a Step
|
||||
*/
|
||||
public function update($stepUid, $triggerUid, $type, $arrayData)
|
||||
public function update($stepUid, $type, $triggerUid, $arrayData)
|
||||
{
|
||||
try {
|
||||
$step = new \BusinessModel\Step();
|
||||
@@ -56,6 +124,23 @@ class Trigger
|
||||
|
||||
$taskUid = $arrayDataUid["TAS_UID"];
|
||||
|
||||
//Verify data
|
||||
$step = new \Step();
|
||||
|
||||
if (!$step->StepExists($stepUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid, "STEP"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
$trigger = new \Triggers();
|
||||
|
||||
if (!$trigger->TriggerExists($triggerUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($triggerUid, "TRIGGERS"), "The UID \"{0}\" doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
if (isset($arrayData["st_position"]) && $this->existsRecord($stepUid, $type, "", $arrayData["st_position"], $triggerUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}", "{2}"), array($arrayData["st_position"], $stepUid . ", " . $type . ", " . $arrayData["st_position"], "STEP_TRIGGER"), "The \"{0}\" position for the record \"{1}\", exists in table {2}")));
|
||||
}
|
||||
|
||||
//Update
|
||||
$stepTrigger = new \StepTrigger();
|
||||
|
||||
@@ -75,6 +160,8 @@ class Trigger
|
||||
}
|
||||
|
||||
$stepTrigger->update($arrayUpdateData);
|
||||
|
||||
return array_change_key_case($arrayUpdateData, CASE_LOWER);
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
@@ -84,12 +171,12 @@ class Trigger
|
||||
* Delete Trigger of a Step
|
||||
*
|
||||
* @param string $stepUid Unique id of Step
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
* @param string $type Type (BEFORE, AFTER)
|
||||
* @param string $triggerUid Unique id of Trigger
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function delete($stepUid, $triggerUid, $type)
|
||||
public function delete($stepUid, $type, $triggerUid)
|
||||
{
|
||||
try {
|
||||
$step = new \BusinessModel\Step();
|
||||
@@ -98,6 +185,11 @@ class Trigger
|
||||
|
||||
$taskUid = $arrayDataUid["TAS_UID"];
|
||||
|
||||
//Verify data
|
||||
if (!$this->existsRecord($stepUid, $type, $triggerUid)) {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($stepUid . ", " . $type . ", " . $triggerUid, "STEP_TRIGGER"), "The record \"{0}\", doesn't exist in table {1}")));
|
||||
}
|
||||
|
||||
//Get position
|
||||
$stepTrigger = new \StepTrigger();
|
||||
|
||||
|
||||
@@ -43,9 +43,9 @@ class Step extends Api
|
||||
|
||||
$step = new \BusinessModel\Step();
|
||||
|
||||
$stepUid = $step->create($activityUid, $projectUid, $request_data);
|
||||
$arrayData = $step->create($activityUid, $projectUid, $request_data);
|
||||
|
||||
$response = array("old_uid" => $request_data["step_uid"], "new_uid" => $stepUid);
|
||||
$response = $arrayData;
|
||||
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
@@ -68,7 +68,7 @@ class Step extends Api
|
||||
|
||||
$step = new \BusinessModel\Step();
|
||||
|
||||
$step->update($stepUid, $request_data);
|
||||
$arrayData = $step->update($stepUid, $request_data);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
@@ -128,11 +128,6 @@ class Step extends Api
|
||||
|
||||
class StepPostStructure
|
||||
{
|
||||
/**
|
||||
* @var string {@from body}{@min 32}{@max 32}
|
||||
*/
|
||||
public $step_uid;
|
||||
|
||||
/**
|
||||
* @var string {@from body}{@choice DYNAFORM,INPUT_DOCUMENT,OUTPUT_DOCUMENT}{@required true}
|
||||
*/
|
||||
|
||||
@@ -44,7 +44,7 @@ class Trigger extends Api
|
||||
|
||||
$stepTrigger = new \BusinessModel\Step\Trigger();
|
||||
|
||||
$stepTrigger->create($stepUid, $request_data["tri_uid"], $request_data["st_type"], $request_data);
|
||||
$arrayData = $stepTrigger->create($stepUid, $request_data["st_type"], $request_data["tri_uid"], $request_data);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class Trigger extends Api
|
||||
|
||||
$stepTrigger = new \BusinessModel\Step\Trigger();
|
||||
|
||||
$stepTrigger->update($stepUid, $triggerUid, $request_data["st_type"], $request_data);
|
||||
$arrayData = $stepTrigger->update($stepUid, $request_data["st_type"], $triggerUid, $request_data);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
@@ -86,7 +86,7 @@ class Trigger extends Api
|
||||
try {
|
||||
$stepTrigger = new \BusinessModel\Step\Trigger();
|
||||
|
||||
$stepTrigger->delete($stepUid, $triggerUid, strtoupper($type));
|
||||
$stepTrigger->delete($stepUid, strtoupper($type), $triggerUid);
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
@@ -95,11 +95,29 @@ class Trigger extends Api
|
||||
|
||||
class StepTriggerPostStructure
|
||||
{
|
||||
/**
|
||||
* @var string {@from body}{@choice BEFORE,AFTER}{@required true}
|
||||
*/
|
||||
public $st_type;
|
||||
|
||||
/**
|
||||
* @var string {@from body}{@min 32}{@max 32}{@required true}
|
||||
*/
|
||||
public $tri_uid;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $st_condition;
|
||||
|
||||
/**
|
||||
* @var int {@from body}{@min 1}
|
||||
*/
|
||||
public $st_position;
|
||||
}
|
||||
|
||||
class StepTriggerPutStructure
|
||||
{
|
||||
/**
|
||||
* @var string {@from body}{@choice BEFORE,AFTER}{@required true}
|
||||
*/
|
||||
@@ -116,21 +134,3 @@ class StepTriggerPostStructure
|
||||
public $st_position;
|
||||
}
|
||||
|
||||
class StepTriggerPutStructure
|
||||
{
|
||||
/**
|
||||
* @var string {@from body}{@choice BEFORE,AFTER}
|
||||
*/
|
||||
public $st_type;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $st_condition;
|
||||
|
||||
/**
|
||||
* @var int {@from body}{@min 1}
|
||||
*/
|
||||
public $st_position;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user