composition issues fix

Issue-ID: SDC-1591
Change-Id: I1cf9fc840d42c3d84c0f71ddcce0a9749f802c05
Signed-off-by: Stanislav Vishnevetskiy <shlomo-stanisla.vishnevetskiy@amdocs.com>
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/composition/CompositionView.js b/workflow-designer-ui/src/main/frontend/src/features/version/composition/CompositionView.js
index d5b06d3..41c6db0 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/composition/CompositionView.js
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/composition/CompositionView.js
@@ -46,7 +46,7 @@
     }
 
     componentDidMount() {
-        const { composition, activities } = this.props;
+        const { composition, activities, inputOutput } = this.props;
 
         this.modeler = new CustomModeler({
             propertiesPanel: {
@@ -61,7 +61,8 @@
             },
             workflow: {
                 activities: activities,
-                onChange: this.onActivityChanged
+                onChange: this.onActivityChanged,
+                workflowInputOutput: inputOutput
             }
         });
 
@@ -79,16 +80,20 @@
         const selectedActivity = this.props.activities.find(
             el => el.name === selectedValue
         );
+        const config = this.modeler.get('config');
 
         if (selectedActivity) {
             const inputsOutputs = {
                 inputs: selectedActivity.inputs,
                 outputs: selectedActivity.outputs
             };
+            config.workflow.selectedActivityInputs = inputsOutputs;
+            this.modeler.config = config;
             setElementInputsOutputs(
                 bo,
                 inputsOutputs,
-                this.modeler.get('moddle')
+                this.modeler.get('moddle'),
+                true
             );
         }
     };
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/composition/bpmnUtils.js b/workflow-designer-ui/src/main/frontend/src/features/version/composition/bpmnUtils.js
index adc4286..d5916f1 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/composition/bpmnUtils.js
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/composition/bpmnUtils.js
@@ -34,7 +34,12 @@
     });
 }
 
-export function setElementInputsOutputs(businessObject, inputOutput, moddle) {
+export function setElementInputsOutputs(
+    businessObject,
+    inputOutput,
+    moddle,
+    cleanInputsOutpus
+) {
     const { inputs = [], outputs = [] } = inputOutput;
 
     if (!businessObject.extensionElements) {
@@ -51,14 +56,20 @@
     const processInputs = updatedData(
         moddle,
         inputs,
-        (existingInputOutput && existingInputOutput.inputParameters) || [],
+        cleanInputsOutpus
+            ? []
+            : (existingInputOutput && existingInputOutput.inputParameters) ||
+              [],
         bpmnElementsTypes.INPUT_PARAMETER
     );
 
     const processOutputs = updatedData(
         moddle,
         outputs,
-        (existingInputOutput && existingInputOutput.outputParameters) || [],
+        cleanInputsOutpus
+            ? []
+            : (existingInputOutput && existingInputOutput.outputParameters) ||
+              [],
         bpmnElementsTypes.OUTPUT_PARAMETER
     );
 
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/descriptors/camunda.json b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/descriptors/camunda.json
index b671c43..6613c4b 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/descriptors/camunda.json
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/descriptors/camunda.json
@@ -563,6 +563,16 @@
           "type": "String"
         },
         {
+          "name": "workflowSource",
+          "isAttr": true,
+          "type": "String"
+        },
+        {
+          "name": "workflowTarget",
+          "isAttr": true,
+          "type": "String"
+        },
+        {
           "name": "value",
           "isBody": true,
           "type": "String"
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/WorkflowPropertiesProvider.js b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/WorkflowPropertiesProvider.js
index 98a5797..34130d0 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/WorkflowPropertiesProvider.js
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/WorkflowPropertiesProvider.js
@@ -278,7 +278,8 @@
                 element,
                 bpmnFactory,
                 elementRegistry,
-                translate
+                translate,
+                config
             )
         };
         tabs.unshift(inputOutputTab);
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/InputOutputParameterProps.js b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/InputOutputParameterProps.js
index a1f1efb..d221c6e 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/InputOutputParameterProps.js
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/InputOutputParameterProps.js
@@ -1,15 +1,21 @@
-'use strict';
-
 import inputOutputParameter from './implementation/InputOutputParameter';
 import assign from 'lodash.assign';
 
-module.exports = function(group, element, bpmnFactory, options, translate) {
+export default function(
+    group,
+    element,
+    bpmnFactory,
+    options,
+    translate,
+    config
+) {
     group.entries = group.entries.concat(
         inputOutputParameter(
             element,
             bpmnFactory,
             assign({}, options),
-            translate
+            translate,
+            config
         )
     );
-};
+}
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/InputOutputProps.js b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/InputOutputProps.js
index df1e543..bdcbab4 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/InputOutputProps.js
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/InputOutputProps.js
@@ -1,13 +1,13 @@
 'use strict';
 
-var inputOutput = require('./implementation/InputOutput');
+import inputOutput from './implementation/InputOutput';
 
-module.exports = function(group, element, bpmnFactory, translate) {
-    var inputOutputEntry = inputOutput(element, bpmnFactory, {}, translate);
+export default function(group, element, bpmnFactory, translate) {
+    const inputOutputEntry = inputOutput(element, bpmnFactory, {}, translate);
 
     group.entries = group.entries.concat(inputOutputEntry.entries);
 
     return {
         getSelectedParameter: inputOutputEntry.getSelectedParameter
     };
-};
+}
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/createInputOutputTabGroups.js b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/createInputOutputTabGroups.js
index f14e359..3dede1a 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/createInputOutputTabGroups.js
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/createInputOutputTabGroups.js
@@ -1,6 +1,6 @@
-let inputOutputParameter = require('./InputOutputParameterProps');
-let inputOutput = require('./InputOutputProps');
-var is = require('bpmn-js/lib/util/ModelUtil').is;
+import inputOutputParameter from './InputOutputParameterProps';
+import inputOutput from './InputOutputProps';
+const is = require('bpmn-js/lib/util/ModelUtil').is;
 
 var getInputOutputParameterLabel = function(param, translate) {
     if (is(param, 'camunda:InputParameter')) {
@@ -18,7 +18,8 @@
     element,
     bpmnFactory,
     elementRegistry,
-    translate
+    translate,
+    config
 ) {
     var inputOutputGroup = {
         id: 'input-output',
@@ -32,7 +33,6 @@
         bpmnFactory,
         translate
     );
-
     var inputOutputParameterGroup = {
         id: 'input-output-parameter',
         entries: [],
@@ -50,7 +50,8 @@
         element,
         bpmnFactory,
         options,
-        translate
+        translate,
+        config
     );
 
     return [inputOutputGroup, inputOutputParameterGroup];
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/InputOutput.js b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/InputOutput.js
index 2adf7f7..8962a30 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/InputOutput.js
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/InputOutput.js
@@ -1,9 +1,8 @@
-'use strict';
+import inputOutputHelper from './InputOutputHelper';
 var getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject;
 
 var elementHelper = require('bpmn-js-properties-panel/lib/helper/ElementHelper'),
     extensionElementsHelper = require('bpmn-js-properties-panel/lib/helper/ExtensionElementsHelper'),
-    inputOutputHelper = require('./InputOutputHelper'),
     cmdHelper = require('bpmn-js-properties-panel/lib/helper/CmdHelper');
 
 var extensionElementsEntry = require('bpmn-js-properties-panel/lib/provider/camunda/parts/implementation//ExtensionElements');
@@ -61,7 +60,7 @@
     );
 }
 
-module.exports = function(element, bpmnFactory, options, translate) {
+export default function(element, bpmnFactory, options, translate) {
     var TYPE_LABEL = {
         'camunda:Map': translate('Map'),
         'camunda:List': translate('List'),
@@ -144,8 +143,6 @@
                       name: value
                   });
 
-            console.log(newElem);
-
             commands.push(
                 cmdHelper.addElementsTolist(element, inputOutput, prop, [
                     newElem
@@ -289,4 +286,4 @@
     }
 
     return result;
-};
+}
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/InputOutputHelper.js b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/InputOutputHelper.js
index 13bc50a..e3a79d4 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/InputOutputHelper.js
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/InputOutputHelper.js
@@ -1,5 +1,3 @@
-'use strict';
-
 var ModelUtil = require('bpmn-js/lib/util/ModelUtil'),
     is = ModelUtil.is,
     getBusinessObject = ModelUtil.getBusinessObject;
@@ -13,8 +11,6 @@
 
 var InputOutputHelper = {};
 
-module.exports = InputOutputHelper;
-
 function getElements(bo, type, prop) {
     var elems = extensionElementsHelper.getExtensionElements(bo, type) || [];
     return !prop ? elems : (elems[0] || {})[prop] || [];
@@ -164,3 +160,5 @@
         element.type !== 'bpmn:Process'
     );
 };
+
+export default InputOutputHelper;
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/InputOutputParameter.js b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/InputOutputParameter.js
index 628874f..faa20fb 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/InputOutputParameter.js
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/InputOutputParameter.js
@@ -1,9 +1,8 @@
-'use strict';
+import inputOutputHelper from './InputOutputHelper';
 
 var is = require('bpmn-js/lib/util/ModelUtil').is;
 
 var elementHelper = require('bpmn-js-properties-panel/lib/helper/ElementHelper'),
-    inputOutputHelper = require('./InputOutputHelper'),
     cmdHelper = require('bpmn-js-properties-panel/lib/helper/CmdHelper'),
     utils = require('bpmn-js-properties-panel/lib/Utils');
 
@@ -34,7 +33,7 @@
     return inputOutputHelper.isInputOutputSupported(element, insideConnector);
 }
 
-module.exports = function(element, bpmnFactory, options, translate) {
+export default function(element, bpmnFactory, options, translate, config) {
     var typeInfo = {
         'camunda:Map': {
             value: 'map',
@@ -421,5 +420,97 @@
         })
     );
 
+    //workflow source parameter  (type = text) ///////////////////////////////////////////////////////
+    const workflowInputs = config.workflowInputOutput.inputs.map(item => ({
+        name: item.name,
+        value: item.name
+    }));
+
+    const workflowOutputs = config.workflowInputOutput.outputs.map(item => ({
+        name: item.name,
+        value: item.name
+    }));
+
+    const workflowSources = [
+        { name: '', value: '' },
+        ...workflowInputs,
+        ...workflowOutputs
+    ];
+
+    entries.push(
+        entryFactory.selectBox({
+            id: 'parameter-workflowSource',
+            label: 'Workflow Source Parameter',
+            selectOptions: workflowSources,
+            modelProperty: 'workflowSource',
+
+            get: function(element, node) {
+                return {
+                    workflowSource: (getSelected(element, node) || {})
+                        .workflowSource
+                };
+            },
+
+            set: function(element, values, node) {
+                var properties = {
+                    workflowSource: undefined
+                };
+
+                properties.workflowSource = values.workflowSource;
+                var param = getSelected(element, node);
+                values.workflowSource = values.workflowSource || undefined;
+
+                return cmdHelper.updateBusinessObject(element, param, values);
+            },
+
+            hidden: function(element, node) {
+                var bo = getSelected(element, node);
+                return !(
+                    bo &&
+                    bo.$type &&
+                    bo.$type === 'camunda:InputParameter'
+                );
+            }
+        })
+    );
+
+    //workflow target parameter  (type = text) ///////////////////////////////////////////////////////
+    entries.push(
+        entryFactory.selectBox({
+            id: 'parameter-workflowTarget',
+            label: 'Workflow Target Parameter',
+            selectOptions: workflowSources,
+            modelProperty: 'workflowTarget',
+
+            get: function(element, node) {
+                return {
+                    workflowTarget: (getSelected(element, node) || {})
+                        .workflowTarget
+                };
+            },
+
+            set: function(element, values, node) {
+                var properties = {
+                    workflowTarget: undefined
+                };
+
+                properties.workflowTarget = values.workflowTarget;
+                var param = getSelected(element, node);
+                values.workflowTarget = values.workflowTarget || undefined;
+
+                return cmdHelper.updateBusinessObject(element, param, values);
+            },
+
+            hidden: function(element, node) {
+                var bo = getSelected(element, node);
+                return !(
+                    bo &&
+                    bo.$type &&
+                    bo.$type === 'camunda:OutputParameter'
+                );
+            }
+        })
+    );
+
     return entries;
-};
+}
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/WorkflowImplementationType.js b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/WorkflowImplementationType.js
index 11e8fcb..eac00fd 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/WorkflowImplementationType.js
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/composition/custom-properties-provider/provider/camunda/parts/implementation/WorkflowImplementationType.js
@@ -33,7 +33,7 @@
 
 ACTIVITY_PROPS[implementationType] = undefined;
 
-module.exports = function(element, bpmnFactory, options, translate) {
+export default function(element, bpmnFactory, options, translate) {
     var DEFAULT_OPTIONS = [
         { value: 'class', name: translate('Java Class') },
         { value: 'expression', name: translate('Expression') },
@@ -224,4 +224,4 @@
     );
 
     return entries;
-};
+}
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/composition/newDiagram.bpmn b/workflow-designer-ui/src/main/frontend/src/features/version/composition/newDiagram.bpmn
index 7ed9b6e..1e2ca7a 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/composition/newDiagram.bpmn
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/composition/newDiagram.bpmn
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="UTF-8"?>
+export default `<?xml version="1.0" encoding="UTF-8"?>
 <bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="sample-diagram" targetNamespace="http://bpmn.io/schema/bpmn">
   <bpmn2:process id="Process_1" isExecutable="false">
   </bpmn2:process>
@@ -6,4 +6,5 @@
     <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
     </bpmndi:BPMNPlane>
   </bpmndi:BPMNDiagram>
-</bpmn2:definitions>
+</bpmn2:definitions>`;
+
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/inputOutput/InputOutputView.jsx b/workflow-designer-ui/src/main/frontend/src/features/version/inputOutput/InputOutputView.jsx
index 6b76933..4dea49d 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/inputOutput/InputOutputView.jsx
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/inputOutput/InputOutputView.jsx
@@ -67,13 +67,7 @@
         this.props.handleSearch(value);
     };
 
-    handleNameChange = (key, isBlur = false) => value => {
-        let name = isBlur ? value.target.value : value;
-        name = name.replace(/\s+/g, ' ');
-        name = isBlur
-            ? name.replace(/^\s+|\s+$/g, '')
-            : name.replace(/^\s+/g, '');
-
+    handleNameChange = key => name => {
         this.props.handleNameChange(name, key);
     };
 
@@ -144,7 +138,6 @@
                     nameErrorMessage={errorMessage}
                     dataTestId="wf-input-output-row"
                     handleNameChange={this.handleNameChange(i)}
-                    handleNameBlur={this.handleNameChange(i, true)}
                     handleTypeChange={this.handleTypeChange(i)}
                     handleMandatoryChange={this.handleMandatoryChange(i)}
                     handleRemoveClick={this.handleRemoveClick(i)}
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/inputOutput/inputOutputValidations.js b/workflow-designer-ui/src/main/frontend/src/features/version/inputOutput/inputOutputValidations.js
index 50a6421..d405787 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/inputOutput/inputOutputValidations.js
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/inputOutput/inputOutputValidations.js
@@ -52,7 +52,7 @@
         const groupKey = value.name;
 
         if (groupKey) {
-            if (!/^[\w\s\d]+$/.test(groupKey)) {
+            if (!/^[\w\d]+$/.test(groupKey)) {
                 result.push(key);
             }
         }
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/versionApi.js b/workflow-designer-ui/src/main/frontend/src/features/version/versionApi.js
index 4e591c9..ab9394c 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/versionApi.js
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/versionApi.js
@@ -46,10 +46,20 @@
             `${baseUrl(workflowId)}/${versionId}/artifact`
         );
     },
-    updateVersionArtifact: ({ workflowId, versionId, payload }) => {
+    updateVersionArtifact: ({
+        workflowId,
+        versionId,
+        workflowName,
+        versionName,
+        payload
+    }) => {
         let formData = new FormData();
         var blob = new Blob([payload], { type: 'text/xml' });
-        formData.append('fileToUpload', blob);
+        formData.append(
+            'fileToUpload',
+            blob,
+            `${workflowName}-${versionName}.bpmn`
+        );
 
         return RestfulAPIUtil.put(
             `${baseUrl(workflowId)}/${versionId}/artifact`,
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/versionController/VersionControllerView.jsx b/workflow-designer-ui/src/main/frontend/src/features/version/versionController/VersionControllerView.jsx
index d018887..20a14c6 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/versionController/VersionControllerView.jsx
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/versionController/VersionControllerView.jsx
@@ -51,8 +51,13 @@
     };
 
     sendSaveParamsToServer = () => {
-        const { savedParams, saveParamsToServer, workflowId } = this.props;
-        saveParamsToServer({ params: savedParams, workflowId });
+        const {
+            savedParams,
+            saveParamsToServer,
+            workflowId,
+            workflowName
+        } = this.props;
+        saveParamsToServer({ params: savedParams, workflowId, workflowName });
     };
 
     certifyVersion = () => {
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/versionSaga.js b/workflow-designer-ui/src/main/frontend/src/features/version/versionSaga.js
index c8fdaaf..a7dabed 100644
--- a/workflow-designer-ui/src/main/frontend/src/features/version/versionSaga.js
+++ b/workflow-designer-ui/src/main/frontend/src/features/version/versionSaga.js
@@ -78,8 +78,10 @@
     try {
         const {
             workflowId,
+            workflowName,
             params: { composition, ...versionData }
         } = action.payload;
+
         yield call(versionApi.updateVersion, {
             workflowId,
             params: versionData
@@ -87,6 +89,8 @@
         if (composition) {
             yield call(versionApi.updateVersionArtifact, {
                 workflowId,
+                workflowName,
+                versionName: versionData.name.split('.').join('_'),
                 versionId: versionData.id,
                 payload: composition
             });