package com.francelabs.datafari.servlets.admin;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.json.JSONException;
import org.json.JSONObject;

import com.francelabs.datafari.constants.CodesReturned;
import com.francelabs.datafari.service.db.UserDataService;
import com.francelabs.datafari.user.User;

/**
 * Servlet implementation class getAllUsersAndRoles
 */
@WebServlet("/SearchAdministrator/addUser")
public class AddUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private static final Logger logger = Logger.getLogger(AddUser.class.getName());  
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddUser() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		JSONObject jsonResponse = new JSONObject();
		request.setCharacterEncoding("utf8");
		response.setContentType("application/json");
		try{
			if (request.getParameter(UserDataService.USERNAMECOLUMN)!=null && request.getParameter(UserDataService.PASSWORDCOLUMN)!=null && request.getParameter(UserDataService.ROLECOLUMN+"[]")!=null){
				User user = new User(request.getParameter(UserDataService.USERNAMECOLUMN).toString(),request.getParameter(UserDataService.PASSWORDCOLUMN).toString());
				int code = user.signup(Arrays.asList(request.getParameter(UserDataService.ROLECOLUMN+"[]")));
				if ( code == CodesReturned.ALLOK ){
					jsonResponse.put("code", CodesReturned.ALLOK).put("statut", "User deleted with success");
				}else if ( code == CodesReturned.USERALREADYINBASE){
					jsonResponse.put("code", CodesReturned.USERALREADYINBASE).put("statut", "User already Signed up");
				}else{
					jsonResponse.put("code", CodesReturned.PROBLEMCONNECTIONDATABASE).put("statut", "Problem with database");
				}
			}else{
				jsonResponse.put("code", CodesReturned.PROBLEMQUERY).put("statut", "Problem with query");
			}
		}catch (JSONException e) {
			logger.error(e);
		}
		PrintWriter out = response.getWriter();
		out.print(jsonResponse);
	}

}

@@ -102,36 +102,8 @@
 er;%0A
-import java.util.ArrayList;%0A
 impo
@@ -787,20 +787,17 @@
 D = 1L;%0A
-    
+%09
 private 
@@ -871,23 +871,16 @@
 ());
-  %0A    /**%0A    
+%0A%0A%09/**%0A%09
  * @
@@ -913,20 +913,14 @@
 t()%0A
-     */%0A    
+%09 */%0A%09
 publ
@@ -934,24 +934,18 @@
 ser() %7B%0A
-        
+%09%09
 super();
@@ -949,16 +949,10 @@
 ();%0A
-        
+%09%09
 // T
@@ -991,12 +991,9 @@
 tub%0A
-    
+%09
 %7D%0A%0A%09
@@ -1062,32 +1062,41 @@
 pServletResponse
+%0A%09 *     
  response)%0A%09 */%0A
@@ -1095,16 +1095,27 @@
 e)%0A%09 */%0A
+%09@Override%0A
 %09protect
@@ -1129,16 +1129,22 @@
  doPost(
+final 
 HttpServ
@@ -1154,32 +1154,38 @@
 Request request,
+ final
  HttpServletResp
@@ -1240,16 +1240,22 @@
 ion %7B%0A%09%09
+final 
 JSONObje
@@ -1382,16 +1382,17 @@
 );%0A%09%09try
+ 
 %7B%0A%09%09%09if 
@@ -1440,26 +1440,28 @@
 RNAMECOLUMN)
+ 
 !=
+ 
 null && requ
@@ -1512,15 +1512,22 @@
 UMN)
+ 
 !=
+ 
 null
- 
+%0A%09%09%09%09%09
 && r
@@ -1576,27 +1576,38 @@
 LUMN
-+
+ + 
 %22%5B%5D%22)
+ 
 !=
+ 
 null)
+ 
 %7B%0A%09%09%09%09
+final 
 User
@@ -1687,16 +1687,23 @@
 tring(),
+%0A%09%09%09%09%09%09
 request.
@@ -1764,16 +1764,22 @@
 ));%0A%09%09%09%09
+final 
 int code
@@ -1819,32 +1819,38 @@
 est.getParameter
+Values
 (UserDataService
@@ -1860,17 +1860,19 @@
 LECOLUMN
-+
+ + 
 %22%5B%5D%22)));
@@ -1876,25 +1876,24 @@
 ));%0A%09%09%09%09if (
- 
 code == Code
@@ -1911,10 +1911,10 @@
 LLOK
- 
 )
+ 
 %7B%0A%09%09
@@ -2007,24 +2007,25 @@
 ess%22);%0A%09%09%09%09%7D
+ 
 else if ( co
@@ -2021,17 +2021,16 @@
 lse if (
- 
 code == 
@@ -2061,16 +2061,17 @@
 YINBASE)
+ 
 %7B%0A%09%09%09%09%09j
@@ -2169,28 +2169,30 @@
  up%22);%0A%09%09%09%09%7D
+ 
 else
+ 
 %7B%0A%09%09%09%09%09jsonR
@@ -2302,20 +2302,22 @@
 %09%09%7D%0A%09%09%09%7D
+ 
 else
+ 
 %7B%0A%09%09%09%09js
@@ -2416,15 +2416,22 @@
 %0A%09%09%7D
+ 
 catch (
+final 
 JSON
@@ -2471,16 +2471,22 @@
 ;%0A%09%09%7D%0A%09%09
+final 
 PrintWri

Add several roles to new user fix