All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.formkiq.server.controller.IndexController Maven / Gradle / Ivy

There is a newer version: 0.6.1
Show newest version
package com.formkiq.server.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.formkiq.server.service.UserService;

/**
 * Static Content Controller.
 *
 */
@Controller
public class IndexController {

    /** User Service. */
    @Autowired
    private UserService userservice;

    /** User Count Cache. */
    private int userCount = -1;

    /**
     * @return int
     */
    private int getUserCount() {

        if (this.userCount < 1) {
            this.userCount = this.userservice.findUsers().getUsers().size();
        }

        return this.userCount;
    }

    /**
     * Handle static home page.
     * @return {@link String}
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index() {

        if (getUserCount() < 1) {
            return "redirect:/setup";
        }

        return "redirect:/login";
    }

    /**
     * Handle static login page.
     * @return {@link String}
     */
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login() {
        return "login";
    }

    /**
     * Handle static setup page.
     * @return {@link String}
     */
    @RequestMapping(value = "/setup", method = RequestMethod.GET)
    public String setup() {

        if (getUserCount() == 0) {
            return "setup";
        }

        return "redirect:/";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy