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 */ 019 020package pt.ua.dicoogle.server.web.servlets.management; 021 022import java.io.IOException; 023import java.net.URI; 024import java.net.URISyntaxException; 025import java.util.Arrays; 026 027import javax.servlet.ServletException; 028import javax.servlet.http.HttpServlet; 029import javax.servlet.http.HttpServletRequest; 030import javax.servlet.http.HttpServletResponse; 031import org.slf4j.Logger; 032import org.slf4j.LoggerFactory; 033 034import pt.ua.dicoogle.plugins.PluginController; 035 036/** Remove servlet. 037 * 038 * @author Tiago Marques Godinho <tmgodinho@ua.pt> 039 */ 040public class RemoveServlet extends HttpServlet { 041 042 private static final Logger logger = LoggerFactory.getLogger(RemoveServlet.class); 043 044 /** 045 */ 046 private static final long serialVersionUID = 1L; 047 048 @Override 049 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 050 051 // Getting Parameters. 052 String[] uris = req.getParameterValues("uri"); 053 054 if (uris == null) { 055 resp.sendError(400, "No uri provided"); 056 return; 057 } 058 059 URI[] effUris = new URI[uris.length]; 060 try { 061 for (int i = 0 ; i < effUris.length ; i++) { 062 effUris[i] = new URI(uris[i]); 063 } 064 } catch (URISyntaxException ex) { 065 logger.info("Received bad URI", ex); 066 resp.sendError(400, "Bad URI: " + ex.getInput()); 067 return; 068 } 069 070 // unindex 071 for (URI uri : effUris) { 072 try { 073 PluginController.getInstance().remove(uri); 074 } catch (RuntimeException ex) { 075 logger.error(ex.getMessage(), ex); 076 } 077 } 078 079 logger.info("Finished removing {}", Arrays.asList(uris)); 080 resp.setStatus(200); 081 } 082}