use of com.serotonin.m2m2.vo.DataPointVO in project ma-modules-public by infiniteautomation.
the class DataPointRestController method getDataPointById.
@ApiOperation(value = "Get data point by ID", notes = "Returned as CSV or JSON, only points that user has read permission to are returned")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv", "application/sero-json" }, value = "/by-id/{id}")
public ResponseEntity<DataPointModel> getDataPointById(@ApiParam(value = "Valid Data Point ID", required = true, allowMultiple = false) @PathVariable int id, HttpServletRequest request) {
RestProcessResult<DataPointModel> result = new RestProcessResult<DataPointModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
DataPointVO vo = DataPointDao.instance.get(id);
if (vo == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
// Check permissions
try {
if (Permissions.hasDataPointReadPermission(user, vo))
return result.createResponseEntity(new DataPointModel(vo));
else {
LOG.warn("User: " + user.getUsername() + " tried to access data point with xid " + vo.getXid());
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} catch (PermissionException e) {
LOG.warn(e.getMessage(), e);
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-modules-public by infiniteautomation.
the class DataPointRestController method getDataPoint.
@ApiOperation(value = "Get data point by XID", notes = "Returned as CSV or JSON, only points that user has read permission to are returned")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv", "application/sero-json" }, value = "/{xid}")
public ResponseEntity<DataPointModel> getDataPoint(@ApiParam(value = "Valid Data Point XID", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
RestProcessResult<DataPointModel> result = new RestProcessResult<DataPointModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
DataPointVO vo = DataPointDao.instance.getByXid(xid);
if (vo == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
// Check permissions
try {
if (Permissions.hasDataPointReadPermission(user, vo))
return result.createResponseEntity(new DataPointModel(vo));
else {
LOG.warn("User: " + user.getUsername() + " tried to access data point with xid " + vo.getXid());
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} catch (PermissionException e) {
LOG.warn(e.getMessage(), e);
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-modules-public by infiniteautomation.
the class DataPointRestController method queryRQL.
@ApiOperation(value = "Query Data Points", notes = "Use RQL formatted query", response = DataPointModel.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<QueryDataPageStream<DataPointVO>> queryRQL(HttpServletRequest request) {
RestProcessResult<QueryDataPageStream<DataPointVO>> result = new RestProcessResult<QueryDataPageStream<DataPointVO>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
try {
ASTNode node = parseRQLtoAST(request.getQueryString());
if (user.isAdmin()) {
// Admin Users Don't need to filter the results
return result.createResponseEntity(getPageStream(node));
} else {
// Limit our results based on the fact that our permissions should be in the permissions strings
node = addPermissionsFilter(node, user);
DataPointStreamCallback callback = new DataPointStreamCallback(this, user);
FilteredPageQueryStream<DataPointVO, DataPointModel, DataPointDao> stream = new FilteredPageQueryStream<DataPointVO, DataPointModel, DataPointDao>(DataPointDao.instance, this, node, callback);
stream.setupQuery();
return result.createResponseEntity(stream);
}
} catch (InvalidRQLRestException e) {
LOG.error(e.getMessage(), e);
result.addRestMessage(getInternalServerErrorMessage(e.getMessage()));
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-modules-public by infiniteautomation.
the class DataPointRestController method updateDataPoint.
/**
* Update a data point in the system
* @param vo
* @param xid
* @param builder
* @param request
* @return
*/
@ApiOperation(value = "Update an existing data point", notes = "Content may be CSV or JSON")
@RequestMapping(method = RequestMethod.PUT, consumes = { "application/json", "text/csv", "application/sero-json" }, produces = { "application/json", "text/csv", "application/sero-json" }, value = "/{xid}")
public ResponseEntity<DataPointModel> updateDataPoint(@PathVariable String xid, @ApiParam(value = "Updated data point model", required = true) @RequestBody(required = true) DataPointModel model, UriComponentsBuilder builder, HttpServletRequest request) {
RestProcessResult<DataPointModel> result = new RestProcessResult<DataPointModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
boolean contentTypeCsv = false;
if (request.getContentType().toLowerCase().contains("text/csv"))
contentTypeCsv = true;
DataPointVO vo = model.getData();
DataPointVO existingDp = DataPointDao.instance.getByXid(xid);
if (existingDp == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
// We will always override the DS Info with the one from the XID Lookup
DataSourceVO<?> dsvo = DataSourceDao.instance.getDataSource(existingDp.getDataSourceXid());
// TODO this implies that we may need to have a different JSON Converter for data points
// Need to set DataSourceId among other things
vo.setDataSourceId(existingDp.getDataSourceId());
// Check permissions
try {
if (!Permissions.hasDataSourcePermission(user, vo.getDataSourceId())) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} catch (PermissionException e) {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
vo.setId(existingDp.getId());
// Set all properties that are not in the template or the spreadsheet
// Use ID to get detectors
DataPointDao.instance.setEventDetectors(vo);
vo.setPointFolderId(existingDp.getPointFolderId());
if (vo.getTextRenderer() == null) {
vo.setTextRenderer(new PlainRenderer());
}
if (vo.getChartColour() == null) {
vo.setChartColour("");
}
// Check the Template and see if we need to use it
if (model.getTemplateXid() != null) {
DataPointPropertiesTemplateVO template = (DataPointPropertiesTemplateVO) TemplateDao.instance.getByXid(model.getTemplateXid());
if (template != null) {
template.updateDataPointVO(vo);
template.updateDataPointVO(model.getData());
} else {
model.addValidationMessage("validate.invalidReference", RestMessageLevel.ERROR, "templateXid");
result.addRestMessage(new RestMessage(HttpStatus.NOT_ACCEPTABLE, new TranslatableMessage("emport.dataPoint.badReference", model.getTemplateXid())));
}
} else {
if (contentTypeCsv) {
model.addValidationMessage("validate.required", RestMessageLevel.ERROR, "templateXid");
result.addRestMessage(this.getValidationFailedError());
return result.createResponseEntity(model);
}
}
if (!model.validate()) {
result.addRestMessage(this.getValidationFailedError());
return result.createResponseEntity(model);
} else {
if (dsvo == null) {
result.addRestMessage(HttpStatus.NOT_ACCEPTABLE, new TranslatableMessage("emport.dataPoint.badReference", xid));
return result.createResponseEntity();
} else {
// Does the old point have a different data source?
if (existingDp.getDataSourceId() != dsvo.getId()) {
vo.setDataSourceId(dsvo.getId());
vo.setDataSourceName(dsvo.getName());
}
}
Common.runtimeManager.saveDataPoint(vo);
}
// Put a link to the updated data in the header?
URI location = builder.path("/v1/data-points/{xid}").buildAndExpand(vo.getXid()).toUri();
result.addRestMessage(getResourceUpdatedMessage(location));
return result.createResponseEntity(model);
}
// Not logged in
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.DataPointVO in project ma-modules-public by infiniteautomation.
the class DataPointRestController method query.
@ApiOperation(value = "Query Data Points", notes = "", response = DataPointModel.class, responseContainer = "Array")
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/query")
public ResponseEntity<QueryDataPageStream<DataPointVO>> query(@ApiParam(value = "Query", required = true) @RequestBody(required = true) ASTNode root, HttpServletRequest request) {
RestProcessResult<QueryDataPageStream<DataPointVO>> result = new RestProcessResult<QueryDataPageStream<DataPointVO>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
// 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);
if (!user.isAdmin()) {
// Limit our results based on the fact that our permissions should be in the permissions strings
root = addPermissionsFilter(root, user);
FilteredPageQueryStream<DataPointVO, DataPointModel, DataPointDao> stream = new FilteredPageQueryStream<DataPointVO, DataPointModel, DataPointDao>(DataPointDao.instance, this, root, callback);
stream.setupQuery();
return result.createResponseEntity(stream);
} else {
// Admin Users Don't need to filter the results
return result.createResponseEntity(getPageStream(root));
}
}
return result.createResponseEntity();
}
Aggregations