use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestMessage in project ma-modules-public by infiniteautomation.
the class RealTimeDataRestController method query.
/**
* Query the User's Real Time Data
* @param request
* @param limit
* @return
*/
@ApiOperation(value = "Query realtime values", notes = "Check the status member to ensure the point is OK not DISABLED or UNRELIABLE")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<List<RealTimeModel>> query(HttpServletRequest request) {
RestProcessResult<List<RealTimeModel>> result = new RestProcessResult<List<RealTimeModel>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
ASTNode model;
try {
model = parseRQLtoAST(request.getQueryString());
if (model == null) {
result.addRestMessage(new RestMessage(HttpStatus.NOT_ACCEPTABLE, new TranslatableMessage("common.default", "Query Required")));
return result.createResponseEntity();
}
List<RealTimeDataPointValue> values = RealTimeDataPointValueCache.instance.getUserView(user);
values = model.accept(new RQLToObjectListQuery<RealTimeDataPointValue>(), values);
List<RealTimeModel> models = new ArrayList<RealTimeModel>();
UriComponentsBuilder imageServletBuilder = UriComponentsBuilder.fromPath("/imageValue/{ts}_{id}.jpg");
for (RealTimeDataPointValue value : values) {
if (value.getDataTypeId() == DataTypes.IMAGE) {
models.add(new RealTimeModel(value, imageServletBuilder.buildAndExpand(value.getTimestamp(), value.getDataPointId()).toUri()));
} else {
models.add(new RealTimeModel(value, value.getValue()));
}
}
return result.createResponseEntity(models);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
Aggregations