
package org.kar.karideo;

import java.util.logging.LogManager;

import org.kar.archidata.tools.ConfigBaseVariable;
import org.kar.karideo.migration.Initialization;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;

public class WebLauncherLocal extends WebLauncher {
	private static final Logger LOGGER = LoggerFactory.getLogger(WebLauncherLocal.class);

	private WebLauncherLocal() {}

	public static void main(final String[] args) throws Exception {
		// Loop-back of logger JDK logging API to SLF4J
		LogManager.getLogManager().reset();
		SLF4JBridgeHandler.install();
		// Generate the APIs in type-script
		Initialization.generateObjects();
		final WebLauncherLocal launcher = new WebLauncherLocal();
		launcher.process();
		LOGGER.info("end-configure the server & wait finish process:");
		Thread.currentThread().join();
		LOGGER.info("STOP the REST server:");
	}

	@Override
	public void process() throws InterruptedException {
		if (true) {
			// for local test:
			ConfigBaseVariable.apiAdress = "http://0.0.0.0:18080/karideo/api/";
			ConfigBaseVariable.dbPort = "3906";
			ConfigBaseVariable.testMode = "true";
		}
		try {
			super.migrateDB();
		} catch (final Exception e) {
			e.printStackTrace();
			while (true) {
				LOGGER.error("============================================================================");
				LOGGER.error("== Migration fail ==> waiting intervention of administrator...");
				LOGGER.error("============================================================================");
				Thread.sleep(60 * 60 * 1000);
			}
		}
		super.process();
	}
}
