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