Example usage for com.mongodb DBObject get

List of usage examples for com.mongodb DBObject get

Introduction

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

Prototype

Object get(String key);

Source Link

Document

Gets a field from this object by a given name.

Usage

From source file:MashUp.java

public ArrayList<String> getApibasedonTags(String tags) {
    DBCursor cursor = table1.find();//w  w  w  .j  av a 2 s . c  om

    ArrayList<String> api = new ArrayList<String>();
    while (cursor.hasNext()) {
        DBObject temp = cursor.next();
        String tags_1[] = tags.split(" ");

        for (int i = 0; i < tags_1.length; i++) {
            if (temp.get("Tags").toString().contains(tags_1[i])) {

                api.add(temp.get("id").toString());
            }
        }
    }
    return api;
}

From source file:MashUp.java

public HashMap<String, String> getApibasedonRating(float rating) {
    HashMap<String, String> api = new HashMap<String, String>();
    DBCursor cursor = table1.find();/*from   w w w .  j av a2  s .c  o  m*/

    while (cursor.hasNext()) {
        DBObject temp = cursor.next();
        //System.out.println(temp.get("id").toString()+ " "+temp.get("rating").toString());
        if (temp.get("rating").toString() == "") {
            temp.put("rating", "0.0");
        }
        if (Float.parseFloat(temp.get("rating").toString()) > rating) {
            if (api.get("Higher") == null) {

                api.put("Higher", temp.get("id").toString());

            } else {
                if (!api.get("Higher").contains(temp.get("id").toString())) {
                    String temp1 = api.get("Higher") + " " + temp.get("id").toString();
                    api.put("Higher", temp1);
                }
            }
        } else if (Float.parseFloat(temp.get("rating").toString()) < rating) {
            if (api.get("Lower") == null) {
                api.put("Lower", temp.get("id").toString());
            } else {
                if (!api.get("Lower").contains(temp.get("id").toString())) {
                    String temp1 = api.get("Lower") + " " + temp.get("id").toString();
                    api.put("Lower", temp1);
                }
            }
        } else {
            if (api.get("Equals") == null) {
                api.put("Equals", temp.get("id").toString());
            } else {
                if (!api.get("Equals").contains(temp.get("id").toString())) {
                    String temp1 = api.get("Equals") + " " + temp.get("id").toString();
                    api.put("Equals", temp1);
                }
            }
        }
    }
    return api;

}

From source file:MashUp.java

public ArrayList<String> getapibyYear(String year) {
    DBCursor cursor = table1.find();//ww w  .j  a v  a2 s.  c  om

    ArrayList<String> api = new ArrayList<String>();
    while (cursor.hasNext()) {
        DBObject temp = cursor.next();

        if (temp.get("updated").toString().contains(year)) {

            api.add(temp.get("id").toString());
        }
    }
    return api;
}

From source file:MashUp.java

public HashMap<String, String> getInformation(String keywords) {
    DBCursor cursor = table1.find();//from w  w  w  .j  a v  a2s .  c  om

    HashMap<String, String> api = new HashMap<String, String>();
    while (cursor.hasNext()) {
        DBObject temp = cursor.next();
        String keywords_list[] = keywords.split(" ");
        for (int i = 0; i < keywords_list.length; i++) {
            if (temp.get("title").toString().contains(keywords_list[i])) {
                if (api.get("title") == null) {

                    api.put("title", "APINAME" + temp.get("id") + "$$" + temp.get("title").toString());
                } else {
                    if (!api.get("title")
                            .contains("APINAME" + temp.get("id") + "$$" + temp.get("title").toString())) {
                        api.put("title", api.get("title") + " " + "APINAME" + temp.get("id") + "$$"
                                + temp.get("title").toString());
                    }
                }

            }
            if (temp.get("summary").toString().contains(keywords_list[i])) {
                if (api.get("summary") == null) {
                    System.out.println("Entering");
                    api.put("summary", "APINAME" + temp.get("id") + "$$" + temp.get("summary").toString());
                } else {
                    if (!api.get("summary")
                            .contains("APINAME" + temp.get("id") + "$$" + temp.get("summary").toString())) {
                        api.put("summary", api.get("summary") + " " + "APINAME" + temp.get("id") + "$$"
                                + temp.get("summary").toString());
                    }
                }

            }
            if (temp.get("description").toString().contains(keywords_list[i])) {
                if (api.get("description") == null) {
                    System.out.println("Entering");
                    api.put("description",
                            "APINAME" + temp.get("id") + "$$" + temp.get("description").toString());
                } else {
                    if (!api.get("description")
                            .contains("APINAME" + temp.get("id") + "$$" + temp.get("description").toString())) {
                        api.put("description", api.get("description") + " " + "APINAME" + temp.get("id") + "$$"
                                + temp.get("description").toString());
                    }
                }

            }
        }
    }
    return api;
}

From source file:MashUp.java

public ArrayList<String> getMashUpbyYear(String year) {
    DBCursor cursor = table2.find();/*from w ww .jav  a  2  s .co m*/

    ArrayList<String> api = new ArrayList<String>();
    while (cursor.hasNext()) {
        DBObject temp = cursor.next();

        if (temp.get("updated").toString().contains(year)) {

            api.add(temp.get("id").toString());
        }
    }
    return api;
}

From source file:MashUp.java

public ArrayList<String> getMashUpbyUsedApis(String Api) {
    DBCursor cursor = table2.find();//  w w  w  . j  av  a 2  s  .c o  m

    ArrayList<String> api = new ArrayList<String>();
    while (cursor.hasNext()) {
        DBObject temp = cursor.next();

        if (temp.get("APIs").toString().contains(Api)) {

            api.add(temp.get("APIs").toString());
        }
    }
    return api;
}

From source file:MashUp.java

public ArrayList<String> getMashUpbasedonTags(String tags) {
    DBCursor cursor = table2.find();//from   w  ww .java 2 s  . c  o  m

    ArrayList<String> api = new ArrayList<String>();
    while (cursor.hasNext()) {
        DBObject temp = cursor.next();
        String tags_1[] = tags.split(" ");

        for (int i = 0; i < tags_1.length; i++) {
            if (temp.get("Tags").toString().contains(tags_1[i])) {

                api.add(temp.get("id").toString());
            }
        }
    }
    return api;
}

From source file:MashUp.java

public ArrayList<String> getMashUpVisual() {
    DBCursor cursor = table1.find();//from w  ww  . ja v  a2s.  c  o m

    ArrayList<String> api = new ArrayList<String>();
    while (cursor.hasNext()) {
        DBObject temp = cursor.next();

        if (temp.get("updated").toString().contains("2013")) {

            api.add(temp.get("name").toString());
        }

    }
    return api;
}

From source file:MashUp.java

public HashMap<String, String> getMashUpInformation(String keywords) {
    DBCursor cursor = table2.find();//from  www. java  2  s. c om

    HashMap<String, String> api = new HashMap<String, String>();
    while (cursor.hasNext()) {
        DBObject temp = cursor.next();
        String keywords_list[] = keywords.split(" ");
        for (int i = 0; i < keywords_list.length; i++) {
            if (temp.get("title").toString().contains(keywords_list[i])) {
                if (api.get("title") == null) {

                    api.put("title", "APINAME" + temp.get("id") + "$$" + temp.get("title").toString());
                } else {
                    if (!api.get("title")
                            .contains("APINAME" + temp.get("id") + "$$" + temp.get("title").toString())) {
                        api.put("title", api.get("title") + " " + "APINAME" + temp.get("id") + "$$"
                                + temp.get("title").toString());
                    }
                }

            }
            if (temp.get("summary").toString().contains(keywords_list[i])) {
                if (api.get("summary") == null) {
                    System.out.println("Entering");
                    api.put("summary", "APINAME" + temp.get("id") + "$$" + temp.get("summary").toString());
                } else {
                    if (!api.get("summary")
                            .contains("APINAME" + temp.get("id") + "$$" + temp.get("summary").toString())) {
                        api.put("summary", api.get("summary") + " " + "APINAME" + temp.get("id") + "$$"
                                + temp.get("summary").toString());
                    }
                }

            }
            if (temp.get("description").toString().contains(keywords_list[i])) {
                if (api.get("description") == null) {
                    System.out.println("Entering");
                    api.put("description",
                            "APINAME" + temp.get("id") + "$$" + temp.get("description").toString());
                } else {
                    if (!api.get("description")
                            .contains("APINAME" + temp.get("id") + "$$" + temp.get("description").toString())) {
                        api.put("description", api.get("description") + " " + "APINAME" + temp.get("id") + "$$"
                                + temp.get("description").toString());
                    }
                }

            }
        }
    }
    return api;
}

From source file:MashUp.java

public String queryDatabaseApi(String Year, String Protocol, String Category, String Tags, String Keywords,
        Double Rating) {/*from w  ww .j  a v  a  2  s  . com*/

    String temp = "";
    BasicDBObject gtQuery = new BasicDBObject();
    BasicDBObject ltQuery = new BasicDBObject();
    BasicDBObject eqQuery = new BasicDBObject();

    if (!Rating.equals(0.0)) {

        /*
        greater than
        */

        temp = temp + "\n";
        temp = temp + "Greater than " + Rating + "\n" + "\n";
        temp = temp + "\n";

        if (!Year.equals("")) {
            gtQuery.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
        }
        if (!Protocol.equals("")) {
            gtQuery.put("protocols", Protocol);
        }

        if (!Category.equals("")) {
            gtQuery.put("category", Category);
        }
        if (!Tags.equals("")) {
            gtQuery.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
        }
        if (!Keywords.equals("")) {
            DBObject clause1 = new BasicDBObject("summary",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause2 = new BasicDBObject("description",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            BasicDBList or = new BasicDBList();
            or.add(clause1);
            or.add(clause3);
            or.add(clause2);
            gtQuery.put("$or", or);
            //DBObject query = new BasicDBObject("$or", or);
            //System.out.println(query);

        }

        gtQuery.put("rating", new BasicDBObject("$gt", Rating));
        DBCursor cursor = table1.find(gtQuery);
        while (cursor.hasNext()) {
            DBObject temp1 = cursor.next();
            if (!temp.contains(temp1.get("name").toString()))
                temp = temp + " " + temp1.get("name") + "\n";
        }

        /*
        lower than
        */

        temp = temp + "\n";
        temp = temp + "Lower than " + Rating + "\n" + "\n";
        temp = temp + "\n";

        if (!Year.equals("")) {
            ltQuery.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
        }
        if (!Protocol.equals("")) {
            ltQuery.put("protocols", Protocol);
        }

        if (!Category.equals("")) {
            ltQuery.put("category", Category);
        }
        if (!Tags.equals("")) {
            ltQuery.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
        }
        if (!Keywords.equals("")) {
            DBObject clause1 = new BasicDBObject("summary",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause2 = new BasicDBObject("description",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            BasicDBList or = new BasicDBList();
            or.add(clause1);
            or.add(clause3);
            or.add(clause2);
            ltQuery.put("$or", or);
            //DBObject query = new BasicDBObject("$or", or);
            //System.out.println(query);

        }

        ltQuery.put("rating", new BasicDBObject("$lt", Rating));
        DBCursor cursor2 = table1.find(ltQuery);
        while (cursor2.hasNext()) {
            DBObject temp1 = cursor2.next();
            if (!temp.contains(temp1.get("name").toString()))
                temp = temp + " " + temp1.get("name") + "\n";
        }

        /*
                
        equal to 
        */

        temp = temp + "\n";
        temp = temp + "Equal to " + Rating + "\n" + "\n";
        temp = temp + "\n";

        if (!Year.equals("")) {
            eqQuery.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
        }
        if (!Protocol.equals("")) {
            eqQuery.put("protocols", Protocol);
        }

        if (!Category.equals("")) {
            eqQuery.put("category", Category);
        }
        if (!Tags.equals("")) {
            eqQuery.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
        }
        if (!Keywords.equals("")) {
            DBObject clause1 = new BasicDBObject("summary",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause2 = new BasicDBObject("description",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            BasicDBList or = new BasicDBList();
            or.add(clause1);
            or.add(clause3);
            or.add(clause2);
            eqQuery.put("$or", or);
            //DBObject query = new BasicDBObject("$or", or);
            //System.out.println(query);

        }

        eqQuery.put("rating", new BasicDBObject("$eq", Rating));
        DBCursor cursor3 = table1.find(eqQuery);
        while (cursor3.hasNext()) {
            DBObject temp1 = cursor3.next();
            if (!temp.contains(temp1.get("name").toString()))
                temp = temp + " " + temp1.get("name") + "\n";
        }

    } else {

        BasicDBObject test = new BasicDBObject();
        if (!Year.equals("")) {
            test.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
        }
        if (!Protocol.equals("")) {
            test.put("protocols", Protocol);
        }

        if (!Category.equals("")) {
            test.put("category", Category);
        }
        if (!Tags.equals("")) {
            test.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
        }
        if (!Keywords.equals("")) {
            DBObject clause1 = new BasicDBObject("summary",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause2 = new BasicDBObject("description",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            BasicDBList or = new BasicDBList();
            or.add(clause1);
            or.add(clause3);
            or.add(clause2);
            test.put("$or", or);
            //DBObject query = new BasicDBObject("$or", or);
            //System.out.println(query);

        }

        DBCursor cursor = table1.find(test);
        while (cursor.hasNext()) {
            DBObject temp1 = cursor.next();
            if (!temp.contains(temp1.get("name").toString()))
                temp = temp + " " + temp1.get("name") + "\n";
        }
    }

    /*
    if(!Year.equals("")){
    //gtQuery.put("rating", new BasicDBObject("$gt", "4"));
    gtQuery.put("updated",new BasicDBObject("$regex",".*"+Year+".*"));
    }
    if(!Protocol.equals("")){
    gtQuery.put("protocols",Protocol);
    }
            
    if(!Category.equals("")){
    gtQuery.put("category",Category);
    }
    if(!Tags.equals("")){
    gtQuery.put("Tags",new BasicDBObject("$regex",".*"+Tags+".*") );
    }
     if(!Keywords.equals("")){
    DBObject clause1 = new BasicDBObject("summary", new BasicDBObject("$regex",".*"+Keywords+".*"));  
    DBObject clause2 = new BasicDBObject("description", new BasicDBObject("$regex",".*"+Keywords+".*"));
    DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex",".*"+Keywords+".*")); 
    BasicDBList or = new BasicDBList();
    or.add(clause1);or.add(clause3);
    or.add(clause2);
    gtQuery.put("$or", or);
    //DBObject query = new BasicDBObject("$or", or);
    //System.out.println(query);
            
    }
             
            
            
    //gtQuery.put("rating", new BasicDBObject("$gt", "4").append("$lt", "5"));
    //  gtQuery.put("updated", "2012-12-17T09:51:40Z");
    DBCursor cursor = table1.find(gtQuery);
    String temp="";
            
    if(!Rating.equals(0.0)){
     gtQuery.put("rating",new BasicDBObject("$gt",Rating));
     temp="Greater than "+Rating+"\n"+"\n";
      while(cursor.hasNext()) {
    DBObject temp1 = cursor.next();
         temp=temp+" "+temp1.get("name")+"\n";
      }
              
      gtQuery.remove("rating");
      temp=temp+"\n";
    gtQuery.put("rating",new BasicDBObject("$lt",Rating));
     temp= temp+"Lesser than "+Rating+"\n"+"\n";
      while(cursor.hasNext()) {
    DBObject temp1 = cursor.next();
         temp=temp+" "+temp1.get("name")+"\n";
    }
            
    gtQuery.remove("rating");
    temp=temp+"\n";
    gtQuery.put("rating",new BasicDBObject("$eq",Rating));
     temp=temp+"Equal to "+Rating+"\n"+"\n";
      while(cursor.hasNext()) {
    DBObject temp1 = cursor.next();
         temp=temp+" "+temp1.get("name")+"\n";
    }
            
    }else{
    while(cursor.hasNext()) {
    DBObject temp1 = cursor.next();
         temp=temp+" "+temp1.get("name")+"\n";
    }
    }
            
    */

    return temp;
}