// Path: src/main/java/com/homeadvisor/kafdrop/model/ConsumerVO.java
// public class ConsumerVO implements Comparable<ConsumerVO>
// {
//    private String groupId;
//    private Map<String, ConsumerTopicVO> topics = new TreeMap<>();
//    private List<ConsumerRegistrationVO> activeInstances = new ArrayList<>();
//    private boolean legacy = false;
// 
//    public ConsumerVO(String groupId)
//    {
//       Validate.notEmpty("groupId is required");
//       this.groupId = groupId;
//    }
// 
//    public boolean isLegacy()
//    {
//       return legacy;
//    }
// 
//    public void setLegacy(boolean legacy)
//    {
//       this.legacy = legacy;
//    }
// 
//    public String getGroupId()
//    {
//       return groupId;
//    }
// 
//    public void setGroupId(String groupId)
//    {
//       this.groupId = groupId;
//    }
// 
//    public void addActiveInstance(ConsumerRegistrationVO id)
//    {
//       activeInstances.add(id);
//    }
// 
//    public List<ConsumerRegistrationVO> getActiveInstances()
//    {
//       return activeInstances;
//    }
// 
//    public List<ConsumerRegistrationVO> getActiveInstancesForTopic(String topic)
//    {
//       return activeInstances.stream()
//          .filter(registration -> registration.subscribesToTopic(topic))
//          .collect(Collectors.toList());
//    }
// 
//    public void addTopic(ConsumerTopicVO topic)
//    {
//       topics.put(topic.getTopic(), topic);
//    }
// 
//    public ConsumerTopicVO getTopic(String topic)
//    {
//       return topics.get(topic);
//    }
// 
//    public ConsumerTopicVO getOrCreateTopic(String topic)
//    {
//       ConsumerTopicVO consumerTopic = getTopic(topic);
//       if (consumerTopic == null)
//       {
//          consumerTopic = new ConsumerTopicVO(topic, groupId);
//          addTopic(consumerTopic);
//       }
//       return consumerTopic;
//    }
// 
//    public Collection<ConsumerTopicVO> getTopics()
//    {
//       return topics.values();
//    }
// 
//    public int getActiveTopicCount()
//    {
//       return topics.values().stream()
//          .map(t -> t.getAssignedPartitionCount() > 0 ? 1 : 0)
//          .reduce(0, Integer::sum);
//    }
// 
//    @Override
//    public int compareTo(ConsumerVO that)
//    {
//       return this.groupId.compareTo(that.groupId);
//    }
// 
//    @Override
//    public boolean equals(Object o)
//    {
//       if (this == o) return true;
//       if (o == null || getClass() != o.getClass()) return false;
// 
//       ConsumerVO vo = (ConsumerVO) o;
// 
//       if (!groupId.equals(vo.groupId)) return false;
// 
//       return true;
//    }
// 
//    @Override
//    public int hashCode()
//    {
//       return groupId.hashCode();
//    }
// 
// }
// 
// Path: src/main/java/com/homeadvisor/kafdrop/service/ConsumerNotFoundException.java
// @ResponseStatus(HttpStatus.NOT_FOUND)
// public class ConsumerNotFoundException extends RuntimeException
// {
//    public ConsumerNotFoundException(String message)
//    {
//       super(message);
//    }
// 
//    public ConsumerNotFoundException()
//    {
//    }
// }
// 
// Path: src/main/java/com/homeadvisor/kafdrop/service/KafkaMonitor.java
// public interface KafkaMonitor
// {
//    List<BrokerVO> getBrokers();
// 
//    Optional<BrokerVO> getBroker(int id);
// 
//    default Optional<BrokerConfigurationVO> getBrokerConfiguration(int id)
//    {
//       return Optional.empty();
//    }
// 
//    List<TopicVO> getTopics();
// 
//    Optional<TopicVO> getTopic(String topic);
// 
//    ClusterSummaryVO getClusterSummary(Collection<TopicVO> topics);
// 
//    List<ConsumerVO> getConsumers(TopicVO topic);
// 
//    Optional<ConsumerVO> getConsumer(String groupId);
// 
//    Optional<ConsumerVO> getConsumerByTopic(String groupId, TopicVO topic);
// }


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Optional;
import com.homeadvisor.kafdrop.model.ConsumerVO;
import com.homeadvisor.kafdrop.service.ConsumerNotFoundException;
import com.homeadvisor.kafdrop.service.KafkaMonitor;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
/*
 * Copyright 2017 HomeAdvisor, Inc.
 *
 * 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 com.homeadvisor.kafdrop.controller;



@Controller
@RequestMapping("/consumer")
public class ConsumerController
{
   private final KafkaMonitor kafkaMonitor;

   public ConsumerController(KafkaMonitor kafkaMonitor)
   {
      this.kafkaMonitor = kafkaMonitor;
   }

   @RequestMapping("{groupId:.+}")
   public String consumerDetail(@PathVariable("groupId") String groupId, Model model)
   {
      model.addAttribute("consumer", kafkaMonitor.getConsumer(groupId)
// Path: src/main/java/com/homeadvisor/kafdrop/model/ConsumerVO.java
// public class ConsumerVO implements Comparable<ConsumerVO>
// {
//    private String groupId;
//    private Map<String, ConsumerTopicVO> topics = new TreeMap<>();
//    private List<ConsumerRegistrationVO> activeInstances = new ArrayList<>();
//    private boolean legacy = false;
// 
//    public ConsumerVO(String groupId)
//    {
//       Validate.notEmpty("groupId is required");
//       this.groupId = groupId;
//    }
// 
//    public boolean isLegacy()
//    {
//       return legacy;
//    }
// 
//    public void setLegacy(boolean legacy)
//    {
//       this.legacy = legacy;
//    }
// 
//    public String getGroupId()
//    {
//       return groupId;
//    }
// 
//    public void setGroupId(String groupId)
//    {
//       this.groupId = groupId;
//    }
// 
//    public void addActiveInstance(ConsumerRegistrationVO id)
//    {
//       activeInstances.add(id);
//    }
// 
//    public List<ConsumerRegistrationVO> getActiveInstances()
//    {
//       return activeInstances;
//    }
// 
//    public List<ConsumerRegistrationVO> getActiveInstancesForTopic(String topic)
//    {
//       return activeInstances.stream()
//          .filter(registration -> registration.subscribesToTopic(topic))
//          .collect(Collectors.toList());
//    }
// 
//    public void addTopic(ConsumerTopicVO topic)
//    {
//       topics.put(topic.getTopic(), topic);
//    }
// 
//    public ConsumerTopicVO getTopic(String topic)
//    {
//       return topics.get(topic);
//    }
// 
//    public ConsumerTopicVO getOrCreateTopic(String topic)
//    {
//       ConsumerTopicVO consumerTopic = getTopic(topic);
//       if (consumerTopic == null)
//       {
//          consumerTopic = new ConsumerTopicVO(topic, groupId);
//          addTopic(consumerTopic);
//       }
//       return consumerTopic;
//    }
// 
//    public Collection<ConsumerTopicVO> getTopics()
//    {
//       return topics.values();
//    }
// 
//    public int getActiveTopicCount()
//    {
//       return topics.values().stream()
//          .map(t -> t.getAssignedPartitionCount() > 0 ? 1 : 0)
//          .reduce(0, Integer::sum);
//    }
// 
//    @Override
//    public int compareTo(ConsumerVO that)
//    {
//       return this.groupId.compareTo(that.groupId);
//    }
// 
//    @Override
//    public boolean equals(Object o)
//    {
//       if (this == o) return true;
//       if (o == null || getClass() != o.getClass()) return false;
// 
//       ConsumerVO vo = (ConsumerVO) o;
// 
//       if (!groupId.equals(vo.groupId)) return false;
// 
//       return true;
//    }
// 
//    @Override
//    public int hashCode()
//    {
//       return groupId.hashCode();
//    }
// 
// }
// 
// Path: src/main/java/com/homeadvisor/kafdrop/service/ConsumerNotFoundException.java
// @ResponseStatus(HttpStatus.NOT_FOUND)
// public class ConsumerNotFoundException extends RuntimeException
// {
//    public ConsumerNotFoundException(String message)
//    {
//       super(message);
//    }
// 
//    public ConsumerNotFoundException()
//    {
//    }
// }
// 
// Path: src/main/java/com/homeadvisor/kafdrop/service/KafkaMonitor.java
// public interface KafkaMonitor
// {
//    List<BrokerVO> getBrokers();
// 
//    Optional<BrokerVO> getBroker(int id);
// 
//    default Optional<BrokerConfigurationVO> getBrokerConfiguration(int id)
//    {
//       return Optional.empty();
//    }
// 
//    List<TopicVO> getTopics();
// 
//    Optional<TopicVO> getTopic(String topic);
// 
//    ClusterSummaryVO getClusterSummary(Collection<TopicVO> topics);
// 
//    List<ConsumerVO> getConsumers(TopicVO topic);
// 
//    Optional<ConsumerVO> getConsumer(String groupId);
// 
//    Optional<ConsumerVO> getConsumerByTopic(String groupId, TopicVO topic);
// }


// Path: src/main/java/com/homeadvisor/kafdrop/controller/ConsumerController.java
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Optional;
import com.homeadvisor.kafdrop.model.ConsumerVO;
import com.homeadvisor.kafdrop.service.ConsumerNotFoundException;
import com.homeadvisor.kafdrop.service.KafkaMonitor;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;

/*
 * Copyright 2017 HomeAdvisor, Inc.
 *
 * 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 com.homeadvisor.kafdrop.controller;



@Controller
@RequestMapping("/consumer")
public class ConsumerController
{
   private final KafkaMonitor kafkaMonitor;

   public ConsumerController(KafkaMonitor kafkaMonitor)
   {
      this.kafkaMonitor = kafkaMonitor;
   }

   @RequestMapping("{groupId:.+}")
   public String consumerDetail(@PathVariable("groupId") String groupId, Model model)
   {
      model.addAttribute("consumer", kafkaMonitor.getConsumer(groupId)
         .orElseThrow(() -> new ConsumerNotFoundException(groupId)));