@@ -0,0 +1,3824 @@
+/*%0A * Copyright 2019 Google LLC%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.example.fostracker.servlets.FosTrackerServlet;%0A%0Aimport com.example.fostracker.models.*;%0Aimport com.google.gson.Gson;%0A%0Aimport javax.servlet.ServletException;%0Aimport javax.servlet.annotation.WebServlet;%0Aimport javax.servlet.http.HttpServlet;%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpServletResponse;%0Aimport java.io.IOException;%0Aimport java.io.PrintWriter;%0A%0Aimport com.google.cloud.spanner.ResultSet;%0Aimport com.google.gson.JsonObject;%0Aimport com.example.fostracker.servlets.VerificationServlet.VerificationDatabaseHelper;%0A%0A/**%0A * Prints the Store status given Store phone from Stores table in JSON format.%0A * %3Cp%3E%0A * This Servlet converts the ResultSet into JSON object and prints to the response on @WebServlet(value = %22/store/phon/status%22).%0A */%0A@WebServlet(value = %22/store/phone/status%22)%0Apublic class GetStoreStatusByStorePhoneServlet extends HttpServlet %7B%0A%0A    //Gson object that is used to convert Strings into JSON objects%0A    private Gson gson = new Gson();%0A%0A    class StoreStatus %7B%0A        String status;%0A%0A        StoreStatus( String status )%7B%0A            this.status = status;%0A        %7D%0A    %7D%0A%0A    /**%0A     * HTTP Get method prints the query as response.%0A     *%0A     * @param storeDetailsRequest is GET request.%0A     * @param response            is HttpServletResponse object that is used to write the response.%0A     * @throws ServletException%0A     * @throws IOException%0A     */%0A    @Override%0A    protected void doPost(HttpServletRequest storeDetailsRequest, HttpServletResponse response) throws ServletException, IOException %7B%0A%0A        // Reads the json String using POST request.%0A        String json = storeDetailsRequest.getReader().readLine();%0A%0A        // sets the response to json format.%0A        response.setContentType(%22application/json%22);%0A        response.setCharacterEncoding(%22UTF-8%22);%0A%0A        // output variable is used to write to response.%0A        PrintWriter output;%0A        output = response.getWriter();%0A%0A        // If json is null ( No data was posted ) set the error to 403.%0A        if (json == null) %7B%0A            output.print(%22No data given%22);%0A            response.setStatus(403);%0A        %7D else %7B%0A%0A            // Convert json string to json object to parse data.%0A            JsonObject jsonObj = new Gson().fromJson(json, JsonObject.class);%0A%0A            // Get phone from the JSON object.%0A            String storePhone = jsonObj.get(%22storePhone%22).getAsString();%0A%0A            StoreStatus storeAndStatus;%0A            String storeStatusString;%0A            String status = VerificationDatabaseHelper.queryStatusUsingStorePhone(storePhone);%0A%0A            // If storeData is not empty then sets status to grey.%0A            if (status!=null) %7B%0A                storeAndStatus = new StoreStatus(status);%0A                storeStatusString = this.gson.toJson(storeAndStatus);%0A                output.println(storeStatusString);%0A            %7D else %7B%0A                storeAndStatus = new StoreStatus(%22grey%22);%0A                storeStatusString = this.gson.toJson(storeAndStatus);%0A                output.println(storeStatusString);%0A            %7D%0A%0A            // Prints success message.%0A            output.print(%22Successful%22);%0A            output.flush();%0A        %7D%0A    %7D%0A%7D%0A%0A

Add Servlet that fetches store status if store phone is given