Example usage for com.mongodb BasicDBList get

List of usage examples for com.mongodb BasicDBList get

Introduction

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

Prototype

public Object get(final String key) 

Source Link

Document

Gets a value at an index.

Usage

From source file:ch.windmobile.server.mongo.MongoDataSource.java

License:Open Source License

private StationInfo createStationInfo(BasicDBObject stationJson) {
    StationInfo stationInfo = new StationInfo();

    stationInfo.setId(stationJson.getString("_id"));
    stationInfo.setShortName(stationJson.getString("short"));
    stationInfo.setName(stationJson.getString("name"));
    stationInfo.setDataValidity(getDataValidity(new DateTime()));
    stationInfo.setStationLocationType(StationLocationType.TAKEOFF);
    BasicDBList locationJson = (BasicDBList) stationJson.get("loc");
    stationInfo.setWgs84Longitude((Double) locationJson.get(0));
    stationInfo.setWgs84Latitude((Double) locationJson.get(1));
    ;/*w  w  w  . ja v  a 2 s.  c  o m*/
    stationInfo.setAltitude(stationJson.getInt("alt"));
    stationInfo.setMaintenanceStatus(Status.fromValue(stationJson.getString("status")));

    return stationInfo;
}

From source file:com.appdynamics.monitors.mongo.MongoDBMonitor.java

License:Apache License

private void printReplicaStats(DBObject replicaStats) {
    if (replicaStats != null) {
        String replicaStatsPath = getReplicaStatsMetricPrefix();
        BasicDBList members = (BasicDBList) replicaStats.get("members");
        for (int i = 0; i < members.size(); i++) {
            DBObject member = (DBObject) members.get(i);
            printMetric(replicaStatsPath + member.get("name") + METRIC_SEPARATOR + "Health",
                    (Number) member.get("health"));
            printMetric(replicaStatsPath + member.get("name") + METRIC_SEPARATOR + "State",
                    (Number) member.get("state"));
            printMetric(replicaStatsPath + member.get("name") + METRIC_SEPARATOR + "Uptime",
                    (Number) member.get("uptime"));
        }/*  w  ww  . j  a v a2s . c o m*/
    }
}

From source file:com.edgytech.umongo.ReplSetNode.java

License:Apache License

@Override
protected void populateChildren() {
    // need to make a query to update server list
    try {//  w  w w .  j av  a  2s  .  c  om
        mongo.getDatabaseNames();
    } catch (Exception e) {
        getLogger().log(Level.WARNING, null, e);
    }

    // need to pull servers from configuration to see hidden
    //        List<ServerAddress> addrs = mongo.getServerAddressList();
    final DBCollection col = mongo.getDB("local").getCollection("system.replset");
    DBObject config = col.findOne();
    if (config == null) {
        getLogger().log(Level.WARNING, "No replica set configuration found");
        return;
    }

    BasicDBList members = (BasicDBList) config.get("members");
    for (int i = 0; i < members.size(); ++i) {
        String host = (String) ((DBObject) members.get(i)).get("host");
        try {
            // this will create new MongoClient instance, catch any exception
            addChild(new ServerNode(host, mongo.getMongoClientOptions(), true, false));
        } catch (Exception e) {
            getLogger().log(Level.WARNING, null, e);
        }
    }
}

From source file:com.edgytech.umongo.ReplSetPanel.java

License:Apache License

public void addReplica(ButtonBase button) {
    final DBCollection col = getReplSetNode().getMongoClient().getDB("local").getCollection("system.replset");
    DBObject config = col.findOne();/*from www . j a v  a  2  s  .  c  o m*/
    if (config == null) {
        new InfoDialog(null, "reconfig error", null, "No existing replica set configuration").show();
        return;
    }

    BasicDBList members = (BasicDBList) config.get("members");
    int max = 0;
    for (int i = 0; i < members.size(); ++i) {
        int id = (Integer) ((DBObject) members.get(i)).get("_id");
        if (id > max)
            max = id;
    }

    ReplicaDialog dia = UMongo.instance.getGlobalStore().getReplicaDialog();
    if (!dia.show())
        return;
    BasicDBObject conf = dia.getReplicaConfig(max + 1);
    members.add(conf);
    reconfigure(getReplSetNode(), config);
}

From source file:com.edgytech.umongo.ServerPanel.java

License:Apache License

public void rsRemove(ButtonBase button) throws Exception {
    ReplSetNode replset = (ReplSetNode) getServerNode().getParentNode();
    final DBCollection col = replset.getMongoClient().getDB("local").getCollection("system.replset");
    DBObject config = col.findOne();/* w w  w .  jav a 2 s .co m*/

    BasicDBList members = (BasicDBList) config.get("members");
    int i = 0;
    String myhost = getServerNode().getServerAddress().getHost() + ":"
            + getServerNode().getServerAddress().getPort();
    for (; i < members.size(); ++i) {
        if (myhost.equals(((DBObject) members.get(i)).get("host")))
            break;
    }

    if (i == members.size()) {
        throw new Exception("No such server in configuration");
    }

    members.remove(i);
    ReplSetPanel.reconfigure(replset, config);
}

From source file:com.edgytech.umongo.ServerPanel.java

License:Apache License

public void rsReconfigure(ButtonBase button) throws Exception {
    ReplSetNode replset = (ReplSetNode) getServerNode().getParentNode();
    final DBCollection col = replset.getMongoClient().getDB("local").getCollection("system.replset");
    DBObject config = col.findOne();/* w  w  w .j a  v a  2s  .  co m*/

    BasicDBList members = (BasicDBList) config.get("members");
    int i = 0;
    String myhost = getServerNode().getServerAddress().getHost() + ":"
            + getServerNode().getServerAddress().getPort();
    for (; i < members.size(); ++i) {
        if (myhost.equals(((DBObject) members.get(i)).get("host")))
            break;
    }

    if (i == members.size()) {
        throw new Exception("No such server in configuration");
    }

    ReplicaDialog dia = UMongo.instance.getGlobalStore().getReplicaDialog();
    BasicDBObject oldConf = (BasicDBObject) members.get(i);
    dia.updateFromReplicaConfig(oldConf);
    if (!dia.show())
        return;
    BasicDBObject conf = dia.getReplicaConfig(oldConf.getInt("_id"));
    members.put(i, conf);

    ReplSetPanel.reconfigure(replset, config);
}

From source file:com.fliker.Modal.GuidancePreview.java

public ArrayList onGoingResources(String userid) {

    ArrayList guidancelist = new ArrayList<Post>();

    MongoConnection mongocon = new MongoConnection();
    DBCursor resultcursor = mongocon.getDBObject("provideruserid", userid, "GuidanceContent");
    /*if(resultcursor.hasNext()){
       DBObject theObj = resultcursor.next();*/

    while (resultcursor.hasNext()) {

        DBObject dbj = resultcursor.next();
        HashMap totalSet = new HashMap();
        GuidancePreview guidprev = new GuidancePreview();

        totalSet.put("sharetokenid", (String) dbj.get("sharetokenid"));
        totalSet.put("dashboardid", (String) dbj.get("dashboardid"));
        totalSet.put("averageVelocity", (String) dbj.get("averageVelocity"));
        totalSet.put("blogid", (String) dbj.get("blogid"));

        BasicDBList likedlist = (BasicDBList) dbj.get("likeid");
        BasicDBList sharedlist = (BasicDBList) dbj.get("sharedid");

        totalSet.put("likeid", likedlist.size());
        totalSet.put("shareid", sharedlist.size());

        Guidance guidance = guidprev.getGuidanceSection((String) dbj.get("guidanceid"));

        totalSet.put("guidanceduration", guidance.getGuidanceduration());
        totalSet.put("guidancelocation", guidance.getGuidancelocation());
        totalSet.put("guidancereason", guidance.getGuidancereason());
        totalSet.put("guidancesubject", guidance.getGuidanceSubject());
        totalSet.put("guidancetype", guidance.getGuidencetype());

        ProfilePreview profprev = new ProfilePreview();
        BasicDBList consumeridslist = (BasicDBList) dbj.get("consumeruserid");
        /*for(int i=0;i<fileids.size();i++){ 
           String fileid = (String);/*  ww w.ja v a 2  s.c o  m*/
           fileids.get(i); System.out.println("fileid ++"+fileid); }*/
        LinkedList consumerlist = new LinkedList();

        for (int n = 0; n < consumeridslist.size(); n++) {

            ArrayList profileinfo = profprev.getProfileInfo((String) consumeridslist.get(n));

            for (int m = 0; m < profileinfo.size(); m++) {

                if (profileinfo.get(m) instanceof Profile) {
                    Profile profileinfos = (Profile) profileinfo.get(m);

                    HashMap profileset = new HashMap();

                    profileset.put("profileid", profileinfos.getProfileid());
                    profileset.put("profileImage", profileinfos.getProfileImageid());
                    profileset.put("profileName", profileinfos.getName());
                    profileset.put("userid", profileinfos.getUserid());

                    consumerlist.add(profileset);

                }

            }

        }

        String nextmeeting = guidprev.getnextMeeting((String) dbj.get("timetableid"));

        totalSet.put("nextmeeting", nextmeeting);
        String topiccount = guidprev.getNumberOfBlogsTopics((String) dbj.get("blogid"), userid);
        totalSet.put("topiccount", topiccount);
        totalSet.put("consumerids", consumerlist);

        totalSet.put("guidanceid", (String) dbj.get("guidanceid"));
        totalSet.put("timetableid", (String) dbj.get("timetableid"));

        ArrayList providerprofileinfo = profprev.getProfileInfo((String) dbj.get("provideruserid"));

        for (int m = 0; m < providerprofileinfo.size(); m++) {

            if (providerprofileinfo.get(m) instanceof Profile) {
                Profile profileinfos = (Profile) providerprofileinfo.get(m);

                totalSet.put("providerprofileid", profileinfos.getProfileid());
                totalSet.put("providerprofileimage", profileinfos.getProfileImageid());
                totalSet.put("providername", profileinfos.getName());
                totalSet.put("provideruserid", profileinfos.getUserid());

                //consumerlist.add(profileset);

            }

        }

        //totalSet.put("provideruserid", (String)dbj.get("provideruserid"));

        guidancelist.add(totalSet);
    }

    MongoConnection mongoconnew = new MongoConnection();
    DBCursor resultcursornew = mongoconnew.getDBObject("consumeruserid", userid, "GuidanceContent");

    while (resultcursornew.hasNext()) {

        DBObject dbj = resultcursornew.next();
        HashMap totalSet = new HashMap();
        GuidancePreview guidprev = new GuidancePreview();

        totalSet.put("sharetokenid", (String) dbj.get("sharetokenid"));
        totalSet.put("dashboardid", (String) dbj.get("dashboardid"));
        totalSet.put("averageVelocity", (String) dbj.get("averageVelocity"));
        totalSet.put("blogid", (String) dbj.get("blogid"));

        Guidance guidance = guidprev.getGuidanceSection((String) dbj.get("guidanceid"));

        totalSet.put("guidanceduration", guidance.getGuidanceduration());
        totalSet.put("guidancelocation", guidance.getGuidancelocation());
        totalSet.put("guidancereason", guidance.getGuidancereason());
        totalSet.put("guidancesubject", guidance.getGuidanceSubject());
        totalSet.put("guidancetype", guidance.getGuidencetype());

        ProfilePreview profprev = new ProfilePreview();
        BasicDBList consumeridslist = (BasicDBList) dbj.get("consumeruserid");
        LinkedList consumerlist = new LinkedList();

        for (int n = 0; n < consumeridslist.size(); n++) {

            ArrayList profileinfo = profprev.getProfileInfo((String) consumeridslist.get(n));

            for (int m = 0; m < profileinfo.size(); m++) {

                if (profileinfo.get(m) instanceof Profile) {
                    Profile profileinfos = (Profile) profileinfo.get(m);

                    HashMap profileset = new HashMap();

                    profileset.put("profileid", profileinfos.getProfileid());
                    profileset.put("profileImage", profileinfos.getProfileImageid());
                    profileset.put("profileName", profileinfos.getName());
                    profileset.put("userid", profileinfos.getUserid());

                    consumerlist.add(profileset);

                }

            }

        }

        String nextmeeting = guidprev.getnextMeeting((String) dbj.get("timetableid"));

        totalSet.put("nextmeeting", nextmeeting);
        String topiccount = guidprev.getNumberOfBlogsTopics((String) dbj.get("blogid"), userid);
        totalSet.put("topiccount", topiccount);
        totalSet.put("consumerids", consumerlist);

        totalSet.put("guidanceid", (String) dbj.get("guidanceid"));
        totalSet.put("timetableid", (String) dbj.get("timetableid"));

        ArrayList providerprofileinfo = profprev.getProfileInfo((String) dbj.get("provideruserid"));

        for (int m = 0; m < providerprofileinfo.size(); m++) {

            if (providerprofileinfo.get(m) instanceof Profile) {
                Profile profileinfos = (Profile) providerprofileinfo.get(m);

                HashMap profileset = new HashMap();

                totalSet.put("providerprofileid", profileinfos.getProfileid());
                totalSet.put("providerprofileimage", profileinfos.getProfileImageid());
                totalSet.put("providername", profileinfos.getName());
                totalSet.put("provideruserid", profileinfos.getUserid());

                consumerlist.add(profileset);

            }

        }

        //totalSet.put("provideruserid", (String)dbj.get("provideruserid"));

        guidancelist.add(totalSet);
    }

    return guidancelist;

}

From source file:com.fliker.Modal.GuidancePreview.java

public HashMap getGuidanceData(String guidanceid) {
    // TODO Auto-generated method stub
    HashMap guidanceinfomap = new HashMap();
    MongoConnection mongocon = new MongoConnection();
    DBCursor resultcursor = mongocon.getDBObject("guidanceinfoid", guidanceid, "GuidanceInfo");
    if (resultcursor.hasNext()) {
        DBObject theObj = resultcursor.next();

        String guidancedescription = (String) theObj.get("guidancedescription");
        String guidanceprice = (String) theObj.get("guidanceprice");
        String guidancesubjectexperience = (String) theObj.get("guidancesubjectexperience");
        BasicDBList guidanceendorebylist = (BasicDBList) theObj.get("guidanceendorseby");
        BasicDBList guidanceachevements = (BasicDBList) theObj.get("guidanceachievements");

        LinkedList companylist = new LinkedList();

        if (guidanceendorebylist.size() > 0) {
            for (int m = 0; m < guidanceendorebylist.size(); m++) {

                DBCursor companycursor = mongocon.getDBObject("companyid", (String) guidanceendorebylist.get(m),
                        "Company");
                if (companycursor.hasNext()) {
                    DBObject companyObj = companycursor.next();
                    HashMap companyinfo = new HashMap();
                    companyinfo.put("companyname", companyObj.get("companyname"));
                    companyinfo.put("companylogo", companyObj.get("companylogoid"));

                    companylist.add(companyinfo);
                }/*  w w w.  ja  va 2  s. c  o  m*/

            }
        }
        LinkedList achievements = new LinkedList();

        if (guidanceachevements.size() > 0) {

            for (int n = 0; n < guidanceachevements.size(); n++) {

                achievements.add((String) guidanceachevements.get(n));
            }

        }

        guidanceinfomap.put("guidancedescription", guidancedescription);
        guidanceinfomap.put("guidanceprice", guidanceprice);
        guidanceinfomap.put("guidancesubjectexperience", guidancesubjectexperience);
        guidanceinfomap.put("guidanceendorebylist", companylist);
        guidanceinfomap.put("guidanceachevements", achievements);

    }

    return guidanceinfomap;
}

From source file:com.fliker.Modal.GuidancePreview.java

public void saveFileToStudentsShare(String userids, String fileid, String guidanceid) {
    // TODO Auto-generated method stub

    GuidancePreview guidprev = new GuidancePreview();
    if (userids.equalsIgnoreCase("All")) {
        MongoConnection mongocon = new MongoConnection();

        DBCursor profilecursor = mongocon.getDBObject("guidanceid", guidanceid, "GuidanceContent");
        while (profilecursor.hasNext()) {
            DBObject basicdbj = profilecursor.next();

            BasicDBList userlist = (BasicDBList) basicdbj.get("consumeruserid");
            for (int k = 0; k < userlist.size(); k++) {

                DBCursor profileusercursor = mongocon.getDBObject("userid", (String) userlist.get(k),
                        "Profile");
                while (profileusercursor.hasNext()) {
                    DBObject basicprofdbj = profileusercursor.next();

                    BasicDBList guidancelist = (BasicDBList) basicprofdbj.get("guidanceids");
                    for (int g = 0; g < guidancelist.size(); g++) {

                        DBCursor resultcursor = mongocon.getDBObject("guidanceid", (String) guidancelist.get(g),
                                "GuidanceEntry");
                        while (resultcursor.hasNext()) {
                            DBObject dbj = resultcursor.next();

                            String consumeguidanceid = (String) dbj.get("consumeguidanceid");
                            if (consumeguidanceid.equalsIgnoreCase(guidanceid)) {

                                String sharetokenid = (String) dbj.get("sharetokenid");
                                mongocon.updateObject(new BasicDBObject("guidanceshareid", sharetokenid),
                                        new BasicDBObject("$push",
                                                new BasicDBObject("guidancefileids", fileid)),
                                        "GuidanceEntryShare");
                            }/*from www.ja v  a  2 s.  co  m*/

                        }

                    }
                }

            }
        }
    } else {
        String[] useridrow = userids.split(",");

        for (int i = 0; i < useridrow.length; i++) {
            MongoConnection mongocon = new MongoConnection();

            DBCursor profilecursor = mongocon.getDBObject("userid", useridrow[i], "Profile");
            while (profilecursor.hasNext()) {
                DBObject basicdbj = profilecursor.next();

                BasicDBList guidancelist = (BasicDBList) basicdbj.get("guidanceids");
                for (int g = 0; g < guidancelist.size(); g++) {

                    DBCursor resultcursor = mongocon.getDBObject("guidanceid", (String) guidancelist.get(g),
                            "GuidanceEntry");
                    while (resultcursor.hasNext()) {
                        DBObject dbj = resultcursor.next();

                        String consumeguidanceid = (String) dbj.get("consumeguidanceid");
                        if (consumeguidanceid.equalsIgnoreCase(guidanceid)) {

                            String sharetokenid = (String) dbj.get("sharetokenid");
                            mongocon.updateObject(new BasicDBObject("guidanceshareid", sharetokenid),
                                    new BasicDBObject("$push", new BasicDBObject("guidancefileids", fileid)),
                                    "GuidanceEntryShare");
                        }

                    }

                }
            }
        }

    }

    GuidanceFileShare guidfileshare = new GuidanceFileShare();
    if (userids.equalsIgnoreCase("All")) {
        String[] AllUser = { "All" };
        guidfileshare.setConsumerids(AllUser);
    } else {
        String[] useridnew = userids.split(",");
        guidfileshare.setConsumerids(useridnew);
    }
    guidfileshare.setGuidancefileid(fileid);
    guidfileshare.setGuidanceid(guidanceid);

    MongoConnection mongocon = new MongoConnection();
    BasicDBObject basicreqobjsearch = guidprev.formGuidShareDBObject(guidfileshare);
    mongocon.saveObject(basicreqobjsearch, "GuidanceDashFileShare");

}

From source file:com.fliker.Modal.GuidancePreview.java

public ArrayList getAllGuidanceFiles(String guidanceid) {
    // TODO Auto-generated method stub
    ArrayList existingfiles = new ArrayList();
    MongoConnection mongocon = new MongoConnection();

    DBCursor filecursor = mongocon.getDBObject("guidancesharedid", guidanceid, "GuidanceContentShare");
    while (filecursor.hasNext()) {
        DBObject basicdbj = filecursor.next();
        BasicDBList filelist = (BasicDBList) basicdbj.get("guidancefilelistid");
        for (int t = 0; t < filelist.size(); t++) {
            String filename = "";
            String filesize = "";
            DBCursor filenamecursor = mongocon.getDBObject("fileid", (String) filelist.get(t), "fileupload");
            if (filenamecursor.hasNext()) {
                DBObject filedbj = filenamecursor.next();
                existingfiles.add((String) filelist.get(t) + ":" + (String) filedbj.get("name") + ":"
                        + (String) filedbj.get("size") + ":" + (String) filedbj.get("type"));
            }//from w  w w . j a  v a2  s  . co m
        }
    }
    return existingfiles;
}