From 3c7390d38becdc60402f7e54298c746098551e17 Mon Sep 17 00:00:00 2001 From: Victor Saisa Lopez Date: Fri, 13 Dec 2013 12:57:02 -0400 Subject: [PATCH 1/3] ProcessMaker-MA "Input Documents Resources" - Se ha implementado los siguientes Endpoints: GET * /api/1.0/{workspace}/project/{prj_uid}/input-documents GET * /api/1.0/{workspace}/project/{prj_uid}/input-document/{inp_doc_uid} POST * /api/1.0/{workspace}/project/{prj_uid}/input-document PUT * /api/1.0/{workspace}/project/{prj_uid}/input-document/{inp_doc_uid} DELETE /api/1.0/{workspace}/project/{prj_uid}/input-document/{inp_doc_uid} Para los Endpoints con *, se ha corregido los siguientes atributos: - "out_doc_form_needed" se a cambiado por "inp_doc_form_needed" - "inp_doc_versionning" se a cambiado por "inp_doc_versioning" --- .../src/BusinessModel/Inputdocument.php | 361 ++++++++++++++++++ workflow/engine/src/BusinessModel/Process.php | 42 ++ .../src/Services/Api/ProcessMaker/Project.php | 17 + .../ProcessMaker/Project/Inputdocument.php | 175 +++++++++ workflow/engine/src/Services/api.ini | 2 + 5 files changed, 597 insertions(+) create mode 100644 workflow/engine/src/BusinessModel/Inputdocument.php create mode 100644 workflow/engine/src/Services/Api/ProcessMaker/Project/Inputdocument.php diff --git a/workflow/engine/src/BusinessModel/Inputdocument.php b/workflow/engine/src/BusinessModel/Inputdocument.php new file mode 100644 index 000000000..354855e69 --- /dev/null +++ b/workflow/engine/src/BusinessModel/Inputdocument.php @@ -0,0 +1,361 @@ +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; + } + } + + /** + * Checks if the title exists in the InputDocuments of Process + * + * @param string $processUid Unique id of Process + * @param string $title Title + * @param string $inputDocumentUidExclude Unique id of InputDocument to exclude + * + * return bool Return true if the title exists in the InputDocuments of Process, false otherwise + */ + public function existsTitle($processUid, $title, $inputDocumentUidExclude = "") + { + try { + $delimiter = \DBAdapter::getStringDelimiter(); + + $criteria = new \Criteria("workflow"); + + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_UID); + + $criteria->addAlias("CT", "CONTENT"); + + $arrayCondition = array(); + $arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CT.CON_ID", \Criteria::EQUAL); + $arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "INP_DOC_TITLE" . $delimiter, \Criteria::EQUAL); + $arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL); + $criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN); + + $criteria->add(\InputDocumentPeer::PRO_UID, $processUid, \Criteria::EQUAL); + + if ($inputDocumentUidExclude != "") { + $criteria->add(\InputDocumentPeer::INP_DOC_UID, $inputDocumentUidExclude, \Criteria::NOT_EQUAL); + } + + $criteria->add("CT.CON_VALUE", $title, \Criteria::EQUAL); + + $rsCriteria = \InputDocumentPeer::doSelectRS($criteria); + $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + + if ($rsCriteria->next()) { + return true; + } else { + return false; + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * 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) { + //if ($value . "" != "") { + $arrayData[$key] = $value; + //} + } + + return $arrayData; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Create InputDocument for a Process + * + * @param string $processUid Unique id of Process + * @param array $arrayData Data + * + * return array Return data of the new InputDocument created + */ + public function create($processUid, $arrayData) + { + try { + $arrayData = array_change_key_case($arrayData, CASE_UPPER); + + unset($arrayData["INP_DOC_UID"]); + + //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}"))); + } + + if (isset($arrayData["INP_DOC_TITLE"]) && $this->existsTitle($processUid, $arrayData["INP_DOC_TITLE"])) { + throw (new \Exception(\G::LoadTranslation("ID_INPUT_NOT_SAVE"))); + } + + //Create + $inputdoc = new \InputDocument(); + + $arrayData["PRO_UID"] = $processUid; + + $inputDocumentUid = $inputdoc->create($arrayData); + + //Return + unset($arrayData["PRO_UID"]); + + $arrayData = array_change_key_case($arrayData, CASE_LOWER); + + $arrayData["inp_doc_uid"] = $inputDocumentUid; + + return $arrayData; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Update InputDocument + * + * @param string $inputDocumentUid Unique id of InputDocument + * @param array $arrayData Data + * + * return array Return data of the InputDocument updated + */ + public function update($inputDocumentUid, $arrayData) + { + try { + $arrayData = array_change_key_case($arrayData, CASE_UPPER); + + //Verify data + $inputdoc = new \InputDocument(); + + if (!$inputdoc->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); + + $processUid = $arrayDataUid["PRO_UID"]; + + //Verify data + if (isset($arrayData["INP_DOC_TITLE"]) && $this->existsTitle($processUid, $arrayData["INP_DOC_TITLE"], $inputDocumentUid)) { + throw (new \Exception(\G::LoadTranslation("ID_INPUT_NOT_SAVE"))); + } + + //Update + $arrayData["INP_DOC_UID"] = $inputDocumentUid; + + $result = $inputdoc->update($arrayData); + + //Return + unset($arrayData["INP_DOC_UID"]); + + return array_change_key_case($arrayData, CASE_LOWER); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Delete InputDocument + * + * @param string $inputDocumentUid Unique id of InputDocument + * + * return void + */ + public function delete($inputDocumentUid) + { + try { + //Verify data + $inputdoc = new \InputDocument(); + + if (!$inputdoc->InputExists($inputDocumentUid)) { + throw (new \Exception(str_replace(array("{0}", "{1}"), array($inputDocumentUid, "INPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}"))); + } + + //Delete + //StepSupervisor + $stepSupervisor = new \StepSupervisor(); + + $arrayData = $stepSupervisor->loadInfo($inputDocumentUid); + $result = $stepSupervisor->remove($arrayData["STEP_UID"]); + + //ObjectPermission + $objectPermission = new \ObjectPermission(); + + $arrayData = $objectPermission->loadInfo($inputDocumentUid); + + if (is_array($arrayData)) { + $result = $objectPermission->remove($arrayData["OP_UID"]); + } + + //InputDocument + $inputdoc = new \InputDocument(); + + $result = $inputdoc->remove($inputDocumentUid); + + //Step + $step = new \Step(); + + $step->removeStep("INPUT_DOCUMENT", $inputDocumentUid); + + //ObjectPermission + $objectPermission = new \ObjectPermission(); + + $objectPermission->removeByObject("INPUT", $inputDocumentUid); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get criteria for InputDocument + * + * return object + */ + public function getInputDocumentCriteria() + { + try { + $delimiter = \DBAdapter::getStringDelimiter(); + + $criteria = new \Criteria("workflow"); + + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_UID); + $criteria->addAsColumn("INP_DOC_TITLE", "CT.CON_VALUE"); + $criteria->addAsColumn("INP_DOC_DESCRIPTION", "CD.CON_VALUE"); + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_FORM_NEEDED); + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_ORIGINAL); + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_PUBLISHED); + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_VERSIONING); + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_DESTINATION_PATH); + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_TAGS); + + $criteria->addAlias("CT", "CONTENT"); + $criteria->addAlias("CD", "CONTENT"); + + $arrayCondition = array(); + $arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CT.CON_ID", \Criteria::EQUAL); + $arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "INP_DOC_TITLE" . $delimiter, \Criteria::EQUAL); + $arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL); + $criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN); + + $arrayCondition = array(); + $arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CD.CON_ID", \Criteria::EQUAL); + $arrayCondition[] = array("CD.CON_CATEGORY", $delimiter . "INP_DOC_DESCRIPTION" . $delimiter, \Criteria::EQUAL); + $arrayCondition[] = array("CD.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL); + $criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN); + + return $criteria; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get data of an InputDocument from a record + * + * @param array $record Record + * + * return array Return an array with data of an InputDocument + */ + public function getInputDocumentDataFromRecord($record) + { + try { + return array( + "inp_doc_uid" => $record["INP_DOC_UID"], + "inp_doc_title" => $record["INP_DOC_TITLE"], + "inp_doc_description" => $record["INP_DOC_DESCRIPTION"] . "", + "inp_doc_form_needed" => $record["INP_DOC_FORM_NEEDED"], + "inp_doc_original" => $record["INP_DOC_ORIGINAL"], + "inp_doc_published" => $record["INP_DOC_PUBLISHED"], + "inp_doc_versioning" => (int)($record["INP_DOC_VERSIONING"]), + "inp_doc_destination_path" => $record["INP_DOC_DESTINATION_PATH"] . "", + "inp_doc_tags" => $record["INP_DOC_TAGS"] . "" + ); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get data of an InputDocument + * + * @param string $inputDocumentUid Unique id of InputDocument + * + * return array Return an array with data of an InputDocument + */ + public function getInputDocument($inputDocumentUid) + { + try { + //Verify data + $inputdoc = new \InputDocument(); + + if (!$inputdoc->InputExists($inputDocumentUid)) { + throw (new \Exception(str_replace(array("{0}", "{1}"), array($inputDocumentUid, "INPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}"))); + } + + //Get data + $criteria = $this->getInputDocumentCriteria(); + + $criteria->add(\InputDocumentPeer::INP_DOC_UID, $inputDocumentUid, \Criteria::EQUAL); + + $rsCriteria = \InputDocumentPeer::doSelectRS($criteria); + $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + + $rsCriteria->next(); + + $row = $rsCriteria->getRow(); + + if ($row["INP_DOC_TITLE"] . "" == "") { + //There is no transaltion for this Document name, try to get/regenerate the label + $arrayInputdocData = $inputdoc->load($inputDocumentUid); + + $row["INP_DOC_TITLE"] = $arrayInputdocData["INP_DOC_TITLE"]; + $row["INP_DOC_DESCRIPTION"] = $arrayInputdocData["INP_DOC_DESCRIPTION"]; + } + + return $this->getInputDocumentDataFromRecord($row); + } catch (\Exception $e) { + throw $e; + } + } +} + diff --git a/workflow/engine/src/BusinessModel/Process.php b/workflow/engine/src/BusinessModel/Process.php index e163d804c..c0c8bcb1d 100644 --- a/workflow/engine/src/BusinessModel/Process.php +++ b/workflow/engine/src/BusinessModel/Process.php @@ -509,5 +509,47 @@ class Process return $processMap->deleteProcess($processUid); } + + /** + * Get all InputDocuments of a Process + * + * @param string $processUid Unique id of Process + * + * return array Return an array with all InputDocuments of a Process + */ + public function getInputDocuments($processUid) + { + 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}"))); + } + + //Get data + $arrayInputDocument = array(); + + $inputdoc = new \BusinessModel\Inputdocument(); + + $criteria = $inputdoc->getInputDocumentCriteria(); + + $criteria->add(\InputDocumentPeer::PRO_UID, $processUid, \Criteria::EQUAL); + $criteria->addAscendingOrderByColumn("INP_DOC_TITLE"); + + $rsCriteria = \InputDocumentPeer::doSelectRS($criteria); + $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + + while ($rsCriteria->next()) { + $row = $rsCriteria->getRow(); + + $arrayInputDocument[] = $inputdoc->getInputDocumentDataFromRecord($row); + } + + return $arrayInputDocument; + } catch (\Exception $e) { + throw $e; + } + } } diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project.php b/workflow/engine/src/Services/Api/ProcessMaker/Project.php index a83a9760e..b3c097fb8 100644 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project.php +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project.php @@ -57,4 +57,21 @@ class Project extends Api throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); } } + + /** + * @url GET /:projectUid/input-documents + */ + public function doGetInputDocuments($projectUid) + { + try { + $process = new \BusinessModel\Process(); + + $response = $process->getInputDocuments($projectUid); + + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } } + diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/Inputdocument.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/Inputdocument.php new file mode 100644 index 000000000..02d1eaecb --- /dev/null +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project/Inputdocument.php @@ -0,0 +1,175 @@ +getInputDocument($inputDocumentUid); + + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * @url POST /:projectUid/input-document + * + * @param string $projectUid + * @param InputdocumentPostStructure $request_data + * + * @status 201 + */ + public function doPostInputDocument($projectUid, InputdocumentPostStructure $request_data = null) + { + try { + $inputdoc = new \BusinessModel\Inputdocument(); + + $arrayData = $inputdoc->getArrayDataFromRequestData($request_data); + + $arrayData = $inputdoc->create($projectUid, $arrayData); + + $response = $arrayData; + + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * @url PUT /:projectUid/input-document/:inputDocumentUid + * + * @param string $inputDocumentUid + * @param string $projectUid + * @param InputdocumentPutStructure $request_data + */ + public function doPutInputDocument($inputDocumentUid, $projectUid, InputdocumentPutStructure $request_data = null) + { + try { + $inputdoc = new \BusinessModel\Inputdocument(); + + $arrayData = $inputdoc->getArrayDataFromRequestData($request_data); + + $arrayData = $inputdoc->update($inputDocumentUid, $arrayData); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * @url DELETE /:projectUid/input-document/:inputDocumentUid + */ + public function doDeleteInputDocument($inputDocumentUid, $projectUid) + { + try { + $inputdoc = new \BusinessModel\Inputdocument(); + + $inputdoc->delete($inputDocumentUid); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } +} + +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; +} + diff --git a/workflow/engine/src/Services/api.ini b/workflow/engine/src/Services/api.ini index c0ca23507..8322f3be6 100644 --- a/workflow/engine/src/Services/api.ini +++ b/workflow/engine/src/Services/api.ini @@ -19,6 +19,8 @@ debug = 1 trigger = "Services\Api\ProcessMaker\Project\Activity\Step\Trigger" project = "Services\Api\ProcessMaker\Project" trigger2 = "Services\Api\ProcessMaker\Project\Trigger" + input-document = "Services\Api\ProcessMaker\Project\Inputdocument" [alias: projects] project = "Services\Api\ProcessMaker\Project" + From 6aee3c17679b8d1696da50a0bd156e66fb5e19f9 Mon Sep 17 00:00:00 2001 From: Victor Saisa Lopez Date: Mon, 16 Dec 2013 11:40:15 -0400 Subject: [PATCH 2/3] ProcessMaker-MA "Input Documents Resources (endpoints)" - Se han implementado los siguientes Endpoints: GET * /api/1.0/{workspace}/project/{prj_uid}/input-documents GET * /api/1.0/{workspace}/project/{prj_uid}/input-document/{inp_doc_uid} POST * /api/1.0/{workspace}/project/{prj_uid}/input-document PUT * /api/1.0/{workspace}/project/{prj_uid}/input-document/{inp_doc_uid} DELETE /api/1.0/{workspace}/project/{prj_uid}/input-document/{inp_doc_uid} Para los Endpoints con *, se ha corregido los siguientes atributos: - "out_doc_form_needed" se a cambiado por "inp_doc_form_needed" - "inp_doc_versionning" se a cambiado por "inp_doc_versioning" --- .../src/BusinessModel/Inputdocument.php | 361 ------------------ workflow/engine/src/BusinessModel/Process.php | 2 +- .../ProcessMaker/Project/Inputdocument.php | 175 --------- workflow/engine/src/Services/api.ini | 2 +- 4 files changed, 2 insertions(+), 538 deletions(-) delete mode 100644 workflow/engine/src/BusinessModel/Inputdocument.php delete mode 100644 workflow/engine/src/Services/Api/ProcessMaker/Project/Inputdocument.php diff --git a/workflow/engine/src/BusinessModel/Inputdocument.php b/workflow/engine/src/BusinessModel/Inputdocument.php deleted file mode 100644 index 354855e69..000000000 --- a/workflow/engine/src/BusinessModel/Inputdocument.php +++ /dev/null @@ -1,361 +0,0 @@ -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; - } - } - - /** - * Checks if the title exists in the InputDocuments of Process - * - * @param string $processUid Unique id of Process - * @param string $title Title - * @param string $inputDocumentUidExclude Unique id of InputDocument to exclude - * - * return bool Return true if the title exists in the InputDocuments of Process, false otherwise - */ - public function existsTitle($processUid, $title, $inputDocumentUidExclude = "") - { - try { - $delimiter = \DBAdapter::getStringDelimiter(); - - $criteria = new \Criteria("workflow"); - - $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_UID); - - $criteria->addAlias("CT", "CONTENT"); - - $arrayCondition = array(); - $arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CT.CON_ID", \Criteria::EQUAL); - $arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "INP_DOC_TITLE" . $delimiter, \Criteria::EQUAL); - $arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL); - $criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN); - - $criteria->add(\InputDocumentPeer::PRO_UID, $processUid, \Criteria::EQUAL); - - if ($inputDocumentUidExclude != "") { - $criteria->add(\InputDocumentPeer::INP_DOC_UID, $inputDocumentUidExclude, \Criteria::NOT_EQUAL); - } - - $criteria->add("CT.CON_VALUE", $title, \Criteria::EQUAL); - - $rsCriteria = \InputDocumentPeer::doSelectRS($criteria); - $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); - - if ($rsCriteria->next()) { - return true; - } else { - return false; - } - } catch (\Exception $e) { - throw $e; - } - } - - /** - * 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) { - //if ($value . "" != "") { - $arrayData[$key] = $value; - //} - } - - return $arrayData; - } catch (\Exception $e) { - throw $e; - } - } - - /** - * Create InputDocument for a Process - * - * @param string $processUid Unique id of Process - * @param array $arrayData Data - * - * return array Return data of the new InputDocument created - */ - public function create($processUid, $arrayData) - { - try { - $arrayData = array_change_key_case($arrayData, CASE_UPPER); - - unset($arrayData["INP_DOC_UID"]); - - //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}"))); - } - - if (isset($arrayData["INP_DOC_TITLE"]) && $this->existsTitle($processUid, $arrayData["INP_DOC_TITLE"])) { - throw (new \Exception(\G::LoadTranslation("ID_INPUT_NOT_SAVE"))); - } - - //Create - $inputdoc = new \InputDocument(); - - $arrayData["PRO_UID"] = $processUid; - - $inputDocumentUid = $inputdoc->create($arrayData); - - //Return - unset($arrayData["PRO_UID"]); - - $arrayData = array_change_key_case($arrayData, CASE_LOWER); - - $arrayData["inp_doc_uid"] = $inputDocumentUid; - - return $arrayData; - } catch (\Exception $e) { - throw $e; - } - } - - /** - * Update InputDocument - * - * @param string $inputDocumentUid Unique id of InputDocument - * @param array $arrayData Data - * - * return array Return data of the InputDocument updated - */ - public function update($inputDocumentUid, $arrayData) - { - try { - $arrayData = array_change_key_case($arrayData, CASE_UPPER); - - //Verify data - $inputdoc = new \InputDocument(); - - if (!$inputdoc->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); - - $processUid = $arrayDataUid["PRO_UID"]; - - //Verify data - if (isset($arrayData["INP_DOC_TITLE"]) && $this->existsTitle($processUid, $arrayData["INP_DOC_TITLE"], $inputDocumentUid)) { - throw (new \Exception(\G::LoadTranslation("ID_INPUT_NOT_SAVE"))); - } - - //Update - $arrayData["INP_DOC_UID"] = $inputDocumentUid; - - $result = $inputdoc->update($arrayData); - - //Return - unset($arrayData["INP_DOC_UID"]); - - return array_change_key_case($arrayData, CASE_LOWER); - } catch (\Exception $e) { - throw $e; - } - } - - /** - * Delete InputDocument - * - * @param string $inputDocumentUid Unique id of InputDocument - * - * return void - */ - public function delete($inputDocumentUid) - { - try { - //Verify data - $inputdoc = new \InputDocument(); - - if (!$inputdoc->InputExists($inputDocumentUid)) { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($inputDocumentUid, "INPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}"))); - } - - //Delete - //StepSupervisor - $stepSupervisor = new \StepSupervisor(); - - $arrayData = $stepSupervisor->loadInfo($inputDocumentUid); - $result = $stepSupervisor->remove($arrayData["STEP_UID"]); - - //ObjectPermission - $objectPermission = new \ObjectPermission(); - - $arrayData = $objectPermission->loadInfo($inputDocumentUid); - - if (is_array($arrayData)) { - $result = $objectPermission->remove($arrayData["OP_UID"]); - } - - //InputDocument - $inputdoc = new \InputDocument(); - - $result = $inputdoc->remove($inputDocumentUid); - - //Step - $step = new \Step(); - - $step->removeStep("INPUT_DOCUMENT", $inputDocumentUid); - - //ObjectPermission - $objectPermission = new \ObjectPermission(); - - $objectPermission->removeByObject("INPUT", $inputDocumentUid); - } catch (\Exception $e) { - throw $e; - } - } - - /** - * Get criteria for InputDocument - * - * return object - */ - public function getInputDocumentCriteria() - { - try { - $delimiter = \DBAdapter::getStringDelimiter(); - - $criteria = new \Criteria("workflow"); - - $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_UID); - $criteria->addAsColumn("INP_DOC_TITLE", "CT.CON_VALUE"); - $criteria->addAsColumn("INP_DOC_DESCRIPTION", "CD.CON_VALUE"); - $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_FORM_NEEDED); - $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_ORIGINAL); - $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_PUBLISHED); - $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_VERSIONING); - $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_DESTINATION_PATH); - $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_TAGS); - - $criteria->addAlias("CT", "CONTENT"); - $criteria->addAlias("CD", "CONTENT"); - - $arrayCondition = array(); - $arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CT.CON_ID", \Criteria::EQUAL); - $arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "INP_DOC_TITLE" . $delimiter, \Criteria::EQUAL); - $arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL); - $criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN); - - $arrayCondition = array(); - $arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CD.CON_ID", \Criteria::EQUAL); - $arrayCondition[] = array("CD.CON_CATEGORY", $delimiter . "INP_DOC_DESCRIPTION" . $delimiter, \Criteria::EQUAL); - $arrayCondition[] = array("CD.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL); - $criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN); - - return $criteria; - } catch (\Exception $e) { - throw $e; - } - } - - /** - * Get data of an InputDocument from a record - * - * @param array $record Record - * - * return array Return an array with data of an InputDocument - */ - public function getInputDocumentDataFromRecord($record) - { - try { - return array( - "inp_doc_uid" => $record["INP_DOC_UID"], - "inp_doc_title" => $record["INP_DOC_TITLE"], - "inp_doc_description" => $record["INP_DOC_DESCRIPTION"] . "", - "inp_doc_form_needed" => $record["INP_DOC_FORM_NEEDED"], - "inp_doc_original" => $record["INP_DOC_ORIGINAL"], - "inp_doc_published" => $record["INP_DOC_PUBLISHED"], - "inp_doc_versioning" => (int)($record["INP_DOC_VERSIONING"]), - "inp_doc_destination_path" => $record["INP_DOC_DESTINATION_PATH"] . "", - "inp_doc_tags" => $record["INP_DOC_TAGS"] . "" - ); - } catch (\Exception $e) { - throw $e; - } - } - - /** - * Get data of an InputDocument - * - * @param string $inputDocumentUid Unique id of InputDocument - * - * return array Return an array with data of an InputDocument - */ - public function getInputDocument($inputDocumentUid) - { - try { - //Verify data - $inputdoc = new \InputDocument(); - - if (!$inputdoc->InputExists($inputDocumentUid)) { - throw (new \Exception(str_replace(array("{0}", "{1}"), array($inputDocumentUid, "INPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}"))); - } - - //Get data - $criteria = $this->getInputDocumentCriteria(); - - $criteria->add(\InputDocumentPeer::INP_DOC_UID, $inputDocumentUid, \Criteria::EQUAL); - - $rsCriteria = \InputDocumentPeer::doSelectRS($criteria); - $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); - - $rsCriteria->next(); - - $row = $rsCriteria->getRow(); - - if ($row["INP_DOC_TITLE"] . "" == "") { - //There is no transaltion for this Document name, try to get/regenerate the label - $arrayInputdocData = $inputdoc->load($inputDocumentUid); - - $row["INP_DOC_TITLE"] = $arrayInputdocData["INP_DOC_TITLE"]; - $row["INP_DOC_DESCRIPTION"] = $arrayInputdocData["INP_DOC_DESCRIPTION"]; - } - - return $this->getInputDocumentDataFromRecord($row); - } catch (\Exception $e) { - throw $e; - } - } -} - diff --git a/workflow/engine/src/BusinessModel/Process.php b/workflow/engine/src/BusinessModel/Process.php index c0c8bcb1d..38e7c473e 100644 --- a/workflow/engine/src/BusinessModel/Process.php +++ b/workflow/engine/src/BusinessModel/Process.php @@ -530,7 +530,7 @@ class Process //Get data $arrayInputDocument = array(); - $inputdoc = new \BusinessModel\Inputdocument(); + $inputdoc = new \BusinessModel\InputDocument(); $criteria = $inputdoc->getInputDocumentCriteria(); diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/Inputdocument.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/Inputdocument.php deleted file mode 100644 index 02d1eaecb..000000000 --- a/workflow/engine/src/Services/Api/ProcessMaker/Project/Inputdocument.php +++ /dev/null @@ -1,175 +0,0 @@ -getInputDocument($inputDocumentUid); - - return $response; - } catch (\Exception $e) { - throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); - } - } - - /** - * @url POST /:projectUid/input-document - * - * @param string $projectUid - * @param InputdocumentPostStructure $request_data - * - * @status 201 - */ - public function doPostInputDocument($projectUid, InputdocumentPostStructure $request_data = null) - { - try { - $inputdoc = new \BusinessModel\Inputdocument(); - - $arrayData = $inputdoc->getArrayDataFromRequestData($request_data); - - $arrayData = $inputdoc->create($projectUid, $arrayData); - - $response = $arrayData; - - return $response; - } catch (\Exception $e) { - throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); - } - } - - /** - * @url PUT /:projectUid/input-document/:inputDocumentUid - * - * @param string $inputDocumentUid - * @param string $projectUid - * @param InputdocumentPutStructure $request_data - */ - public function doPutInputDocument($inputDocumentUid, $projectUid, InputdocumentPutStructure $request_data = null) - { - try { - $inputdoc = new \BusinessModel\Inputdocument(); - - $arrayData = $inputdoc->getArrayDataFromRequestData($request_data); - - $arrayData = $inputdoc->update($inputDocumentUid, $arrayData); - } catch (\Exception $e) { - throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); - } - } - - /** - * @url DELETE /:projectUid/input-document/:inputDocumentUid - */ - public function doDeleteInputDocument($inputDocumentUid, $projectUid) - { - try { - $inputdoc = new \BusinessModel\Inputdocument(); - - $inputdoc->delete($inputDocumentUid); - } catch (\Exception $e) { - throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); - } - } -} - -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; -} - diff --git a/workflow/engine/src/Services/api.ini b/workflow/engine/src/Services/api.ini index 14ac7f21e..3f8527e19 100644 --- a/workflow/engine/src/Services/api.ini +++ b/workflow/engine/src/Services/api.ini @@ -19,7 +19,7 @@ debug = 1 trigger = "Services\Api\ProcessMaker\Project\Activity\Step\Trigger" project = "Services\Api\ProcessMaker\Project" trigger2 = "Services\Api\ProcessMaker\Project\Trigger" - input-document = "Services\Api\ProcessMaker\Project\Inputdocument" + input-document = "Services\Api\ProcessMaker\Project\InputDocument" output-documents = "Services\Api\ProcessMaker\Project\OutputDocuments" [alias: projects] From 7252fbdd402168ea03f1a57076075880251cacae Mon Sep 17 00:00:00 2001 From: Victor Saisa Lopez Date: Mon, 16 Dec 2013 11:59:47 -0400 Subject: [PATCH 3/3] ProcessMaker-MA "Input Documents Resources (endpoints)" - Se han implementado los siguientes Endpoints: GET * /api/1.0/{workspace}/project/{prj_uid}/input-documents GET * /api/1.0/{workspace}/project/{prj_uid}/input-document/{inp_doc_uid} POST * /api/1.0/{workspace}/project/{prj_uid}/input-document PUT * /api/1.0/{workspace}/project/{prj_uid}/input-document/{inp_doc_uid} DELETE /api/1.0/{workspace}/project/{prj_uid}/input-document/{inp_doc_uid} Para los Endpoints con *, se ha corregido los siguientes atributos: - "out_doc_form_needed" se a cambiado por "inp_doc_form_needed" - "inp_doc_versionning" se a cambiado por "inp_doc_versioning" --- .../src/BusinessModel/InputDocument.php | 359 ++++++++++++++++++ .../ProcessMaker/Project/InputDocument.php | 175 +++++++++ 2 files changed, 534 insertions(+) create mode 100644 workflow/engine/src/BusinessModel/InputDocument.php create mode 100644 workflow/engine/src/Services/Api/ProcessMaker/Project/InputDocument.php diff --git a/workflow/engine/src/BusinessModel/InputDocument.php b/workflow/engine/src/BusinessModel/InputDocument.php new file mode 100644 index 000000000..4b2f04eb4 --- /dev/null +++ b/workflow/engine/src/BusinessModel/InputDocument.php @@ -0,0 +1,359 @@ +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; + } + } + + /** + * Checks if the title exists in the InputDocuments of Process + * + * @param string $processUid Unique id of Process + * @param string $title Title + * @param string $inputDocumentUidExclude Unique id of InputDocument to exclude + * + * return bool Return true if the title exists in the InputDocuments of Process, false otherwise + */ + public function titleExists($processUid, $title, $inputDocumentUidExclude = "") + { + try { + $delimiter = \DBAdapter::getStringDelimiter(); + + $criteria = new \Criteria("workflow"); + + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_UID); + + $criteria->addAlias("CT", "CONTENT"); + + $arrayCondition = array(); + $arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CT.CON_ID", \Criteria::EQUAL); + $arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "INP_DOC_TITLE" . $delimiter, \Criteria::EQUAL); + $arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL); + $criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN); + + $criteria->add(\InputDocumentPeer::PRO_UID, $processUid, \Criteria::EQUAL); + + if ($inputDocumentUidExclude != "") { + $criteria->add(\InputDocumentPeer::INP_DOC_UID, $inputDocumentUidExclude, \Criteria::NOT_EQUAL); + } + + $criteria->add("CT.CON_VALUE", $title, \Criteria::EQUAL); + + $rsCriteria = \InputDocumentPeer::doSelectRS($criteria); + $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + + if ($rsCriteria->next()) { + return true; + } else { + return false; + } + } catch (\Exception $e) { + throw $e; + } + } + + /** + * 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 + * + * @param string $processUid Unique id of Process + * @param array $arrayData Data + * + * return array Return data of the new InputDocument created + */ + public function create($processUid, $arrayData) + { + try { + $arrayData = array_change_key_case($arrayData, CASE_UPPER); + + unset($arrayData["INP_DOC_UID"]); + + //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}"))); + } + + if (isset($arrayData["INP_DOC_TITLE"]) && $this->titleExists($processUid, $arrayData["INP_DOC_TITLE"])) { + throw (new \Exception(\G::LoadTranslation("ID_INPUT_NOT_SAVE"))); + } + + //Create + $inputdoc = new \InputDocument(); + + $arrayData["PRO_UID"] = $processUid; + + $inputDocumentUid = $inputdoc->create($arrayData); + + //Return + unset($arrayData["PRO_UID"]); + + $arrayData = array_change_key_case($arrayData, CASE_LOWER); + + $arrayData["inp_doc_uid"] = $inputDocumentUid; + + return $arrayData; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Update InputDocument + * + * @param string $inputDocumentUid Unique id of InputDocument + * @param array $arrayData Data + * + * return array Return data of the InputDocument updated + */ + public function update($inputDocumentUid, $arrayData) + { + try { + $arrayData = array_change_key_case($arrayData, CASE_UPPER); + + //Verify data + $inputdoc = new \InputDocument(); + + if (!$inputdoc->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); + + $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"))); + } + + //Update + $arrayData["INP_DOC_UID"] = $inputDocumentUid; + + $result = $inputdoc->update($arrayData); + + //Return + unset($arrayData["INP_DOC_UID"]); + + return array_change_key_case($arrayData, CASE_LOWER); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Delete InputDocument + * + * @param string $inputDocumentUid Unique id of InputDocument + * + * return void + */ + public function delete($inputDocumentUid) + { + try { + //Verify data + $inputdoc = new \InputDocument(); + + if (!$inputdoc->InputExists($inputDocumentUid)) { + throw (new \Exception(str_replace(array("{0}", "{1}"), array($inputDocumentUid, "INPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}"))); + } + + //Delete + //StepSupervisor + $stepSupervisor = new \StepSupervisor(); + + $arrayData = $stepSupervisor->loadInfo($inputDocumentUid); + $result = $stepSupervisor->remove($arrayData["STEP_UID"]); + + //ObjectPermission + $objectPermission = new \ObjectPermission(); + + $arrayData = $objectPermission->loadInfo($inputDocumentUid); + + if (is_array($arrayData)) { + $result = $objectPermission->remove($arrayData["OP_UID"]); + } + + //InputDocument + $inputdoc = new \InputDocument(); + + $result = $inputdoc->remove($inputDocumentUid); + + //Step + $step = new \Step(); + + $step->removeStep("INPUT_DOCUMENT", $inputDocumentUid); + + //ObjectPermission + $objectPermission = new \ObjectPermission(); + + $objectPermission->removeByObject("INPUT", $inputDocumentUid); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get criteria for InputDocument + * + * return object + */ + public function getInputDocumentCriteria() + { + try { + $delimiter = \DBAdapter::getStringDelimiter(); + + $criteria = new \Criteria("workflow"); + + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_UID); + $criteria->addAsColumn("INP_DOC_TITLE", "CT.CON_VALUE"); + $criteria->addAsColumn("INP_DOC_DESCRIPTION", "CD.CON_VALUE"); + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_FORM_NEEDED); + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_ORIGINAL); + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_PUBLISHED); + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_VERSIONING); + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_DESTINATION_PATH); + $criteria->addSelectColumn(\InputDocumentPeer::INP_DOC_TAGS); + + $criteria->addAlias("CT", "CONTENT"); + $criteria->addAlias("CD", "CONTENT"); + + $arrayCondition = array(); + $arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CT.CON_ID", \Criteria::EQUAL); + $arrayCondition[] = array("CT.CON_CATEGORY", $delimiter . "INP_DOC_TITLE" . $delimiter, \Criteria::EQUAL); + $arrayCondition[] = array("CT.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL); + $criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN); + + $arrayCondition = array(); + $arrayCondition[] = array(\InputDocumentPeer::INP_DOC_UID, "CD.CON_ID", \Criteria::EQUAL); + $arrayCondition[] = array("CD.CON_CATEGORY", $delimiter . "INP_DOC_DESCRIPTION" . $delimiter, \Criteria::EQUAL); + $arrayCondition[] = array("CD.CON_LANG", $delimiter . SYS_LANG . $delimiter, \Criteria::EQUAL); + $criteria->addJoinMC($arrayCondition, \Criteria::LEFT_JOIN); + + return $criteria; + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get data of an InputDocument from a record + * + * @param array $record Record + * + * return array Return an array with data of an InputDocument + */ + public function getInputDocumentDataFromRecord($record) + { + try { + return array( + "inp_doc_uid" => $record["INP_DOC_UID"], + "inp_doc_title" => $record["INP_DOC_TITLE"], + "inp_doc_description" => $record["INP_DOC_DESCRIPTION"] . "", + "inp_doc_form_needed" => $record["INP_DOC_FORM_NEEDED"], + "inp_doc_original" => $record["INP_DOC_ORIGINAL"], + "inp_doc_published" => $record["INP_DOC_PUBLISHED"], + "inp_doc_versioning" => (int)($record["INP_DOC_VERSIONING"]), + "inp_doc_destination_path" => $record["INP_DOC_DESTINATION_PATH"] . "", + "inp_doc_tags" => $record["INP_DOC_TAGS"] . "" + ); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * Get data of an InputDocument + * + * @param string $inputDocumentUid Unique id of InputDocument + * + * return array Return an array with data of an InputDocument + */ + public function getInputDocument($inputDocumentUid) + { + try { + //Verify data + $inputdoc = new \InputDocument(); + + if (!$inputdoc->InputExists($inputDocumentUid)) { + throw (new \Exception(str_replace(array("{0}", "{1}"), array($inputDocumentUid, "INPUT_DOCUMENT"), "The UID \"{0}\" doesn't exist in table {1}"))); + } + + //Get data + $criteria = $this->getInputDocumentCriteria(); + + $criteria->add(\InputDocumentPeer::INP_DOC_UID, $inputDocumentUid, \Criteria::EQUAL); + + $rsCriteria = \InputDocumentPeer::doSelectRS($criteria); + $rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC); + + $rsCriteria->next(); + + $row = $rsCriteria->getRow(); + + if ($row["INP_DOC_TITLE"] . "" == "") { + //There is no transaltion for this Document name, try to get/regenerate the label + $arrayInputdocData = $inputdoc->load($inputDocumentUid); + + $row["INP_DOC_TITLE"] = $arrayInputdocData["INP_DOC_TITLE"]; + $row["INP_DOC_DESCRIPTION"] = $arrayInputdocData["INP_DOC_DESCRIPTION"]; + } + + return $this->getInputDocumentDataFromRecord($row); + } catch (\Exception $e) { + throw $e; + } + } +} + diff --git a/workflow/engine/src/Services/Api/ProcessMaker/Project/InputDocument.php b/workflow/engine/src/Services/Api/ProcessMaker/Project/InputDocument.php new file mode 100644 index 000000000..d11d4c75f --- /dev/null +++ b/workflow/engine/src/Services/Api/ProcessMaker/Project/InputDocument.php @@ -0,0 +1,175 @@ +getInputDocument($inputDocumentUid); + + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * @url POST /:projectUid/input-document + * + * @param string $projectUid + * @param InputDocumentPostStructure $request_data + * + * @status 201 + */ + public function doPostInputDocument($projectUid, InputDocumentPostStructure $request_data = null) + { + try { + $inputdoc = new \BusinessModel\InputDocument(); + + $arrayData = $inputdoc->getArrayDataFromRequestData($request_data); + + $arrayData = $inputdoc->create($projectUid, $arrayData); + + $response = $arrayData; + + return $response; + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * @url PUT /:projectUid/input-document/:inputDocumentUid + * + * @param string $inputDocumentUid + * @param string $projectUid + * @param InputDocumentPutStructure $request_data + */ + public function doPutInputDocument($inputDocumentUid, $projectUid, InputDocumentPutStructure $request_data = null) + { + try { + $inputdoc = new \BusinessModel\InputDocument(); + + $arrayData = $inputdoc->getArrayDataFromRequestData($request_data); + + $arrayData = $inputdoc->update($inputDocumentUid, $arrayData); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } + + /** + * @url DELETE /:projectUid/input-document/:inputDocumentUid + */ + public function doDeleteInputDocument($inputDocumentUid, $projectUid) + { + try { + $inputdoc = new \BusinessModel\InputDocument(); + + $inputdoc->delete($inputDocumentUid); + } catch (\Exception $e) { + throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); + } + } +} + +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; +} +