use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.
the class DataSourceRestController method deleteDataSource.
@ApiOperation(value = "Delete data source")
@RequestMapping(method = { RequestMethod.DELETE }, value = { "/{xid}" }, produces = { "application/json" })
public ResponseEntity<AbstractDataSourceModel<?>> deleteDataSource(@PathVariable String xid, UriComponentsBuilder builder, HttpServletRequest request) {
RestProcessResult<AbstractDataSourceModel<?>> result = new RestProcessResult<AbstractDataSourceModel<?>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
DataSourceVO<?> existing = (DataSourceVO<?>) DataSourceDao.instance.getByXid(xid);
if (existing == null) {
result.addRestMessage(this.getDoesNotExistMessage());
return result.createResponseEntity();
} else {
try {
if (!Permissions.hasDataSourcePermission(user, existing.getId())) {
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
}
} catch (PermissionException pe) {
LOG.warn(pe.getMessage(), pe);
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
}
Common.runtimeManager.deleteDataSource(existing.getId());
return result.createResponseEntity(existing.asModel());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.
the class DataSourceRestController method getAllDataSources.
@ApiOperation(value = "Get all data sources", notes = "Only returns data sources available to logged in user")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/list")
@ResponseStatus(HttpStatus.OK)
public ResponseEntity<List<AbstractDataSourceModel<?>>> getAllDataSources(HttpServletRequest request) {
RestProcessResult<List<AbstractDataSourceModel<?>>> result = new RestProcessResult<List<AbstractDataSourceModel<?>>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
List<DataSourceVO<?>> dataSources = DataSourceDao.instance.getAll();
List<AbstractDataSourceModel<?>> models = new ArrayList<AbstractDataSourceModel<?>>();
for (DataSourceVO<?> ds : dataSources) {
try {
if (Permissions.hasDataSourcePermission(user, ds))
models.add(ds.asModel());
} catch (PermissionException e) {
// Munch Munch
}
}
return result.createResponseEntity(models);
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.
the class DataPointRestController method createDataPoint.
@ApiOperation(value = "Create a new data point")
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<DataPointModel> createDataPoint(@ApiParam(value = "Data point model", required = true) @RequestBody(required = true) DataPointModel model, @AuthenticationPrincipal User user, UriComponentsBuilder builder) {
DataSourceVO<?> dataSource = DataSourceDao.instance.getByXid(model.getDataSourceXid());
if (dataSource == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.invalidDataSourceXid"));
}
Permissions.ensureDataSourcePermission(user, dataSource);
DataPointVO dataPoint = new DataPointVO(dataSource);
model.copyPropertiesTo(dataPoint);
if (model.getTemplateXid() != null) {
DataPointPropertiesTemplateVO template = (DataPointPropertiesTemplateVO) TemplateDao.instance.getByXid(model.getTemplateXid());
if (template == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.invalidTemplateXid"));
}
dataPoint.withTemplate(template);
}
dataPoint.ensureValid();
Common.runtimeManager.saveDataPoint(dataPoint);
URI location = builder.path("/v2/data-points/{xid}").buildAndExpand(dataPoint.getXid()).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(new DataPointModel(dataPoint), headers, HttpStatus.CREATED);
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.
the class EventDetectorRestV2Controller method getForDataSource.
@ApiOperation(value = "Get all Event Detectors for a given data source", notes = "Must have permission for all data points", response = AbstractEventDetectorModel.class, responseContainer = "List")
@RequestMapping(method = RequestMethod.GET, value = "/data-source/{xid}")
public ResponseEntity<List<AbstractEventDetectorModel<?>>> getForDataSource(@AuthenticationPrincipal User user, @ApiParam(value = "Valid Data Source XID", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
DataSourceVO<?> ds = DataSourceDao.instance.getByXid(xid);
if (ds == null)
throw new NotFoundRestException();
List<DataPointVO> points = DataPointDao.instance.getDataPoints(ds.getId(), null, false);
List<AbstractEventDetectorModel<?>> models = new ArrayList<AbstractEventDetectorModel<?>>();
for (DataPointVO dp : points) {
// Check permissions
if (!user.isAdmin())
Permissions.ensureDataPointReadPermission(user, dp);
DataPointDao.instance.setEventDetectors(dp);
for (AbstractPointEventDetectorVO<?> ped : dp.getEventDetectors()) models.add(ped.asModel());
}
return new ResponseEntity<>(models, HttpStatus.OK);
}
use of com.serotonin.m2m2.vo.dataSource.DataSourceVO in project ma-modules-public by infiniteautomation.
the class EventTypeV2RestController method getAllDataSourceEventTypes.
private void getAllDataSourceEventTypes(List<EventTypeModel> types, User user, Integer dataSourceId, Integer dataSourceEventId) {
List<DataSourceVO<?>> dataSources = DataSourceDao.instance.getAll();
final boolean admin = Permissions.hasAdmin(user);
for (DataSourceVO<?> dsvo : dataSources) if (dataSourceId == null || dataSourceId.intValue() == dsvo.getId())
for (EventTypeVO dset : (List<EventTypeVO>) dsvo.getEventTypes()) if (dataSourceEventId == null || dataSourceEventId.intValue() == dset.getTypeRef2()) {
EventType et = dset.createEventType();
if (admin || Permissions.hasEventTypePermission(user, et))
types.add(et.asModel());
}
}
Aggregations