コード例 #1
0
  private void deleteAction(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    Survey survey = (Survey) request.getAttribute(RequestUtils.SURVEY);

    List<Question> questions = (List<Question>) request.getAttribute(RequestUtils.QUESTIONS);
    List<Language> languages = (List<Language>) request.getAttribute(RequestUtils.LANGUAGES);
    List<AnswerSet> answerSets = (List<AnswerSet>) request.getAttribute(RequestUtils.ANSWER_SETS);

    if (!questions.isEmpty()) {
      EditUtils.addEditUsingKey(request, "surveyCantBeDeletedWithQuestionsMessage");
    }

    if (!languages.isEmpty()) {
      EditUtils.addEditUsingKey(request, "surveyCantBeDeletedWithLanguagesMessage");
    }

    if (!answerSets.isEmpty()) {
      EditUtils.addEditUsingKey(request, "surveyCantBeDeletedWithAnswerSetsMessage");
    }

    if (!EditUtils.hasEdits(request)) {
      survey.setLastUpdateUserId(request.getUserPrincipal().getName());
      SurveyDelete.execute(survey);
    }

    if (!EditUtils.hasEdits(request)) {
      RequestUtils.forwardTo(request, response, ControllerConstants.SURVEYS_REDIRECT);
    } else {
      RequestUtils.forwardTo(request, response, ControllerConstants.SURVEY_UPDATE);
    }
  }
コード例 #2
0
  /** Update or delete survey. */
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    setUpData(request);

    Survey survey = (Survey) request.getAttribute(RequestUtils.SURVEY);
    String action = RequestUtils.getAlphaInput(request, "action", "Action", true);
    ResourceBundle bundle = ResourceBundle.getBundle("Text");

    // Process based on action
    if (!StringUtils.isEmpty(action)) {
      if (action.equals(bundle.getString("updateLabel"))) {

        // Fields
        String name =
            RequestUtils.getAlphaInput(request, "name", bundle.getString("nameLabel"), true);
        survey.setName(name);

        updateAction(request, response);
      } else if (action.equals(bundle.getString("deleteLabel"))) {
        deleteAction(request, response);
      }
    } else {
      RequestUtils.forwardTo(request, response, ControllerConstants.SURVEYS_REDIRECT);
    }
  }
コード例 #3
0
  private void updateAction(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    Survey survey = (Survey) request.getAttribute(RequestUtils.SURVEY);

    survey.setLastUpdateUserId(request.getUserPrincipal().getName());
    survey = SurveyUpdate.execute(survey);

    // If no edits, forward to question.
    if (!EditUtils.hasEdits(request)) {
      request.setAttribute("surveyId", survey.getKey().getId());
      RequestUtils.forwardTo(request, response, ControllerConstants.SURVEY_REDIRECT);
    } else {
      RequestUtils.forwardTo(request, response, ControllerConstants.SURVEY_UPDATE);
    }
  }