ATEST-633
This commit is contained in:
@ -81,6 +81,8 @@ public class JSONTableResponseStreamWriter implements ResponseStreamWriter {
|
||||
@Resource(name = QueryRestConfig.BEAN_NAME_DEFAULT_RESPONSE_AGGREGATIONS)
|
||||
private Set<Aggregation> defaultResponseAggregations;
|
||||
|
||||
// In case ArchiverAppliance had several events within the 10ms mapping interval, return these
|
||||
// aggregations
|
||||
private Set<String> defaultResponseAggregationsStr;
|
||||
|
||||
@PostConstruct
|
||||
@ -92,7 +94,7 @@ public class JSONTableResponseStreamWriter implements ResponseStreamWriter {
|
||||
|
||||
@Override
|
||||
public void respond(final List<Entry<DAQQueryElement, Stream<Triple<BackendQuery, ChannelName, ?>>>> results,
|
||||
final OutputStream out, final Response response) throws Exception {
|
||||
final OutputStream out, final Response response) throws Exception {
|
||||
respond(context, jsonFactory, mapper, defaultResponseAggregationsStr, results, out, response);
|
||||
}
|
||||
|
||||
@ -103,7 +105,7 @@ public class JSONTableResponseStreamWriter implements ResponseStreamWriter {
|
||||
final OutputStream out, final Response response) throws Exception {
|
||||
AtomicReference<Exception> exception = new AtomicReference<>();
|
||||
JsonGenerator generator = factory.createGenerator(out, JsonEncoding.UTF8);
|
||||
|
||||
|
||||
try {
|
||||
if (results.size() > 1) {
|
||||
generator.writeStartArray();
|
||||
@ -116,7 +118,9 @@ public class JSONTableResponseStreamWriter implements ResponseStreamWriter {
|
||||
/* make sure identifiers are available */
|
||||
includedFields.add(QueryField.channel.name());
|
||||
includedFields.add(QueryField.backend.name());
|
||||
includedFields.addAll(defaultResponseAggregationsStr);
|
||||
if (!containsAggregation(includedFields)) {
|
||||
includedFields.addAll(defaultResponseAggregationsStr);
|
||||
}
|
||||
|
||||
ObjectWriter writer = JSONResponseStreamWriter.configureWriter(includedFields, mapper);
|
||||
|
||||
@ -211,4 +215,13 @@ public class JSONTableResponseStreamWriter implements ResponseStreamWriter {
|
||||
throw exception.get();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean containsAggregation(Set<String> includedFields) {
|
||||
for (Aggregation aggregation : Aggregation.values()) {
|
||||
if (includedFields.contains(aggregation.name())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -145,6 +145,72 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1].iocMillis").value(1010));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPulseRangeQuery_NrOfBins() throws Exception {
|
||||
DAQQuery request = new DAQQuery(
|
||||
new RequestRangePulseId(
|
||||
100,
|
||||
101),
|
||||
TEST_CHANNEL_NAMES);
|
||||
request.setMapping(new Mapping());
|
||||
request.addField(QueryField.pulseId);
|
||||
request.addField(QueryField.globalSeconds);
|
||||
request.addField(QueryField.globalMillis);
|
||||
request.addField(QueryField.iocSeconds);
|
||||
request.addField(QueryField.iocMillis);
|
||||
request.addField(QueryField.value);
|
||||
|
||||
AggregationDescriptor aggregation = new AggregationDescriptor(AggregationType.value);
|
||||
aggregation.setNrOfBins(1);
|
||||
aggregation.setAggregations(Arrays.asList(Aggregation.mean));
|
||||
request.setAggregation(aggregation);
|
||||
|
||||
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.SF_DATABUFFER.getKey()))
|
||||
.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][0].value.mean").value(100.5))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].value.min").doesNotExist())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][0].value.max").doesNotExist())
|
||||
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1]").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1]").isMap())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].channel").value(TEST_CHANNEL_02))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].backend").value(Backend.SF_DATABUFFER.getKey()))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].pulseId").value(100))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].globalSeconds").value(
|
||||
TestTimeUtils.getTimeStr(1, 0)))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].globalMillis").value(1000))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].iocSeconds").value(
|
||||
TestTimeUtils.getTimeStr(1, 0)))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].iocMillis").value(1000))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].value.mean").value(100.5))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].value.min").doesNotExist())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].value.max").doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPulseRangeQuery_ChannelOrder() throws Exception {
|
||||
DAQQuery request = new DAQQuery(
|
||||
@ -369,7 +435,8 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1]").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1]").isMap())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].channel").value(TEST_CHANNEL_02))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].backend").value(Backend.SF_ARCHIVERAPPLIANCE.getKey()))
|
||||
.andExpect(
|
||||
MockMvcResultMatchers.jsonPath("$.data[0][1].backend").value(Backend.SF_ARCHIVERAPPLIANCE.getKey()))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].pulseId").value(100))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[0][1].globalSeconds").value(
|
||||
TestTimeUtils.getTimeStr(1, 0)))
|
||||
@ -385,7 +452,8 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1]").exists())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1]").isMap())
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1].channel").value(TEST_CHANNEL_02))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1].backend").value(Backend.SF_ARCHIVERAPPLIANCE.getKey()))
|
||||
.andExpect(
|
||||
MockMvcResultMatchers.jsonPath("$.data[1][1].backend").value(Backend.SF_ARCHIVERAPPLIANCE.getKey()))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1].pulseId").value(101))
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[1][1].globalSeconds").value(
|
||||
TestTimeUtils.getTimeStr(1, 10000000)));
|
||||
@ -1929,7 +1997,7 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[7]").doesNotExist());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testPulseRangeQuery_Match_KeepAsIs_Combine_Waveform() throws Exception {
|
||||
Map<String, Set<Long>> channelSeq = new HashMap<>();
|
||||
@ -2141,7 +2209,7 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
.andExpect(MockMvcResultMatchers.jsonPath("$.data[7]").doesNotExist());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testValueTransformation_01() throws Exception {
|
||||
String channelName = "TestImage";
|
||||
@ -2159,9 +2227,9 @@ public class JsonQueryRestControllerTableTest extends AbstractDaqRestTest {
|
||||
request.setValueTransformation(
|
||||
new ValueTransformationSequence(
|
||||
new ImageDownScaleValueTransformation(8, Color.BLUE, Color.RED),
|
||||
new ImageEncodingValueTransformation(
|
||||
ImageFormat.PNG,
|
||||
new Base64ImageEncoder(StandardCharsets.UTF_8, true, false))));
|
||||
new ImageEncodingValueTransformation(
|
||||
ImageFormat.PNG,
|
||||
new Base64ImageEncoder(StandardCharsets.UTF_8, true, false))));
|
||||
|
||||
String content = mapper.writeValueAsString(request);
|
||||
System.out.println(content);
|
||||
|
Reference in New Issue
Block a user