text: /*******************************************************************************
   * This file is part of OpenNMS(R).
   *
   * Copyright (C) 2009-2014 The OpenNMS Group, Inc.
   * OpenNMS(R) is Copyright (C) 1999-2014 The OpenNMS Group, Inc.
   *
   * OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
   *
   * OpenNMS(R) is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Affero General Public License as published
   * by the Free Software Foundation, either version 3 of the License,
   * or (at your option) any later version.
   *
   * OpenNMS(R) is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU Affero General Public License for more details.
   *
   * You should have received a copy of the GNU Affero General Public License
   * along with OpenNMS(R).  If not, see:
   *      http://www.gnu.org/licenses/
   *
   * For more information contact:
   *     OpenNMS(R) Licensing <license@opennms.org>
   *     http://www.opennms.org/
   *     http://www.opennms.com/
   *******************************************************************************/
  
  package org.opennms.web.controller.outage;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.opennms.core.utils.WebSecurityUtils;
  import org.opennms.web.filter.Filter;
  import org.opennms.web.outage.Outage;
  import org.opennms.web.outage.SortStyle;
  import org.opennms.web.outage.WebOutageRepository;
  import org.opennms.web.outage.filter.NodeFilter;
  import org.opennms.web.outage.filter.OutageCriteria;
  import org.opennms.web.outage.filter.PerspectiveLocationFilter;
  import org.opennms.web.outage.filter.RecentOutagesFilter;
  import org.springframework.beans.factory.InitializingBean;
  import org.springframework.util.Assert;
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.mvc.AbstractController;
  
  /**
   * <p>NodeOutagesController class.</p>
   *
   * @author ranger
   * @version $Id: $
   * @since 1.8.1
   */
  public class NodeOutagesController extends AbstractController implements InitializingBean {
  
      private String m_successView;
      private WebOutageRepository m_webOutageRepository;
  
      /** {@inheritDoc} */
      @Override
      protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
      	String nodeIdString = request.getParameter("node");
      	
      	int nodeId = -1;
      	
      	if (nodeIdString != null ) 
          	nodeId = WebSecurityUtils.safeParseInt(nodeIdString);
          Outage[] outages = new Outage[0];
  
          if (nodeId > 0) {
              List<Filter> filters = new ArrayList<>();
  
              filters.add(new NodeFilter(nodeId, getServletContext()));
              filters.add(new RecentOutagesFilter());
              filters.add(new PerspectiveLocationFilter(null));
  
              OutageCriteria criteria = new OutageCriteria(filters.toArray(new Filter[0]), SortStyle.ID, null, -1, -1);
              outages = m_webOutageRepository.getMatchingOutages(criteria);
          }
  
          ModelAndView modelAndView = new ModelAndView(getSuccessView());
          modelAndView.addObject("nodeId", nodeId);
          modelAndView.addObject("outages", outages);
          return modelAndView;
      }
  
      /**
       * <p>afterPropertiesSet</p>
       *
       * @throws java.lang.Exception if any.
       */
      @Override
      public void afterPropertiesSet() throws Exception {
          Assert.notNull(m_successView, "property successView must be set");
          Assert.notNull(m_webOutageRepository, "webOutageRepository must be set");
      }
  
      private String getSuccessView() {
          return m_successView;
      }
  
      /**
       * <p>setSuccessView</p>
       *
       * @param successView a {@link java.lang.String} object.
       */
      public void setSuccessView(String successView) {
          m_successView = successView;
      }
      
      /**
       * <p>setWebOutageRepository</p>
       *
       * @param webOutageRepository a {@link org.opennms.web.outage.WebOutageRepository} object.
       */
      public void setWebOutageRepository(WebOutageRepository webOutageRepository) {
          m_webOutageRepository = webOutageRepository;
      }
  
  }
  