Use new query structure.
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package ch.psi.daq.queryrest.response;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.servlet.ServletResponse;
|
||||
@@ -24,6 +21,7 @@ import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
|
||||
|
||||
import ch.psi.daq.domain.cassandra.DataEvent;
|
||||
import ch.psi.daq.query.model.AbstractQuery;
|
||||
import ch.psi.daq.query.model.AggregationEnum;
|
||||
|
||||
/**
|
||||
* Takes a Java 8 stream and writes it to the output stream provided by the {@link ServletResponse}
|
||||
@@ -41,6 +39,7 @@ public class ResponseStreamWriter {
|
||||
|
||||
@Autowired
|
||||
private Set<String> defaultResponseFields;
|
||||
|
||||
/**
|
||||
* Responding with the the contents of the stream by writing into the output stream of the
|
||||
* {@link ServletResponse}.
|
||||
@@ -52,17 +51,13 @@ public class ResponseStreamWriter {
|
||||
*/
|
||||
public void respond(Stream<DataEvent> stream, AbstractQuery query, ServletResponse response) throws IOException {
|
||||
|
||||
Set<String> includedFields = query.getFields();
|
||||
if (includedFields == null) {
|
||||
includedFields = defaultResponseFields;
|
||||
}
|
||||
Set<String> includedFields = query.getFieldsOrDefault(defaultResponseFields);
|
||||
|
||||
if (query.getAggregations() != null) {
|
||||
includedFields.addAll(query.getAggregations()
|
||||
.stream()
|
||||
.map(a -> {
|
||||
return a.getType().toString();
|
||||
}).collect(Collectors.toSet()));
|
||||
includedFields = new LinkedHashSet<String>(includedFields);
|
||||
for (AggregationEnum aggregation : query.getAggregations()) {
|
||||
includedFields.add(aggregation.name());
|
||||
}
|
||||
}
|
||||
ObjectWriter writer = configureWriter(includedFields);
|
||||
respondInternal(stream, response, writer);
|
||||
|
||||
Reference in New Issue
Block a user