Example usage for com.mongodb BasicDBObject getObjectId

List of usage examples for com.mongodb BasicDBObject getObjectId

Introduction

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

Prototype

public ObjectId getObjectId(final String field) 

Source Link

Document

Returns the object id or null if not set.

Usage

From source file:controllers.DadosBean.java

public void guardarDadosPC() {

    contratacao.setPid(Integer.parseInt(mySessionBean.getPid()));
    String muser = mySessionBean.getUser();

    //verificar se o registo j existe
    BasicDBObject res = (BasicDBObject) conn.getDBCollection()
            .findOne(new BasicDBObject("pid", contratacao.getPid()));
    BasicDBObject o = CPParsers.contratacaoToJson(contratacao);

    if (res == null) {
        //faz insert
        String user = mySessionBean.getUser();
        o.put("user", muser);
        o.put("updated", new Date());
        conn.getDBCollection().insert(o);
    } else {/*from   w  w w. j  a v a2  s .  c  o  m*/
        //faz backup
        conn.setDBCollection("collProcContratacao_Backup");
        res.put("_idOld", res.getObjectId("_id"));
        res.removeField("_id");
        conn.getDBCollection().insert(res);
        //faz update
        conn.setDBCollection("collProcContratacao");

        o.put("user", muser);
        o.put("updated", new Date());
        o.removeField("_id");
        conn.getDBCollection().update(new BasicDBObject("pid", res.getInt("pid")), o);
    }

    APPEUtils.printMessage("Dados guardados com sucesso!");

}

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");
    }//from w w w.  j  ava  2  s .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:net.cogz.friends.GearzFriends.java

License:Open Source License

public List<String> getPlayerFriends(String player) {
    List<String> friends = new ArrayList<>();
    Object friendsObj = getPlayerDocument(player).get("friends");
    if (friendsObj == null || !(friendsObj instanceof BasicDBList)) {
        return friends;
    }/*from ww w  .  j ava  2s  .  c  o  m*/
    BasicDBList friendsList = (BasicDBList) friendsObj;
    for (Object o : friendsList) {
        if (!(o instanceof BasicDBObject))
            continue;
        BasicDBObject friend = (BasicDBObject) o;
        ObjectId id = friend.getObjectId("name");
        DBObject friendObject = getById(id);
        friends.add((String) friendObject.get("current_username"));
    }
    return friends;
}

From source file:net.cogz.friends.GearzFriends.java

License:Open Source License

public void removeFriend(String toUpdate, String toRemove, boolean primary) {
    DBObject playerDocument = getPlayerDocument(toUpdate);
    Object friendsObj = playerDocument.get("friends");
    if (friendsObj == null || !(friendsObj instanceof BasicDBList)) {
        throw new IllegalStateException("That player is not your friend");
    }//from   w w w .  j a v  a  2 s  .  c  o  m
    BasicDBList friendsList = (BasicDBList) friendsObj;
    for (Object object : friendsList) {
        if (!(object instanceof BasicDBObject))
            continue;
        BasicDBObject friend = (BasicDBObject) object;
        ObjectId s = friend.getObjectId("name");
        DBObject toRemoveDocument = getPlayerDocument(toRemove);
        if (s.equals(getObjectId(toRemoveDocument))) {
            friendsList.remove(friend);
            if (primary) {
                removeFriend(toRemove, toUpdate, false);
            }
            playerDocument.put("friends", friendsList);
            getCollection().save(playerDocument);
            return;
        }
    }
    throw new IllegalStateException("That player is not your friend");
}

From source file:net.cogz.friends.GearzFriends.java

License:Open Source License

/**
 * Checks if a player is friends/*from  w  w w. j  a v  a  2s  . c o m*/
 * with another player
 *
 * @param friendOf Player to check friends list of
 * @param toCheck  Player to search list for
 * @return whether or not players are friends
 */
public boolean isFriend(String friendOf, String toCheck) {
    Object friendsObj = getPlayerDocument(friendOf).get("friends");
    if (friendsObj == null || !(friendsObj instanceof BasicDBList))
        return false;
    BasicDBList friendsList = (BasicDBList) friendsObj;
    for (Object object : friendsList) {
        if (!(object instanceof BasicDBObject))
            continue;
        BasicDBObject friend = (BasicDBObject) object;
        DBObject toCheckDocument = getPlayerDocument(toCheck);
        ObjectId name = friend.getObjectId("name");
        if (name.equals(getObjectId(toCheckDocument))) {
            return true;
        }
    }
    return false;
}

From source file:net.cogz.friends.GearzFriends.java

License:Open Source License

public List<String> getPendingRequests(String player) {
    List<String> friends = new ArrayList<>();
    Object friendsObj = getPlayerDocument(player).get("friend_requests");
    if (friendsObj == null || !(friendsObj instanceof BasicDBList)) {
        return friends;
    }//from  w  w w.ja  v  a 2  s .  c  o m
    BasicDBList friendsList = (BasicDBList) friendsObj;
    for (Object o : friendsList) {
        if (!(o instanceof BasicDBObject))
            continue;
        BasicDBObject friend = (BasicDBObject) o;
        ObjectId id = friend.getObjectId("name");
        DBObject friendObject = getById(id);
        friends.add((String) friendObject.get("current_username"));
    }
    return friends;
}