diff --git a/features/backend/projects/project_export_import/main_tests_project_export_import.feature b/features/backend/projects/project_export_import/main_tests_project_export_import.feature index 437a9efbd..dfa4af573 100644 --- a/features/backend/projects/project_export_import/main_tests_project_export_import.feature +++ b/features/backend/projects/project_export_import/main_tests_project_export_import.feature @@ -1,21 +1,14 @@ @ProcessMakerMichelangelo @RestAPI Feature: Import/Export Process Main Tests Requirements: - a workspace without the project 1455892245368ebeb11c1a5001393784 ("Process Complete BPMN") already loaded + a workspace without the project 1455892245368ebeb11c1a5001393784 ("Process Complete BPMN", "Export process empty") already loaded there are many activities, steps, triggers, pmtables, asignee, process supervisor, process permissions, etc. in the process Background: Given that I have a valid access_token -Scenario: Get for Export Project - Given I request "project/1455892245368ebeb11c1a5001393784/export" - Then the response status code should be 200 - And the response charset is "UTF-8" - And the content type is "application/xml" - And the type is "array" - -#Verificar cantidad de dynaform, output, inputs, triggers, asignacion de usuarios, etc. +#Verificar cantidad de dynaform, output, inputs, triggers, asignacion de usuarios, etc. del proyecto "Process Complete BPMN" Scenario: Get a List DynaForms of a Project Process Complete BPMN Given I request "project/1455892245368ebeb11c1a5001393784/dynaforms" @@ -86,6 +79,20 @@ Scenario: Get a list templates folder of process files manager And the type is "array" And the response has 1 records +Scenario: Verify that there are report tables + Given I request "project/1455892245368ebeb11c1a5001393784/report-tables" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the response has 1 record + +Scenario: Get the Case Trackers Objects of a Project + And I request "project/1455892245368ebeb11c1a5001393784/case-tracker/objects" + 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 response has 1 record + Scenario: Get a single Process Given that I want to get a resource with the key "obj_uid" stored in session array And I request "project/1455892245368ebeb11c1a5001393784/process" @@ -122,6 +129,24 @@ Scenario: Get a single Process And that "pro_summary_dynaform" is set to "898822326536be3a12addb0034537553" And that "pro_calendar" is set to "14606161052f50839307899033145440" +#Export Process + +Scenario: Get for Export Project + Given I request "project/1455892245368ebeb11c1a5001393784/export" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/xml" + And save exported process to "/home/wendy/uploadfiles/" as "Process_Complete_BPMN" + + +Scenario: Delete a Project created previously in this script + Given that I want to delete a resource with the key "prj_uid" stored in session array + And I request "projects/1455892245368ebeb11c1a5001393784" + 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" + #Import Process Scenario Outline: Import a process @@ -136,9 +161,10 @@ Scenario Outline: Import a process Examples: | project_file | import_option | prj_uid_number | | /home/wendy/uploadfiles/Process_NewCreate_BPMN.pmx | create | 1 | - | /home/wendy/uploadfiles/Process_Complete_BPMN.pmx | overwrite | 2 | - | /home/wendy/uploadfiles/Process_Complete_BPMN.pmx | disable | 3 | - | /home/wendy/uploadfiles/Process_Complete_BPMN.pmx | keep | 4 | + | /home/wendy/uploadfiles/Process_Complete_BPMN.pmx | create | 2 | + | /home/wendy/uploadfiles/Process_Complete_BPMN.pmx | overwrite | 3 | + | /home/wendy/uploadfiles/Process_Complete_BPMN.pmx | disable | 4 | + | /home/wendy/uploadfiles/Process_Complete_BPMN.pmx | keep | 5 | #Verificar cantidad de dynaform, output, inputs, triggers, asignacion de usuarios, etc. @@ -154,9 +180,10 @@ Scenario Outline: Get a List DynaForms of a Project Process Complete BPMN Examples: | import_option | prj_uid_number | prj_uid | records | | create | 1 | 601816709536cfeae7d7cd9079578104 | 4 | - | overwrite | 2 | 1455892245368ebeb11c1a5001393784 | 26 | - | disable | 3 | 1455892245368ebeb11c1a5001393784 | 26 | - | keep | 4 | 1455892245368ebeb11c1a5001393784 | 26 | + | create | 2 | 1455892245368ebeb11c1a5001393784 | 26 | + | overwrite | 3 | 1455892245368ebeb11c1a5001393784 | 26 | + | disable | 4 | 1455892245368ebeb11c1a5001393784 | 26 | + | keep | 5 | 1455892245368ebeb11c1a5001393784 | 26 | Scenario Outline: Get the Input Documents List when there are exactly zero input documents @@ -170,9 +197,10 @@ Scenario Outline: Get the Input Documents List when there are exactly zero input Examples: | import_option | prj_uid_number | prj_uid | records | | create | 1 | 601816709536cfeae7d7cd9079578104 | 0 | - | overwrite | 2 | 1455892245368ebeb11c1a5001393784 | 1 | - | disable | 3 | 1455892245368ebeb11c1a5001393784 | 1 | - | keep | 4 | 1455892245368ebeb11c1a5001393784 | 1 | + | create | 2 | 1455892245368ebeb11c1a5001393784 | 1 | + | overwrite | 3 | 1455892245368ebeb11c1a5001393784 | 1 | + | disable | 4 | 1455892245368ebeb11c1a5001393784 | 1 | + | keep | 5 | 1455892245368ebeb11c1a5001393784 | 1 | Scenario Outline: Get the Output Documents List when there are exactly two output documents @@ -186,9 +214,10 @@ Scenario Outline: Get the Output Documents List when there are exactly two outpu Examples: | import_option | prj_uid_number | prj_uid | records | | create | 1 | 601816709536cfeae7d7cd9079578104 | 0 | - | overwrite | 2 | 1455892245368ebeb11c1a5001393784 | 1 | - | disable | 3 | 1455892245368ebeb11c1a5001393784 | 1 | - | keep | 4 | 1455892245368ebeb11c1a5001393784 | 1 | + | create | 2 | 1455892245368ebeb11c1a5001393784 | 1 | + | overwrite | 3 | 1455892245368ebeb11c1a5001393784 | 1 | + | disable | 4 | 1455892245368ebeb11c1a5001393784 | 1 | + | keep | 5 | 1455892245368ebeb11c1a5001393784 | 1 | Scenario Outline: Get the Triggers List when there are exactly two triggers @@ -202,9 +231,10 @@ Scenario Outline: Get the Triggers List when there are exactly two triggers Examples: | import_option | prj_uid_number | prj_uid | records | | create | 1 | 601816709536cfeae7d7cd9079578104 | 0 | - | overwrite | 2 | 1455892245368ebeb11c1a5001393784 | 3 | - | disable | 3 | 1455892245368ebeb11c1a5001393784 | 3 | - | keep | 4 | 1455892245368ebeb11c1a5001393784 | 3 | + | create | 2 | 1455892245368ebeb11c1a5001393784 | 3 | + | overwrite | 3 | 1455892245368ebeb11c1a5001393784 | 3 | + | disable | 4 | 1455892245368ebeb11c1a5001393784 | 3 | + | keep | 5 | 1455892245368ebeb11c1a5001393784 | 3 | Scenario Outline: List assignees of each activity @@ -220,9 +250,10 @@ Scenario Outline: List assignees of each activity Examples: | import_option | prj_uid_number | prj_uid | records | project | activity | records | aas_uid | aas_type | | create | 1 | 601816709536cfeae7d7cd9079578104 | 0 | 601816709536cfeae7d7cd9079578104 | 771350954536cfec446fab9019867857 | 1 | 70084316152d56749e0f393054862525 | group | - | overwrite | 2 | 1455892245368ebeb11c1a5001393784 | 26 | 1455892245368ebeb11c1a5001393784 | 6274755055368eed1116388064384542 | 1 | 70084316152d56749e0f393054862525 | group | - | disable | 3 | 1455892245368ebeb11c1a5001393784 | 26 | 1455892245368ebeb11c1a5001393784 | 4790702485368efad167477011123879 | 1 | 70084316152d56749e0f393054862525 | group | - | keep | 4 | 1455892245368ebeb11c1a5001393784 | 26 | 1455892245368ebeb11c1a5001393784 | 2072984565368efc137a394001073529 | 1 | 70084316152d56749e0f393054862525 | group | + | create | 2 | 1455892245368ebeb11c1a5001393784 | 26 | 1455892245368ebeb11c1a5001393784 | 6274755055368eed1116388064384542 | 1 | 70084316152d56749e0f393054862525 | group | + | overwrite | 3 | 1455892245368ebeb11c1a5001393784 | 26 | 1455892245368ebeb11c1a5001393784 | 6274755055368eed1116388064384542 | 1 | 70084316152d56749e0f393054862525 | group | + | disable | 4 | 1455892245368ebeb11c1a5001393784 | 26 | 1455892245368ebeb11c1a5001393784 | 4790702485368efad167477011123879 | 1 | 70084316152d56749e0f393054862525 | group | + | keep | 5 | 1455892245368ebeb11c1a5001393784 | 26 | 1455892245368ebeb11c1a5001393784 | 2072984565368efc137a394001073529 | 1 | 70084316152d56749e0f393054862525 | group | Scenario Outline: Get a List of current process supervisors of a project @@ -236,9 +267,10 @@ Scenario Outline: Get a List of current process supervisors of a project Examples: | import_option | prj_uid_number | prj_uid | records | | create | 1 | 601816709536cfeae7d7cd9079578104 | 0 | - | overwrite | 2 | 1455892245368ebeb11c1a5001393784 | 1 | - | disable | 3 | 1455892245368ebeb11c1a5001393784 | 1 | - | keep | 4 | 1455892245368ebeb11c1a5001393784 | 1 | + | create | 2 | 1455892245368ebeb11c1a5001393784 | 1 | + | overwrite | 3 | 1455892245368ebeb11c1a5001393784 | 1 | + | disable | 4 | 1455892245368ebeb11c1a5001393784 | 1 | + | keep | 5 | 1455892245368ebeb11c1a5001393784 | 1 | Scenario Outline: Get a List of current Process Permissions of a project @@ -250,9 +282,10 @@ Scenario Outline: Get a List of current Process Permissions of a project Examples: | import_option | prj_uid_number | prj_uid | records | | create | 1 | 601816709536cfeae7d7cd9079578104 | 0 | - | overwrite | 2 | 1455892245368ebeb11c1a5001393784 | 1 | - | disable | 3 | 1455892245368ebeb11c1a5001393784 | 1 | - | keep | 4 | 1455892245368ebeb11c1a5001393784 | 1 | + | create | 2 | 1455892245368ebeb11c1a5001393784 | 1 | + | overwrite | 3 | 1455892245368ebeb11c1a5001393784 | 1 | + | disable | 4 | 1455892245368ebeb11c1a5001393784 | 1 | + | keep | 5 | 1455892245368ebeb11c1a5001393784 | 1 | Scenario Outline: Get a list templates folder of process files manager @@ -266,9 +299,10 @@ Scenario Outline: Get a list templates folder of process files manager Examples: | import_option | prj_uid_number | prj_uid | records | | create | 1 | 601816709536cfeae7d7cd9079578104 | 0 | - | overwrite | 2 | 1455892245368ebeb11c1a5001393784 | 1 | - | disable | 3 | 1455892245368ebeb11c1a5001393784 | 1 | - | keep | 4 | 1455892245368ebeb11c1a5001393784 | 1 | + | create | 2 | 1455892245368ebeb11c1a5001393784 | 1 | + | overwrite | 3 | 1455892245368ebeb11c1a5001393784 | 1 | + | disable | 4 | 1455892245368ebeb11c1a5001393784 | 1 | + | keep | 5 | 1455892245368ebeb11c1a5001393784 | 1 | Scenario: Get a single Process process "Process Complete BPMN" @@ -358,8 +392,8 @@ Scenario Outline: Delete a Project created previously in this script | prj_uid_number | | 1 | | 2 | - | 3 | | 4 | + | 5 | Scenario: Get a list of projects @@ -380,4 +414,66 @@ Scenario Outline: Import a process Examples: | project_file | import_option | | /home/wendy/uploadfiles/Process_Complete_BPMN.pmx | create | - \ No newline at end of file + + +#For example, to export a empty process + +Scenario: Get for Export Project "Export process empty" + Given I request "project/5195971265375127fce82f4015927137/export" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/xml" + And save exported process to "/home/wendy/uploadfiles/" as "Export process empty" + +Scenario: Delete a Project created previously in this script "Export process empty" + Given that I want to delete a resource with the key "prj_uid" stored in session array + And I request "projects/5195971265375127fce82f4015927137" + 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" + +Scenario: Import a process "Export process empty" + Given POST upload a project file "/home/wendy/uploadfiles/Export_process_empty.pmx" to "project/import?option=create" + Then the response status code should be 201 + And the response charset is "UTF-8" + And the content type is "application/json" + And the type is "object" + +Scenario: Get a List DynaForms of a Project "Export process empty" + Given I request "project/5195971265375127fce82f4015927137/dynaforms" with the key "prj_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 response has 0 records + +Scenario: Get the Input Documents List when there are exactly zero input documents + Given I request "project/5195971265375127fce82f4015927137/input-documents" with the key "prj_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 response has 0 records + +Scenario: Get the Output Documents List when there are exactly zero output documents + Given I request "project/5195971265375127fce82f4015927137/output-documents" with the key "prj_uid" stored in session array + Then the response status code should be 200 + And the response charset is "UTF-8" + And the content type is "application/json" + And the type is "array" + And the response has 0 records + +Scenario: Verify that there are report tables + Given I request "project/5195971265375127fce82f4015927137/report-tables" + Then the response status code should be 200 + And the response charset is "UTF-8" + And the response has 0 record + +Scenario: Get the Case Trackers Objects of a Project + And I request "project/5195971265375127fce82f4015927137/case-tracker/objects" + 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 response has 0 record \ No newline at end of file diff --git a/features/bootstrap/RestContext.php b/features/bootstrap/RestContext.php index ba7a8d63a..0f8f07ea2 100644 --- a/features/bootstrap/RestContext.php +++ b/features/bootstrap/RestContext.php @@ -1623,4 +1623,29 @@ class RestContext extends BehatContext throw new \Exception("JSON Response does not have '$varName' property\n\n" ); } } + /** + * @Given /^save exported process to "([^"]*)"$/ + * @Given /^save exported process to "([^"]*)" as "([^"]*)"$/ + */ + public function saveExportedProcessTo($destinationFolder, $exportedProcessFileName="") + { + + if($exportedProcessFileName == ""){//Obtain name from XML + $exportedProcessFileName=$this->_data->xpath('//metadata/meta[@key="name"]'); + $exportedProcessFileName = $exportedProcessFileName[0]; + $exportedProcessFileName = "ExpBehat ".$exportedProcessFileName; + + + } + + $exportedProcessFileName = $destinationFolder.str_replace(" ","_",$exportedProcessFileName).".pmx"; + + $this->printDebug("Exporting process to: $exportedProcessFileName"); + + file_put_contents($exportedProcessFileName, $this->_response->getBody(true)); + + + + } + } \ No newline at end of file diff --git a/features/json/process_template_sequencial.json b/features/json/process_template_sequencial.json index 9fe68aed2..5b66a18c4 100644 --- a/features/json/process_template_sequencial.json +++ b/features/json/process_template_sequencial.json @@ -299,7 +299,52 @@ ] } ], - "artifacts": [], + "artifacts": [ + { + "art_uid": "9008273035360fb4508c320094467351", + "art_type": "VERTICAL_LINE", + "art_name": "linea ejemplo", + "art_category_ref": "9008273035360fb4508c320094467351", + "bou_x": "180", + "bou_y": "0", + "bou_width": "50", + "bou_height": "0", + "bou_container": "" + }, + { + "art_uid": "9008273035360fb4508c320094467351", + "art_type": "VERTICAL_LINE", + "art_name": "linea ejemplo", + "art_category_ref": "9008273035360fb4508c320094467351", + "bou_x": "420", + "bou_y": "0", + "bou_width": "50", + "bou_height": "0", + "bou_container": "" + }, + { + "art_uid": "9008273035360fb4508c320094467351", + "art_type": "VERTICAL_LINE", + "art_name": "linea ejemplo", + "art_category_ref": "9008273035360fb4508c320094467351", + "bou_x": "660", + "bou_y": "0", + "bou_width": "50", + "bou_height": "0", + "bou_container": "" + }, + { + "art_uid": "9008273035360fb4508c320094467351", + "art_type": "VERTICAL_LINE", + "art_name": "linea ejemplo", + "art_category_ref": "9008273035360fb4508c320094467351", + "bou_x": "900", + "bou_y": "0", + "bou_width": "50", + "bou_height": "0", + "bou_container": "" + } + ], "laneset": [], "lanes": [] } diff --git a/workflow/engine/methods/processes/processes_Import_Ajax.php b/workflow/engine/methods/processes/processes_Import_Ajax.php index 98cbc4a8a..47d991337 100644 --- a/workflow/engine/methods/processes/processes_Import_Ajax.php +++ b/workflow/engine/methods/processes/processes_Import_Ajax.php @@ -24,57 +24,18 @@ use ProcessMaker\Importer\XmlImporter; -ini_set( 'max_execution_time', '0' ); - -if (isset($_FILES["PROCESS_FILENAME"])) { - $ext = pathinfo($_FILES["PROCESS_FILENAME"]["name"], PATHINFO_EXTENSION); - - if ($ext == "pmx") { - $importer = new XmlImporter(); - $importer->setData("usr_uid", $_SESSION['USER_LOGGED']); - $importer->setSaveDir(PATH_DOCUMENT . 'input'); - $importer->setSourceFromGlobals("PROCESS_FILENAME"); - - try { - $prjUid = $importer->import(); - - $result = array( - "success" => true, - "catchMessage" => "", - "ExistProcessInDatabase" => 0, - "ExistGroupsInDatabase" => 0, - "sNewProUid" => $prjUid, - "project_type" => "bpmn" - ); - } catch (Exception $e) { - $result = array( - "success" => true, - "catchMessage" => "", //$e->getMessage(), - "ExistProcessInDatabase" => 1, - "ExistGroupsInDatabase" => 0, - "groupBeforeAccion" => "uploadFileNewProcess", - "sNewProUid" => "", - "proFileName" => $_FILES['PROCESS_FILENAME']['name'], - "project_type" => "bpmn" - ); - } - - echo json_encode($result); - exit(0); - } -} elseif (isset($_POST["PRO_FILENAME"]) && file_exists(PATH_DOCUMENT . "input" . PATH_SEP . $_POST["PRO_FILENAME"]) && pathinfo(PATH_DOCUMENT . "input" . PATH_SEP . $_POST["PRO_FILENAME"], PATHINFO_EXTENSION) == "pmx") { - switch ($_POST["IMPORT_OPTION"]) { - case 1: $option = XmlImporter::IMPORT_OPTION_OVERWRITE; break; - case 2: $option = XmlImporter::IMPORT_OPTION_DISABLE_AND_CREATE_NEW; break; - case 3: $option = XmlImporter::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW; break; - } +ini_set("max_execution_time", 0); +if (isset($_FILES["PROCESS_FILENAME"]) && + pathinfo($_FILES["PROCESS_FILENAME"]["name"], PATHINFO_EXTENSION) == "pmx" +) { $importer = new XmlImporter(); - $importer->setData("usr_uid", $_SESSION['USER_LOGGED']); - $importer->setSourceFile(PATH_DOCUMENT . 'input' . PATH_SEP . $_POST["PRO_FILENAME"]); + $importer->setData("usr_uid", $_SESSION["USER_LOGGED"]); + $importer->setSaveDir(PATH_DOCUMENT . "input"); + $importer->setSourceFromGlobals("PROCESS_FILENAME"); try { - $prjUid = $importer->import($option); + $prjUid = $importer->import(); $result = array( "success" => true, @@ -84,16 +45,18 @@ if (isset($_FILES["PROCESS_FILENAME"])) { "sNewProUid" => $prjUid, "project_type" => "bpmn" ); - } catch (\Exception $e) { + } catch (Exception $e) { $result = array( "success" => true, - "catchMessage" => $e->getMessage(), - "ExistProcessInDatabase" => 1, - "ExistGroupsInDatabase" => 0, - "groupBeforeAccion" => "uploadFileNewProcess", + "catchMessage" => (in_array($e->getCode(), array(XmlImporter::IMPORT_STAT_TARGET_ALREADY_EXISTS, XmlImporter::IMPORT_STAT_GROUP_ALREADY_EXISTS)))? "" : $e->getMessage(), + "ExistProcessInDatabase" => ($e->getCode() == XmlImporter::IMPORT_STAT_TARGET_ALREADY_EXISTS)? 1 : 0, + "ExistGroupsInDatabase" => ($e->getCode() == XmlImporter::IMPORT_STAT_GROUP_ALREADY_EXISTS)? 1 : 0, "sNewProUid" => "", - "proFileName" => "", - "project_type" => "bpmn" + "project_type" => "bpmn", + + "proFileName" => $_FILES["PROCESS_FILENAME"]["name"], + "groupBeforeAccion" => "uploadFileNewProcess", + "importOption" => 0 ); } @@ -101,38 +64,73 @@ if (isset($_FILES["PROCESS_FILENAME"])) { exit(0); } -function reservedWordsSqlValidate ($data) -{ - $arrayAux = array (); - $reservedWordsSql = G::reservedWordsSql(); +if (isset($_POST["PRO_FILENAME"]) && + file_exists(PATH_DOCUMENT . "input" . PATH_SEP . $_POST["PRO_FILENAME"]) && + pathinfo(PATH_DOCUMENT . "input" . PATH_SEP . $_POST["PRO_FILENAME"], PATHINFO_EXTENSION) == "pmx" +) { + $option = XmlImporter::IMPORT_OPTION_CREATE_NEW; - foreach ($data->reportTables as $rptIndex => $rptValue) { - if (in_array( strtoupper( $rptValue["REP_TAB_NAME"] ), $reservedWordsSql )) { - $arrayAux[] = $rptValue["REP_TAB_NAME"]; - } + switch ((isset($_POST["IMPORT_OPTION"]))? (int)($_POST["IMPORT_OPTION"]) : 0) { + case 1: + $option = XmlImporter::IMPORT_OPTION_OVERWRITE; + break; + case 2: + $option = XmlImporter::IMPORT_OPTION_DISABLE_AND_CREATE_NEW; + break; + case 3: + $option = XmlImporter::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW; + break; } - if (count( $arrayAux ) > 0) { - throw (new Exception( G::LoadTranslation( "ID_PMTABLE_INVALID_NAME", array (implode( ", ", $arrayAux ) - ) ) )); + $optionGroup = XmlImporter::GROUP_IMPORT_OPTION_CREATE_NEW; + + switch ((isset($_POST["optionGroupExistInDatabase"]))? (int)($_POST["optionGroupExistInDatabase"]) : 0) { + case 1: + $optionGroup = XmlImporter::GROUP_IMPORT_OPTION_RENAME; + break; + case 2: + $optionGroup = XmlImporter::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT; + break; } - $arrayAux = array (); + $importer = new XmlImporter(); + $importer->setData("usr_uid", $_SESSION["USER_LOGGED"]); + $importer->setSourceFile(PATH_DOCUMENT . "input" . PATH_SEP . $_POST["PRO_FILENAME"]); - foreach ($data->reportTablesVars as $rptIndex => $rptValue) { - if (in_array( strtoupper( $rptValue["REP_VAR_NAME"] ), $reservedWordsSql )) { - $arrayAux[] = $rptValue["REP_VAR_NAME"]; - } + try { + $prjUid = $importer->import($option, $optionGroup); + + $result = array( + "success" => true, + "catchMessage" => "", + "ExistProcessInDatabase" => 0, + "ExistGroupsInDatabase" => 0, + "sNewProUid" => $prjUid, + "project_type" => "bpmn" + ); + } catch (Exception $e) { + $result = array( + "success" => true, + "catchMessage" => (in_array($e->getCode(), array(XmlImporter::IMPORT_STAT_TARGET_ALREADY_EXISTS, XmlImporter::IMPORT_STAT_GROUP_ALREADY_EXISTS)))? "" : $e->getMessage(), + "ExistProcessInDatabase" => ($e->getCode() == XmlImporter::IMPORT_STAT_TARGET_ALREADY_EXISTS)? 1 : 0, + "ExistGroupsInDatabase" => ($e->getCode() == XmlImporter::IMPORT_STAT_GROUP_ALREADY_EXISTS)? 1 : 0, + "sNewProUid" => "", + "project_type" => "bpmn", + + "proFileName" => $_POST["PRO_FILENAME"], + "groupBeforeAccion" => "uploadFileNewProcess", + "importOption" => (isset($_POST["IMPORT_OPTION"]))? (int)($_POST["IMPORT_OPTION"]) : 0 + ); } - if (count( $arrayAux ) > 0) { - throw (new Exception( G::LoadTranslation( "ID_PMTABLE_INVALID_FIELD_NAME", array (implode( ", ", $arrayAux ) - ) ) )); - } + echo G::json_encode($result); + exit(0); } $action = isset( $_REQUEST['ajaxAction'] ) ? $_REQUEST['ajaxAction'] : null; +$importer = new XmlImporter(); + $result = new stdClass(); $result->success = true; $result->catchMessage = ""; @@ -201,7 +199,7 @@ if ($action == "uploadFileNewProcess") { $oData = $oProcess->getProcessData( $path . $filename ); } - reservedWordsSqlValidate( $oData ); + $importer->throwExceptionIfExistsReservedWordsSql($oData); //!Upload file $Fields['PRO_FILENAME'] = $filename; @@ -286,7 +284,7 @@ if ($action == "uploadFileNewProcessExist") { $oData = $oProcess->getProcessData( $path . $filename ); } - reservedWordsSqlValidate( $oData ); + $importer->throwExceptionIfExistsReservedWordsSql($oData); $Fields['PRO_FILENAME'] = $filename; $sProUid = $oData->process['PRO_UID']; @@ -352,7 +350,7 @@ if ($action == "uploadFileNewProcessExist") { } //!data ouput - $result->fileName = $filename; + $result->proFileName = $filename; $result->importOption = $option; $result->sNewProUid = $sNewProUid; $result->success = true; diff --git a/workflow/engine/src/ProcessMaker/Importer/Importer.php b/workflow/engine/src/ProcessMaker/Importer/Importer.php index 58797862c..30b3f4fcc 100644 --- a/workflow/engine/src/ProcessMaker/Importer/Importer.php +++ b/workflow/engine/src/ProcessMaker/Importer/Importer.php @@ -18,22 +18,58 @@ abstract class Importer const IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW = "project.import.keep_without_changing_and_create_new"; const IMPORT_OPTION_CREATE_NEW = "project.import.create_new"; - /** - * Success, Project imported successfully. - */ - const IMPORT_STAT_SUCCESS = 100; - /** - * Error, Target Project already exists. - */ - const IMPORT_STAT_TARGET_ALREADY_EXISTS = 101; - /** - * Error, Invalid file type or the file have corrupt data. - */ - const IMPORT_STAT_INVALID_SOURCE_FILE = 102; + const GROUP_IMPORT_OPTION_RENAME = "group.import.rename"; + const GROUP_IMPORT_OPTION_MERGE_PREEXISTENT = "group.import.merge.preexistent"; + const GROUP_IMPORT_OPTION_CREATE_NEW = "group.import.create_new"; + + const IMPORT_STAT_SUCCESS = 100; //Success, Project imported successfully. + const IMPORT_STAT_TARGET_ALREADY_EXISTS = 101; //Error, Target Project already exists. + const IMPORT_STAT_INVALID_SOURCE_FILE = 102; //Error, Invalid file type or the file have corrupt data. + const IMPORT_STAT_GROUP_ALREADY_EXISTS = 105; //Error, Group already exists. public abstract function load(); - public function import($option = self::IMPORT_OPTION_CREATE_NEW) + /** + * Verify if exists reserved words SQL + * + * @param object $data Data + * + * return void Throw exception if exists reserved words SQL + */ + public function throwExceptionIfExistsReservedWordsSql($data) + { + $arrayReservedWordsSql = \G::reservedWordsSql(); + + $arrayAux = array(); + + foreach ($data->reportTables as $key => $value) { + $record = $value; + + if (in_array(strtoupper($record["REP_TAB_NAME"]), $arrayReservedWordsSql)) { + $arrayAux[] = $record["REP_TAB_NAME"]; + } + } + + if (count($arrayAux) > 0) { + throw new \Exception(\G::LoadTranslation("ID_PMTABLE_INVALID_NAME", array(implode(", ", $arrayAux)))); + } + + $arrayAux = array(); + + foreach ($data->reportTablesVars as $key => $value) { + $record = $value; + + if (in_array(strtoupper($record["REP_VAR_NAME"]), $arrayReservedWordsSql)) { + $arrayAux[] = $record["REP_VAR_NAME"]; + } + } + + if (count($arrayAux) > 0) { + throw new \Exception(\G::LoadTranslation("ID_PMTABLE_INVALID_FIELD_NAME", array(implode(", ", $arrayAux)))); + } + } + + public function import($option = self::IMPORT_OPTION_CREATE_NEW, $optionGroup = self::GROUP_IMPORT_OPTION_CREATE_NEW) { $this->prepare(); @@ -68,6 +104,35 @@ abstract class Importer break; } + $processes = new \Processes(); + + switch ($optionGroup) { + case self::GROUP_IMPORT_OPTION_CREATE_NEW: + $arrayAux = $processes->checkExistingGroups($this->importData["tables"]["workflow"]["groupwfs"]); + + if (is_array($arrayAux) && count($arrayAux) > 0) { + throw new \Exception( + str_replace( + array("{0}"), + array(implode("|", array(self::GROUP_IMPORT_OPTION_CREATE_NEW, self::GROUP_IMPORT_OPTION_RENAME, self::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT))), + "Group already exists, you need set an action to continue. Available actions: [{0}]." + ), + self::IMPORT_STAT_GROUP_ALREADY_EXISTS + ); + } + break; + case self::GROUP_IMPORT_OPTION_RENAME: + $arrayAux = $processes->renameExistingGroups($this->importData["tables"]["workflow"]["groupwfs"]); + + if (is_array($arrayAux) && count($arrayAux) > 0) { + $this->importData["tables"]["workflow"]["groupwfs"] = $arrayAux; + } + break; + case self::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT: + $this->importData["tables"]["workflow"] = (array)($processes->groupwfsUpdateUidByDatabase((object)($this->importData["tables"]["workflow"]))); + break; + } + $this->importData["tables"]["bpmn"]["project"][0]["prj_name"] = $name; $this->importData["tables"]["bpmn"]["diagram"][0]["dia_name"] = $name; $this->importData["tables"]["bpmn"]["process"][0]["pro_name"] = $name; @@ -128,6 +193,8 @@ abstract class Importer throw new \Exception("BPMN table: \"Project\", definition is missing or has multiple definition."); } + $this->throwExceptionIfExistsReservedWordsSql((object)($this->importData["tables"]["workflow"])); + return true; } @@ -386,17 +453,19 @@ abstract class Importer * Imports a Project sent through the POST method ($_FILES) * * @param array $arrayData Data - * @param string $option Option ("CREATE", "OVERWRITE", "DISABLE", "KEEP") + * @param string $option Option for Project ("CREATE", "OVERWRITE", "DISABLE", "KEEP") + * @param string $optionGroup Option for Group ("CREATE", "RENAME", "MERGE") * @param array $arrayFieldName The field's names * * return array Returns the data sent and the unique id of Project */ - public function importPostFile(array $arrayData, $option = "CREATE", array $arrayFieldName = array()) + public function importPostFile(array $arrayData, $option = "CREATE", $optionGroup = "CREATE", array $arrayFieldName = array()) { try { //Set data $arrayFieldName["projectFile"] = (isset($arrayFieldName["projectFile"]))? $arrayFieldName["projectFile"] : "PROJECT_FILE"; $arrayFieldName["option"] = (isset($arrayFieldName["option"]))? $arrayFieldName["option"] : "OPTION"; + $arrayFieldName["optionGroup"] = (isset($arrayFieldName["optionGroup"]))? $arrayFieldName["optionGroup"] : "OPTION_GROUP"; $arrayFieldDefinition = array( $arrayFieldName["projectFile"] => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectFile") @@ -418,6 +487,9 @@ abstract class Importer $optionCaseUpper = (strtoupper($option) == $option)? true : false; $option = strtoupper($option); + $optionGroupCaseUpper = (strtoupper($optionGroup) == $optionGroup)? true : false; + $optionGroup = strtoupper($optionGroup); + //Verify data $process = new \ProcessMaker\BusinessModel\Process(); $validator = new \ProcessMaker\BusinessModel\Validator(); @@ -427,12 +499,29 @@ abstract class Importer $process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $arrayFieldDefinition, $arrayFieldNameForException, true); $arrayOptionDefaultValues = array("CREATE", "OVERWRITE", "DISABLE", "KEEP"); + $arrayOptionGroupDefaultValues = array("CREATE", "RENAME", "MERGE"); - if ($option . "" != "") { - if (!in_array($option, $arrayOptionDefaultValues, true)) { - $strdv = implode("|", $arrayOptionDefaultValues); + $arrayAux = array( + array($option, $arrayOptionDefaultValues, $arrayFieldNameForException["option"], $optionCaseUpper), + array($optionGroup, $arrayOptionGroupDefaultValues, $arrayFieldNameForException["optionGroup"], $optionGroupCaseUpper) + ); - throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayFieldNameForException["option"], ($optionCaseUpper)? $strdv : strtolower($strdv)), "Invalid value for \"{0}\", it only accepts values: \"{1}\"."))); + foreach ($arrayAux as $value) { + $opt = $value[0]; + $arrayDefaultValues = $value[1]; + $fieldNameForException = $value[2]; + $caseUpper = $value[3]; + + if ($opt != "") { + if (!in_array($opt, $arrayDefaultValues, true)) { + $strdv = implode("|", $arrayDefaultValues); + + throw new \Exception( + str_replace(array("{0}", "{1}"), + array($fieldNameForException, ($caseUpper)? $strdv : strtolower($strdv)), + "Invalid value for \"{0}\", it only accepts values: \"{1}\".") + ); + } } } @@ -443,21 +532,22 @@ abstract class Importer } //Set variables - $opt = self::IMPORT_OPTION_CREATE_NEW; //CREATE + $arrayAux = array( + (($option != "")? "CREATE" : "") => self::IMPORT_OPTION_CREATE_NEW, + "OVERWRITE" => self::IMPORT_OPTION_OVERWRITE, + "DISABLE" => self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW, + "KEEP" => self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW + ); - switch ($option) { - case "OVERWRITE": - $opt = self::IMPORT_OPTION_OVERWRITE; - break; - case "DISABLE": - $opt = self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW; - break; - case "KEEP": - $opt = self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW; - break; - } + $option = $arrayAux[$option]; - $option = $opt; + $arrayAux = array( + (($optionGroup != "")? "CREATE" : "") => self::GROUP_IMPORT_OPTION_CREATE_NEW, + "RENAME" => self::GROUP_IMPORT_OPTION_RENAME, + "MERGE" => self::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT + ); + + $optionGroup = $arrayAux[$optionGroup]; if (isset($_FILES["filePmx"])) { $this->setSourceFromGlobals("filePmx"); @@ -473,13 +563,32 @@ abstract class Importer //Import try { - $projectUid = $this->import($option); + $projectUid = $this->import($option, $optionGroup); $arrayData = array_merge(array("PRJ_UID" => $projectUid), $arrayData); } catch (\Exception $e) { - $msg = str_replace(array(self::IMPORT_OPTION_CREATE_NEW, self::IMPORT_OPTION_OVERWRITE, self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW, self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW), $arrayOptionDefaultValues, $e->getMessage()); + $strOpt = implode("|", $arrayOptionDefaultValues); + $strOptg = implode("|", $arrayOptionGroupDefaultValues); - throw (new \Exception($msg)); + $strOpt = ($optionCaseUpper)? $strOpt : strtolower($strOpt); + $strOptg = ($optionGroupCaseUpper)? $strOptg : strtolower($strOptg); + + $msg = str_replace( + array( + self::IMPORT_OPTION_CREATE_NEW, + self::IMPORT_OPTION_OVERWRITE, + self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW, + self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW, + + self::GROUP_IMPORT_OPTION_CREATE_NEW, + self::GROUP_IMPORT_OPTION_RENAME, + self::GROUP_IMPORT_OPTION_MERGE_PREEXISTENT + ), + array_merge(explode("|", $strOpt), explode("|", $strOptg)), + $e->getMessage() + ); + + throw new \Exception($msg); } //Return diff --git a/workflow/engine/src/ProcessMaker/Services/Api/Project.php b/workflow/engine/src/ProcessMaker/Services/Api/Project.php index 3832ac898..893d5e909 100644 --- a/workflow/engine/src/ProcessMaker/Services/Api/Project.php +++ b/workflow/engine/src/ProcessMaker/Services/Api/Project.php @@ -131,7 +131,7 @@ class Project extends Api * * @status 201 */ - public function doPostImport(array $request_data, $option = null) + public function doPostImport(array $request_data, $option = null, $option_group = null) { try { $importer = new \ProcessMaker\Importer\XmlImporter(); @@ -139,7 +139,12 @@ class Project extends Api $importer->setSaveDir(PATH_DOCUMENT . "input"); $importer->setData("usr_uid", $this->getUserId()); - $arrayData = $importer->importPostFile($request_data, $option, array("projectFile" => "project_file", "option" => "option")); + $arrayData = $importer->importPostFile( + $request_data, + $option, + $option_group, + array("projectFile" => "project_file", "option" => "option", "optionGroup" => "option_group") + ); $response = $arrayData; diff --git a/workflow/engine/templates/processes/main.js b/workflow/engine/templates/processes/main.js index a776cb1b7..f02e76a8f 100755 --- a/workflow/engine/templates/processes/main.js +++ b/workflow/engine/templates/processes/main.js @@ -846,7 +846,12 @@ importProcessExistGroup = function() success : function(o, resp) { var resp_ = Ext.util.JSON.decode(resp.response.responseText); var sNewProUid = resp_.sNewProUid; - window.location.href = "processes_Map?PRO_UID=" + sNewProUid; + + if (typeof(resp_.project_type) != "undefined" && resp_.project_type == "bpmn") { + window.location.href = "../designer?prj_uid=" + sNewProUid; + } else { + window.location.href = "processes_Map?PRO_UID=" + sNewProUid; + } }, failure: function(o, resp) { w.close(); @@ -975,17 +980,16 @@ importProcessExistProcess = function() success: function(o, resp) { var resp_ = Ext.util.JSON.decode(resp.response.responseText); var sNewProUid = resp_.sNewProUid; - var projectType = (typeof(resp_.project_type) != "undefined")? resp_.project_type : "classicProject"; if (resp_.ExistGroupsInDatabase == 0) { - if (projectType == "classicProject") { - window.location.href = "processes_Map?PRO_UID=" + sNewProUid; - } else { + if (typeof(resp_.project_type) != "undefined" && resp_.project_type == "bpmn") { window.location.href = "../designer?prj_uid=" + sNewProUid; + } else { + window.location.href = "processes_Map?PRO_UID=" + sNewProUid; } } else { - importProcessGlobal.proFileName = resp_.fileName; + importProcessGlobal.proFileName = resp_.proFileName; importProcessGlobal.groupBeforeAccion = resp_.groupBeforeAccion; importProcessGlobal.sNewProUid = resp_.sNewProUid; importProcessGlobal.importOption = resp_.importOption; @@ -1090,8 +1094,9 @@ importProcess = function() if (resp_.catchMessage == "") { if (resp_.ExistProcessInDatabase == "0") { if (resp_.ExistGroupsInDatabase == "0") { - var sNewProUid = resp_.sNewProUid; - if (resp_.project_type && resp_.project_type == "bpmn") { + var sNewProUid = resp_.sNewProUid; + + if (typeof(resp_.project_type) != "undefined" && resp_.project_type == "bpmn") { window.location.href = "../designer?prj_uid=" + sNewProUid; } else { window.location.href = "processes_Map?PRO_UID=" + sNewProUid;