<commit_before>/*
 * Copyright 2014 <NAME>, This source is a part of 
 * Audit4j - An open source auditing framework.
 * http://audit4j.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.audit4j.core;

import java.io.IOException;
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.List;

import org.audit4j.core.dto.AuditEvent;
import org.audit4j.core.exception.ConfigurationException;
import org.audit4j.core.exception.TroubleshootException;

/**
 * The Class TroubleshootManager.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * 
 * @since 1.0.0
 */
public final class TroubleshootManager {

	/** The Constant MIN_PORT_NUMBER. */
	public static final int MIN_PORT_NUMBER = 1100;

	/** The Constant MAX_PORT_NUMBER. */
	public static final int MAX_PORT_NUMBER = 49151;

	/**
	 * Troubleshoot event.
	 * 
	 * @param event
	 *            the event
	 */
	public static void troubleshootEvent(AuditEvent event) {
		if (event == null) {
			throw new TroubleshootException(
					"Invalid Audit event type,\n Audit4j: Audit Event should not null, This event will not be logged by the Audit4j.");
		} else if (event.getActor() == null) {
			if (Context.getConfigContext().getMetaData().getClass().equals(DummyMetaData.class)) {
				event.setActor(CoreConstants.DEFAULT_ACTOR);
				Log.warn("Audit4j:WARN If you are not parsing the actor to the AuditEvent,\n"
						+ "Audit4j:WARN you should make a your own AuditMetaData implementation. \n"
						+ "Audit4j:WARN otherwise actor will be hard coded as \"" + CoreConstants.DEFAULT_ACTOR
						+ "\" in the audit log. " + "\nAudit4j: See " + ErrorURL.NULL_ACTOR + " for further details.");

			} else {
				event.setActor(Context.getConfigContext().getMetaData().getActor());
			}
		}
		
		// TODO commented due to fix
		//else if (event.getOrigin() == null) {
		//	throw new TroubleshootException(
		//			"Invalid Audit event type,\n Audit4j: origin should not null, This event will not be logged by the Audit4j.");
		//}
	}

	/**
	 * Troubleshoot configuration.
	 * 
	 * @param e
	 *            the e
	 */
	public static void troubleshootConfiguration(ConfigurationException e) {
		if (e.getId().equals("CONF_001")) {
			System.err.println("Audit4j:WARN Initial confguration file not found. \n"
					+ "Audit4j: Creating a new configuration file - " + CoreConstants.CONFIG_FILE_NAME);
			ConfigUtil.generateConfigFromText();
		} else if (e.getId().equals("CONF_002")) {
			throw new TroubleshootException("Configuration file currupted or invalid configuration.\n"
					+ "Audit4j: See " + ErrorURL.CONFIG_ERROR + "for further details.", e);
		}
	}

	/**
	 * Checks if is port available.
	 * 
	 * @param port
	 *            the port
	 * @return true, if is port available
	 */
	static boolean isPortAvailable(final int port) {<commit_msg>Typo in TroubleshootManager fixed.<commit_after>/*
 * Copyright 2014 <NAME>, This source is a part of 
 * Audit4j - An open source auditing framework.
 * http://audit4j.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.audit4j.core;

import java.io.IOException;
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.util.ArrayList;
import java.util.List;

import org.audit4j.core.dto.AuditEvent;
import org.audit4j.core.exception.ConfigurationException;
import org.audit4j.core.exception.TroubleshootException;

/**
 * The Class TroubleshootManager.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * 
 * @since 1.0.0
 */
public final class TroubleshootManager {

	/** The Constant MIN_PORT_NUMBER. */
	public static final int MIN_PORT_NUMBER = 1100;

	/** The Constant MAX_PORT_NUMBER. */
	public static final int MAX_PORT_NUMBER = 49151;

	/**
	 * Troubleshoot event.
	 * 
	 * @param event
	 *            the event
	 */
	public static void troubleshootEvent(AuditEvent event) {
		if (event == null) {
			throw new TroubleshootException(
					"Invalid Audit event type,\n Audit4j: Audit Event should not null, This event will not be logged by the Audit4j.");
		} else if (event.getActor() == null) {
			if (Context.getConfigContext().getMetaData().getClass().equals(DummyMetaData.class)) {
				event.setActor(CoreConstants.DEFAULT_ACTOR);
				Log.warn("Audit4j:WARN If you are not parsing the actor to the AuditEvent,\n"
						+ "Audit4j:WARN you should make a your own AuditMetaData implementation. \n"
						+ "Audit4j:WARN otherwise actor will be hard coded as \"" + CoreConstants.DEFAULT_ACTOR
						+ "\" in the audit log. " + "\nAudit4j: See " + ErrorURL.NULL_ACTOR + " for further details.");

			} else {
				event.setActor(Context.getConfigContext().getMetaData().getActor());
			}
		}
		
		// TODO commented due to fix
		//else if (event.getOrigin() == null) {
		//	throw new TroubleshootException(
		//			"Invalid Audit event type,\n Audit4j: origin should not null, This event will not be logged by the Audit4j.");
		//}
	}

	/**
	 * Troubleshoot configuration.
	 * 
	 * @param e
	 *            the e
	 */
	public static void troubleshootConfiguration(ConfigurationException e) {
		if (e.getId().equals("CONF_001")) {
			System.err.println("Audit4j:WARN Initial configuration file not found. \n"
					+ "Audit4j: Creating a new configuration file - " + CoreConstants.CONFIG_FILE_NAME);
			ConfigUtil.generateConfigFromText();
		} else if (e.getId().equals("CONF_002")) {
			throw new TroubleshootException("Configuration file currupted or invalid configuration.\n"
					+ "Audit4j: See " + ErrorURL.CONFIG_ERROR + "for further details.", e);
		}
	}

	/**
	 * Checks if is port available.
	 * 
	 * @param port
	 *            the port
	 * @return true, if is port available
	 */
	static boolean isPortAvailable(final int port) {
{'fraction_non_alphanumeric': 0.11083160698431489, 'fraction_numerical': 0.012725658478839894, 'mean_word_length': 3.5150300601202407, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5827907', 'n_tokens_mistral': 2260, 'n_tokens_neox': 2047, 'n_words': 651}