use of com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class DataPointRestController method enableDisable.
@ApiOperation(value = "Enable/disable/restart a data point")
@RequestMapping(method = RequestMethod.PUT, value = "/enable-disable/{xid}")
public ResponseEntity<Void> enableDisable(@AuthenticationPrincipal User user, @PathVariable String xid, @ApiParam(value = "Enable or disable the data point", required = true, allowMultiple = false) @RequestParam(required = true) boolean enabled, @ApiParam(value = "Restart the data point, enabled must equal true", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean restart) {
DataPointVO dataPoint = DataPointDao.instance.getByXid(xid);
if (dataPoint == null) {
throw new NotFoundRestException();
}
Permissions.ensureDataSourcePermission(user, dataPoint.getDataSourceId());
if (enabled && restart) {
Common.runtimeManager.restartDataPoint(dataPoint);
} else {
Common.runtimeManager.enableDataPoint(dataPoint, enabled);
}
return new ResponseEntity<>(HttpStatus.OK);
}
use of com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException 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.infiniteautomation.mango.rest.v2.exception.NotFoundRestException 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.infiniteautomation.mango.rest.v2.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class EventDetectorRestV2Controller method getForDataPoint.
@ApiOperation(value = "Get all Event Detectors for a given data point", notes = "", response = AbstractEventDetectorModel.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET, value = "/data-point/{xid}")
public ResponseEntity<List<AbstractEventDetectorModel<?>>> getForDataPoint(@AuthenticationPrincipal User user, @ApiParam(value = "Valid Data Point XID", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
DataPointVO dp = DataPointDao.instance.getByXid(xid);
if (dp == null)
throw new NotFoundRestException();
// Check permissions
if (!user.isAdmin())
Permissions.ensureDataPointReadPermission(user, dp);
DataPointDao.instance.setEventDetectors(dp);
List<AbstractEventDetectorModel<?>> models = new ArrayList<AbstractEventDetectorModel<?>>();
for (AbstractPointEventDetectorVO<?> ped : dp.getEventDetectors()) models.add(ped.asModel());
return new ResponseEntity<>(models, HttpStatus.OK);
}
use of com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class EventDetectorRestV2Controller method delete.
@ApiOperation(value = "Delete an Event Detector", notes = "")
@RequestMapping(method = RequestMethod.DELETE, value = { "/{xid}" })
public ResponseEntity<AbstractEventDetectorModel<?>> delete(@ApiParam(value = "Valid Event Detector XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal User user, UriComponentsBuilder builder, HttpServletRequest request) {
// Check to see if it already exists
AbstractEventDetectorVO<?> existing = this.dao.getByXid(xid);
if (existing == null) {
throw new NotFoundRestException();
}
// Check permission
DataPointVO dp = DataPointDao.instance.get(existing.getSourceId());
Permissions.ensureDataSourcePermission(user, dp.getDataSourceId());
// TODO Fix this when we have other types of detectors
AbstractPointEventDetectorVO<?> ped = (AbstractPointEventDetectorVO<?>) existing;
ped.njbSetDataPoint(dp);
// Remove it from the data point, if it isn't replaced we fail.
boolean removed = false;
DataPointDao.instance.setEventDetectors(dp);
ListIterator<AbstractPointEventDetectorVO<?>> it = dp.getEventDetectors().listIterator();
while (it.hasNext()) {
AbstractPointEventDetectorVO<?> ed = it.next();
if (ed.getId() == ped.getId()) {
it.remove();
removed = true;
break;
}
}
if (!removed)
throw new ServerErrorException(new TranslatableMessage("rest.error.eventDetectorNotAssignedToThisPoint"));
// Save the data point
Common.runtimeManager.saveDataPoint(dp);
return new ResponseEntity<>(existing.asModel(), HttpStatus.OK);
}
Aggregations