diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 5b5155d..2ed8f44 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,9 @@ # +<<<<<<< HEAD +#Thu Oct 29 09:13:22 CET 2015 +======= #Wed Oct 28 12:53:12 CET 2015 +>>>>>>> refs/heads/master org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve diff --git a/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java b/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java index 78eaf75..fd712db 100644 --- a/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java +++ b/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java @@ -26,7 +26,6 @@ import org.springframework.validation.Validator; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import ch.psi.daq.cassandra.util.test.CassandraDataGen; -import ch.psi.daq.common.json.deserialize.AttributeBasedDeserializer; import ch.psi.daq.common.statistic.StorelessStatistics; import ch.psi.daq.domain.DataEvent; import ch.psi.daq.query.analyzer.QueryAnalyzer; @@ -35,7 +34,6 @@ import ch.psi.daq.query.config.QueryConfig; import ch.psi.daq.query.model.Aggregation; import ch.psi.daq.query.model.Query; import ch.psi.daq.query.model.QueryField; -import ch.psi.daq.query.model.impl.AbstractQuery; import ch.psi.daq.queryrest.controller.validator.QueryValidator; import ch.psi.daq.queryrest.filter.CorsFilter; import ch.psi.daq.queryrest.model.PropertyFilterMixin; @@ -80,15 +78,6 @@ public class QueryRestConfig extends WebMvcConfigurerAdapter { @PostConstruct public void afterPropertiesSet() { - // add deserializers to ObjectMapper - String packageName = AbstractQuery.class.getPackage().getName(); - Class abstractQueryClass = AbstractQuery.class; - AttributeBasedDeserializer abstractQueryDeserializer = - new AttributeBasedDeserializer(abstractQueryClass).register(packageName); - SimpleModule module = new SimpleModule("PolymorphicAbstractQuery", Version.unknownVersion()); - module.addDeserializer(abstractQueryClass, abstractQueryDeserializer); - objectMapper.registerModule(module); - // only include non-null values objectMapper.setSerializationInclusion(Include.NON_NULL); // Mixin which is used dynamically to filter out which properties get serialised and which @@ -98,7 +87,7 @@ public class QueryRestConfig extends WebMvcConfigurerAdapter { objectMapper.addMixIn(EnumMap.class, PropertyFilterMixin.class); // defines how to writer inner Streams (i.e. Stream>> toSerialize) - module = new SimpleModule("Streams API", Version.unknownVersion()); + SimpleModule module = new SimpleModule("Streams API", Version.unknownVersion()); module.addSerializer(new JsonStreamSerializer()); objectMapper.registerModule(module); 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 4abb185..0f4a938 100644 --- a/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java +++ b/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java @@ -37,10 +37,10 @@ import ch.psi.daq.query.model.AggregationType; import ch.psi.daq.query.model.DBMode; import ch.psi.daq.query.model.Query; import ch.psi.daq.query.model.QueryField; -import ch.psi.daq.query.model.impl.AbstractQuery; +import ch.psi.daq.query.model.impl.DAQQuery; import ch.psi.daq.query.processor.QueryProcessor; +import ch.psi.daq.query.request.ChannelsRequest; import ch.psi.daq.queryrest.config.QueryRestConfig; -import ch.psi.daq.queryrest.model.ChannelsRequest; import ch.psi.daq.queryrest.response.ResponseStreamWriter; import com.google.common.collect.Lists; @@ -185,17 +185,17 @@ public class QueryRestController { /** * Catch-all query method for getting data from the backend. *

- * The {@link AbstractQuery} object will be a concrete subclass based on the combination of + * The {@link DAQQuery} object will be a concrete subclass based on the combination of * fields defined in the user's query. The {@link AttributeBasedDeserializer} decides which class * to deserialize the information into and has been configured (see * QueryRestConfig#afterPropertiesSet) accordingly. * - * @param query concrete implementation of {@link AbstractQuery} + * @param query concrete implementation of {@link DAQQuery} * @param res the {@link HttpServletResponse} instance associated with this request * @throws IOException thrown if writing to the output stream fails */ @RequestMapping(value = QUERY, method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE}) - public void executeQuery(@RequestBody @Valid AbstractQuery query, HttpServletResponse res) throws IOException { + public void executeQuery(@RequestBody @Valid DAQQuery query, HttpServletResponse res) throws IOException { try { LOGGER.debug("Executing query '{}'", query.toString()); @@ -207,7 +207,7 @@ public class QueryRestController { } } - public Stream> executeQuery(AbstractQuery query) { + public Stream> executeQuery(DAQQuery query) { QueryAnalyzer queryAnalizer = queryAnalizerFactory.apply(query); // all the magic happens here diff --git a/src/main/java/ch/psi/daq/queryrest/controller/validator/QueryValidator.java b/src/main/java/ch/psi/daq/queryrest/controller/validator/QueryValidator.java index a280239..ad8b75e 100644 --- a/src/main/java/ch/psi/daq/queryrest/controller/validator/QueryValidator.java +++ b/src/main/java/ch/psi/daq/queryrest/controller/validator/QueryValidator.java @@ -12,7 +12,7 @@ import org.springframework.validation.Validator; import ch.psi.daq.query.model.Aggregation; import ch.psi.daq.query.model.DBMode; import ch.psi.daq.query.model.QueryField; -import ch.psi.daq.query.model.impl.AbstractQuery; +import ch.psi.daq.query.model.impl.DAQQuery; import ch.psi.daq.cassandra.request.Request; import ch.psi.daq.cassandra.request.range.RequestRangeTime; import ch.psi.daq.queryrest.config.QueryRestConfig; @@ -30,7 +30,7 @@ public class QueryValidator implements Validator { */ @Override public boolean supports(Class clazz) { - return AbstractQuery.class.isAssignableFrom(clazz); + return DAQQuery.class.isAssignableFrom(clazz); } /** @@ -39,7 +39,7 @@ public class QueryValidator implements Validator { @Override public void validate(Object target, Errors errors) { - AbstractQuery query = (AbstractQuery) target; + DAQQuery query = (DAQQuery) target; Request request = query.getRequest(); diff --git a/src/main/java/ch/psi/daq/queryrest/model/ChannelsRequest.java b/src/main/java/ch/psi/daq/queryrest/model/ChannelsRequest.java deleted file mode 100644 index d9b56a0..0000000 --- a/src/main/java/ch/psi/daq/queryrest/model/ChannelsRequest.java +++ /dev/null @@ -1,41 +0,0 @@ -package ch.psi.daq.queryrest.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; - -import ch.psi.daq.query.model.DBMode; - -// as RequestBody due to special chars in regex -@JsonInclude(Include.NON_DEFAULT) -public class ChannelsRequest { - private DBMode dbMode = DBMode.databuffer; - // null for no regex - private String regex = null; - - public ChannelsRequest() {} - - public ChannelsRequest(String regex) { - this(DBMode.databuffer, regex); - } - - public ChannelsRequest(DBMode dbMode, String regex) { - this.regex = regex; - this.dbMode = dbMode; - } - - public DBMode getDbMode() { - return dbMode; - } - - public void setDbMode(DBMode dbMode) { - this.dbMode = dbMode; - } - - public String getRegex() { - return regex; - } - - public void setRegex(String regex) { - this.regex = regex; - } -} diff --git a/src/main/java/ch/psi/daq/queryrest/response/ResponseStreamWriter.java b/src/main/java/ch/psi/daq/queryrest/response/ResponseStreamWriter.java index e5c5483..de4e91d 100644 --- a/src/main/java/ch/psi/daq/queryrest/response/ResponseStreamWriter.java +++ b/src/main/java/ch/psi/daq/queryrest/response/ResponseStreamWriter.java @@ -24,7 +24,7 @@ import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; import ch.psi.daq.query.model.Aggregation; import ch.psi.daq.query.model.QueryField; -import ch.psi.daq.query.model.impl.AbstractQuery; +import ch.psi.daq.query.model.impl.DAQQuery; /** * Takes a Java 8 stream and writes it to the output stream provided by the {@link ServletResponse} @@ -45,11 +45,11 @@ public class ResponseStreamWriter { * {@link ServletResponse}. * * @param stream Mapping from channel name to data - * @param query concrete instance of {@link AbstractQuery} + * @param query concrete instance of {@link DAQQuery} * @param response {@link ServletResponse} instance given by the current HTTP request * @throws IOException thrown if writing to the output stream fails */ - public void respond(Stream> stream, AbstractQuery query, + public void respond(Stream> stream, DAQQuery query, ServletResponse response) throws IOException { Set queryFields = query.getFields(); diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index d96482a..f33cac2 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -2,7 +2,7 @@ - .%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %n + .%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %n diff --git a/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerTest.java b/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerTest.java index 03c91d5..9c667fe 100644 --- a/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerTest.java +++ b/src/test/java/ch/psi/daq/test/queryrest/controller/QueryRestControllerTest.java @@ -10,12 +10,13 @@ import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import ch.psi.daq.cassandra.request.range.RequestRangeDate; +import ch.psi.daq.cassandra.request.range.RequestRangePulseId; +import ch.psi.daq.cassandra.request.range.RequestRangeTime; import ch.psi.daq.cassandra.util.test.CassandraDataGen; import ch.psi.daq.common.ordering.Ordering; import ch.psi.daq.query.model.AggregationType; -import ch.psi.daq.query.model.impl.PulseRangeQuery; -import ch.psi.daq.query.model.impl.TimeRangeQuery; -import ch.psi.daq.query.model.impl.TimeRangeQueryDate; +import ch.psi.daq.query.model.impl.DAQQuery; import ch.psi.daq.queryrest.controller.QueryRestController; import ch.psi.daq.queryrest.filter.CorsFilter; import ch.psi.daq.test.cassandra.admin.CassandraTestAdmin; @@ -161,16 +162,15 @@ public class QueryRestControllerTest extends AbstractDaqRestTest { @Test public void testPulseRangeQuery() throws Exception { - PulseRangeQuery request = new PulseRangeQuery( - 100, - 101, + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + 100, + 101), TEST_CHANNEL_NAMES); String content = mapper.writeValueAsString(request); System.out.println(content); - content = "{\"channels\":[\"testChannel1\",\"testChannel2\"],\"startPulseId\":100,\"endPulseId\":101}"; - this.mockMvc .perform(MockMvcRequestBuilders .post(QueryRestController.QUERY) @@ -194,9 +194,10 @@ public class QueryRestControllerTest extends AbstractDaqRestTest { @Test public void testTimeRangeQuery() throws Exception { - TimeRangeQuery request = new TimeRangeQuery( - 100, - 101, + DAQQuery request = new DAQQuery( + new RequestRangeTime( + 100, + 101), TEST_CHANNEL_NAMES); String content = mapper.writeValueAsString(request); @@ -223,11 +224,12 @@ public class QueryRestControllerTest extends AbstractDaqRestTest { @Test public void testDateRangeQuery() throws Exception { - String startDate = TimeRangeQueryDate.format(100); - String endDate = TimeRangeQueryDate.format(101); - TimeRangeQueryDate request = new TimeRangeQueryDate( - startDate, - endDate, + String startDate = RequestRangeDate.format(100); + String endDate = RequestRangeDate.format(101); + DAQQuery request = new DAQQuery( + new RequestRangeDate( + startDate, + endDate), TEST_CHANNEL_NAMES); String content = mapper.writeValueAsString(request); @@ -257,9 +259,10 @@ public class QueryRestControllerTest extends AbstractDaqRestTest { @Test public void testExtremaAggregation() throws Exception { - PulseRangeQuery request = new PulseRangeQuery( - 100, - 101, + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + 100, + 101), false, Ordering.asc, AggregationType.extrema,