From 9a0d526c93bf556047eda1c3f277e9bd75e62448 Mon Sep 17 00:00:00 2001 From: Sebastian Pongratz <s.pongratz@adito.de> Date: Wed, 18 Nov 2020 11:57:06 +0000 Subject: [PATCH] Dependency_WorkflowExtentions --- process/Context_lib/process.js | 21 +++ process/Dependency_lib/process.js | 39 +++- process/Workflow_lib/process.js | 178 +++++++++++++++++- .../process.js | 0 .../workflowExtension_serverProcess.aod | 9 + 5 files changed, 236 insertions(+), 11 deletions(-) create mode 100644 process/workflowExtension_serverProcess/process.js create mode 100644 process/workflowExtension_serverProcess/workflowExtension_serverProcess.aod diff --git a/process/Context_lib/process.js b/process/Context_lib/process.js index 7aa6dedab7..5713843c84 100644 --- a/process/Context_lib/process.js +++ b/process/Context_lib/process.js @@ -86,6 +86,27 @@ ContextUtils.getEntity = function (pContextId) return project.getContextStructure(pContextId).entity; } +/** + * Returns the context associated with the entity + * + * @param {String} pEntity the name of the Entity + * @return {String} the context + */ +ContextUtils.getContextId = function (pEntity) +{ + if (!pEntity) + return null; + + let contexte = ContextUtils.getContexts(false, [], false); + + for (let i = 0; i < contexte.length; i++) { + if (ContextUtils.getEntity(contexte[i][0]) == pEntity) + return contexte[i][0]; + } + return null; + +} + /** * Returns the title of the entity associated with the context * diff --git a/process/Dependency_lib/process.js b/process/Dependency_lib/process.js index d654f2f466..1f4e1267a8 100644 --- a/process/Dependency_lib/process.js +++ b/process/Dependency_lib/process.js @@ -29,6 +29,9 @@ Dependency.mapping = function () return { "Address_entity": { "Organisation_entity" : { + "options" : { + "isObservable" : true + }, "getUIDsfn" : function (pRowData, pChangedData) { var tableField = "ADDRESS.CONTACT_ID"; var res = []; @@ -47,12 +50,26 @@ Dependency.mapping = function () * Returns the dependencies on the entity * * @param {String} [pEntity] the name of the entity + * @param {Object} [pOptionFilter] the Object must be handed over in the format: { "option" : true/false } + * + * @example + * Dependency.getDependency("Organisation_entity", {"isObservable" : true }); + * @example + * Dependency.getDependency("Organisation_entity", {})); + * @example + * Dependency.getDependency("Organisation_entity")); + * * @return {String[]} the founded Dependencies. If no one is found, you get an empty Array */ -Dependency.getDependency = function (pEntity) { +Dependency.getDependency = function (pEntity, pOptionFilter) { if (Dependency.mapping()[pEntity]) { - return Object.keys(Dependency.mapping()[pEntity]); + return Object.keys(Dependency.mapping()[pEntity]).filter(function (key) { + return (!pOptionFilter || Object.keys(pOptionFilter).every(function (pOption) { + let option = Dependency.mapping()[pEntity][key]["options"][pOption] + return option && pOptionFilter[pOption] == option; + })); + }); } @@ -63,10 +80,24 @@ Dependency.getDependency = function (pEntity) { * Returns the dependencies that this entity has on others * * @param {String} [pEntity] the name of the entity + * @param {Object} [pOptionFilter] the Object must be handed over in the format: { "option" : true/false } + * + * @example + * Dependency.getReverseDependency("Organisation_entity", {"isObservable" : true }); + * @example + * Dependency.getReverseDependency("Organisation_entity", {})); + * @example + * Dependency.getReverseDependency("Organisation_entity")); + * * @return {String[]} the founded Dependencies. If no one is found, you get an empty Array */ -Dependency.getReverseDependency = function (pEntity) { +Dependency.getReverseDependency = function (pEntity, pOptionFilter) { return Object.keys(Dependency.mapping()).filter(function (key) { - return Dependency.mapping()[key][pEntity]; + return Dependency.mapping()[key][pEntity] && (!pOptionFilter || Object.keys(pOptionFilter).every(function (pOption){ + let option = Dependency.mapping()[key][pEntity]["options"][pOption] + return option && pOptionFilter[pOption] == option; + })); }); } + + diff --git a/process/Workflow_lib/process.js b/process/Workflow_lib/process.js index 38627a87e2..8e0cef19c1 100644 --- a/process/Workflow_lib/process.js +++ b/process/Workflow_lib/process.js @@ -1,3 +1,4 @@ +import("Employee_lib"); import("system.process"); import("Util_lib"); import("system.text"); @@ -46,18 +47,15 @@ WorkflowUtils.openNewInstance = function (pVariables, pTargetIds, pTargetContext { if ((!pTargetIds || pTargetIds.length === 0) && pSelectionFilter) pTargetIds = []; - else if (!pTargetIds) - pTargetIds = [WorkflowVariables.TARGET_ID.getDefaultValue()]; if (!pVariables) pVariables = {}; Object.assign(pVariables, WorkflowVariables.getTargetVariables(pTargetIds, pTargetContext)); neon.openContext("WorkflowLauncher", "WorkflowLauncherEdit_view", null, neon.OPERATINGSTATE_VIEW, { - "ProcessVariables_param": JSON.stringify(pVariables), - "TargetContext_param": pVariables[WorkflowVariables.TARGET_CONTEXT()], - "TargetFilter_param": pSelectionFilter ? JSON.stringify(pSelectionFilter) : "", - "Targets_param": JSON.stringify(pTargetIds) + "ProcessVariables_param" : JSON.stringify(pVariables), + "TargetContext_param" : pVariables[WorkflowVariables.TARGET_CONTEXT()], + "TargetFilter_param" : pSelectionFilter ? JSON.stringify(pSelectionFilter) : "" }); } @@ -176,7 +174,19 @@ WorkflowSignalSender.deleted = function (pVariables, pTargetId, pTargetContext) */ WorkflowSignalSender.eventHappened = function (pEvent, pTargetId, pTargetContext, pVariables) { - var variables = WorkflowVariables.getTargetVariables(pTargetId, pTargetContext); + let temp = {}; + temp[ WorkflowVariables.TARGET_CONTEXT()] = pTargetContext; + temp[WorkflowVariables.TARGET_ID()] = pTargetId; + temp[WorkflowVariables.TRIGGER()] = pEvent; + let variables = WorkflowVariables.getAllVariablesValue(temp); + + var processConfig = process.createStartAsyncConfig().setName("workflowExtension_serverProcess") + .setLocalVariables({"variablesWorkflow" : JSON.stringify(variables)}) + .setShowErrorDialog(true) + .setUser(vars.get("sys.user")) + .setThreadPriority(process.THREADPRIORITY_NORM) + .setTimerType(process.TIMERTYPE_SERVER); + process.startAsync(processConfig); var signals = WorkflowSignalSender.getSignalConfig(variables[WorkflowVariables.TARGET_CONTEXT()], pEvent); signals.forEach(function (signal) @@ -281,6 +291,160 @@ WorkflowVariables.TARGET_CONTEXT.getDefaultValue = function () return ContextUtils.getCurrentContextId(); } +/** + * Returns the variable name for the rowdata + */ +WorkflowVariables.ROWDATA = function () +{ + return "rowdata"; +} + +/** + * Returns the default value for the rowdata + */ +WorkflowVariables.ROWDATA.getDefaultValue = function () +{ + return JSON.stringify(vars.get("$local.rowdata")); +} + +/** + * Returns the variable name for the changed rows + */ +WorkflowVariables.CHANGED_ROWS = function () +{ + return "changedRows"; +} + +/** + * Returns the default value for the changed rows + */ +WorkflowVariables.CHANGED_ROWS.getDefaultValue = function () +{ + return JSON.stringify(vars.get("$local.changed")); +} + +/** + * Returns the variable name for the event user + */ +WorkflowVariables.EVENT_USER = function () +{ + return "eventUser"; +} + +/** + * Returns the default value for the event user + */ +WorkflowVariables.EVENT_USER.getDefaultValue = function () +{ + return EmployeeUtils.getCurrentUserId(); +} + +/** + * Returns the variable name for the event time + */ +WorkflowVariables.EVENT_TIME = function () +{ + return "eventTime"; +} + +/** + * Returns the default value for the event time + */ +WorkflowVariables.EVENT_TIME.getDefaultValue = function () +{ + return vars.get("$sys.date"); +} + +/** + * Returns the variable name for the trigger + */ +WorkflowVariables.TRIGGER = function () +{ + return "trigger"; +} + +/** + * Returns the default value for the trigger + */ +WorkflowVariables.TRIGGER.getDefaultValue = function () +{ + return null; +} + +/** + * Returns the variable name for the contenttitle + */ +WorkflowVariables.CONTENTTITLE = function () +{ + return "contenttitle"; +} + +/** + * Returns the default value for the contenttitle + */ +WorkflowVariables.CONTENTTITLE.getDefaultValue = function () +{ + return vars.get("$field.#CONTENTTITLE"); +} + +/** + * Returns an array of the WorkflowVariables + * + * @return {Array} array containing the variables name + */ +WorkflowVariables.getAllVariablesName = function () +{ + return [ + WorkflowVariables.TARGET_CONTEXT(), + WorkflowVariables.TARGET_ID() + ] +} + +/** + * Returns an array of the Variables, which contains the variables name + * + * @return {Array} array containing the variables + */ +WorkflowVariables.getAllVariables = function () +{ + return [ + "CHANGED_ROWS", + "EVENT_TIME", + "EVENT_USER", + "ROWDATA", + "TARGET_CONTEXT", + "TARGET_ID", + "TRIGGER", + "CONTENTTITLE" + ] +} + +/** + * Makes an object containing the variables + * + * @param {Objcet} [pVariables] value for the variables, if not provided, the dafault value is used. + * The Object have to hand over in the following format: + * + * {WorkflowVariable : value} + * + * @return {Object} object containing the variables + */ +WorkflowVariables.getAllVariablesValue = function (pVariables) +{ + if (!pVariables) + pVariables = {}; + + let tempVariables = {}; + WorkflowVariables.getAllVariables().forEach(function (v){ + let tempName = WorkflowVariables[v](); + if (pVariables[tempName]) + tempVariables[tempName] = pVariables[tempName] + else + tempVariables[tempName] = WorkflowVariables[v].getDefaultValue(); + }); + return tempVariables; +} + /** * Makes an object containing the variables "targetId" and "targetContext" * diff --git a/process/workflowExtension_serverProcess/process.js b/process/workflowExtension_serverProcess/process.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/process/workflowExtension_serverProcess/workflowExtension_serverProcess.aod b/process/workflowExtension_serverProcess/workflowExtension_serverProcess.aod new file mode 100644 index 0000000000..d9ed92e0f4 --- /dev/null +++ b/process/workflowExtension_serverProcess/workflowExtension_serverProcess.aod @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<process xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.2.1" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/process/1.2.1"> + <name>workflowExtension_serverProcess</name> + <majorModelMode>DISTRIBUTED</majorModelMode> + <process>%aditoprj%/process/workflowExtension_serverProcess/process.js</process> + <variants> + <element>EXECUTABLE</element> + </variants> +</process> -- GitLab