use of com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.statistics.StatisticsStream in project ma-modules-public by infiniteautomation.
the class PointValueRestController method getPointStatistics.
@ApiOperation(value = "Get Point Statistics", notes = "From time inclusive, To time exclusive")
@RequestMapping(method = RequestMethod.GET, value = "/{xid}/statistics", produces = { "application/json" })
public ResponseEntity<StatisticsStream> getPointStatistics(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) @DateTimeFormat(iso = ISO.DATE_TIME) DateTime from, @ApiParam(value = "To time", required = false, allowMultiple = false) @RequestParam(value = "to", required = false) @DateTimeFormat(iso = ISO.DATE_TIME) DateTime to, @ApiParam(value = "Time zone", required = false, allowMultiple = false) @RequestParam(value = "timezone", required = false) String timezone, @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<StatisticsStream> result = new RestProcessResult<StatisticsStream>(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.invalidValue", "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);
}
StatisticsStream stream = new StatisticsStream(vo, useRendered, unitConversion, from.getMillis(), to.getMillis(), dateTimeFormat, timezone);
return result.createResponseEntity(stream);
} 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();
}
}
Aggregations