diff --git a/DatabaseUpdater.java b/DatabaseUpdater.java deleted file mode 100644 index 550649f06ecd195b3627213b1c41825f5cb6bd7e..0000000000000000000000000000000000000000 --- a/DatabaseUpdater.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.group8; - -import com.mongodb.client.MongoClients; -import com.mongodb.client.MongoClient; -import com.mongodb.client.MongoDatabase; -import com.mongodb.client.MongoCollection; -import com.mongodb.client.model.Filters; -import com.mongodb.client.model.ReplaceOptions; -import org.bson.Document; -import object_detection.types.ObjectSet; -import object_detection.types.PointSet; -import java.util.ArrayList; -import java.util.List; - -public class DatabaseUpdater { - - private MongoClient mongoClient; - private MongoDatabase database; - private MongoCollection<Document> collection; - - public DatabaseUpdater() { - String uri = "mongodb+srv://Cluster03790:dlVzT2Z2bEh9@cluster03790.tk4cwyy.mongodb.net/myFirstDatabase?retryWrites=true&w=majority"; - mongoClient = MongoClients.create(uri); - database = mongoClient.getDatabase("Objects"); - collection = database.getCollection("objectSets"); - } - - /** - * Updates the MongoDB with an ObjectSet. - * - * @param objSet The ObjectSet to update in the database. - * @return true if the update was successful, false otherwise. - */ - public boolean updateDB(ObjectSet objSet) { - try { - for (PointSet pointSet : ObjectSet.objects) { - Document doc = pointSetToDocument(String.valueOf(pointSet.hashCode()), pointSet); - ReplaceOptions options = new ReplaceOptions().upsert(true); - collection.replaceOne(Filters.eq("setId", String.valueOf(pointSet.hashCode())), doc, options); - } - return true; - } catch (Exception e) { - System.err.println("An error occurred while updating the database: " + e); - return false; - } - } - - private Document pointSetToDocument(String setId, PointSet pointSet) { - List<Document> pointsList = new ArrayList<>(); - for (Point p : pointSet.getPoints()) { - pointsList.add(new Document("x", p.getX()) - .append("y", p.getY()) - .append("z", p.getZ())); - } - - return new Document("setId", setId) - .append("points", pointsList); - } - - public static void main(String[] args) { - DatabaseUpdater updater = new DatabaseUpdater(); - ObjectSet objectSet = new ObjectSet(); // Assume this is populated - boolean success = updater.updateDB(objectSet); - System.out.println("Update successful: " + success); - } -}