use of com.infiniteautomation.mango.rest.v2.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 {
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);
}
}
}
}
}
Aggregations