<commit_before>package infowall.web.controller;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import infowall.domain.model.Dashboard;
import infowall.domain.process.DashboardProcess;
import infowall.web.services.errorhandling.Errors;
import infowall.web.spring.FlashMessage;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import static infowall.web.spring.ControllerDsl.*;

/**
 *
 */
@Controller
//@Scope("session")
public class DashboardController {

    private final Logger logger = LoggerFactory.getLogger(DashboardController.class);

    private final DashboardProcess process;
    private final FlashMessage flashMessage;

    @Autowired
    public DashboardController(DashboardProcess process, FlashMessage flashMessage) {
        this.process = process;
        this.flashMessage = flashMessage;
    }

    @RequestMapping("/dashboard")
    ModelAndView listDashboards(){

        List<Dashboard> dashboards = process.listAllDashboards();

        return render(
                "dashboard/list",
                "dashboards", dashboards);
    }

    private String toJson(List<Dashboard> dashboards) {
        ObjectMapper mapper = new ObjectMapper();
        String json;
        try {
            json= mapper.writeValueAsString(dashboards);
        } catch (IOException e) {
            json = "{}";
        }
        return json;
    }

    @RequestMapping("/dashboard/{dashboardId}")
    ModelAndView showDashboard(@PathVariable String dashboardId){
        Dashboard dashboard = process.getDashboard(dashboardId);
        if(dashboard == null){
            return redirect("/dashboard");
        }
        return render("dashboard/index",
                "dashboard",dashboard,
                "json",dashboard.toJSON());
    }

    @RequestMapping("/configure/dashboard/{dashboardId}")
    ModelAndView configureDashboard(@PathVariable String dashboardId){

        Dashboard dashboard = process.getDashboard(dashboardId);
        if(dashboard == null){
            return to404();
        }
        
        return render(
                "dashboard/configure",
                flashMessage,
                ImmutableMap.<String, Object>of("dashboard",dashboard));
    }

    @RequestMapping("/reload/dashboard/{dashboardId}")
    ModelAndView reloadDashboard(@PathVariable String dashboardId){
        Errors errors = new Errors();
        Dashboard dashboard = process.reloadDashboard(dashboardId,errors);
        if(dashboard == null){
            return to404();
        }
        Map<String,Object> model =
                Maps.newHashMap(
                    ImmutableMap.<String, Object>of("dashboard", dashboard)
                );
        if(!errors.haveOccurred()){
            flashMessage.putInfo("The configuration has been reloaded.");
        }
        return redirect("/configure/dashboard/" + dashboardId);
    }


}
<commit_msg>cleaned up controller<commit_after>package infowall.web.controller;

import com.google.common.collect.ImmutableMap;
import infowall.domain.model.Dashboard;
import infowall.domain.process.DashboardProcess;
import infowall.web.services.errorhandling.Errors;
import infowall.web.spring.FlashMessage;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.List;

import static infowall.web.spring.ControllerDsl.*;

/**
 *
 */
@Controller
//@Scope("session")
public class DashboardController {

    private final Logger logger = LoggerFactory.getLogger(DashboardController.class);

    private final DashboardProcess process;
    private final FlashMessage flashMessage;

    @Autowired
    public DashboardController(DashboardProcess process, FlashMessage flashMessage) {
        this.process = process;
        this.flashMessage = flashMessage;
    }

    @RequestMapping("/dashboard")
    ModelAndView listDashboards(){

        List<Dashboard> dashboards = process.listAllDashboards();

        return render(
                "dashboard/list",
                "dashboards", dashboards);
    }

    private String toJson(List<Dashboard> dashboards) {
        ObjectMapper mapper = new ObjectMapper();
        String json;
        try {
            json= mapper.writeValueAsString(dashboards);
        } catch (IOException e) {
            json = "{}";
        }
        return json;
    }

    @RequestMapping("/dashboard/{dashboardId}")
    ModelAndView showDashboard(@PathVariable String dashboardId){
        Dashboard dashboard = process.getDashboard(dashboardId);
        if(dashboard == null){
            return redirect("/dashboard");
        }
        return render("dashboard/index",
                "dashboard",dashboard,
                "json",dashboard.toJSON());
    }

    @RequestMapping("/configure/dashboard/{dashboardId}")
    ModelAndView configureDashboard(@PathVariable String dashboardId){

        Dashboard dashboard = process.getDashboard(dashboardId);
        if(dashboard == null){
            return to404();
        }
        
        return render(
                "dashboard/configure",
                flashMessage,
                ImmutableMap.<String, Object>of("dashboard",dashboard));
    }

    @RequestMapping("/reload/dashboard/{dashboardId}")
    ModelAndView reloadDashboard(@PathVariable String dashboardId){
        Errors errors = new Errors();
        Dashboard dashboard = process.reloadDashboard(dashboardId,errors);
        if(dashboard == null){
            return to404();
        }

        if(!errors.haveOccurred()){
            flashMessage.putInfo("The configuration has been reloaded.");
        }
        return redirect("/configure/dashboard/" + dashboardId);
    }


}

{'fraction_non_alphanumeric': 0.10393040236134846, 'fraction_numerical': 0.0024856299518409195, 'mean_word_length': 2.959409594095941, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1692603', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1703, 'n_words': 316}