diff --git a/features/backend/case_tracker/case_tracket.feature b/features/backend/case_tracker/basic_sequence.feature similarity index 100% rename from features/backend/case_tracker/case_tracket.feature rename to features/backend/case_tracker/basic_sequence.feature diff --git a/features/backend/input_documents_resources/basic_sequence.feature b/features/backend/input_documents_resources/basic_sequence.feature new file mode 100644 index 000000000..086df5755 --- /dev/null +++ b/features/backend/input_documents_resources/basic_sequence.feature @@ -0,0 +1,134 @@ +@ProcessMakerMichelangelo @RestAPI +Feature: Input Documents Resources + Background: + Given that I have a valid access_token + + #GET /api/1.0/{workspace}/project/{prj_uid}/input-documents + # Get a List Input Documents of a Project + Scenario: Get a List Input Documents of a Project + And I request "project/14414793652a5d718b65590036026581/input-documents" + 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}/input-document + # Create a new Input Document for a Project + Scenario: Create "My InputDocument1" for a Project + And POST this data: + """ + { + "inp_doc_title": "My InputDocument1", + "inp_doc_description": "My InputDocument1 DESCRIPTION", + "inp_doc_form_needed": "VIRTUAL", + "inp_doc_original": "ORIGINAL", + "inp_doc_published": "PRIVATE", + "inp_doc_versioning": 1, + "inp_doc_destination_path": "", + "inp_doc_tags": "INPUT" + } + """ + And I request "project/14414793652a5d718b65590036026581/input-document" + 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 "inp_doc_uid" in session array as variable "inp_doc_uid1" + + #POST /api/1.0/{workspace}/project/{prj_uid}/input-document + # Create a new Input Document for a Project + Scenario: Create "My InputDocument2" for a Project + And POST this data: + """ + { + "inp_doc_title": "My InputDocument2", + "inp_doc_description": "My InputDocument2 DESCRIPTION", + "inp_doc_form_needed": "VIRTUAL", + "inp_doc_original": "ORIGINAL", + "inp_doc_published": "PRIVATE", + "inp_doc_versioning": 1, + "inp_doc_destination_path": "", + "inp_doc_tags": "INPUT" + } + """ + And I request "project/14414793652a5d718b65590036026581/input-document" + 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 "inp_doc_uid" in session array as variable "inp_doc_uid2" + + #PUT /api/1.0/{workspace}/project/{prj_uid}/input-document/{inp_doc_uid} + # Update an Input Document for a Project + Scenario: Update an Input Document for a Project + And PUT this data: + """ + { + "inp_doc_title": "My InputDocument1 Modified", + "inp_doc_description": "My InputDocument1 DESCRIPTION Modified", + "inp_doc_form_needed": "VIRTUAL", + "inp_doc_original": "ORIGINAL", + "inp_doc_published": "PRIVATE" + } + """ + And that I want to update a resource with the key "inp_doc_uid1" stored in session array + And I request "project/14414793652a5d718b65590036026581/input-document" + 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" + + #GET /api/1.0/{workspace}/project/{prj_uid}/input-documents + # Get a List Input Documents of a Project + Scenario: Get a List Input Documents of a Project + And I request "project/14414793652a5d718b65590036026581/input-documents" + 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 "inp_doc_title" property in row 0 equals "My InputDocument1 Modified" + And the "inp_doc_description" property in row 0 equals "My InputDocument1 DESCRIPTION Modified" + + #GET /api/1.0/{workspace}/project/{prj_uid}/input-document/{inp_doc_uid} + # Get a single Input Document of a Project + Scenario: Get a single Input Document of a Project + And that I want to get a resource with the key "inp_doc_uid1" stored in session array + And I request "project/14414793652a5d718b65590036026581/input-document" + 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 "inp_doc_title" is set to "My InputDocument1 Modified" + And that "inp_doc_description" is set to "My InputDocument1 DESCRIPTION Modified" + + #DELETE /api/1.0/{workspace}/project/{prj_uid}/input-document/{inp_doc_uid} + # Delete an Input Document of a Project + Scenario: Delete a previously created Input Document + And that I want to delete a resource with the key "inp_doc_uid1" stored in session array + And I request "project/14414793652a5d718b65590036026581/input-document" + 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}/input-document/{inp_doc_uid} + # Delete an Input Document of a Project + Scenario: Delete a previously created Input Document + And that I want to delete a resource with the key "inp_doc_uid2" stored in session array + And I request "project/14414793652a5d718b65590036026581/input-document" + 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" + + #GET /api/1.0/{workspace}/project/{prj_uid}/input-documents + # Get a List Input Documents of a Project + Scenario: Get a List Input Documents of a Project + And I request "project/14414793652a5d718b65590036026581/input-documents" + 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/InputDocument.php b/workflow/engine/src/BusinessModel/InputDocument.php index c657422b2..563429540 100644 --- a/workflow/engine/src/BusinessModel/InputDocument.php +++ b/workflow/engine/src/BusinessModel/InputDocument.php @@ -3,34 +3,6 @@ namespace BusinessModel; class InputDocument { - /** - * Get data of unique ids of an InputDocument (Unique id of Process) - * - * @param string $inputDocumentUid Unique id of InputDocument - * - * return array - */ - public function getDataUids($inputDocumentUid) - { - try { - $criteria = new \Criteria("workflow"); - - $criteria->addSelectColumn(\InputDocumentPeer::PRO_UID); - $criteria->add(\InputDocumentPeer::INP_DOC_UID, $inputDocumentUid, \Criteria::EQUAL); - - $rsCriteria = \InputDocumentPeer::doSelectRS($criteria); - $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); - - if ($rsCriteria->next()) { - return $rsCriteria->getRow(); - } else { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($inputDocumentUid, "INPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}"))); - } - } catch (\Exception $e) { - throw $e; - } - } - /** * Verify if the title exists in the InputDocuments of Process * @@ -78,30 +50,6 @@ class InputDocument } } - /** - * Get data from a request data - * - * @param object $requestData Request data - * - * return array Return an array with data of request data - */ - public function getArrayDataFromRequestData($requestData) - { - try { - $arrayData = array(); - - $requestData = (array)($requestData); - - foreach ($requestData as $key => $value) { - $arrayData[$key] = $value; - } - - return $arrayData; - } catch (\Exception $e) { - throw $e; - } - } - /** * Create InputDocument for a Process * @@ -124,20 +72,43 @@ class InputDocument throw (new \Exception(str_replace(array("{0}", "{1}"), array($processUid, "PROCESS"), "The UID \"{0}\" doesn't exist in table {1}"))); } + if (!isset($arrayData["INP_DOC_TITLE"])) { + throw (new \Exception(str_replace(array("{0}"), array("INP_DOC_TITLE"), "The \"{0}\" attribute is not defined"))); + } + + if (isset($arrayData["INP_DOC_TITLE"]) && trim($arrayData["INP_DOC_TITLE"]) == "") { + throw (new \Exception(str_replace(array("{0}"), array("INP_DOC_TITLE"), "The \"{0}\" attribute is empty"))); + } + if (isset($arrayData["INP_DOC_TITLE"]) && $this->titleExists($processUid, $arrayData["INP_DOC_TITLE"])) { throw (new \Exception(\G::LoadTranslation("ID_INPUT_NOT_SAVE"))); } + //Flags + $flagDataDestinationPath = (isset($arrayData["INP_DOC_DESTINATION_PATH"]))? 1 : 0; + $flagDataTags = (isset($arrayData["INP_DOC_TAGS"]))? 1 : 0; + //Create - $inputdoc = new \InputDocument(); + $inputDocument = new \InputDocument(); $arrayData["PRO_UID"] = $processUid; - $inputDocumentUid = $inputdoc->create($arrayData); + $arrayData["INP_DOC_DESTINATION_PATH"] = ($flagDataDestinationPath == 1)? $arrayData["INP_DOC_DESTINATION_PATH"] : ""; + $arrayData["INP_DOC_TAGS"] = ($flagDataTags == 1)? $arrayData["INP_DOC_TAGS"] : ""; + + $inputDocumentUid = $inputDocument->create($arrayData); //Return unset($arrayData["PRO_UID"]); + if ($flagDataDestinationPath == 0) { + unset($arrayData["INP_DOC_DESTINATION_PATH"]); + } + + if ($flagDataTags == 0) { + unset($arrayData["INP_DOC_TAGS"]); + } + $arrayData = array_change_key_case($arrayData, CASE_LOWER); unset($arrayData["inp_doc_uid"]); @@ -161,19 +132,22 @@ class InputDocument try { $arrayData = array_change_key_case($arrayData, CASE_UPPER); - //Verify data - $inputdoc = new \InputDocument(); + $inputDocument = new \InputDocument(); - if (!$inputdoc->InputExists($inputDocumentUid)) { + $arrayInputDocumentData = $inputDocument->load($inputDocumentUid); + + //Uids + $processUid = $arrayInputDocumentData["PRO_UID"]; + + //Verify data + if (!$inputDocument->InputExists($inputDocumentUid)) { throw (new \Exception(str_replace(array("{0}", "{1}"), array($inputDocumentUid, "INPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}"))); } - //Uids - $arrayDataUid = $this->getDataUids($inputDocumentUid); + if (isset($arrayData["INP_DOC_TITLE"]) && trim($arrayData["INP_DOC_TITLE"]) == "") { + throw (new \Exception(str_replace(array("{0}"), array("INP_DOC_TITLE"), "The \"{0}\" attribute is empty"))); + } - $processUid = $arrayDataUid["PRO_UID"]; - - //Verify data if (isset($arrayData["INP_DOC_TITLE"]) && $this->titleExists($processUid, $arrayData["INP_DOC_TITLE"], $inputDocumentUid)) { throw (new \Exception(\G::LoadTranslation("ID_INPUT_NOT_SAVE"))); } @@ -181,7 +155,7 @@ class InputDocument //Update $arrayData["INP_DOC_UID"] = $inputDocumentUid; - $result = $inputdoc->update($arrayData); + $result = $inputDocument->update($arrayData); //Return unset($arrayData["INP_DOC_UID"]); @@ -203,9 +177,9 @@ class InputDocument { try { //Verify data - $inputdoc = new \InputDocument(); + $inputDocument = new \InputDocument(); - if (!$inputdoc->InputExists($inputDocumentUid)) { + if (!$inputDocument->InputExists($inputDocumentUid)) { throw (new \Exception(str_replace(array("{0}", "{1}"), array($inputDocumentUid, "INPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}"))); } @@ -226,9 +200,9 @@ class InputDocument } //InputDocument - $inputdoc = new \InputDocument(); + $inputDocument = new \InputDocument(); - $result = $inputdoc->remove($inputDocumentUid); + $result = $inputDocument->remove($inputDocumentUid); //Step $step = new \Step(); @@ -297,11 +271,11 @@ class InputDocument public function getInputDocumentDataFromRecord($record) { try { - $inputdoc = new \InputDocument(); - if ($record["INP_DOC_TITLE"] . "" == "") { + $inputDocument = new \InputDocument(); + //There is no transaltion for this Document name, try to get/regenerate the label - $arrayInputdocData = $inputdoc->load($record["INP_DOC_UID"]); + $arrayInputdocData = $inputDocument->load($record["INP_DOC_UID"]); $record["INP_DOC_TITLE"] = $arrayInputdocData["INP_DOC_TITLE"]; $record["INP_DOC_DESCRIPTION"] = $arrayInputdocData["INP_DOC_DESCRIPTION"]; @@ -334,9 +308,9 @@ class InputDocument { try { //Verify data - $inputdoc = new \InputDocument(); + $inputDocument = new \InputDocument(); - if (!$inputdoc->InputExists($inputDocumentUid)) { + if (!$inputDocument->InputExists($inputDocumentUid)) { throw (new \Exception(str_replace(array("{0}", "{1}"), array($inputDocumentUid, "INPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}"))); } diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project.php b/workflow/engine/src/Services/Api/ProcessMaker/Project.php index a15b82420..b5ac779e2 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project.php @@ -167,6 +167,8 @@ class Project extends Api /** * @url GET /:projectUid/input-documents + * + * @param string $projectUid {@min 32}{@max 32} */ public function doGetInputDocuments($projectUid) { diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/InputDocument.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/InputDocument.php index d11d4c75f..410a45acb 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project/InputDocument.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project/InputDocument.php @@ -13,6 +13,9 @@ class InputDocument extends Api { /** * @url GET /:projectUid/input-document/:inputDocumentUid + * + * @param string $inputDocumentUid {@min 32}{@max 32} + * @param string $projectUid {@min 32}{@max 32} */ public function doGetInputDocument($inputDocumentUid, $projectUid) { @@ -30,19 +33,35 @@ class InputDocument extends Api /** * @url POST /:projectUid/input-document * - * @param string $projectUid - * @param InputDocumentPostStructure $request_data + * @param string $projectUid {@min 32}{@max 32} + * @param array $request_data + * @param string $inp_doc_title {@from body} + * @param string $inp_doc_description {@from body} + * @param string $inp_doc_form_needed {@from body}{@choice VIRTUAL,REAL,VREAL} + * @param string $inp_doc_original {@from body}{@choice ORIGINAL,COPY} + * @param string $inp_doc_published {@from body}{@choice PRIVATE} + * @param int $inp_doc_versioning {@from body}{@choice 0,1} + * @param string $inp_doc_destination_path {@from body} + * @param string $inp_doc_tags {@from body} * * @status 201 */ - public function doPostInputDocument($projectUid, InputDocumentPostStructure $request_data = null) - { + public function doPostInputDocument( + $projectUid, + $request_data, + $inp_doc_title = "", + $inp_doc_description = "", + $inp_doc_form_needed = "VIRTUAL", + $inp_doc_original = "ORIGINAL", + $inp_doc_published = "PRIVATE", + $inp_doc_versioning = 0, + $inp_doc_destination_path = "", + $inp_doc_tags = "" + ) { try { $inputdoc = new \BusinessModel\InputDocument(); - $arrayData = $inputdoc->getArrayDataFromRequestData($request_data); - - $arrayData = $inputdoc->create($projectUid, $arrayData); + $arrayData = $inputdoc->create($projectUid, $request_data); $response = $arrayData; @@ -55,18 +74,35 @@ class InputDocument extends Api /** * @url PUT /:projectUid/input-document/:inputDocumentUid * - * @param string $inputDocumentUid - * @param string $projectUid - * @param InputDocumentPutStructure $request_data + * @param string $inputDocumentUid {@min 32}{@max 32} + * @param string $projectUid {@min 32}{@max 32} + * @param array $request_data + * @param string $inp_doc_title {@from body} + * @param string $inp_doc_description {@from body} + * @param string $inp_doc_form_needed {@from body}{@choice VIRTUAL,REAL,VREAL} + * @param string $inp_doc_original {@from body}{@choice ORIGINAL,COPY} + * @param string $inp_doc_published {@from body}{@choice PRIVATE} + * @param int $inp_doc_versioning {@from body}{@choice 0,1} + * @param string $inp_doc_destination_path {@from body} + * @param string $inp_doc_tags {@from body} */ - public function doPutInputDocument($inputDocumentUid, $projectUid, InputDocumentPutStructure $request_data = null) - { + public function doPutInputDocument( + $inputDocumentUid, + $projectUid, + $request_data, + $inp_doc_title = "", + $inp_doc_description = "", + $inp_doc_form_needed = "VIRTUAL", + $inp_doc_original = "ORIGINAL", + $inp_doc_published = "PRIVATE", + $inp_doc_versioning = 0, + $inp_doc_destination_path = "", + $inp_doc_tags = "" + ) { try { $inputdoc = new \BusinessModel\InputDocument(); - $arrayData = $inputdoc->getArrayDataFromRequestData($request_data); - - $arrayData = $inputdoc->update($inputDocumentUid, $arrayData); + $arrayData = $inputdoc->update($inputDocumentUid, $request_data); } catch (\Exception $e) { throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); } @@ -74,6 +110,9 @@ class InputDocument extends Api /** * @url DELETE /:projectUid/input-document/:inputDocumentUid + * + * @param string $inputDocumentUid {@min 32}{@max 32} + * @param string $projectUid {@min 32}{@max 32} */ public function doDeleteInputDocument($inputDocumentUid, $projectUid) { @@ -87,89 +126,3 @@ class InputDocument extends Api } } -class InputDocumentPostStructure -{ - /** - * @var string {@from body}{@required true} - */ - public $inp_doc_title; - - /** - * @var string {@from body} - */ - public $inp_doc_description; - - /** - * @var string {@from body}{@choice VIRTUAL,REAL,VREAL} - */ - public $inp_doc_form_needed; - - /** - * @var string {@from body}{@choice ORIGINAL,COPY} - */ - public $inp_doc_original; - - /** - * @var string {@from body}{@choice PRIVATE} - */ - public $inp_doc_published; - - /** - * @var int {@from body}{@choice 0,1} - */ - public $inp_doc_versioning; - - /** - * @var string {@from body} - */ - public $inp_doc_destination_path; - - /** - * @var string {@from body} - */ - public $inp_doc_tags; -} - -class InputDocumentPutStructure -{ - /** - * @var string {@from body} - */ - public $inp_doc_title; - - /** - * @var string {@from body} - */ - public $inp_doc_description; - - /** - * @var string {@from body}{@choice VIRTUAL,REAL,VREAL} - */ - public $inp_doc_form_needed; - - /** - * @var string {@from body}{@choice ORIGINAL,COPY} - */ - public $inp_doc_original; - - /** - * @var string {@from body}{@choice PRIVATE} - */ - public $inp_doc_published; - - /** - * @var int {@from body}{@choice 0,1} - */ - public $inp_doc_versioning; - - /** - * @var string {@from body} - */ - public $inp_doc_destination_path; - - /** - * @var string {@from body} - */ - public $inp_doc_tags; -} -