<commit_before>package fr.inria.anhalytics.commons.managers;

import com.mongodb.*;
import com.mongodb.gridfs.GridFS;
import com.mongodb.gridfs.GridFSDBFile;
import com.mongodb.gridfs.GridFSInputFile;
import com.mongodb.util.JSON;

import fr.inria.anhalytics.commons.data.Annotation;
import fr.inria.anhalytics.commons.data.BiblioObject;
import fr.inria.anhalytics.commons.data.BinaryFile;
import fr.inria.anhalytics.commons.data.Processings;
import fr.inria.anhalytics.commons.exceptions.DataException;
import fr.inria.anhalytics.commons.utilities.Utilities;

import org.apache.commons.io.IOUtils;

import org.apache.commons.lang3.StringUtils;
import org.bson.types.ObjectId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;

/**
 * Class for retrieving, inserting, updating and organizing metadata TEIs, PDFs
 * and extracted TEI files from MongoDB GridFS.
 * <p>
 * WARNING: to keep in mind - this is not thread safe !
 *
 * @author Achraf
 */
public class MongoFileManager extends MongoManager implements MongoCollectionsInterface {

    private static final Logger logger = LoggerFactory.getLogger(MongoFileManager.class);

    public static final DBObject ONLY_NOT_PROCESSED_FULLTEXT_APPEND_PROCESS = new BasicDBObjectBuilder()
            .add("isFulltextAppended", false)
            .add("isWithFulltext", true)
            .get();

    public static final DBObject ONLY_NOT_PROCESSED_GROBID_PROCESS = new BasicDBObjectBuilder()
            .add("isWithFulltext", true)
            .add(Processings.GROBID.getName(), false)
            .get();

    public static final DBObject ONLY_NOT_PROCESSED_TRANSFORM_METADATA_PROCESS = new BasicDBObjectBuilder()
            .add("isProcessedPub2TEI", false).get();

    public static final DBObject ONLY_NOT_MINED_INIT_KB_PROCESS = new BasicDBObjectBuilder()
            .add("isMined", false).get();

    /**
     * A static {@link MongoFileManager} object containing MongoFileManager
     * instance that can be used from different locations..
     */
    private static MongoFileManager mongoManager = null;

    private GridFS gfs = null;

    private DBObject temp = null;
    private DBCursor cursor = null;
    private DBCollection collection = null;

    public MongoFileManager(boolean isTest) {
        super(isTest);<commit_msg>Fix mongodb query.<commit_after>package fr.inria.anhalytics.commons.managers;

import com.mongodb.*;
import com.mongodb.gridfs.GridFS;
import com.mongodb.gridfs.GridFSDBFile;
import com.mongodb.gridfs.GridFSInputFile;
import com.mongodb.util.JSON;

import fr.inria.anhalytics.commons.data.Annotation;
import fr.inria.anhalytics.commons.data.BiblioObject;
import fr.inria.anhalytics.commons.data.BinaryFile;
import fr.inria.anhalytics.commons.data.Processings;
import fr.inria.anhalytics.commons.exceptions.DataException;
import fr.inria.anhalytics.commons.utilities.Utilities;

import org.apache.commons.io.IOUtils;

import org.apache.commons.lang3.StringUtils;
import org.bson.types.ObjectId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.List;

/**
 * Class for retrieving, inserting, updating and organizing metadata TEIs, PDFs
 * and extracted TEI files from MongoDB GridFS.
 * <p>
 * WARNING: to keep in mind - this is not thread safe !
 *
 * @author Achraf
 */
public class MongoFileManager extends MongoManager implements MongoCollectionsInterface {

    private static final Logger logger = LoggerFactory.getLogger(MongoFileManager.class);

    public static final DBObject ONLY_NOT_PROCESSED_FULLTEXT_APPEND_PROCESS = new BasicDBObjectBuilder()
            .add("isFulltextAppended", false)
            .add("isWithFulltext", true)
            .get();

    public static final DBObject ONLY_NOT_PROCESSED_GROBID_PROCESS = new BasicDBObjectBuilder()
            .add("isWithFulltext", true)
            .add(Processings.GROBID.getName(), null)
            .get();

    public static final DBObject ONLY_NOT_PROCESSED_TRANSFORM_METADATA_PROCESS = new BasicDBObjectBuilder()
            .add("isProcessedPub2TEI", false).get();

    public static final DBObject ONLY_NOT_MINED_INIT_KB_PROCESS = new BasicDBObjectBuilder()
            .add("isMined", false).get();

    /**
     * A static {@link MongoFileManager} object containing MongoFileManager
     * instance that can be used from different locations..
     */
    private static MongoFileManager mongoManager = null;

    private GridFS gfs = null;

    private DBObject temp = null;
    private DBCursor cursor = null;
    private DBCollection collection = null;

    public MongoFileManager(boolean isTest) {
        super(isTest);
{'fraction_non_alphanumeric': 0.0908159081590816, 'fraction_numerical': 0.0016400164001640015, 'mean_word_length': 4.082291666666666, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4446245', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1441, 'n_words': 339}