/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package main.java.eu.dnetlib.oa.graph.operausagestats.export;

import org.apache.commons.io.IOUtils;
import org.apache.log4j.BasicConfigurator;

import eu.dnetlib.dhp.application.ArgumentApplicationParser;

/**
 * @author D. Pierrakos, S. Zoupanos
 */
public class ExecuteWorkflow {

	static String operaBaseURL;
	static String operaMeasureURI;
	static String operaReportPath;
	static String startPeriod;
	static String endPeriod;
	static String dbImpalaUrl;
	static String dbHiveUrl;
	static String operaUsageStatsDBSchema;
	static String operaUsageStatsPermanentDBSchema;
	static String statsDBSchema;
	static boolean recreateDbAndTables;
	static boolean datasetsEmptyDirs;
	static boolean finalTablesVisibleToImpala;

	public static void main(String args[]) throws Exception {

		// Sending the logs to the console
		BasicConfigurator.configure();

		final ArgumentApplicationParser parser = new ArgumentApplicationParser(
			IOUtils
				.toString(
					UsageStatsExporter.class
						.getResourceAsStream(
							"/eu/dnetlib/dhp/oa/graph/operausagestats/export/opera_usagestats_parameters.json")));
		parser.parseArgument(args);

		// Setting up the initial parameters
		operaBaseURL = parser.get("operaBaseURL");
		operaMeasureURI = parser.get("operaMeasureURI");
		operaReportPath = parser.get("operaReportPath");
		startPeriod = parser.get("startPeriod");
		endPeriod = parser.get("endPeriod");
		dbHiveUrl = parser.get("dbHiveUrl");
		dbImpalaUrl = parser.get("dbImpalaUrl");
		operaUsageStatsDBSchema = parser.get("operaUsageStatsDBSchema");
		operaUsageStatsPermanentDBSchema = parser.get("operaUsageStatsPermanentDBSchema");
		statsDBSchema = parser.get("statsDBSchema");

		if (parser.get("recreateDbAndTables").toLowerCase().equals("true"))
			recreateDbAndTables = true;
		else
			recreateDbAndTables = false;

		if (parser.get("operaEmptyDirs").toLowerCase().equals("true"))
			datasetsEmptyDirs = true;
		else
			datasetsEmptyDirs = false;

		if (parser.get("finalTablesVisibleToImpala").toLowerCase().equals("true"))
			finalTablesVisibleToImpala = true;
		else
			finalTablesVisibleToImpala = false;

		UsageStatsExporter usagestatsExport = new UsageStatsExporter();
		usagestatsExport.export();
	}

}
