Search in sources :

Example 1 with TemporaryResourceStatus

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

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TemporaryResourceStatus (com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource.TemporaryResourceStatus)1 WebSocketNotification (com.infiniteautomation.mango.rest.latest.websocket.WebSocketNotification)1 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)1 IOException (java.io.IOException)1