no.dusken.barweb.WelcomeController.java Source code

Java tutorial

Introduction

Here is the source code for no.dusken.barweb.WelcomeController.java

Source

/*
 Copyright 2009 - 2010 Under Dusken
    
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
    
 http://www.apache.org/licenses/LICENSE-2.0
    
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */
package no.dusken.barweb;

import no.dusken.barweb.service.BarPersonService;
import no.dusken.barweb.service.GjengService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

import static no.dusken.common.util.AuthenticationUtil.getLoggedinUsername;

/**
 * @author Marvin B. Lillehaug <lillehau@underdusken.no>
 */
public class WelcomeController extends AbstractController {

    private GjengService gjengService;

    private BarPersonService barPersonService;

    private String view;

    public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();

        hackToMakeNullAuthPluginWork(request);

        map.put("gjeng", gjengService.getByDefaultGjengTrue());

        map.put("loggedInPerson", barPersonService.getByUsername(getLoggedinUsername()));

        return new ModelAndView(view, map);
    }

    private void hackToMakeNullAuthPluginWork(HttpServletRequest request) {
        HttpSession session = request.getSession();
    }

    @Autowired
    public void setGjengService(GjengService gjengService) {
        this.gjengService = gjengService;
    }

    @Autowired
    public void setBarPersonService(BarPersonService barPersonService) {
        this.barPersonService = barPersonService;
    }

    public void setView(String view) {
        this.view = view;
    }
}