/** * Bind the table name against a Logical table in the table dictionary. * * @param tableName Name of the logical table from the query * @param granularity The granularity for this request * @param logicalTableDictionary Dictionary to resolve logical tables against. * * @return A logical table */ protected LogicalTable bindLogicalTable( String tableName, Granularity granularity, LogicalTableDictionary logicalTableDictionary ) { TableIdentifier tableId = new TableIdentifier(tableName, granularity); // Logical table must be in the logical table dictionary return logicalTableDictionary.get(tableId); }
/** * Extracts the list of logical table names from the url table path segment and generates a set of logical table * objects based on it. * * @param tableName logical table corresponding to the table name specified in the URL * @param tableDictionary Logical table dictionary contains the map of valid table names and table objects. * * @return Set of logical table objects. * @throws BadApiRequestException if an invalid table is requested or the logical table dictionary is empty. */ protected LinkedHashSet<LogicalTable> generateTables(String tableName, LogicalTableDictionary tableDictionary) throws BadApiRequestException { LinkedHashSet<LogicalTable> generated = tableDictionary.values().stream() .filter(logicalTable -> tableName == null || tableName.equals(logicalTable.getName())) .collect(Collectors.toCollection(LinkedHashSet::new)); // Check if logical tables exist with the requested logical table name if (generated.isEmpty()) { String msg; if (tableDictionary.isEmpty()) { msg = EMPTY_DICTIONARY.logFormat("Logical Table"); } else { msg = TABLE_UNDEFINED.logFormat(tableName); } LOG.error(msg); throw new BadApiRequestException(msg); } LOG.trace("Generated set of logical tables: {}", generated); return generated; }
/** * Get the logical tables for which the given logical metric is valid. * * @param logicalMetric Logical Metric to look up Logical Tables by * * @return The list of logical tables that have the logical metric */ public List<LogicalTable> findByLogicalMetric(LogicalMetric logicalMetric) { return values() .stream() .filter(it -> it.getLogicalMetrics().contains(logicalMetric)) .collect(Collectors.toList()); }
/** * Constructor. */ public ResourceDictionaries() { physical = new PhysicalTableDictionary(); logical = new LogicalTableDictionary(); metric = new MetricDictionary(); dimension = new DimensionDictionary(); }
/** * Load a logical table into the logicalDictionary. * <p> * Note: This builds the logical table as well. * * @param logicalTableName The logical table name * @param nameGroup The table group information for the logical table * @param validGrains The accepted grains for the logical table * @param tableDictionary The dictionary to load the logical table into * @param metricDictionary The dictionary to use when looking up metrics for this table */ public void loadLogicalTableWithGranularities( String logicalTableName, TableGroup nameGroup, Set<? extends Granularity> validGrains, LogicalTableDictionary tableDictionary, MetricDictionary metricDictionary ) { // For every legal grain for (Granularity grain : validGrains) { // Build the logical table LogicalTable logicalTable = new LogicalTable(logicalTableName, grain, nameGroup, metricDictionary); // Load it into the dictionary tableDictionary.put(new TableIdentifier(logicalTable), logicalTable); } }
/** * Get the full view of the logical metric. * * @param logicalMetric Logical metric to get the view of * @param logicalTableDictionary Logical Table Dictionary to look up the logical tables this metric is on * @param uriInfo UriInfo of the request * * @return Full view of the logical metric */ public static Map<String, Object> getLogicalMetricFullView( LogicalMetric logicalMetric, LogicalTableDictionary logicalTableDictionary, UriInfo uriInfo ) { Map<String, Object> resultRow = new LinkedHashMap<>(); resultRow.put("category", logicalMetric.getCategory()); resultRow.put("name", logicalMetric.getName()); resultRow.put("longName", logicalMetric.getLongName()); resultRow.put("description", logicalMetric.getDescription()); resultRow.put( "tables", TablesServlet.getLogicalTableListSummaryView( logicalTableDictionary.findByLogicalMetric(logicalMetric), uriInfo ) ); return resultRow; }
"tables", TablesServlet.getLogicalTableListSummaryView( logicalTableDictionary.findByDimension(dimension), uriInfo
/** * Get the logical tables for which the given logical dimension is valid. * * @param dimension Dimension to look up Logical Tables by * * @return The list of logical tables that have the dimension */ public List<LogicalTable> findByDimension(Dimension dimension) { return values() .stream() .filter(it -> it.getDimensions().contains(dimension)) .collect(Collectors.toList()); } }
/** * Extracts a specific logical table object given a valid table name and a valid granularity. * * @param tableName logical table corresponding to the table name specified in the URL * @param granularity logical table corresponding to the table name specified in the URL * @param logicalTableDictionary Logical table dictionary contains the map of valid table names and table objects. * * @return Set of logical table objects. * @throws BadApiRequestException Invalid table exception if the table dictionary returns a null. */ protected LogicalTable generateTable( String tableName, Granularity granularity, LogicalTableDictionary logicalTableDictionary ) throws BadApiRequestException { LogicalTable generated = logicalTableDictionary.get(new TableIdentifier(tableName, granularity)); // check if requested logical table grain pair exists if (generated == null) { String msg = TABLE_GRANULARITY_MISMATCH.logFormat(granularity, tableName); LOG.error(msg); throw new BadApiRequestException(msg); } LOG.trace("Generated logical table: {} with granularity {}", generated, granularity); return generated; }
LogicalTable logicalTable = tableDictionary.get(TableIdentifier.create(request)); TableGroup group = logicalTable.getTableGroup();