<commit_before>package com.cenfotec.dondeEs.services;


import java.util.ArrayList;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cenfotec.dondeEs.ejb.Chat;
import com.cenfotec.dondeEs.ejb.Event;
import com.cenfotec.dondeEs.ejb.User;
import com.cenfotec.dondeEs.pojo.ChatPOJO;
import com.cenfotec.dondeEs.repositories.ChatRepository;
import com.cenfotec.dondeEs.repositories.EventRepository;
import com.cenfotec.dondeEs.repositories.UserRepository;

import org.springframework.beans.BeanUtils;

@Service
public class ChatService implements ChatServiceInterface {
	@Autowired
	private ChatRepository chatRepository;
	@Autowired
	private UserRepository userRepository;
	@Autowired
	private EventRepository eventRepository;
	
	
	@Override
	@Transactional
	public Boolean saveChat(Chat nchat) {
		Event aux = eventRepository.findOne(nchat.getEvent().getEventId());
		List<User> users = chatRepository.getUsersByEvent(nchat.getEvent().getEventId());
		nchat.setEvent(aux);
		Chat chat = chatRepository.save(nchat);
		users.add(aux.getUser());
		for(User nUser : users){
			if(nUser.getChats() == null){
				nUser.setChats(new ArrayList<Chat>());
			}
			nUser.getChats().add(chat);
			userRepository.save(nUser); 
		}
		return (nchat == null) ? false : true;
	}


	@Override
	public List<ChatPOJO> getAllByUser(int idUser) {
		List<Chat> chatRep = chatRepository.findByUsersUserId(idUser);
		List<ChatPOJO> chatsPOJO = new ArrayList<ChatPOJO>();
		chatRep.stream().forEach(c -> {
			ChatPOJO chatPOJO = new ChatPOJO();
			BeanUtils.copyProperties(c, chatPOJO);
			chatPOJO.setUsers(null);
			chatPOJO.setMessages(null);
			chatsPOJO.add(chatPOJO);
		});
		
		return chatsPOJO;<commit_msg>Adding object event in chat<commit_after>package com.cenfotec.dondeEs.services;


import java.util.ArrayList;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cenfotec.dondeEs.ejb.Chat;
import com.cenfotec.dondeEs.ejb.Event;
import com.cenfotec.dondeEs.ejb.User;
import com.cenfotec.dondeEs.pojo.ChatPOJO;
import com.cenfotec.dondeEs.pojo.EventPOJO;
import com.cenfotec.dondeEs.repositories.ChatRepository;
import com.cenfotec.dondeEs.repositories.EventRepository;
import com.cenfotec.dondeEs.repositories.UserRepository;

import org.springframework.beans.BeanUtils;

@Service
public class ChatService implements ChatServiceInterface {
	@Autowired
	private ChatRepository chatRepository;
	@Autowired
	private UserRepository userRepository;
	@Autowired
	private EventRepository eventRepository;
	
	
	@Override
	@Transactional
	public Boolean saveChat(Chat nchat) {
		Event aux = eventRepository.findOne(nchat.getEvent().getEventId());
		List<User> users = chatRepository.getUsersByEvent(nchat.getEvent().getEventId());
		nchat.setEvent(aux);
		Chat chat = chatRepository.save(nchat);
		users.add(aux.getUser());
		for(User nUser : users){
			if(nUser.getChats() == null){
				nUser.setChats(new ArrayList<Chat>());
			}
			nUser.getChats().add(chat);
			userRepository.save(nUser); 
		}
		return (nchat == null) ? false : true;
	}


	@Override
	public List<ChatPOJO> getAllByUser(int idUser) {
		List<Chat> chatRep = chatRepository.findByUsersUserId(idUser);
		List<ChatPOJO> chatsPOJO = new ArrayList<ChatPOJO>();
		chatRep.stream().forEach(c -> {
			ChatPOJO chatPOJO = new ChatPOJO();
			BeanUtils.copyProperties(c, chatPOJO);
			chatPOJO.setUsers(null);
			chatPOJO.setMessages(null);
			if(c.getEvent() != null){
				EventPOJO eventPOJO = new EventPOJO();
				BeanUtils.copyProperties(c.getEvent(), eventPOJO);
				eventPOJO.setChats(null);
				eventPOJO.setEventParticipants(null);
				eventPOJO.setUser(null);
				eventPOJO.setServiceContacts(null);
				eventPOJO.setNotes(null);
				chatPOJO.setEvent(eventPOJO);
			}
			chatsPOJO.add(chatPOJO);
		});
		
		return chatsPOJO;
{'fraction_non_alphanumeric': 0.11773435567647786, 'fraction_numerical': 0.0, 'mean_word_length': 5.4292527821939585, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '3110061', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1356, 'n_words': 221}