Example usage for com.mongodb BasicDBList BasicDBList

List of usage examples for com.mongodb BasicDBList BasicDBList

Introduction

In this page you can find the example usage for com.mongodb BasicDBList BasicDBList.

Prototype

BasicDBList

Source Link

Usage

From source file:de.uni_koeln.spinfo.maalr.mongo.core.Database.java

License:Apache License

public DatabaseStatistics getStatistics() {
    DatabaseStatistics stats = new DatabaseStatistics();
    stats.setNumberOfEntries((int) entryCollection.getCount());
    Map<Verification, Integer> count = new HashMap<Verification, Integer>();
    DBCursor cursor = entryCollection.find();
    int entryCount = 0, lemmaCount = 0;
    Verification[] values = Verification.values();
    for (Verification verification : values) {
        count.put(verification, 0);/*  w w  w . ja  v a2  s  .  co m*/
    }
    count.put(null, 0);
    while (cursor.hasNext()) {
        LexEntry entry = Converter.convertToLexEntry(cursor.next());
        List<LemmaVersion> history = entry.getVersionHistory();
        entryCount++;
        lemmaCount += history.size();
        for (LemmaVersion lemma : history) {
            Integer old = count.get(lemma.getVerification());
            count.put(lemma.getVerification(), old + 1);
        }
    }
    stats.setNumberOfApproved(count.get(Verification.ACCEPTED));
    stats.setNumberOfSuggestions(count.get(Verification.UNVERIFIED));
    stats.setNumberOfDeleted(count.get(Verification.REJECTED));
    stats.setNumberOfOutdated(count.get(Verification.OUTDATED));
    stats.setNumberOfUndefined(count.get(null));
    stats.setNumberOfEntries(entryCount);
    stats.setNumberOfLemmata(lemmaCount);
    /*
     * TODO: - Create a separate "System/Diagnostics"-Tab, containing a)
     * general information about - RAM - Free Disk Space - CPU - Network b)
     * DB-Statistics - general - entries - users
     * 
     * Check if this will work with sigar:
     * 
     * 
     * 
     * - Add green and red 'lamps' to each entry, each sub-statistic
     * (entries, users, general) - Add one lamp to the navigation bar, to
     * summarize the server state: should always be green.
     */

    CommandResult dbStats = entryCollection.getDB().getStats();

    NumberFormat nf = NumberFormat.getInstance();
    stats.addDBProperty("Server", dbStats.getString("serverUsed"));

    Double serverStatus = dbStats.getDouble("ok");
    if (Double.compare(1D, serverStatus) == 0) {
        stats.addDBProperty("Server Status", "ok");
    } else {
        stats.addDBProperty("Server Status", "not ok: " + serverStatus, Category.ERROR);
    }

    long collections = dbStats.getLong("collections");
    if (collections == 0) {
        stats.addDBProperty("Number of Collections", nf.format(dbStats.getLong("collections")), Category.ERROR);
    } else {
        stats.addDBProperty("Number of Collections", nf.format(dbStats.getLong("collections")));
    }
    stats.addDBProperty("Number of Indexes", nf.format(dbStats.getLong("indexes")));
    stats.addDBProperty("Average Object Size", nf.format(dbStats.getDouble("avgObjSize") / 1024) + " KB");
    stats.addDBProperty("Data Size", nf.format(dbStats.getLong("dataSize") / (1024 * 1024)) + " MB");
    stats.addDBProperty("Storage Size", nf.format(dbStats.getLong("storageSize") / (1024 * 1024)) + " MB");
    stats.addDBProperty("Index Size", nf.format(dbStats.getLong("indexSize") / (1024 * 1024)) + " MB");
    stats.addDBProperty("File Size", nf.format(dbStats.getLong("fileSize") / (1024 * 1024)) + " MB");

    BasicDBObject query;
    BasicDBList attributes;
    query = new BasicDBObject();
    attributes = new BasicDBList();
    DBObject lemmata = new BasicDBObject();
    lemmata.put(QUERY_VERSION_TIMESTAMP, new BasicDBObject("$gt", -1));
    attributes.add(lemmata);
    query.append("$and", attributes);
    // stats.setNumberOfLemmata((int) entryCollection.count(query));

    return stats;
}

From source file:edu.stanford.epad.epadws.aim.AIMQueries.java

License:Open Source License

/**
 * Read the annotations from the AIM database by patient name, patient id, series id, annotation id, or just get all
 * of them on a GET. Can also delete by annotation id.
 * //from w w w.java2  s .c  om
 * @param aimSearchType One of personName, patientId, seriesUID, annotationUID, deleteUID
 * @param value
 * @param user
 * @return List<ImageAnnotationCollection>
 * @throws edu.stanford.hakan.aim4api.base.AimException
 */
public static List<String> getJsonAnnotations(String projectID, AIMSearchType aimSearchType, String value,
        String username) throws Exception {
    //db.Test.find( { 'ImageAnnotationCollection.uniqueIdentifier.root': { $in: [ 'drr7d3pp5sr3up1hbt1v53cf4va5ga57fv8aeri6', 'iqn1vvxtdptm0wtzsc43kptl26oft5c08wxz0w1t' ] } } )
    List<String> results = new ArrayList<String>();
    long time1 = System.currentTimeMillis();
    DBObject query = null;
    if (aimSearchType == AIMSearchType.PERSON_NAME) {
        String personName = value;
        query = new BasicDBObject("ImageAnnotationCollection.person.name.value", personName);
    } else if (aimSearchType == AIMSearchType.PATIENT_ID) {
        String patientId = value;
        query = new BasicDBObject("ImageAnnotationCollection.person.id.value", patientId);
    } else if (aimSearchType == AIMSearchType.SERIES_UID) {
        String seriesUID = value;
        query = new BasicDBObject(
                "ImageAnnotationCollection.imageAnnotations.ImageAnnotation.imageReferenceEntityCollection.ImageReferenceEntity.imageStudy.imageSeries.instanceUid.root",
                seriesUID);
    } else if (aimSearchType == AIMSearchType.ANNOTATION_UID) {
        String annotationUID = value;
        if (value.equals("all")) {
        } else if (value.contains(",")) {
            String[] ids = value.split(",");
            BasicDBList aimIds = new BasicDBList();
            for (String id : ids) {
                aimIds.add(id);
            }
            DBObject inClause = new BasicDBObject("$in", aimIds);
            query = new BasicDBObject("ImageAnnotationCollection.uniqueIdentifier.root", inClause);
        } else {
            query = new BasicDBObject("ImageAnnotationCollection.uniqueIdentifier.root", value);
        }
    } else if (aimSearchType.equals(AIMSearchType.JSON_QUERY)) {
        String jsonQuery = value;
        query = (DBObject) JSON.parse(jsonQuery);
    } else {
        log.warning("Unsupported AIM search type for mongoDB:" + aimSearchType.getName());
    }
    DB mongoDB = MongoDBOperations.getMongoDB();
    if (mongoDB == null)
        throw new Exception("Error connecting to MongoDB");
    DBCollection coll = mongoDB.getCollection(projectID);
    DBCursor cursor = null;
    try {
        cursor = coll.find(query);
        while (cursor.hasNext()) {
            DBObject obj = cursor.next();
            results.add(obj.toString());
        }
    } finally {
        cursor.close();
    }
    long time2 = System.currentTimeMillis();
    log.info("MongoDB query took " + (time2 - time1) + " msecs for " + results.size() + " aims in projectID:"
            + projectID);
    return results;
}

From source file:edu.umass.cs.gnsserver.database.MongoRecords.java

License:Apache License

private BasicDBList parseJSONArrayLocationStringIntoDBList(String string) {
    BasicDBList box1 = new BasicDBList();
    BasicDBList box2 = new BasicDBList();
    BasicDBList box = new BasicDBList();
    try {//from  ww w.jav  a2s . co  m
        JSONArray json = new JSONArray(string);
        box1.add(json.getJSONArray(0).getDouble(0));
        box1.add(json.getJSONArray(0).getDouble(1));
        box2.add(json.getJSONArray(1).getDouble(0));
        box2.add(json.getJSONArray(1).getDouble(1));
        box.add(box1);
        box.add(box2);
    } catch (JSONException e) {
        DatabaseConfig.getLogger().log(Level.SEVERE, "{0} Unable to parse JSON: {1}",
                new Object[] { dbName, e.getMessage() });
    }
    return box;
}

From source file:edu.umass.cs.gnsserver.database.MongoRecords.java

License:Apache License

private MongoRecordCursor selectRecordsNear(String collectionName, ColumnField valuesMapField, String key,
        String value, Double maxDistance, boolean explain) throws FailedDBOperationException {
    db.requestEnsureConnection();/*from  w  w w  .j av  a2 s .  c o  m*/
    DBCollection collection = db.getCollection(collectionName);

    double maxDistanceInRadians = maxDistance / METERS_PER_DEGREE;
    BasicDBList tuple = new BasicDBList();
    try {
        JSONArray json = new JSONArray(value);
        tuple.add(json.getDouble(0));
        tuple.add(json.getDouble(1));
    } catch (JSONException e) {
        DatabaseConfig.getLogger().log(Level.SEVERE, "{0} Unable to parse JSON: {1}",
                new Object[] { dbName, e.getMessage() });
    }
    String fieldName = valuesMapField.getName() + "." + key;
    BasicDBObject nearClause = new BasicDBObject("$near", tuple).append("$maxDistance", maxDistanceInRadians);
    BasicDBObject query = new BasicDBObject(fieldName, nearClause);
    DBCursor cursor = null;
    try {
        cursor = collection.find(query);
    } catch (MongoException e) {
        DatabaseConfig.getLogger().log(Level.FINE, "{0} selectNear failed: {1}",
                new Object[] { dbName, e.getMessage() });
        throw new FailedDBOperationException(collectionName, fieldName,
                "Original mongo exception:" + e.getMessage());
    }
    if (explain) {
        System.out.println(cursor.explain().toString());
    }
    return new MongoRecordCursor(cursor,
            mongoCollectionSpecs.getCollectionSpec(collectionName).getPrimaryKey());
}

From source file:entidades.Carrinho.java

public Document toDocument() {
    Document document = new Document("id", id).append("qtdeItens", qtdeItens).append("valor", valor)
            .append("produtos", produtos);
    BasicDBList produtoList = new BasicDBList();
    for (Produto produto : produtos) {
        produtoList.add(produto.toDocument());
    }/*from   w  w w  . j ava 2  s  .c  o  m*/
    document.append("produtos", produtoList);

    return document;
}

From source file:entitiesConverters.AlbumConverter.java

public static DBObject convertAlbumToDBObject(Album album) {
    BasicDBObject dbAlbum = new BasicDBObject("title", album.getTitle()).append("artist", album.getArtist())
            .append("genre", album.getGenre()).append("label", album.getLabel())
            .append("coverPath", album.getCoverPath()).append("year", album.getYear())
            .append("collection", album.getCollection());

    BasicDBList dbTags = new BasicDBList();
    if (album.getTags() != null && !album.getTags().isEmpty()) {
        for (String tag : album.getTags()) {
            dbTags.add(tag);/* w w w  .  j a  v  a  2 s  . c  o  m*/
        }
    }
    dbAlbum.append("tags", dbTags);

    BasicDBList dbTracks = new BasicDBList();
    if (album.getTracks() != null && !album.getTracks().isEmpty()) {
        for (Track track : album.getTracks()) {
            dbTracks.add(TrackConverter.convertTrackToDBObject(track));
        }
    }
    dbAlbum.append("tracks", dbTracks);

    return dbAlbum;
}

From source file:Entity.Devoir.java

public BasicDBList mapBddRubriques() {
    BasicDBList result = new BasicDBList();
    for (Rubrique rubrique : lstRubrique) {
        BasicDBObject dbRubriques = new BasicDBObject();
        //dbRubriques.append("_id", rubrique.getId());
        dbRubriques.append("libelle", rubrique.getLibelle());
        dbRubriques.append("lstCritere", rubrique.mapBddCritere());
        result.add(dbRubriques);//  w ww  . java 2 s  .  c o m
    }

    return result;
}

From source file:Entity.Devoir.java

public BasicDBList mapBddGroupes() {
    BasicDBList result = new BasicDBList();
    for (Groupe groupe : lstGroupe) {
        BasicDBObject dbGroupes = new BasicDBObject();
        //dbRubriques.append("_id", groupe.getId());
        dbGroupes.append("libelle", groupe.getLibelle());
        dbGroupes.append("lstEtudiant", groupe.mapBddEtudiants());
        dbGroupes.append("lstNote", groupe.mapBddNotes());
        result.add(dbGroupes);//from w w w  .  j a  va  2 s  . c om
    }

    return result;
}

From source file:Entity.Groupe.java

public BasicDBList mapBddNotes() {
    BasicDBList result = new BasicDBList();
    for (Note note : lstNote) {
        BasicDBObject dbNotes = new BasicDBObject();
        //dbRubriques.append("_id", etudiant.getId());
        dbNotes.append("libelle", note.getLibelle());
        dbNotes.append("poid", note.getPoid());
        dbNotes.append("note", note.getNote());
        result.add(dbNotes);/*from w  w w . j a v  a 2s.c  om*/
    }

    return result;
}

From source file:Entity.Groupe.java

public BasicDBList mapBddEtudiants() {
    BasicDBList result = new BasicDBList();
    for (Etudiant etudiant : lstEtudiant) {
        BasicDBObject dbEtudiants = new BasicDBObject();
        //dbRubriques.append("_id", etudiant.getId());
        dbEtudiants.append("nom", etudiant.getNom());
        dbEtudiants.append("prenom", etudiant.getPrenom());
        dbEtudiants.append("classe", etudiant.getClasse());
        result.add(dbEtudiants);/*ww w .j  a  va  2s .c  om*/
    }

    return result;
}