From 14d1c51106c73b5e742456b35892ddff2a636ea5 Mon Sep 17 00:00:00 2001 From: Victor Saisa Lopez Date: Tue, 11 Feb 2014 17:00:26 -0400 Subject: [PATCH] ProcessMaker-MA "Group (endpoints & behat) and Web Entry (behat)" - Se han implementado los siguientes Endpoints: POST /api/1.0/{workspace}/group/{grp_uid}/user DELETE /api/1.0/{workspace}/group/{grp_uid}/user/{usr_uid} - Se han implementado los siguientes features (behat): GET /api/1.0/{workspace}/group/{grp_uid}/users?filter={filter}&start={start}&limit={limit} GET /api/1.0/{workspace}/group/{grp_uid}/available-users?filter={filter}&start={start}&limit={limit} POST /api/1.0/{workspace}/group/{grp_uid}/user DELETE /api/1.0/{workspace}/group/{grp_uid}/user/{usr_uid} - Se han implementado los siguientes negative features (behat): POST /api/1.0/{workspace}/project/{prj_uid}/web-entry --- .../pm_group/basic_sequence_pm_group.feature | 118 +++++++++- .../basic_sequence_web_entry.feature | 27 +++ features/bootstrap/RestContext.php | 32 ++- workflow/engine/src/BusinessModel/Group.php | 18 +- .../engine/src/BusinessModel/Group/User.php | 206 ++++++++++++++++++ .../Services/Api/ProcessMaker/Group/User.php | 52 +++++ 6 files changed, 436 insertions(+), 17 deletions(-) create mode 100644 workflow/engine/src/BusinessModel/Group/User.php create mode 100644 workflow/engine/src/Services/Api/ProcessMaker/Group/User.php diff --git a/features/backend/pm_group/basic_sequence_pm_group.feature b/features/backend/pm_group/basic_sequence_pm_group.feature index 21a5b64a1..857af9624 100644 --- a/features/backend/pm_group/basic_sequence_pm_group.feature +++ b/features/backend/pm_group/basic_sequence_pm_group.feature @@ -3,7 +3,9 @@ Feature: Group Background: Given that I have a valid access_token - #GET /api/1.0/{workspace}/groups?filter=abc&start=0&limit=25 + #GROUP + + #GET /api/1.0/{workspace}/groups?filter={filter}&start={start}&limit={limit} # Get list Groups Scenario: Get list Groups And I request "groups?filter=for basic behat" @@ -56,7 +58,7 @@ Feature: Group | 0 | INACTIVE | | 1 | INACTIVE | - #GET /api/1.0/{workspace}/groups?filter=abc&start=0&limit=25 + #GET /api/1.0/{workspace}/groups?filter={filter}&start={start}&limit={limit} # Get list Groups Scenario Outline: Get list Groups And I request "groups?filter=for basic behat" @@ -108,7 +110,117 @@ Feature: Group | 0 | | 1 | - #GET /api/1.0/{workspace}/groups?filter=abc&start=0&limit=25 + #GET /api/1.0/{workspace}/groups?filter={filter}&start={start}&limit={limit} + # Get list Groups + Scenario: Get list Groups + And I request "groups?filter=for basic behat" + 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 + + #GROUP - USER + + #POST /api/1.0/{workspace}/group + # Create new Group + Scenario Outline: Create new Group + Given POST this data: + """ + { + "grp_title": "", + "grp_status": "" + } + """ + And I request "group" + 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 "grp_uid" in session array as variable "grp_uid" + + Examples: + | i | grp_title | grp_status | + | 0 | Demo Group1 for basic behat | ACTIVE | + + #POST /api/1.0/{workspace}/group/{grp_uid}/user + # Assign User to Group + Scenario Outline: Assign User to Group + Given POST this data: + """ + { + "usr_uid": "" + } + """ + And I request "group/grp_uid/user" with the key "grp_uid" stored in session array + 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" + + Examples: + | i | usr_uid | + | 0 | 00000000000000000000000000000001 | + + #GET /api/1.0/{workspace}/group/{grp_uid}/users?filter={filter}&start={start}&limit={limit} + # List assigned Users to Group + Scenario Outline: List assigned Users to Group + And I request "group/grp_uid/users" with the key "grp_uid" stored in session array + 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 "usr_uid" property in row equals "" + And the "usr_username" property in row equals "" + And the "usr_status" property in row equals "" + + Examples: + | i | usr_uid | usr_username | usr_status | + | 0 | 00000000000000000000000000000001 | admin | ACTIVE | + + #GET /api/1.0/{workspace}/group/{grp_uid}/available-users?filter={filter}&start={start}&limit={limit} + # List available Users to assign to Group + Scenario Outline: List available Users to assign to Group + And I request "group/grp_uid/available-users?filter=none" with the key "grp_uid" stored in session array + 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 + + Examples: + | i | + | 0 | + + #DELETE /api/1.0/{workspace}/group/{grp_uid}/user/{usr_uid} + # Unassign User of the Group + Scenario Outline: Unassign User of the Group + Given that I want to delete a resource with the key "obj_uid" stored in session array + And I request "group/grp_uid/user/" with the key "grp_uid" stored in session array + 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" + + Examples: + | i | usr_uid | + | 0 | 00000000000000000000000000000001 | + + #DELETE /api/1.0/{workspace}/group/{grp_uid} + # Delete Group + Scenario Outline: Delete Group + Given that I want to delete a resource with the key "grp_uid" stored in session array as variable "grp_uid" + And I request "group" + 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" + + Examples: + | i | + | 0 | + + #GET /api/1.0/{workspace}/groups?filter={filter}&start={start}&limit={limit} # Get list Groups Scenario: Get list Groups And I request "groups?filter=for basic behat" diff --git a/features/backend/web_entry/basic_sequence_web_entry.feature b/features/backend/web_entry/basic_sequence_web_entry.feature index d385dd901..3831fc024 100644 --- a/features/backend/web_entry/basic_sequence_web_entry.feature +++ b/features/backend/web_entry/basic_sequence_web_entry.feature @@ -146,6 +146,33 @@ Feature: Web Entry | 44199549652e66ba533bb06088252754 | Task 1 | 60308801852e66b7181ae21045247174 |DynaForm Demo1 | | 56118778152e66babcc2103002009439 | Task 2 | 99869771852e66b7dc4b858088901665 |DynaForm Demo2 | + #POST /api/1.0/{workspace}/project/{prj_uid}/web-entry + # Create a new Web Entry for a project + # Create a new Web Entry using the method: PHP pages with Web Services + Scenario Outline: Create a new Web Entry using the method: PHP pages with Web Services + Given POST this data: + """ + { + "tas_uid": "", + "dyn_uid": "", + "method": "WS", + "input_document_access": 1, + "usr_username": "admin", + "usr_password": "admin" + } + """ + And I request "project/28733629952e66a362c4f63066393844/web-entry" + And the content type is "application/json" + Then the response status code should be + And the response charset is "UTF-8" + And the type is "object" + And the response status message should have the following text "" + + Examples: + | tas_uid | tas_title | dyn_uid | dyn_title | status_code | status_message | + | 44199549652e66ba533bb06088252754 | Task 1 | 60308801852e66b7181ae21045247174 |DynaForm Demo1 | 400 | exist | + | 56118778152e66babcc2103002009439 | Task 2 | 99869771852e66b7dc4b858088901665 |DynaForm Demo2 | 400 | exist | + #DELETE /api/1.0/{workspace}/project/{prj_uid}/web-entry/{tas_uid}/{dyn_uid} # Delete a Web Entry of a Project Scenario Outline: Delete a Web Entry of a Project diff --git a/features/bootstrap/RestContext.php b/features/bootstrap/RestContext.php index 95e3cae34..dc793eb30 100644 --- a/features/bootstrap/RestContext.php +++ b/features/bootstrap/RestContext.php @@ -339,7 +339,7 @@ class RestContext extends BehatContext $this->_headers['Authorization'] = 'Bearer ' . $this->access_token; } - + if($urlType=="absolute"){ $this->_requestUrl = $pageUrl; }else{ @@ -361,7 +361,7 @@ class RestContext extends BehatContext $url .= $this->_restGetQueryStringSuffix; } $this->_request = $this->_client - ->get($url, $this->_headers); + ->get($url, $this->_headers); $this->_response = $this->_request->send(); break; case 'POST': @@ -1237,7 +1237,7 @@ class RestContext extends BehatContext $varValue = $sessionData->$sessionVarName; } - + $pageUrl = str_replace($varName, $varValue, $pageUrl); @@ -1275,4 +1275,28 @@ class RestContext extends BehatContext } } -} \ No newline at end of file + /** + * @When /^I request "([^"]*)" with the keys? "([^"]*)" stored in session array$/ + */ + public function iRequestWithTheKeysStoredInSessionArray($url, $sessionVarName) + { + if (file_exists("session.data")) { + $sessionData = json_decode(file_get_contents("session.data")); + } else { + $sessionData = array(); + } + + $arraySessionVarName = explode(",", $sessionVarName); + + foreach ($arraySessionVarName as $value) { + $varName = trim($value); + + $varValue = (isset($sessionData->$varName))? $sessionData->$varName : ""; + + $url = str_replace($varName, $varValue, $url); + } + + $this->iRequest($url); + } +} + diff --git a/workflow/engine/src/BusinessModel/Group.php b/workflow/engine/src/BusinessModel/Group.php index 71eead596..f335d6e23 100644 --- a/workflow/engine/src/BusinessModel/Group.php +++ b/workflow/engine/src/BusinessModel/Group.php @@ -227,10 +227,10 @@ class Group $arrayData = array_change_key_case($arrayData, CASE_UPPER); //Verify data - $this->throwExceptionIfNoExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]); - $process = new \BusinessModel\Process(); + $this->throwExceptionIfNoExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]); + $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, false); if (isset($arrayData["GRP_TITLE"])) { @@ -475,7 +475,7 @@ class Group $criteria = $this->getGroupCriteria(); if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") { - $criteria->add(\ContentPeer::CON_VALUE, "%" . trim($arrayFilterData["filter"]) . "%", \Criteria::LIKE); + $criteria->add(\ContentPeer::CON_VALUE, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE); } //Number records total @@ -616,12 +616,10 @@ class Group } if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") { - $filter = trim($arrayFilterData["filter"]); - $criteria->add( - $criteria->getNewCriterion(\UsersPeer::USR_USERNAME, "%" . $filter . "%", \Criteria::LIKE)->addOr( - $criteria->getNewCriterion(\UsersPeer::USR_FIRSTNAME, "%" . $filter . "%", \Criteria::LIKE)->addOr( - $criteria->getNewCriterion(\UsersPeer::USR_LASTNAME, "%" . $filter . "%", \Criteria::LIKE))) + $criteria->getNewCriterion(\UsersPeer::USR_USERNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr( + $criteria->getNewCriterion(\UsersPeer::USR_FIRSTNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr( + $criteria->getNewCriterion(\UsersPeer::USR_LASTNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE))) ); } @@ -673,10 +671,10 @@ class Group $arrayUser = array(); //Verify data - $this->throwExceptionIfNoExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]); - $process = new \BusinessModel\Process(); + $this->throwExceptionIfNoExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]); + $process->throwExceptionIfDataNotMetPagerVarDefinition(array("start" => $start, "limit" => $limit), $this->arrayFieldNameForException); //Get data diff --git a/workflow/engine/src/BusinessModel/Group/User.php b/workflow/engine/src/BusinessModel/Group/User.php new file mode 100644 index 000000000..6f453a323 --- /dev/null +++ b/workflow/engine/src/BusinessModel/Group/User.php @@ -0,0 +1,206 @@ + array("type" => "string", "required" => false, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "groupUid"), + "USR_UID" => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "userUid") + ); + + private $formatFieldNameInUppercase = true; + + private $arrayFieldNameForException = array(); + + /** + * 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; + } + } + + /** + * Set the format of the fields name (uppercase, lowercase) + * + * @param bool $flag Value that set the format + * + * return void + */ + public function setFormatFieldNameInUppercase($flag) + { + try { + $this->formatFieldNameInUppercase = $flag; + + $this->setArrayFieldNameForException($this->arrayFieldNameForException); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Set exception messages for fields + * + * @param array $arrayData Data with the fields + * + * return void + */ + public function setArrayFieldNameForException($arrayData) + { + try { + foreach ($arrayData as $key => $value) { + $this->arrayFieldNameForException[$key] = $this->getFieldNameByFormatFieldName($value); + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get the name of the field according to the format + * + * @param string $fieldName Field name + * + * return string Return the field name according the format + */ + public function getFieldNameByFormatFieldName($fieldName) + { + try { + return ($this->formatFieldNameInUppercase)? strtoupper($fieldName) : strtolower($fieldName); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Verify if doesn't exist the User in Group + * + * @param string $groupUid Unique id of Group + * @param string $userUid Unique id of User + * @param string $fieldNameForException Field name for the exception + * + * return void Throw exception if doesn't exist the User in Group + */ + public function throwExceptionIfNotExistsGroupUser($groupUid, $userUid, $fieldNameForException) + { + try { + $obj = \GroupUserPeer::retrieveByPK($groupUid, $userUid); + + if (!(is_object($obj) && get_class($obj) == "GroupUser")) { + $msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $userUid), "The user with {0}: {1}, is not assigned to the group"); + + throw (new \Exception($msg)); + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Verify if exists the User in Group + * + * @param string $groupUid Unique id of Group + * @param string $userUid Unique id of User + * @param string $fieldNameForException Field name for the exception + * + * return void Throw exception if exists the User in Group + */ + public function throwExceptionIfExistsGroupUser($groupUid, $userUid, $fieldNameForException) + { + try { + $obj = \GroupUserPeer::retrieveByPK($groupUid, $userUid); + + if (is_object($obj) && get_class($obj) == "GroupUser") { + $msg = str_replace(array("{0}", "{1}"), array($fieldNameForException, $userUid), "The user with {0}: {1}, is already assigned to the group"); + + throw (new \Exception($msg)); + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Assign User to Group + * + * @param string $groupUid Unique id of Group + * @param array $arrayData Data + * + * return array Return data of the User assigned to Group + */ + public function create($groupUid, $arrayData) + { + try { + $arrayData = array_change_key_case($arrayData, CASE_UPPER); + + unset($arrayData["GRP_UID"]); + + //Verify data + $process = new \BusinessModel\Process(); + $group = new \BusinessModel\Group(); + + $group->throwExceptionIfNoExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]); + + $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $this->arrayFieldDefinition, $this->arrayFieldNameForException, true); + + $process->throwExceptionIfNoExistsUser($arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]); + + $this->throwExceptionIfExistsGroupUser($groupUid, $arrayData["USR_UID"], $this->arrayFieldNameForException["userUid"]); + + //Create + $group = new \Groups(); + + $group->addUserToGroup($groupUid, $arrayData["USR_UID"]); + + //Return + $arrayData = array_merge(array("GRP_UID" => $groupUid), $arrayData); + + if (!$this->formatFieldNameInUppercase) { + $arrayData = array_change_key_case($arrayData, CASE_LOWER); + } + + return $arrayData; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Unassign User of the Group + * + * @param string $groupUid Unique id of Group + * @param string $userUid Unique id of User + * + * return void + */ + public function delete($groupUid, $userUid) + { + try { + //Verify data + $process = new \BusinessModel\Process(); + $group = new \BusinessModel\Group(); + + $group->throwExceptionIfNoExistsGroup($groupUid, $this->arrayFieldNameForException["groupUid"]); + + $process->throwExceptionIfNoExistsUser($userUid, $this->arrayFieldNameForException["userUid"]); + + $this->throwExceptionIfNotExistsGroupUser($groupUid, $userUid, $this->arrayFieldNameForException["userUid"]); + + //Delete + $group = new \Groups(); + + $group->removeUserOfGroup($groupUid, $userUid); + } catch (\Exception $e) { + throw $e; + } + } +} + diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Group/User.php b/workflow/engine/src/Services/Api/ProcessMaker/Group/User.php new file mode 100644 index 000000000..77c8132c3 --- /dev/null +++ b/workflow/engine/src/Services/Api/ProcessMaker/Group/User.php @@ -0,0 +1,52 @@ +setFormatFieldNameInUppercase(false); + + $arrayData = $groupUser->create($grp_uid, $request_data); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * @url DELETE /:grp_uid/user/:usr_uid + * + * @param string $grp_uid {@min 32}{@max 32} + * @param string $usr_uid {@min 32}{@max 32} + */ + public function doDeleteUser($grp_uid, $usr_uid) + { + try { + $groupUser = new \BusinessModel\Group\User(); + $groupUser->setFormatFieldNameInUppercase(false); + + $groupUser->delete($grp_uid, $usr_uid); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } +} +