<commit_before>package nl.sense_os.commonsense.server;

import java.io.IOException;
import java.util.Date;
import java.util.Random;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.repackaged.org.json.JSONArray;
import com.google.appengine.repackaged.org.json.JSONException;
import com.google.appengine.repackaged.org.json.JSONObject;


@SuppressWarnings("serial")
public class IVOServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
		resp.setContentType("text/plain");
		try {
			JSONObject json = new JSONObject(req.getParameter("changes"));
			resp.getWriter().println(json.toString());
			resp.getWriter().println(extract(json));
		} catch (JSONException e) {
			resp.getWriter().println("OOPS! sorry, something went wrong here. Did you submit valid JSON?");
		}		
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
		resp.setContentType("text/plain");
		doGet(req, resp);
	}
	
	private String extract(JSONObject json) {
		JSONObject result = new JSONObject();
		Random rnd = new Random(new Date().getTime());
		JSONArray ar;
		int i;
		
		// Creates
		JSONArray creates = new JSONArray(); 
		try {
			ar = (JSONArray) json.get("CREATE");
			for (i = 0; i < ar.length(); i++) {
				int userId = rnd.nextInt(100)+50;
				JSONObject create = new JSONObject();
				create.put("userId", userId);
				creates.put(create);
			}
			result.put("CREATE", creates);
		} catch (JSONException e) {
		}
		
		// Updates
		JSONArray updates = new JSONArray();
		try {
			ar = (JSONArray) json.get("UPDATE");
			for (i = 0; i < ar.length(); i++) {
				int userId = ((JSONObject) ((JSONObject) ar.get(i)).get("old")).getInt("userId");
				JSONObject update = new JSONObject();
				update.put("userId", userId);
				updates.put(update);
			}
			result.put("UPDATE", updates);
		} catch (JSONException e) {
		}

		// Deletes
		JSONArray deletes = new JSONArray();
		try {
			ar = (JSONArray) json.get("DELETE");
			for (i = 0; i < ar.length(); i++) {
				int userId = ((JSONObject) ar.get(i)).getInt("userId");
				JSONObject delete = new JSONObject();
				delete.put("userId", userId);
				deletes.put(delete);
			}
			result.put("DELETE", updates);
		} catch (JSONException e) {
		}
		return result.toString();
	}	
}<commit_msg>update IVO servlet<commit_after>package nl.sense_os.commonsense.server;

import java.io.IOException;
import java.util.Date;
import java.util.Random;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.repackaged.org.json.JSONArray;
import com.google.appengine.repackaged.org.json.JSONException;
import com.google.appengine.repackaged.org.json.JSONObject;


@SuppressWarnings("serial")
public class IVOServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
		resp.setContentType("text/plain");
		try {
			JSONArray changes = new JSONArray(req.getParameter("changes"));
			//resp.getWriter().println(json.toString());
			resp.getWriter().println(extract(changes));
		} catch (JSONException e) {
			resp.getWriter().println("OOPS! sorry, something went wrong here. Did you submit valid JSON?");
		}		
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
    throws IOException {
		resp.setContentType("text/plain");
		doGet(req, resp);
	}
	
	private String extract(JSONArray changes) {
		JSONArray result = new JSONArray();
		Random rnd = new Random(new Date().getTime());
		int i;

		for (i = 0; i < changes.length(); i++) {
			try {
				JSONObject change = (JSONObject) changes.get(i);
				JSONObject createContainer = new JSONObject();
				JSONObject create = new JSONObject();
				if (change.has("CREATE")) {
					change = (JSONObject) change.get("CREATE");
					int userId = rnd.nextInt(100)+50;
					create.put("userId", userId);
					createContainer.put("CREATE", create);
					result.put(createContainer);
				}
				if (change.has("UPDATE")) {
					change = (JSONObject) change.get("UPDATE");
					int userId = ((JSONObject) change.get("old")).getInt("userId");
					create.put("userId", userId);
					createContainer.put("UPDATE", create);
					result.put(createContainer);
				}
				if (change.has("DELETE")) {
					change = (JSONObject) change.get("DELETE");
					int userId = change.getInt("userId");
					create.put("userId", userId);
					createContainer.put("DELETE", create);
					result.put(createContainer);
				}
			} catch (JSONException e) {
			}
		}	
		return result.toString();
	}
}
{'fraction_non_alphanumeric': 0.1454736842105263, 'fraction_numerical': 0.0029473684210526317, 'mean_word_length': 4.092175777063237, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3827859', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1483, 'n_words': 327}