From d61dc2f7f3cfd699744bb935a5d4c2e859e78123 Mon Sep 17 00:00:00 2001
From: Marcel Heimplatz <m.heimplatz@elo.com>
Date: Fri, 5 Apr 2024 16:51:34 +0200
Subject: [PATCH] Dynamic changing properties in workflow template will be
 ignored

---
 CHANGELOG.md                                  |  8 +-
 build.gradle                                  |  2 +-
 .../eloinst/tasks/DownloadTask.groovy         |  9 +-
 .../installer/lib_sol.common.WfUtils.js       | 90 +++++++++++++++----
 .../installer/lib_sol.dev.BuildPackages.js    |  9 +-
 .../resources/lib_sol.dev.BuildPackages.js    |  9 +-
 6 files changed, 100 insertions(+), 27 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca570b5..4a64f1e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,13 +5,19 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
-## [1.0.3] - 2024-04-04
+## [Unreleased]
 
 ### Changed
 
 - Pulling and pushing to an elo 23 system will let the executed task failure if ix option `ix.feature.preview.enable.newgenarchiveexport` is enabled (new format is not supported at the moment).
 - GUID of each es8 file will be ignored to avoid changes after each push action.
 - Improve gradle lifecycle logging so it is visible which package is pushed or pulled from which index server URL.
+- Dynamic changing properties in workflow template will be ignored
+
+### Fixed
+
+- Fixed an issue with line ending of the installer script files, so building packages in linux environments was not possible
+
 
 ## [1.0.2] - 2024-03-15
 
diff --git a/build.gradle b/build.gradle
index b4efba8..f706428 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,7 +6,7 @@ plugins {
 }
 
 group = 'com.elo.solutions'
-version = '1.0.3'
+version = '1.1.0'
 
 sourceCompatibility = 17
 targetCompatibility = 17
diff --git a/src/main/groovy/com/elo/solutions/eloinst/tasks/DownloadTask.groovy b/src/main/groovy/com/elo/solutions/eloinst/tasks/DownloadTask.groovy
index edf312c..c8fc25c 100644
--- a/src/main/groovy/com/elo/solutions/eloinst/tasks/DownloadTask.groovy
+++ b/src/main/groovy/com/elo/solutions/eloinst/tasks/DownloadTask.groovy
@@ -71,11 +71,10 @@ abstract class DownloadTask extends DefaultTask {
 
         logger.debug("entrypoint {}, scriptArguments={}", entrypoint, scriptArguments)
 
-        logger.lifecycle("""Start downloading package...
-        Repository Path: {}
-        Index Server Url: {}
-        Artifact Name: {}
-        """, packagePath.get(), eloSessionConfiguration.ixUrl, eloinstArtifact.get().asFile.name)
+        logger.lifecycle("Start downloading package {}", project.name)
+        logger.lifecycle(String.format("%-15s: %s", "Repository path", packagePath.get()))
+        logger.lifecycle(String.format("%-15s: %s", "Index Server", eloSessionConfiguration.ixUrl))
+        logger.lifecycle(String.format("%-15s: %s", "Artifact", eloinstArtifact.get().asFile.name))
 
         ScriptRuntime scriptRuntime = scriptWorker.provideScriptRuntime(entrypoint, scriptArguments)
         scriptRuntime.run()
diff --git a/src/main/resources/installer/lib_sol.common.WfUtils.js b/src/main/resources/installer/lib_sol.common.WfUtils.js
index 8aefb20..40ea8ba 100644
--- a/src/main/resources/installer/lib_sol.common.WfUtils.js
+++ b/src/main/resources/installer/lib_sol.common.WfUtils.js
@@ -46,14 +46,19 @@ sol.define("sol.common.WfUtils", {
    * @param {String} flowName Name of the new workflow
    * @param {String} objId Object on which the workflow should be started
    * @param {Number} prio (optional) If specified, the workflow priority will be changed (0=high, 1=medium, 2=low)
+   * @param {Object} params (optional)
+   * @param {de.elo.ix.client.IXConnection} params.connection (optional) Index server connection
    * @return {Number} The ID of the started workflow
    */
-  startWorkflow: function (templFlowId, flowName, objId, prio) {
+  startWorkflow: function (templFlowId, flowName, objId, prio, params) {
     var me = this,
-        flowId;
+        flowId, conn;
 
     me.logger.enter("startWorkflow", arguments);
 
+    params = params || {};
+    conn = params.connection || ixConnect;
+
     if (!templFlowId) {
       throw "Workflow template ID is empty";
     }
@@ -62,9 +67,9 @@ sol.define("sol.common.WfUtils", {
       flowName = flowName.substr(0, 120);
     }
 
-    flowId = ixConnect.ix().startWorkFlow(templFlowId, flowName, objId);
+    flowId = conn.ix().startWorkFlow(templFlowId, flowName, objId);
     if (typeof prio !== "undefined") {
-      me.changeWorkflowPriority(flowId, prio);
+      me.changeWorkflowPriority(flowId, prio, params);
     }
 
     me.logger.exit("startWorkflow", { flowId: flowId });
@@ -128,15 +133,20 @@ sol.define("sol.common.WfUtils", {
    * @param {String} flowId Flow ID
    * @param {Object} params (optional)
    * @param {Boolean} params.inclFinished (optional) If `true`, the workflows will be returned, even if it is already finished
+   * @param {de.elo.ix.client.IXConnection} params.connection (optional) Index server connection
    * @return {de.elo.ix.client.WFDiagram}
    */
   getWorkflow: function (flowId, params) {
-    var workflow;
+    var workflow, conn;
+
+    params = params || {};
+    conn = params.connection || ixConnect;
+
     try {
-      workflow = ixConnect.ix().checkoutWorkFlow(flowId, WFTypeC.ACTIVE, WFDiagramC.mbAll, LockC.NO);
+      workflow = conn.ix().checkoutWorkFlow(flowId, WFTypeC.ACTIVE, WFDiagramC.mbAll, LockC.NO);
     } catch (ex) {
       if (params && (params.inclFinished === true)) {
-        workflow = ixConnect.ix().checkoutWorkFlow(flowId, WFTypeC.FINISHED, WFDiagramC.mbAll, LockC.NO);
+        workflow = conn.ix().checkoutWorkFlow(flowId, WFTypeC.FINISHED, WFDiagramC.mbAll, LockC.NO);
       } else {
         throw ex;
       }
@@ -156,6 +166,10 @@ sol.define("sol.common.WfUtils", {
    * @param {String} config Configuration
    * @param {Boolean} [config.clearUsers=false] Clear the owner names of the template
    * @param {Boolean} [config.addSubTemplateInfo=false] Add sub template information
+   * @param {Boolean} [config.wfDiagramGuid] Update the guid of the workflow
+   * @param {Boolean} [config.wfDiagramId] Update the id of the workflow
+   * @param {Boolean} [config.createDateIso] Update the createDateIson property
+   * @param {Boolean} [config.version] Update the version of the workflow
    * @return {String} JSON representation of the workflow diagram
    */
   getWorkflowAsJson: function (flowId, config) {
@@ -186,10 +200,7 @@ sol.define("sol.common.WfUtils", {
     workflowTplObj = JSON.parse(workflowTplJson);
 
     sol.common.ObjectUtils.traverse(workflowTplObj, function (key, obj) {
-      if (config.clearUsers && (obj._typeId == me.wfVersionTypeId)) {
-        obj.userId = 0;
-        obj.userName = "";
-      }
+       me.updateWorkflowTemplateObj(obj, config)
     });
 
     workflowTplJson = JSON.stringify(workflowTplObj);
@@ -197,6 +208,45 @@ sol.define("sol.common.WfUtils", {
     return workflowTplJson;
   },
 
+  /**
+   *
+   * @private
+   * @param {*} workflowTplObj
+   */
+  updateWorkflowTemplateObj: function(obj, config) {
+    var me = this,
+      config = config || {},
+      isVersionType = function(obj) {
+        return (obj._typeId == me.wfVersionTypeId)
+      },
+      isWfDiagramType = function(obj) {
+        return (obj._typeId == me.wfDiagramTypeId)
+      }
+
+    if (config.clearUsers && isVersionType(obj)) {
+      obj.userId = 0;
+      obj.userName = "";
+    }
+
+    if (config.hasOwnProperty("wfDiagramGuid") && isWfDiagramType(obj)) {
+      obj.guid = config.wfDiagramGuid
+    }
+
+    if (config.hasOwnProperty("wfDiagramId") && isWfDiagramType(obj)) {
+      obj.id = config.wfDiagramId
+    }
+
+    if (config.hasOwnProperty("createDateIso") && isVersionType(obj)) {
+      obj.createDateIso = config.createDateIso
+    }
+
+    if (config.hasOwnProperty("version") && isVersionType(obj) ) {
+      obj.version = config.version
+    }
+
+    return obj;
+  },
+
   /**
    * Adds sub template info
    * @param {Integer} flowId Flow ID
@@ -384,14 +434,20 @@ sol.define("sol.common.WfUtils", {
    * Changes the priority of a workflow.
    * @param {String} flowId The workflows ID
    * @param {Number} prio The new priority (0=high, 1=medium, 2=low)
+   * @param {Object} params (optional)
+   * @param {de.elo.ix.client.IXConnection} params.connection (optional) Index server connection
    */
-  changeWorkflowPriority: function (flowId, prio) {
-    var wfDiagram;
+  changeWorkflowPriority: function (flowId, prio, params) {
+    var wfDiagram, conn;
+
+    params = params || {};
+    conn = params.connection || ixConnect;
+
     if ((typeof prio !== "undefined") && (Object.prototype.toString.call(prio) === "[object Number]") && (prio >= 0) && (prio <= 2)) {
-      wfDiagram = ixConnect.ix().checkoutWorkFlow(flowId, WFTypeC.ACTIVE, WFDiagramC.mbAll, LockC.NO);
+      wfDiagram = conn.ix().checkoutWorkFlow(flowId, WFTypeC.ACTIVE, WFDiagramC.mbAll, LockC.NO);
       if (wfDiagram.prio !== prio) {
         wfDiagram.prio = prio;
-        ixConnect.ix().checkinWorkFlow(wfDiagram, WFDiagramC.mbAll, LockC.NO);
+        conn.ix().checkinWorkFlow(wfDiagram, WFDiagramC.mbAll, LockC.NO);
       }
     }
   },
@@ -1791,6 +1847,4 @@ sol.define("sol.common.WfUtils", {
 
     return appUrl;
   }
-});
-
-
+});
\ No newline at end of file
diff --git a/src/main/resources/installer/lib_sol.dev.BuildPackages.js b/src/main/resources/installer/lib_sol.dev.BuildPackages.js
index fd49911..71622d2 100644
--- a/src/main/resources/installer/lib_sol.dev.BuildPackages.js
+++ b/src/main/resources/installer/lib_sol.dev.BuildPackages.js
@@ -611,7 +611,14 @@ sol.define("sol.dev.BuildPackage", {
 
     workflowTemplateFile = new java.io.File(me.buildConfig.workflowTemplatesDirPath + java.io.File.separator + workflowTemplateFileName + ".json");
 
-    sol.common.WfUtils.exportWorkflowTemplate(workflowTemplateName, workflowTemplateFile, { clearUsers: true, addSubTemplateInfo: true });
+    sol.common.WfUtils.exportWorkflowTemplate(workflowTemplateName, workflowTemplateFile, {
+        clearUsers: true,
+        addSubTemplateInfo: true,
+        wfDiagramGuid: "",
+        wfDiagramId: -1,
+        createDateIso: "",
+        version: "1.0"
+    });
   },
 
   /**
diff --git a/src/main/resources/lib_sol.dev.BuildPackages.js b/src/main/resources/lib_sol.dev.BuildPackages.js
index b40aeb9..e9982bb 100644
--- a/src/main/resources/lib_sol.dev.BuildPackages.js
+++ b/src/main/resources/lib_sol.dev.BuildPackages.js
@@ -610,7 +610,14 @@ sol.define("sol.dev.BuildPackage", {
 
     workflowTemplateFile = new java.io.File(me.buildConfig.workflowTemplatesDirPath + java.io.File.separator + workflowTemplateFileName + ".json");
 
-    sol.common.WfUtils.exportWorkflowTemplate(workflowTemplateName, workflowTemplateFile, { clearUsers: true, addSubTemplateInfo: true });
+    sol.common.WfUtils.exportWorkflowTemplate(workflowTemplateName, workflowTemplateFile, {
+        clearUsers: true,
+        addSubTemplateInfo: true,
+        wfDiagramGuid: "",
+        wfDiagramId: -1,
+        createDateIso: "",
+        version: "1.0"
+    });
   },
 
   /**
-- 
GitLab