ProcessMaker-BE "Proceso -----> Generar BPMN (Endpoint)"

- Se ha implementado el siguiente Endpoint:
    POST /api/1.0/{workspace}/project/process/{pro_uid}/generate-bpmn
This commit is contained in:
Victor Saisa Lopez
2014-07-24 17:18:48 -04:00
parent 31e9f0e198
commit 5b4b571f0f
10 changed files with 942 additions and 69 deletions

View File

@@ -447,5 +447,27 @@ class ProcessProxy extends HttpProxyController
}
$this->rows = $rows;
}
/**
* Generate BPMN (New record is generated)
*
* return void
*/
public function generateBpmn()
{
try {
$processUid = $_POST["processUid"];
$workflowBpmn = new \ProcessMaker\Project\Adapter\WorkflowBpmn();
$projectUid = $workflowBpmn->generateBpmn($processUid, "processUid");
$this->status = "OK";
$this->projectUid = $projectUid;
} catch (Exception $e) {
$this->status = "ERROR";
$this->message = $e->getMessage();
}
}
}

View File

@@ -111,60 +111,12 @@ abstract class Exporter
$bpmnStruct["PROCESS"] = \BpmnProcess::getAll($this->prjUid);
$bpmnStruct["PROJECT"] = array(\BpmnProjectPeer::retrieveByPK($this->prjUid)->toArray());
$oProcess = new \Processes();
$workflowData = (array) $oProcess->getWorkflowData($this->prjUid);
$workflowData["process"]['PRO_DYNAFORMS'] = empty($workflowData["process"]['PRO_DYNAFORMS'])
? "" : serialize($workflowData["process"]['PRO_DYNAFORMS']);
$workflowData["process"] = array($workflowData["process"]);
$workflowData["processCategory"] = empty($workflowData["processCategory"]) ? array() : array($workflowData["processCategory"]);
$workflow = new \ProcessMaker\Project\Workflow();
list($workflowData, $workflowFile) = $workflow->getData($this->prjUid);
$data["bpmn-definition"] = $bpmnStruct;
$data["workflow-definition"] = $workflowData;
$data["workflow-files"] = array();
// getting dynaforms
foreach ($workflowData["dynaforms"] as $dynaform) {
$dynFile = PATH_DYNAFORM . $dynaform['DYN_FILENAME'] . '.xml';
$data["workflow-files"]["DYNAFORMS"][] = array(
"filename" => $dynaform['DYN_TITLE'],
"filepath" => $dynaform['DYN_FILENAME'] . '.xml',
"file_content" => file_get_contents($dynFile)
);
$htmlFile = PATH_DYNAFORM . $dynaform['DYN_FILENAME'] . '.html';
if (file_exists($htmlFile)) {
$data["workflow-files"]["DYNAFORMS"][] = array(
"filename" => $dynaform['DYN_FILENAME'] . '.html',
"filepath" => $dynaform['DYN_FILENAME'] . '.html',
"file_content" => file_get_contents($htmlFile)
);
}
}
// getting templates files
$workspaceTargetDirs = array("TEMPLATES" => "mailTemplates", "PUBLIC" => "public");
$workspaceDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP;
foreach ($workspaceTargetDirs as $target => $workspaceTargetDir) {
$templatesDir = $workspaceDir . $workspaceTargetDir . PATH_SEP . $this->prjUid;
$templatesFiles = Util\Common::rglob("$templatesDir/*", 0, true);
foreach ($templatesFiles as $templatesFile) {
if (is_dir($templatesFile)) {
continue;
}
$filename = basename($templatesFile);
$data["workflow-files"][$target][] = array(
"filename" => $filename,
"filepath" => $this->prjUid . PATH_SEP . $filename,
"file_content" => file_get_contents($templatesFile)
);
}
}
$data["workflow-files"] = $workflowFile;
return $data;
}

View File

@@ -18,6 +18,8 @@ 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";
const IMPORT_OPTION_WORKFLOW_TO_BPMN_GENERATE = "project.import.workflow_to_bpmn_generate";
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";
@@ -29,6 +31,20 @@ abstract class Importer
public abstract function load();
/**
* Set import data
*
* @param array $arrayData Data
*
* return void
*/
public function setImportData(array $arrayData)
{
$this->importData = $arrayData;
$this->validateImportData();
}
/**
* Verify if exists reserved words SQL
*
@@ -71,7 +87,16 @@ abstract class Importer
public function import($option = self::IMPORT_OPTION_CREATE_NEW, $optionGroup = self::GROUP_IMPORT_OPTION_CREATE_NEW)
{
$this->prepare();
$generateUid = false;
if ($option != self::IMPORT_OPTION_WORKFLOW_TO_BPMN_GENERATE) {
$this->prepare();
} else {
$generateUid = true;
$option = "";
$optionGroup = "";
}
$name = $this->importData["tables"]["bpmn"]["project"][0]["prj_name"];
@@ -315,8 +340,8 @@ abstract class Importer
$diagram["events"] = $tables["event"];
$diagram["flows"] = $tables["flow"];
$diagram["gateways"] = $tables["gateway"];
$diagram["data"] = $tables["data"];
$diagram["participants"] = $tables["participant"];
$diagram["data"] = (isset($tables["data"]))? $tables["data"] : array();
$diagram["participants"] = (isset($tables["participant"]))? $tables["participant"] : array();
$diagram["lanes"] = array();
$diagram["laneset"] = array();
$project["diagrams"] = array($diagram);
@@ -415,7 +440,7 @@ abstract class Importer
foreach ($arrayFiles as $key2 => $value2) {
$file = $value2;
$arrayWorkflowFiles[$key1][$key2]["file_path"] = str_replace($projectUidOld, $projectUid, $file["file_path"]);
$arrayWorkflowFiles[$key1][$key2]["file_path"] = str_replace($projectUidOld, $projectUid, (isset($file["file_path"]))? $file["file_path"] : $file["filepath"]);
$arrayWorkflowFiles[$key1][$key2]["file_content"] = str_replace($projectUidOld, $projectUid, $file["file_content"]);
}
}

View File

@@ -926,7 +926,7 @@ class BpmnWorkflow extends Project\Bpmn
if ($forceInsert || is_null($dataObject)) {
if ($generateUid) {
//Event
//Data
unset($dataObjectData["BOU_UID"]);
$uidOld = $dataObjectData["DAT_UID"];
@@ -973,7 +973,7 @@ class BpmnWorkflow extends Project\Bpmn
if ($forceInsert || is_null($dataObject)) {
if ($generateUid) {
//Event
//Participant
unset($participantData["BOU_UID"]);
$uidOld = $participantData["PAR_UID"];
@@ -993,7 +993,7 @@ class BpmnWorkflow extends Project\Bpmn
Util\Logger::log("Update Participant ({$participantData["PAR_UID"]}) Skipped - No changes required");
}
$diagram["participant"][$i] = $participantData;
$diagram["participants"][$i] = $participantData;
$whiteList[] = $participantData["PAR_UID"];
}

View File

@@ -714,7 +714,11 @@ class Bpmn extends Handler
public function addArtifact($data)
{
// setting defaults
$processUid = $this->getProcess("object")->getProUid();
$data['ART_UID'] = array_key_exists('ART_UID', $data) ? $data['ART_UID'] : Common::generateUID();
$data["PRO_UID"] = $processUid;
try {
self::log("Add Artifact with data: ", $data);
$artifact = new Artifact();
@@ -796,7 +800,11 @@ class Bpmn extends Handler
public function addData($data)
{
// setting defaults
$processUid = $this->getProcess("object")->getProUid();
$data['DATA_UID'] = array_key_exists('DAT_UID', $data) ? $data['DAT_UID'] : Common::generateUID();
$data["PRO_UID"] = $processUid;
try {
self::log("Add BpmnData with data: ", $data);
$bpmnData = new \BpmnData();
@@ -878,7 +886,11 @@ class Bpmn extends Handler
public function addParticipant($data)
{
// setting defaults
$processUid = $this->getProcess("object")->getProUid();
$data['PAR_UID'] = array_key_exists('PAR_UID', $data) ? $data['PAR_UID'] : Common::generateUID();
$data["PRO_UID"] = $processUid;
try {
self::log("Add Participant with data: ", $data);
$participant = new Participant();

View File

@@ -911,5 +911,74 @@ class Workflow extends Handler
}
}
public function getData($processUid)
{
try {
$process = new \Processes();
//Get data
$workflowData = (array)($process->getWorkflowData($processUid));
$workflowData["process"]["PRO_DYNAFORMS"] = (empty($workflowData["process"]["PRO_DYNAFORMS"]))? "" : serialize($workflowData["process"]["PRO_DYNAFORMS"]);
$workflowData["process"] = array($workflowData["process"]);
$workflowData["processCategory"] = (empty($workflowData["processCategory"]))? array() : array($workflowData["processCategory"]);
//Get files
$workflowFile = array();
//Getting DynaForms
foreach ($workflowData["dynaforms"] as $dynaform) {
$dynFile = PATH_DYNAFORM . $dynaform["DYN_FILENAME"] . ".xml";
$workflowFile["DYNAFORMS"][] = array(
"filename" => $dynaform["DYN_TITLE"],
"filepath" => $dynaform["DYN_FILENAME"] . ".xml",
"file_content" => file_get_contents($dynFile)
);
$htmlFile = PATH_DYNAFORM . $dynaform["DYN_FILENAME"] . ".html";
if (file_exists($htmlFile)) {
$workflowFile["DYNAFORMS"][] = array(
"filename" => $dynaform["DYN_FILENAME"] . ".html",
"filepath" => $dynaform["DYN_FILENAME"] . ".html",
"file_content" => file_get_contents($htmlFile)
);
}
}
//Getting templates files
$workspaceTargetDirs = array("TEMPLATES" => "mailTemplates", "PUBLIC" => "public");
$workspaceDir = PATH_DATA . "sites" . PATH_SEP . SYS_SYS . PATH_SEP;
foreach ($workspaceTargetDirs as $target => $workspaceTargetDir) {
$templatesDir = $workspaceDir . $workspaceTargetDir . PATH_SEP . $processUid;
$templatesFiles = Util\Common::rglob("$templatesDir/*", 0, true);
foreach ($templatesFiles as $templatesFile) {
if (is_dir($templatesFile)) {
continue;
}
$filename = basename($templatesFile);
$workflowFile[$target][] = array(
"filename" => $filename,
"filepath" => $processUid . PATH_SEP . $filename,
"file_content" => file_get_contents($templatesFile)
);
}
}
//Return
self::log("Getting Workflow data Success!");
return array($workflowData, $workflowFile);
} catch (\Exception $e) {
self::log("Exception: ", $e->getMessage(), "Trace: ", $e->getTraceAsString());
throw $e;
}
}
}

View File

@@ -193,6 +193,30 @@ class Project extends Api
}
}
/**
* @url POST /process/:pro_uid/generate-bpmn
*
* @param string $pro_uid {@min 32}{@max 32}
*
* @status 201
*/
public function doPostProcessGenerateBpmn($pro_uid)
{
try {
$workflowBpmn = new \ProcessMaker\Project\Adapter\WorkflowBpmn();
$projectUid = $workflowBpmn->generateBpmn($pro_uid, "pro_uid");
$arrayData = array_change_key_case(array("PRJ_UID" => $projectUid), CASE_LOWER);
$response = $arrayData;
return $response;
} catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* @url GET /:prj_uid/dynaforms
*

View File

@@ -342,7 +342,7 @@ accessTokenSetup.application = {
sm.selectRow(rowIndex, true);
var record = grdpnlMain.getSelectionModel().getSelected();
console.log(record);
if (typeof(record) != "undefined") {
Ext.MessageBox.confirm(
_("ID_CONFIRM"),

View File

@@ -394,11 +394,10 @@ Ext.onReady(function(){
}
if (rowSelected.data.PROJECT_TYPE == "bpmn"){
Ext.getCmp('edit_with_classic_editor').setDisabled(false);
Ext.getCmp("mnuGenerateBpmn").setDisabled(true);
} else {
Ext.getCmp('edit_with_classic_editor').setDisabled(true);
Ext.getCmp("mnuGenerateBpmn").setDisabled(false);
}
}, this);
processesGrid.on('contextmenu', function (evt) {
evt.preventDefault();
@@ -435,6 +434,15 @@ Ext.onReady(function(){
handler: function () {
exportProcess();
}
},
{
id: "mnuGenerateBpmn",
text: _("ID_GENERATE_BPMN_PROJECT"),
iconCls: "button_menu_ext ss_sprite ss_page_white_go",
handler: function ()
{
generateBpmn();
}
}
]
});
@@ -584,7 +592,7 @@ editProcess = function(typeParam)
var rowSelected = processesGrid.getSelectionModel().getSelected();
if (!rowSelected) {
Ext.Msg.show({
title: '',
title: _("ID_INFORMATION"),
msg: _('ID_NO_SELECTION_WARNING'),
buttons: Ext.Msg.INFO,
fn: function () {
@@ -617,7 +625,7 @@ editNewProcess = function(){
location.href = '../designer?pro_uid='+rowSelected.data.PRO_UID
} else {
Ext.Msg.show({
title:'',
title: _("ID_INFORMATION"),
msg: _('ID_NO_SELECTION_WARNING'),
buttons: Ext.Msg.INFO,
fn: function(){},
@@ -701,7 +709,7 @@ deleteProcess = function(){
}
} else {
Ext.Msg.show({
title:'',
title: _("ID_INFORMATION"),
msg: _('ID_NO_SELECTION_WARNING'),
buttons: Ext.Msg.INFO,
fn: function(){},
@@ -743,7 +751,7 @@ function exportProcess() {
}
else {
Ext.Msg.show({
title: "",
title: _("ID_INFORMATION"),
msg: _("ID_NO_SELECTION_WARNING"),
icon: Ext.MessageBox.INFO,
buttons: Ext.MessageBox.OK
@@ -751,6 +759,60 @@ function exportProcess() {
}
}
function generateBpmn()
{
var record = processesGrid.getSelectionModel().getSelections();
if (typeof(record) != "undefined") {
if (record.length == 1) {
var loadMaskGenerateBpmn = new Ext.LoadMask(Ext.getBody(), {msg: _("ID_PROCESSING")});
var processUid = record[0].get("PRO_UID");
loadMaskGenerateBpmn.show();
Ext.Ajax.request({
url: "../processProxy/generateBpmn",
method: "POST",
params: {
processUid: processUid
},
success: function (response, opts)
{
var dataResponse = Ext.util.JSON.decode(response.responseText);
if (dataResponse.status) {
if (dataResponse.status == "OK") {
//processesGrid.store.reload();
location.assign("../designer?prj_uid=" + dataResponse.projectUid);
} else {
Ext.MessageBox.show({
title: _("ID_ERROR"),
icon: Ext.MessageBox.ERROR,
buttons: Ext.MessageBox.OK,
msg: dataResponse.message
});
}
}
loadMaskGenerateBpmn.hide();
},
failure: function (response, opts)
{
loadMaskGenerateBpmn.hide();
}
});
} else {
Ext.MessageBox.show({
title: _("ID_INFORMATION"),
icon: Ext.MessageBox.INFO,
buttons: Ext.MessageBox.OK,
msg: _("ID_NO_SELECTION_WARNING")
});
}
}
}
importProcessExistGroup = function()
{
@@ -1191,7 +1253,7 @@ function activeDeactive(){
});
} else {
Ext.Msg.show({
title:'',
title: _("ID_INFORMATION"),
msg: _('ID_NO_SELECTION_WARNING'),
buttons: Ext.Msg.INFO,
fn: function(){},
@@ -1227,7 +1289,7 @@ function enableDisableDebug()
});
} else {
Ext.Msg.show({
title:'',
title: _("ID_INFORMATION"),
msg: _('ID_NO_SELECTION_WARNING'),
buttons: Ext.Msg.INFO,
fn: function(){},