HOR-1317: Adding support for plugin extensions for the granular import and export.

This commit is contained in:
Gustavo Adolfo Cruz Laura
2016-06-16 18:10:18 -04:00
parent 9e95b10463
commit 00a4022d6f
11 changed files with 191 additions and 36 deletions

View File

@@ -1789,5 +1789,28 @@ class PMPluginRegistry
return $this->_aOpenReassignCallback; return $this->_aOpenReassignCallback;
} }
public function getPluginsData()
{
return $this->_aPlugins;
}
/**
* The following function method extracts the plugin if exists one
* with the same uppercase characters, this is required for the
*
* @param $code
*/
public function getPluginByCode($code)
{
$plugin = false;
foreach ($this->_aPlugins as $plugin) {
$plugin = (array)$plugin;
if (strtoupper($plugin['sNamespace']) == $code) {
return (object)$plugin;
}
}
return $plugin;
}
} }

View File

@@ -0,0 +1 @@
tables = 'APPLICATION|APP_SEQUENCE|APP_DELEGATION|APP_DOCUMENT|APP_MESSAGE|APP_OWNER|CONFIGURATION|CONTENT|DEPARTMENT|DYNAFORM|GROUPWF|GROUP_USER|HOLIDAY|INPUT_DOCUMENT|ISO_COUNTRY|ISO_LOCATION|ISO_SUBDIVISION|LANGUAGE|LEXICO|OUTPUT_DOCUMENT|PROCESS|PROCESS_OWNER|REPORT_TABLE|REPORT_VAR|ROUTE|STEP|STEP_TRIGGER|SWIMLANES_ELEMENTS|TASK|TASK_USER|TRANSLATION|TRIGGERS|USERS|APP_THREAD|APP_DELAY|PROCESS_USER|SESSION|DB_SOURCE|STEP_SUPERVISOR|OBJECT_PERMISSION|CASE_TRACKER|CASE_TRACKER_OBJECT|CASE_CONSOLIDATED|STAGE|SUB_PROCESS|SUB_APPLICATION|LOGIN_LOG|USERS_PROPERTIES|ADDITIONAL_TABLES|FIELDS|SHADOW_TABLE|EVENT|GATEWAY|APP_EVENT|APP_CACHE_VIEW|DIM_TIME_DELEGATE|DIM_TIME_COMPLETE|APP_HISTORY|APP_FOLDER|FIELD_CONDITION|LOG_CASES_SCHEDULER|CASE_SCHEDULER|CALENDAR_DEFINITION|CALENDAR_BUSINESS_HOURS|CALENDAR_HOLIDAYS|CALENDAR_ASSIGNMENTS|PROCESS_CATEGORY|APP_NOTES|DASHLET|DASHLET_INSTANCE|APP_SOLR_QUEUE|SEQUENCES|SESSION_STORAGE|PROCESS_FILES|WEB_ENTRY|OAUTH_ACCESS_TOKENS|OAUTH_AUTHORIZATION_CODES|OAUTH_CLIENTS|OAUTH_REFRESH_TOKENS|OAUTH_SCOPES|PMOAUTH_USER_ACCESS_TOKENS|BPMN_PROJECT|BPMN_PROCESS|BPMN_ACTIVITY|BPMN_ARTIFACT|BPMN_DIAGRAM|BPMN_BOUND|BPMN_DATA|BPMN_EVENT|BPMN_FLOW|BPMN_GATEWAY|BPMN_LANESET|BPMN_LANE|BPMN_PARTICIPANT|BPMN_EXTENSION|BPMN_DOCUMENTATION|PROCESS_VARIABLES|APP_TIMEOUT_ACTION_EXECUTED|ADDONS_STORE|ADDONS_MANAGER|LICENSE_MANAGER|APP_ASSIGN_SELF_SERVICE_VALUE|LIST_INBOX|LIST_PARTICIPATED_HISTORY|LIST_PARTICIPATED_LAST|LIST_COMPLETED|LIST_PAUSED|LIST_CANCELED|LIST_MY_INBOX|LIST_UNASSIGNED|LIST_UNASSIGNED_GROUP|MESSAGE_TYPE|MESSAGE_TYPE_VARIABLE|EMAIL_SERVER|WEB_ENTRY_EVENT|MESSAGE_EVENT_DEFINITION|MESSAGE_EVENT_RELATION|MESSAGE_APPLICATION|ELEMENT_TASK_RELATION|ABE_CONFIGURATION|ABE_REQUESTS|ABE_RESPONSES|USR_REPORTING|PRO_REPORTING|DASHBOARD|DASHBOARD_INDICATOR|DASHBOARD_DAS_IND|CATALOG|SCRIPT_TASK|TIMER_EVENT|EMAIL_EVENT|NOTIFICATION_DEVICE|GMAIL_RELABELING|RBAC_PERMISSIONS|RBAC_ROLES|RBAC_ROLES_PERMISSIONS|RBAC_SYSTEMS|RBAC_USERS|RBAC_USERS_ROLES|RBAC_AUTHENTICATION_SOURCE|'

View File

@@ -7,22 +7,31 @@ class ExportObjects
* @var array * @var array
*/ */
protected $objectsList = array( protected $objectsList = array(
'Process Definition', 'PROCESSDEFINITION' => 'Process Definition',
'Assignment Rules', 'ASSIGNMENTRULES' => 'Assignment Rules',
'Variables', 'VARIABLES' => 'Variables',
'Dynaforms', 'DYNAFORMS' => 'Dynaforms',
'Input Documents', 'INPUTDOCUMENTS' => 'Input Documents',
'Output Documents', 'OUTPUTDOCUMENTS' => 'Output Documents',
'Triggers', 'TRIGGERS' => 'Triggers',
'Report Tables', 'REPORTTABLES' => 'Report Tables',
'Templates', 'TEMPLATES' => 'Templates',
'Files', 'FILES' => 'Files',
'DB Connection', 'DBCONNECTION' => 'DB Connection',
'Permissions', 'PERMISSIONS' => 'Permissions',
'Supervisors', 'SUPERVISORS' => 'Supervisors',
'Supervisors Objects' 'SUPERVISORSOBJECTS' => 'Supervisors Objects'
); );
/**
* ExportObjects constructor.
*/
public function __construct()
{
$this->objectsList = array_merge($this->objectsList, $this->processMigrablePlugins());
}
/** /**
* @return array * @return array
*/ */
@@ -51,13 +60,12 @@ class ExportObjects
$aObjectsEnable = explode('|', $objectsEnable); $aObjectsEnable = explode('|', $objectsEnable);
foreach ($this->objectsList as $key => $val) { foreach ($this->objectsList as $key => $val) {
$grid[] = array( $grid[] = array(
'OBJECT_ID' => $key+1, 'OBJECT_ID' => strtoupper(str_replace(' ', '',$val)),
'OBJECT_NAME' => $val, 'OBJECT_NAME' => $val,
'OBJECT_ACTION' => 1, 'OBJECT_ACTION' => 1,
'OBJECT_ENABLE' => in_array(strtoupper(str_replace(' ', '',$val)), $aObjectsEnable) 'OBJECT_ENABLE' => in_array(strtoupper(str_replace(' ', '',$val)), $aObjectsEnable)
); );
} }
$r = new \stdclass(); $r = new \stdclass();
$r->data = $grid; $r->data = $grid;
@@ -67,6 +75,21 @@ class ExportObjects
} }
} }
public function processMigrablePlugins()
{
\G::LoadClass("pluginRegistry");
$plugins = array();
$registry = \PMPluginRegistry::getSingleton();
$data = $registry->getPluginsData();
foreach ($data as $detail) {
$detail = (array)$detail;
if (isset($detail['bIsMigrable']) && $detail['bIsMigrable']) {
$plugins[strtoupper($detail['sNamespace'])] = $detail['sNamespace'];
}
}
return $plugins;
}
/** /**
* @param $idObject * @param $idObject
* @return mixed * @return mixed
@@ -75,7 +98,7 @@ class ExportObjects
public function getObjectName($idObject) public function getObjectName($idObject)
{ {
try { try {
return (str_replace(' ', '', $this->objectsList[$idObject - 1])); return (str_replace(' ', '', $this->objectsList[$idObject]));
} catch (\Exception $e) { } catch (\Exception $e) {
throw $e; throw $e;
@@ -92,7 +115,7 @@ class ExportObjects
try { try {
$mapObjectList = array(); $mapObjectList = array();
foreach ($objects as $objectId) { foreach ($objects as $objectId) {
array_push($mapObjectList, strtoupper(str_replace(' ', '', $this->objectsList[$objectId - 1]))); array_push($mapObjectList, strtoupper(str_replace(' ', '', $this->objectsList[$objectId])));
} }
return $mapObjectList; return $mapObjectList;
} catch (\Exception $e) { } catch (\Exception $e) {
@@ -110,10 +133,9 @@ class ExportObjects
try { try {
$idObjectList = array(); $idObjectList = array();
foreach ($this->objectsList as $key => $val) { foreach ($this->objectsList as $key => $val) {
$key++;
foreach ($objects as $row) { foreach ($objects as $row) {
if(strtoupper(str_replace(' ', '', $this->objectsList[$key - 1])) === $row){ if(strtoupper(str_replace(' ', '', $this->objectsList[$key])) === $row){
array_push($idObjectList, $key); array_push($idObjectList, $row);
} }
} }
} }

View File

@@ -39,8 +39,10 @@ class GranularExporter
$this->beforeExport($objectList); $this->beforeExport($objectList);
foreach ($objectList as $data) { foreach ($objectList as $data) {
$migrator = $this->factory->create($data); $migrator = $this->factory->create($data);
$migrator->beforeExport();
$migratorData = $migrator->export($this->prjuid); $migratorData = $migrator->export($this->prjuid);
$this->mergeData($migratorData); $this->mergeData($migratorData);
$migrator->afterExport();
} }
return $this->publish(); return $this->publish();
} else { } else {
@@ -121,7 +123,8 @@ class GranularExporter
$data = array( $data = array(
'bpmn-definition' => $bpnmDefinition, 'bpmn-definition' => $bpnmDefinition,
'workflow-definition' => $workflowDefinition, 'workflow-definition' => $workflowDefinition,
'workflow-files' => [] 'workflow-files' => [],
'plugin-data' => []
); );
$data["filename"] = $outputFilename; $data["filename"] = $outputFilename;

View File

@@ -36,8 +36,16 @@ class GranularImporter
$this->exportObjects = new ExportObjects(); $this->exportObjects = new ExportObjects();
//create structure //create structure
foreach ($aGranular as $key => $rowObject) { foreach ($aGranular as $key => $rowObject) {
array_push($listObjectGranular, array("name" => strtoupper($this->exportObjects->getObjectName array_push(
($rowObject->id)), "data" => "", "value" => $rowObject->action)); $listObjectGranular,
array(
"name" => strtoupper(
$this->exportObjects->getObjectName($rowObject->id)
),
"data" => [],
"value" => $rowObject->action
)
);
} }
//add data //add data
foreach ($listObjectGranular as $key => $rowObject) { foreach ($listObjectGranular as $key => $rowObject) {
@@ -57,9 +65,9 @@ class GranularImporter
switch ($nameObject) { switch ($nameObject) {
case 'PROCESSDEFINITION': case 'PROCESSDEFINITION':
$objectList['PROCESSDEFINITION']['bpmn'] = isset($data['tables']['bpmn']) ? $this->structureBpmnData $objectList['PROCESSDEFINITION']['bpmn'] = isset($data['tables']['bpmn']) ? $this->structureBpmnData
($data['tables']['bpmn']) : ''; ($data['tables']['bpmn']) : [];
$objectList['PROCESSDEFINITION']['workflow'] = isset($data['tables']['workflow']) ? $objectList['PROCESSDEFINITION']['workflow'] = isset($data['tables']['workflow']) ?
$data['tables']['workflow'] : ''; $data['tables']['workflow'] : [];
break; break;
case 'ASSIGNMENTRULES': case 'ASSIGNMENTRULES':
$objectList['ASSIGNMENTRULES']['tasks'] = isset($data['tables']['workflow']['tasks']) ? $objectList['ASSIGNMENTRULES']['tasks'] = isset($data['tables']['workflow']['tasks']) ?
@@ -127,6 +135,8 @@ class GranularImporter
$data['tables']['workflow']['reportTablesFields'] : []; $data['tables']['workflow']['reportTablesFields'] : [];
break; break;
default: default:
$objectList[$nameObject] = isset($data['tables']['plugins'][strtolower($nameObject)]) ?
$data['tables']['plugins'][strtolower($nameObject)] : '';
break; break;
} }
return $objectList; return $objectList;
@@ -170,7 +180,9 @@ class GranularImporter
if (is_object($objClass)) { if (is_object($objClass)) {
$dataImport = $data['data'][$data['name']]; $dataImport = $data['data'][$data['name']];
$replace = ($data['value'] == 'replace') ? true : false; $replace = ($data['value'] == 'replace') ? true : false;
$objClass->beforeImport($dataImport);
$migratorData = $objClass->import($dataImport, $replace); $migratorData = $objClass->import($dataImport, $replace);
$objClass->afterImport($dataImport);
} }
} }
} else { } else {
@@ -201,10 +213,34 @@ class GranularImporter
{ {
try { try {
if (XmlImporter::IMPORT_OPTION_OVERWRITE !== $option) { if (XmlImporter::IMPORT_OPTION_OVERWRITE !== $option) {
if (count($objectList) !== count($this->exportObjects->getObjectsList())) { $nativeElements = array(
$exception = new ImportException(); 'PROCESSDEFINITION',
$exception->setNameException(\G::LoadTranslation('ID_PROCESS_DEFINITION_INCOMPLETE')); 'ASSIGNMENTRULES',
throw($exception); 'VARIABLES',
'DYNAFORMS',
'INPUTDOCUMENTS',
'OUTPUTDOCUMENTS',
'TRIGGERS',
'REPORTTABLES',
'TEMPLATES',
'FILES',
'DBCONNECTION',
'PERMISSIONS',
'SUPERVISORS',
'SUPERVISORSOBJECTS'
);
foreach ($nativeElements as $element) {
$found = false;
foreach($objectList as $object) {
if ($element == $object->id) {
$found = true;
}
}
if (!$found) {
$exception = new ImportException();
$exception->setNameException(\G::LoadTranslation('ID_PROCESS_DEFINITION_INCOMPLETE'));
throw($exception);
}
} }
} }
return true; return true;
@@ -215,7 +251,7 @@ class GranularImporter
/** /**
* It's very important to import the elements in the right order, if not * It's very important to import the elements in the right order, if not
* chaos will be unleashed, God forgive us all. * some strange behavior will occur during import and export.
* @param $objectList * @param $objectList
*/ */
public function reorderImportOrder($objectList) public function reorderImportOrder($objectList)
@@ -242,6 +278,10 @@ class GranularImporter
$orderedList[$executionOrder] = $objectList[$objectOrder]; $orderedList[$executionOrder] = $objectList[$objectOrder];
} }
} }
for ($j=count($arrangeList); $j<count($objectList); $j++) {
$orderedList[$j] = $objectList[$j];
}
ksort($orderedList); ksort($orderedList);
return $orderedList; return $orderedList;
} }
@@ -272,6 +312,7 @@ class GranularImporter
list($arrayWorkflowTables, $arrayWorkflowFiles) = $workflow->updateDataUidByArrayUid($arrayWorkflowTables, $arrayWorkflowFiles, $result); list($arrayWorkflowTables, $arrayWorkflowFiles) = $workflow->updateDataUidByArrayUid($arrayWorkflowTables, $arrayWorkflowFiles, $result);
} }
$newData['tables']['workflow'] = $arrayWorkflowTables; $newData['tables']['workflow'] = $arrayWorkflowTables;
$newData['tables']['plugins'] = $data["tables"]["plugins"];
$newData['files']['workflow'] = $arrayWorkflowFiles; $newData['files']['workflow'] = $arrayWorkflowFiles;
return array( return array(

View File

@@ -52,6 +52,9 @@ class MigratorFactory
case 'PERMISSIONS': case 'PERMISSIONS':
$class = new PermissionsMigrator(); $class = new PermissionsMigrator();
break; break;
default:
$class = new PluginMigratorAdapter($classname);
break;
} }
return $class; return $class;
} }

View File

@@ -56,7 +56,11 @@ class PMXGenerator
$rootNode->appendChild($metadataNode); $rootNode->appendChild($metadataNode);
$dbData = array("BPMN" => $data["bpmn-definition"], "workflow" => $data["workflow-definition"]); $dbData = array(
"BPMN" => $data["bpmn-definition"],
"workflow" => $data["workflow-definition"],
"plugins" => $data["plugin-data"]
);
foreach ($dbData as $sectionName => $sectionData) { foreach ($dbData as $sectionName => $sectionData) {
$dataNode = $this->domDocument->createElement("definition"); $dataNode = $this->domDocument->createElement("definition");
$dataNode->setAttribute("class", $sectionName); $dataNode->setAttribute("class", $sectionName);

View File

@@ -0,0 +1,60 @@
<?php
namespace ProcessMaker\BusinessModel\Migrator;
/**
* Class PluginMigratorAdapter
* @package ProcessMaker\BusinessModel\Migrator
*/
class PluginMigratorAdapter implements Exportable, Importable
{
private $migrator;
/**
* PluginMigratorAdapter constructor.
*/
public function __construct($pluginName)
{
\G::LoadClass('pluginRegistry');
$registry = \PMPluginRegistry::getSingleton();
$plugin = $registry->getPluginByCode($pluginName);
require_once (
PATH_PLUGINS.PATH_SEP.
$plugin->sPluginFolder.PATH_SEP.
'classes'.PATH_SEP.
$plugin->sMigratorClassName.'.php'
);
$this->migrator = new $plugin->sMigratorClassName();
}
public function beforeExport()
{
return $this->migrator->beforeExport();
}
public function export($prj_uid)
{
return $this->migrator->export($prj_uid);
}
public function afterExport()
{
return $this->migrator->afterExport();
}
public function beforeImport($data)
{
return $this->migrator->beforeImport($data);
}
public function import($data, $replace)
{
return $this->migrator->import($data, $replace);
}
public function afterImport($data)
{
return $this->migrator->afterImport($data);
}
}

View File

@@ -37,8 +37,6 @@ class ProcessDefinitionMigrator implements Importable, Exportable
//Bpmn elements //Bpmn elements
$pjrUid = $this->bpmn->createFromStruct($data['bpmn'], false); $pjrUid = $this->bpmn->createFromStruct($data['bpmn'], false);
//Import workflow elements //Import workflow elements
$this->afterImport($data);
} catch (\Exception $e) { } catch (\Exception $e) {
$exception = new ImportException($e->getMessage()); $exception = new ImportException($e->getMessage());
$exception->setNameException($this->className); $exception->setNameException($this->className);

View File

@@ -242,7 +242,7 @@ abstract class Importer
$newObjectArray = array(); $newObjectArray = array();
$count = 0; $count = 0;
foreach ($objectsToImport as $key => $rowObject) { foreach ($objectsToImport as $key => $rowObject) {
if($rowObject->id != '1'){ if($rowObject->id != 'PROCESSDEFINITION'){
$newObjectArray[++$count] = $rowObject; $newObjectArray[++$count] = $rowObject;
} }
} }

View File

@@ -1184,7 +1184,7 @@ function exportImportProcessObjects(typeAction)
if(!inArray(row.get('OBJECT_ID'),importProcessGlobal.objectGranularImport)) { if(!inArray(row.get('OBJECT_ID'),importProcessGlobal.objectGranularImport)) {
store.remove(row); store.remove(row);
} }
if(row.get('OBJECT_ID') === 1) { /*process definition*/ if(row.get('OBJECT_ID') === "PROCESSDEFINITION") { /*process definition*/
row.set("OBJECT_ACTION","2"); row.set("OBJECT_ACTION","2");
} }
}); });