diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoDBHandler.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoDBHandler.java index 436ad38..e347e32 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoDBHandler.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoDBHandler.java @@ -56,7 +56,9 @@ public class MongoDBHandler { private MongoCollection memberPhotoCollection; private MongoCollection historyCollection; - + /** + * Implementiert von Valentin + */ public MongoDBHandler() { // Set loglevel for slf4j to avoid spam // TODO: Fix this (optional) System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "error"); @@ -115,6 +117,7 @@ public class MongoDBHandler { /** * Get the MongoDB according to properties. * If a local server URI is defined, use it. Otherwise, use remote server. + * Implementiert von Valentin * @return MongoDatabase */ static public MongoDatabase getMongoDatabase() { @@ -175,6 +178,7 @@ public class MongoDBHandler { /** * * @return List with the names of all collections + * Implementiert von Valentin */ public Set getCollectionNames() { // return getDatabase().listCollectionNames().into(new ArrayList<>()); @@ -185,6 +189,7 @@ public class MongoDBHandler { * * @param name Name of collection to check for existance * @return does the collection exist + * Implementiert von Valentin */ public boolean collectionExists(String name) { return getDatabase().listCollectionNames().into(new ArrayList<>()).contains(name); @@ -193,6 +198,7 @@ public class MongoDBHandler { /** * Tries to create a collection. If the collection exists and contains documents, throw an exception + * Implementiert von Valentin * @param database * @param collectionName */ @@ -218,6 +224,7 @@ public class MongoDBHandler { /** * Create Collection + * Implementiert von Valentin * @param database * @param collectionName */ @@ -236,6 +243,7 @@ public class MongoDBHandler { /** * Creates a collection. If the collection exists already, delete all its document + * Implementiert von Valentin * @param database * @param collectionName */ @@ -251,7 +259,12 @@ public class MongoDBHandler { } } - + /** + * Implementiert von Valentin + * @param collection + * @param indexName + * @param isAscending + */ static public void createIndexForCollection(MongoCollection collection, String indexName, boolean isAscending) { // MongoDB creates automatically an index on "_id" if (indexName.equals(DEFAULT_ID_FIELD_NAME)) { @@ -265,6 +278,12 @@ public class MongoDBHandler { } } + /** + * Implementiert von Valentin + * @param collection + * @param indexNames + * @param isAscending + */ static public void createIndexForCollection(MongoCollection collection, List indexNames, boolean isAscending) { // MongoDB creates automatically an index on "_id" if (indexNames.contains(DEFAULT_ID_FIELD_NAME)) { @@ -279,6 +298,9 @@ public class MongoDBHandler { } } + /** + * Implementiert von Valentin + */ public void createIndicesForSpeakerCollection() { if (speakerCollection.listIndexes().into(new ArrayList<>()).size() == 1) { MongoDBHandler.createIndexForCollection(speakerCollection,"name", true); @@ -287,6 +309,10 @@ public class MongoDBHandler { } } + + /** + * Implementiert von Valentin + */ public void createIndicesForSpeechCollection() { if (speechesCollection.listIndexes().into(new ArrayList<>()).size() == 1) { MongoDBHandler.createIndexForCollection(speechesCollection, "speakerId", true); @@ -301,6 +327,7 @@ public class MongoDBHandler { /** * Does a document with a given ID (for the "_id"-field) exists in a given collection? + * Implementiert von Valentin * @param collection * @param id * @return @@ -314,6 +341,7 @@ public class MongoDBHandler { /** * Find a document with a given ID (for the "_id"-field) in a given collection + * Implementiert von Valentin * @param collection * @param id * @return the document (null if not found) @@ -325,7 +353,7 @@ public class MongoDBHandler { } /** - * + *Implementiert von Valentin * @param collection * @return count of documents in the collection */ @@ -339,7 +367,7 @@ public class MongoDBHandler { /** - * + *Implementiert von Valentin * @param database * @param collectionName * @return count of documents in the collection @@ -353,7 +381,7 @@ public class MongoDBHandler { } /** - * + *Implementiert von Valentin * @param database * @param collectionName */ @@ -372,6 +400,7 @@ public class MongoDBHandler { */ /** + * Implementiert von Valentin * Creates a BSON document containing only simple fields according to fields given in a map * @param attributes * @return @@ -390,6 +419,7 @@ public class MongoDBHandler { } /** + * Implementiert von Valentin * Creates a BSON document containing simple fields (attributes) as well as other (possibly nested) objects * @param attributes the simple fields * @param fields the (possibly nested) objects @@ -418,6 +448,7 @@ public class MongoDBHandler { } /** + * Implementiert von Valentin * Liefert ein Feldwert aks Double, auch wenn er in der Datenbank als Integer oder String steht * @param doc Mongo-Dokument * @param fieldName Feldname @@ -439,7 +470,7 @@ public class MongoDBHandler { /** - * + *Implementiert von Valentin * @param collection * @param doc * @return @@ -449,7 +480,7 @@ public class MongoDBHandler { } /** - * + *Implementiert von Valentin * @param collection * @param docs * @return @@ -459,7 +490,7 @@ public class MongoDBHandler { } /** - * + *Implementiert von Valentin * @param collection * @param fieldName * @param fieldValue @@ -471,6 +502,7 @@ public class MongoDBHandler { /** + * Implementiert von Valentin * Searches a document and performs an update on it * The document to update must be matched by name and value of a certain field * @param collection @@ -493,7 +525,7 @@ public class MongoDBHandler { /** - * + *Implementiert von Valentin * @param collection * @param searchCriteriaName search criteria: name of the field * @param searchCriteriaValue search criteria: value of the field diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoObjectFactory.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoObjectFactory.java index dd5ac73..c1fd65c 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoObjectFactory.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoObjectFactory.java @@ -13,7 +13,7 @@ public class MongoObjectFactory { private static MongoObjectFactory factory = null; /** - * + *Gesamte File implementiert von Valentin * @return MongoObjectFactory */ public static MongoObjectFactory getFactory() { diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoOperations.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoOperations.java index 4fd3dc8..627c782 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoOperations.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoOperations.java @@ -4,6 +4,10 @@ import org.bson.Document; import java.util.List; +/** + * Implementiert von Valentin + * @param + */ public interface MongoOperations { MongoObjectFactory factory = MongoObjectFactory.getFactory(); public Document createEntity(T entity); diff --git a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoPprUtils.java b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoPprUtils.java index 52b20ef..595d43e 100644 --- a/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoPprUtils.java +++ b/src/main/java/org/texttechnologylab/project/gruppe_05_1/database/MongoPprUtils.java @@ -57,11 +57,18 @@ public class MongoPprUtils { private static MongoCollection commentCollection = null; private static MongoCollection metadataCollection = null; + /** + * Implementiert von Valentin + * @return + */ public static MongoCollection getSpeakerCollection() { if (speakerCollection == null) speakerCollection = MongoDBHandler.getMongoDatabase().getCollection(SPEAKER_COLLECTION_NAME); return speakerCollection; } - + /** + * Implementiert von Valentin + * @return + */ public static MongoCollection getSpeechCollection() { if (speechCollection == null) speechCollection = MongoDBHandler.getMongoDatabase().getCollection(SPEECH_COLLECTION_NAME); return speechCollection; @@ -82,12 +89,17 @@ public class MongoPprUtils { return picturesCollection; } + /** + * Implementiert von Valentin + * @return + */ public static MongoCollection getMetadataCollection() { if (metadataCollection == null) metadataCollection = MongoDBHandler.getMongoDatabase().getCollection(METADATA_COLLECTION_NAME); return metadataCollection; } /** + * Implementiert von Valentin * Create the Speaker Collection and useful indices for it */ public static void createIndexForSpeakerCollection() { @@ -98,6 +110,7 @@ public class MongoPprUtils { } /** + * Implementiert von Valentin * Create the Speech Collection and useful indices for it */ public static void createIndexForSpeechCollection() { @@ -107,6 +120,7 @@ public class MongoPprUtils { /** + * Implementiert von Valentin * Truncate the Speaker Collection. * Note that it is quicker (and saves space) to drop and re-create rather than removing all documents using "remove({})" */ @@ -123,6 +137,7 @@ public class MongoPprUtils { /** + * Implementiert von Valentin * Holt alle Parlamentarier, die einen Suchkriterium erfüllen. * Das Suchkriterium wird auf allen Feldern angewandt: Vorname, Nachname, Partei. * Ist das Suchkriterium leer, werden alle Parlamentarier zurückgeliefert @@ -246,6 +261,7 @@ public class MongoPprUtils { /** + * Implementiert von Valentin * Hole alle Reden gefiltert nach den Form-Parameter * @param ctx Session Context, aus dem man alle Parameter abfragen kann * @return @@ -301,6 +317,7 @@ public class MongoPprUtils { /** + * Implementiert von Valentin * Liest einen Parlamentarier von der MongoDB * @param doc - MongoDB Dokument eines Parlamentariers * @return Parlamentarier @@ -367,6 +384,7 @@ public class MongoPprUtils { /** + * Implementiert von Valentin * Holt die Details eines Parlamentariers * @param id Parlamentarier-ID (Integer) * @return ParlamentarierDetails @@ -474,9 +492,9 @@ public class MongoPprUtils { // Speech - // TODO: kopiere die Speech-Sachen von Übung 4 hierher! /** + * Implementiert von Valentin * Aufzählen, wie viele Reden eines bestimmten Redners gespeichert sind * @param speakerId * @return Anzahl Reden @@ -487,6 +505,7 @@ public class MongoPprUtils { /** + * Implementiert von Valentin * Liefert alle Reden eines Redners zurück * @param speakerId * @return Alle Reden eines Redners @@ -505,6 +524,7 @@ public class MongoPprUtils { } /** + * Implementiert von Valentin * Liefert alle Reden zurück * Die Auswahl kann durch einen (textuellen) Filter eingeschränkt werden * @param filter @@ -541,6 +561,7 @@ public class MongoPprUtils { } /** + * Implementiert von Valentin * Liefert Metadaten (aber keine Inhalte!) für alle Reden eines Redners zurück. * Als Metadaten zählen das Datum, Agenda-ID etc. * @param speakerId @@ -584,6 +605,7 @@ public class MongoPprUtils { } /** + * Implementiert von Valentin * Liefert Metadaten (aber keine Inhalte!) für alle Reden zurück. * Die Auswahl kann durch einen (textuellen) Filter eingeschränkt werden * Als Metadaten zählen das Datum, Agenda-ID etc. @@ -646,6 +668,7 @@ public class MongoPprUtils { /** + * Implementiert von Valentin * Holt die Redeinformationen aus der Datenbank, die wichtig sind, um eine Liste der Reden in HTML darzustellen * @return */ @@ -682,6 +705,7 @@ public class MongoPprUtils { } /** + * Implementiert von Valentin * Holt die Redeinformationen aus der Datenbank, die wichtig sind, um eine Liste der Reden eines Parlamentariers in HTML darzustellen * @param speakerId * @return @@ -721,6 +745,7 @@ public class MongoPprUtils { } /** + * Implementiert von Valentin * Füge Rede-Metadaten (welche in der Session-Collection stehen) der Rede hinzu. * Achtung: Redezeit ist in der Datenbank in unterschiedlichen Formaten vorhanden. * @param sessionId @@ -746,6 +771,7 @@ public class MongoPprUtils { } /** + * Implementiert von Valentin * Liefert das Datum und die Uhrzeit einer Sitzung zurück * @param sessionId * @return @@ -761,6 +787,7 @@ public class MongoPprUtils { } /** + * Implementiert von Valentin * Liefert den Agenda-Titel zurück * @param sessionId * @return @@ -777,6 +804,7 @@ public class MongoPprUtils { } /** + * Implementiert von Valentin * Liefert die Rede-Informationen für die Anzeige einer Rede: * - die Rede-ID * - Name und Fraktion des Redners @@ -827,6 +855,7 @@ public class MongoPprUtils { /** + * Implementiert von Valentin * Aktualisiert (or erzeugt, falls nicht bereits vorhanden) diverse Metadaten: * - Die Liste der Parteien/Fraktionen, wie sie im Speaker-Collection stehen * - Die Liste der Parteien/Fraktionen, wie sie im Speech-Collection stehen (diese Listen sind recht unterschiedlich) @@ -879,6 +908,11 @@ public class MongoPprUtils { Logger.info("Updating Metadata Collection: end"); } + /** + * Implementiert von Valentin + * @param speakerId + * @return + */ public static List getSpeechesBySpeakerId(String speakerId) { List speechIds = new ArrayList<>(); Document filter = new Document("speakerId", Integer.parseInt(speakerId)); @@ -889,6 +923,10 @@ public class MongoPprUtils { return speechIds; } + /** + * Implementiert von Valentin + * @return + */ public static List getAllSpeeches() { List speechIds = new ArrayList<>(); Document filter = new Document(); @@ -949,6 +987,7 @@ public class MongoPprUtils { } /** + * Implementiert von Valentin * Liefert die Liste aller Parteien/Fraktionen, welche in der Liste der Parlamentarier stehen, zurück. * Diese Liste dient zur Filterung der Parlamentarier auf der entsprechenden Seite. * @return List Liste aller Parteien/Fraktionen, welche in der Liste der Parlamentarier stehen @@ -970,6 +1009,7 @@ public class MongoPprUtils { ); /** + * Implementiert von Valentin * Liefert die Liste aller Parteien/Fraktionen, welche in der Liste der Reden stehen, zurück. * Diese Liste dient zur Filterung der Reden auf der entsprechenden Seite. * Da die Datenqualität dieses Feldes extrem schlecht ist, muss man hier etwas tricksen: @@ -986,6 +1026,7 @@ public class MongoPprUtils { } /** + * Implementiert von Valentin * Reichere die Rede-Dokumente um Informationen an: * - Datum und Uhrzeit der Rede (als DateTime und textuell): dateTimeString , dateTime * - Agenda-Titel: agendaTitel @@ -1051,6 +1092,7 @@ public class MongoPprUtils { } /** + * Implementiert von Valentin * Liefert die Liste aller Topics, zurück. * Diese Liste dient zur Filterung der Reden auf der entsprechenden Seite. * @return Liste aller Topics