package com.enseirb.telecom.dngroup.dvd2c.db;

import java.net.UnknownHostException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.util.JSON;


//NHE a class with only static methods should be final or abstract
public class DbInit {
	//NHE no hard coded values allowed in the code
	String hostname = "127.0.0.1";
	//NHE no hard coded values allowed in the code
	int port = 27017;
	String username;
	String password;

	//NHE bad method firstname https://google-styleguide.googlecode.com/svn/trunk/javaguide.html#s5.2.3-method-names
	public static MongoClient connect() throws UnknownHostException {
		DbInit Database = new DbInit();
		MongoClient mongoClient = new MongoClient(Database.hostname, Database.port);
		//NHE where is it closed ? http://api.mongodb.org/java/2.10.0/com/mongodb/Mongo.html#close%28%29
		return mongoClient;
	}
	public static DBObject createDBObject(Object o) throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();
		DBObject dbo = (DBObject)JSON.parse(mapper.writeValueAsString(o));
		return dbo;
	}
}

@@ -79,16 +79,74 @@
 ption;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0A
 import c
@@ -196,16 +196,16 @@
 eption;%0A
-
 import c
@@ -430,16 +430,95 @@
 bInit %7B%0A
+%09private static final Logger LOGGER = LoggerFactory.getLogger(DbInit.class);%0A%09%0A
 %09//NHE n
@@ -581,17 +581,15 @@
  = %22
-127
+0
 .0.0.
-1
+0
 %22;%0A%09
@@ -906,16 +906,19 @@
 Init();%0A
+%09%09%0A
 %09%09MongoC
@@ -923,16 +923,40 @@
 oClient 
+mongoClient;%0A%09%09try %7B%0A%09%09%09
 mongoCli
@@ -1012,16 +1012,125 @@
 .port);%0A
+%09%09%7D catch (UnknownHostException e) %7B%0A%09%09%09LOGGER.error(%22try to connect to %7Bhostname%7D:%7Bport%7D%22);%0A%09%09%09throw e;%0A%09%09%7D%0A
 %09%09//NHE 

Change host name to 0.0.0.0