// Path: src/main/java/certh/iti/mklab/easie/configuration/Configuration.java
// public final class Configuration {
// 
//     public URL url;
// 
//     public HashSet<String> group_of_urls;
// 
//     public String source_name;
// 
//     public String entity_name;
// 
//     public String table_selector;
// 
//     public ArrayList<ScrapableField> metrics;
// 
//     public ArrayList<ScrapableField> entity_info;
// 
//     public String next_page_selector;
// 
//     public boolean dynamic_page;
// 
//     public Object events;
// 
//     public Store store;
// 
//     public Configuration crawl;
// 
//     public void setEvents(ArrayList<Event> events) {
//         this.events = events;
//     }
// 
//     public void setEvents(Event events) {
//         this.events = events;
//     }
// 
//     public static class ScrapableField {
// 
//         public Object label;
// 
//         public Object value;
// 
//         public Object citeyear;
// 
//         public void setLabel(ExtractionProperties ep) {
//             label = ep;
//         }
// 
//         public void setValue(ExtractionProperties ep) {
//             value = ep;
//         }
// 
//         public void setCiteyear(ExtractionProperties ep) {
//             citeyear = ep;
//         }
//     }
// 
//     public static class ExtractionProperties {
// 
//         public String selector;
// 
//         public String type;
// 
//         public Object citeyear;
// 
//         public ReplaceField replace;
// 
//     }
// 
//     public static class ReplaceField {
// 
//         public List<String> regex;
// 
//         public List<String> with;
//     }
// 
//     public static class Event {
// 
//         public String type;
// 
//         public String selector;
// 
//         public Integer times_to_repeat;
// 
//         public String extraction_type;
//     }
// 
//     public static class URL {
// 
//         public String base_url;
// 
//         public String relative_url;
//     }
// 
//     public class Store {
// 
//         public String format;
// 
//         public String database;
// 
//         public String hd_path;
// 
//         public String companies_collection;
// 
//         public String metrics_collection;
// 
//         public DBCreadentials db_credentials;
// 
//         public String wikirate_metric_designer;
//     }
// 
//     public class DBCreadentials {
// 
//         public String username;
// 
//         public String password;
// 
//         public String server_address;
// 
//         public String db;
//     }
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/configuration/Configuration.java
// public static class Event {
// 
//     public String type;
// 
//     public String selector;
// 
//     public Integer times_to_repeat;
// 
//     public String extraction_type;
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/configuration/Configuration.java
// public static class ExtractionProperties {
// 
//     public String selector;
// 
//     public String type;
// 
//     public Object citeyear;
// 
//     public ReplaceField replace;
// 
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/configuration/Configuration.java
// public static class ScrapableField {
// 
//     public Object label;
// 
//     public Object value;
// 
//     public Object citeyear;
// 
//     public void setLabel(ExtractionProperties ep) {
//         label = ep;
//     }
// 
//     public void setValue(ExtractionProperties ep) {
//         value = ep;
//     }
// 
//     public void setCiteyear(ExtractionProperties ep) {
//         citeyear = ep;
//     }
// }


import certh.iti.mklab.easie.configuration.Configuration;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.internal.LinkedTreeMap;
import certh.iti.mklab.easie.configuration.Configuration.Event;
import certh.iti.mklab.easie.configuration.Configuration.ExtractionProperties;
import certh.iti.mklab.easie.configuration.Configuration.ScrapableField;
import java.lang.reflect.Type;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONObject;

package certh.iti.mklab.easie.configuration;


/**
 * JSONConfigurationDeserializer extends JsonDeserializer and is responsible of
 * the deserialization of a JSON formated file into Configuration Object.
 * Required fields can be set through registerRequiredField method.
 *
 * @author vasgat
 */
public class JSONConfigurationDeserializer implements JsonDeserializer<Configuration> {

    @Override
    public Configuration deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
        Configuration configuration = new Gson().fromJson(json, Configuration.class);

        configuration.metrics = transform_metrics(configuration.metrics);

        configuration.entity_info = transform_CompanyInfo(configuration.entity_info);

        Configuration crawl = configuration.crawl;
        while (crawl != null) {
            crawl.metrics = transform_metrics(crawl.metrics);
            crawl.entity_info = transform_CompanyInfo(crawl.entity_info);
            crawl = crawl.crawl;
        }

        if (configuration.dynamic_page) {
            Object events = configuration.events;
            if (configuration.events != null) {
                if (events instanceof ArrayList) {

// Path: src/main/java/certh/iti/mklab/easie/configuration/Configuration.java
// public final class Configuration {
// 
//     public URL url;
// 
//     public HashSet<String> group_of_urls;
// 
//     public String source_name;
// 
//     public String entity_name;
// 
//     public String table_selector;
// 
//     public ArrayList<ScrapableField> metrics;
// 
//     public ArrayList<ScrapableField> entity_info;
// 
//     public String next_page_selector;
// 
//     public boolean dynamic_page;
// 
//     public Object events;
// 
//     public Store store;
// 
//     public Configuration crawl;
// 
//     public void setEvents(ArrayList<Event> events) {
//         this.events = events;
//     }
// 
//     public void setEvents(Event events) {
//         this.events = events;
//     }
// 
//     public static class ScrapableField {
// 
//         public Object label;
// 
//         public Object value;
// 
//         public Object citeyear;
// 
//         public void setLabel(ExtractionProperties ep) {
//             label = ep;
//         }
// 
//         public void setValue(ExtractionProperties ep) {
//             value = ep;
//         }
// 
//         public void setCiteyear(ExtractionProperties ep) {
//             citeyear = ep;
//         }
//     }
// 
//     public static class ExtractionProperties {
// 
//         public String selector;
// 
//         public String type;
// 
//         public Object citeyear;
// 
//         public ReplaceField replace;
// 
//     }
// 
//     public static class ReplaceField {
// 
//         public List<String> regex;
// 
//         public List<String> with;
//     }
// 
//     public static class Event {
// 
//         public String type;
// 
//         public String selector;
// 
//         public Integer times_to_repeat;
// 
//         public String extraction_type;
//     }
// 
//     public static class URL {
// 
//         public String base_url;
// 
//         public String relative_url;
//     }
// 
//     public class Store {
// 
//         public String format;
// 
//         public String database;
// 
//         public String hd_path;
// 
//         public String companies_collection;
// 
//         public String metrics_collection;
// 
//         public DBCreadentials db_credentials;
// 
//         public String wikirate_metric_designer;
//     }
// 
//     public class DBCreadentials {
// 
//         public String username;
// 
//         public String password;
// 
//         public String server_address;
// 
//         public String db;
//     }
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/configuration/Configuration.java
// public static class Event {
// 
//     public String type;
// 
//     public String selector;
// 
//     public Integer times_to_repeat;
// 
//     public String extraction_type;
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/configuration/Configuration.java
// public static class ExtractionProperties {
// 
//     public String selector;
// 
//     public String type;
// 
//     public Object citeyear;
// 
//     public ReplaceField replace;
// 
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/configuration/Configuration.java
// public static class ScrapableField {
// 
//     public Object label;
// 
//     public Object value;
// 
//     public Object citeyear;
// 
//     public void setLabel(ExtractionProperties ep) {
//         label = ep;
//     }
// 
//     public void setValue(ExtractionProperties ep) {
//         value = ep;
//     }
// 
//     public void setCiteyear(ExtractionProperties ep) {
//         citeyear = ep;
//     }
// }


// Path: src/main/java/certh/iti/mklab/easie/configuration/JSONConfigurationDeserializer.java
import certh.iti.mklab.easie.configuration.Configuration;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.internal.LinkedTreeMap;
import certh.iti.mklab.easie.configuration.Configuration.Event;
import certh.iti.mklab.easie.configuration.Configuration.ExtractionProperties;
import certh.iti.mklab.easie.configuration.Configuration.ScrapableField;
import java.lang.reflect.Type;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONObject;

package certh.iti.mklab.easie.configuration;


/**
 * JSONConfigurationDeserializer extends JsonDeserializer and is responsible of
 * the deserialization of a JSON formated file into Configuration Object.
 * Required fields can be set through registerRequiredField method.
 *
 * @author vasgat
 */
public class JSONConfigurationDeserializer implements JsonDeserializer<Configuration> {

    @Override
    public Configuration deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
        Configuration configuration = new Gson().fromJson(json, Configuration.class);

        configuration.metrics = transform_metrics(configuration.metrics);

        configuration.entity_info = transform_CompanyInfo(configuration.entity_info);

        Configuration crawl = configuration.crawl;
        while (crawl != null) {
            crawl.metrics = transform_metrics(crawl.metrics);
            crawl.entity_info = transform_CompanyInfo(crawl.entity_info);
            crawl = crawl.crawl;
        }

        if (configuration.dynamic_page) {
            Object events = configuration.events;
            if (configuration.events != null) {
                if (events instanceof ArrayList) {

                    ArrayList<Event> evnts = new Gson().fromJson(
