Example usage for com.mongodb DBCursor next

List of usage examples for com.mongodb DBCursor next

Introduction

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

Prototype

@Override
public DBObject next() 

Source Link

Document

Returns the object the cursor is at and moves the cursor ahead by one.

Usage

From source file:com.fileoperations.FolderDownload.java

private void getPathOfAllChildrenFolder(String parentPath, String folderName) {
    BasicDBObject toFindAllFolderInFolder = new BasicDBObject();
    pathOfChildrenFolders.add(new BasicDBObject("path", parentPath + pathMerger + folderName));
    pathOfChildrenEmptyFolders.add(new BasicDBObject("parent", parentPath + pathMerger + folderName));
    //   pathOfChildrenEmptyFolders.add(new BasicDBObject("path",parentPath+pathMerger+folderName));
    toFindAllFolderInFolder.put("parent", parentPath + pathMerger + folderName);
    DBCursor allFolder = collection.find(toFindAllFolderInFolder);
    while (allFolder.hasNext()) {
        DBObject indivFolder = allFolder.next();
        getPathOfAllChildrenFolder(indivFolder.get("parent").toString(), indivFolder.get("name").toString());

    }// ww w . ja va2s.  co m

}

From source file:com.fileoperations.FolderDownload.java

public File makeFolder() throws IOException {
    try {//from   w w  w  .jav  a  2 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()) {

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

            for (int i = 0; i < AllFiles.size(); i++) {
                GridFSDBFile indivFile = AllFiles.get(i);
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                InputStream in = indivFile.getInputStream();
                int data = in.read();
                while (data >= 0) {
                    out.write((char) data);
                    data = in.read();
                }

                out.flush();
                String zipPath;
                zipPath = indivFile.get("path").toString() + pathMerger + indivFile.getFilename();
                zipPath = zipPath.replaceFirst(parentPath, "");
                zipPath = zipPath.replaceFirst(pathMerger, "");
                ZipEntry add = new ZipEntry(zipPath);
                folderToZip.putNextEntry(add);
                folderToZip.write(out.toByteArray(), 0, out.toByteArray().length);

            }

            BasicDBObject toFindAllEmptyFilesInFolder = new BasicDBObject();
            toFindAllEmptyFilesInFolder.put("$or", pathOfChildrenEmptyFolders);
            DBCursor emptyFolder = collection.find(toFindAllEmptyFilesInFolder);
            List<String> emptyFolderPathToAdd = new ArrayList<String>();
            while (emptyFolder.hasNext()) {
                DBObject temp = emptyFolder.next();
                BasicDBObject isEmpty = new BasicDBObject();
                isEmpty.put("parent", temp.get("_id").toString());

                if (!collection.find(isEmpty).hasNext()) {
                    if (!temp.get("_id").toString().contains(".")) {
                        emptyFolderPathToAdd.add(temp.get("_id").toString());
                    }
                }

            }
            for (int i = 0; i < emptyFolderPathToAdd.size(); i++) {
                String temp = emptyFolderPathToAdd.get(i).replaceFirst(parentPath, "");
                temp = temp.replaceFirst(pathMerger, "");
                ZipEntry add = new ZipEntry(temp + pathMerger);
                folderToZip.putNextEntry(add);

            }

            folderToZip.closeEntry();
            folderToZip.close();
            return zip;
        } else {
            return null;
        }

    } finally {
        mymongo.closeConnection();
    }

}

From source file:com.fileoperations.FolderDownload.java

public Boolean copyFolder(String newPath) throws IOException {
    try {/*from  w  w w  .  jav a  2s.  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", newPath + pathMerger + folderName);
            if (collection.find(newquery).hasNext()) {
                return false;
            }

            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, newPath);
                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().replaceFirst(parentPath, newPath);
                    BasicDBObject document = new BasicDBObject();
                    document.put("_id", tempPath + pathMerger + temp.get("name"));
                    document.put("folder", "1");
                    document.put("name", temp.get("name"));
                    document.put("parent", tempPath);
                    document.put("type", "1");
                    collection.insert(document);

                }
            }

            return true;
        } else {
            return false;
        }

    } finally {
        mymongo.closeConnection();
    }
}

From source file:com.fileoperations.FolderDownload.java

public Boolean renameFolder(String newName) throws IOException {
    try {/*from  w ww  .  ja  va2  s. c  om*/
        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 RenameFolder(String userID, String parentPath, String oldName, String newName)
        throws UnknownHostException {
    this.userID = userID;
    this.parentPath = parentPath;
    this.oldName = oldName;
    this.newName = newName;
    mymongo = new Connection();
    DBCollection usercol = mymongo.getMembersCol();
    BasicDBObject query = new BasicDBObject();
    query.put("_id", userID);
    DBCursor cursor = usercol.find(query);
    DBObject col = cursor.next();
    userCollectionName = col.get("collection").toString();
    collection = mymongo.getCollection(userCollectionName);
}

From source file:com.fileoperations.RenameFolder.java

public Boolean forSingleFile() {
    try {//  www  .j  a  v  a  2s . 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.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 {//from  w ww .  j a  va2  s .  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);//from w  w w. ja  va 2 s  .  c om
           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"));

    }/* ww  w .ja  va 2 s .c om*/
    return guidance;

}

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

public ArrayList getGuidanceResources(String subject, String guidancetype) {

    /*ArrayList postlist = new ArrayList();
            // w w w .  j  a va  2  s.  c o m
    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;

}