use of com.serotonin.m2m2.web.mvc.rest.v1.model.RealTimeModel 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();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.RealTimeModel in project ma-modules-public by infiniteautomation.
the class RealTimeDataRestController method get.
@ApiOperation(value = "Get realtime value of point based on XID", notes = "Check the status member to ensure the point is OK not DISABLED or UNRELIABLE")
@RequestMapping(method = RequestMethod.GET, value = "/by-xid/{xid}", produces = { "application/json" })
public ResponseEntity<RealTimeModel> get(@PathVariable String xid, HttpServletRequest request) {
RestProcessResult<RealTimeModel> result = new RestProcessResult<RealTimeModel>(HttpStatus.OK);
// Check the user
User user = checkUser(request, result);
// If no messages then go for it
if (result.isOk()) {
List<RealTimeDataPointValue> values = RealTimeDataPointValueCache.instance.getUserView(user);
ASTNode root = new ASTNode("eq", "xid", xid);
values = root.accept(new RQLToObjectListQuery<RealTimeDataPointValue>(), values);
if (values.size() == 0) {
LOG.debug("Attempted access of Real time point that DNE.");
result.addRestMessage(HttpStatus.NOT_FOUND, new TranslatableMessage("common.default", "Point doesn't exist or is not enabled."));
return result.createResponseEntity();
}
RealTimeModel model;
RealTimeDataPointValue value = values.get(0);
if (value.getDataTypeId() != DataTypes.IMAGE)
model = new RealTimeModel(value, value.getValue());
else {
UriComponentsBuilder imageServletBuilder = UriComponentsBuilder.fromPath("/imageValue/{ts}_{id}.jpg");
model = new RealTimeModel(value, imageServletBuilder.buildAndExpand(value.getTimestamp(), value.getDataPointId()).toUri());
}
return result.createResponseEntity(model);
} else {
return result.createResponseEntity();
}
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.RealTimeModel in project ma-modules-public by infiniteautomation.
the class RealTimeDataRestController method getAll.
/**
* Get all of the Users Real Time Data
* @param request
* @param limit
* @return
*/
@ApiOperation(value = "List realtime values", notes = "Check the status member to ensure the point is OK not DISABLED or UNRELIABLE")
@RequestMapping(method = RequestMethod.GET, value = "/list", produces = { "application/json" })
public ResponseEntity<List<RealTimeModel>> getAll(HttpServletRequest request, @ApiParam(value = "Limit the number of results", required = false) @RequestParam(value = "limit", required = false, defaultValue = "100") int limit) {
RestProcessResult<List<RealTimeModel>> result = new RestProcessResult<List<RealTimeModel>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
List<RealTimeDataPointValue> values = RealTimeDataPointValueCache.instance.getUserView(user);
ASTNode root = new ASTNode("limit", limit);
values = root.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);
}
return result.createResponseEntity();
}
Aggregations