Search in sources :

Example 1 with PointValueTimeJsonWriter

use of com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeJsonWriter in project ma-modules-public by infiniteautomation.

the class MultiPointStatisticsStreamTest method generateOutput.

/**
 * Generate a JsonNode from the query
 */
protected JsonNode generateOutput(ZonedDateTimeStatisticsQueryInfo info, Map<Integer, DataPointVO> voMap) throws QueryCancelledException, IOException {
    MultiPointStatisticsStream stream = new MultiPointStatisticsStream(info, voMap, Common.getBean(PointValueDao.class));
    JsonFactory factory = new JsonFactory();
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    JsonGenerator jgen = factory.createGenerator(output);
    PointValueTimeWriter writer = new PointValueTimeJsonWriter(stream.getQueryInfo(), jgen);
    stream.setContentType(StreamContentType.JSON);
    stream.start(writer);
    stream.streamData(writer);
    stream.finish(writer);
    jgen.flush();
    ObjectMapper mapper = new ObjectMapper();
    return mapper.readTree(output.toString(StandardCharsets.UTF_8.name()));
}
Also used : PointValueDao(com.serotonin.m2m2.db.dao.PointValueDao) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PointValueTimeWriter(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PointValueTimeJsonWriter(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeJsonWriter)

Example 2 with PointValueTimeJsonWriter

use of com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeJsonWriter in project ma-modules-public by infiniteautomation.

the class PointValueTimeStreamJsonSerializer method serialize.

@Override
public void serialize(PointValueTimeStream<T, INFO> value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
    PointValueTimeWriter writer = new PointValueTimeJsonWriter(value.getQueryInfo(), jgen);
    value.setContentType(StreamContentType.JSON);
    try {
        value.start(writer);
        value.streamData(writer);
        value.finish(writer);
        jgen.flush();
    } catch (QueryCancelledException e) {
        LOG.info("Query cancelled.", e);
    }
}
Also used : PointValueTimeWriter(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeWriter) QueryCancelledException(com.infiniteautomation.mango.db.query.QueryCancelledException) PointValueTimeJsonWriter(com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeJsonWriter)

Aggregations

PointValueTimeJsonWriter (com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeJsonWriter)2 PointValueTimeWriter (com.infiniteautomation.mango.rest.latest.model.pointValue.PointValueTimeWriter)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 QueryCancelledException (com.infiniteautomation.mango.db.query.QueryCancelledException)1 PointValueDao (com.serotonin.m2m2.db.dao.PointValueDao)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1