use of com.serotonin.m2m2.web.mvc.rest.v1.model.PageQueryResultModel in project ma-modules-public by infiniteautomation.
the class ServerRestController method queryTimezone.
@ApiOperation(value = "Query Timezones", notes = "", response = TimezoneModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/timezones")
public ResponseEntity<PageQueryResultModel<TimezoneModel>> queryTimezone(HttpServletRequest request) {
RestProcessResult<PageQueryResultModel<TimezoneModel>> result = new RestProcessResult<PageQueryResultModel<TimezoneModel>>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
try {
// Parse the RQL Query
ASTNode root = parseRQLtoAST(request.getQueryString());
List<TimezoneModel> list = root.accept(new RQLToObjectListQuery<TimezoneModel>(), allTimezones);
PageQueryResultModel<TimezoneModel> model = new PageQueryResultModel<TimezoneModel>(list, allTimezones.size() + 1);
return result.createResponseEntity(model);
} catch (InvalidRQLRestException 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.PageQueryResultModel 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.serotonin.m2m2.web.mvc.rest.v1.model.PageQueryResultModel 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.serotonin.m2m2.web.mvc.rest.v1.model.PageQueryResultModel in project ma-modules-public by infiniteautomation.
the class ServerRestV2Controller method queryTimezone.
@ApiOperation(value = "Query Timezones", notes = "", response = TimezoneModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET, value = "/timezones")
public ResponseEntity<PageQueryResultModel<TimezoneModel>> queryTimezone(HttpServletRequest request) {
ASTNode root = parseRQLtoAST(request.getQueryString());
List<TimezoneModel> list = root.accept(new RQLToObjectListQuery<TimezoneModel>(), allTimezones);
PageQueryResultModel<TimezoneModel> model = new PageQueryResultModel<TimezoneModel>(list, allTimezones.size() + 1);
return new ResponseEntity<PageQueryResultModel<TimezoneModel>>(model, HttpStatus.OK);
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.PageQueryResultModel in project ma-modules-public by infiniteautomation.
the class UserEventsV2Controller method query.
@ApiOperation(value = "Query User Events", notes = "Query via rql in url against events for the current user", response = EventInstanceModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET, value = "")
public ResponseEntity<PageQueryResultModel<EventInstanceModel>> query(@AuthenticationPrincipal User user, HttpServletRequest request) {
// Parse the RQL Query
ASTNode query = parseRQLtoAST(request.getQueryString());
List<EventInstance> results;
List<EventInstance> events = Common.eventManager.getAllActiveUserEvents(user.getId());
if (query != null)
results = query.accept(new RQLToObjectListQuery<EventInstance>(), events);
else
results = events;
List<EventInstanceModel> models = new ArrayList<>();
// Convert to models
for (EventInstance event : results) {
models.add(new EventInstanceModel(event));
}
// Query the models
return new ResponseEntity<>(new PageQueryResultModel<>(models, events.size()), HttpStatus.OK);
}
Aggregations