<commit_before>package org.pocketcampus.plugin.freeroom.server;

import static org.pocketcampus.platform.launcher.server.PCServerConfig.PC_SRV_CONFIG;

import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import org.apache.thrift.TException;
import org.pocketcampus.platform.sdk.server.database.ConnectionManager;
import org.pocketcampus.platform.sdk.server.database.handlers.exceptions.ServerException;
import org.pocketcampus.plugin.freeroom.server.utils.CheckRequests;
import org.pocketcampus.plugin.freeroom.server.utils.OccupancySorted;
import org.pocketcampus.plugin.freeroom.server.utils.Utils;
import org.pocketcampus.plugin.freeroom.shared.ActualOccupation;
import org.pocketcampus.plugin.freeroom.shared.AutoCompleteReply;
import org.pocketcampus.plugin.freeroom.shared.AutoCompleteRequest;
import org.pocketcampus.plugin.freeroom.shared.AutoCompleteUserMessageReply;
import org.pocketcampus.plugin.freeroom.shared.AutoCompleteUserMessageRequest;
import org.pocketcampus.plugin.freeroom.shared.Constants;
import org.pocketcampus.plugin.freeroom.shared.FRPeriod;
import org.pocketcampus.plugin.freeroom.shared.FRReply;
import org.pocketcampus.plugin.freeroom.shared.FRRequest;
import org.pocketcampus.plugin.freeroom.shared.FRRoom;
import org.pocketcampus.plugin.freeroom.shared.FreeRoomService;
import org.pocketcampus.plugin.freeroom.shared.ImWorkingReply;
import org.pocketcampus.plugin.freeroom.shared.ImWorkingRequest;
import org.pocketcampus.plugin.freeroom.shared.LogMessage;
import org.pocketcampus.plugin.freeroom.shared.Occupancy;
import org.pocketcampus.plugin.freeroom.shared.RegisterUser;
import org.pocketcampus.plugin.freeroom.shared.WhoIsWorkingReply;
import org.pocketcampus.plugin.freeroom.shared.WhoIsWorkingRequest;
import org.pocketcampus.plugin.freeroom.shared.WorkingOccupancy;
import org.pocketcampus.plugin.freeroom.shared.utils.FRTimes;

/**
 * The actual implementation of the server side of the FreeRoom Plugin.
 * 
 * It responds to different types of request from the clients.
 * 
 * @author FreeRoom Project Team (2014/05)
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * 
 */

public class FreeRoomServiceImpl implements FreeRoomService.Iface {

	private final int LIMIT_AUTOCOMPLETE = 50;

	/**
	 * some rooms don't have a capacity, so we display the occupation based on
	 * 40 places, which is probably under-evaluated, so wont create many
	 * issues...
	 */
	int defaultCapacity = 40;

	private ConnectionManager connMgr;
	private Logger logger = Logger.getLogger(FreeRoomServiceImpl.class
			.getName());
	private SimpleDateFormat dateLogFormat = new SimpleDateFormat(
			"MMM dd,yyyy HH:mm");
	private final String LOG_FOLDER = "log";
	private final String PATH_LOG_PATTERN = "./" + LOG_FOLDER
			+ "/freeroom%g.log";
	// total size of log can be MAX_BYTES_PER_LOGFILE * MAX_LOGFILES
	private final int MAX_BYTES_PER_LOGFILE = 4 * 1000 * 1000;
	private final int MAX_LOGFILES = 200;
	private String DB_URL;
	private String DB_USER;
	private String DB_PASSWORD;

	// be careful when changing this, it might lead to invalid data already
	// stored !
	// this is what is used to differentiate a room from a student occupation in
	// the DB.
	public enum OCCUPANCY_TYPE {
		ROOM, USER;
	};

	// used to differentiate android log and server logs.
	private enum LOG_SIDE {
		ANDROID, SERVER;
	};

	public FreeRoomServiceImpl() {
		System.out.println("Starting FreeRoom plugin server ... V2");
		createLogFolder();
		logger.setLevel(Level.INFO);
		FileHandler logHandler = null;
		try {
			logHandler = new FileHandler(PATH_LOG_PATTERN,
					MAX_BYTES_PER_LOGFILE, MAX_LOGFILES, true);
			SimpleFormatter logFormatter = new SimpleFormatter();
			logHandler.setFormatter(logFormatter);
		} catch (SecurityException e1) {
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}

		if (logHandler != null) {
			logger.addHandler(logHandler);

		}

		DB_URL = PC_SRV_CONFIG.getString("DB_URL") + "?allowMultiQueries=true";
		DB_USER = PC_SRV_CONFIG.getString("DB_USERNAME");
		DB_PASSWORD = PC_SRV_CONFIG.getString("DB_PASSWORD");
<commit_msg>[freeroom.server] changing log level to warning<commit_after>package org.pocketcampus.plugin.freeroom.server;

import static org.pocketcampus.platform.launcher.server.PCServerConfig.PC_SRV_CONFIG;

import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import org.apache.thrift.TException;
import org.pocketcampus.platform.sdk.server.database.ConnectionManager;
import org.pocketcampus.platform.sdk.server.database.handlers.exceptions.ServerException;
import org.pocketcampus.plugin.freeroom.server.utils.CheckRequests;
import org.pocketcampus.plugin.freeroom.server.utils.OccupancySorted;
import org.pocketcampus.plugin.freeroom.server.utils.Utils;
import org.pocketcampus.plugin.freeroom.shared.ActualOccupation;
import org.pocketcampus.plugin.freeroom.shared.AutoCompleteReply;
import org.pocketcampus.plugin.freeroom.shared.AutoCompleteRequest;
import org.pocketcampus.plugin.freeroom.shared.AutoCompleteUserMessageReply;
import org.pocketcampus.plugin.freeroom.shared.AutoCompleteUserMessageRequest;
import org.pocketcampus.plugin.freeroom.shared.Constants;
import org.pocketcampus.plugin.freeroom.shared.FRPeriod;
import org.pocketcampus.plugin.freeroom.shared.FRReply;
import org.pocketcampus.plugin.freeroom.shared.FRRequest;
import org.pocketcampus.plugin.freeroom.shared.FRRoom;
import org.pocketcampus.plugin.freeroom.shared.FreeRoomService;
import org.pocketcampus.plugin.freeroom.shared.ImWorkingReply;
import org.pocketcampus.plugin.freeroom.shared.ImWorkingRequest;
import org.pocketcampus.plugin.freeroom.shared.LogMessage;
import org.pocketcampus.plugin.freeroom.shared.Occupancy;
import org.pocketcampus.plugin.freeroom.shared.RegisterUser;
import org.pocketcampus.plugin.freeroom.shared.WhoIsWorkingReply;
import org.pocketcampus.plugin.freeroom.shared.WhoIsWorkingRequest;
import org.pocketcampus.plugin.freeroom.shared.WorkingOccupancy;
import org.pocketcampus.plugin.freeroom.shared.utils.FRTimes;

/**
 * The actual implementation of the server side of the FreeRoom Plugin.
 * 
 * It responds to different types of request from the clients.
 * 
 * @author FreeRoom Project Team (2014/05)
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * 
 */

public class FreeRoomServiceImpl implements FreeRoomService.Iface {

	private final int LIMIT_AUTOCOMPLETE = 50;

	/**
	 * some rooms don't have a capacity, so we display the occupation based on
	 * 40 places, which is probably under-evaluated, so wont create many
	 * issues...
	 */
	int defaultCapacity = 40;

	private ConnectionManager connMgr;
	private Logger logger = Logger.getLogger(FreeRoomServiceImpl.class
			.getName());
	private SimpleDateFormat dateLogFormat = new SimpleDateFormat(
			"MMM dd,yyyy HH:mm");
	private final String LOG_FOLDER = "log";
	private final String PATH_LOG_PATTERN = "./" + LOG_FOLDER
			+ "/freeroom%g.log";
	// total size of log can be MAX_BYTES_PER_LOGFILE * MAX_LOGFILES
	private final int MAX_BYTES_PER_LOGFILE = 4 * 1000 * 1000;
	private final int MAX_LOGFILES = 200;
	private String DB_URL;
	private String DB_USER;
	private String DB_PASSWORD;

	// be careful when changing this, it might lead to invalid data already
	// stored !
	// this is what is used to differentiate a room from a student occupation in
	// the DB.
	public enum OCCUPANCY_TYPE {
		ROOM, USER;
	};

	// used to differentiate android log and server logs.
	private enum LOG_SIDE {
		ANDROID, SERVER;
	};

	public FreeRoomServiceImpl() {
		System.out.println("Starting FreeRoom plugin server ... V2");
		createLogFolder();
		logger.setLevel(Level.WARNING);
		FileHandler logHandler = null;
		try {
			logHandler = new FileHandler(PATH_LOG_PATTERN,
					MAX_BYTES_PER_LOGFILE, MAX_LOGFILES, true);
			SimpleFormatter logFormatter = new SimpleFormatter();
			logHandler.setFormatter(logFormatter);
		} catch (SecurityException e1) {
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}

		if (logHandler != null) {
			logger.addHandler(logHandler);

		}

		DB_URL = PC_SRV_CONFIG.getString("DB_URL") + "?allowMultiQueries=true";
		DB_USER = PC_SRV_CONFIG.getString("DB_USERNAME");
		DB_PASSWORD = PC_SRV_CONFIG.getString("DB_PASSWORD");

{'fraction_non_alphanumeric': 0.09825829773250082, 'fraction_numerical': 0.006353379340563041, 'mean_word_length': 5.380153738644305, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '989076', 'n_tokens_mistral': 3072, 'n_tokens_neox': 2852, 'n_words': 613}