private WebSocketMessage getMessageForEvent(final SecurityContext securityContext, final ModificationEvent modificationEvent) throws FrameworkException {

		final String callbackId = modificationEvent.getCallbackId();

		if (modificationEvent.isNode()) {

			final NodeInterface node = (NodeInterface) modificationEvent.getGraphObject();

			if (modificationEvent.isDeleted()) {

				final WebSocketMessage message = createMessage("DELETE", callbackId);

				message.setId(modificationEvent.getRemovedProperties().get(GraphObject.id));
				message.setCode(200);

				return message;
			}

			if (modificationEvent.isCreated()) {

				final WebSocketMessage message = createMessage("CREATE", callbackId);

				message.setGraphObject(node);
				message.setResult(Arrays.asList(node));
				message.setCode(201);

				return message;
			}

			if (modificationEvent.isModified()) {

				final WebSocketMessage message = createMessage("UPDATE", callbackId);

				// at login the securityContext is still null
				if (securityContext != null) {

					// only include changed properties (+ id and type)
					final LinkedHashSet<String> propertySet = new LinkedHashSet();

					propertySet.add("id");
					propertySet.add("type");

					for (Iterator<PropertyKey> it = modificationEvent.getModifiedProperties().keySet().iterator(); it.hasNext(); ) {

						final String jsonName = ((PropertyKey)it.next()).jsonName();
						if (!propertySet.contains(jsonName)) {

							propertySet.add(jsonName);
						}
					}

					for (Iterator<PropertyKey> it = modificationEvent.getRemovedProperties().keySet().iterator(); it.hasNext(); ) {

						final String jsonName = ((PropertyKey)it.next()).jsonName();
						if (!propertySet.contains(jsonName)) {

							propertySet.add(jsonName);
						}
					}

					if (propertySet.size() > 2) {
						securityContext.setCustomView(propertySet);
					}
				}

				message.setGraphObject(node);
				message.setResult(Arrays.asList(node));
				message.setId(node.getUuid());
				message.getModifiedProperties().addAll(modificationEvent.getModifiedProperties().keySet());
				message.getRemovedProperties().addAll(modificationEvent.getRemovedProperties().keySet());
				message.setNodeData(modificationEvent.getData(securityContext));
				message.setCode(200);

				if (securityContext != null) {
					// Clear custom view here. This is necessary because the security context is reused for all websocket frames.
					securityContext.clearCustomView();
				}

				return message;
			}

		} else {

			// handle relationship
			final RelationshipInterface relationship = (RelationshipInterface) modificationEvent.getGraphObject();
			final RelationshipType relType = modificationEvent.getRelationshipType();

			// special treatment of CONTAINS relationships
			if ("CONTAINS".equals(relType.name())) {

				if (modificationEvent.isDeleted()) {

					final WebSocketMessage message = createMessage("REMOVE_CHILD", callbackId);

					message.setNodeData("parentId", relationship.getSourceNodeId());
					message.setId(relationship.getTargetNodeId());
					message.setCode(200);

					return message;
				}

				if (modificationEvent.isCreated()) {

					final WebSocketMessage message = new WebSocketMessage();
					final NodeInterface startNode = relationship.getSourceNode();
					final NodeInterface endNode = relationship.getTargetNode();

					// If either start or end node are not visible for the user to be notified,
					// don't send a notification
					if (startNode == null || endNode == null) {
						return null;
					}

					message.setResult(Arrays.asList(new GraphObject[]{endNode}));
					message.setId(endNode.getUuid());
					message.setNodeData("parentId", startNode.getUuid());

					message.setCode(200);
					message.setCommand("APPEND_CHILD");

					if (endNode instanceof DOMNode) {

						org.w3c.dom.Node refNode = ((DOMNode) endNode).getNextSibling();
						if (refNode != null) {

							message.setCommand("INSERT_BEFORE");
							message.setNodeData("refId", ((AbstractNode) refNode).getUuid());
						}

					} else if (endNode instanceof User || endNode instanceof Group) {

						message.setCommand("APPEND_MEMBER");
						message.setNodeData("refId", startNode.getUuid());

					} else if (endNode instanceof AbstractFile) {

						message.setCommand("APPEND_FILE");
						message.setNodeData("refId", startNode.getUuid());
					}

					return message;
				}
			}

			if (modificationEvent.isDeleted()) {

				final WebSocketMessage message = createMessage("DELETE", callbackId);
				message.setId(modificationEvent.getRemovedProperties().get(GraphObject.id));
				message.setCode(200);

				return message;
			}

			if (modificationEvent.isModified()) {

				final WebSocketMessage message = createMessage("UPDATE", callbackId);

				message.getModifiedProperties().addAll(modificationEvent.getModifiedProperties().keySet());
				message.getRemovedProperties().addAll(modificationEvent.getRemovedProperties().keySet());
				message.setNodeData(modificationEvent.getData(securityContext));

				message.setGraphObject(relationship);
				message.setId(relationship.getUuid());
				message.setCode(200);

				final PropertyMap relProperties = relationship.getProperties();
				//final NodeInterface startNode = relationship.getSourceNode();
				//final NodeInterface endNode = relationship.getTargetNode();

				//relProperties.put(new StringProperty("startNodeId"), startNode.getUuid());
				//relProperties.put(new StringProperty("endNodeId"), endNode.getUuid());

				final Map<String, Object> properties = PropertyMap.javaTypeToInputType(securityContext, relationship.getClass(), relProperties);

				message.setRelData(properties);

				return message;
			}

		}

		return null;
	}
private WebSocketMessage getMessageForEvent ( final SecurityContext securityContext , final ModificationEvent modificationEvent ) throws FrameworkException { final String callbackId = modificationEvent . getCallbackId ( ) ; if ( modificationEvent . isNode ( ) ) { final NodeInterface node = ( NodeInterface ) modificationEvent . getGraphObject ( ) ; if ( modificationEvent . isDeleted ( ) ) { final WebSocketMessage message = createMessage ( "DELETE" , callbackId ) ; message . setId ( modificationEvent . getRemovedProperties ( ) . get ( GraphObject . id ) ) ; message . setCode ( 200 ) ; return message ; } if ( modificationEvent . isCreated ( ) ) { final WebSocketMessage message = createMessage ( "CREATE" , callbackId ) ; message . setGraphObject ( node ) ; message . setResult ( Arrays . asList ( node ) ) ; message . setCode ( 201 ) ; return message ; } if ( modificationEvent . isModified ( ) ) { final WebSocketMessage message = createMessage ( "UPDATE" , callbackId ) ; if ( securityContext != null ) { final LinkedHashSet < String > propertySet = new LinkedHashSet ( ) ; propertySet . add ( "id" ) ; propertySet . add ( "type" ) ; for ( Iterator < PropertyKey > it = modificationEvent . getModifiedProperties ( ) . keySet ( ) . iterator ( ) ; it . hasNext ( ) ; ) { final String jsonName = ( ( PropertyKey ) it . next ( ) ) . jsonName ( ) ; if ( ! propertySet . contains ( jsonName ) ) { propertySet . add ( jsonName ) ; } } for ( Iterator < PropertyKey > it = modificationEvent . getRemovedProperties ( ) . keySet ( ) . iterator ( ) ; it . hasNext ( ) ; ) { final String jsonName = ( ( PropertyKey ) it . next ( ) ) . jsonName ( ) ; if ( ! propertySet . contains ( jsonName ) ) { propertySet . add ( jsonName ) ; } } if ( propertySet . size ( ) > 2 ) { securityContext . setCustomView ( propertySet ) ; } } message . setGraphObject ( node ) ; message . setResult ( Arrays . asList ( node ) ) ; message . setId ( node . getUuid ( ) ) ; message . getModifiedProperties ( ) . addAll ( modificationEvent . getModifiedProperties ( ) . keySet ( ) ) ; message . getRemovedProperties ( ) . addAll ( modificationEvent . getRemovedProperties ( ) . keySet ( ) ) ; message . setNodeData ( modificationEvent . getData ( securityContext ) ) ; message . setCode ( 200 ) ; if ( securityContext != null ) { securityContext . clearCustomView ( ) ; } return message ; } } else { final RelationshipInterface relationship = ( RelationshipInterface ) modificationEvent . getGraphObject ( ) ; final RelationshipType relType = modificationEvent . getRelationshipType ( ) ; if ( "CONTAINS" . equals ( relType . name ( ) ) ) { if ( modificationEvent . isDeleted ( ) ) { final WebSocketMessage message = createMessage ( "REMOVE_CHILD" , callbackId ) ; message . setNodeData ( "parentId" , relationship . getSourceNodeId ( ) ) ; message . setId ( relationship . getTargetNodeId ( ) ) ; message . setCode ( 200 ) ; return message ; } if ( modificationEvent . isCreated ( ) ) { final WebSocketMessage message = new WebSocketMessage ( ) ; final NodeInterface startNode = relationship . getSourceNode ( ) ; final NodeInterface endNode = relationship . getTargetNode ( ) ; if ( startNode == null || endNode == null ) { return null ; } message . setResult ( Arrays . asList ( new GraphObject [ ] { endNode } ) ) ; message . setId ( endNode . getUuid ( ) ) ; message . setNodeData ( "parentId" , startNode . getUuid ( ) ) ; message . setCode ( 200 ) ; message . setCommand ( "APPEND_CHILD" ) ; if ( endNode instanceof DOMNode ) { org . w3c . dom . Node refNode = ( ( DOMNode ) endNode ) . getNextSibling ( ) ; if ( refNode != null ) { message . setCommand ( "INSERT_BEFORE" ) ; message . setNodeData ( "refId" , ( ( AbstractNode ) refNode ) . getUuid ( ) ) ; } } else if ( endNode instanceof User || endNode instanceof Group ) { message . setCommand ( "APPEND_MEMBER" ) ; message . setNodeData ( "refId" , startNode . getUuid ( ) ) ; } else if ( endNode instanceof AbstractFile ) { message . setCommand ( "APPEND_FILE" ) ; message . setNodeData ( "refId" , startNode . getUuid ( ) ) ; } return message ; } } if ( modificationEvent . isDeleted ( ) ) { final WebSocketMessage message = createMessage ( "DELETE" , callbackId ) ; message . setId ( modificationEvent . getRemovedProperties ( ) . get ( GraphObject . id ) ) ; message . setCode ( 200 ) ; return message ; } if ( modificationEvent . isModified ( ) ) { final WebSocketMessage message = createMessage ( "UPDATE" , callbackId ) ; message . getModifiedProperties ( ) . addAll ( modificationEvent . getModifiedProperties ( ) . keySet ( ) ) ; message . getRemovedProperties ( ) . addAll ( modificationEvent . getRemovedProperties ( ) . keySet ( ) ) ; message . setNodeData ( modificationEvent . getData ( securityContext ) ) ; message . setGraphObject ( relationship ) ; message . setId ( relationship . getUuid ( ) ) ; message . setCode ( 200 ) ; final PropertyMap relProperties = relationship . getProperties ( ) ; final Map < String , Object > properties = PropertyMap . javaTypeToInputType ( securityContext , relationship . getClass ( ) , relProperties ) ; message . setRelData ( properties ) ; return message ; } } return null ; }
----- private methods -----