1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you
5  * may not use this file except in compliance with the License. You may
6  * obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13  * implied. See the License for the specific language governing
14  * permissions and limitations under the License.
15  */
16 
17 package com.android.vts.servlet;
18 
19 import static com.googlecode.objectify.ObjectifyService.ofy;
20 
21 import com.android.vts.entity.TestEntity;
22 import com.google.appengine.api.datastore.DatastoreService;
23 import com.google.appengine.api.datastore.DatastoreServiceFactory;
24 import com.google.appengine.api.datastore.Entity;
25 import com.google.appengine.api.datastore.Query;
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.Comparator;
29 import java.util.HashSet;
30 import java.util.List;
31 import java.util.Set;
32 import java.util.logging.Level;
33 import java.util.stream.Collectors;
34 import javax.servlet.RequestDispatcher;
35 import javax.servlet.ServletException;
36 import javax.servlet.http.HttpServletRequest;
37 import javax.servlet.http.HttpServletResponse;
38 
39 /**
40  * Servlet for handling requests to display profiling tests.
41  */
42 public class ShowProfilingListServlet extends BaseServlet {
43 
44   private static final String PROFILING_LIST_JSP = "WEB-INF/jsp/show_profiling_list.jsp";
45 
46   @Override
getNavParentType()47   public PageType getNavParentType() {
48     return PageType.PROFILING_LIST;
49   }
50 
51   @Override
getBreadcrumbLinks(HttpServletRequest request)52   public List<Page> getBreadcrumbLinks(HttpServletRequest request) {
53     return null;
54   }
55 
56   @Override
doGetHandler(HttpServletRequest request, HttpServletResponse response)57   public void doGetHandler(HttpServletRequest request, HttpServletResponse response)
58       throws IOException {
59     List<String> tests = ofy().load().type(TestEntity.class)
60         .filter(TestEntity.HAS_PROFILING_DATA, true).list().stream()
61         .sorted(Comparator.comparing(TestEntity::getTestName)).map(t -> t.getTestName())
62         .collect(Collectors.toList());
63 
64     response.setStatus(HttpServletResponse.SC_OK);
65     request.setAttribute("testNames", tests);
66     RequestDispatcher dispatcher = request.getRequestDispatcher(PROFILING_LIST_JSP);
67     try {
68       dispatcher.forward(request, response);
69     } catch (ServletException e) {
70       logger.log(Level.SEVERE, "Servlet Excpetion caught : ", e);
71     }
72   }
73 }
74