use of com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource in project ma-modules-public by infiniteautomation.
the class TemporaryResourceWebSocketHandler method notifySession.
private void notifySession(WebSocketSession session, CrudNotificationType type, TemporaryResource<?, ?> resource) throws JsonProcessingException, IOException {
User user = this.getUser(session);
if (user == null)
return;
TemporaryResourceSubscription subscription = (TemporaryResourceSubscription) session.getAttributes().get(SUBSCRIPTION_ATTRIBUTE);
if (resource.getUserId() == user.getId() || (user.isAdmin() && !subscription.isOwnResourcesOnly())) {
Set<TemporaryResourceStatus> statuses = subscription.getStatuses();
Set<String> resourceTypes = subscription.getResourceTypes();
if ((subscription.isAnyStatus() || statuses.contains(resource.getStatus())) && (subscription.isAnyResourceType() || resourceTypes.contains(resource.getResourceType()))) {
WebSocketNotification<TemporaryResource<?, ?>> notificationMessage = new WebSocketNotification<>(type, resource);
boolean showResult = !resource.isComplete() && subscription.isShowResultWhenIncomplete() || resource.isComplete() && subscription.isShowResultWhenComplete();
if (type == CrudNotificationType.DELETE) {
showResult = false;
}
Class<?> view = showResult ? TemporaryResourceViews.ShowResult.class : Object.class;
if (log.isTraceEnabled()) {
log.trace("Notifying session " + session.getId() + " of change to resource " + resource);
}
try {
this.sendMessageUsingView(session, notificationMessage, view);
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("Error notifying session " + session.getId() + " of change to resource " + resource, e);
}
}
}
}
}
use of com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource 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.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource 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.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource in project ma-modules-public by infiniteautomation.
the class DataPointTagsRestController method getBulkDataPointTagOperations.
@ApiOperation(value = "Get a list of current bulk tag operations", notes = "User can only get their own bulk tag operations unless they are an admin")
@RequestMapping(method = RequestMethod.GET, value = "/bulk")
public MappingJacksonValue getBulkDataPointTagOperations(@AuthenticationPrincipal User user, HttpServletRequest request) {
List<TemporaryResource<TagBulkResponse, AbstractRestV2Exception>> preFiltered = this.bulkResourceManager.list().stream().filter((tr) -> user.isAdmin() || user.getId() == tr.getUserId()).collect(Collectors.toList());
List<TemporaryResource<TagBulkResponse, AbstractRestV2Exception>> results = preFiltered;
ASTNode query = BaseMangoRestController.parseRQLtoAST(request.getQueryString());
if (query != null) {
results = query.accept(new RQLToObjectListQuery<TemporaryResource<TagBulkResponse, AbstractRestV2Exception>>(), preFiltered);
}
PageQueryResultModel<TemporaryResource<TagBulkResponse, 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.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource in project ma-modules-public by infiniteautomation.
the class DataPointTagsRestController method bulkDataPointTagOperation.
@ApiOperation(value = "Bulk get/set/add data point tags for a list of XIDs", notes = "User must have read/edit permission for the data point")
@RequestMapping(method = RequestMethod.POST, value = "/bulk")
public ResponseEntity<TemporaryResource<TagBulkResponse, AbstractRestV2Exception>> bulkDataPointTagOperation(@RequestBody TagBulkRequest requestBody, @AuthenticationPrincipal User user, UriComponentsBuilder builder) {
BulkTagAction defaultAction = requestBody.getAction();
Map<String, String> defaultBody = requestBody.getBody();
List<TagIndividualRequest> 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<TagBulkResponse, AbstractRestV2Exception> responseBody = bulkResourceManager.newTemporaryResource(RESOURCE_TYPE_BULK_DATA_POINT_TAGS, resourceId, user.getId(), expiration, timeout, (resource) -> {
TagBulkResponse bulkResponse = new TagBulkResponse();
int i = 0;
resource.progress(bulkResponse, i++, requests.size());
for (TagIndividualRequest request : requests) {
TagIndividualResponse individualResponse = doIndividualRequest(request, defaultAction, defaultBody, user);
bulkResponse.addResponse(individualResponse);
resource.progressOrSuccess(bulkResponse, i++, requests.size());
}
});
HttpHeaders headers = new HttpHeaders();
headers.setLocation(builder.path("/v2/data-point-tags/bulk/{id}").buildAndExpand(responseBody.getId()).toUri());
return new ResponseEntity<TemporaryResource<TagBulkResponse, AbstractRestV2Exception>>(responseBody, headers, HttpStatus.CREATED);
}
Aggregations