use of com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource.TemporaryResourceStatus in project ma-modules-public by infiniteautomation.
the class TemporaryResourceWebSocketHandler method notifySession.
private void notifySession(WebSocketSession session, CrudNotificationType type, TemporaryResource<?, ?> resource) throws JsonProcessingException, IOException {
PermissionHolder user = this.getUser(session);
TemporaryResourceSubscription subscription = (TemporaryResourceSubscription) session.getAttributes().get(SUBSCRIPTION_ATTRIBUTE);
boolean hasAccess = permissionService.hasAccessToResource(user, resource);
boolean isOwner = resource.isOwnedBy(user);
if (hasAccess && (!subscription.isOwnResourcesOnly() || isOwner)) {
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.sendRawMessageUsingView(session, notificationMessage, view);
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("Error notifying session " + session.getId() + " of change to resource " + resource, e);
}
}
}
}
}
Aggregations