ATEST-246
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user