use of com.torodb.packaging.config.model.protocol.mongo.FilterList in project torodb by torodb.
the class FilterListSerializer method serializeFields.
private void serializeFields(FilterList value, JsonGenerator jgen) throws IOException {
for (Map.Entry<String, Map<String, List<IndexFilter>>> databaseEntry : value.entrySet()) {
jgen.writeArrayFieldStart(databaseEntry.getKey());
for (Map.Entry<String, List<IndexFilter>> collection : databaseEntry.getValue().entrySet()) {
if (collection.getValue().isEmpty()) {
jgen.writeString(collection.getKey());
} else {
jgen.writeStartObject();
jgen.writeArrayFieldStart(collection.getKey());
for (IndexFilter indexFilter : collection.getValue()) {
jgen.writeObject(indexFilter);
}
jgen.writeEndArray();
jgen.writeEndObject();
}
}
jgen.writeEndArray();
}
}
use of com.torodb.packaging.config.model.protocol.mongo.FilterList in project torodb by torodb.
the class FilterListDeserializer method deserialize.
@Override
@SuppressFBWarnings("REC_CATCH_EXCEPTION")
public FilterList deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
FilterList filterList = new FilterList();
JsonNode node = jp.getCodec().readTree(jp);
if (node instanceof ObjectNode) {
Iterator<Entry<String, JsonNode>> databaseEntriesIterator = node.fields();
while (databaseEntriesIterator.hasNext()) {
Entry<String, JsonNode> databaseEntry = databaseEntriesIterator.next();
try {
Map<String, List<IndexFilter>> collections = new HashMap<>();
if (databaseEntry.getValue() instanceof ObjectNode) {
readCollectionObject(jp, (ObjectNode) databaseEntry.getValue(), collections);
} else if (databaseEntry.getValue() instanceof ArrayNode) {
ArrayNode collectionsArray = (ArrayNode) databaseEntry.getValue();
Iterator<JsonNode> collectionsIterator = collectionsArray.elements();
int position = 0;
while (collectionsIterator.hasNext()) {
try {
JsonNode collection = collectionsIterator.next();
if (collection instanceof ObjectNode) {
readCollectionObject(jp, (ObjectNode) collection, collections);
} else if (collection instanceof ArrayNode) {
throw new JsonMappingException("wrong filter format: collection value inside " + "database array can not be an array", jp.getCurrentLocation());
} else {
collections.put(collection.asText(), new ArrayList<>());
}
position++;
} catch (Exception e) {
throw JsonMappingException.wrapWithPath(e, collections, position);
}
}
}
filterList.put(databaseEntry.getKey(), collections);
} catch (Exception e) {
throw JsonMappingException.wrapWithPath(e, filterList, databaseEntry.getKey());
}
}
} else {
throw new JsonMappingException("wrong filter format: filter list was not an object", jp.getCurrentLocation());
}
return filterList;
}
use of com.torodb.packaging.config.model.protocol.mongo.FilterList 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();
}
Aggregations