Example usage for com.mongodb BasicDBObject getString

List of usage examples for com.mongodb BasicDBObject getString

Introduction

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

Prototype

public String getString(final String key) 

Source Link

Document

Returns the value of a field as a string

Usage

From source file:cs.rsa.ts14dist.appserver.StandardServerRequestHandler.java

License:Apache License

private boolean updateContentsForUserWithNewLine(String user, String newLineToAdd) {
    // query the database for the document for this user 
    // and update the contents 
    boolean lineAdded = true;
    BasicDBObject persistentObject = storage.getDocumentFor(user);
    if (persistentObject == null) {
        persistentObject = new BasicDBObject();
        persistentObject.put("user", user);
        persistentObject.put("contents", newLineToAdd);
        storage.updateDocument(user, persistentObject);
    } else {//from  www.ja  v  a  2 s. c o m
        String contents = persistentObject.getString("contents");
        if ((contents.length() + newLineToAdd.length() + 1) > Constants.MAX_DOCUMENT_SIZE) {
            lineAdded = false;
        } else {
            contents += "\n" + newLineToAdd;
            persistentObject.put("contents", contents);
            // finally, write the document back into the document database 
            storage.updateDocument(user, persistentObject);
        }
    }
    return lineAdded;
}

From source file:cs.rsa.ts14dist.manual.TeztMongoConnector.java

License:Apache License

@Test
public void shouldStoreAndRetrieveADocument() {

    shouldStoreADocument();/*w  ww . ja v a  2 s.  c o  m*/

    // Validate that the object has been stored in the data storage  
    BasicDBObject dboStored;

    dboStored = storage.getDocumentFor(user);
    String timeSagContents = dboStored.getString("contents");

    assertTrue(timeSagContents.contains("Week 2 :  5 : 0"));
    assertTrue(timeSagContents.contains("Fri    Bi        8.30-16.30"));

    System.out.println(timeSagContents);
}

From source file:DataAccess.Entity.Restaurant.java

public Restaurant(BasicDBObject dBObjectRs) {
    this.name = dBObjectRs.getString("name");
    this.address = dBObjectRs.getString("direccion");
    this.phone = dBObjectRs.getInt("phone");
}

From source file:dk.au.cs.karibu.deserializer.EXMRE001.java

License:Apache License

@Override
public BasicDBObject buildDocumentFromByteArray(byte[] payload) {
    Date theTimestamp;/*from  w w w  . ja  v  a  2  s.  c o m*/

    // The binary payload is actually a string in JSON format 
    String asJSON = new String(payload);

    // and Mongo has utils to convert that :) 
    BasicDBObject dbo = (BasicDBObject) com.mongodb.util.JSON.parse(asJSON);

    // Read out the timestamp as string and write it back as Date object 
    String asISODate = dbo.getString("timestamp");
    theTimestamp = ISO8601Utils.parse(asISODate);
    dbo.put("timestamp", theTimestamp);

    return dbo;
}

From source file:edu.slu.mongoEntity.AcceptedServer.java

public AcceptedServer(BasicDBObject dbo) {
    this.objectID = dbo.getObjectId("_id").toString();
    this.name = dbo.getString("name");
    this.ip = dbo.getString("ip");
    this.contact = dbo.getString("contact");
}

From source file:edu.slu.mongoEntity.Agent.java

public Agent(BasicDBObject dbo) {
    this.objectID = dbo.getObjectId("_id").toString();
    this.aID = dbo.getString("@id");
    this.mbox = dbo.getString("mbox");
    this.mbox_sha1sum = dbo.getString("mbox_sha1sum");
    this.type = dbo.getString("type");
    this.created = dbo.getLong("created");
    this.modified = dbo.getLong("modified");
    this.group = JSONArray.fromObject(dbo.get("group"));
    this.personID = dbo.getString("personID");
    this.organization = JSONArray.fromObject(dbo.get("organization"));
}

From source file:edu.slu.mongoEntity.Person.java

public Person(BasicDBObject dbo) {
    this.objectID = dbo.getObjectId("_id").toString();
    this.email = dbo.getString("email");
    this.surname = dbo.getString("surname");
    this.familyname = dbo.getString("familyname");
    this.pwd = dbo.getString("pwd");
    this.aID = dbo.getString("@id");
    this.dateCreated = dbo.getLong("date_created");
    this.dateUpdated = dbo.getLong("date_updated");
}

From source file:edu.slu.mongoEntity.ProjectUserProfile.java

public ProjectUserProfile(BasicDBObject dbo) {
    this.objectID = dbo.getObjectId("_id").toString();
    if (null != dbo.getString("userObjectID")) {
        this.objectID = dbo.getString("userObjectID");
    }/*  ww w . ja v  a2s .c  o m*/
    if (null != dbo.getString("alias")) {
        this.alias = dbo.getString("alias");
    }
    if (null != dbo.getString("server_ip")) {
        JSONArray ja = (JSONArray) dbo.get("ls_serverIP");
        this.ls_serverIP = ja.subList(0, ja.size() - 1);
    }
    this.dateCreated = dbo.getLong("date_created");
    this.dateUpdated = dbo.getLong("date_updated");
    if (null != dbo.getString("config")) {
        this.config = dbo.getString("config");
    }
}

From source file:entity.Annotation.java

public Annotation(BasicDBObject dbo) {
    this.objectID = dbo.getObjectId("_id").toString();
    this.namespace = dbo.getString("namespace");
    this.content = dbo.getString("content");
    this.selector = dbo.getString("selector");
    this.title = dbo.getString("title");
    this.resource = dbo.getString("resource");
    this.resourceType = dbo.getString("resourceType");
    this.outterRelative = dbo.getString("outterRelative");
    this.addedTime = dbo.getLong("addedTime");
    this.fontColor = dbo.getString("fontColor");
    this.fontType = dbo.getString("fontType");
    this.permission = dbo.getInt("permission");
    this.originalAnnoID = dbo.getString("originalAnnoID");
    this.versionNum = dbo.getInt("versionNum");
    this.forkFromID = dbo.getString("forkFromID");
}

From source file:eu.eubrazilcc.lvl.storage.dao.LeishmaniaDAO.java

License:EUPL

private BasicDBObject parseFilter(final String parameter, final String expression, final BasicDBObject query)
        throws InvalidFilterParseException {
    BasicDBObject query2 = query;// w ww.j  a  v a  2s.  c om
    if (isNotBlank(parameter) && isNotBlank(expression)) {
        String field = null;
        // keyword matching search
        if ("source".equalsIgnoreCase(parameter)) {
            field = DB_PREFIX + "dataSource";
        } else if ("definition".equalsIgnoreCase(parameter)) {
            field = DB_PREFIX + "definition";
        } else if ("accession".equalsIgnoreCase(parameter)) {
            field = DB_PREFIX + "accession";
        } else if ("length".equalsIgnoreCase(parameter)) {
            field = DB_PREFIX + "length";
        } else if ("gene".equalsIgnoreCase(parameter)) {
            field = DB_PREFIX + "gene";
        } else if ("organism".equalsIgnoreCase(parameter)) {
            field = DB_PREFIX + "organism";
        } else if ("country".equalsIgnoreCase(parameter)) {
            field = DB_PREFIX + "countryFeature";
        } else if ("locale".equalsIgnoreCase(parameter)) {
            field = DB_PREFIX + "locale";
        }
        if (isNotBlank(field)) {
            if ("accession".equalsIgnoreCase(parameter)) {
                // convert the expression to upper case and compare for exact matching
                query2 = (query2 != null ? query2 : new BasicDBObject()).append(field,
                        expression.toUpperCase());
            } else if ("locale".equalsIgnoreCase(parameter)) {
                // regular expression to match the language part of the locale
                final Pattern regex = compile("(" + expression.toLowerCase() + ")([_]{1}[A-Z]{2}){0,1}");
                query2 = (query2 != null ? query2 : new BasicDBObject()).append(field, regex);
            } else if ("length".equalsIgnoreCase(parameter)) {
                // comparison operator
                query2 = mongoNumeriComparison(field, expression);
            } else {
                // regular expression to match all entries that contains the keyword
                final Pattern regex = compile(".*" + expression + ".*", CASE_INSENSITIVE);
                query2 = (query2 != null ? query2 : new BasicDBObject()).append(field, regex);
            }
        } else {
            // full-text search
            if ("text".equalsIgnoreCase(parameter)) {
                field = "$text";
            }
            if (isNotBlank(field)) {
                if (query2 != null) {
                    final BasicDBObject textSearch = (BasicDBObject) query2.get("$text");
                    final BasicDBObject search = new BasicDBObject("$search",
                            textSearch != null ? textSearch.getString("$search") + " " + expression
                                    : expression);
                    query2 = query2.append("$text", search.append("$language", "english"));
                } else {
                    final BasicDBObject search = new BasicDBObject("$search", expression);
                    query2 = new BasicDBObject().append("$text", search.append("$language", "english"));
                }
            } else {
                throw new InvalidFilterParseException(parameter);
            }
        }
    }
    return query2;
}