Package com.vst.webapp.action

Source Code of com.vst.webapp.action.QuestionController

package com.vst.webapp.action;

import com.vst.Constants;
import com.vst.model.Question;
import com.vst.service.ConstructionTypeManager;
import com.vst.service.QuestionManager;
import com.vst.service.QuestionTypeManager;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.ResourceBundle;

public class QuestionController implements Controller {
    private final Log log = LogFactory.getLog(QuestionController.class);
    private QuestionManager questionManager = null;
    private ConstructionTypeManager constructionTypeManager = null;
    private QuestionTypeManager questionTypeManager = null;


    public void setConstructionTypeManager(ConstructionTypeManager constructionTypeManager) {
        this.constructionTypeManager = constructionTypeManager;
    }

    public void setQuestionTypeManager(QuestionTypeManager questionTypeManager) {
        this.questionTypeManager = questionTypeManager;
    }

    public void setQuestionManager(QuestionManager questionManager) {
        this.questionManager = questionManager;
    }

    public ModelAndView handleRequest(HttpServletRequest request,
                                      HttpServletResponse response)
            throws Exception {

        request.setAttribute("questionVisualTypeList", questionManager.getQuestionVisualList());

        if (log.isDebugEnabled()) {
            log.debug("entering 'handleRequest' method...");
        }

        if (request.getParameter("edited") != null) {
            request.setAttribute("addition", "?edited=1");
        }

        String pageNumber = request.getParameter("d-7815394-p");
        if (pageNumber != null) {
            request.setAttribute("pageNumber", "d-7815394-p=" + pageNumber);
        }

        request.setAttribute("constructionTypeList", constructionTypeManager.getConstructionTypes(null));
        request.setAttribute("questionTypeList", questionTypeManager.getQuestionTypes(null));

        if (request.getParameter("delete") != null) {
            String questionId = request.getParameter("id");
            ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");
            boolean hasFatalError = false;
            try {
                if (questionManager.removeQuestion(questionId)) {

                    request.setAttribute("message", bundle.getString("question.deleted"));
                } else {
                    request.setAttribute("errormessage", bundle.getString("question.isUsed"));
                    request.setAttribute("refferenceList", questionManager.getConnectedRefferences(questionId));

                }
            } catch (Exception e) {
                e.printStackTrace();
                hasFatalError = true;
            }
            if (hasFatalError) {
                request.setAttribute("errormessage", bundle.getString("commonMistake"));
            }
        }

        if (request.getParameter("raise") != null) {
            String questionId = request.getParameter("id");

            questionManager.raisePriority(questionId);
        }

        List questions;
        if (request.getParameter("isSearched") == null) {
            questions = questionManager.getQuestions(null);
        } else {
            Question question = new Question();
            Integer constructionTypeId = (Integer) Integer.parseInt(request.getParameter("constructionTypeId"));
            Integer questionTypeId = (Integer) Integer.parseInt(request.getParameter("questionTypeId"));
            question.setConstructionTypeId(constructionTypeId);
            if (questionTypeId.equals(new Integer(1))) {
                question.setQuestionTypeId(new Integer(1));
            }
            if (questionTypeId.equals(new Integer(2))) {
                question.setQuestionTypeId(new Integer(1));
                question.setForObjectStructure(true);
            }

            if (questionTypeId.equals(new Integer(3))) {
                question.setQuestionTypeId(new Integer(0));
            }
            questions = questionManager.findQuestions(question);
            request.setAttribute("currentConstructionTypeId", constructionTypeId);
            request.setAttribute("currentQuestionTypeId", questionTypeId);
        }

        return new ModelAndView("questionList", Constants.QUESTION_LIST, questions);
    }
}
TOP

Related Classes of com.vst.webapp.action.QuestionController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.