<commit_before>/*
 * Copyright 1998-2018 Linux.org.ru
 *    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 ru.org.linux.comment;

import com.google.common.collect.ImmutableMap;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import ru.org.linux.auth.IPBlockDao;
import ru.org.linux.auth.IPBlockInfo;
import ru.org.linux.csrf.CSRFNoAuto;
import ru.org.linux.markup.MessageTextService;
import ru.org.linux.search.SearchQueueSender;
import ru.org.linux.site.Template;
import ru.org.linux.spring.dao.MessageText;
import ru.org.linux.spring.dao.MsgbaseDao;
import ru.org.linux.topic.Topic;
import ru.org.linux.topic.TopicPermissionService;
import ru.org.linux.user.User;
import ru.org.linux.util.ServletParameterException;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Controller
public class EditCommentController {
  @Autowired
  private CommentService commentService;

  @Autowired
  private MsgbaseDao msgbaseDao;

  @Autowired
  private IPBlockDao ipBlockDao;

  @Autowired
  private TopicPermissionService topicPermissionService;

  @Autowired
  private CommentPrepareService commentPrepareService;

  @Autowired
  private SearchQueueSender searchQueueSender;

  @InitBinder("edit")
  public void requestValidator(WebDataBinder binder) {
    commentService.requestValidator(binder);
  }

  @InitBinder
  public void initBinder(WebDataBinder binder) {
    commentService.initBinder(binder);
  }

  @ModelAttribute("ipBlockInfo")
  private IPBlockInfo loadIPBlock(HttpServletRequest request) {
    return ipBlockDao.getBlockInfo(request.getRemoteAddr());
  }

  @ModelAttribute("modes")
  public Map<String, String> getModes(HttpServletRequest request) {
    Template tmpl = Template.getTemplate(request);

    if (tmpl.getProf().getFormatMode().equals("ntobr")) {
      return MessageTextService.PostingModesJava();
    } else {
      return ImmutableMap.of();
    }
  }

  /**
   * Показ формы изменения комментария.
   */
  @RequestMapping(value = "/edit_comment", method = RequestMethod.GET)
  public ModelAndView editCommentShowHandler(
          @ModelAttribute("add") @Valid CommentRequest commentRequest,
          HttpServletRequest request
  ) throws Exception {
    Topic topic = commentRequest.getTopic();

    if (topic == null) {
      throw new ServletParameterException("тема на задана");
    }

    Comment original = commentRequest.getOriginal();<commit_msg>one more fixup<commit_after>/*
 * Copyright 1998-2018 <EMAIL>
 *    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 ru.org.linux.comment;

import com.google.common.collect.ImmutableMap;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.Errors;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import ru.org.linux.auth.IPBlockDao;
import ru.org.linux.auth.IPBlockInfo;
import ru.org.linux.csrf.CSRFNoAuto;
import ru.org.linux.search.SearchQueueSender;
import ru.org.linux.site.Template;
import ru.org.linux.spring.dao.MessageText;
import ru.org.linux.spring.dao.MsgbaseDao;
import ru.org.linux.topic.Topic;
import ru.org.linux.topic.TopicPermissionService;
import ru.org.linux.user.User;
import ru.org.linux.util.ServletParameterException;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Controller
public class EditCommentController {
  @Autowired
  private CommentService commentService;

  @Autowired
  private MsgbaseDao msgbaseDao;

  @Autowired
  private IPBlockDao ipBlockDao;

  @Autowired
  private TopicPermissionService topicPermissionService;

  @Autowired
  private CommentPrepareService commentPrepareService;

  @Autowired
  private SearchQueueSender searchQueueSender;

  @InitBinder("edit")
  public void requestValidator(WebDataBinder binder) {
    commentService.requestValidator(binder);
  }

  @InitBinder
  public void initBinder(WebDataBinder binder) {
    commentService.initBinder(binder);
  }

  @ModelAttribute("ipBlockInfo")
  private IPBlockInfo loadIPBlock(HttpServletRequest request) {
    return ipBlockDao.getBlockInfo(request.getRemoteAddr());
  }

  @ModelAttribute("modes")
  public Map<String, String> getModes() {
    return ImmutableMap.of();
  }

  /**
   * Показ формы изменения комментария.
   */
  @RequestMapping(value = "/edit_comment", method = RequestMethod.GET)
  public ModelAndView editCommentShowHandler(
          @ModelAttribute("add") @Valid CommentRequest commentRequest,
          HttpServletRequest request
  ) throws Exception {
    Topic topic = commentRequest.getTopic();

    if (topic == null) {
      throw new ServletParameterException("тема на задана");
    }

    Comment original = commentRequest.getOriginal();
{'fraction_non_alphanumeric': 0.0921090803597331, 'fraction_numerical': 0.0034812880765883376, 'mean_word_length': 4.69364161849711, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7319648', 'n_tokens_mistral': 1949, 'n_tokens_neox': 1971, 'n_words': 466}