package com.heroku;

import com.atlassian.bamboo.collections.ActionParametersMap;
import com.atlassian.bamboo.task.AbstractTaskConfigurator;
import com.atlassian.bamboo.task.TaskDefinition;
import com.atlassian.bamboo.utils.error.ErrorCollection;
import com.opensymphony.xwork.TextProvider;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

public class ArtifactDeploymentConfigurator extends AbstractTaskConfigurator {
    private TextProvider textProvider;

    @NotNull
    @Override
    public Map<String, String> generateTaskConfigMap(@NotNull final ActionParametersMap params, @Nullable final TaskDefinition previousTaskDefinition) {
        final Map<String, String> config = super.generateTaskConfigMap(params, previousTaskDefinition);
        config.put("apiKey", params.getString("apiKey"));
        config.put("appName", params.getString("appName"));
        config.put("artifactPath", params.getString("artifactPath"));
        return config;
    }

    @Override
    public void populateContextForCreate(@NotNull final Map<String, Object> context) {
        super.populateContextForCreate(context);

//        context.put("say", "Hello, World!");
    }

    @Override
    public void populateContextForEdit(@NotNull final Map<String, Object> context, @NotNull final TaskDefinition taskDefinition) {
        super.populateContextForEdit(context, taskDefinition);

        populateForViewAndEdit(context, taskDefinition);
    }

    @Override
    public void populateContextForView(@NotNull final Map<String, Object> context, @NotNull final TaskDefinition taskDefinition) {
        super.populateContextForView(context, taskDefinition);

        populateForViewAndEdit(context, taskDefinition);
    }

    private void populateForViewAndEdit(Map<String, Object> context, TaskDefinition taskDefinition) {
        context.put("apiKey", taskDefinition.getConfiguration().get("apiKey"));
        context.put("appName", taskDefinition.getConfiguration().get("appName"));
        context.put("artifactPath", taskDefinition.getConfiguration().get("artifactPath"));
    }

    @Override
    public void validate(@NotNull final ActionParametersMap params, @NotNull final ErrorCollection errorCollection) {
        super.validate(params, errorCollection);

        final String apiKey = params.getString("apiKey");
        if (StringUtils.isEmpty(apiKey)) {
            errorCollection.addError("apiKey", textProvider.getText("com.heroku.say.error"));
        }
        //TODO: more requiredess
    }

    public void setTextProvider(final TextProvider textProvider) {
        this.textProvider = textProvider;
    }
}

@@ -236,24 +236,72 @@
 Collection;%0A
+import com.google.common.collect.ImmutableList;%0A
 import com.o
@@ -328,24 +328,24 @@
 xtProvider;%0A
-
 import org.a
@@ -380,40 +380,8 @@
 ls;%0A
-import org.apache.log4j.Logger;%0A
 impo
@@ -462,16 +462,39 @@
 lable;%0A%0A
+import java.util.List;%0A
 import j
@@ -627,16 +627,127 @@
 vider;%0A%0A
+    private static final List%3CString%3E FIELDS_TO_COPY = ImmutableList.of(%22apiKey%22, %22appName%22, %22artifactPath%22);%0A%0A
     @Not
@@ -1034,185 +1034,103 @@
     
-config.put(%22apiKey%22, params.getString(%22apiKey%22));%0A        config.put(%22appName%22, params.getString(%22appName%22));%0A        config.put(%22artifactPath%22, params.getString(%22artifactPath%22)
+taskConfiguratorHelper.populateTaskConfigMapWithActionParameters(config, params, FIELDS_TO_COPY
 );%0A 
@@ -1567,33 +1567,32 @@
 efinition);%0A
-%0A
         
 populateForV
@@ -1579,38 +1579,71 @@
         
-populateForViewAndEdit
+taskConfiguratorHelper.populateContextWithConfiguration
 (context
@@ -1650,32 +1650,48 @@
 , taskDefinition
+, FIELDS_TO_COPY
 );%0A    %7D%0A%0A    @O
@@ -1892,25 +1892,24 @@
 ition);%0A
-%0A
         
 populate
@@ -1904,417 +1904,103 @@
     
-populateForViewAndEdit(context, taskDefinition);%0A    %7D%0A%0A    private void populateForViewAndEdit(Map%3CString, Object%3E context, TaskDefinition taskDefinition) %7B%0A        context.put(%22apiKey%22, taskDefinition.getConfiguration().get(%22apiKey%22));%0A        context.put(%22appName%22, taskDefinition.getConfiguration().get(%22appName%22));%0A        context.put(%22artifactPath%22, taskDefinition.getConfiguration().get(%22artifactPath%22)
+taskConfiguratorHelper.populateContextWithConfiguration(context, taskDefinition, FIELDS_TO_COPY
 );%0A 
@@ -2129,32 +2129,32 @@
 orCollection) %7B%0A
+
         super.va
@@ -2186,17 +2186,16 @@
 ction);%0A
-%0A
         

use task helper