/*******************************************************************************
 * (c) Copyright 2016 Hewlett-Packard Development Company, L.P.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0 which accompany this distribution.
 *
 * The Apache License is available at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *******************************************************************************/
package io.cloudslang.lang.runtime.steps;

import io.cloudslang.lang.compiler.modeller.model.SeqStep;
import io.cloudslang.lang.entities.bindings.values.SensitiveValue;
import io.cloudslang.lang.entities.bindings.values.Value;
import io.cloudslang.runtime.api.sequential.SequentialExecutionParametersProvider;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.apache.commons.lang3.StringUtils.substring;

public class CloudSlangSequentialExecutionParametersProviderImpl implements SequentialExecutionParametersProvider,
        Serializable {
    private static final long serialVersionUID = -6086097846840796564L;

    public static final String SEQUENTIAL_PARAMETER = "Parameter(";
    private final Map<String, Value> currentContext;
    private final List<SeqStep> seqSteps;
    private final boolean external;

    public CloudSlangSequentialExecutionParametersProviderImpl(
            Map<String, Value> currentContext,
            List<SeqStep> seqSteps,
            Boolean external) {
        this.currentContext = currentContext;
        this.seqSteps = seqSteps;
        this.external = external;
    }

    @Override
    public Object[] getExecutionParameters() {
        Map<String, Value> execParams = new HashMap<>();
        for (SeqStep step : seqSteps) {
            String args = step.getArgs();
            if (StringUtils.startsWith(args, SEQUENTIAL_PARAMETER)) {
                String paramName = substring(args, SEQUENTIAL_PARAMETER.length(), args.length() - 1)
                        .replaceAll("^\"|\"$", "");
                Value value = currentContext.get(paramName);
                if (value != null) {
                    execParams.put(paramName, value);
                }
            }
        }
        // TODO fix get execution from map
        return new Object[]{execParams};
    }

    @Override
    public boolean getExternal() {
        return external;
    }
}

@@ -1823,24 +1823,219 @@
 ashMap%3C%3E();%0A
+%0A        if (external) %7B%0A            // External seq operation doesn't require step args filtering since all the inputs are external%0A            execParams = currentContext;%0A        %7D else %7B%0A    
         for 
@@ -2058,24 +2058,28 @@
 seqSteps) %7B%0A
+    
             
@@ -2116,24 +2116,28 @@
             
+ 
+   
 if (StringUt
@@ -2178,24 +2178,28 @@
 RAMETER)) %7B%0A
+    
             
@@ -2311,16 +2311,20 @@
         
+    
 .replace
@@ -2343,16 +2343,20 @@
 %22, %22%22);%0A
+    
         
@@ -2420,24 +2420,28 @@
             
+    
 if (value !=
@@ -2445,24 +2445,28 @@
  != null) %7B%0A
+    
             
@@ -2503,24 +2503,46 @@
 me, value);%0A
+                    %7D%0A
             

Add all inputs for external operation (#1099)