/*
 * Copyright © 2015 Cask Data, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package co.cask.cdap.dq;

import co.cask.cdap.api.data.stream.Stream;
import co.cask.cdap.api.dataset.Dataset;
import co.cask.cdap.api.dataset.DatasetProperties;
import co.cask.cdap.api.dataset.module.DatasetModule;
import co.cask.cdap.api.mapreduce.MapReduceConfigurer;
import co.cask.cdap.api.templates.plugins.PluginProperties;
import co.cask.cdap.api.templates.plugins.PluginSelector;
import co.cask.cdap.template.etl.api.PipelineConfigurer;

import javax.annotation.Nullable;

/**
 * Implementation of {@link PipelineConfigurer} that delegates to {@link MapReduceConfigurer}
 */
public class MapReducePipelineConfigurer implements PipelineConfigurer {
  private final MapReduceConfigurer mrConfigurer;
  private final String prefixId;

  public MapReducePipelineConfigurer(MapReduceConfigurer configurer, String prefixId) {
    this.mrConfigurer = configurer;
    this.prefixId = prefixId;
  }

  @Override
  public void addStream(Stream stream) {
    mrConfigurer.addStream(stream);
  }

  @Override
  public void addDatasetModule(String moduleName, Class<? extends DatasetModule> moduleClass) {
    mrConfigurer.addDatasetModule(moduleName, moduleClass);
  }

  @Override
  public void addDatasetType(Class<? extends Dataset> datasetClass) {
    mrConfigurer.addDatasetType(datasetClass);
  }

  @Override
  public void createDataset(String datasetName, String typeName, DatasetProperties properties) {
    mrConfigurer.createDataset(datasetName, typeName, properties);
  }

  @Override
  public void createDataset(String datasetName, Class<? extends Dataset> datasetClass, DatasetProperties props) {
    mrConfigurer.createDataset(datasetName, datasetClass, props);
  }

  @Nullable
  @Override
  public <T> T usePlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties) {
    return mrConfigurer.usePlugin(pluginType, pluginName, prefixId + pluginId, properties);
  }

  @Nullable
  @Override
  public <T> T usePlugin(String pluginType, String pluginName, String pluginId, PluginProperties properties,
                         PluginSelector selector) {
    return mrConfigurer.usePlugin(pluginType, pluginName, prefixId + pluginId, properties);
  }

  @Nullable
  @Override
  public <T> Class<T> usePluginClass(String pluginType, String pluginName, String pluginId,
                                     PluginProperties properties) {
    return mrConfigurer.usePluginClass(pluginType, pluginName, prefixId + pluginId, properties);
  }

  @Nullable
  @Override
  public <T> Class<T> usePluginClass(String pluginType, String pluginName, String pluginId, PluginProperties properties,
                                     PluginSelector selector) {
    return mrConfigurer.usePluginClass(pluginType, pluginName, prefixId + pluginId, properties);
  }
}

@@ -617,16 +617,65 @@
 ap.dq;%0A%0A
+import co.cask.cdap.api.artifact.PluginSelector;%0A
 import c
@@ -710,16 +710,16 @@
 Stream;%0A
-
 import c
@@ -975,66 +975,8 @@
 es;%0A
-import co.cask.cdap.api.templates.plugins.PluginSelector;%0A
 impo
@@ -1568,32 +1568,134 @@
 m(stream);%0A  %7D%0A%0A
+  @Override%0A  public void addStream(String streamName) %7B%0A    mrConfigurer.addStream(streamName);%0A  %7D%0A%0A
   @Override%0A  pu
@@ -2158,32 +2158,171 @@
 operties);%0A  %7D%0A%0A
+  @Override%0A  public void createDataset(String datasetName, String typeName) %7B%0A    mrConfigurer.createDataset(datasetName, typeName);%0A  %7D%0A%0A
   @Override%0A  pu
@@ -2494,32 +2494,197 @@
 s, props);%0A  %7D%0A%0A
+  @Override%0A  public void createDataset(String datasetName, Class%3C? extends Dataset%3E datasetClass) %7B%0A    mrConfigurer.createDataset(datasetName, datasetClass);%0A  %7D%0A%0A
   @Nullable%0A  @O
@@ -3165,32 +3165,42 @@
 inId, properties
+, selector
 );%0A  %7D%0A%0A  @Nulla
@@ -3678,32 +3678,32 @@
 tor selector) %7B%0A
-
     return mrCon
@@ -3776,21 +3776,31 @@
 , properties
+, selector
 );%0A  %7D%0A%7D%0A

Address a PR comment by using the pluginSelector