use of com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery in project ma-modules-public by infiniteautomation.
the class DataPointRestController method getBulkDataPointOperations.
@ApiOperation(value = "Get a list of current bulk data point operations", notes = "User can only get their own bulk data point operations unless they are an admin")
@RequestMapping(method = RequestMethod.GET, value = "/bulk")
public MappingJacksonValue getBulkDataPointOperations(@AuthenticationPrincipal User user, HttpServletRequest request) {
List<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>> preFiltered = this.bulkResourceManager.list().stream().filter((tr) -> user.isAdmin() || user.getId() == tr.getUserId()).collect(Collectors.toList());
List<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>> results = preFiltered;
ASTNode query = BaseMangoRestController.parseRQLtoAST(request.getQueryString());
if (query != null) {
results = query.accept(new RQLToObjectListQuery<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>>(), preFiltered);
}
PageQueryResultModel<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>> result = new PageQueryResultModel<>(results, preFiltered.size());
// hide result property by setting a view
MappingJacksonValue resultWithView = new MappingJacksonValue(result);
resultWithView.setSerializationView(Object.class);
return resultWithView;
}
use of com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery in project ma-modules-public by infiniteautomation.
the class DataPointTagsRestController method getBulkDataPointTagOperations.
@ApiOperation(value = "Get a list of current bulk tag operations", notes = "User can only get their own bulk tag operations unless they are an admin")
@RequestMapping(method = RequestMethod.GET, value = "/bulk")
public MappingJacksonValue getBulkDataPointTagOperations(@AuthenticationPrincipal User user, HttpServletRequest request) {
List<TemporaryResource<TagBulkResponse, AbstractRestV2Exception>> preFiltered = this.bulkResourceManager.list().stream().filter((tr) -> user.isAdmin() || user.getId() == tr.getUserId()).collect(Collectors.toList());
List<TemporaryResource<TagBulkResponse, AbstractRestV2Exception>> results = preFiltered;
ASTNode query = BaseMangoRestController.parseRQLtoAST(request.getQueryString());
if (query != null) {
results = query.accept(new RQLToObjectListQuery<TemporaryResource<TagBulkResponse, AbstractRestV2Exception>>(), preFiltered);
}
PageQueryResultModel<TemporaryResource<TagBulkResponse, AbstractRestV2Exception>> result = new PageQueryResultModel<>(results, preFiltered.size());
// hide result property by setting a view
MappingJacksonValue resultWithView = new MappingJacksonValue(result);
resultWithView.setSerializationView(Object.class);
return resultWithView;
}
use of com.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery 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.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery 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.infiniteautomation.mango.db.query.pojo.RQLToObjectListQuery 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