ATEST-246
This commit is contained in:
@ -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
|
||||
|
@ -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<AbstractQuery> abstractQueryClass = AbstractQuery.class;
|
||||
AttributeBasedDeserializer<AbstractQuery> abstractQueryDeserializer =
|
||||
new AttributeBasedDeserializer<AbstractQuery>(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<Entry<String, Stream<?>>> toSerialize)
|
||||
module = new SimpleModule("Streams API", Version.unknownVersion());
|
||||
SimpleModule module = new SimpleModule("Streams API", Version.unknownVersion());
|
||||
module.addSerializer(new JsonStreamSerializer());
|
||||
objectMapper.registerModule(module);
|
||||
|
||||
|
@ -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.
|
||||
* <p>
|
||||
* 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<Entry<String, ?>> executeQuery(AbstractQuery query) {
|
||||
public Stream<Entry<String, ?>> executeQuery(DAQQuery query) {
|
||||
QueryAnalyzer queryAnalizer = queryAnalizerFactory.apply(query);
|
||||
|
||||
// all the magic happens here
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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<Entry<String, ?>> stream, AbstractQuery query,
|
||||
public void respond(Stream<Entry<String, ?>> stream, DAQQuery query,
|
||||
ServletResponse response) throws IOException {
|
||||
|
||||
Set<QueryField> queryFields = query.getFields();
|
||||
|
@ -2,7 +2,7 @@
|
||||
<configuration>
|
||||
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<Pattern>.%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %n
|
||||
<Pattern>.%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %n
|
||||
</Pattern>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
|
@ -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())
|
||||
|
Reference in New Issue
Block a user