@@ -0,0 +1,2437 @@
+package com.google.sps.servlets;%0A%0Aimport com.google.appengine.api.users.UserService;%0Aimport com.google.appengine.api.users.UserServiceFactory;%0Aimport com.google.sps.data.User;%0Aimport com.google.sps.utilities.Constants;%0Aimport com.google.sps.utilities.DatabaseWrapper;%0Aimport java.io.IOException;%0Aimport java.util.HashSet;%0Aimport java.util.Arrays;%0Aimport java.util.Set;%0Aimport javax.json.Json;%0Aimport javax.json.JsonArray;%0Aimport javax.json.JsonArrayBuilder;%0Aimport javax.servlet.annotation.WebServlet;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0A%0A/** Servlet that handles user profile edits. */%0A@WebServlet(%22/profile-update%22)%0Apublic class UserProfileUpdateServlet extends HttpServlet %7B%0A  private static final String email = UserServiceFactory.getUserService().getCurrentUser().getEmail();%0A  private DatabaseWrapper databaseWrapper = new DatabaseWrapper(Constants.DB_INSTANCEID, Constants.DB_DATABASEID);%0A%0A  @Override%0A  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException %7B%0A    User user = databaseWrapper.readUserFromEmail(email);%0A    String userJson = Json.createObjectBuilder()%0A        .add(%22name%22, user.getName())%0A        .add(%22email%22, email)%0A        .add(%22interests%22, createJsonArray(user.getInterests()))%0A        .add(%22skills%22, createJsonArray(user.getSkills()))%0A        .build()%0A        .toString();%0A    response.setContentType(%22application/json;%22);%0A    response.setCharacterEncoding(%22UTF-8%22);%0A    response.getWriter().println(userJson);%0A  %7D%0A%0A  public JsonArray createJsonArray(Set%3CString%3E elements) %7B%0A    JsonArrayBuilder builder = Json.createArrayBuilder();%0A    for (String element : elements) %7B%0A      builder.add(element);%0A    %7D%0A    return builder.build();%0A  %7D%0A%0A  @Override%0A  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException %7B%0A    // Get the input from the form.%0A    String name = request.getParameter(%22name%22);%0A    Set%3CString%3E interests = new HashSet%3C%3E(Arrays.asList(request.getParameter(%22interests%22)));%0A    Set%3CString%3E skills = new HashSet%3C%3E(Arrays.asList(request.getParameter(%22skills%22)));%0A    %0A    User updatedUser =%0A        new User.Builder(name, email)%0A            .setInterests(interests)%0A            .setSkills(skills)%0A            .build();%0A    databaseWrapper.insertOrUpdateUser(updatedUser);%0A    response.sendRedirect(%22/profile.html%22);%0A  %7D%0A%7D%0A

Add user profile update servlet