Search in sources :

Example 6 with QueryArrayStream

use of com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream in project ma-modules-public by infiniteautomation.

the class DataPointRestController method getAllDataPoints.

@ApiOperation(value = "Get all data points", notes = "Only returns points available to logged in user")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/list")
public ResponseEntity<QueryArrayStream<DataPointVO>> getAllDataPoints(HttpServletRequest request, @ApiParam(value = "Limit the number of results", required = false) @RequestParam(value = "limit", required = false, defaultValue = "100") int limit) {
    RestProcessResult<QueryArrayStream<DataPointVO>> result = new RestProcessResult<QueryArrayStream<DataPointVO>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        ASTNode root = new ASTNode("limit", limit);
        if (user.isAdmin()) {
            // Admin Users Don't need to filter the results
            return result.createResponseEntity(getStream(root));
        } else {
            // We are going to filter the results, so we need to strip out the limit(limit,offset) or limit(limit) clause.
            DataPointStreamCallback callback = new DataPointStreamCallback(this, user);
            FilteredQueryStream<DataPointVO, DataPointModel, DataPointDao> stream = new FilteredQueryStream<DataPointVO, DataPointModel, DataPointDao>(DataPointDao.instance, this, root, callback);
            stream.setupQuery();
            return result.createResponseEntity(stream);
        }
    }
    return result.createResponseEntity();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) DataPointStreamCallback(com.serotonin.m2m2.web.mvc.rest.v1.model.dataPoint.DataPointStreamCallback) DataPointModel(com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel) User(com.serotonin.m2m2.vo.User) DataPointDao(com.serotonin.m2m2.db.dao.DataPointDao) ASTNode(net.jazdw.rql.parser.ASTNode) FilteredQueryStream(com.serotonin.m2m2.web.mvc.rest.v1.model.FilteredQueryStream) QueryArrayStream(com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with QueryArrayStream

use of com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream in project ma-modules-public by infiniteautomation.

the class EventsRestController method getAll.

@ApiOperation(value = "Get all events", notes = "", response = EventInstanceModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/list")
public ResponseEntity<QueryArrayStream<EventInstanceVO>> getAll(HttpServletRequest request, @RequestParam(value = "limit", required = false, defaultValue = "100") Integer limit) {
    RestProcessResult<QueryArrayStream<EventInstanceVO>> result = new RestProcessResult<QueryArrayStream<EventInstanceVO>>(HttpStatus.OK);
    User user = this.checkUser(request, result);
    if (result.isOk()) {
        ASTNode root = new ASTNode("and", new ASTNode("eq", "userId", user.getId()), new ASTNode("limit", limit));
        return result.createResponseEntity(getPageStream(root));
    }
    return result.createResponseEntity();
}
Also used : RestProcessResult(com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) User(com.serotonin.m2m2.vo.User) ASTNode(net.jazdw.rql.parser.ASTNode) QueryArrayStream(com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with QueryArrayStream

use of com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream in project ma-core-public by infiniteautomation.

the class CsvQueryArrayStreamMessageConverter method writeInternal.

/* (non-Javadoc)
	 * @see org.springframework.http.converter.AbstractHttpMessageConverter#writeInternal(java.lang.Object, org.springframework.http.HttpOutputMessage)
	 */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void writeInternal(QueryArrayStream stream, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
    CSVPojoWriter out = new CSVPojoWriter(new CSVWriter(new OutputStreamWriter(outputMessage.getBody(), Common.UTF8_CS), separator, quote));
    stream.streamData(out);
    out.close();
}
Also used : CSVPojoWriter(com.serotonin.m2m2.web.mvc.rest.v1.csv.CSVPojoWriter) CSVWriter(au.com.bytecode.opencsv.CSVWriter) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)7 QueryArrayStream (com.serotonin.m2m2.web.mvc.rest.v1.model.QueryArrayStream)7 User (com.serotonin.m2m2.vo.User)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)4 ValidationFailedRestException (com.infiniteautomation.mango.rest.v2.exception.ValidationFailedRestException)4 RestValidationResult (com.infiniteautomation.mango.rest.v2.model.RestValidationResult)4 RTException (com.serotonin.m2m2.rt.RTException)4 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)4 RestValidationFailedException (com.serotonin.m2m2.web.mvc.rest.v1.exception.RestValidationFailedException)4 PointValueTimeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.PointValueTimeModel)4 RecentPointValueTimeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.RecentPointValueTimeModel)4 XidPointValueTimeModel (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.XidPointValueTimeModel)4 HashMap (java.util.HashMap)3 ASTNode (net.jazdw.rql.parser.ASTNode)3 IdPointValueRollupCalculator (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.IdPointValueRollupCalculator)2 IdPointValueTimeDatabaseStream (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.IdPointValueTimeDatabaseStream)2 IdPointValueTimeLatestPointValueFacadeStream (com.serotonin.m2m2.web.mvc.rest.v1.model.pointValue.IdPointValueTimeLatestPointValueFacadeStream)2