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.ArrayList; 023import java.util.List; 024 025import javax.servlet.ServletException; 026import javax.servlet.http.HttpServlet; 027import javax.servlet.http.HttpServletRequest; 028import javax.servlet.http.HttpServletResponse; 029 030import net.sf.json.JSONSerializer; 031import pt.ua.dicoogle.core.XMLSupport; 032import pt.ua.dicoogle.server.SOPList; 033import pt.ua.dicoogle.server.TransfersStorage; 034import pt.ua.dicoogle.server.web.utils.ResponseUtil; 035 036 037/** 038* 039* @author Frederico Silva<fredericosilva@ua.pt> 040*/ 041public class TransferOptionsServlet extends HttpServlet { 042 043 @Override 044 protected void doGet(HttpServletRequest req, HttpServletResponse resp) 045 throws ServletException, IOException { 046 String uid = req.getParameter("uid"); 047 048 resp.setContentType("application/json"); 049 String soplist = SOPList.getInstance().getSOPList(); 050 resp.getWriter().write(soplist); 051 } 052 053 @Override 054 protected void doPost(HttpServletRequest req, HttpServletResponse resp) 055 throws ServletException, IOException { 056 057 String UID = req.getParameter("uid"); 058 String option = req.getParameter("option"); 059 String valueS = req.getParameter("value"); 060 boolean value = Boolean.parseBoolean(req.getParameter("value")); 061 062 SOPList.getInstance().updateTSField(UID, option, value); 063 new XMLSupport().printXML(); 064 ResponseUtil.simpleResponse(resp, "success", true); 065 } 066 067 public static class TransferenceOptionsResponse { 068 List<Option> options; 069 070 public TransferenceOptionsResponse() { 071 options = new ArrayList<>(); 072 073 } 074 075 public List<Option> getOptions() { 076 return options; 077 } 078 079 public void setOptions(List<Option> options) { 080 this.options = options; 081 } 082 083 public static TransferenceOptionsResponse fromBooleanList(boolean[] tsList) { 084 TransferenceOptionsResponse tor = new TransferenceOptionsResponse(); 085 for (int i = 0; i < tsList.length; i++) { 086 tor.options.add(new Option( 087 TransfersStorage.globalTransferMap.get(i), tsList[i])); 088 } 089 return tor; 090 } 091 092 public static String getJSON(boolean[] tsList) { 093 TransferenceOptionsResponse tor = fromBooleanList(tsList); 094 return JSONSerializer.toJSON(tor).toString(); 095 } 096 097 public static class Option { 098 String name; 099 boolean value; 100 101 public Option(String name, boolean value) { 102 this.name = name; 103 this.value = value; 104 } 105 106 public String getName() { 107 return name; 108 } 109 110 public void setName(String name) { 111 this.name = name; 112 } 113 114 public boolean isValue() { 115 return value; 116 } 117 118 public void setValue(boolean value) { 119 this.value = value; 120 } 121 } 122 } 123} 124