<commit_before>package es.uvigo.esei.daa.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Iterator;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import es.uvigo.esei.daa.entities.Event;

public class EventDAO extends DAO {
	private final static Logger LOG = Logger.getLogger("EventDAO");

	public Event get(int id) throws DAOException, IllegalArgumentException {
		try (final Connection conn = this.getConnection()) {
			final String query = "SELECT * FROM event WHERE id=?";

			try (final PreparedStatement statement = conn
					.prepareStatement(query)) {
				statement.setInt(1, id);

				try (final ResultSet result = statement.executeQuery()) {
					if (result.next()) {
						return new Event(result.getInt("id"),
								result.getString("nameEvent"),
								result.getTimestamp("dateCreate"),
								result.getTimestamp("dateInit"),
								result.getTimestamp("dateFinal"),
								result.getString("description"),
								result.getString("category"));
					} else {
						throw new IllegalArgumentException("Invalid id");
					}
				}
			}
		} catch (SQLException e) {
			LOG.log(Level.SEVERE, "Error getting an event", e);
			throw new DAOException(e);
		}
	}

	/*
	 * public List<Event> list() throws DAOException { try (final Connection
	 * conn = this.getConnection()) { final String query =
	 * "SELECT * FROM event";
	 * 
	 * try (final PreparedStatement statement = conn.prepareStatement(query)) {
	 * try (final ResultSet result = statement.executeQuery()) { final
	 * List<Event> events = new LinkedList<>(); while (result.next()) {
	 * events.add(new Event( result.getInt("id"), result.getString("nameEvent"),
	 * result.getTimestamp("dateCreate"), result.getTimestamp("dateInit"),
	 * result.getTimestamp("dateFinal"), result.getString("description"),
	 * result.getString("category") )); }
	 * 
	 * return events; } } } catch (SQLException e) { LOG.log(Level.SEVERE,
	 * "Error listing events", e); throw new DAOException(e); } }
	 */
	//mcpaz y adri
	public Vector<Event> listRecomended(String login) throws DAOException {
		final SortedMap<String, Integer> mapaCategorias = new TreeMap();//sortedMap devielve un mapa ordenado
		try (final Connection conn = this.getConnection()) {
			final String eventosUser = "SELECT event.category FROM eventUser,event where event.id == eventUser.id ";

			try (final PreparedStatement statement = conn
					.prepareStatement(eventosUser)) {
				try (final ResultSet result = statement.executeQuery()) {
					while (result.next()) {// aqui creo que estamos contando las
											// veces que se repite una categoria
						if (!mapaCategorias.containsKey(result
								.getString("category"))) {
							mapaCategorias.put(result.getString("category"), 1);
						} else {
							mapaCategorias.replace(
									result.getString("category"),
									mapaCategorias.get(result
											.getString("category")) + 1);
						}
					}
					
					Iterator<String> iterator = mapaCategorias.keySet()
							.iterator();
					final Vector<Event> events = new Vector<>();
					while (iterator.hasNext()) {
						String key = (String) iterator.next();
						final String eventoRecomen = "SELECT * FROM event where event ==  "
								+ key;

						try (final PreparedStatement stat = conn
								.prepareStatement(eventoRecomen)) {
							try (final ResultSet res = stat.executeQuery()) {

								while (res.next()) {
									events.add(new Event(res.getInt("id"), res
											.getString("nameEvent"), res
											.getTimestamp("dateCreate"), res
											.getTimestamp("dateInit"), res
											.getTimestamp("dateFinal"), res
											.getString("description"), res
											.getString("category")));
								}

							}
						}
					}

					return events;

				}

			}

		} catch (SQLException e) {<commit_msg>Nueva modificacion de lógica e negocio<commit_after>package es.uvigo.esei.daa.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import es.uvigo.esei.daa.entities.Event;

public class EventDAO extends DAO {
	private final static Logger LOG = Logger.getLogger("EventDAO");

	public Event get(int id) throws DAOException, IllegalArgumentException {
		try (final Connection conn = this.getConnection()) {
			final String query = "SELECT * FROM event WHERE id=?";

			try (final PreparedStatement statement = conn
					.prepareStatement(query)) {
				statement.setInt(1, id);

				try (final ResultSet result = statement.executeQuery()) {
					if (result.next()) {
						return new Event(result.getInt("id"),
								result.getString("nameEvent"),
								result.getTimestamp("dateCreate"),
								result.getTimestamp("dateInit"),
								result.getTimestamp("dateFinal"),
								result.getString("description"),
								result.getString("category"));
					} else {
						throw new IllegalArgumentException("Invalid id");
					}
				}
			}
		} catch (SQLException e) {
			LOG.log(Level.SEVERE, "Error getting an event", e);
			throw new DAOException(e);
		}
	}

	/*
	 * public List<Event> list() throws DAOException { try (final Connection
	 * conn = this.getConnection()) { final String query =
	 * "SELECT * FROM event";
	 * 
	 * try (final PreparedStatement statement = conn.prepareStatement(query)) {
	 * try (final ResultSet result = statement.executeQuery()) { final
	 * List<Event> events = new LinkedList<>(); while (result.next()) {
	 * events.add(new Event( result.getInt("id"), result.getString("nameEvent"),
	 * result.getTimestamp("dateCreate"), result.getTimestamp("dateInit"),
	 * result.getTimestamp("dateFinal"), result.getString("description"),
	 * result.getString("category") )); }
	 * 
	 * return events; } } } catch (SQLException e) { LOG.log(Level.SEVERE,
	 * "Error listing events", e); throw new DAOException(e); } }
	 */
	//mcpaz y adri
	public Event[] listRecomended(String login) throws DAOException {
		final SortedMap<String, Integer> mapaCategorias = new TreeMap();//sortedMap devielve un mapa ordenado
		try (final Connection conn = this.getConnection()) {
			final String eventosUser = "SELECT event.category FROM eventUser,event where event.id == eventUser.id ";

			try (final PreparedStatement statement = conn
					.prepareStatement(eventosUser)) {
				try (final ResultSet result = statement.executeQuery()) {
					while (result.next()) {// aqui creo que estamos contando las
											// veces que se repite una categoria
						if (!mapaCategorias.containsKey(result
								.getString("category"))) {
							mapaCategorias.put(result.getString("category"), 1);
						} else {
							mapaCategorias.replace(
									result.getString("category"),
									mapaCategorias.get(result
											.getString("category")) + 1);
						}
					}
					
					Iterator<String> iterator = mapaCategorias.keySet()
							.iterator();
					final Event[] events = new Event[10];
					while (iterator.hasNext()) {
						String key = (String) iterator.next();
						final String eventoRecomen = "SELECT * FROM event where event ==  "
								+ key;

						try (final PreparedStatement stat = conn
								.prepareStatement(eventoRecomen)) {
							try (final ResultSet res = stat.executeQuery()) {
								int i=0;//esto es una xapuza para devolver el array que tanto quieren
								while (res.next()) {
									events[i]=(new Event(res.getInt("id"), res
											.getString("nameEvent"), res
											.getTimestamp("dateCreate"), res
											.getTimestamp("dateInit"), res
											.getTimestamp("dateFinal"), res
											.getString("description"), res
											.getString("category")));
										i++;
								}

							}
						}
					}

					return events;

				}

			}

		} catch (SQLException e) {
{'fraction_non_alphanumeric': 0.12948061448427212, 'fraction_numerical': 0.0010972933430870519, 'mean_word_length': 3.230531201650335, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '7250076', 'n_tokens_mistral': 3068, 'n_tokens_neox': 2345, 'n_words': 582}