ATEST-79:

- implementing first draft of timerange and pulserange queries
- adding tests, again based on an embedded local cassandra instance
This commit is contained in:
Zellweger Christof Ralf
2015-06-19 15:14:54 +02:00
parent aaaf5a72fe
commit c1098a398f
17 changed files with 589 additions and 167 deletions

View File

@ -0,0 +1,80 @@
package ch.psi.daq.rest;
import java.io.IOException;
import java.util.Map;
import java.util.stream.Stream;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ch.psi.daq.domain.cassandra.DataEvent;
import ch.psi.daq.hazelcast.common.query.processor.QueryProcessor;
import ch.psi.daq.rest.queries.AbstractQuery;
import ch.psi.daq.rest.queries.PulseRangeQuery;
import ch.psi.daq.rest.queries.TimeRangeQuery;
@RestController
public class DaqRestController {
private static final Logger logger = LoggerFactory.getLogger(DaqRestController.class);
@Autowired
private ResponseStreamWriter responseStreamWriter;
// TODO: just a dummy test implementation - remove when the real processor is ready
@Autowired
private QueryProcessor queryProcessor;
/**
*
* @param query
* @param res
* @throws IOException
*/
@RequestMapping(value = "/pulserange")
public void pulseRange(@RequestBody PulseRangeQuery query, HttpServletResponse res) throws IOException {
logger.debug("PulseRangeQuery received: {}", query);
executeQuery(query, res);
}
/**
*
* @param query
* @param res
* @throws IOException
*/
@RequestMapping(value = "/timerange")
public void pulseRange(@RequestBody TimeRangeQuery query, HttpServletResponse res) throws IOException {
logger.debug("TimeRangeQuery received: {}", query);
executeQuery(query, res);
}
/**
*
* @param query
* @param res
* @throws IOException
*/
private void executeQuery(AbstractQuery query, HttpServletResponse res) throws IOException {
// all the magic happens here
Map<String, Stream<? extends DataEvent>> process = queryProcessor.process(query);
Stream<DataEvent> flatStreams = process.values().stream().flatMap(s -> {
return s;
});
// write the response back to the client using java 8 streams
responseStreamWriter.respond(flatStreams, query, res);
}
}