<commit_before>package com.exadel.borsch.web.controllers;

import com.exadel.borsch.dao.Dish;
import com.exadel.borsch.dao.MenuItem;
import com.exadel.borsch.dao.Order;
import com.exadel.borsch.dao.User;
import com.exadel.borsch.managers.ManagerFactory;
import com.exadel.borsch.managers.OrderManager;
import com.exadel.borsch.managers.PriceManager;
import com.exadel.borsch.util.DateTimeUtils;
import com.exadel.borsch.web.users.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.Principal;
import java.util.List;
import java.util.UUID;
import org.joda.time.DateTime;
import org.joda.time.Weeks;
import org.joda.time.format.DateTimeFormat;

/**
 *
 * @author Vlad
 */
@Controller
public class HomeController {
    @Autowired
    private ManagerFactory managerFactory;

    public void fillInPageModel(Model model, Principal principal, DateTime date) {
        OrderManager orderManager = managerFactory.getOrderManager();
        User user = UserUtils.getUserByPrincipal(principal);

        DateTime prevWeek = date.minusWeeks(1);
        if (orderManager.findOrderAtDateForUser(user, prevWeek) != null) {
            model.addAttribute("prevWeek", prevWeek.toString("dd-MM-yyy"));
        }
        DateTime nextWeek = date.plusWeeks(1);
        if (orderManager.findOrderAtDateForUser(user, nextWeek) != null) {
            model.addAttribute("nextWeek", nextWeek.toString("dd-MM-yyy"));
        }
        model.addAttribute("currentWeekCode",
                Weeks.weeksBetween(DateTimeUtils.getStartOfNextWeek(), date).getWeeks() + 2);
    }

    @Secured("ROLE_EDIT_MENU_SELF")
    @RequestMapping("/home")
    public String processPageRequest(Model model, Principal principal) {
        OrderManager orderManager = managerFactory.getOrderManager();
        User user = UserUtils.getUserByPrincipal(principal);

        Order order = orderManager.getCurrentOrderForUser(user);
        model.addAttribute(order);

        fillInPageModel(model, principal, DateTimeUtils.getStartOfNextWeek());

        return ViewURLs.HOME_PAGE;
    }

    @Secured("ROLE_EDIT_MENU_SELF")
    @RequestMapping("/home/{date}")
    public String processPageRequestForDate(Model model, Principal principal,
        @PathVariable String date) {
        OrderManager orderManager = managerFactory.getOrderManager();
        User user = UserUtils.getUserByPrincipal(principal);

        DateTime orderDate = DateTime.parse(date, DateTimeFormat.forPattern("dd-MM-yyy"));
        Order order = orderManager.findOrderAtDateForUser(user, orderDate);
        if (order == null) {
            return "redirect:/home";
        }

        fillInPageModel(model, principal, orderDate);

        model.addAttribute(order);
        return ViewURLs.HOME_PAGE;
    }

    @RequestMapping("/gentestorders")
    public String processGenTestOrders() {
        OrderManager orderManager = managerFactory.getOrderManager();
        // Test data
        User admin = managerFactory.getUserManager().getUserByLogin("rod");
        Order testOrder1 = orderManager.getCurrentOrderForUser(admin);
        testOrder1.setStartDate(testOrder1.getStartDate().minusWeeks(1));
        testOrder1.setEndDate(testOrder1.getEndDate().minusWeeks(1));
        orderManager.deleteOrderById(testOrder1.getId());

        Order testOrder2 = orderManager.getCurrentOrderForUser(admin);
        testOrder2.setStartDate(testOrder2.getStartDate().minusWeeks(2));
        testOrder2.setEndDate(testOrder2.getEndDate().minusWeeks(2));
        orderManager.deleteOrderById(testOrder2.getId());

        orderManager.getCurrentOrderForUser(admin);
        orderManager.addOrder(testOrder1);
        orderManager.addOrder(testOrder2);

        return "redirect:/home";
    }

    @Secured("ROLE_EDIT_MENU_SELF")
    @RequestMapping("/")
    public String processDefaultPageRequest(Model model, Principal principal) {
        return "redirect:/home";
    }

    @ResponseBody
    @Secured("ROLE_EDIT_MENU_SELF")
    @RequestMapping("/home/orders/{day}")
    public List<Dish> processOrderRequest(Principal principal, @PathVariable int day) {

        OrderManager orderManager = managerFactory.getOrderManager();
        User user = UserUtils.getUserByPrincipal(principal);

        Order order = orderManager.getCurrentOrderForUser(user);
        if (day < 0 || day > order.getOrder().size()) {
            return null;
        }
<commit_msg>Fixed test data generator<commit_after>package com.exadel.borsch.web.controllers;

import com.exadel.borsch.dao.Dish;
import com.exadel.borsch.dao.MenuItem;
import com.exadel.borsch.dao.Order;
import com.exadel.borsch.dao.User;
import com.exadel.borsch.managers.ManagerFactory;
import com.exadel.borsch.managers.OrderManager;
import com.exadel.borsch.managers.PriceManager;
import com.exadel.borsch.util.DateTimeUtils;
import com.exadel.borsch.web.users.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.security.Principal;
import java.util.List;
import java.util.UUID;
import org.joda.time.DateTime;
import org.joda.time.Weeks;
import org.joda.time.format.DateTimeFormat;

/**
 *
 * @author Vlad
 */
@Controller
public class HomeController {
    @Autowired
    private ManagerFactory managerFactory;

    public void fillInPageModel(Model model, Principal principal, DateTime date) {
        OrderManager orderManager = managerFactory.getOrderManager();
        User user = UserUtils.getUserByPrincipal(principal);

        DateTime prevWeek = date.minusWeeks(1);
        if (orderManager.findOrderAtDateForUser(user, prevWeek) != null) {
            model.addAttribute("prevWeek", prevWeek.toString("dd-MM-yyy"));
        }
        DateTime nextWeek = date.plusWeeks(1);
        if (orderManager.findOrderAtDateForUser(user, nextWeek) != null) {
            model.addAttribute("nextWeek", nextWeek.toString("dd-MM-yyy"));
        }
        model.addAttribute("currentWeekCode",
                Weeks.weeksBetween(DateTimeUtils.getStartOfNextWeek(), date).getWeeks() + 2);
    }

    @Secured("ROLE_EDIT_MENU_SELF")
    @RequestMapping("/home")
    public String processPageRequest(Model model, Principal principal) {
        OrderManager orderManager = managerFactory.getOrderManager();
        User user = UserUtils.getUserByPrincipal(principal);

        Order order = orderManager.getCurrentOrderForUser(user);
        model.addAttribute(order);

        fillInPageModel(model, principal, DateTimeUtils.getStartOfNextWeek());

        return ViewURLs.HOME_PAGE;
    }

    @Secured("ROLE_EDIT_MENU_SELF")
    @RequestMapping("/home/{date}")
    public String processPageRequestForDate(Model model, Principal principal,
        @PathVariable String date) {
        OrderManager orderManager = managerFactory.getOrderManager();
        User user = UserUtils.getUserByPrincipal(principal);

        DateTime orderDate = DateTime.parse(date, DateTimeFormat.forPattern("dd-MM-yyy"));
        Order order = orderManager.findOrderAtDateForUser(user, orderDate);
        if (order == null) {
            return "redirect:/home";
        }

        fillInPageModel(model, principal, orderDate);

        model.addAttribute(order);
        return ViewURLs.HOME_PAGE;
    }

    @RequestMapping("/gentestorders")
    public String processGenTestOrders() {
        OrderManager orderManager = managerFactory.getOrderManager();
        // Test data
        User admin = managerFactory.getUserManager().getUserByLogin("rod");
        Order testOrder1 = orderManager.getCurrentOrderForUser(admin);
        testOrder1.setStartDate(testOrder1.getStartDate().minusWeeks(1));
        testOrder1.setEndDate(testOrder1.getEndDate().minusWeeks(1));
        for (MenuItem item: testOrder1.getOrder())
            item.setDate(item.getDate().minusWeeks(1));
        orderManager.deleteOrderById(testOrder1.getId());

        Order testOrder2 = orderManager.getCurrentOrderForUser(admin);
        testOrder2.setStartDate(testOrder2.getStartDate().minusWeeks(2));
        testOrder2.setEndDate(testOrder2.getEndDate().minusWeeks(2));
        for (MenuItem item: testOrder2.getOrder())
            item.setDate(item.getDate().minusWeeks(2));
        orderManager.deleteOrderById(testOrder2.getId());

        orderManager.getCurrentOrderForUser(admin);
        orderManager.addOrder(testOrder1);
        orderManager.addOrder(testOrder2);

        return "redirect:/home";
    }

    @Secured("ROLE_EDIT_MENU_SELF")
    @RequestMapping("/")
    public String processDefaultPageRequest(Model model, Principal principal) {
        return "redirect:/home";
    }

    @ResponseBody
    @Secured("ROLE_EDIT_MENU_SELF")
    @RequestMapping("/home/orders/{day}")
    public List<Dish> processOrderRequest(Principal principal, @PathVariable int day) {

        OrderManager orderManager = managerFactory.getOrderManager();
        User user = UserUtils.getUserByPrincipal(principal);

        Order order = orderManager.getCurrentOrderForUser(user);
        if (day < 0 || day > order.getOrder().size()) {
            return null;
        }

{'fraction_non_alphanumeric': 0.10942311640320262, 'fraction_numerical': 0.004927119687949086, 'mean_word_length': 3.8232673267326733, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6002751', 'n_tokens_mistral': 2790, 'n_tokens_neox': 2745, 'n_words': 445}