package gw2trades.importer;

import com.fasterxml.jackson.databind.ObjectMapper;
import gw2trades.importer.dao.TradingPost;
import gw2trades.importer.http.ApiClient;
import org.yaml.snakeyaml.Yaml;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

/**
 * TODO
 * @author Stefan Lotties (slotties@gmail.com)
 */
public class Main {
    public static void main(String[] args) throws Exception {
        ApiClient apiClient = new ApiClient();
        ObjectMapper objectMapper = new ObjectMapper();

        TradingPost tradingPost = new TradingPost();
        tradingPost.setApiClient(apiClient);
        tradingPost.setObjectMapper(objectMapper);

        Config config = readConfig("/import.yaml");

        Importer importer = new Importer(config, tradingPost);
        // TODO: handle errors
        importer.execute();
    }

    private static Config readConfig(String fileName) throws IOException {
        Yaml yamlConfig = new Yaml();
        try (InputStream in = Main.class.getResourceAsStream(fileName)) {
            Map configData = (Map) yamlConfig.load(in);
            return new Config(configData);
        }
    }
}

@@ -159,16 +159,100 @@
 Client;%0A
+import org.apache.logging.log4j.LogManager;%0Aimport org.apache.logging.log4j.Logger;%0A
 import o
@@ -367,82 +367,264 @@
  * T
-ODO%0A * @author Stefan Lotties (slotties@gmail.com)%0A */%0Apublic class Main %7B
+he importer pulls data from the Guild Wars 2 API and writes it into the repository used by the server module.%0A * @author Stefan Lotties (slotties@gmail.com)%0A */%0Apublic class Main %7B%0A    private static final Logger LOGGER = LogManager.getLogger(Main.class);%0A
 %0A   
@@ -1064,31 +1064,18 @@
     
-// TODO: handle errors%0A
+try %7B%0A    
     
@@ -1094,24 +1094,165 @@
 .execute();%0A
+        %7D catch (IOException e) %7B%0A            LOGGER.error(%22Could not import: %7B%7D%22, e.getMessage(), e);%0A            System.exit(1);%0A        %7D%0A
     %7D%0A%0A    p

exit with a specific status code when the import fails