package edu.brown.hackathon.fifteenminutes;

import java.io.IOException;
import java.util.List;

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.FetchOptions;
import com.google.appengine.api.datastore.Query;
import com.google.gson.Gson;

@SuppressWarnings("serial")
public class IsFamousServlet extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    long userId = getUserIdOfFamousUser();
    
    UserResource ur = new UserResource(userId);
    Gson gson = new Gson();
    resp.setContentType("application/json");
    resp.getWriter().println(gson.toJson(ur));
  }
  
  public static long getUserIdOfFamousUser() {
    Query query = new Query("FamousUser");
    query.addSort("current_time", Query.SortDirection.DESCENDING);
    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    List<Entity> results = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(1));
    return (Long)results.get(0).getProperty("user_id");
  }
}
@@ -1260,16 +1260,78 @@
 it(1));%0A
+    if (results.size() %3C 1) %7B%0A      return -1;%0A    %7D else %7B%0A  
     retu
@@ -1378,13 +1378,19 @@
 r_id%22);%0A
+    %7D%0A
   %7D%0A%7D

Allow creation of the first famous user.