diff --git a/features/backend/project_properties_step_resources/step.feature b/features/backend/project_properties_step_resources/step.feature index 3318c4fca..ce23727fc 100644 --- a/features/backend/project_properties_step_resources/step.feature +++ b/features/backend/project_properties_step_resources/step.feature @@ -1,39 +1,303 @@ @ProcessMakerMichelangelo @RestAPI Feature: Project Properties - Step Resources + #STEPS OF A ACTIVITY - Background: - Given that I have a valid access_token + #GET /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/steps + # List assigned Steps to an Activity + Scenario: List assigned Steps to "Task1" + Given that I have a valid access_token + And I request "project/16062437052cd6141881e06088349078/activity/10163687452cd6234e0dd25086954968/steps" + 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 - Scenario: List assigned steps to an Activity - Given this scenario is not implemented yet + #POST /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step + # Assign a Step to an Activity + Scenario: Assign "DynaForm Demo1" to "Task1" + Given that I have a valid access_token + And POST this data: + """ + { + "step_type_obj": "DYNAFORM", + "step_uid_obj": "50332332752cd9b9a7cc989003652905", + "step_condition": "", + "step_position": 1, + "step_mode": "EDIT" + } + """ + And I request "project/16062437052cd6141881e06088349078/activity/10163687452cd6234e0dd25086954968/step" + 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 "step_uid" in session array as variable "step1" - Scenario: List available steps to assign to an Activity - Given this scenario is not implemented yet + #POST /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step + # Assign a Step to an Activity + Scenario: Assign "InputDocument Demo" to "Task1" + Given that I have a valid access_token + And POST this data: + """ + { + "step_type_obj": "INPUT_DOCUMENT", + "step_uid_obj": "83199959452cd62589576c1018679557", + "step_condition": "", + "step_position": 2, + "step_mode": "EDIT" + } + """ + And I request "project/16062437052cd6141881e06088349078/activity/10163687452cd6234e0dd25086954968/step" + 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 "step_uid" in session array as variable "step2" - Scenario: Get a single step assigned to an Activity - Given this scenario is not implemented yet + #PUT /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step/{step_uid} + # Update a Step assignation of an Activity + Scenario: Update Step "DynaForm Demo1" assigned to "Task1" + Given that I have a valid access_token + And PUT this data: + """ + { + "step_condition": "@@FIELD1 == 1", + "step_mode": "VIEW" + } + """ + And that I want to update a resource with the key "step1" stored in session array + And I request "project/16062437052cd6141881e06088349078/activity/10163687452cd6234e0dd25086954968/step" + 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" + And that "step_condition" is set to "@@FIELD1 == 1" - Scenario: Assing a step to a Activity - Given this scenario is not implemented yet + #GET /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/steps + # List assigned Steps to an Activity + Scenario: List assigned Steps to "Task1" + Given that I have a valid access_token + And I request "project/16062437052cd6141881e06088349078/activity/10163687452cd6234e0dd25086954968/steps" + 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 "step_type_obj" property in row 1 equals "INPUT_DOCUMENT" + And the "step_uid_obj" property in row 1 equals "83199959452cd62589576c1018679557" + And the "step_condition" property in row 1 equals "" + And the "step_position" property in row 1 equals "2" + And the "step_mode" property in row 1 equals "EDIT" + And the "obj_title" property in row 1 equals "InputDocument Demo" + And the "obj_description" property in row 1 equals "Description" - Scenario: Unassign a step from an activity - Given this scenario is not implemented yet + #GET /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/available-steps + # List available Steps to assign to an Activity + Scenario: List available Steps to assign to "Task1" + Given that I have a valid access_token + And I request "project/16062437052cd6141881e06088349078/activity/10163687452cd6234e0dd25086954968/available-steps" + 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 "obj_uid" property in row 1 equals "32743823452cd63105006e1076595203" + And the "obj_title" property in row 1 equals "OutputDocument Demo" + And the "obj_description" property in row 1 equals "Description" + And the "obj_type" property in row 1 equals "OUTPUT_DOCUMENT" - Scenario: List assigned triggers to a Step - Given this scenario is not implemented yet + #GET /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step/{step_uid} + # Get a single Step assigned to an Activity + Scenario: Get a single Step "DynaForm Demo1" assigned to "Task1" + Given that I have a valid access_token + And that I want to get a resource with the key "step1" stored in session array + And I request "project/16062437052cd6141881e06088349078/activity/10163687452cd6234e0dd25086954968/step" + 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" + And that "step_type_obj" is set to "DYNAFORM" + And that "step_uid_obj" is set to "50332332752cd9b9a7cc989003652905" + And that "step_condition" is set to "@@FIELD1 == 1" + And that "step_position" is set to "1" + And that "step_mode" is set to "VIEW" + And that "obj_title" is set to "DynaForm Demo1" + And that "obj_description" is set to "Description" - Scenario: List available triggers to assign to a Step - Given this scenario is not implemented yet + #DELETE /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step/{step_uid} + # Unassign a Step from an Activity + Scenario: Unassign "DynaForm Demo1" from "Task1" + Given that I have a valid access_token + And that I want to delete a resource with the key "step1" stored in session array + And I request "project/16062437052cd6141881e06088349078/activity/10163687452cd6234e0dd25086954968/step" + And the content type is "application/json" + Then the response status code should be 200 + And the response charset is "UTF-8" - Scenario: Get a single trigger assigned to a Step - Given this scenario is not implemented yet + #DELETE /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step/{step_uid} + # Unassign a Step from an Activity + Scenario: Unassign "InputDocument Demo" from "Task1" + Given that I have a valid access_token + And that I want to delete a resource with the key "step2" stored in session array + And I request "project/16062437052cd6141881e06088349078/activity/10163687452cd6234e0dd25086954968/step" + And the content type is "application/json" + Then the response status code should be 200 + And the response charset is "UTF-8" - Scenario: Assign a trigger to a Step - Given this scenario is not implemented yet + #GET /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/steps + # List assigned Steps to an Activity + Scenario: List assigned Steps to "Task1" + Given that I have a valid access_token + And I request "project/16062437052cd6141881e06088349078/activity/10163687452cd6234e0dd25086954968/steps" + 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 - Scenario: Update a trigger assignation of a Step - Given this scenario is not implemented yet + #TRIGGERS OF A STEP - Scenario: Remove a trigger assignation of a Step - Given this scenario is not implemented yet + #GET /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step/{step_uid}/triggers + # List assigned Triggers to a Step + Scenario: List Triggers assigned to first Step of "Task2" + Given that I have a valid access_token + And I request "project/16062437052cd6141881e06088349078/activity/89706843252cd9decdcf9b3047762708/step/65093024352cd9df93d9675058012924/triggers" + 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}/activity/{act_uid}/step/{step_uid}/trigger + # Assign a Trigger to a Step + Scenario: Assign "Trigger Demo1" to first Step of "Task2" + Given that I have a valid access_token + And POST this data: + """ + { + "tri_uid": "81919273152cd636c665080083928728", + "st_type": "BEFORE", + "st_condition": "", + "st_position": 1 + } + """ + And I request "project/16062437052cd6141881e06088349078/activity/89706843252cd9decdcf9b3047762708/step/65093024352cd9df93d9675058012924/trigger" + And the content type is "application/json" + Then the response status code should be 201 + And the response charset is "UTF-8" + + #POST /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step/{step_uid}/trigger + # Assign a Trigger to a Step + Scenario: Assign "Trigger Demo2" to first Step of "Task2" + Given that I have a valid access_token + And POST this data: + """ + { + "tri_uid": "56359776552cd6378b38e47080912028", + "st_type": "BEFORE", + "st_condition": "", + "st_position": 2 + } + """ + And I request "project/16062437052cd6141881e06088349078/activity/89706843252cd9decdcf9b3047762708/step/65093024352cd9df93d9675058012924/trigger" + And the content type is "application/json" + Then the response status code should be 201 + And the response charset is "UTF-8" + + #PUT /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step/{step_uid}/trigger/{tri_uid} + # Update a Trigger assignation of a Step + Scenario: Update "Trigger Demo1" assigned to first Step of "Task2" + Given that I have a valid access_token + And PUT this data: + """ + { + "st_type": "BEFORE", + "st_condition": "@@FIELD2 == 2" + } + """ + And that I want to update a resource with the key "tgr1" stored in session array + And I request "project/16062437052cd6141881e06088349078/activity/89706843252cd9decdcf9b3047762708/step/65093024352cd9df93d9675058012924/trigger/81919273152cd636c665080083928728" + 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" + And that "st_condition" is set to "@@FIELD2 == 2" + + #GET /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step/{step_uid}/triggers + # List assigned Triggers to a Step + Scenario: List Triggers assigned to first Step of "Task2" + Given that I have a valid access_token + And I request "project/16062437052cd6141881e06088349078/activity/89706843252cd9decdcf9b3047762708/step/65093024352cd9df93d9675058012924/triggers" + 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 "tri_uid" property in row 1 equals "56359776552cd6378b38e47080912028" + And the "tri_title" property in row 1 equals "Trigger Demo2" + And the "tri_description" property in row 1 equals "Description" + And the "st_type" property in row 1 equals "BEFORE" + And the "st_condition" property in row 1 equals "" + And the "st_position" property in row 1 equals "2" + + #GET /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step/{step_uid}/available-triggers/{type} + # List available Triggers to assign to a Step + Scenario: List available Triggers to assign to first Step of "Task2" + Given that I have a valid access_token + And I request "project/16062437052cd6141881e06088349078/activity/89706843252cd9decdcf9b3047762708/step/65093024352cd9df93d9675058012924/available-triggers/before" + 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 "tri_uid" property in row 0 equals "57401970252cd6393531551040242546" + And the "tri_title" property in row 0 equals "Trigger Demo3" + And the "tri_description" property in row 0 equals "Description" + And the "tri_type" property in row 0 equals "SCRIPT" + And the "tri_webbot" property in row 0 equals "" + And the "tri_param" property in row 0 equals "" + + #GET /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step/{step_uid}/trigger/{tri_uid}/{type} + # Get a single Trigger assigned to a Step + Scenario: Get a single Trigger "Trigger Demo1" assigned to first Step of "Task2" + Given that I have a valid access_token + And I request "project/16062437052cd6141881e06088349078/activity/89706843252cd9decdcf9b3047762708/step/65093024352cd9df93d9675058012924/trigger/81919273152cd636c665080083928728/before" + 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" + And that "tri_uid" is set to "81919273152cd636c665080083928728" + And that "tri_title" is set to "Trigger Demo1" + And that "tri_description" is set to "Description" + And that "st_type" is set to "BEFORE" + And that "st_condition" is set to "@@FIELD2 == 2" + And that "st_position" is set to "1" + + #DELETE /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step/{step_uid}/trigger/{tri_uid}/{type} + # Remove a Trigger assignation of a Step + Scenario: Remove "Trigger Demo1" assigned to first Step of "Task2" + Given that I have a valid access_token + And that I want to delete a resource with the key "tgr1" stored in session array + And I request "project/16062437052cd6141881e06088349078/activity/89706843252cd9decdcf9b3047762708/step/65093024352cd9df93d9675058012924/trigger/81919273152cd636c665080083928728/before" + And the content type is "application/json" + Then the response status code should be 200 + And the response charset is "UTF-8" + + #DELETE /api/1.0/{workspace}/project/{prj_uid}/activity/{act_uid}/step/{step_uid}/trigger/{tri_uid}/{type} + # Remove a Trigger assignation of a Step + Scenario: Remove "Trigger Demo2" assigned to first Step of "Task2" + Given that I have a valid access_token + And that I want to delete a resource with the key "tgr2" stored in session array + And I request "project/16062437052cd6141881e06088349078/activity/89706843252cd9decdcf9b3047762708/step/65093024352cd9df93d9675058012924/trigger/56359776552cd6378b38e47080912028/before" + 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}/activity/{act_uid}/step/{step_uid}/triggers + # List assigned Triggers to a Step + Scenario: List Triggers assigned to first Step of "Task2" + Given that I have a valid access_token + And I request "project/16062437052cd6141881e06088349078/activity/89706843252cd9decdcf9b3047762708/step/65093024352cd9df93d9675058012924/triggers" + 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 diff --git a/workflow/engine/src/BusinessModel/Step.php b/workflow/engine/src/BusinessModel/Step.php index 562d48503..926bb72a7 100644 --- a/workflow/engine/src/BusinessModel/Step.php +++ b/workflow/engine/src/BusinessModel/Step.php @@ -465,9 +465,11 @@ class Step public function getTriggers($stepUid) { try { + //Get data $arrayTrigger = array(); - $trigger = new \BusinessModel\Trigger(); + $bmTrigger = new \BusinessModel\Trigger(); + $bmStepTrigger = new \BusinessModel\Step\Trigger(); $arrayDataUid = $this->getDataUids($stepUid); @@ -508,8 +510,9 @@ class Step $stepTrigger->orderPosition($stepUid, $taskUid, $type); //Criteria - $criteria = $trigger->getTriggerCriteria(); + $criteria = $bmTrigger->getTriggerCriteria(); + $criteria->addSelectColumn(\StepTriggerPeer::ST_TYPE); $criteria->addSelectColumn(\StepTriggerPeer::ST_CONDITION); $criteria->addSelectColumn(\StepTriggerPeer::ST_POSITION); $criteria->addJoin(\StepTriggerPeer::TRI_UID, \TriggersPeer::TRI_UID, \Criteria::LEFT_JOIN); @@ -524,14 +527,7 @@ class Step while ($rsCriteria->next()) { $row = $rsCriteria->getRow(); - $arrayTrigger[] = array( - "tri_uid" => $row["TRI_UID"], - "tri_title" => $row["TRI_TITLE"], - "tri_description" => $row["TRI_DESCRIPTION"], - "st_type" => $triggerType, - "st_condition" => $row["ST_CONDITION"], - "st_position" => (int)($row["ST_POSITION"]) - ); + $arrayTrigger[] = $bmStepTrigger->getTriggerDataFromRecord($row); } } diff --git a/workflow/engine/src/BusinessModel/Step/Trigger.php b/workflow/engine/src/BusinessModel/Step/Trigger.php index f1f9ac62c..c22b91dfc 100644 --- a/workflow/engine/src/BusinessModel/Step/Trigger.php +++ b/workflow/engine/src/BusinessModel/Step/Trigger.php @@ -206,5 +206,78 @@ class Trigger throw $e; } } + + /** + * Get data of a Trigger from a record + * + * @param array $record Record + * + * return array Return an array with data of a Trigger + */ + public function getTriggerDataFromRecord($record) + { + try { + return array( + "tri_uid" => $record["TRI_UID"], + "tri_title" => $record["TRI_TITLE"], + "tri_description" => $record["TRI_DESCRIPTION"], + "st_type" => $record["ST_TYPE"], + "st_condition" => $record["ST_CONDITION"], + "st_position" => (int)($record["ST_POSITION"]) + ); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get data of a Trigger + * + * @param string $stepUid Unique id of Step + * @param string $type Type (BEFORE, AFTER) + * @param string $triggerUid Unique id of Trigger + * + * return array Return an array with data of a Trigger + */ + public function getTrigger($stepUid, $type, $triggerUid) + { + try { + $step = new \BusinessModel\Step(); + + $arrayDataUid = $step->getDataUids($stepUid); + + $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 data + $trigger = new \BusinessModel\Trigger(); + + $criteria = $trigger->getTriggerCriteria(); + + $criteria->addSelectColumn(\StepTriggerPeer::ST_TYPE); + $criteria->addSelectColumn(\StepTriggerPeer::ST_CONDITION); + $criteria->addSelectColumn(\StepTriggerPeer::ST_POSITION); + $criteria->addJoin(\StepTriggerPeer::TRI_UID, \TriggersPeer::TRI_UID, \Criteria::LEFT_JOIN); + $criteria->add(\TriggersPeer::TRI_UID, $triggerUid, \Criteria::EQUAL); + $criteria->add(\StepTriggerPeer::STEP_UID, $stepUid, \Criteria::EQUAL); + $criteria->add(\StepTriggerPeer::TAS_UID, $taskUid, \Criteria::EQUAL); + $criteria->add(\StepTriggerPeer::ST_TYPE, $type, \Criteria::EQUAL); + + $rsCriteria = \StepTriggerPeer::doSelectRS($criteria); + $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + + $rsCriteria->next(); + + $row = $rsCriteria->getRow(); + + return $this->getTriggerDataFromRecord($row); + } catch (\Exception $e) { + throw $e; + } + } } diff --git a/workflow/engine/src/BusinessModel/Trigger.php b/workflow/engine/src/BusinessModel/Trigger.php index 357ac3bfb..4ff82a92e 100644 --- a/workflow/engine/src/BusinessModel/Trigger.php +++ b/workflow/engine/src/BusinessModel/Trigger.php @@ -43,43 +43,6 @@ class Trigger } } - /** - * Get data of a Trigger - * - * @param string $triggerUid Unique id of Trigger - * - * return array - */ - public function getTrigger($triggerUid) - { - try { - //Criteria - $criteria = $this->getTriggerCriteria(); - - $criteria->add(\TriggersPeer::TRI_UID, $triggerUid, \Criteria::EQUAL); - - $rsCriteria = \TriggersPeer::doSelectRS($criteria); - $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); - - $rsCriteria->next(); - - $row = $rsCriteria->getRow(); - - $arrayTrigger = array( - "tri_uid" => $row["TRI_UID"], - "tri_title" => $row["TRI_TITLE"], - "tri_description" => $row["TRI_DESCRIPTION"], - "tri_type" => $row["TRI_TYPE"], - "tri_webbot" => $row["TRI_WEBBOT"], - "tri_param" => $row["TRI_PARAM"] - ); - - return $arrayTrigger; - } catch (\Exception $e) { - throw $e; - } - } - /** * List of Triggers in process * @var string $sProcessUID. Uid for Process diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/Activity/Step/Trigger.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/Activity/Step/Trigger.php index d8019e0e7..c8f988dec 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project/Activity/Step/Trigger.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project/Activity/Step/Trigger.php @@ -12,14 +12,20 @@ use \Luracast\Restler\RestException; class Trigger extends Api { /** - * @url GET /:projectUid/activity/:activityUid/step/:stepUid/trigger/:triggerUid + * @url GET /:projectUid/activity/:activityUid/step/:stepUid/trigger/:triggerUid/:type + * + * @param string $triggerUid + * @param string $stepUid + * @param string $activityUid + * @param string $projectUid + * @param string $type {@from body}{@choice before,after} */ - public function doGetActivityStepTrigger($triggerUid, $stepUid, $activityUid, $projectUid) + public function doGetActivityStepTrigger($triggerUid, $stepUid, $activityUid, $projectUid, $type) { try { - $trigger = new \BusinessModel\Trigger(); + $stepTrigger = new \BusinessModel\Step\Trigger(); - $response = $trigger->getTrigger($triggerUid); + $response = $stepTrigger->getTrigger($stepUid, strtoupper($type), $triggerUid); return $response; } catch (\Exception $e) {