// Path: src/main/java/certh/iti/mklab/easie/MongoUtils.java
// public final class MongoUtils {
// 
//     /**
//      * Creates new mongodb client
//      *
//      * @param username
//      * @param password
//      * @param db
//      * @return
//      */
//     public static MongoClient newClient(String server_address, String username, String password, String db) {
//         List<ServerAddress> seeds = new ArrayList<ServerAddress>();
//         seeds.add(new ServerAddress(server_address));
//         List<MongoCredential> credentials = new ArrayList<MongoCredential>();
//         credentials.add(
//                 MongoCredential.createScramSha1Credential(
//                         username,
//                         db,
//                         password.toCharArray()
//                 )
//         );
// 
//         return new MongoClient(seeds, credentials);
//     }
// 
//     /**
//      * Creates new mongodb client
//      *
//      * @return
//      */
//     public static MongoClient newClient() {
//         return new MongoClient();
//     }
// 
//     /**
//      * Connects to mongoDB and returns a specified collection
//      *
//      * @param mongoDB name
//      * @param Collection collection
//      * @return DBCollection object
//      */
//     public static MongoCollection connect(MongoClient client, String dbname, String cname) {
//         MongoDatabase db = client.getDatabase(dbname);
//         MongoCollection collection = db.getCollection(cname);
//         return collection;
//     }
// 
//     /**
//      * Inserts a document in mongoDB
//      *
//      * @param mongoDB name
//      * @param Collection name
//      * @param document
//      */
//     public static ObjectId insertDoc(MongoClient mongoClient, String dbname, String cname, Document document) {
//         MongoCollection collection = connect(mongoClient, dbname, cname);
//         collection.insertOne(document);
//         return (ObjectId) document.get("_id");
//     }
// 
//     public static ObjectId insertDoc(MongoCollection collection, Document document) {
//         collection.insertOne(document);
//         return (ObjectId) document.get("_id");
//     }
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/configuration/Configuration.java
// 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;
// }


import com.mongodb.MongoClient;
import certh.iti.mklab.easie.MongoUtils;
import certh.iti.mklab.easie.configuration.Configuration.Store;
import com.mongodb.client.MongoCollection;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import org.bson.Document;

/*
 * Copyright 2016 vasgat.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package certh.iti.mklab.easie.executor.handlers;




/**
 * DataHandler transforms the extracted data into Snippet Objects and stores
 * them into a mongodb or in the drive
 *
 * @author vasgat
 */
public class DataHandler {

    private List<Document> extracted_company_info;
    private List<ArrayList<Document>> extracted_metrics;
    private StoreUtils storeUtils;
    private String entity_name;

    /**
     * Creates SnippetHandler Object
     *
     * @param extracted_company_info: extracted company fields
     * @param extracted_metrics:      extracted snippet fields
     * @throws Exception
     */
    public DataHandler(List<Document> extracted_company_info, List<ArrayList<Document>> extracted_metrics, String entity_name) {
        this.extracted_company_info = extracted_company_info;
        this.extracted_metrics = extracted_metrics;
        this.entity_name = entity_name;
        storeUtils = new StoreUtils(extracted_company_info, extracted_metrics, entity_name);
    }

    /**
     * Stores the extracted data (companies_fields and extracted_metrics) into
     * mongodb or drive
     *
     * @param store       contains information about where the data are going to be
     *                    stored
     * @param source_name
     * @throws UnknownHostException
     * @throws FileNotFoundException
     * @throws Exception
     */

// Path: src/main/java/certh/iti/mklab/easie/MongoUtils.java
// public final class MongoUtils {
// 
//     /**
//      * Creates new mongodb client
//      *
//      * @param username
//      * @param password
//      * @param db
//      * @return
//      */
//     public static MongoClient newClient(String server_address, String username, String password, String db) {
//         List<ServerAddress> seeds = new ArrayList<ServerAddress>();
//         seeds.add(new ServerAddress(server_address));
//         List<MongoCredential> credentials = new ArrayList<MongoCredential>();
//         credentials.add(
//                 MongoCredential.createScramSha1Credential(
//                         username,
//                         db,
//                         password.toCharArray()
//                 )
//         );
// 
//         return new MongoClient(seeds, credentials);
//     }
// 
//     /**
//      * Creates new mongodb client
//      *
//      * @return
//      */
//     public static MongoClient newClient() {
//         return new MongoClient();
//     }
// 
//     /**
//      * Connects to mongoDB and returns a specified collection
//      *
//      * @param mongoDB name
//      * @param Collection collection
//      * @return DBCollection object
//      */
//     public static MongoCollection connect(MongoClient client, String dbname, String cname) {
//         MongoDatabase db = client.getDatabase(dbname);
//         MongoCollection collection = db.getCollection(cname);
//         return collection;
//     }
// 
//     /**
//      * Inserts a document in mongoDB
//      *
//      * @param mongoDB name
//      * @param Collection name
//      * @param document
//      */
//     public static ObjectId insertDoc(MongoClient mongoClient, String dbname, String cname, Document document) {
//         MongoCollection collection = connect(mongoClient, dbname, cname);
//         collection.insertOne(document);
//         return (ObjectId) document.get("_id");
//     }
// 
//     public static ObjectId insertDoc(MongoCollection collection, Document document) {
//         collection.insertOne(document);
//         return (ObjectId) document.get("_id");
//     }
// }
// 
// Path: src/main/java/certh/iti/mklab/easie/configuration/Configuration.java
// 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;
// }


// Path: src/main/java/certh/iti/mklab/easie/executor/handlers/DataHandler.java
import com.mongodb.MongoClient;
import certh.iti.mklab.easie.MongoUtils;
import certh.iti.mklab.easie.configuration.Configuration.Store;
import com.mongodb.client.MongoCollection;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import org.bson.Document;

/*
 * Copyright 2016 vasgat.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package certh.iti.mklab.easie.executor.handlers;




/**
 * DataHandler transforms the extracted data into Snippet Objects and stores
 * them into a mongodb or in the drive
 *
 * @author vasgat
 */
public class DataHandler {

    private List<Document> extracted_company_info;
    private List<ArrayList<Document>> extracted_metrics;
    private StoreUtils storeUtils;
    private String entity_name;

    /**
     * Creates SnippetHandler Object
     *
     * @param extracted_company_info: extracted company fields
     * @param extracted_metrics:      extracted snippet fields
     * @throws Exception
     */
    public DataHandler(List<Document> extracted_company_info, List<ArrayList<Document>> extracted_metrics, String entity_name) {
        this.extracted_company_info = extracted_company_info;
        this.extracted_metrics = extracted_metrics;
        this.entity_name = entity_name;
        storeUtils = new StoreUtils(extracted_company_info, extracted_metrics, entity_name);
    }

    /**
     * Stores the extracted data (companies_fields and extracted_metrics) into
     * mongodb or drive
     *
     * @param store       contains information about where the data are going to be
     *                    stored
     * @param source_name
     * @throws UnknownHostException
     * @throws FileNotFoundException
     * @throws Exception
     */

    public void store(Store store, String source_name) throws UnknownHostException, FileNotFoundException, IOException {
