package cs263;

import java.io.IOException;
import java.util.Date;

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

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

// The Worker servlet should be mapped to the "/worker" URL.
public class Worker extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String title = request.getParameter("title");
        String year = request.getParameter("year");
        String director = request.getParameter("director");
        String genre = request.getParameter("genre");
        String plot = request.getParameter("plot");
        String rating = request.getParameter("rating");
        String poster_url = request.getParameter("poster");
        		
        System.out.println(title);
        System.out.println(year);
        System.out.println(director);
        System.out.println(rating);
        System.out.println(poster_url);
        
        //TODO Convert json_data to GSON object

        Key movieKey = KeyFactory.createKey("Movie", title);
        Entity movie = new Entity("Movies", movieKey);
        movie.setProperty("title", title);
        movie.setProperty("year", year);
        movie.setProperty("director", director);
        movie.setProperty("genre", genre);
        movie.setProperty("plot", plot);
        movie.setProperty("rating", rating);
        movie.setProperty("poster", poster_url);

        DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
        datastore.put(movie);
    }
}

@@ -1144,16 +1144,8 @@
 ;%0A  
-      %09%09
 %0A   
@@ -1153,239 +1153,40 @@
     
-System.out.println(title);%0A        System.out.println(year);%0A        System.out.println(director);%0A        System.out.println(rating);%0A        System.out.println(poster_url);%0A        %0A        //TODO Convert json_data to GSON object
+%0A        Date date = new Date();
 %0A%0A  
@@ -1284,17 +1284,16 @@
 y(%22Movie
-s
 %22, movie
@@ -1298,16 +1298,57 @@
 ieKey);%0A
+        movie.setProperty(%22date%22, date);%0A
         

Add Date to movie information