@@ -0,0 +1,2697 @@
+package com.google.sps.servlets;%0A%0Aimport com.google.appengine.api.datastore.DatastoreService;%0Aimport com.google.appengine.api.datastore.DatastoreServiceConfig;%0Aimport com.google.appengine.api.datastore.DatastoreServiceFactory;%0Aimport com.google.appengine.api.datastore.Entity;%0Aimport com.google.appengine.api.datastore.EntityNotFoundException;%0Aimport com.google.appengine.api.datastore.Key;%0Aimport com.google.appengine.api.datastore.KeyFactory;%0Aimport com.google.firebase.auth.FirebaseAuth;%0Aimport com.google.firebase.auth.FirebaseAuthException;%0Aimport com.google.firebase.auth.FirebaseToken;%0Aimport com.google.gson.Gson;%0Aimport com.google.sps.firebase.FirebaseAppManager;%0Aimport java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport javax.servlet.ServletConfig;%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.annotation.WebServlet;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0A%0A@WebServlet(%22/check-student%22)%0Apublic class CheckStudentStatus extends HttpServlet %7B%0A  FirebaseAuth authInstance;%0A  DatastoreService datastore;%0A%0A  @Override%0A  public void init(ServletConfig config) throws ServletException %7B%0A    try %7B%0A      authInstance = FirebaseAuth.getInstance(FirebaseAppManager.getApp());%0A%0A      datastore = DatastoreServiceFactory.getDatastoreService();%0A      System.setProperty(%0A          DatastoreServiceConfig.DATASTORE_EMPTY_LIST_SUPPORT, Boolean.TRUE.toString());%0A    %7D catch (IOException e) %7B%0A      throw new ServletException(e);%0A    %7D%0A  %7D%0A%0A  @Override%0A  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException %7B%0A    try %7B%0A      // Find user ID%0A      String idToken = request.getParameter(%22userToken%22);%0A      FirebaseToken decodedToken = authInstance.verifyIdToken(idToken);%0A      String uID = decodedToken.getUid();%0A%0A      // Retrive entity%0A      String classCode = request.getParameter(%22classCode%22).trim();%0A      Key classKey = KeyFactory.stringToKey(classCode);%0A      Entity classEntity = datastore.get(classKey);%0A%0A      // Find position in queue%0A      ArrayList%3CString%3E queue = (ArrayList) classEntity.getProperty(%22studentQueue%22);%0A      String pos = Integer.toString(queue.indexOf(uID));%0A%0A      Gson gson = new Gson();%0A      response.setContentType(%22application/json;%22);%0A      response.getWriter().println(gson.toJson(pos));%0A%0A    %7D catch (EntityNotFoundException e) %7B%0A      response.sendError(HttpServletResponse.SC_NOT_FOUND);%0A    %7D catch (IllegalArgumentException e) %7B%0A      response.sendError(HttpServletResponse.SC_BAD_REQUEST);%0A    %7D catch (FirebaseAuthException e) %7B%0A      response.sendError(HttpServletResponse.SC_FORBIDDEN);%0A    %7D%0A  %7D%0A%7D%0A

Create servlet that returns student position on queue