use of com.wordnik.swagger.annotations.ApiOperation 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.wordnik.swagger.annotations.ApiOperation in project ma-modules-public by infiniteautomation.
the class DataPointRestController method getBulkDataPointOperations.
@ApiOperation(value = "Get a list of current bulk data point operations", notes = "User can only get their own bulk data point operations unless they are an admin")
@RequestMapping(method = RequestMethod.GET, value = "/bulk")
public MappingJacksonValue getBulkDataPointOperations(@AuthenticationPrincipal User user, HttpServletRequest request) {
List<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>> preFiltered = this.bulkResourceManager.list().stream().filter((tr) -> user.isAdmin() || user.getId() == tr.getUserId()).collect(Collectors.toList());
List<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>> results = preFiltered;
ASTNode query = BaseMangoRestController.parseRQLtoAST(request.getQueryString());
if (query != null) {
results = query.accept(new RQLToObjectListQuery<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>>(), preFiltered);
}
PageQueryResultModel<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>> result = new PageQueryResultModel<>(results, preFiltered.size());
// hide result property by setting a view
MappingJacksonValue resultWithView = new MappingJacksonValue(result);
resultWithView.setSerializationView(Object.class);
return resultWithView;
}
use of com.wordnik.swagger.annotations.ApiOperation in project ma-modules-public by infiniteautomation.
the class DataPointRestController method bulkDataPointOperation.
@ApiOperation(value = "Bulk get/create/update/delete data points", notes = "User must have read/edit permission for the data point")
@RequestMapping(method = RequestMethod.POST, value = "/bulk")
public ResponseEntity<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>> bulkDataPointOperation(@RequestBody DataPointBulkRequest requestBody, @AuthenticationPrincipal User user, UriComponentsBuilder builder) {
VoAction defaultAction = requestBody.getAction();
DataPointModel defaultBody = requestBody.getBody();
List<DataPointIndividualRequest> requests = requestBody.getRequests();
if (requests == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "requests"));
}
String resourceId = requestBody.getId();
Long expiration = requestBody.getExpiration();
Long timeout = requestBody.getTimeout();
TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception> responseBody = bulkResourceManager.newTemporaryResource(RESOURCE_TYPE_BULK_DATA_POINT, resourceId, user.getId(), expiration, timeout, (resource) -> {
DataPointBulkResponse bulkResponse = new DataPointBulkResponse();
int i = 0;
resource.progress(bulkResponse, i++, requests.size());
for (DataPointIndividualRequest request : requests) {
UriComponentsBuilder reqBuilder = UriComponentsBuilder.newInstance();
DataPointIndividualResponse individualResponse = doIndividualRequest(request, defaultAction, defaultBody, user, reqBuilder);
bulkResponse.addResponse(individualResponse);
resource.progressOrSuccess(bulkResponse, i++, requests.size());
}
});
HttpHeaders headers = new HttpHeaders();
headers.setLocation(builder.path("/v2/data-points/bulk/{id}").buildAndExpand(responseBody.getId()).toUri());
return new ResponseEntity<TemporaryResource<DataPointBulkResponse, AbstractRestV2Exception>>(responseBody, headers, HttpStatus.CREATED);
}
use of com.wordnik.swagger.annotations.ApiOperation 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.wordnik.swagger.annotations.ApiOperation 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);
}
Aggregations