@@ -0,0 +1,3315 @@
+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.appengine.api.datastore.Transaction;%0Aimport com.google.firebase.auth.FirebaseAuth;%0Aimport com.google.firebase.auth.FirebaseAuthException;%0Aimport com.google.firebase.auth.UserRecord;%0Aimport com.google.sps.firebase.FirebaseAppManager;%0Aimport java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.ConcurrentModificationException;%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/** Servlet that creates a new class Datastore. */%0A@WebServlet(%22/end-help%22)%0Apublic class EndHelp 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    %7D catch (IOException e) %7B%0A      throw new ServletException(e);%0A    %7D%0A  %7D%0A%0A  @Override%0A  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException %7B%0A    // Get the input from the form.%0A    // navigate to /_ah/admin to view Datastore%0A%0A    datastore = DatastoreServiceFactory.getDatastoreService();%0A    System.setProperty(%0A        DatastoreServiceConfig.DATASTORE_EMPTY_LIST_SUPPORT, Boolean.TRUE.toString());%0A%0A    try %7B%0A      String classCode = request.getParameter(%22classCode%22).trim();%0A%0A      int retries = 10;%0A      while (true) %7B%0A        Transaction txn = datastore.beginTransaction();%0A        try %7B%0A          // Retrive class entity%0A          Key classKey = KeyFactory.stringToKey(classCode);%0A          Entity classEntity = datastore.get(txn, classKey);%0A%0A          // Get uID from uEmail%0A          String uEmail = request.getParameter(%22uEmail%22);%0A          UserRecord userRecord = authInstance.getUserByEmail(uEmail);%0A          String uID = userRecord.getUid();%0A%0A          // Update beingHelped%0A          ArrayList%3CString%3E beingHelped = (ArrayList) classEntity.getProperty(%22beingHelped%22);%0A          beingHelped.remove(uID);%0A%0A          classEntity.setProperty(%22beingHelped%22, beingHelped);%0A          datastore.put(txn, classEntity);%0A%0A          txn.commit();%0A          break;%0A        %7D catch (ConcurrentModificationException e) %7B%0A          if (retries == 0) %7B%0A            throw e;%0A          %7D%0A          // Allow retry to occur%0A          --retries;%0A        %7D finally %7B%0A          if (txn.isActive()) %7B%0A            txn.rollback();%0A          %7D%0A        %7D%0A      %7D%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

Remove student from beingHelped property