Search in sources :

Example 1 with RollupEnum

use of com.serotonin.m2m2.web.mvc.rest.v1.model.time.RollupEnum in project ma-modules-public by infiniteautomation.

the class PointValueRestController method count.

@ApiOperation(value = "Count point values in a Time Range", notes = "From time inclusive, To time exclusive", response = PointValueTimeModel.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET, value = "/{xid}/count", produces = { "application/json" })
public ResponseEntity<Long> count(HttpServletRequest request, @ApiParam(value = "Point xid", required = true, allowMultiple = false) @PathVariable String xid, @ApiParam(value = "From time", required = false, allowMultiple = false) @RequestParam(value = "from", required = false) // Not working yet@DateTimeFormat(pattern = "${rest.customDateInputFormat}") Date from,
@DateTimeFormat(iso = ISO.DATE_TIME) DateTime from, @ApiParam(value = "To time", required = false, allowMultiple = false) @RequestParam(value = "to", required = false) // Not working yet@DateTimeFormat(pattern = "${rest.customDateInputFormat}") Date to,
@DateTimeFormat(iso = ISO.DATE_TIME) DateTime to, @ApiParam(value = "Rollup type", required = false, allowMultiple = false) @RequestParam(value = "rollup", required = false) RollupEnum rollup, @ApiParam(value = "Time Period Type", required = false, allowMultiple = false) @RequestParam(value = "timePeriodType", required = false) TimePeriodType timePeriodType, @ApiParam(value = "Time Periods", required = false, allowMultiple = false) @RequestParam(value = "timePeriods", required = false) Integer timePeriods, @ApiParam(value = "Time zone", required = false, allowMultiple = false) @RequestParam(value = "timezone", required = false) String timezone) {
    RestProcessResult<Long> result = new RestProcessResult<Long>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        if (timezone != null) {
            try {
                ZoneId.of(timezone);
            } catch (Exception e) {
                RestValidationResult vr = new RestValidationResult();
                vr.addError("validate.invalidValue", "timezone");
                throw new ValidationFailedRestException(vr);
            }
        }
        DataPointVO vo = DataPointDao.instance.getByXid(xid);
        if (vo == null) {
            result.addRestMessage(getDoesNotExistMessage());
            return result.createResponseEntity();
        }
        try {
            if (Permissions.hasDataPointReadPermission(user, vo)) {
                long current = Common.timer.currentTimeMillis();
                if (from == null)
                    from = new DateTime(current);
                if (to == null)
                    to = new DateTime(current);
                // better not to for RESTfulness
                if (timezone != null) {
                    DateTimeZone zone = DateTimeZone.forID(timezone);
                    from = from.withZone(zone);
                    to = to.withZone(zone);
                }
                // Are we using rollup
                if ((rollup != null) && (rollup != RollupEnum.NONE)) {
                    // First check to see if there are any values in the range
                    long pointValueCount = Common.databaseProxy.newPointValueDao().dateRangeCount(vo.getId(), from.getMillis(), to.getMillis());
                    if (pointValueCount == 0)
                        return result.createResponseEntity(pointValueCount);
                    long count = new Long(0);
                    TimePeriodBucketCalculator calc = new TimePeriodBucketCalculator(from, to, TimePeriodType.convertFrom(timePeriodType), timePeriods);
                    while (calc.getNextPeriodTo().isBefore(calc.getEndTime())) {
                        count++;
                    }
                    return result.createResponseEntity(count);
                } else {
                    long count = Common.databaseProxy.newPointValueDao().dateRangeCount(vo.getId(), from.getMillis(), to.getMillis());
                    return result.createResponseEntity(count);
                }
            } else {
                result.addRestMessage(getUnauthorizedMessage());
                return result.createResponseEntity();
            }
        } catch (PermissionException e) {
            LOG.error(e.getMessage(), e);
            result.addRestMessage(getUnauthorizedMessage());
            return result.createResponseEntity();
        }
    } else {
        return result.createResponseEntity();
    }
}
Also used : RestValidationResult(com.infiniteautomation.mango.rest.v2.model.RestValidationResult) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) User(com.serotonin.m2m2.vo.User) ValidationFailedRestException(com.infiniteautomation.mango.rest.v2.exception.ValidationFailedRestException) RestValidationFailedException(com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException) ValidationFailedRestException(com.infiniteautomation.mango.rest.v2.exception.ValidationFailedRestException) RTException(com.serotonin.m2m2.rt.RTException) NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) DateTime(org.joda.time.DateTime) DateTimeZone(org.joda.time.DateTimeZone) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) TimePeriodBucketCalculator(com.serotonin.m2m2.view.quantize2.TimePeriodBucketCalculator) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with RollupEnum

use of com.serotonin.m2m2.web.mvc.rest.v1.model.time.RollupEnum in project ma-modules-public by infiniteautomation.

the class PointValueRestController method getPointValues.

@ApiOperation(value = "Query Time Range", notes = "From time inclusive, To time exclusive", response = PointValueTimeModel.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET, value = "/{xid}", produces = { "application/json", "text/csv" })
public ResponseEntity<QueryArrayStream<PointValueTimeModel>> getPointValues(HttpServletRequest request, @ApiParam(value = "Point xid", required = true, allowMultiple = false) @PathVariable String xid, @ApiParam(value = "Return rendered value as String", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean useRendered, @ApiParam(value = "Return converted value using displayed unit", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean unitConversion, @ApiParam(value = "From time", required = false, allowMultiple = false) @RequestParam(value = "from", required = false) // Not working yet@DateTimeFormat(pattern = "${rest.customDateInputFormat}") Date from,
@DateTimeFormat(iso = ISO.DATE_TIME) DateTime from, @ApiParam(value = "To time", required = false, allowMultiple = false) @RequestParam(value = "to", required = false) // Not working yet@DateTimeFormat(pattern = "${rest.customDateInputFormat}") Date to,
@DateTimeFormat(iso = ISO.DATE_TIME) DateTime to, @ApiParam(value = "Rollup type", required = false, allowMultiple = false) @RequestParam(value = "rollup", required = false) RollupEnum rollup, @ApiParam(value = "Time Period Type", required = false, allowMultiple = false) @RequestParam(value = "timePeriodType", required = false) TimePeriodType timePeriodType, @ApiParam(value = "Time Periods", required = false, allowMultiple = false) @RequestParam(value = "timePeriods", required = false) Integer timePeriods, @ApiParam(value = "Time zone", required = false, allowMultiple = false) @RequestParam(value = "timezone", required = false) String timezone, @ApiParam(value = "Limit", required = false, allowMultiple = false) @RequestParam(value = "limit", required = false) Integer limit, @ApiParam(value = "Date Time format pattern for timestamps as strings, if not included epoch milli number is used", required = false, allowMultiple = false) @RequestParam(value = "dateTimeFormat", required = false) String dateTimeFormat) {
    RestProcessResult<QueryArrayStream<PointValueTimeModel>> result = new RestProcessResult<QueryArrayStream<PointValueTimeModel>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        if (dateTimeFormat != null) {
            try {
                DateTimeFormatter.ofPattern(dateTimeFormat);
            } catch (IllegalArgumentException e) {
                RestValidationResult vr = new RestValidationResult();
                vr.addError("validate.invalid", "dateTimeFormat");
                throw new ValidationFailedRestException(vr);
            }
        }
        if (timezone != null) {
            try {
                ZoneId.of(timezone);
            } catch (Exception e) {
                RestValidationResult vr = new RestValidationResult();
                vr.addError("validate.invalidValue", "timezone");
                throw new ValidationFailedRestException(vr);
            }
        }
        DataPointVO vo = DataPointDao.instance.getByXid(xid);
        if (vo == null) {
            result.addRestMessage(getDoesNotExistMessage());
            return result.createResponseEntity();
        }
        try {
            if (Permissions.hasDataPointReadPermission(user, vo)) {
                long current = Common.timer.currentTimeMillis();
                if (from == null)
                    from = new DateTime(current);
                if (to == null)
                    to = new DateTime(current);
                // better not to for RESTfulness
                if (timezone != null) {
                    DateTimeZone zone = DateTimeZone.forID(timezone);
                    from = from.withZone(zone);
                    to = to.withZone(zone);
                }
                // Are we using rollup
                if ((rollup != null) && (rollup != RollupEnum.NONE)) {
                    if (rollup == RollupEnum.FFT) {
                        // Special Rollup for FFT's with no time rollup action
                        // TODO Need a way to return frequency or period values
                        PointValueFftCalculator calc = new PointValueFftCalculator(vo, from.getMillis(), to.getMillis(), true);
                        return result.createResponseEntity(calc);
                    } else {
                        TimePeriod timePeriod = null;
                        if ((timePeriodType != null) && (timePeriods != null)) {
                            timePeriod = new TimePeriod(timePeriods, timePeriodType);
                        }
                        PointValueRollupCalculator calc = new PointValueRollupCalculator(vo, useRendered, unitConversion, rollup, timePeriod, from, to, limit, dateTimeFormat, timezone);
                        return result.createResponseEntity(calc);
                    }
                } else {
                    PointValueTimeDatabaseStream pvtDatabaseStream = new PointValueTimeDatabaseStream(vo, useRendered, unitConversion, from.getMillis(), to.getMillis(), this.dao, limit, dateTimeFormat, timezone);
                    return result.createResponseEntity(pvtDatabaseStream);
                }
            } else {
                result.addRestMessage(getUnauthorizedMessage());
                return result.createResponseEntity();
            }
        } catch (PermissionException e) {
            LOG.error(e.getMessage(), e);
            result.addRestMessage(getUnauthorizedMessage());
            return result.createResponseEntity();
        }
    } else {
        return result.createResponseEntity();
    }
}
Also used : RestValidationResult(com.infiniteautomation.mango.rest.v2.model.RestValidationResult) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) User(com.serotonin.m2m2.vo.User) XidPointValueTimeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.XidPointValueTimeModel) RecentPointValueTimeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.RecentPointValueTimeModel) PointValueTimeModel(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeModel) ValidationFailedRestException(com.infiniteautomation.mango.rest.v2.exception.ValidationFailedRestException) PointValueTimeDatabaseStream(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeDatabaseStream) IdPointValueTimeDatabaseStream(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.IdPointValueTimeDatabaseStream) TimePeriod(com.serotonin.m2m2.web.mvc.rest.v1.model.time.TimePeriod) PointValueFftCalculator(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueFftCalculator) QueryArrayStream(com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream) PointValueRollupCalculator(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueRollupCalculator) IdPointValueRollupCalculator(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.IdPointValueRollupCalculator) RestValidationFailedException(com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException) ValidationFailedRestException(com.infiniteautomation.mango.rest.v2.exception.ValidationFailedRestException) RTException(com.serotonin.m2m2.rt.RTException) NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) DateTime(org.joda.time.DateTime) DateTimeZone(org.joda.time.DateTimeZone) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with RollupEnum

use of com.serotonin.m2m2.web.mvc.rest.v1.model.time.RollupEnum in project ma-modules-public by infiniteautomation.

the class PointValueRestController method pointValuesForMultiplePointsAsMultipleArrays.

public ResponseEntity<ObjectStream<Map<String, List<PointValueTime>>>> pointValuesForMultiplePointsAsMultipleArrays(HttpServletRequest request, String[] xids, boolean useRendered, boolean unitConversion, DateTime from, DateTime to, RollupEnum rollup, TimePeriodType timePeriodType, Integer timePeriods, String timezone, Integer limit, String dateTimeFormat) {
    RestProcessResult<ObjectStream<Map<String, List<PointValueTime>>>> result = new RestProcessResult<ObjectStream<Map<String, List<PointValueTime>>>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        if (dateTimeFormat != null) {
            try {
                DateTimeFormatter.ofPattern(dateTimeFormat);
            } catch (IllegalArgumentException e) {
                RestValidationResult vr = new RestValidationResult();
                vr.addError("validate.invalid", "dateTimeFormat");
                throw new ValidationFailedRestException(vr);
            }
        }
        if (timezone != null) {
            try {
                ZoneId.of(timezone);
            } catch (Exception e) {
                RestValidationResult vr = new RestValidationResult();
                vr.addError("validate.invalidValue", "timezone");
                throw new ValidationFailedRestException(vr);
            }
        }
        Map<Integer, DataPointVO> pointIdMap = new HashMap<Integer, DataPointVO>(xids.length);
        DataPointVO vo;
        for (String xid : xids) {
            vo = DataPointDao.instance.getByXid(xid);
            if (vo != null) {
                if (Permissions.hasDataPointReadPermission(user, vo))
                    pointIdMap.put(vo.getId(), vo);
                else {
                    // Abort, invalid permissions
                    result.addRestMessage(getUnauthorizedMessage());
                    return result.createResponseEntity();
                }
            }
        }
        // Do we have any valid points?
        if (pointIdMap.size() == 0) {
            result.addRestMessage(getDoesNotExistMessage());
            return result.createResponseEntity();
        }
        try {
            long current = Common.timer.currentTimeMillis();
            if (from == null)
                from = new DateTime(current);
            if (to == null)
                to = new DateTime(current);
            // better not to for RESTfulness
            if (timezone != null) {
                DateTimeZone zone = DateTimeZone.forID(timezone);
                from = from.withZone(zone);
                to = to.withZone(zone);
            }
            // Are we using rollup
            if ((rollup != null) && (rollup != RollupEnum.NONE)) {
                if (rollup == RollupEnum.FFT) {
                // Special Rollup for FFT's with no time rollup action
                // TODO Need a way to return frequency or period values
                // IdPointValueFftCalculator calc = new
                // IdPointValueFftCalculator(pointIdMap, from.getTime(), to.getTime(),
                // true);
                // return result.createResponseEntity(calc);
                } else {
                    TimePeriod timePeriod = null;
                    if ((timePeriodType != null) && (timePeriods != null)) {
                        timePeriod = new TimePeriod(timePeriods, timePeriodType);
                    }
                    XidPointValueMapRollupCalculator calc = new XidPointValueMapRollupCalculator(pointIdMap, useRendered, unitConversion, rollup, timePeriod, from, to, limit, dateTimeFormat, timezone);
                    return result.createResponseEntity(calc);
                }
                return result.createResponseEntity();
            } else {
                XidPointValueTimeMapDatabaseStream pvtDatabaseStream = new XidPointValueTimeMapDatabaseStream(pointIdMap, useRendered, unitConversion, from.getMillis(), to.getMillis(), this.dao, limit, dateTimeFormat, timezone);
                return result.createResponseEntity(pvtDatabaseStream);
            }
        } catch (PermissionException e) {
            LOG.error(e.getMessage(), e);
            result.addRestMessage(getUnauthorizedMessage());
            return result.createResponseEntity();
        }
    } else {
        return result.createResponseEntity();
    }
}
Also used : RestValidationResult(com.infiniteautomation.mango.rest.v2.model.RestValidationResult) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) User(com.serotonin.m2m2.vo.User) XidPointValueTimeMapDatabaseStream(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.XidPointValueTimeMapDatabaseStream) ValidationFailedRestException(com.infiniteautomation.mango.rest.v2.exception.ValidationFailedRestException) HashMap(java.util.HashMap) TimePeriod(com.serotonin.m2m2.web.mvc.rest.v1.model.time.TimePeriod) RestValidationFailedException(com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException) ValidationFailedRestException(com.infiniteautomation.mango.rest.v2.exception.ValidationFailedRestException) RTException(com.serotonin.m2m2.rt.RTException) NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) PermissionException(com.serotonin.m2m2.vo.permission.PermissionException) DateTime(org.joda.time.DateTime) DateTimeZone(org.joda.time.DateTimeZone) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) ObjectStream(com.serotonin.m2m2.web.mvc.rest.v1.model.ObjectStream) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) List(java.util.List) ArrayList(java.util.ArrayList) XidPointValueMapRollupCalculator(com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.XidPointValueMapRollupCalculator) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with RollupEnum

use of com.serotonin.m2m2.web.mvc.rest.v1.model.time.RollupEnum in project ma-modules-public by infiniteautomation.

the class PointValueRestController method getRollupPointValuesAsMultipleArrays.

@ApiOperation(value = "Rollup values for multiple data points, return in time ascending order", notes = "From time inclusive, To time exclusive.  Returns a map of xid to point value time arrays.", response = PointValueTimeModel.class, responseContainer = "Object")
@RequestMapping(method = RequestMethod.GET, value = "/multiple-arrays/time-period/{xids}/{rollup}")
public ResponseEntity<PointValueTimeStream<Map<String, List<PointValueTime>>, ZonedDateTimeRangeQueryInfo>> getRollupPointValuesAsMultipleArrays(HttpServletRequest request, @ApiParam(value = "Point xids", required = true, allowMultiple = true) @PathVariable String[] xids, @ApiParam(value = "Rollup type", required = false, allowMultiple = false) @PathVariable(value = "rollup") RollupEnum rollup, @ApiParam(value = "From time", required = false, allowMultiple = false) @RequestParam(value = "from", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime from, @ApiParam(value = "To time", required = false, allowMultiple = false) @RequestParam(value = "to", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) ZonedDateTime to, @ApiParam(value = "Time Period Type", required = false, allowMultiple = false) @RequestParam(value = "timePeriodType", required = false) TimePeriodType timePeriodType, @ApiParam(value = "Time Periods", required = false, allowMultiple = false) @RequestParam(value = "timePeriods", required = false) Integer timePeriods, @ApiParam(value = "Time zone", required = false, allowMultiple = false) @RequestParam(value = "timezone", required = false) String timezone, @ApiParam(value = "Limit (per series)", required = false, allowMultiple = false) @RequestParam(value = "limit", required = false) Integer limit, @ApiParam(value = "Date Time format pattern for timestamps as strings, if not included epoch milli number is used", required = false, allowMultiple = false) @RequestParam(value = "dateTimeFormat", required = false) String dateTimeFormat, @ApiParam(value = "Truncate the from time and expand to time based on the time period settings", required = false, allowMultiple = false) @RequestParam(value = "truncate", required = false, defaultValue = "false") boolean truncate, @ApiParam(value = "Fields to be included in the returned data, default is TIMESTAMP,VALUE", required = false, allowMultiple = false) @RequestParam(required = false) PointValueField[] fields, @AuthenticationPrincipal User user) {
    TimePeriod timePeriod = null;
    if ((timePeriodType != null) && (timePeriods != null)) {
        timePeriod = new TimePeriod(timePeriods, timePeriodType);
    }
    ZonedDateTimeRangeQueryInfo info = new ZonedDateTimeRangeQueryInfo(from, to, dateTimeFormat, timezone, rollup, timePeriod, limit, true, false, false, PointValueTimeCacheControl.NONE, null, null, truncate, fields);
    return generateStream(user, info, xids);
}
Also used : TimePeriod(com.serotonin.m2m2.web.mvc.rest.v1.model.time.TimePeriod) ZonedDateTimeRangeQueryInfo(com.infiniteautomation.mango.rest.v2.model.pointValue.query.ZonedDateTimeRangeQueryInfo) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with RollupEnum

use of com.serotonin.m2m2.web.mvc.rest.v1.model.time.RollupEnum in project ma-modules-public by infiniteautomation.

the class PointValueTimeStreamCsvMessageConverter method writeInternal.

@Override
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    MediaType contentType = outputMessage.getHeaders().getContentType();
    JsonEncoding encoding = getJsonEncoding(contentType);
    try {
        PointValueTimeStream<?, ?> stream = (PointValueTimeStream<?, ?>) object;
        stream.setContentType(StreamContentType.CSV);
        JsonGenerator generator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(), encoding);
        // Set the schema
        CsvSchema.Builder builder = CsvSchema.builder();
        builder.setUseHeader(true);
        // Setup our rendering parameters
        LatestQueryInfo info = stream.getQueryInfo();
        if (stream instanceof MultiPointTimeRangeDatabaseStream || stream instanceof MultiPointLatestDatabaseStream) {
            if (info.isSingleArray()) {
                if (info.isMultiplePointsPerArray()) {
                    Map<Integer, DataPointVO> voMap = stream.getVoMap();
                    Iterator<Integer> it = voMap.keySet().iterator();
                    boolean firstTimestamp = true;
                    while (it.hasNext()) {
                        String xid = voMap.get(it.next()).getXid();
                        for (PointValueField field : info.getFields()) {
                            if (field == PointValueField.TIMESTAMP) {
                                if (firstTimestamp)
                                    field.createColumn(builder, xid);
                                firstTimestamp = false;
                            } else
                                field.createColumn(builder, xid);
                        }
                    }
                } else {
                    for (PointValueField field : info.getFields()) field.createColumn(builder, null);
                }
            } else {
                for (PointValueField field : info.getFields()) field.createColumn(builder, null);
            }
        } else if (stream instanceof MultiDataPointStatisticsQuantizerStream) {
            if (stream.getQueryInfo().isSingleArray()) {
                if (stream.getQueryInfo().isMultiplePointsPerArray()) {
                    Map<Integer, DataPointVO> voMap = stream.getVoMap();
                    Iterator<Integer> it = voMap.keySet().iterator();
                    boolean firstTimestamp = true;
                    while (it.hasNext()) {
                        String xid = voMap.get(it.next()).getXid();
                        for (PointValueField field : info.getFields()) {
                            if (field == PointValueField.TIMESTAMP) {
                                if (firstTimestamp)
                                    field.createColumn(builder, xid);
                                firstTimestamp = false;
                            } else if (field == PointValueField.VALUE) {
                                if (info.getRollup() == RollupEnum.ALL) {
                                    for (RollupEnum rollup : getAllRollups()) {
                                        builder.addColumn(xid + PointValueTimeWriter.DOT + rollup.name(), ColumnType.NUMBER_OR_STRING);
                                    }
                                } else {
                                    field.createColumn(builder, xid);
                                }
                            } else {
                                field.createColumn(builder, xid);
                            }
                        }
                    }
                } else {
                    // Single array
                    if (info.getRollup() == RollupEnum.ALL) {
                        for (RollupEnum rollup : getAllRollups()) {
                            builder.addColumn(rollup.name(), ColumnType.NUMBER_OR_STRING);
                        }
                        for (PointValueField field : info.getFields()) {
                            if (field == PointValueField.VALUE)
                                continue;
                            field.createColumn(builder, null);
                        }
                    } else {
                        for (PointValueField field : info.getFields()) field.createColumn(builder, null);
                    }
                }
            } else {
                if (info.getRollup() == RollupEnum.ALL) {
                    for (RollupEnum rollup : getAllRollups()) {
                        builder.addColumn(rollup.name(), ColumnType.NUMBER_OR_STRING);
                    }
                    for (PointValueField field : info.getFields()) {
                        if (field == PointValueField.VALUE)
                            continue;
                        field.createColumn(builder, null);
                    }
                } else {
                    for (PointValueField field : info.getFields()) field.createColumn(builder, null);
                }
            }
        }
        generator.setSchema(builder.build());
        PointValueTimeWriter writer = new PointValueTimeCsvWriter(stream.getQueryInfo(), stream.getVoMap().size(), generator);
        stream.start(writer);
        stream.streamData(writer);
        stream.finish(writer);
        generator.flush();
    } catch (JsonProcessingException ex) {
        throw new HttpMessageNotWritableException("Could not write content: " + ex.getMessage(), ex);
    }
}
Also used : PointValueTimeStream(com.infiniteautomation.mango.rest.v2.model.pointValue.PointValueTimeStream) MultiDataPointStatisticsQuantizerStream(com.infiniteautomation.mango.rest.v2.model.pointValue.quantize.MultiDataPointStatisticsQuantizerStream) LatestQueryInfo(com.infiniteautomation.mango.rest.v2.model.pointValue.query.LatestQueryInfo) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) PointValueTimeCsvWriter(com.infiniteautomation.mango.rest.v2.model.pointValue.PointValueTimeCsvWriter) JsonEncoding(com.fasterxml.jackson.core.JsonEncoding) MultiPointTimeRangeDatabaseStream(com.infiniteautomation.mango.rest.v2.model.pointValue.query.MultiPointTimeRangeDatabaseStream) Iterator(java.util.Iterator) MediaType(org.springframework.http.MediaType) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RollupEnum(com.serotonin.m2m2.web.mvc.rest.v1.model.time.RollupEnum) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) MultiPointLatestDatabaseStream(com.infiniteautomation.mango.rest.v2.model.pointValue.query.MultiPointLatestDatabaseStream) DataPointVO(com.serotonin.m2m2.vo.DataPointVO) HttpMessageNotWritableException(org.springframework.http.converter.HttpMessageNotWritableException) PointValueTimeWriter(com.infiniteautomation.mango.rest.v2.model.pointValue.PointValueTimeWriter) Map(java.util.Map) PointValueField(com.infiniteautomation.mango.rest.v2.model.pointValue.PointValueField)

Aggregations

DataPointVO (com.serotonin.m2m2.vo.DataPointVO)6 TimePeriod (com.serotonin.m2m2.web.mvc.rest.v1.model.time.TimePeriod)6 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)5 User (com.serotonin.m2m2.vo.User)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ValidationFailedRestException (com.infiniteautomation.mango.rest.v2.exception.ValidationFailedRestException)4 RestValidationResult (com.infiniteautomation.mango.rest.v2.model.RestValidationResult)4 RTException (com.serotonin.m2m2.rt.RTException)4 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)4 RestValidationFailedException (com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException)4 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)4 DateTime (org.joda.time.DateTime)4 DateTimeZone (org.joda.time.DateTimeZone)4 ZonedDateTimeRangeQueryInfo (com.infiniteautomation.mango.rest.v2.model.pointValue.query.ZonedDateTimeRangeQueryInfo)3 PointValueTimeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeModel)3 QueryArrayStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream)2 IdPointValueRollupCalculator (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.IdPointValueRollupCalculator)2 IdPointValueTimeDatabaseStream (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.IdPointValueTimeDatabaseStream)2 RecentPointValueTimeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.RecentPointValueTimeModel)2