// 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");
//     }
// }


import certh.iti.mklab.easie.MongoUtils;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import java.net.UnknownHostException;
import java.util.ArrayList;
import org.bson.Document;
import org.bson.types.ObjectId;

    /**
     * @returns Company's name
     */
    public String getCompanyName() {
        return company_name;
    }

    /**
     * @returns Company's website
     */
    public String getWebsite() {
        return website;
    }

    /**
     * Inserts Company to the database based on the available company name and
     * website
     *
     * @return company's id
     */
    private ObjectId insertCompany() {
        Document object = new Document();

        object.append("company_name", company_name.trim());
        if (website != null) {
            object.append("website", website.toLowerCase());
        }
        ArrayList list = new ArrayList();
        list.add(company_name.trim());
        object.append("aliases", list);

// 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/companymatching/CompanyMatcher.java
import certh.iti.mklab.easie.MongoUtils;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoCursor;
import java.net.UnknownHostException;
import java.util.ArrayList;
import org.bson.Document;
import org.bson.types.ObjectId;

    /**
     * @returns Company's name
     */
    public String getCompanyName() {
        return company_name;
    }

    /**
     * @returns Company's website
     */
    public String getWebsite() {
        return website;
    }

    /**
     * Inserts Company to the database based on the available company name and
     * website
     *
     * @return company's id
     */
    private ObjectId insertCompany() {
        Document object = new Document();

        object.append("company_name", company_name.trim());
        if (website != null) {
            object.append("website", website.toLowerCase());
        }
        ArrayList list = new ArrayList();
        list.add(company_name.trim());
        object.append("aliases", list);

        ObjectId id = MongoUtils.insertDoc(companies, object);
