diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 38cfd99..2dc7c06 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,5 @@ # -#Wed Sep 16 07:23:26 CEST 2015 +#Thu Oct 29 09:13:22 CET 2015 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 eebc710..9346d2f 100644 --- a/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java +++ b/src/main/java/ch/psi/daq/queryrest/config/QueryRestConfig.java @@ -30,7 +30,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; 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; @@ -39,7 +38,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.model.PropertyFilterMixin; import ch.psi.daq.queryrest.response.JsonByteArraySerializer; @@ -77,15 +75,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 @@ -95,7 +84,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 ab518a7..0fa945e 100644 --- a/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java +++ b/src/main/java/ch/psi/daq/queryrest/controller/QueryRestController.java @@ -33,10 +33,10 @@ import ch.psi.daq.query.model.Aggregation; 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; @RestController @@ -117,17 +117,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()); @@ -139,7 +139,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/DaqRestControllerTest.java b/src/test/java/ch/psi/daq/test/queryrest/controller/DaqRestControllerTest.java index 3c0ac75..5b888ec 100644 --- a/src/test/java/ch/psi/daq/test/queryrest/controller/DaqRestControllerTest.java +++ b/src/test/java/ch/psi/daq/test/queryrest/controller/DaqRestControllerTest.java @@ -10,12 +10,14 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +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.Query; +import ch.psi.daq.query.model.impl.DAQQuery; import ch.psi.daq.queryrest.controller.QueryRestController; import ch.psi.daq.test.cassandra.admin.CassandraTestAdmin; import ch.psi.daq.test.queryrest.AbstractDaqRestTest; @@ -24,18 +26,18 @@ import ch.psi.daq.test.queryrest.AbstractDaqRestTest; * Tests the {@link DaqController} implementation. */ public class DaqRestControllerTest extends AbstractDaqRestTest { - + @Resource private CassandraTestAdmin cassandraTestAdmin; @Resource private CassandraDataGen dataGen; - + private static final boolean initialized = false; - + private static final int DATA_KEYSPACE = 1; - public static final String[] TEST_CHANNEL_NAMES = new String[]{"testChannel1", "testChannel2"}; - + public static final String[] TEST_CHANNEL_NAMES = new String[] {"testChannel1", "testChannel2"}; + @Before public void setUp() throws Exception { if (!initialized) { @@ -50,9 +52,9 @@ public class DaqRestControllerTest extends AbstractDaqRestTest { @Test public void testChannelNameQuery() throws Exception { - + this.mockMvc.perform( - MockMvcRequestBuilders + MockMvcRequestBuilders .get(QueryRestController.CHANNELS) .contentType(MediaType.APPLICATION_JSON)) .andDo(MockMvcResultHandlers.print()) @@ -64,19 +66,20 @@ public class DaqRestControllerTest extends AbstractDaqRestTest { .andExpect(MockMvcResultMatchers.jsonPath("$[1]").value("testChannel2")) .andExpect(MockMvcResultMatchers.jsonPath("$[2]").doesNotExist()); } - + @Test public void testPulseRangeQuery() throws Exception { - PulseRangeQuery request = new PulseRangeQuery( - 100, - 101, + Query 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) @@ -100,17 +103,18 @@ public class DaqRestControllerTest extends AbstractDaqRestTest { @Test public void testTimeRangeQuery() throws Exception { - TimeRangeQuery request = new TimeRangeQuery( - 100, - 101, + Query request = new DAQQuery( + new RequestRangeTime( + 100, + 101), TEST_CHANNEL_NAMES); String content = mapper.writeValueAsString(request); this.mockMvc.perform(MockMvcRequestBuilders - .post(QueryRestController.QUERY) - .contentType(MediaType.APPLICATION_JSON) - .content(content)) + .post(QueryRestController.QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().isOk()) @@ -129,11 +133,12 @@ public class DaqRestControllerTest 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); + Query request = new DAQQuery( + new RequestRangeDate( + startDate, + endDate), TEST_CHANNEL_NAMES); String content = mapper.writeValueAsString(request); @@ -142,9 +147,9 @@ public class DaqRestControllerTest extends AbstractDaqRestTest { this.mockMvc .perform( MockMvcRequestBuilders - .post(QueryRestController.QUERY) - .contentType(MediaType.APPLICATION_JSON) - .content(content) + .post(QueryRestController.QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content) ) .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().isOk()) @@ -160,12 +165,13 @@ public class DaqRestControllerTest extends AbstractDaqRestTest { .andExpect(MockMvcResultMatchers.jsonPath("$[1].data[0].pulseId").value(100)) .andExpect(MockMvcResultMatchers.jsonPath("$[1].data[1].pulseId").value(101)); } - + @Test public void testExtremaAggregation() throws Exception { - PulseRangeQuery request = new PulseRangeQuery( - 100, - 101, + Query request = new DAQQuery( + new RequestRangePulseId( + 100, + 101), false, Ordering.asc, AggregationType.extrema, @@ -180,7 +186,7 @@ public class DaqRestControllerTest extends AbstractDaqRestTest { .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().isOk()) - + .andExpect(MockMvcResultMatchers.jsonPath("$").exists()) .andExpect(MockMvcResultMatchers.jsonPath("$.minima").exists()) .andExpect(MockMvcResultMatchers.jsonPath("$.minima.min").exists())