From 044a23f27c7e82162c8e9705ba4f171d0f92ecc0 Mon Sep 17 00:00:00 2001 From: Zellweger Christof Ralf Date: Tue, 10 Nov 2015 14:47:34 +0100 Subject: [PATCH] ATEST-266: - adding a method for returning all dbmodes - temporary fix for ajax CORS call issue (see comment) --- .../controller/QueryRestController.java | 32 ++++++++++++------- .../psi/daq/queryrest/filter/CorsFilter.java | 5 +++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java b/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java index 0f4a938..60f5bd3 100644 --- a/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java +++ b/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java @@ -87,8 +87,7 @@ public class QueryRestController { } } - @RequestMapping(value = CHANNELS, method = {RequestMethod.GET, RequestMethod.POST}, - produces = {MediaType.APPLICATION_JSON_VALUE}) + @RequestMapping(value = CHANNELS, method = {RequestMethod.GET, RequestMethod.POST}, produces = {MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody Collection getChannels(@RequestBody(required = false) ChannelsRequest request) throws Throwable { // in case not specified use default (e.g. GET) @@ -113,8 +112,7 @@ public class QueryRestController { * @return Collection of channel names matching the specified input channel name * @throws Throwable in case something goes wrong */ - @RequestMapping(value = CHANNELS + "/{channelName}", method = {RequestMethod.GET}, - produces = {MediaType.APPLICATION_JSON_VALUE}) + @RequestMapping(value = CHANNELS + "/{channelName}", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody Collection getChannels(@PathVariable(value = "channelName") String channelName) throws Throwable { return getChannels(new ChannelsRequest(channelName)); @@ -126,8 +124,7 @@ public class QueryRestController { * * @return list of {@link Ordering}s as String array */ - @RequestMapping(value = "ordering", method = {RequestMethod.GET}, - produces = {MediaType.APPLICATION_JSON_VALUE}) + @RequestMapping(value = "ordering", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody List getOrderingValues() { List orderings = Lists.newArrayList(Ordering.values()); return orderings.stream() @@ -141,8 +138,7 @@ public class QueryRestController { * * @return list of {@link QueryField}s as String array */ - @RequestMapping(value = "queryfields", method = {RequestMethod.GET}, - produces = {MediaType.APPLICATION_JSON_VALUE}) + @RequestMapping(value = "queryfields", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody List getQueryFieldValues() { List orderings = Lists.newArrayList(QueryField.values()); return orderings.stream() @@ -156,8 +152,7 @@ public class QueryRestController { * * @return list of {@link Aggregation}s as String array */ - @RequestMapping(value = "aggregations", method = {RequestMethod.GET}, - produces = {MediaType.APPLICATION_JSON_VALUE}) + @RequestMapping(value = "aggregations", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody List getAggregationsValues() { List orderings = Lists.newArrayList(Aggregation.values()); return orderings.stream() @@ -171,8 +166,7 @@ public class QueryRestController { * * @return list of {@link AggregationType}s as String array */ - @RequestMapping(value = "aggregationtypes", method = {RequestMethod.GET}, - produces = {MediaType.APPLICATION_JSON_VALUE}) + @RequestMapping(value = "aggregationtypes", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE}) public @ResponseBody List getAggregationTypesValues() { List orderings = Lists.newArrayList(AggregationType.values()); return orderings.stream() @@ -180,6 +174,20 @@ public class QueryRestController { return value.toString(); }).collect(Collectors.toList()); } + + /** + * Returns the current list of {@link DBMode} values. + * + * @return list of {@link DBMode}s as String array + */ + @RequestMapping(value = "dbmodes", method = {RequestMethod.GET}, produces = {MediaType.APPLICATION_JSON_VALUE}) + public @ResponseBody List getDBModeValues() { + List orderings = Lists.newArrayList(DBMode.values()); + return orderings.stream() + .map((DBMode value) -> { + return value.toString(); + }).collect(Collectors.toList()); + } /** diff --git a/src/main/java/ch/psi/daq/queryrest/filter/CorsFilter.java b/src/main/java/ch/psi/daq/queryrest/filter/CorsFilter.java index 003b7d3..0afd969 100644 --- a/src/main/java/ch/psi/daq/queryrest/filter/CorsFilter.java +++ b/src/main/java/ch/psi/daq/queryrest/filter/CorsFilter.java @@ -61,6 +61,11 @@ public class CorsFilter extends OncePerRequestFilter { response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"); response.addHeader("Access-Control-Allow-Headers", "Origin, Authorization, Accept, Content-Type"); response.addHeader("Access-Control-Max-Age", "1800"); + + + // FIXME zellweger_c: remove me once https://github.com/PolymerElements/iron-ajax/pull/147 has been merged! + response.addHeader("Access-Control-Expose-Headers", "X-JSON-Prefix"); + }