package com.google.sps.search.servlets;

import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.sps.Objects.User;
import com.google.sps.search.CsvReader;

@WebServlet("/name-test-data")
public class NameTestDataServlet extends HttpServlet {

  @Override
  public void init() {
    CsvReader reader = new CsvReader();
    List<String> userInfo = reader.parseCorpus("../../data/user_data.csv");
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    int counter = 0;
    for (String str : userInfo) {
      String[] split = str.split(" ");
      String firstName = split[0];
      String lastName = split[1];
      String userId = firstName + "_" + lastName + counter;
      String email = userId + "@gmail.com";
      User user = new User(userId, firstName, lastName, email, "", "", null, null, null);
      datastore.put(user.toEntity());
      counter++;
    }
  }
}

@@ -685,16 +685,46 @@
 er = 0;%0A
+    if (userInfo != null) %7B%0A  
     for 
@@ -745,24 +745,26 @@
 userInfo) %7B%0A
+  
       String
@@ -786,24 +786,26 @@
 split(%22 %22);%0A
+  
       String
@@ -829,24 +829,26 @@
 t%5B0%5D;%0A      
+  
 String lastN
@@ -863,16 +863,18 @@
 lit%5B1%5D;%0A
+  
       St
@@ -927,24 +927,26 @@
 nter;%0A      
+  
 String email
@@ -977,16 +977,18 @@
 ;%0A      
+ 
+ 
 User use
@@ -1069,16 +1069,18 @@
 ;%0A      
+  
 datastor
@@ -1109,16 +1109,18 @@
 ;%0A      
+  
 counter+
@@ -1122,16 +1122,24 @@
 nter++;%0A
+      %7D%0A
     %7D%0A  

check parseCorpus doesn't return null