001/** 002 * Copyright (C) 2014 Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/ 003 * 004 * This file is part of Dicoogle/dicoogle. 005 * 006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Dicoogle/dicoogle is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Dicoogle. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package pt.ua.dicoogle.server.web.servlets.management; 020 021import java.io.IOException; 022import java.util.concurrent.ExecutionException; 023 024import javax.servlet.ServletException; 025import javax.servlet.http.HttpServlet; 026import javax.servlet.http.HttpServletRequest; 027import javax.servlet.http.HttpServletResponse; 028 029import pt.ua.dicoogle.server.web.utils.ResponseUtil; 030import pt.ua.dicoogle.taskManager.RunningIndexTasks; 031 032/** 033* 034* @author Frederico Silva<fredericosilva@ua.pt> 035*/ 036public class RunningTasksServlet extends HttpServlet { 037 038 @Override 039 protected void doGet(HttpServletRequest req, HttpServletResponse resp) 040 throws ServletException, IOException { 041 042 resp.setContentType("application/json"); 043 resp.getWriter().write(RunningIndexTasks.getInstance().toJson()); 044 } 045 046 @Override 047 protected void doPost(HttpServletRequest req, HttpServletResponse resp) 048 throws ServletException, IOException { 049 String action = req.getParameter("action"); 050 051 if(action != null && !action.equals("delete")) 052 { 053 resp.sendError(400, "action param needed: only delete is supported"); 054 } 055 056 String type = req.getParameter("type"); 057 String taskUid = req.getParameter("uid"); 058 if(type == null) 059 { 060 resp.sendError(400,"type param not existent"); 061 } 062 if(type.equals("close")) 063 ResponseUtil.simpleResponse(resp, "removed", RunningIndexTasks.getInstance().removeTask(taskUid)); 064 else if(type.equals("stop")) 065 ResponseUtil.simpleResponse(resp, "stopped", RunningIndexTasks.getInstance().stopTask(taskUid)); 066 else 067 ResponseUtil.simpleResponse(resp, "error", true); 068 } 069 070 071}