diff --git a/src/main/java/ch/psi/daq/queryrest/response/csv/CSVResponseStreamWriter.java b/src/main/java/ch/psi/daq/queryrest/response/csv/CSVResponseStreamWriter.java index 951e08c..5b710bf 100644 --- a/src/main/java/ch/psi/daq/queryrest/response/csv/CSVResponseStreamWriter.java +++ b/src/main/java/ch/psi/daq/queryrest/response/csv/CSVResponseStreamWriter.java @@ -88,9 +88,9 @@ public class CSVResponseStreamWriter implements ResponseStreamWriter, Applicatio @SuppressWarnings("unchecked") @Override public void respond( - final Object query, + final Object query, final R result, - final OutputStream out, + final OutputStream out, final AbstractHTTPResponse response, final ResponseFormatter formatter) throws Exception { if (query instanceof DAQQueries) { @@ -152,6 +152,7 @@ public class CSVResponseStreamWriter implements ResponseStreamWriter, Applicatio new MapFiller<>(), null, padder, + streams.keySet(), streams.values()); final Iterator> streamsMatchIter = streamMatcher.iterator(); diff --git a/src/main/java/ch/psi/daq/queryrest/response/formatter/DAQQueriesResponseFormatter.java b/src/main/java/ch/psi/daq/queryrest/response/formatter/DAQQueriesResponseFormatter.java index eebc97f..f148a26 100644 --- a/src/main/java/ch/psi/daq/queryrest/response/formatter/DAQQueriesResponseFormatter.java +++ b/src/main/java/ch/psi/daq/queryrest/response/formatter/DAQQueriesResponseFormatter.java @@ -233,6 +233,7 @@ public class DAQQueriesResponseFormatter implements ResponseFormatter(), new BinnedValueCombiner(binningStrategy), padder, + streams.keySet(), streams.values()); final Iterator> streamsMatchIter = streamMatcher.iterator(); diff --git a/src/test/java/ch/psi/daq/test/queryrest/controller/JsonQueryRestControllerTableTest.java b/src/test/java/ch/psi/daq/test/queryrest/controller/JsonQueryRestControllerTableTest.java index 4a0368f..f47ea7e 100644 --- a/src/test/java/ch/psi/daq/test/queryrest/controller/JsonQueryRestControllerTableTest.java +++ b/src/test/java/ch/psi/daq/test/queryrest/controller/JsonQueryRestControllerTableTest.java @@ -54,6 +54,7 @@ import ch.psi.daq.domain.request.range.RequestRangeDate; import ch.psi.daq.domain.request.range.RequestRangePulseId; import ch.psi.daq.domain.request.range.RequestRangeTime; import ch.psi.daq.domain.test.TestTimeUtils; +import ch.psi.daq.domain.test.reader.TestReader; import ch.psi.daq.test.queryrest.AbstractDaqRestTest; /** @@ -163,6 +164,88 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest implem .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1].iocMillis").value(1010)); } + @Test + public void testPulseRangeQuery_FillNull_NotExists() throws Exception { + final String[] TEST_CHANNEL_NAMES = + new String[] {TEST_CHANNEL_01, TestReader.DOES_NOT_EXIST_CHANNEL, TEST_CHANNEL_02}; + DAQQuery request = new DAQQuery( + new RequestRangePulseId( + 100, + 101), + TEST_CHANNEL_NAMES); + request.setMapping(new Mapping(IncompleteStrategy.FILL_NULL)); + request.addField(EventField.pulseId); + request.addField(EventField.globalSeconds); + request.addField(EventField.globalMillis); + request.addField(EventField.iocSeconds); + request.addField(EventField.iocMillis); + + String content = mapper.writeValueAsString(request); + System.out.println(content); + + this.mockMvc + .perform(MockMvcRequestBuilders + .post(DomainConfig.PATH_QUERY) + .contentType(MediaType.APPLICATION_JSON) + .content(content)) + + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.data").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0]").isArray()) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].backend").value(backend.getName())) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].globalMillis").value(1000)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].iocMillis").value(1000)) + + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][2]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][2].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][2].backend").value(backend.getName())) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][2].pulseId").value(100)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][2].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][2].globalMillis").value(1000)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][2].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 0))) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[0][2].iocMillis").value(1000)) + + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][0]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][0]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][0].channel").value(TEST_CHANNEL_01)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][0].backend").value(backend.getName())) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][0].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][0].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][0].globalMillis").value(1010)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][0].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][0].iocMillis").value(1010)) + + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1]").doesNotExist()) + + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][2]").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][2]").isMap()) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][2].channel").value(TEST_CHANNEL_02)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][2].backend").value(backend.getName())) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][2].pulseId").value(101)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][2].globalSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][2].globalMillis").value(1010)) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][2].iocSeconds").value( + TestTimeUtils.getTimeStr(1, 10000000))) + .andExpect(MockMvcResultMatchers.jsonPath("$.data[1][2].iocMillis").value(1010)); + } @Test public void testPulseRangeQuery_NrOfBins() throws Exception {