use of com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel in project ma-modules-public by infiniteautomation.
the class DataPointRestController method getDataPoint.
@ApiOperation(value = "Get data point by XID", notes = "Only points that user has read permission to are returned")
@RequestMapping(method = RequestMethod.GET, value = "/{xid}")
public DataPointModel getDataPoint(@ApiParam(value = "Valid Data Point XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal User user) {
DataPointVO dataPoint = DataPointDao.instance.getByXid(xid);
if (dataPoint == null) {
throw new NotFoundRestException();
}
DataPointDao.instance.loadPartialRelationalData(dataPoint);
Permissions.ensureDataPointReadPermission(user, dataPoint);
return new DataPointModel(dataPoint);
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel in project ma-modules-public by infiniteautomation.
the class DataPointRestController method deleteDataPoint.
@ApiOperation(value = "Delete a data point")
@RequestMapping(method = RequestMethod.DELETE, value = "/{xid}")
public DataPointModel deleteDataPoint(@ApiParam(value = "Valid Data Point XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal User user) {
DataPointVO dataPoint = DataPointDao.instance.getByXid(xid);
if (dataPoint == null) {
throw new NotFoundRestException();
}
Permissions.ensureDataPointReadPermission(user, dataPoint);
Common.runtimeManager.deleteDataPoint(dataPoint);
return new DataPointModel(dataPoint);
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel in project ma-modules-public by infiniteautomation.
the class DataPointRestController method getDataPointById.
@ApiOperation(value = "Get data point by ID", notes = "Only points that user has read permission to are returned")
@RequestMapping(method = RequestMethod.GET, value = "/by-id/{id}")
public DataPointModel getDataPointById(@ApiParam(value = "Valid Data Point ID", required = true, allowMultiple = false) @PathVariable int id, @AuthenticationPrincipal User user) {
DataPointVO dataPoint = DataPointDao.instance.get(id);
if (dataPoint == null) {
throw new NotFoundRestException();
}
DataPointDao.instance.loadPartialRelationalData(dataPoint);
Permissions.ensureDataPointReadPermission(user, dataPoint);
return new DataPointModel(dataPoint);
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel in project ma-modules-public by infiniteautomation.
the class DataPointRestController method doIndividualRequest.
private DataPointIndividualResponse doIndividualRequest(DataPointIndividualRequest request, VoAction defaultAction, DataPointModel defaultBody, User user, UriComponentsBuilder builder) {
DataPointIndividualResponse result = new DataPointIndividualResponse();
try {
String xid = request.getXid();
VoAction action = request.getAction() == null ? defaultAction : request.getAction();
if (action == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "action"));
}
result.setAction(action);
DataPointModel body = request.getBody() == null ? defaultBody : request.getBody();
switch(action) {
case GET:
if (xid == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "xid"));
}
result.setBody(this.getDataPoint(xid, user));
break;
case CREATE:
if (body == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "body"));
}
result.setBody(this.createDataPoint(body, user, builder).getBody());
break;
case UPDATE:
if (xid == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "xid"));
}
if (body == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "body"));
}
result.setBody(this.updateDataPoint(xid, body, user, builder).getBody());
break;
case DELETE:
if (xid == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "xid"));
}
result.setBody(this.deleteDataPoint(xid, user));
break;
}
} catch (Exception e) {
result.exceptionCaught(e);
}
return result;
}
use of com.serotonin.m2m2.web.mvc.rest.v1.model.DataPointModel in project ma-modules-public by infiniteautomation.
the class DataPointRestController method getDataPointsForDataSource.
@ApiOperation(value = "Get all data points for data source", 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 = "/data-source/{xid}")
public ResponseEntity<List<DataPointModel>> getDataPointsForDataSource(@ApiParam(value = "Valid Data Source XID", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
RestProcessResult<List<DataPointModel>> result = new RestProcessResult<List<DataPointModel>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
DataSourceVO<?> dataSource = DataSourceDao.instance.getDataSource(xid);
if (dataSource == null) {
result.addRestMessage(getDoesNotExistMessage());
return result.createResponseEntity();
}
try {
if (!Permissions.hasDataSourcePermission(user, dataSource)) {
LOG.warn("User: " + user.getUsername() + " tried to access data source with xid " + xid);
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
} catch (PermissionException e) {
LOG.warn(e.getMessage(), e);
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
List<DataPointVO> dataPoints = DataPointDao.instance.getDataPoints(dataSource.getId(), null);
List<DataPointModel> userDataPoints = new ArrayList<DataPointModel>();
for (DataPointVO vo : dataPoints) {
try {
if (Permissions.hasDataPointReadPermission(user, vo)) {
userDataPoints.add(new DataPointModel(vo));
}
} catch (PermissionException e) {
// Munched
}
}
result.addRestMessage(getSuccessMessage());
return result.createResponseEntity(userDataPoints);
}
return result.createResponseEntity();
}
Aggregations