diff --git a/features/backend/events/basic_sequence_event.feature b/features/backend/events/basic_sequence_event.feature index 10808acc7..158b7472b 100644 --- a/features/backend/events/basic_sequence_event.feature +++ b/features/backend/events/basic_sequence_event.feature @@ -4,7 +4,7 @@ Feature: Events Resources @1: TEST FOR GET EVENTS /---------------------------------------------------------------------- Scenario: List all the events (result 0 events) Given that I have a valid access_token - And I request "project/251815090529619a99a2bf4013294414/events" + And I request "project/74621721252eab0a6383731089824705/events" Then the response status code should be 200 And the response charset is "UTF-8" And the response has 0 record @@ -20,23 +20,22 @@ Feature: Events Resources "evn_status": "ACTIVE", "evn_action": "SEND_MESSAGE", "evn_related_to": "SINGLE", - "tas_uid": "97192372152a5c78f04a794095806311", - "evn_tas_uid_from": "97192372152a5c78f04a794095806311", + "tas_uid": "46337349752eab0df6e7b61093784394", "evn_tas_estimated_duration": 1, "evn_time_unit": "DAYS", "evn_when": 1, "evn_when_occurs": "AFTER_TIME", - "tri_uid": "75916963152cc6ab085a704081670580" + "tri_uid": "95002116552eab0b786a743075022999" } """ - And I request "project/251815090529619a99a2bf4013294414/event" + And I request "project/74621721252eab0a6383731089824705/event" Then the response status code should be 201 And store "evn_uid" in session array @3: TEST FOR GET EVENTS /---------------------------------------------------------------------- Scenario: List all the events (result 1 event) Given that I have a valid access_token - And I request "project/251815090529619a99a2bf4013294414/events" + And I request "project/74621721252eab0a6383731089824705/events" Then the response status code should be 200 And the response charset is "UTF-8" And the response has 1 record @@ -50,18 +49,18 @@ Feature: Events Resources "evn_description": "change description", "evn_status": "ACTIVE", "evn_action": "SEND_MESSAGE", - "evn_related_to": "SINGLE", - "tas_uid": "97192372152a5c78f04a794095806311", - "evn_tas_uid_from": "97192372152a5c78f04a794095806311", + "evn_related_to": "MULTIPLE", + "evn_tas_uid_from": "46337349752eab0df6e7b61093784394", + "evn_tas_uid_to": "86505074952eab0e1007790039372925", "evn_tas_estimated_duration": 1, "evn_time_unit": "DAYS", "evn_when": 1, "evn_when_occurs": "AFTER_TIME", - "tri_uid": "75916963152cc6ab085a704081670580" + "tri_uid": "95002116552eab0b786a743075022999" } """ And that I want to update a resource with the key "evn_uid" stored in session array - And I request "project/251815090529619a99a2bf4013294414/event" + And I request "project/74621721252eab0a6383731089824705/event" Then the response status code should be 200 And the response charset is "UTF-8" And the type is "object" @@ -71,7 +70,7 @@ Feature: Events Resources Scenario: Get a event (with change in "evn_description") Given that I have a valid access_token And that I want to get a resource with the key "evn_uid" stored in session array - And I request "project/251815090529619a99a2bf4013294414/event" + And I request "project/74621721252eab0a6383731089824705/event" Then the response status code should be 200 And the response charset is "UTF-8" And the type is "object" @@ -82,7 +81,7 @@ Feature: Events Resources Scenario: Delete a event Given that I have a valid access_token And that I want to delete a resource with the key "evn_uid" stored in session array - And I request "project/251815090529619a99a2bf4013294414/event" + And I request "project/74621721252eab0a6383731089824705/event" Then the response status code should be 200 And the response charset is "UTF-8" And the type is "object" @@ -90,7 +89,7 @@ Feature: Events Resources @7: TEST FOR GET EVENTS /---------------------------------------------------------------------- Scenario: List all the events (result 0 events) Given that I have a valid access_token - And I request "project/251815090529619a99a2bf4013294414/events" + And I request "project/74621721252eab0a6383731089824705/events" Then the response status code should be 200 And the response charset is "UTF-8" And the response has 0 record \ No newline at end of file diff --git a/workflow/engine/src/BusinessModel/Event.php b/workflow/engine/src/BusinessModel/Event.php index df9ecd5ba..d5bdd4991 100644 --- a/workflow/engine/src/BusinessModel/Event.php +++ b/workflow/engine/src/BusinessModel/Event.php @@ -93,14 +93,28 @@ class Event if ( ($sProcessUID == '') || (count($dataEvent) == 0) ) { return false; } - - $oProcess = new \Process(); - if (!($oProcess->processExists($sProcessUID))) { - throw (new \Exception( 'This process doesn\'t exist!' )); - } - $dataEvent = array_change_key_case($dataEvent, CASE_UPPER); + $this->validateProcess($sProcessUID); + + if ($dataEvent['EVN_RELATED_TO'] == 'SINGLE') { + if (empty($dataEvent['TAS_UID'])) { + throw (new \Exception('The field "tas_uid" is required!')); + } + $this->validateTask($dataEvent['TAS_UID']); + } else { + if (empty($dataEvent['EVN_TAS_UID_FROM'])) { + throw (new \Exception('The field "evn_tas_uid_from" is required!')); + } + $this->validateTask($dataEvent['EVN_TAS_UID_FROM']); + + if (empty($dataEvent['EVN_TAS_UID_TO'])) { + throw (new \Exception('The field "evn_tas_uid_to" is required!')); + } + $this->validateTask($dataEvent['EVN_TAS_UID_TO']); + } + + $this->validateTrigger($dataEvent['TRI_UID']); if ( $create && (isset($dataEvent['ENV_UID'])) ) { unset($dataEvent['ENV_UID']); } @@ -139,5 +153,47 @@ class Event throw $e; } } + + public function validateProcess($proUid) { + $proUid = trim($proUid); + if ($proUid == '') { + throw (new \Exception('This process doesn\'t exist!')); + } + + $oProcess = new \Process(); + if (!($oProcess->processExists($proUid))) { + throw (new \Exception('This process doesn\'t exist!')); + } + + return $proUid; + } + + public function validateTask($taskUid) { + $taskUid = trim($taskUid); + if ($taskUid == '') { + throw (new \Exception('This task doesn\'t exist!')); + } + + $oTask = new \Task(); + if (!($oTask->taskExists($taskUid))) { + throw (new \Exception('This task doesn\'t exist!')); + } + + return $taskUid; + } + + public function validateTrigger($triUid) { + $triUid = trim($triUid); + if ($triUid == '') { + throw (new \Exception('This trigger doesn\'t exist!')); + } + + $oTriggers = new \Triggers(); + if (!($oTriggers->TriggerExists($triUid))) { + throw (new \Exception('This trigger doesn\'t exist!')); + } + + return $triUid; + } } diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/Event.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/Event.php index b1c72cdcd..48bbb674d 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project/Event.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project/Event.php @@ -85,13 +85,13 @@ class Event extends Api * @param string $evn_status {@from body} {@choice ACTIVE,INACTIVE} * @param string $evn_action {@from body} {@choice SEND_MESSAGE,EXECUTE_CONDITIONAL_TRIGGER,EXECUTE_TRIGGER} * @param string $evn_related_to {@from body} {@choice SINGLE,MULTIPLE} - * @param string $tas_uid {@from body} {@min 1} - * @param string $evn_tas_uid_from {@from body} {@min 1} * @param string $evn_tas_estimated_duration {@from body} {@min 1} * @param string $evn_time_unit {@from body} {@choice DAYS,HOURS} * @param string $evn_when {@from body} {@type float} * @param string $evn_when_occurs {@from body} {@choice AFTER_TIME,TASK_STARTED} * @param string $tri_uid {@from body} {@min 1} + * @param string $tas_uid {@from body} + * @param string $evn_tas_uid_from {@from body} * @param string $evn_tas_uid_to {@from body} * @param string $evn_conditions {@from body} * @@ -111,13 +111,13 @@ class Event extends Api $evn_status, $evn_action, $evn_related_to, - $tas_uid, - $evn_tas_uid_from, $evn_tas_estimated_duration, $evn_time_unit, $evn_when, $evn_when_occurs, $tri_uid, + $tas_uid = '', + $evn_tas_uid_from = '', $evn_tas_uid_to = '', $evn_conditions = '' ) { @@ -146,13 +146,13 @@ class Event extends Api * @param string $evn_status {@from body} {@choice ACTIVE,INACTIVE} * @param string $evn_action {@from body} {@choice SEND_MESSAGE,EXECUTE_CONDITIONAL_TRIGGER,EXECUTE_TRIGGER} * @param string $evn_related_to {@from body} {@choice SINGLE,MULTIPLE} - * @param string $tas_uid {@from body} {@min 1} - * @param string $evn_tas_uid_from {@from body} {@min 1} * @param string $evn_tas_estimated_duration {@from body} {@min 1} * @param string $evn_time_unit {@from body} {@choice DAYS,HOURS} * @param string $evn_when {@from body} {@type float} * @param string $evn_when_occurs {@from body} {@choice AFTER_TIME,TASK_STARTED} * @param string $tri_uid {@from body} {@min 1} + * @param string $tas_uid {@from body} + * @param string $evn_tas_uid_from {@from body} * @param string $evn_tas_uid_to {@from body} * @param string $evn_conditions {@from body} * @@ -172,13 +172,13 @@ class Event extends Api $evn_status, $evn_action, $evn_related_to, - $tas_uid, - $evn_tas_uid_from, $evn_tas_estimated_duration, $evn_time_unit, $evn_when, $evn_when_occurs, $tri_uid, + $tas_uid = '', + $evn_tas_uid_from = '', $evn_tas_uid_to = '', $evn_conditions = '' ) {