<commit_before>package uk.gov.openregister.store.mongodb;

import com.google.common.collect.Lists;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.MongoIterable;
import org.bson.Document;
import play.libs.Json;
import uk.gov.openregister.domain.Record;
import uk.gov.openregister.store.Store;

import java.util.*;

public class MongodbStore extends Store {


    private static final int LIMIT = 100;
    private MongoClientURI conf = new MongoClientURI(databaseURI);
    private MongoDatabase db = new MongoClient(conf).getDatabase(conf.getDatabase());
    private String collection;

    public MongodbStore(String databaseURI, String collection) {
        super(databaseURI);
        this.collection = collection;
    }

    @Override
    public List<String> keys() {
        // TODO This is a hack, the list of keys should be provided. Registers register?
        Document first = db.getCollection(this.collection).find().limit(1).first();
        if (first != null) {

            Document node = first.get("entry", Document.class);
            return new ArrayList<>(node.keySet());
        }
        return Collections.emptyList();
    }

    @Override
    public void save(Record s) {

        MongoCollection<Document> collection = db.getCollection(this.collection);
        collection.insertOne(Document.parse(s.toString()));
    }

    @Override
    public Optional<Record> findByKV(String key, String value) {
        BasicDBObject whereQuery = new BasicDBObject();
        whereQuery.put("entry." + key, new BasicDBObject("$regex", "^" + value + "$").append("$options", "i"));
<commit_msg>Adding an extra line so that build can find changes and build again<commit_after>package uk.gov.openregister.store.mongodb;

import com.google.common.collect.Lists;
import com.mongodb.BasicDBList;
import com.mongodb.BasicDBObject;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.MongoIterable;
import org.bson.Document;
import play.libs.Json;
import uk.gov.openregister.domain.Record;
import uk.gov.openregister.store.Store;

import java.util.*;

public class MongodbStore extends Store {


    private static final int LIMIT = 100;
    private MongoClientURI conf = new MongoClientURI(databaseURI);
    private MongoDatabase db = new MongoClient(conf).getDatabase(conf.getDatabase());
    private String collection;

    public MongodbStore(String databaseURI, String collection) {
        super(databaseURI);
        this.collection = collection;
    }

    @Override
    public List<String> keys() {
        // TODO This is a hack, the list of keys should be provided. Registers register?
        Document first = db.getCollection(this.collection).find().limit(1).first();
        if (first != null) {

            Document node = first.get("entry", Document.class);
            return new ArrayList<>(node.keySet());
        }
        return Collections.emptyList();
    }

    @Override
    public void save(Record s) {

        MongoCollection<Document> collection = db.getCollection(this.collection);
        collection.insertOne(Document.parse(s.toString()));
    }

    @Override
    public Optional<Record> findByKV(String key, String value) {
        BasicDBObject whereQuery = new BasicDBObject();

        whereQuery.put("entry." + key, new BasicDBObject("$regex", "^" + value + "$").append("$options", "i"));

{'fraction_non_alphanumeric': 0.11263073209975864, 'fraction_numerical': 0.002145347278090641, 'mean_word_length': 3.697732997481108, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5709183', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1030, 'n_words': 256}