ProcessMaker-BE "BPMN Import (endpoint)"
- Se a implementado el siguiente Endpoint:
POST /api/1.0/{workspace}/project/import
- Se ha completado la eliminacion de datos de la tabla WEB_ENTRY cuando
se elimina el projecto desde el DESIGNER
- Al importar un projecto con las opciones "OVERWRITE y DISABLE" se encontraron
problemas, los mismos fueron solucionados
This commit is contained in:
@@ -371,5 +371,99 @@ abstract class Importer
|
||||
//Return
|
||||
return $projectUid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports a Project sent through the POST method ($_FILES)
|
||||
*
|
||||
* @param array $arrayData Data
|
||||
* @param array $arrayFieldName The field's names
|
||||
*
|
||||
* return array Returns the data sent and the unique id of Project
|
||||
*/
|
||||
public function importPostFile($arrayData, $arrayFieldName = array())
|
||||
{
|
||||
try {
|
||||
//Set data
|
||||
$arrayFieldName["projectFile"] = (isset($arrayFieldName["projectFile"]))? $arrayFieldName["projectFile"] : "PRJ_FILE";
|
||||
$arrayFieldName["option"] = (isset($arrayFieldName["option"]))? $arrayFieldName["option"] : "OPTION";
|
||||
|
||||
$arrayFieldDefinition = array(
|
||||
$arrayFieldName["projectFile"] => array("type" => "string", "required" => true, "empty" => false, "defaultValues" => array(), "fieldNameAux" => "projectFile"),
|
||||
$arrayFieldName["option"] => array("type" => "int", "required" => false, "empty" => false, "defaultValues" => array("CREATE", "OVERWRITE", "DISABLE", "KEEP"), "fieldNameAux" => "option")
|
||||
);
|
||||
|
||||
$arrayFieldNameForException = $arrayFieldName;
|
||||
|
||||
if (isset($_FILES[$arrayFieldName["projectFile"]])) {
|
||||
$_FILES["filepmx"] = $_FILES[$arrayFieldName["projectFile"]];
|
||||
}
|
||||
|
||||
if (isset($arrayData[$arrayFieldName["projectFile"]]) &&
|
||||
isset($arrayData[$arrayFieldName["projectFile"]]["name"]) &&
|
||||
is_array($arrayData[$arrayFieldName["projectFile"]])
|
||||
) {
|
||||
$arrayData[$arrayFieldName["projectFile"]] = $arrayData[$arrayFieldName["projectFile"]]["name"];
|
||||
}
|
||||
|
||||
//Verify data
|
||||
$process = new \ProcessMaker\BusinessModel\Process();
|
||||
$validator = new \ProcessMaker\BusinessModel\Validator();
|
||||
|
||||
$validator->throwExceptionIfDataIsNotArray($arrayData, "\$arrayData");
|
||||
$validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData");
|
||||
|
||||
$process->throwExceptionIfDataNotMetFieldDefinition($arrayData, $arrayFieldDefinition, $arrayFieldNameForException, true);
|
||||
|
||||
if ((isset($_FILES["filepmx"]) && pathinfo($_FILES["filepmx"]["name"], PATHINFO_EXTENSION) != "pmx") ||
|
||||
(isset($arrayData[$arrayFieldName["projectFile"]]) && pathinfo($arrayData[$arrayFieldName["projectFile"]], PATHINFO_EXTENSION) != "pmx")
|
||||
) {
|
||||
throw (new \Exception("The file extension not is \"pmx\""));
|
||||
}
|
||||
|
||||
//Set variables
|
||||
$option = self::IMPORT_OPTION_CREATE_NEW;
|
||||
|
||||
switch ((isset($arrayData[$arrayFieldName["option"]]))? $arrayData[$arrayFieldName["option"]] : "CREATE") {
|
||||
case "OVERWRITE":
|
||||
$option = self::IMPORT_OPTION_OVERWRITE;
|
||||
break;
|
||||
case "DISABLE":
|
||||
$option = self::IMPORT_OPTION_DISABLE_AND_CREATE_NEW;
|
||||
break;
|
||||
case "KEEP":
|
||||
$option = self::IMPORT_OPTION_KEEP_WITHOUT_CHANGING_AND_CREATE_NEW;
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($_FILES["filepmx"])) {
|
||||
$this->setSaveDir(PATH_DOCUMENT . "input");
|
||||
$this->setSourceFromGlobals("filepmx");
|
||||
} else {
|
||||
if (isset($arrayData[$arrayFieldName["projectFile"]]) && file_exists(PATH_DOCUMENT . "input" . PATH_SEP . $arrayData[$arrayFieldName["projectFile"]])) {
|
||||
$this->setSourceFile(PATH_DOCUMENT . "input" . PATH_SEP . $arrayData[$arrayFieldName["projectFile"]]);
|
||||
} else {
|
||||
throw (new \Exception(str_replace(array("{0}", "{1}"), array($arrayFieldNameForException["projectFile"], $arrayData[$arrayFieldName["projectFile"]]), "The file with {0}: \"{1}\" does not exist.")));
|
||||
}
|
||||
}
|
||||
|
||||
//Import
|
||||
try {
|
||||
$projectUid = $this->import($option);
|
||||
|
||||
$arrayData = array_merge(array("PRJ_UID" => $projectUid), $arrayData);
|
||||
} catch (\Exception $e) {
|
||||
throw (new \Exception("Project already exists"));
|
||||
}
|
||||
|
||||
//Return
|
||||
if ($arrayFieldName["projectFile"] != strtoupper($arrayFieldName["projectFile"])) {
|
||||
$arrayData = array_change_key_case($arrayData, CASE_LOWER);
|
||||
}
|
||||
|
||||
return $arrayData;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,11 +83,26 @@ class BpmnWorkflow extends Project\Bpmn
|
||||
public function update($data)
|
||||
{
|
||||
parent::update($data);
|
||||
$this->wp->update(array(
|
||||
"PRO_UID" => $data["PRJ_UID"],
|
||||
"PRO_TITLE" => $data["PRJ_NAME"],
|
||||
"PRO_DESCRIPTION" => $data["PRJ_DESCRIPTION"],
|
||||
));
|
||||
|
||||
$arrayData = array();
|
||||
|
||||
if (isset($data["PRJ_UID"])) {
|
||||
$arrayData["PRO_UID"] = $data["PRJ_UID"];
|
||||
}
|
||||
|
||||
if (isset($data["PRJ_NAME"])) {
|
||||
$arrayData["PRO_TITLE"] = $data["PRJ_NAME"];
|
||||
}
|
||||
|
||||
if (isset($data["PRJ_DESCRIPTION"])) {
|
||||
$arrayData["PRO_DESCRIPTION"] = $data["PRJ_DESCRIPTION"];
|
||||
}
|
||||
|
||||
if (isset($data["PRJ_STATUS"])) {
|
||||
$arrayData["PRO_STATUS"] = $data["PRJ_STATUS"];
|
||||
}
|
||||
|
||||
$this->wp->update($arrayData);
|
||||
}
|
||||
|
||||
public static function getList($start = null, $limit = null, $filter = "", $changeCaseTo = CASE_UPPER)
|
||||
|
||||
@@ -451,7 +451,10 @@ class Workflow extends Handler
|
||||
RoutePeer::ROU_NEXT_TASK => $toTasUid
|
||||
));
|
||||
|
||||
if ($route != null) {
|
||||
$route->delete();
|
||||
}
|
||||
|
||||
self::log("Remove Route Success!");
|
||||
} catch (\Exception $e) {
|
||||
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
|
||||
@@ -754,6 +757,23 @@ class Workflow extends Handler
|
||||
$oCriteria = new Criteria('workflow');
|
||||
$oCriteria->add(\CaseTrackerObjectPeer::PRO_UID, $sProcessUID);
|
||||
\ProcessUserPeer::doDelete($oCriteria);
|
||||
|
||||
//Delete Web Entries
|
||||
$webEntry = new \ProcessMaker\BusinessModel\WebEntry();
|
||||
|
||||
$criteria = new \Criteria("workflow");
|
||||
$criteria->addSelectColumn(\WebEntryPeer::WE_UID);
|
||||
$criteria->add(\WebEntryPeer::PRO_UID, $sProcessUID, \Criteria::EQUAL);
|
||||
|
||||
$rsCriteria = \WebEntryPeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
$webEntry->delete($row["WE_UID"]);
|
||||
}
|
||||
|
||||
//Delete the process
|
||||
try {
|
||||
$oProcess->remove($sProcessUID);
|
||||
@@ -888,3 +908,4 @@ class Workflow extends Handler
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,30 @@ class Project extends Api
|
||||
$httpStream->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* @url POST /import
|
||||
*
|
||||
* @param array $request_data
|
||||
*
|
||||
* @status 201
|
||||
*/
|
||||
public function doPostImport($request_data)
|
||||
{
|
||||
try {
|
||||
$importer = new \ProcessMaker\Importer\XmlImporter();
|
||||
|
||||
$importer->setData("usr_uid", $this->getUserId());
|
||||
|
||||
$arrayData = $importer->importPostFile($request_data, array("projectFile" => "prj_file", "option" => "option"));
|
||||
|
||||
$response = $arrayData;
|
||||
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @url GET /:prj_uid/process
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user