/*
 * Copyright 2015 Data Artisans GmbH
 *
 * 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 com.dataartisans.flink.dataflow.examples;

import com.dataartisans.flink.dataflow.FlinkPipelineOptions;
import com.dataartisans.flink.dataflow.FlinkPipelineRunner;
import com.google.cloud.dataflow.examples.WordCount.CountWords;
import com.google.cloud.dataflow.sdk.Pipeline;
import com.google.cloud.dataflow.sdk.io.TextIO;
import com.google.cloud.dataflow.sdk.options.Default;
import com.google.cloud.dataflow.sdk.options.Description;
import com.google.cloud.dataflow.sdk.options.PipelineOptions;
import com.google.cloud.dataflow.sdk.options.PipelineOptionsFactory;

public class WordCount {

	/**
	 * Options supported by {@link WordCount}.
	 * <p>
	 * Inherits standard configuration options.
	 */
	public static interface Options extends PipelineOptions, FlinkPipelineOptions {
		@Description("Path of the file to read from")
		@Default.String("gs://dataflow-samples/shakespeare/kinglear.txt")
		String getInput();
		void setInput(String value);

		@Description("Path of the file to write to")
		String getOutput();
		void setOutput(String value);

		/**
		 * By default (numShards == 0), the system will choose the shard count.
		 * Most programs will not need this option.
		 */
		@Description("Number of output shards (0 if the system should choose automatically)")
		int getNumShards();
		void setNumShards(int value);
	}
	
	public static void main(String[] args) {

		Options options = PipelineOptionsFactory.fromArgs(args).as(Options.class);
		options.setRunner(FlinkPipelineRunner.class);

		Pipeline p = Pipeline.create(options);

		p.apply(TextIO.Read.named("ReadLines").from(options.getInput()))
				.apply(new CountWords())
				.apply(TextIO.Write.named("WriteCounts")
						.to(options.getOutput())
						.withNumShards(options.getNumShards()));

		p.run();
	}

}

@@ -1168,16 +1168,71 @@
 Factory;
+%0Aimport com.google.cloud.dataflow.sdk.transforms.ParDo;
 %0A%0Apublic
@@ -1712,283 +1712,8 @@
 ue);
-%0A%0A%09%09/**%0A%09%09 * By default (numShards == 0), the system will choose the shard count.%0A%09%09 * Most programs will not need this option.%0A%09%09 */%0A%09%09@Description(%22Number of output shards (0 if the system should choose automatically)%22)%0A%09%09int getNumShards();%0A%09%09void setNumShards(int value);
 %0A%09%7D%0A
@@ -1814,16 +1814,38 @@
 gs(args)
+.withValidation()%0A%09%09%09%09
 .as(Opti
@@ -1943,24 +1943,174 @@
 (options);%0A%0A
+%09%09// Concepts #2 and #3: Our pipeline applies the composite CountWords transform, and passes the%0A%09%09// static FormatAsTextFn() to the ParDo transform.%0A
 %09%09p.apply(Te
@@ -2189,24 +2189,112 @@
 untWords())%0A
+%09%09%09%09.apply(ParDo.of(new com.google.cloud.dataflow.examples.WordCount.FormatAsTextFn()))%0A
 %09%09%09%09.apply(T
@@ -2325,23 +2325,16 @@
 Counts%22)
-%0A%09%09%09%09%09%09
 .to(opti
@@ -2353,53 +2353,8 @@
 t())
-%0A%09%09%09%09%09%09.withNumShards(options.getNumShards())
 );%0A%0A

fix WordCount example program