<commit_before>/**
 * Licensed to Apereo under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Apereo licenses this file to you 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 the following location:
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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 org.jasig.portlet.announcements.mvc.portlet.display;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequest;
import javax.portlet.RenderRequest;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.xml.namespace.QName;

import com.fasterxml.jackson.databind.ObjectMapper;
import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jasig.portlet.announcements.UnauthorizedException;
import org.jasig.portlet.announcements.model.Announcement;
import org.jasig.portlet.announcements.model.AnnouncementSortStrategy;
import org.jasig.portlet.announcements.model.Topic;
import org.jasig.portlet.announcements.model.TopicSubscription;
import org.jasig.portlet.announcements.model.UserRoles;
import org.jasig.portlet.announcements.mvc.IViewNameSelector;
import org.jasig.portlet.announcements.service.IAnnouncementService;
import org.jasig.portlet.announcements.service.ITopicSubscriptionService;
import org.jasig.portlet.announcements.service.UserIdService;
import org.jasig.portlet.announcements.service.UserPermissionChecker;
import org.jasig.portlet.announcements.service.UserPermissionCheckerFactory;
import org.jasig.portlet.notice.NotificationCategory;
import org.jasig.portlet.notice.NotificationEntry;
import org.jasig.portlet.notice.NotificationQuery;
import org.jasig.portlet.notice.NotificationResponse;
import org.jasig.portlet.notice.NotificationResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.portlet.bind.annotation.EventMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;

@Controller
@RequestMapping("VIEW")
public class AnnouncementsViewController {

  public static final String ACTION_DISPLAY_FULL_ANNOUNCEMENT = "displayFullAnnouncement";

  public static final String PREFERENCE_DISPLAY_STARTDATE =
      "AnnouncementsViewController.displayPublishDate";
  public static final String PREFERENCE_DISABLE_EDIT =
      "AnnouncementsViewController.PREFERENCE_DISABLE_EDIT";
  public static final String PREFERENCE_PAGE_SIZE = "AnnouncementsViewController.PAGE_SIZE";
  public static final String PREFERENCE_SORT_STRATEGY =
      "AnnouncementsViewController.AnnouncementSortStrategy";
  public static final String PREFERENCE_USE_SCROLLING_DISPLAY =
      "AnnouncementsViewController.useScrollingDisplay";
  public static final String PREFERENCE_SCROLLING_DISPLAY_HEIGHT_PIXELS =
      "AnnouncementsViewController.scrollingDisplayHeightPixels";
  public static final String PREFERENCE_HIDE_ABSTRACT = "AnnouncementsViewController.hideAbstract";
  public static final String PREFERENCE_SYNDICATE_TOPICS_AS_NOTIFICATIONS =
      "AnnouncementsViewController.syndicateTopicsAsNotifications";
  public static final String PREFERENCE_SYNDICATE_TOPICS_ANNOUNCEMENTS_DISPLAY_FNAME =
      "AnnouncementsViewController.syndicateTopicsAnnouncementsDisplayFName";
  public static final String DEFAULT_SORT_STRATEGY = "START_DISPLAY_DATE_ASCENDING";

  public static final String NOTIFICATION_NAMESPACE =
      "https://source.jasig.org/schemas/portlet/notification";
  public static final String NOTIFICATION_QUERY_LOCAL_NAME = "NotificationQuery";
  public static final QName NOTIFICATION_QUERY_QNAME =
      new QName(NOTIFICATION_NAMESPACE, NOTIFICATION_QUERY_LOCAL_NAME);
  public static final String NOTIFICATION_QUERY_QNAME_STRING =
      "{" + NOTIFICATION_NAMESPACE + "}" + NOTIFICATION_QUERY_LOCAL_NAME;
  public static final String NOTIFICATION_RESULT_LOCAL_NAME = "NotificationResult";
  public static final QName NOTIFICATION_RESULT_QNAME =
      new QName(NOTIFICATION_NAMESPACE, NOTIFICATION_RESULT_LOCAL_NAME);
  public static final String NOTIFICATION_RESULT_QNAME_STRING =
      "{" + NOTIFICATION_NAMESPACE + "}" + NOTIFICATION_RESULT_LOCAL_NAME;
  @Autowired
  private final IAnnouncementService announcementService = null;
  private final ObjectMapper mapper = new ObjectMapper();
  private final Logger logger = LogFactory.getLog(getClass());
  @Autowired
  private ITopicSubscriptionService tss = null;
  @Autowired
  private EhCacheCacheManager cm = null;
  @Autowired(required = true)
  private IViewNameSelector viewNameSelector;
  @Autowired
  private UserPermissionCheckerFactory userPermissionCheckerFactory;
  @Autowired
  private UserIdService userIdService;

  /**
   * Main method of this display controller. Calculates which topics should be shown to this user
   * and which announcements to show from those topics.
   */
  @SuppressWarnings("unchecked")
  @RenderMapping()
  public String mainView(
      Model model,
      RenderRequest request,
      @RequestParam(value = "from", required = false) Integer from,
      @RequestParam(value = "to", required = false) Integer to)
      throws PortletException {<commit_msg>Update AnnouncementsViewController.java<commit_after>/**
 * Licensed to Apereo under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Apereo licenses this file to you 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 the following location:
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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 org.jasig.portlet.announcements.mvc.portlet.display;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequest;
import javax.portlet.RenderRequest;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.xml.namespace.QName;

import com.fasterxml.jackson.databind.ObjectMapper;
import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jasig.portlet.announcements.UnauthorizedException;
import org.jasig.portlet.announcements.model.Announcement;
import org.jasig.portlet.announcements.model.AnnouncementSortStrategy;
import org.jasig.portlet.announcements.model.Topic;
import org.jasig.portlet.announcements.model.TopicSubscription;
import org.jasig.portlet.announcements.model.UserRoles;
import org.jasig.portlet.announcements.mvc.IViewNameSelector;
import org.jasig.portlet.announcements.service.IAnnouncementService;
import org.jasig.portlet.announcements.service.ITopicSubscriptionService;
import org.jasig.portlet.announcements.service.UserIdService;
import org.jasig.portlet.announcements.service.UserPermissionChecker;
import org.jasig.portlet.announcements.service.UserPermissionCheckerFactory;
import org.jasig.portlet.notice.NotificationCategory;
import org.jasig.portlet.notice.NotificationEntry;
import org.jasig.portlet.notice.NotificationQuery;
import org.jasig.portlet.notice.NotificationResponse;
import org.jasig.portlet.notice.NotificationResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.portlet.bind.annotation.EventMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;

@Controller
@RequestMapping("VIEW")
public class AnnouncementsViewController {

  public static final String ACTION_DISPLAY_FULL_ANNOUNCEMENT = "displayFullAnnouncement";

  public static final String PREFERENCE_DISPLAY_STARTDATE =
      "AnnouncementsViewController.displayPublishDate";
  public static final String PREFERENCE_DISABLE_EDIT =
      "AnnouncementsViewController.PREFERENCE_DISABLE_EDIT";
  public static final String PREFERENCE_PAGE_SIZE = "AnnouncementsViewController.PAGE_SIZE";
  public static final String PREFERENCE_SORT_STRATEGY =
      "AnnouncementsViewController.AnnouncementSortStrategy";
  public static final String PREFERENCE_USE_SCROLLING_DISPLAY =
      "AnnouncementsViewController.useScrollingDisplay";
  public static final String PREFERENCE_SCROLLING_DISPLAY_HEIGHT_PIXELS =
      "AnnouncementsViewController.scrollingDisplayHeightPixels";
  public static final String PREFERENCE_HIDE_ABSTRACT = "AnnouncementsViewController.hideAbstract";
  public static final String PREFERENCE_SYNDICATE_TOPICS_AS_NOTIFICATIONS =
      "AnnouncementsViewController.syndicateTopicsAsNotifications";
  public static final String PREFERENCE_SYNDICATE_TOPICS_ANNOUNCEMENTS_DISPLAY_FNAME =
      "AnnouncementsViewController.syndicateTopicsAnnouncementsDisplayFName";
  public static final String DEFAULT_SORT_STRATEGY = "START_DISPLAY_DATE_ASCENDING";

  public static final String NOTIFICATION_NAMESPACE =
      "https://source.jasig.org/schemas/portlet/notification";
  public static final String NOTIFICATION_QUERY_LOCAL_NAME = "NotificationQuery";
  public static final QName NOTIFICATION_QUERY_QNAME =
      new QName(NOTIFICATION_NAMESPACE, NOTIFICATION_QUERY_LOCAL_NAME);
  public static final String NOTIFICATION_QUERY_QNAME_STRING =
      "{" + NOTIFICATION_NAMESPACE + "}" + NOTIFICATION_QUERY_LOCAL_NAME;
  public static final String NOTIFICATION_RESULT_LOCAL_NAME = "NotificationResult";
  public static final QName NOTIFICATION_RESULT_QNAME =
      new QName(NOTIFICATION_NAMESPACE, NOTIFICATION_RESULT_LOCAL_NAME);
  public static final String NOTIFICATION_RESULT_QNAME_STRING =
      "{" + NOTIFICATION_NAMESPACE + "}" + NOTIFICATION_RESULT_LOCAL_NAME;
  @Autowired
  private final IAnnouncementService announcementService = null;
  private final ObjectMapper mapper = new ObjectMapper();
  private final Log logger = LogFactory.getLog(getClass());
  @Autowired
  private ITopicSubscriptionService tss = null;
  @Autowired
  private EhCacheCacheManager cm = null;
  @Autowired(required = true)
  private IViewNameSelector viewNameSelector;
  @Autowired
  private UserPermissionCheckerFactory userPermissionCheckerFactory;
  @Autowired
  private UserIdService userIdService;

  /**
   * Main method of this display controller. Calculates which topics should be shown to this user
   * and which announcements to show from those topics.
   */
  @SuppressWarnings("unchecked")
  @RenderMapping()
  public String mainView(
      Model model,
      RenderRequest request,
      @RequestParam(value = "from", required = false) Integer from,
      @RequestParam(value = "to", required = false) Integer to)
      throws PortletException {
{'fraction_non_alphanumeric': 0.07314821936774095, 'fraction_numerical': 0.0006153372817475579, 'mean_word_length': 6.085558583106267, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, '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': '2410417', 'n_tokens_mistral': 3632, 'n_tokens_neox': 3644, 'n_words': 841}