dimensionDictionary.findAll().stream() .filter(dimension -> dimension instanceof RegisteredLookupDimension) .map(dimension -> (RegisteredLookupDimension) dimension)
@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)); } }
/** * 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; }
Set<Dimension> dimensions = dictionary.findAll(); List<Throwable> caughtExceptions = Collections.emptyList(); for (Dimension dimension : dimensions) {
Set<Dimension> dimensions = dictionary.findAll(); List<Throwable> caughtExceptions = Collections.emptyList(); for (Dimension dimension : dimensions) {