# HG changeset patch # User Raimund Renkert # Date 1423062438 -3600 # Node ID be0cd91abd0f3c6f32d00e82d29488ed82c5450a # Parent 397ce12d42225c380f93905000e031ec345a6bff Added classes for REST support. diff -r 397ce12d4222 -r be0cd91abd0f src/main/java/de/intevation/lada/util/rest/JaxRsActivator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/util/rest/JaxRsActivator.java Wed Feb 04 16:07:18 2015 +0100 @@ -0,0 +1,17 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada.util.rest; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + + +@ApplicationPath("/rest") +public class JaxRsActivator extends Application { + +} diff -r 397ce12d4222 -r be0cd91abd0f src/main/java/de/intevation/lada/util/rest/Response.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/intevation/lada/util/rest/Response.java Wed Feb 04 16:07:18 2015 +0100 @@ -0,0 +1,158 @@ +/* Copyright (C) 2013 by Bundesamt fuer Strahlenschutz + * Software engineering by Intevation GmbH + * + * This file is Free Software under the GNU GPL (v>=3) + * and comes with ABSOLUTELY NO WARRANTY! Check out + * the documentation coming with IMIS-Labordaten-Application for details. + */ +package de.intevation.lada.util.rest; + +import java.util.HashMap; +import java.util.Map; + + +/** +* Response object storing information about success, warnings, errors and +* the data object. This class is used as return value in REST services. +* +* @author Torsten Irländer +*/ +public class Response implements java.io.Serializable { + + private static final long serialVersionUID = 1L; + + private Boolean success; + private String message; + private Object data; + private Map errors; + private Map warnings; + private Boolean readonly; + private int totalCount; + + /** + * Constructor to create a basic Response object. + * + * @param success Information if the operation was successful. + * @param code The return code. + * @param data The data object wrapped by the response. + */ + public Response(boolean success, int code, Object data) { + this.success = success; + this.message = Integer.toString(code); + this.data = data; + this.errors = new HashMap(); + this.warnings = new HashMap(); + this.readonly = Boolean.FALSE; + this.totalCount = 0; + } + + /** + * Constructor to create a basic Response object. + * + * @param success Information if the operation was successful. + * @param code The return code. + * @param data The data object wrapped by the response. + */ + public Response(boolean success, int code, Object data, int totalCount) { + this.success = success; + this.message = Integer.toString(code); + this.data = data; + this.errors = new HashMap(); + this.warnings = new HashMap(); + this.readonly = Boolean.FALSE; + this.totalCount = totalCount; + } + + public Boolean getSuccess() { + return success; + } + + public void setSuccess(Boolean success) { + this.success = success; + } + + public String getMessage() { + return message; + } + + public void setMessage(int message) { + this.message = Integer.toString(message); + } + + public Object getData() { + return data; + } + + public void setData(Object data) { + this.data = data; + } + + public Map getErrors() { + return errors; + } + + public void setErrors(Map errors) { + this.errors = this.convertCodes(errors); + } + + public Map getWarnings() { + return warnings; + } + + public void setWarnings(Map warnings) { + this.warnings = this.convertCodes(warnings); + } + + public Boolean getReadonly() { + return readonly; + } + + public void setReadonly(Boolean readonly) { + this.readonly = readonly; + } + + /** + * @return the totalCount + */ + public int getTotalCount() { + return totalCount; + } + + /** + * @param totalCount the totalCount to set + */ + public void setTotalCount(int totalCount) { + this.totalCount = totalCount; + } + + private HashMap convertCodes(Map codes) { + HashMap converted = new HashMap(); + if (codes == null || codes.isEmpty()) { + return converted; + } + for (Map.Entry entry: codes.entrySet()) { + converted.put(entry.getKey(), Integer.toString(entry.getValue())); + } + return converted; + } + + /* Currently unused but might be helpfull later */ + @SuppressWarnings("unused") + private String codes2string(Map codes) { + String response = "{"; + if (codes == null || codes.isEmpty()) { + response += "}"; + return response; + } + boolean first = true; + for (Map.Entry entry: codes.entrySet()) { + if (!first) { + response +=","; + } + response += entry.getKey() + ":" + "\"" + entry.getValue() + "\""; + first = false; + } + response += "}"; + return response; + } +}