dimensionDictionary.findAll().stream() .filter(dimension -> dimension instanceof RegisteredLookupDimension) .map(dimension -> (RegisteredLookupDimension) dimension)
/** * Adds all of the dimensions in the specified collection to the dictionary. * * @param dimensions collection of dimensions to add * * @return <tt>true</tt> if the dictionary changed as a result of the call * @see Set#addAll(Collection) */ public boolean addAll(Collection<? extends Dimension> dimensions) { boolean flag = false; for (Dimension dimension : dimensions) { flag = add(dimension) || flag; } return flag; }
/** * Constructor. * * @param dimensions Set of Dimension values to add */ public DimensionDictionary(Set<Dimension> dimensions) { this(); addAll(dimensions); }
/** * Cardinality metrics depend on dimensions not metrics. * * @param dependentDimensions The dimension names for this cardinality metric */ @Override protected void assertDependentMetricsExist(List<String> dependentDimensions) { for (String dependentDimension : dependentDimensions) { if (dimensionDictionary.findByApiName(dependentDimension) == null) { String message = String.format( "Cardinality metric dependent dimension %s is not in the dimension dictionary", dependentDimension); LOG.error(message); throw new IllegalArgumentException(message); } } }
/** * Constructor. */ public ResourceDictionaries() { physical = new PhysicalTableDictionary(); logical = new LogicalTableDictionary(); metric = new MetricDictionary(); dimension = new DimensionDictionary(); }
/** * Bind a map from String dimension names to dimension keys. * * @param dimensionNameMap The configuration map from dimension names to sets of dimension key values. * @param dimensionDictionary The dictionary of dimensions to use for binding. * * @return a map of dimensions to dimension key values. */ private Map<Dimension, Set<String>> toDimensionValuesMap( Map<String, Set<String>> dimensionNameMap, DimensionDictionary dimensionDictionary ) { return dimensionNameMap.entrySet().stream() .collect(Collectors.toMap( entry -> dimensionDictionary.findByApiName(entry.getKey()), Map.Entry::getValue ) ); } }
/** * Returns a set of dimension names that contains either the requested dimension or all the available ones. * * @param apiDimension Dimension string from the URL. * @param dimensionDictionary Dimension dictionary contains the map of valid dimension names and dimension objects. * * @return Set of dimension objects. * @throws BadApiRequestException if an invalid dimension is requested or the dimension dictionary is empty. */ protected LinkedHashSet<Dimension> generateDimensions( String apiDimension, DimensionDictionary dimensionDictionary ) throws BadApiRequestException { // Dimension is optional hence check if dimension is requested. LinkedHashSet<Dimension> generated = dimensionDictionary.findAll().stream() .filter(dimension -> apiDimension == null || apiDimension.equals(dimension.getApiName())) .collect(Collectors.toCollection(LinkedHashSet::new)); if (generated.isEmpty()) { String msg; if (dimensionDictionary.findAll().isEmpty()) { msg = EMPTY_DICTIONARY.logFormat("Dimension"); } else { msg = DIMENSIONS_UNDEFINED.logFormat(apiDimension); } LOG.error(msg); throw new BadApiRequestException(msg); } LOG.trace("Generated set of dimensions: {}", generated); return generated; }
/** * Method to get dimension from DimensionDictionary for a given name. * * @param dimensionName To find Dimension from dimension dictionary * * @return The dimension with the given name */ private Dimension resolveDimensionName(String dimensionName) { Dimension dimension = dimensionDictionary.findByApiName(dimensionName); if (dimension == null) { String msg = ErrorMessageFormat.UNABLE_TO_FIND_DIMENSION_FROM_DICTIONARY.format(dimensionName); LOG.error(msg); throw new DeserializationException(msg); } return dimension; }
@Override public void loadDimensionDictionary(DimensionDictionary dimensions) { for (DimensionConfig dimensionConfig : configSource) { if (dimensionConfig.getType().equals(KeyValueStoreDimension.class)) { dimensions.add(new KeyValueStoreDimension(dimensionConfig)); } else if (dimensionConfig.getType().equals(LookupDimension.class)) { dimensions.add(new LookupDimension((LookupDimensionConfig) dimensionConfig)); } else if (dimensionConfig.getType().equals(RegisteredLookupDimension.class)) { dimensions.add(new RegisteredLookupDimension((RegisteredLookupDimensionConfig) dimensionConfig)); } else { throw new RuntimeException( DIMENSION_TYPE_INVALID.format( dimensionConfig.getType(), dimensionConfig.getApiName() ) ); } registerHealthChecks(dimensionConfig); } }
@Override protected Result check() throws Exception { // Gather information about what has been loaded and what hasn't Map<String, String> dimensionLastUpdated = dimensionDictionary.findAll().stream() .collect( StreamUtils.toLinkedMap( Dimension::getApiName, dim -> dim.getLastUpdated() == null ? NEVER : dim.getLastUpdated().toString() ) ); // Signal health if (dimensionLastUpdated.containsValue(NEVER)) { return Result.unhealthy( String.format( "These dimensions have not been loaded: %s", dimensionLastUpdated.entrySet().stream() .filter(entry -> NEVER.equals(entry.getValue())) .map(Map.Entry::getKey) .collect(Collectors.toSet()) ) ); } else { return Result.healthy(String.format("Dimensions have all been loaded: %s", dimensionLastUpdated)); } }
public Response getDimensionLastUpdated(@PathParam("dimensionName") String dimensionName) { Dimension dimension = dimensionDictionary.findByApiName(dimensionName); if (dimension == null) { String message = String.format("Dimension %s cannot be found.", dimensionName);
Set<Dimension> dimensions = dictionary.findAll(); List<Throwable> caughtExceptions = Collections.emptyList(); for (Dimension dimension : dimensions) {
try { Dimension dimension = dimensionDictionary.findByApiName(dimensionName); if (dimension == null) { String message = String.format("Dimension %s cannot be found.", dimensionName);
Set<Dimension> dimensions = dictionary.findAll(); List<Throwable> caughtExceptions = Collections.emptyList(); for (Dimension dimension : dimensions) {
/** * Extracts the list of dimensions from the url dimension path segments and "show" matrix params and generates a map * of dimension to dimension fields which needs to be annotated on the response. * <p> * If no "show" matrix param has been set, it returns the default dimension fields configured for the dimension. * * @param apiDimensionPathSegments Path segments for the dimensions * @param dimensionDictionary Dimension dictionary to look the dimensions up in * * @return A map of dimension to requested dimension fields */ protected LinkedHashMap<Dimension, LinkedHashSet<DimensionField>> generateDimensionFields( @NotNull List<PathSegment> apiDimensionPathSegments, @NotNull DimensionDictionary dimensionDictionary ) { try (TimedPhase timer = RequestLog.startTiming("GeneratingDimensionFields")) { return apiDimensionPathSegments.stream() .filter(pathSegment -> !pathSegment.getPath().isEmpty()) .collect(Collectors.toMap( pathSegment -> dimensionDictionary.findByApiName(pathSegment.getPath()), pathSegment -> bindShowClause(pathSegment, dimensionDictionary), (LinkedHashSet<DimensionField> e, LinkedHashSet<DimensionField> i) -> { e.addAll(i); return e; }, LinkedHashMap::new )); } }
List<String> invalidDimensions = new ArrayList<>(); for (String dimApiName : dimApiNames) { Dimension dimension = dimensionDictionary.findByApiName(dimApiName);
try { Dimension dimension = dimensionDictionary.findByApiName(dimensionName); if (dimension == null) { String message = String.format("Dimension %s cannot be found.", dimensionName);
Dimension dimension = dimensionDictionary.findByApiName(pathSegment.getPath()); List<String> showFields = pathSegment.getMatrixParameters().entrySet().stream() .filter(entry -> entry.getKey().equals("show"))
try { Dimension dimension = dimensionDictionary.findByApiName(dimensionName); if (dimension == null) { String message = String.format("Dimension %s cannot be found.", dimensionName);
Dimension dimension = dimensionDictionary.findByApiName(filterDimensionName);