// Path: src/main/java/com/l2bq/datastore/analysis/builtin/BuiltinDatastoreExportConfiguration.java
// public interface BuiltinDatastoreExportConfiguration {
// 	/**
// 	 * specifies which entity kinds should be exported to bigquery
// 	 * @return a list of strings, each representing the name of the entity kind
// 	 */
// 	public List<String> getEntityKindsToExport();
// 	
// 	/**
// 	 * 
// 	 * @return the bucket name you'd like the datastore backup stored to
// 	 */
// 	public String getBucketName();
// 	
// 	/**
// 	 * 
// 	 * @return the dataset in bigquery that you'd like tables created in for this datastore export
// 	 */
// 	public String getBigqueryDatasetId();
// 	
// 	/**
// 	 * 
// 	 * @return your project id available in the api console
// 	 */
// 	public String getBigqueryProjectId();
// 	
// 	/**
// 	 * 
// 	 * @return in bigquery whether or not to append the timestamp of the export to the 
// 	 * names of the tables created in bigquery. If you wawant your export to overwrite 
// 	 * previous exports in bigquery you should set this to false that way it overrides the last export.
// 	 */
// 	public boolean appendTimestampToDatatables();
// 	
// 	/**
// 	 * 
// 	 * @return the task queue to use for this job. Return null if you want to use default queue
// 	 */
// 	public String getQueueName();
// 	
// 	/**
// 	 * Return true if you want to just use mache for automatic backup creation to cloud storage and not exporting to bigquery. Normally this should be set to false. 
// 	 * @return whether or not to export to bigquery
// 	 */
// 	public boolean shouldSkipExportToBigquery();
// 	
// 	/**
// 	 * This allows you to name the backups created in cloudstrage and the datastore admin console for future reference 
// 	 * @return the name of the backup to be used in Google Cloud Storage, or null to use the default
// 	 */
// 	public String getBackupNamePrefix();
// }


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.nio.channels.Channels;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpResponse;
import com.google.appengine.api.datastore.Text;
import com.google.appengine.api.files.AppEngineFile;
import com.google.appengine.api.files.FileReadChannel;
import com.google.appengine.api.files.FileService;
import com.google.appengine.api.files.FileServiceFactory;
import com.google.appengine.api.files.FileWriteChannel;
import com.google.appengine.api.files.FinalizationException;
import com.google.appengine.api.files.GSFileOptions.GSFileOptionsBuilder;
import com.google.appengine.api.files.LockException;
import com.l2bq.datastore.analysis.builtin.BuiltinDatastoreExportConfiguration;
		FileService fileService = FileServiceFactory.getFileService();
		AppEngineFile schemaFile = new AppEngineFile(schemaFileName);
		FileReadChannel readChannel = fileService.openReadChannel(schemaFile, false);
		BufferedReader reader = new BufferedReader(Channels.newReader(readChannel, "UTF8"));
		String schemaLine;
		try {
			schemaLine = reader.readLine().trim();
		} catch (NullPointerException npe) {
			throw new IOException("Encountered NPE reading " + schemaFileName);
		}
		reader.close();
		readChannel.close();
		return schemaLine;
	}

	public static String failureJson(String message) {
		return "{\"success\":false, \"message\":\"" + message + "\"}";
	}
	
	public static String successJson(String message) {
		return "{\"success\":true, \"message\":\"" + message + "\"}";
	}
	
	public static BuiltinDatastoreExportConfiguration instantiateExportConfig(String builtinDatastoreExportConfig) {
		Class exportConfigClass;
		try {
			exportConfigClass = Class.forName(builtinDatastoreExportConfig);
		} catch (ClassNotFoundException e) {
			throw new InvalidTaskParameterException("Got invalid BuiltinDatastoreExportConfig class name: " + builtinDatastoreExportConfig);
		}
// Path: src/main/java/com/l2bq/datastore/analysis/builtin/BuiltinDatastoreExportConfiguration.java
// public interface BuiltinDatastoreExportConfiguration {
// 	/**
// 	 * specifies which entity kinds should be exported to bigquery
// 	 * @return a list of strings, each representing the name of the entity kind
// 	 */
// 	public List<String> getEntityKindsToExport();
// 	
// 	/**
// 	 * 
// 	 * @return the bucket name you'd like the datastore backup stored to
// 	 */
// 	public String getBucketName();
// 	
// 	/**
// 	 * 
// 	 * @return the dataset in bigquery that you'd like tables created in for this datastore export
// 	 */
// 	public String getBigqueryDatasetId();
// 	
// 	/**
// 	 * 
// 	 * @return your project id available in the api console
// 	 */
// 	public String getBigqueryProjectId();
// 	
// 	/**
// 	 * 
// 	 * @return in bigquery whether or not to append the timestamp of the export to the 
// 	 * names of the tables created in bigquery. If you wawant your export to overwrite 
// 	 * previous exports in bigquery you should set this to false that way it overrides the last export.
// 	 */
// 	public boolean appendTimestampToDatatables();
// 	
// 	/**
// 	 * 
// 	 * @return the task queue to use for this job. Return null if you want to use default queue
// 	 */
// 	public String getQueueName();
// 	
// 	/**
// 	 * Return true if you want to just use mache for automatic backup creation to cloud storage and not exporting to bigquery. Normally this should be set to false. 
// 	 * @return whether or not to export to bigquery
// 	 */
// 	public boolean shouldSkipExportToBigquery();
// 	
// 	/**
// 	 * This allows you to name the backups created in cloudstrage and the datastore admin console for future reference 
// 	 * @return the name of the backup to be used in Google Cloud Storage, or null to use the default
// 	 */
// 	public String getBackupNamePrefix();
// }


// Path: src/main/java/com/l2bq/logging/analysis/AnalysisUtility.java
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.nio.channels.Channels;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpResponse;
import com.google.appengine.api.datastore.Text;
import com.google.appengine.api.files.AppEngineFile;
import com.google.appengine.api.files.FileReadChannel;
import com.google.appengine.api.files.FileService;
import com.google.appengine.api.files.FileServiceFactory;
import com.google.appengine.api.files.FileWriteChannel;
import com.google.appengine.api.files.FinalizationException;
import com.google.appengine.api.files.GSFileOptions.GSFileOptionsBuilder;
import com.google.appengine.api.files.LockException;
import com.l2bq.datastore.analysis.builtin.BuiltinDatastoreExportConfiguration;

		FileService fileService = FileServiceFactory.getFileService();
		AppEngineFile schemaFile = new AppEngineFile(schemaFileName);
		FileReadChannel readChannel = fileService.openReadChannel(schemaFile, false);
		BufferedReader reader = new BufferedReader(Channels.newReader(readChannel, "UTF8"));
		String schemaLine;
		try {
			schemaLine = reader.readLine().trim();
		} catch (NullPointerException npe) {
			throw new IOException("Encountered NPE reading " + schemaFileName);
		}
		reader.close();
		readChannel.close();
		return schemaLine;
	}

	public static String failureJson(String message) {
		return "{\"success\":false, \"message\":\"" + message + "\"}";
	}
	
	public static String successJson(String message) {
		return "{\"success\":true, \"message\":\"" + message + "\"}";
	}
	
	public static BuiltinDatastoreExportConfiguration instantiateExportConfig(String builtinDatastoreExportConfig) {
		Class exportConfigClass;
		try {
			exportConfigClass = Class.forName(builtinDatastoreExportConfig);
		} catch (ClassNotFoundException e) {
			throw new InvalidTaskParameterException("Got invalid BuiltinDatastoreExportConfig class name: " + builtinDatastoreExportConfig);
		}
		if (!BuiltinDatastoreExportConfiguration.class.isAssignableFrom(exportConfigClass)) {