package com.linkedin.thirdeye.dashboard.views;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.apache.commons.math3.util.Pair;

import com.linkedin.thirdeye.dashboard.api.MetricTable;

import io.dropwizard.views.View;

public class DimensionViewContributors extends View {

  private final List<String> metrics;
  private final List<String> dimensions;
  private final Map<String, MetricTable> metricTotalTable;
  private final Map<Pair<String, String>, Map<String, MetricTable>> dimensionValueTables;

  public DimensionViewContributors(List<String> metrics, List<String> dimensions,
      Map<String, MetricTable> metricTotalTable,
      Map<Pair<String, String>, Map<String, MetricTable>> tables) {
    super("dimensions/breakdown.ftl");
    this.metrics = new ArrayList<>(metrics);
    Collections.sort(this.metrics);
    this.metricTotalTable = metricTotalTable;
    this.dimensions = new ArrayList<>(dimensions);
    Collections.sort(this.dimensions);
    this.dimensionValueTables = tables;
  }

  public List<String> getMetrics() {
    return metrics;
  }

  public Map<String, MetricTable> getMetricTotalTable() {
    return metricTotalTable;
  }

  public List<String> getDimensions() {
    return dimensions;
  }

  /*
   * Recommended not to use this. Key = (metric, dimension)
   */
  public Map<Pair<String, String>, Map<String, MetricTable>> getDimensionValueTables() {
    return dimensionValueTables;
  }

  public Map<String, MetricTable> getDimensionValueTable(String metric, String dimension) {
    // return (Map<String, MetricTable>) dimensionValueTables.get(metric, dimension);
    return dimensionValueTables.get(new Pair<String, String>(metric, dimension));
  }

}

@@ -1584,19 +1584,8 @@
     
-// return (
 Map%3C
@@ -1604,17 +1604,33 @@
 icTable%3E
-)
+ result =%0A       
  dimensi
@@ -1647,16 +1647,41 @@
 les.get(
+new Pair%3CString, String%3E(
 metric, 
@@ -1690,16 +1690,17 @@
 mension)
+)
 ;%0A    re
@@ -1708,41 +1708,38 @@
 urn 
-dimensionValueTables.get(new Pair
+(result == null ? Collections.
 %3CStr
@@ -1747,34 +1747,40 @@
 ng, 
-String%3E(metric, dimension)
+MetricTable%3E emptyMap() : result
 );%0A 

Fix Contributors view to support dimension filters by returning empty data for pre-selected dimensions