Search in sources :

Example 1 with IndexPattern

use of com.torodb.mongodb.repl.ReplicationFilters.IndexPattern in project torodb by torodb.

the class ReplicationFiltersFactory method convertFilterList.

@SuppressWarnings("checkstyle:LineLength")
private static ImmutableMap<Pattern, ImmutableMap<Pattern, ImmutableList<IndexPattern>>> convertFilterList(FilterList filterList) {
    ImmutableMap.Builder<Pattern, ImmutableMap<Pattern, ImmutableList<IndexPattern>>> filterBuilder = ImmutableMap.builder();
    if (filterList != null) {
        for (Map.Entry<String, Map<String, List<IndexFilter>>> databaseEntry : filterList.entrySet()) {
            ImmutableMap.Builder<Pattern, ImmutableList<IndexPattern>> collectionsBuilder = ImmutableMap.builder();
            for (Map.Entry<String, List<IndexFilter>> collection : databaseEntry.getValue().entrySet()) {
                ImmutableList.Builder<IndexPattern> indexesBuilder = ImmutableList.builder();
                for (IndexFilter indexFilter : collection.getValue()) {
                    Pattern indexNamePattern = ANY;
                    if (indexFilter.getName() != null) {
                        indexNamePattern = SimpleRegExpDecoder.decode(indexFilter.getName());
                    }
                    IndexPattern.Builder indexPatternBuilder = new IndexPattern.Builder(indexNamePattern, indexFilter.getUnique());
                    for (Map.Entry<String, String> indexFieldFilter : indexFilter.getKeys().entrySet()) {
                        ImmutableList.Builder<Pattern> fieldReferencePatternBuilder = ImmutableList.builder();
                        for (String indexFieldKeyFilter : KEYS_SPLITTER.split(indexFieldFilter.getKey())) {
                            fieldReferencePatternBuilder.add(SimpleRegExpDecoder.decode(indexFieldKeyFilter));
                        }
                        indexPatternBuilder.addFieldPattern(fieldReferencePatternBuilder.build(), SimpleRegExpDecoder.decode(FilterList.getIndexType(indexFieldFilter.getValue()).getName()));
                    }
                    indexesBuilder.add(indexPatternBuilder.build());
                }
                collectionsBuilder.put(SimpleRegExpDecoder.decode(collection.getKey()), indexesBuilder.build());
            }
            filterBuilder.put(SimpleRegExpDecoder.decode(databaseEntry.getKey()), collectionsBuilder.build());
        }
    }
    return filterBuilder.build();
}
Also used : IndexPattern(com.torodb.mongodb.repl.ReplicationFilters.IndexPattern) Pattern(java.util.regex.Pattern) IndexPattern(com.torodb.mongodb.repl.ReplicationFilters.IndexPattern) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMap(com.google.common.collect.ImmutableMap) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) FilterList(com.torodb.packaging.config.model.protocol.mongo.FilterList) IndexFilter(com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 IndexPattern (com.torodb.mongodb.repl.ReplicationFilters.IndexPattern)1 FilterList (com.torodb.packaging.config.model.protocol.mongo.FilterList)1 IndexFilter (com.torodb.packaging.config.model.protocol.mongo.FilterList.IndexFilter)1 List (java.util.List)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1