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;
023
024import javax.servlet.ServletException;
025import javax.servlet.http.HttpServlet;
026import javax.servlet.http.HttpServletRequest;
027import javax.servlet.http.HttpServletResponse;
028import net.sf.json.JSONSerializer;
029
030import org.apache.commons.lang3.StringUtils;
031
032import pt.ua.dicoogle.core.ServerSettings;
033
034/**
035 *
036 * @author Frederico Silva <fredericosilva@ua.pt>
037 */
038public class DicomQuerySettingsServlet extends HttpServlet {
039
040        @Override
041        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
042                        throws ServletException, IOException {
043                ServerSettings ss = ServerSettings.getInstance();
044
045                int responseTimeout = ss.getRspDelay();
046                int connectionTimeout = ss.getConnectionTimeout();
047                int idleTimeout = ss.getIdleTimeout();
048                int acceptTimeout = ss.getAcceptTimeout();
049                int maxPduSend = ss.getMaxPDULenghtSend();
050                int maxPduReceive = ss.getMaxPDULengthReceive();
051                int maxAssociations = ss.getMaxClientAssoc();
052
053                QueryRetrieveSettingsObject queryRetrieveSettings = new QueryRetrieveSettingsObject(
054                                responseTimeout, connectionTimeout, idleTimeout, acceptTimeout,
055                                maxPduSend, maxPduReceive, maxAssociations);
056                resp.setContentType("application/json");
057                resp.getWriter().write(JSONSerializer.toJSON(queryRetrieveSettings).toString());
058        }
059
060        @Override
061        protected void doPost(HttpServletRequest req, HttpServletResponse resp)
062                        throws ServletException, IOException {
063                String responseTimeout = req.getParameter("responseTimeout");
064                String connectionTimeout = req.getParameter("connectionTimeout");
065                String idleTimeout = req.getParameter("idleTimeout");
066                String acceptTimeout = req.getParameter("acceptTimeout");
067                String maxPduSend = req.getParameter("maxPduSend");
068                String maxPduReceive = req.getParameter("maxPduReceive");
069                String maxAssociations = req.getParameter("maxAssociations");
070
071                ServerSettings ss = ServerSettings.getInstance();
072
073                if (StringUtils.isNotEmpty(responseTimeout)) {
074                        int intV = Integer.parseInt(responseTimeout);
075                        ss.setRspDelay(intV);
076                }
077                if (StringUtils.isNotEmpty(connectionTimeout)) {
078                        int intV = Integer.parseInt(connectionTimeout);
079                        ss.setConnectionTimeout(intV);
080                }
081                if (StringUtils.isNotEmpty(idleTimeout)) {
082                        int intV = Integer.parseInt(idleTimeout);
083                        ss.setIdleTimeout(intV);
084                }
085                if (StringUtils.isNotEmpty(acceptTimeout)) {
086                        int intV = Integer.parseInt(acceptTimeout);
087                        ss.setAcceptTimeout(intV);
088                }
089                if (StringUtils.isNotEmpty(maxPduSend)) {
090                        int intV = Integer.parseInt(maxPduSend);
091                        ss.setMaxPDULengthSend(intV);
092                }
093                if (StringUtils.isNotEmpty(maxPduReceive)) {
094                        int intV = Integer.parseInt(maxPduReceive);
095                        ss.setMaxPDULengthReceive(intV);
096                }
097                if (StringUtils.isNotEmpty(maxAssociations)) {
098                        int intV = Integer.parseInt(maxAssociations);
099                        ss.setMaxClientAssoc(intV);
100                }
101
102        }
103
104        /*
105         * MODEL FOR QUERY RETRIEVE SETTINGS
106         */
107        public static class QueryRetrieveSettingsObject {
108        private int responseTimeout, connectionTimeout, idleTimeout, acceptTimeout,
109                                maxPduSend, maxPduReceive, maxAssociations;
110
111        public QueryRetrieveSettingsObject() {
112        }
113        
114                public QueryRetrieveSettingsObject(int responseTimeout,
115                                int connectionTimeout, int idleTimeout, int acceptTimeout,
116                                int maxPduSend, int maxPduReceive, int maxAssociations) {
117                        super();
118                        this.responseTimeout = responseTimeout;
119                        this.connectionTimeout = connectionTimeout;
120                        this.idleTimeout = idleTimeout;
121                        this.acceptTimeout = acceptTimeout;
122                        this.maxPduSend = maxPduSend;
123                        this.maxPduReceive = maxPduReceive;
124                        this.maxAssociations = maxAssociations;
125                }
126
127        public int getResponseTimeout() {
128            return responseTimeout;
129        }
130
131        public void setResponseTimeout(int responseTimeout) {
132            this.responseTimeout = responseTimeout;
133        }
134
135        public int getConnectionTimeout() {
136            return connectionTimeout;
137        }
138
139        public void setConnectionTimeout(int connectionTimeout) {
140            this.connectionTimeout = connectionTimeout;
141        }
142
143        public int getIdleTimeout() {
144            return idleTimeout;
145        }
146
147        public void setIdleTimeout(int idleTimeout) {
148            this.idleTimeout = idleTimeout;
149        }
150
151        public int getAcceptTimeout() {
152            return acceptTimeout;
153        }
154
155        public void setAcceptTimeout(int acceptTimeout) {
156            this.acceptTimeout = acceptTimeout;
157        }
158
159        public int getMaxPduSend() {
160            return maxPduSend;
161        }
162
163        public void setMaxPduSend(int maxPduSend) {
164            this.maxPduSend = maxPduSend;
165        }
166
167        public int getMaxPduReceive() {
168            return maxPduReceive;
169        }
170
171        public void setMaxPduReceive(int maxPduReceive) {
172            this.maxPduReceive = maxPduReceive;
173        }
174
175        public int getMaxAssociations() {
176            return maxAssociations;
177        }
178
179        public void setMaxAssociations(int maxAssociations) {
180            this.maxAssociations = maxAssociations;
181        }
182
183        }
184}