com.seajas.search.attender.controller.HomePageController.java Source code

Java tutorial

Introduction

Here is the source code for com.seajas.search.attender.controller.HomePageController.java

Source

/**
 * Copyright (C) 2013 Seajas, the Netherlands.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.seajas.search.attender.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.seajas.search.attender.model.setting.MailSettings;
import com.seajas.search.attender.service.attender.AttenderService;
import com.seajas.search.utilities.spring.security.model.ExtendedUserDetails;
import com.seajas.search.utilities.spring.security.model.User;

/**
 * Home page controller.
 * 
 * @author Jasper van Veghel <jasper@seajas.com>
 */
@RequestMapping({ "/", "/index.html" })
@Controller
public class HomePageController {
    /**
     * Attender service.
     */
    @Autowired
    private AttenderService attenderService;

    /**
     * User attribute.
     */
    @ModelAttribute("user")
    public User populateUser() {
        return ((ExtendedUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal())
                .getUser();
    }

    /**
     * Inject whether we use a fixed e-mail server.
     * 
     * @return String
     */
    @ModelAttribute("mailSettingsFixed")
    public Boolean populateMailSettingsFixed() {
        return attenderService.getMailServerFixed();
    }

    /**
     * Inject the current mail settings, if any.
     * 
     * @return MailSettings
     */
    @ModelAttribute("mailSettings")
    public MailSettings populateMailSettings() {
        return attenderService.getMailServerDetails();
    }

    /**
     * Inject whether the current mail settings, if any, are valid.
     * 
     * @return Boolean
     */
    @ModelAttribute("mailSettingsValidated")
    public Boolean populateMailSettingsValidated() {
        return attenderService.validateCurrentMailServerDetails();
    }

    /**
     * Handle the request.
     * 
     * @param model
     */
    @RequestMapping(method = RequestMethod.GET)
    public String handleRequest(final ModelMap model) {
        model.put("profiles", attenderService.getProfileCount());
        model.put("profilesDisabled", attenderService.getDisabledProfileCount());
        model.put("profilesNotifiable", attenderService.getNotifiableProfileCount());

        return "index";
    }
}