<commit_before>package com.rodionov.cityoffice.controllers;

import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.rodionov.cityoffice.dto.EmployeeDTO;
import com.rodionov.cityoffice.dto.EmployeeProjectDTO;
import com.rodionov.cityoffice.model.UserProject;
import com.rodionov.cityoffice.services.ProjectService;
import com.rodionov.cityoffice.services.UserService;

@RestController
public class EmployeeController {
	
	private static final Logger logger = Logger.getLogger(EmployeeController.class);
	
	private static final Integer DEFAULT_PERIOD = 180;

	@Autowired
	private UserService userService;
	
	@Autowired
	private ProjectService projectService;
	
	/**
	 * Get information about employees:
	 *  their projects in the specified period
	 *  their vacancies 
	 * @param periodInDays Period in days from today to the future (example: 180 - half a year)
	 * @return
	 */
	@RequestMapping(value = "/employee/info", method = RequestMethod.GET)
	public List<EmployeeDTO> getEmployeePeriodInfo(@RequestParam(required=false) Integer periodInDays) {
		
		logger.info("getEmployeePeriodInfo invoked. (periodInDays = " + periodInDays + ")");
		
		if (periodInDays == null) {
			periodInDays = DEFAULT_PERIOD;
		}

		Pageable pageable = new PageRequest(0, Integer.MAX_VALUE);
		LocalDate finishAfter = LocalDate.now();
		LocalDate startBefore = finishAfter.plusDays(periodInDays);
		List<UserProject> userProjects = userService.getUserProjects(null, null, startBefore, finishAfter, pageable).getContent();
		
		List<EmployeeDTO> employees = userProjects.stream()
					.collect(Collectors.groupingBy(UserProject::getUserId))
					.entrySet()
					.stream()
					.map(entry -> convertToDto(entry.getKey(), entry.getValue()))
					.collect(Collectors.toList());
		
		return employees;
	}
	
	private EmployeeDTO convertToDto(String userId, List<UserProject> projects) {
		EmployeeDTO dto = new EmployeeDTO();
		dto.setId(userId);
		dto.setName(userService.getUser(userId).getUsername());
		dto.setProjects(projects.stream().map(this::convertToProjectDTO).collect(Collectors.toList()));
		
		return dto;
	}
	
	private EmployeeProjectDTO convertToProjectDTO(UserProject userProject) {
		EmployeeProjectDTO dto = new EmployeeProjectDTO();
		dto.setId(userProject.getProjectId());
		dto.setName(projectService.getProject(userProject.getProjectId()).getName());
		dto.setStartDate(userProject.getStartDate());
		dto.setFinishDate(userProject.getFinishDate());
		
		return dto;
	}
}<commit_msg>bug fix in employee controller<commit_after>package com.rodionov.cityoffice.controllers;

import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.rodionov.cityoffice.dto.EmployeeDTO;
import com.rodionov.cityoffice.dto.EmployeeProjectDTO;
import com.rodionov.cityoffice.model.UserProject;
import com.rodionov.cityoffice.services.ProjectService;
import com.rodionov.cityoffice.services.UserService;

@RestController
@RequestMapping("/employee")
public class EmployeeController {
	
	private static final Logger logger = Logger.getLogger(EmployeeController.class);
	
	private static final Integer DEFAULT_PERIOD = 180;

	@Autowired
	private UserService userService;
	
	@Autowired
	private ProjectService projectService;
	
	/**
	 * Get information about employees:
	 *  their projects in the specified period
	 *  their vacancies 
	 * @param periodInDays Period in days from today to the future (example: 180 - half a year)
	 * @return
	 */
	@RequestMapping(method = RequestMethod.GET)
	public List<EmployeeDTO> getEmployeesList(
			@RequestParam(required=false) Integer periodInDays) {
		
		logger.info("getEmployeePeriodInfo invoked. (periodInDays = " + periodInDays + ")");
		
		if (periodInDays == null) {
			periodInDays = DEFAULT_PERIOD;
		}

		Pageable pageable = new PageRequest(0, Integer.MAX_VALUE);
		LocalDate finishAfter = LocalDate.now();
		LocalDate startBefore = finishAfter.plusDays(periodInDays);
		List<UserProject> userProjects = userService.getUserProjects(null, null, startBefore, finishAfter, pageable).getContent();
		
		List<EmployeeDTO> employees = userProjects.stream()
					.collect(Collectors.groupingBy(UserProject::getUserId))
					.entrySet()
					.stream()
					.map(entry -> convertToDto(entry.getKey(), entry.getValue()))
					.collect(Collectors.toList());
		
		return employees;
	}
	
	private EmployeeDTO convertToDto(String userId, List<UserProject> projects) {
		EmployeeDTO dto = new EmployeeDTO();
		dto.setId(userId);
		dto.setName(userService.getUser(userId).getUsername());
		dto.setProjects(projects.stream().map(this::convertToProjectDTO).collect(Collectors.toList()));
		
		return dto;
	}
	
	private EmployeeProjectDTO convertToProjectDTO(UserProject userProject) {
		EmployeeProjectDTO dto = new EmployeeProjectDTO();
		dto.setId(userProject.getProjectId());
		dto.setName(projectService.getProject(userProject.getProjectId()).getName());
		dto.setStartDate(userProject.getStartDate());
		dto.setFinishDate(userProject.getFinishDate());
		dto.setWorkload(userProject.getLoad());
		
		return dto;
	}
}
{'fraction_non_alphanumeric': 0.10777944361152757, 'fraction_numerical': 0.0026653339996668335, 'mean_word_length': 5.693422519509476, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '4156000', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1753, 'n_words': 331}