Search in sources :

Example 1 with TemporaryResourceStatus

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);
                }
            }
        }
    }
}
Also used : User(com.serotonin.m2m2.vo.User) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TemporaryResourceStatus(com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource.TemporaryResourceStatus)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TemporaryResourceStatus (com.infiniteautomation.mango.rest.v2.temporaryResource.TemporaryResource.TemporaryResourceStatus)1 User (com.serotonin.m2m2.vo.User)1 IOException (java.io.IOException)1