Search in sources :

Example 6 with MongoCollection

use of com.mongodb.client.MongoCollection in project repairnator by Spirals-Team.

the class CheckIfFutureBuildIdWhereWellComputed method main.

public static void main(String[] args) throws IOException {
    List<String> allIds = Files.readAllLines(new File(args[0]).toPath());
    String dbCollectionUrl = args[1];
    String dbName = args[2];
    String collectionName = args[3];
    final List<String> projectsNames = Files.readAllLines(new File(args[4]).toPath());
    String githubLogin = args[5];
    String githubToken = args[6];
    RepairnatorConfig.getInstance().setGithubLogin(githubLogin);
    RepairnatorConfig.getInstance().setGithubToken(githubToken);
    MongoConnection mongoConnection = new MongoConnection(dbCollectionUrl, dbName);
    MongoDatabase database = mongoConnection.getMongoDatabase();
    MongoCollection collection = database.getCollection(collectionName);
    Calendar limitDateMay = Calendar.getInstance();
    limitDateMay.set(2017, Calendar.MAY, 10);
    HashMap<String, List<Integer>> results = new HashMap<>();
    Block<Document> block = new Block<Document>() {

        @Override
        public void apply(Document document) {
            Object pBuildId = document.get("previousBuildId");
            if (pBuildId instanceof Integer) {
                int previousBuildId = document.getInteger("previousBuildId", -1);
                int nextBuildId = document.getInteger("buildId", -1);
                if (previousBuildId != -1 && nextBuildId != -1) {
                    Build previousBuild = BuildHelper.getBuildFromId(previousBuildId, null);
                    Build nextBuild = BuildHelper.getNextBuildOfSameBranchOfStatusAfterBuild(previousBuild, null);
                    if (nextBuild.getId() != nextBuildId) {
                        String projectName = previousBuild.getRepository().getSlug();
                        if (projectsNames == null || projectsNames.contains(projectName)) {
                            if (!results.containsKey(projectName)) {
                                results.put(projectName, new ArrayList<>());
                            }
                            results.get(projectName).add(previousBuildId);
                            i++;
                        }
                    }
                }
            }
        }
    };
    for (String s : allIds) {
        int buildId = Integer.parseInt(s);
        collection.find(and(gt("buildReproductionDate", limitDateMay.getTime()), eq("previousBuildId", buildId), eq("lastReproducedBuggyBuild", true))).forEach(block);
    }
    System.out.println(allIds.size() + " ids read, and got: " + i);
    System.out.println(results.keySet().size() + " detected projects: (" + StringUtils.join(results.keySet(), ",") + ")");
    System.out.println("Results:");
    for (String s : results.keySet()) {
        System.out.println("Project " + s + " : ");
        System.out.println(StringUtils.join(results.get(s), "\n"));
        System.out.println("\n");
    }
}
Also used : HashMap(java.util.HashMap) Calendar(java.util.Calendar) Document(org.bson.Document) MongoCollection(com.mongodb.client.MongoCollection) Build(fr.inria.spirals.jtravis.entities.Build) Block(com.mongodb.Block) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) MongoDatabase(com.mongodb.client.MongoDatabase)

Example 7 with MongoCollection

use of com.mongodb.client.MongoCollection in project repairnator by Spirals-Team.

the class CheckIfIdsAreInDatabase method main.

public static void main(String[] args) throws IOException {
    List<String> allIds = Files.readAllLines(new File(args[0]).toPath());
    String dbCollectionUrl = args[1];
    String dbName = args[2];
    String collectionName = args[3];
    List<String> projectsNames = null;
    if (args.length > 4) {
        projectsNames = Files.readAllLines(new File(args[4]).toPath());
        String githubLogin = args[5];
        String githubToken = args[6];
        RepairnatorConfig.getInstance().setGithubLogin(githubLogin);
        RepairnatorConfig.getInstance().setGithubToken(githubToken);
    }
    MongoConnection mongoConnection = new MongoConnection(dbCollectionUrl, dbName);
    MongoDatabase database = mongoConnection.getMongoDatabase();
    MongoCollection collection = database.getCollection(collectionName);
    Calendar limitDateMay = Calendar.getInstance();
    // limitDateMay.set(2017, Calendar.MAY, 10);
    limitDateMay.set(2017, Calendar.SEPTEMBER, 8);
    Calendar limitDateNow = Calendar.getInstance();
    HashMap<String, List<Integer>> results = new HashMap<>();
    int i = 0;
    for (String s : allIds) {
        int buildId = Integer.parseInt(s);
        long total = collection.count(and(gt("buildReproductionDate", limitDateMay.getTime()), eq("previousBuildId", buildId)));
        if (total == 0) {
            Build build = BuildHelper.getBuildFromId(buildId, null);
            String projectName = build.getRepository().getSlug();
            if (projectsNames == null || projectsNames.contains(projectName)) {
                if (!results.containsKey(projectName)) {
                    results.put(projectName, new ArrayList<>());
                }
                results.get(projectName).add(buildId);
                i++;
            }
        }
    }
    System.out.println(allIds.size() + " ids read, and got: " + i);
    System.out.println(results.keySet().size() + " detected projects: (" + StringUtils.join(results.keySet(), ",") + ")");
    System.out.println("Results:");
    for (String s : results.keySet()) {
        System.out.println("Project " + s + " : ");
        System.out.println(StringUtils.join(results.get(s), "\n"));
        System.out.println("\n");
    }
}
Also used : HashMap(java.util.HashMap) Calendar(java.util.Calendar) MongoCollection(com.mongodb.client.MongoCollection) Build(fr.inria.spirals.jtravis.entities.Build) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) MongoDatabase(com.mongodb.client.MongoDatabase)

Example 8 with MongoCollection

use of com.mongodb.client.MongoCollection in project repairnator by Spirals-Team.

the class UpdateDataForSpecifyingLastReproduction method main.

public static void main(String[] args) {
    String dbConnectionUrl = args[0];
    String dbName = args[1];
    String collectionName = args[2];
    MongoConnection mongoConnection = new MongoConnection(dbConnectionUrl, dbName);
    MongoDatabase database = mongoConnection.getMongoDatabase();
    MongoCollection collection = database.getCollection(collectionName);
    Calendar limitDateMay = Calendar.getInstance();
    limitDateMay.set(2017, Calendar.MAY, 10);
    final List<ObjectId> updatedDocs = new ArrayList<>();
    Set<Integer> ids = new HashSet<>();
    Block<Document> block = new Block<Document>() {

        @Override
        public void apply(Document document) {
            ObjectId documentId = document.getObjectId("_id");
            Object pBuildId = document.get("previousBuildId");
            if (pBuildId instanceof Integer) {
                int previousBuildId = document.getInteger("previousBuildId", -1);
                if (previousBuildId != -1) {
                    boolean lastReproducedBuggyBuild = !ids.contains(previousBuildId);
                    ids.add(previousBuildId);
                    document.append("lastReproducedBuggyBuild", lastReproducedBuggyBuild);
                    collection.replaceOne(eq("_id", documentId), document, new UpdateOptions().upsert(true));
                    updatedDocs.add(documentId);
                }
            }
        }
    };
    collection.find().sort(orderBy(descending("buildReproductionDate"))).forEach(block);
    System.out.println("Updated docs: " + updatedDocs.size());
}
Also used : ObjectId(org.bson.types.ObjectId) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Document(org.bson.Document) UpdateOptions(com.mongodb.client.model.UpdateOptions) MongoCollection(com.mongodb.client.MongoCollection) Block(com.mongodb.Block) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) MongoDatabase(com.mongodb.client.MongoDatabase) HashSet(java.util.HashSet)

Example 9 with MongoCollection

use of com.mongodb.client.MongoCollection in project repairnator by Spirals-Team.

the class CleanNopolCollection method main.

public static void main(String[] args) {
    Map<Integer, Set<String>> presentInDb = new HashMap<>();
    String dbCollectionUrl = args[0];
    String dbName = args[1];
    String collectionName = args[2];
    MongoConnection mongoConnection = new MongoConnection(dbCollectionUrl, dbName);
    MongoDatabase database = mongoConnection.getMongoDatabase();
    MongoCollection collection = database.getCollection(collectionName);
    Block<Document> block = new Block<Document>() {

        @Override
        public void apply(Document document) {
            int buildId = document.getInteger("buildId");
            String location = document.getString("testClassLocation");
            ObjectId id = document.getObjectId("_id");
            if (presentInDb.containsKey(buildId)) {
                Set<String> localSet = presentInDb.get(buildId);
                if (localSet.contains(location)) {
                    collection.deleteOne(eq("_id", id));
                    counterDeleted++;
                    return;
                } else {
                    localSet.add(location);
                }
            } else {
                Set<String> localSet = new HashSet<>();
                localSet.add(location);
                presentInDb.put(buildId, localSet);
            }
            counterKept++;
        }
    };
    collection.find().forEach(block);
    System.out.println(counterDeleted + " entries deleted and " + counterKept + " kept.");
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ObjectId(org.bson.types.ObjectId) Document(org.bson.Document) MongoCollection(com.mongodb.client.MongoCollection) Block(com.mongodb.Block) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) MongoDatabase(com.mongodb.client.MongoDatabase) HashSet(java.util.HashSet)

Example 10 with MongoCollection

use of com.mongodb.client.MongoCollection in project repairnator by Spirals-Team.

the class RemoveDuplicatedBuildsId method main.

public static void main(String[] args) {
    Set<Integer> buildIds = new HashSet<>();
    String dbCollectionUrl = args[0];
    String dbName = args[1];
    String collectionName = args[2];
    MongoConnection mongoConnection = new MongoConnection(dbCollectionUrl, dbName);
    MongoDatabase database = mongoConnection.getMongoDatabase();
    MongoCollection collection = database.getCollection(collectionName);
    Block<Document> block = new Block<Document>() {

        @Override
        public void apply(Document document) {
            int buildId = document.getInteger("buildId");
            ObjectId id = document.getObjectId("_id");
            if (buildIds.contains(buildId)) {
                collection.deleteOne(eq("_id", id));
                counterDeleted++;
                return;
            } else {
                buildIds.add(buildId);
                counterKept++;
            }
        }
    };
    collection.find().sort(orderBy(descending("buildReproductionDate"))).forEach(block);
    System.out.println(counterDeleted + " entries deleted and " + counterKept + " kept.");
}
Also used : MongoCollection(com.mongodb.client.MongoCollection) ObjectId(org.bson.types.ObjectId) Block(com.mongodb.Block) Document(org.bson.Document) MongoConnection(fr.inria.spirals.repairnator.serializer.mongodb.MongoConnection) HashSet(java.util.HashSet) MongoDatabase(com.mongodb.client.MongoDatabase)

Aggregations

MongoCollection (com.mongodb.client.MongoCollection)53 Document (org.bson.Document)39 MongoDatabase (com.mongodb.client.MongoDatabase)21 List (java.util.List)16 FindIterable (com.mongodb.client.FindIterable)14 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)11 BasicDBObject (com.mongodb.BasicDBObject)10 Set (java.util.Set)9 ObjectId (org.bson.types.ObjectId)9 MongoCursor (com.mongodb.client.MongoCursor)7 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Bson (org.bson.conversions.Bson)7 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 BsonDocument (org.bson.BsonDocument)6 Block (com.mongodb.Block)5 UpdateOptions (com.mongodb.client.model.UpdateOptions)5