// Path: src/main/java/edu/sjsu/mithai/config/Configuration.java
// public class Configuration {
// 
//     protected String propertyFile;
//     protected Properties properties;
// 
//     public Configuration(String propertyFile) throws IOException {
//         this.propertyFile = propertyFile;
//         this.properties = new Properties();
//         properties.load(new FileReader(propertyFile));
//     }
// 
//     public String getProperty(String key) {
//         return properties.getProperty(key);
//     }
// 
//     public void setProperty(String key, String value) {
//         properties.setProperty(key, value);
//     }
// 
//     public Properties getProperties() {
//         return properties;
//     }
// 
//     public void setProperties(Properties properties) {
//         this.properties = properties;
//     }
// 
//     public void setPropertyFile(String propertyFile) {
//         this.propertyFile = propertyFile;
//     }
// 
//     public String getPropertyFile() {
//         return propertyFile;
//     }
// 
//     public void reload() throws IOException {
//         properties.clear();
//         properties.load(new FileReader(propertyFile));
//         System.out.println("=>" + properties);
//     }
// }
// 
// Path: src/main/java/edu/sjsu/mithai/config/MithaiProperties.java
// public interface MithaiProperties {
// 
//     // Self node properties
//     String IP = "IP";
//     String ID = "ID";
//     String CONNECTED_DEVICE_IDS = "CONNECTED_DEVICE_IDS";
//     String LOCAL_GRAPH = "LOCAL_GRAPH";
// 
//     // Sensor & Data generation related properties
//     String NUMBER_OF_SENSORS = "NUMBER_OF_SENSORS";
//     String DATA_GENERATION_INTERVAL = "DATA_GENERATION_INTERVAL";
//     String META_DATA_GENERATION_INTERVAL = "META_DATA_GENERATION_INTERVAL";
//     String QUIESCE_TIMEOUT = "QUIESCE_TIMEOUT";
//     String RESEND_COUNT = "RESEND_COUNT";
//     String STARTUP_THRESHOLD = "STARTUP_THRESHOLD";
// 
//     // INJECTOR PROPERTIES
//     String MQTT_BROKER = "MQTT_BROKER";
//     String MQTT_TOPIC = "MQTT_TOPIC";
// 
//     // Visualization System Properties
//     String VISUALIZATION_SYSTEM_EXPORTER_URL = "VISUALIZATION_SYSTEM_EXPORTER_URL";
// 
//     // EXPORTER PROPERTIES
//     String EXPORTER_TYPE = "EXPORTER_TYPE";
//     String EXPORTER_REMOTE_URI = "EXPORTER_REMOTE_IP";
//     String EXPORTER_KAFKA_TOPIC = "EXPORTER_KAFKA_TOPIC";
//     String EXPORTER_TIME_INTERVAL = "EXPORTER_TIME_INTERVAL";
// 
//     // Graphite exporter properties
//     String GRAPHITE_HOSTNAME = "GRAPHITE_HOSTNAME";
//     String GRAPHITE_PORT = "GRAPHITE_PORT";
// 
//     //Graph Processor Tasks
//     String ENTRY = "ENTRY";
//     String TASK_LIST = "TASK_LIST";
//     String FUNCTION_LIST = "FUNCTION_LIST";
// 
//     //Store Properties
//     String MESSAGE_STORE_QUEUE_SIZE = "MESSAGE_STORE_QUEUE_SIZE";
//     String MQTT_MESSAGE_STORE_QUEUE_SIZE = "MQTT_MESSAGE_STORE_QUEUE_SIZE";
//     String SPARKCONTEXT_INTERVAL = "SPARKCONTEXT_INTERVAL";
// 
// }
// 
// Path: src/main/scala/edu/sjsu/mithai/mqtt/MqttService.java
// public class MqttService {
//     private static MQTTPublisher publisher;
// 
//     private MqttService() {
//     }
// 
//     public static MQTTPublisher getPublisher(Configuration configuration) {
// 
//         if (publisher == null) {
//             publisher = new MQTTPublisher(configuration.getProperty(MithaiProperties.MQTT_BROKER));
//         }
// 
//         return publisher;
//     }
// }
// 
// Path: src/main/java/edu/sjsu/mithai/util/StoppableExecutableTask.java
// public abstract class StoppableExecutableTask implements Runnable, Executable, Stoppable {
// 
//     protected boolean stop;
// 
//     public StoppableExecutableTask() {
//         this.stop = false;
//     }
// 
//     @Override
//     public void run() {
//         do {
//             execute();
//         } while (!stop);
//     }
// 
//     @Override
//     public void stop() {
//         stop = true;
//     }
// 
// }


import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import edu.sjsu.mithai.config.Configuration;
import edu.sjsu.mithai.config.MithaiProperties;
import edu.sjsu.mithai.mqtt.MQTTPublisher;
import edu.sjsu.mithai.mqtt.MqttService;
import edu.sjsu.mithai.util.StoppableExecutableTask;
import java.util.ArrayList;
import java.util.List;

        String localGraph = configuration.getProperty(MithaiProperties.LOCAL_GRAPH);

        JsonParser parser = new JsonParser();
        JsonElement graph = parser.parse(localGraph);

        List<AvroGraphMetadata> localGraphList = new ArrayList<>();
        if (graph.isJsonArray()) {

            List<GraphMetadata> metadataList = new ArrayList<>();
            graph.getAsJsonArray().forEach(t -> {
                t.getAsJsonObject();
                //System.out.println(t.getAsJsonObject());
                localGraphList.add(gson.fromJson(t, AvroGraphMetadata.class));
            });
        }

        List<String> connectedDevices = new ArrayList<>();

        if (connectedDeviceIds != null && !connectedDeviceIds.trim().isEmpty()) {
            String[] ids = connectedDeviceIds.split(",");

            if (ids != null && ids.length > 0) {
                for (String id: ids) {
                    connectedDevices.add(id.trim());
                }
            }
        }

        metadata.setConnectedDevices(connectedDevices);
// Path: src/main/java/edu/sjsu/mithai/config/Configuration.java
// public class Configuration {
// 
//     protected String propertyFile;
//     protected Properties properties;
// 
//     public Configuration(String propertyFile) throws IOException {
//         this.propertyFile = propertyFile;
//         this.properties = new Properties();
//         properties.load(new FileReader(propertyFile));
//     }
// 
//     public String getProperty(String key) {
//         return properties.getProperty(key);
//     }
// 
//     public void setProperty(String key, String value) {
//         properties.setProperty(key, value);
//     }
// 
//     public Properties getProperties() {
//         return properties;
//     }
// 
//     public void setProperties(Properties properties) {
//         this.properties = properties;
//     }
// 
//     public void setPropertyFile(String propertyFile) {
//         this.propertyFile = propertyFile;
//     }
// 
//     public String getPropertyFile() {
//         return propertyFile;
//     }
// 
//     public void reload() throws IOException {
//         properties.clear();
//         properties.load(new FileReader(propertyFile));
//         System.out.println("=>" + properties);
//     }
// }
// 
// Path: src/main/java/edu/sjsu/mithai/config/MithaiProperties.java
// public interface MithaiProperties {
// 
//     // Self node properties
//     String IP = "IP";
//     String ID = "ID";
//     String CONNECTED_DEVICE_IDS = "CONNECTED_DEVICE_IDS";
//     String LOCAL_GRAPH = "LOCAL_GRAPH";
// 
//     // Sensor & Data generation related properties
//     String NUMBER_OF_SENSORS = "NUMBER_OF_SENSORS";
//     String DATA_GENERATION_INTERVAL = "DATA_GENERATION_INTERVAL";
//     String META_DATA_GENERATION_INTERVAL = "META_DATA_GENERATION_INTERVAL";
//     String QUIESCE_TIMEOUT = "QUIESCE_TIMEOUT";
//     String RESEND_COUNT = "RESEND_COUNT";
//     String STARTUP_THRESHOLD = "STARTUP_THRESHOLD";
// 
//     // INJECTOR PROPERTIES
//     String MQTT_BROKER = "MQTT_BROKER";
//     String MQTT_TOPIC = "MQTT_TOPIC";
// 
//     // Visualization System Properties
//     String VISUALIZATION_SYSTEM_EXPORTER_URL = "VISUALIZATION_SYSTEM_EXPORTER_URL";
// 
//     // EXPORTER PROPERTIES
//     String EXPORTER_TYPE = "EXPORTER_TYPE";
//     String EXPORTER_REMOTE_URI = "EXPORTER_REMOTE_IP";
//     String EXPORTER_KAFKA_TOPIC = "EXPORTER_KAFKA_TOPIC";
//     String EXPORTER_TIME_INTERVAL = "EXPORTER_TIME_INTERVAL";
// 
//     // Graphite exporter properties
//     String GRAPHITE_HOSTNAME = "GRAPHITE_HOSTNAME";
//     String GRAPHITE_PORT = "GRAPHITE_PORT";
// 
//     //Graph Processor Tasks
//     String ENTRY = "ENTRY";
//     String TASK_LIST = "TASK_LIST";
//     String FUNCTION_LIST = "FUNCTION_LIST";
// 
//     //Store Properties
//     String MESSAGE_STORE_QUEUE_SIZE = "MESSAGE_STORE_QUEUE_SIZE";
//     String MQTT_MESSAGE_STORE_QUEUE_SIZE = "MQTT_MESSAGE_STORE_QUEUE_SIZE";
//     String SPARKCONTEXT_INTERVAL = "SPARKCONTEXT_INTERVAL";
// 
// }
// 
// Path: src/main/scala/edu/sjsu/mithai/mqtt/MqttService.java
// public class MqttService {
//     private static MQTTPublisher publisher;
// 
//     private MqttService() {
//     }
// 
//     public static MQTTPublisher getPublisher(Configuration configuration) {
// 
//         if (publisher == null) {
//             publisher = new MQTTPublisher(configuration.getProperty(MithaiProperties.MQTT_BROKER));
//         }
// 
//         return publisher;
//     }
// }
// 
// Path: src/main/java/edu/sjsu/mithai/util/StoppableExecutableTask.java
// public abstract class StoppableExecutableTask implements Runnable, Executable, Stoppable {
// 
//     protected boolean stop;
// 
//     public StoppableExecutableTask() {
//         this.stop = false;
//     }
// 
//     @Override
//     public void run() {
//         do {
//             execute();
//         } while (!stop);
//     }
// 
//     @Override
//     public void stop() {
//         stop = true;
//     }
// 
// }


// Path: src/main/scala/edu/sjsu/mithai/data/MetadataGenerationTask.java
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import edu.sjsu.mithai.config.Configuration;
import edu.sjsu.mithai.config.MithaiProperties;
import edu.sjsu.mithai.mqtt.MQTTPublisher;
import edu.sjsu.mithai.mqtt.MqttService;
import edu.sjsu.mithai.util.StoppableExecutableTask;
import java.util.ArrayList;
import java.util.List;


        String localGraph = configuration.getProperty(MithaiProperties.LOCAL_GRAPH);

        JsonParser parser = new JsonParser();
        JsonElement graph = parser.parse(localGraph);

        List<AvroGraphMetadata> localGraphList = new ArrayList<>();
        if (graph.isJsonArray()) {

            List<GraphMetadata> metadataList = new ArrayList<>();
            graph.getAsJsonArray().forEach(t -> {
                t.getAsJsonObject();
                //System.out.println(t.getAsJsonObject());
                localGraphList.add(gson.fromJson(t, AvroGraphMetadata.class));
            });
        }

        List<String> connectedDevices = new ArrayList<>();

        if (connectedDeviceIds != null && !connectedDeviceIds.trim().isEmpty()) {
            String[] ids = connectedDeviceIds.split(",");

            if (ids != null && ids.length > 0) {
                for (String id: ids) {
                    connectedDevices.add(id.trim());
                }
            }
        }

        metadata.setConnectedDevices(connectedDevices);
        metadata.setLocalGraph(localGraphList);