Example usage for com.mongodb DBCursor hasNext

List of usage examples for com.mongodb DBCursor hasNext

Introduction

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

Prototype

@Override
public boolean hasNext() 

Source Link

Document

Checks if there is another object available.

Usage

From source file:com.fileoperations.FolderDownload.java

public Boolean renameFolder(String newName) throws IOException {
    try {/*ww w  .  j  av  a2  s  . c  o  m*/
        String mongoFolder = parentPath + pathMerger + folderName;
        BasicDBObject query = new BasicDBObject();
        query.put("_id", mongoFolder);
        DBCursor cursor = collection.find(query);
        if (cursor.hasNext()) {
            BasicDBObject newquery = new BasicDBObject();
            newquery.put("_id", parentPath + pathMerger + newName);
            if (collection.find(newquery).hasNext()) {
                return false;
            }
            BasicDBObject doc = new BasicDBObject();
            doc.put("_id", parentPath + pathMerger + newName);
            doc.put("folder", "1");
            doc.put("name", newName);
            doc.put("parent", parentPath);
            doc.put("type", "1");

            collection.insert(doc);

            getPathOfAllChildrenFolder(parentPath, folderName);
            BasicDBObject toFindAllFilesInFolder = new BasicDBObject();
            toFindAllFilesInFolder.put("$or", pathOfChildrenFolders);
            GridFS fileStore = new GridFS(mymongo.getDB(), userCollectionName);
            List<GridFSDBFile> AllFiles = fileStore.find(toFindAllFilesInFolder);

            for (int i = 0; i < AllFiles.size(); i++) {
                GridFSDBFile indivFile = AllFiles.get(i);
                InputStream data = indivFile.getInputStream();
                String zipPath;
                zipPath = indivFile.get("path").toString();
                String tempFileName = indivFile.getFilename();
                zipPath = zipPath.replaceFirst(parentPath + pathMerger + folderName,
                        parentPath + pathMerger + newName);
                BasicDBObject document = new BasicDBObject();
                document.append("_id", zipPath + pathMerger + tempFileName);
                document.append("folder", "0");
                document.append("parent", zipPath);
                document.append("name", tempFileName);
                int index = tempFileName.lastIndexOf(".");
                document.append("type", tempFileName.substring(index));
                collection.insert(document);
                GridFSInputFile inputFile = fileStore.createFile(data);
                inputFile.setId(zipPath + pathMerger + tempFileName);
                inputFile.put("path", zipPath);
                inputFile.setFilename(tempFileName);
                inputFile.save();

            }

            BasicDBObject toFindAllEmptyFilesInFolder = new BasicDBObject();
            toFindAllEmptyFilesInFolder.put("$or", pathOfChildrenEmptyFolders);
            DBCursor allFolders = collection.find(toFindAllEmptyFilesInFolder);
            while (allFolders.hasNext()) {
                DBObject temp = allFolders.next();
                if (temp.get("folder").toString().equals("1")) {
                    String tempPath = temp.get("parent").toString();
                    tempPath = tempPath.replaceFirst(parentPath + pathMerger + folderName,
                            parentPath + pathMerger + newName);
                    BasicDBObject updocument = new BasicDBObject();
                    updocument.put("_id", tempPath + pathMerger + temp.get("name"));
                    updocument.put("folder", "1");
                    updocument.put("name", temp.get("name"));
                    updocument.put("parent", tempPath);
                    updocument.put("type", "1");
                    collection.insert(updocument);

                }
            }

            return true;
        } else {
            return false;
        }

    } finally {
        mymongo.closeConnection();
    }
}

From source file:com.fileoperations.RenameFolder.java

public Boolean forSingleFile() {
    try {/*from w  ww  .j  a  v  a2 s. c om*/
        if (oldName.contains(".")) {

            BasicDBObject query = new BasicDBObject();
            query.put("_id", parentPath + pathMerger + oldName);
            DBCursor cursor = collection.find(query);

            if (cursor.hasNext()) {
                DBObject renameFile = cursor.next();
                BasicDBObject checknewquery = new BasicDBObject();
                checknewquery.put("_id", parentPath + pathMerger + newName + renameFile.get("type").toString());
                DBCursor tempCursor = collection.find(checknewquery);
                if (tempCursor.hasNext()) {
                    return false;
                }

                GridFS file = new GridFS(mymongo.getDB(), userCollectionName);
                InputStream data = file.findOne(query).getInputStream();

                BasicDBObject document = new BasicDBObject();
                document.append("_id", parentPath + pathMerger + newName + renameFile.get("type").toString());
                document.append("folder", "0");
                document.append("parent", parentPath);
                document.append("name", newName + renameFile.get("type").toString());
                document.append("type", renameFile.get("type").toString());
                collection.insert(document);
                GridFSInputFile inputFile = file.createFile(data);
                inputFile.setId(parentPath + pathMerger + newName + renameFile.get("type").toString());
                inputFile.put("path", parentPath);
                inputFile.setFilename(newName + renameFile.get("type").toString());
                inputFile.save();
                file.remove(file.findOne(query));
                collection.remove(renameFile);
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    } finally {
        mymongo.closeConnection();
    }
}

From source file:com.fileoperations.RenameFolder.java

public Boolean forFolder() throws UnknownHostException, IOException {
    try {/*from  w  w  w  .  jav a 2 s  . c o  m*/
        String mongoFolder = parentPath + pathMerger + oldName;
        BasicDBObject query = new BasicDBObject();
        query.put("_id", mongoFolder);
        DBCursor cursor = collection.find(query);
        if (cursor.hasNext()) {
            BasicDBObject newquery = new BasicDBObject();
            newquery.put("_id", parentPath + pathMerger + newName);
            if (collection.find(newquery).hasNext()) {
                return false;
            }
            FolderDownload folder = new FolderDownload(userID, parentPath, oldName);
            folder.renameFolder(newName);
            return true;
        } else {
            return false;
        }

    } finally {
        mymongo.closeConnection();
    }
}

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

public ArrayList getGuidance(String lastid) {

    ArrayList postlist = new ArrayList();

    MongoConnection mongoconn = new MongoConnection();
    DBCollection collection = mongoconn.getDBConnection("GuidanceSelection");
    DBCursor cursor;
    if (lastid.isEmpty()) {
        cursor = collection.find().limit(50).sort(new BasicDBObject("profileid", -1));
    } else {//www  .  j a v  a2s  .c o m
        cursor = collection.find(new BasicDBObject("profileid", lastid)).limit(50)
                .sort(new BasicDBObject("profileid", -1));
    }

    while (cursor.hasNext()) {
        postlist.add(cursor.next());
    }

    return postlist;
}

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);/* w ww.j  a 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

private Guidance getGuidanceSection(String guidanceid) {
    // TODO Auto-generated method stub

    Guidance guidance = new Guidance();
    MongoConnection mongoconnew = new MongoConnection();
    DBCursor resultcursornew = mongoconnew.getDBObject("guidanceid", guidanceid, "GuidanceSelection");

    if (resultcursornew.hasNext()) {

        DBObject dbj = resultcursornew.next();

        guidance.setGuidanceduration((String) dbj.get("guidanceduration"));
        guidance.setGuidanceflag((String) dbj.get("guidanceflag"));
        guidance.setGuidancelocation((String) dbj.get("guidancelocation"));
        guidance.setGuidancereason((String) dbj.get("guidancereason"));
        guidance.setGuidanceSubject((String) dbj.get("guidanceSubject"));
        guidance.setGuidencetype((String) dbj.get("guidencetype"));

    }/*from   w w w . j a v a  2s. com*/
    return guidance;

}

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

public ArrayList getGuidanceResources(String subject, String guidancetype) {

    /*ArrayList postlist = new ArrayList();
            /* ww w  .j av  a 2 s .  com*/
    MongoConnection mongoconn = new MongoConnection();
    DBCollection collection = mongoconn.getDBConnection("GuidanceSelection");
    DBCursor cursor;
    if(lastid.isEmpty()){
       cursor = collection.find().limit(50).sort(new BasicDBObject("guidanceid",-1));
    }else{
       cursor = collection.find(new BasicDBObject("guidanceid", lastid)).limit(50).sort(new BasicDBObject("guidanceid",-1));
    }
            
    while(cursor.hasNext()){
       postlist.add(cursor.next());
    }
            
    ArrayList guidancelist =  new ArrayList();
            
    for (int i = 0; i < postlist.size(); i++) {
       System.out.println("postlist.size() ><><" + postlist.size());
       HashMap perPostSet = (HashMap) postlist.get(i);
       Set perset = perPostSet.entrySet();
       Iterator perit = perset.iterator();
       while (perit.hasNext()) {
            
    Map.Entry perme = (Map.Entry) perit.next();
            
    String keyvalue = (String) perme.getKey();
            
    System.out.println(perme.getValue());
            
    if (keyvalue.equalsIgnoreCase("guidanceSubject")) {
               
       BasicDBList basicdb = (BasicDBList)perme.getValue();
               
       for(int m = 0;m< basicdb.size(); m++){
          String guidencesub = (String)basicdb.get(m);
          if(guidencesub.equalsIgnoreCase(subject)){
             guidancelist.add(postlist.get(i));
          }
          //System.out.println(imageid);
       }
               
    }
       }
               
    }
            
            
    return guidancelist;*/

    ArrayList guidancelist = new ArrayList<Post>();

    MongoConnection mongoconn = new MongoConnection();
    DBCollection collection = mongoconn.getDBConnection("GuidanceSelection");
    DBCursor cursor;
    cursor = collection.find().limit(20).sort(new BasicDBObject("guidanceid", -1));

    while (cursor.hasNext()) {

        DBObject dbj = cursor.next();
        HashMap totalSet = new HashMap();

        if (((dbj.get("guidanceSubject").toString()).equalsIgnoreCase(subject))
                && ((dbj.get("guidencetype").toString()).equalsIgnoreCase(guidancetype))) {
            totalSet.put("guidanceid", (String) dbj.get("guidanceid"));
            totalSet.put("guidanceSubject", (String) dbj.get("guidanceSubject"));
            totalSet.put("guidanceflag", (String) dbj.get("guidanceflag"));
            totalSet.put("guidencetype", (String) dbj.get("guidencetype"));
            ProfilePreview profprev = new ProfilePreview();
            ArrayList profileinfo = profprev.getProfileInfo((String) dbj.get("userid"));
            for (int m = 0; m < profileinfo.size(); m++) {

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

                    totalSet.put("profileid", (String) dbj.get("profileid"));
                    totalSet.put("profileImage", (String) dbj.get("profileImageid"));
                    totalSet.put("profileName", (String) dbj.get("name"));

                }

            }

            totalSet.put("userid", (String) dbj.get("userid"));

        }

        guidancelist.add(totalSet);
    }

    return guidancelist;

}

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

public ArrayList getNextSetGuidanceResources(String pageno, String subject) {

    ArrayList guidancelist = new ArrayList<Post>();

    MongoConnection mongoconn = new MongoConnection();
    DBCollection collection = mongoconn.getDBConnection("GuidanceSelection");
    DBCursor cursor;
    int pagenos = Integer.parseInt(pageno);
    cursor = collection.find().skip(20 * pagenos).limit(20).sort(new BasicDBObject("guidanceid", -1));

    while (cursor.hasNext()) {

        DBObject dbj = cursor.next();//  ww  w  .j a  va 2 s  .c  o m
        HashMap totalSet = new HashMap();

        if ((dbj.get("guidanceflag").toString()).equalsIgnoreCase(subject)) {
            totalSet.put("guidanceid", dbj.get("guidanceid"));
            totalSet.put("guidanceSubject", dbj.get("guidanceSubject"));
            totalSet.put("guidanceflag", dbj.get("guidanceflag"));
            totalSet.put("guidencetype", dbj.get("guidencetype"));
        }

        guidancelist.add(totalSet);
    }

    return guidancelist;

}

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

public HashMap getDashBoardData(String guidanceid) {

    HashMap dashboarddata = new HashMap();
    HashMap assignmentdata = new HashMap();
    HashMap actualdata = new HashMap();
    HashMap truedata = new HashMap();
    HashMap assignmentperprogress = new HashMap();

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

        String dashboardid = (String) theObj.get("dashboardid");

        MongoConnection mongoconint = new MongoConnection();
        DBCursor guidcursor = mongoconint.getDBObject("guidancecontentDashid", guidanceid,
                "GuidanceContentDash");

        if (guidcursor.hasNext()) {

            DBObject theObjgrid = guidcursor.next();

            String[] dashboardids = (String[]) theObjgrid.get("guidancedashdataid");

            for (int m = 0; m < dashboardids.length; m++) {

                MongoConnection mongocondash = new MongoConnection();
                DBCursor dashcursor = mongocondash.getDBObject("dashdataid", dashboardids[m], "DashBoardData");

                if (dashcursor.hasNext()) {

                    DBObject theObjdash = dashcursor.next();
                    if (((String) theObjdash.get("dashdatatype")).equalsIgnoreCase("assignment")) {
                        assignmentdata.put((String) theObjdash.get("dashXdata"),
                                (String) theObjdash.get("dashYdata"));
                    } else if (((String) theObjdash.get("dashdatatype")).equalsIgnoreCase("truedata")) {
                        truedata.put((String) theObjdash.get("dashXdata"),
                                (String) theObjdash.get("dashYdata"));
                    } else if (((String) theObjdash.get("dashdatatype")).equalsIgnoreCase("actualdata")) {
                        actualdata.put((String) theObjdash.get("dashXdata"),
                                (String) theObjdash.get("dashYdata"));
                    }//from   www  .  j  a  v  a  2  s.c  o  m

                }

            }

        }
        if (!assignmentdata.isEmpty()) {
            dashboarddata.put("assignment", assignmentdata);
        }
        if (!truedata.isEmpty()) {
            dashboarddata.put("truedata", truedata);
        }
        if (!actualdata.isEmpty()) {
            dashboarddata.put("actualdata", actualdata);
        }
    }
    return dashboarddata;
}

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

public Timetable getTimeTableInfo(String guidanceid) {
    // TODO Auto-generated method stub
    String timelineids = "";
    Timetable timetable = new Timetable();
    MongoConnection mongocon = new MongoConnection();
    DBCursor resultcursor = mongocon.getDBObject("guidanceid", guidanceid, "GuidanceContent");
    if (resultcursor.hasNext()) {
        DBObject theObj = resultcursor.next();
        timelineids = (String) theObj.get("timetableid");

        MongoConnection mongotimecon = new MongoConnection();
        DBCursor timecursor = mongotimecon.getDBObject("timeableid", timelineids, "Timetable");
        if (timecursor.hasNext()) {
            DBObject theObjtime = timecursor.next();

            timetable.setTimeableid((String) theObjtime.get("timetableid"));
            timetable.setEventid((String[]) theObjtime.get("eventid"));

        }/* w  w w.j  av  a2 s.  co  m*/

    }
    return timetable;
}