<commit_before>package controllers;

import org.codehaus.jackson.JsonNode;

import play.libs.Json;

import com.blopker.wamplay.annotations.ControllerURIPrefix;
import com.blopker.wamplay.annotations.onPublish;
import com.blopker.wamplay.annotations.onSubscribe;
import com.blopker.wamplay.controllers.WAMPlayContoller;

// Prefix is optional, but helps remove duplicate code.
@ControllerURIPrefix("http://example.com/")
public class PubSub extends WAMPlayContoller {
	static int MAX_MESSAGE_LENGTH = 10;
	
	/**
	 * Method that truncates an event message before it's published. 
	 * @param client WAMP client that sent the event
	 * @param event Event to be truncated
	 * @return Modified json event, null to halt publish
	 */
	@onPublish("truncate")
	public static JsonNode truncatePublish(String sessionID, JsonNode event) {
		if (!event.isTextual()) {
			return cancel();
		}		
		String message = event.asText();
		if (message.length() > 10) {
			message = message.substring(0, MAX_MESSAGE_LENGTH);
		}
		return Json.toJson(message);
	}
	
	/**
	 * Only one onPublish or onSubscribe annotation is necessary to create a topic.
	 * @param subscribingClient
	 * @return True if client is allowed to subscribe, false otherwise.
	 */
	@onSubscribe("truncate")
	public static boolean capitalSubscribe(String sessionID) {
		return true;
	}
}
<commit_msg>tag 0.0.4<commit_after>package controllers;

import org.codehaus.jackson.JsonNode;

import play.libs.Json;

import com.blopker.wamplay.annotations.URIPrefix;
import com.blopker.wamplay.annotations.onPublish;
import com.blopker.wamplay.annotations.onSubscribe;
import com.blopker.wamplay.controllers.WAMPlayContoller;

// Prefix is optional, but helps remove duplicate code.
@URIPrefix("http://example.com/")
public class PubSub extends WAMPlayContoller {
	static int MAX_MESSAGE_LENGTH = 10;
	
	/**
	 * Method that truncates an event message before it's published. 
	 * @param client WAMP client that sent the event
	 * @param event Event to be truncated
	 * @return Modified json event, null to halt publish
	 */
	@onPublish("truncate")
	public static JsonNode truncatePublish(String sessionID, JsonNode event) {
		if (!event.isTextual()) {
			return cancel();
		}		
		String message = event.asText();
		if (message.length() > 10) {
			message = message.substring(0, MAX_MESSAGE_LENGTH);
		}
		return Json.toJson(message);
	}
	
	/**
	 * Only one onPublish or onSubscribe annotation is necessary to create a topic.
	 * @param subscribingClient
	 * @return True if client is allowed to subscribe, false otherwise.
	 */
	@onSubscribe("truncate")
	public static boolean capitalSubscribe(String sessionID) {
		return true;
	}
}

{'fraction_non_alphanumeric': 0.09880239520958084, 'fraction_numerical': 0.0048652694610778445, 'mean_word_length': 4.477459016393443, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1446982', 'n_tokens_mistral': 889, 'n_tokens_neox': 801, 'n_words': 237}