Example usage for com.mongodb DBObject put

List of usage examples for com.mongodb DBObject put

Introduction

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

Prototype

Object put(String key, Object v);

Source Link

Document

Sets a name/value pair in this object.

Usage

From source file:LoginUI.java

private HashMap<String, String> getUserInfo() throws ParseException {
    DBCollection collection = db.getCollection("Users");

    DBObject allquery = new BasicDBObject();
    DBObject fields = new BasicDBObject();
    fields.put("Info", 1);

    DBCursor infocursor = collection.find(allquery, fields);
    HashMap<String, String> userpw = new HashMap<String, String>();

    while (infocursor.hasNext()) {
        String json = infocursor.next().toString();
        JSONParser parser = new JSONParser();
        JSONObject jsonFile = (JSONObject) parser.parse(json);
        JSONObject structure = (JSONObject) jsonFile.get("Info");
        String user = structure.get("Username").toString();
        String pw = structure.get("Password").toString();
        JSONObject idStruct = (JSONObject) jsonFile.get("_id");
        String id = idStruct.get("$oid").toString();

        userpw.put(user, pw);//from   www  .  j ava  2s . c  o  m
    }
    return userpw;
}

From source file:gMIRC_handler.java

private int UpdateLastActive(String username) {
    int ret = 0;/*from  w w w  . j a  va  2 s .c om*/
    try {

        MongoClient mongoClient = new MongoClient();
        DB db = mongoClient.getDB("mirc");
        DBCollection coll = db.getCollection("activeUser");
        BasicDBObject query = new BasicDBObject("username", username);

        DBCursor cursor = coll.find(query);

        try {
            if (cursor.hasNext()) {
                DBObject temp = cursor.next();
                java.util.Date date = new java.util.Date();
                temp.put("timestamp", date);
                coll.save(temp);
            } else {
                java.util.Date date = new java.util.Date();
                BasicDBObject doc = new BasicDBObject("username", username).append("timestamp", date);
                coll.insert(doc);
                System.out.println(username + " online !");
            }
        } finally {
            cursor.close();
        }

    } catch (UnknownHostException ex) {
        Logger.getLogger(gMIRC_handler.class.getName()).log(Level.SEVERE, null, ex);
    }
    return 0;
}

From source file:MashUp.java

public HashMap<String, String> getApibasedonRating(float rating) {
    HashMap<String, String> api = new HashMap<String, String>();
    DBCursor cursor = table1.find();//w ww .  j ava  2 s  .c om

    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:UserHistoryGUI.java

/**
 * @param args the command line arguments
 * @throws ParseException //  w  w  w. j  ava  2  s. co  m
 */

private void initScores() throws ParseException {
    DBCollection collection = db.getCollection("Users");

    DBObject query = new BasicDBObject();
    query.put("Info.Username", username);
    DBObject fields = new BasicDBObject();
    fields.put("Beginner", 1);
    fields.put("Easy", 1);
    fields.put("Medium", 1);
    fields.put("Hard", 1);
    fields.put("Last", 1);

    DBCursor scoreCursor = collection.find(query, fields);
    JSONParser parser = new JSONParser();
    int totalScore = 0;
    int totalAnswered = 0;
    int totalCorrect = 0;

    while (scoreCursor.hasNext()) {
        String json = scoreCursor.next().toString();
        JSONObject jsonFile = (JSONObject) parser.parse(json);

        //beginner scores
        JSONObject beginner = (JSONObject) jsonFile.get("Beginner");
        int beginnerTotal = Integer.parseInt(beginner.get("Total").toString());
        totalAnswered += beginnerTotal;
        int beginnerCorrect = Integer.parseInt(beginner.get("Correct").toString());
        totalCorrect += beginnerCorrect;
        totalScore += beginnerCorrect * 10;
        float beginnerRate = 0.0f;
        if (beginnerTotal != 0) {
            beginnerRate = (float) beginnerCorrect / beginnerTotal;
        }

        //easy scores
        JSONObject easy = (JSONObject) jsonFile.get("Easy");
        int easyTotal = Integer.parseInt(easy.get("Total").toString());
        int easyCorrect = Integer.parseInt(easy.get("Correct").toString());
        totalAnswered += easyTotal;
        totalCorrect += easyCorrect;
        totalScore += easyCorrect * 20;

        float easyRate = 0.0f;
        if (easyTotal != 0) {
            easyRate = (float) easyCorrect / easyTotal;
        }

        //med scores
        JSONObject med = (JSONObject) jsonFile.get("Medium");
        int medTotal = Integer.parseInt(med.get("Total").toString());
        int medCorrect = Integer.parseInt(med.get("Correct").toString());

        totalAnswered += medTotal;
        totalCorrect += medCorrect;
        totalScore += medCorrect * 30;

        float medRate = 0.0f;
        if (medTotal != 0) {
            medRate = (float) medCorrect / medTotal;
        }

        // hard scores
        JSONObject hard = (JSONObject) jsonFile.get("Hard");
        int hardTotal = Integer.parseInt(hard.get("Total").toString());
        int hardCorrect = Integer.parseInt(hard.get("Correct").toString());

        totalAnswered += hardTotal;
        totalCorrect += hardCorrect;
        totalScore += hardCorrect * 50;

        float hardRate = 0.0f;
        if (hardTotal != 0) {
            hardRate = (float) hardCorrect / hardTotal;
        }

        // Question
        JSONObject q = (JSONObject) jsonFile.get("Last");
        String question = q.get("Question").toString();
        String answer = q.get("Answer").toString();
        String correct = q.get("Correct").toString();

        BeginnerTotal.setText("" + beginnerTotal);
        BeginnerCorrect.setText("" + beginnerCorrect);
        BeginnerRate.setText("" + beginnerRate);

        EasyTotal.setText("" + easyTotal);
        EasyCorrect.setText("" + easyCorrect);
        EasyRate.setText("" + easyRate);

        MedTotal.setText("" + medTotal);
        MedCorrect.setText("" + medCorrect);
        MedRate.setText("" + medRate);

        HardTotal.setText("" + hardTotal);
        HardCorrect.setText("" + hardCorrect);
        HardRate.setText("" + hardRate);

        TotalScore.setText("" + totalScore);
        jTextArea2.setText(question);
        Answer.setText(answer);
        CorrectorNo.setText(correct);
    }

}

From source file:HW4.java

@SuppressWarnings("empty-statement")
private void executeQueryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_executeQueryButtonActionPerformed

    DefaultTableModel dtm = new DefaultTableModel(0, 0);

    //nothing is selected
    if (finalCat.isEmpty()) {
        if (!Address.isEmpty() && !proximity.isEmpty()) {

            if (Address.contains("3799 S Las Vegas Blvd Eastside Las Vegas, NV 89119")) {
                longitude = -115.16768879999999;
                latitude = 36.103017899999998;
            }/*from w w w  . j  a v a  2s  . co m*/

            if (Address.equalsIgnoreCase("6002 S Durango Dr Ste 100 Spring Valley Las Vegas, NV 89113")) {
                longitude = -115.27906539999999;
                latitude = 36.079256100000002;
            }

            if (Address.equalsIgnoreCase("1801 E Baseline Rd, #101 Ste 101 Tempe, AZ 85283")) {
                longitude = -111.90860979259;
                latitude = 33.377052104372098;
            }

            if (Address.equalsIgnoreCase("1033 S Park St Bay Creek Madison, WI 53715")) {
                longitude = -89.397478300000003;
                latitude = 43.055539400000001;
            }

            if (Address.equalsIgnoreCase("University Center II Lot Phoenix, AZ 85008")) {
                longitude = -112.02540759999999;
                latitude = 33.451857400000002;
            }
            DB dbBusiness = mongoClient.getDB("business");
            DBCollection collBusiness = dbBusiness.getCollection("business");

            BasicDBList geoCoord = new BasicDBList();

            geoCoord.add(longitude);
            geoCoord.add(latitude);

            BasicDBList geoParams = new BasicDBList();
            geoParams.add(geoCoord);
            geoParams.add(Integer.parseInt(proximity) / 1018.59);

            BasicDBObject query = new BasicDBObject("loc",
                    new BasicDBObject("$geoWithin", new BasicDBObject("$center", geoParams)));

            resultTable.setModel(dtm);
            String header[] = new String[] { "B_ID", "Business", "City", "State", "Stars" };
            dtm.setColumnIdentifiers(header);
            DBCursor cursorForBusiness = collBusiness.find(query);
            while (cursorForBusiness.hasNext()) {
                //pointInterest.add(cursorForBusiness.next());
                Object[] row = new Object[5];
                row[0] = cursorForBusiness.next().get("business_id");
                row[1] = cursorForBusiness.next().get("name");
                row[2] = cursorForBusiness.next().get("city");
                row[3] = cursorForBusiness.next().get("state");
                row[4] = cursorForBusiness.next().get("stars");

                dtm.addRow(row);
            }

        }

        if (!memberSince.isEmpty() || !operReviewCount.isEmpty() || !operNoOfFriends.isEmpty()
                || !operAvgStar.isEmpty() || !valueReviewCount.isEmpty() || !valueNoOfFriends.isEmpty()
                || !valueAvgStar.isEmpty() || !andOrAttribute.isEmpty() || !operNoOfVotes.isEmpty()
                || !valueNoOfVotes.isEmpty()) {

            DB dbUser = mongoClient.getDB("user");
            DBCollection collUser = dbUser.getCollection("user");
            BasicDBObject andQuery = new BasicDBObject();
            List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
            try {
                if (!memberSince.isEmpty()) {
                    obj.add(new BasicDBObject("yelping_since", memberSince));
                }
                if (!valueReviewCount.isEmpty()) {
                    int vrc = Integer.parseInt(valueReviewCount);
                    BasicDBObject rCount = null;
                    if (operReviewCount.equals(">")) {
                        rCount = new BasicDBObject("review_count", new BasicDBObject("$gt", vrc));
                        //rCount = new BasicDBObject("$where", "review_count >" + vrc);
                    }
                    if (operReviewCount.equals("<")) {
                        rCount = new BasicDBObject("review_count", new BasicDBObject("$lt", vrc));
                        //rCount = new BasicDBObject("$where", "review_count <" + vrc);
                    }
                    if (operReviewCount.equals("=")) {
                        rCount = new BasicDBObject("review_count", vrc);
                        // rCount = new BasicDBObject("$where", "review_count =" + vrc);
                    }

                    obj.add(new BasicDBObject(rCount));
                }
                if (!valueNoOfFriends.isEmpty()) {
                    int vnf = Integer.parseInt(valueNoOfFriends);
                    BasicDBObject vFriends = null;
                    if (operNoOfFriends.equals(">")) {
                        vFriends = new BasicDBObject("$where", "this.friends.length >" + vnf);
                    }
                    if (operNoOfFriends.equals("<")) {
                        vFriends = new BasicDBObject("$where", "this.friends.length <" + vnf);
                    }
                    if (operNoOfFriends.equals("=")) {
                        vFriends = new BasicDBObject("$where", "this.friends.length =" + vnf);
                    }

                    obj.add(new BasicDBObject(vFriends));
                }
                if (!valueAvgStar.isEmpty()) {
                    Double doubleValueAvgStar = Double.parseDouble(valueAvgStar);
                    BasicDBObject avgStarValue = null;
                    if (operAvgStar.equals(">")) {
                        avgStarValue = new BasicDBObject("average_stars",
                                new BasicDBObject("$gt", doubleValueAvgStar));
                        // avgStarValue = new BasicDBObject("$where", "average_stars >" + doubleValueAvgStar);
                    }
                    if (operAvgStar.equals("<")) {
                        avgStarValue = new BasicDBObject("average_stars",
                                new BasicDBObject("$lt", doubleValueAvgStar));
                        // avgStarValue = new BasicDBObject("$where", "average_stars <" + doubleValueAvgStar);
                    }
                    if (operAvgStar.equals("=")) {
                        avgStarValue = new BasicDBObject("average_stars", doubleValueAvgStar);
                        // avgStarValue = new BasicDBObject("$where", "average_stars =" + doubleValueAvgStar);
                    }

                    obj.add(new BasicDBObject(avgStarValue));

                }
                if (!valueNoOfVotes.isEmpty()) {
                    //                                BasicDBObject noOfVotesValue = null;
                    //                                 if (operNoOfVotes.equals(">")) {
                    //                            noOfVotesValue = new BasicDBObject("average_stars", new BasicDBObject("$gt", valueNoOfVotes));
                    //                        }
                    //                        if (operNoOfVotes.equals("<")) {
                    //                            noOfVotesValue = new BasicDBObject("average_stars", new BasicDBObject("$lt", valueNoOfVotes));
                    //                        }
                    //                        if (operNoOfVotes.equals("=")) {
                    //                            noOfVotesValue = new BasicDBObject("average_stars", new BasicDBObject("$eq", valueNoOfVotes));
                    //                        }   
                    //                        
                    //                        obj.add(new BasicDBObject(noOfVotesValue));

                }
                System.out.println(andOrAttribute);
                if (andOrAttribute.equalsIgnoreCase("AND")) {
                    System.out.println("Here");
                    andQuery.put("$and", obj);
                } else {
                    andQuery.put("$or", obj);
                }
                queryLabel.setText("<html><p>" + andQuery.toString() + "</p></html>");
                List<DBObject> outputMyList = new ArrayList<DBObject>();
                DBCursor cursor = collUser.find(andQuery);
                while (cursor.hasNext()) {
                    //System.out.println(cursor.next());
                    outputMyList.add(cursor.next());
                }

                resultTable.setModel(dtm);
                String header[] = new String[] { "U_ID", "User Name", "Yelping Since", "Avg Stars",
                        "Review Count" };
                // add header in table model     
                dtm.setColumnIdentifiers(header);
                for (DBObject temp : outputMyList) {
                    //System.out.println("Business Name : " + temp.get("name") + " Category :  " + temp.get("categories"));
                    Object[] row = new Object[5];
                    row[0] = temp.get("user_id");
                    row[1] = temp.get("name");
                    row[2] = temp.get("yelping_since");
                    row[3] = temp.get("average_stars");
                    row[4] = temp.get("review_count");

                    dtm.addRow(row);
                }

            } catch (Exception e) {

            }

        } else {
            queryLabel.setText("Please select atleast one category from business");
        }
    } //only cat selected
      //////////////////////////Business//////////////////////////////////////////////////////////
    if (finalCat.size() > 0) {
        DB dbBusiness = mongoClient.getDB("business");
        DBCollection collBusiness = dbBusiness.getCollection("business");
        if (!fromCheckin.isEmpty() && !fromCheckinHour.isEmpty() && !toCheckin.isEmpty()
                && !toCheckinHour.isEmpty() && !operationCheckin.isEmpty() && !valueCheckin.isEmpty()) {
            DB dbCheckin = mongoClient.getDB("checkin");
            DBCollection collCheckin = dbCheckin.getCollection("checkin");

            if (!fromReview.isEmpty() && !toReview.isEmpty() && !operationStar.isEmpty() && !valueStar.isEmpty()
                    && !operationVote.isEmpty() && !valueVote.isEmpty()) {
                //////////////////////Category, Checkin and Review///////////////////////////////////////////////////
                DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
                String fromDate1 = fromReview;
                String fromdate = fromDate1 + "T00:00:00Z";
                String toDate1 = toReview;
                String todate = toDate1 + "T00:00:00Z";
                int starValue = Integer.parseInt(valueStar);
                int voteValue = Integer.parseInt(valueVote);
                StringBuffer finalQuery = new StringBuffer();
                DB dbReview = mongoClient.getDB("review");
                DBCollection collReview = dbReview.getCollection("review");
                int j = 0;
                int l = 0;

                HashMap<String, Integer> tempCheckin = new HashMap<String, Integer>();
                ArrayList<String> finalCheckinBid = new ArrayList<String>();

                ArrayList<CheckinDetail> checkinList = new ArrayList<CheckinDetail>();
                //System.out.println("I am in checkin box");
                String[] arrayDays = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
                        "Saturday" };
                for (int i = 0; i < arrayDays.length; i++) {
                    if (fromCheckin == arrayDays[i]) {
                        j = i;
                    } else if (toCheckin == arrayDays[i]) {
                        l = i;
                    }
                }
                ArrayList<Integer> days = new ArrayList<Integer>();
                days.add(j);
                int temfromday = j;
                days.add(l);

                int difference = CheckForDay(fromCheckin, toCheckin);
                if (difference > 0) {
                    for (int k = 0; k < difference; k++) {
                        j = j + 1;
                        if (j == 7) {
                            j = 0;
                        }
                        days.add(j);

                    }
                }
                List<DBObject> categoryIdList = new ArrayList<DBObject>();
                for (String t : finalCat) {
                    BasicDBObject whereQueryBusiness = new BasicDBObject();
                    BasicDBObject fieldsBusiness = new BasicDBObject();
                    fieldsBusiness.put("business_id", 1);
                    whereQueryBusiness.put("categories", t);
                    DBCursor cursorForBusiness = collBusiness.find(whereQueryBusiness, fieldsBusiness);
                    finalQuery.append(whereQueryBusiness);
                    while (cursorForBusiness.hasNext()) {
                        int i = 1;
                        categoryIdList.add(cursorForBusiness.next());
                        i++;
                    }
                } //for FINALCAT
                List<DBObject> checkinCategoryIdList = new ArrayList<DBObject>();
                for (DBObject s : categoryIdList) {
                    //System.out.println(s.get("business_id"));
                    BasicDBObject whereQueryCheckin = new BasicDBObject();
                    whereQueryCheckin.put("business_id", s.get("business_id"));
                    DBCursor cursorForCheckin = collCheckin.find(whereQueryCheckin);
                    while (cursorForCheckin.hasNext()) {
                        int i = 1;
                        checkinCategoryIdList.add(cursorForCheckin.next());
                        i++;
                    }
                } //for DBObject s:categoryIdList
                for (DBObject u : checkinCategoryIdList) {
                    String full = u.get("checkin_info").toString();
                    String a = full.replaceAll("[{}]", "");
                    String[] b = a.split(",");
                    for (int x = 0; x < b.length; x++) {
                        CheckinDetail objCheckin = new CheckinDetail();
                        String[] c = b[x].split(":");

                        String d = c[0].replaceAll("[\"]", "");
                        String[] e = d.split("-");
                        objCheckin.b_Id = u.get("business_id").toString();
                        objCheckin.fromTime = Integer.parseInt(e[0].replaceAll("\\s+", ""));
                        objCheckin.checkinDay = Integer.parseInt(e[1].replaceAll("\\s+", ""));
                        objCheckin.CountValue = Integer.parseInt(c[1].replaceAll("\\s+", ""));
                        ;
                        checkinList.add(objCheckin);
                    }
                }

                for (CheckinDetail e : checkinList) {
                    for (int f : days) {
                        if ((f == temfromday && temfromday == e.checkinDay
                                && Integer.parseInt(fromCheckinHour) <= e.fromTime)
                                || (f == l && l == e.checkinDay
                                        && Integer.parseInt(toCheckinHour) >= e.fromTime)
                                || (f == e.checkinDay && f != temfromday && f != l)) {
                            //                                    System.out.println(e.b_Id);
                            //                                    System.out.println(e.CountValue);
                            if (tempCheckin.containsKey(e.b_Id)) {
                                tempCheckin.put(e.b_Id, tempCheckin.get(e.b_Id) + e.CountValue);
                            } else {
                                tempCheckin.put(e.b_Id, e.CountValue);
                            }

                        }
                    }
                }

                Iterator itr = tempCheckin.entrySet().iterator();
                while (itr.hasNext()) {
                    Map.Entry entry = (Map.Entry) itr.next();
                    if ((operationCheckin.contains("="))) {
                        if (entry.getValue() == valueCheckin) {
                            finalCheckinBid.add(entry.getKey().toString());
                        }
                    }
                    if ((operationCheckin.contains("<"))) {
                        if (Integer.parseInt(entry.getValue().toString()) < Integer.parseInt(valueCheckin)) {
                            finalCheckinBid.add(entry.getKey().toString());
                            //System.out.println("in <");
                        }
                    }
                    if ((operationCheckin.contains(">"))) {
                        if (Integer.parseInt(entry.getValue().toString()) > Integer.parseInt(valueCheckin)) {
                            finalCheckinBid.add(entry.getKey().toString());
                            //System.out.println("in >");
                        }
                    }
                }
                //abhi tak ki bid is in finalCheckinBid
                //                    for(String a :finalCheckinBid){
                //                    System.out.println(a);
                //                    }
                finalQuery.append(
                        "Stage{name='$match', value=Or Filter{filters=[Operator Filter{fieldName='checkin_info.2-3', operator='$exists', value=BsonBoolean{value=true}}, Operator Filter{fieldName='checkin_info.2-4', operator='$exists', value=BsonBoolean{value=true}}]}}\n"
                                + "Document{{$group=Document{{_id=$business_id, total1=Document{{$sum=$checkin_info.2-4}}, total2=Document{{$sum=$checkin_info.2-3}}}}}}\n"
                                + "Stage{name='$match', value=Operator Filter{fieldName='totalCheckins', operator='$gt', value=4}}");
                try {
                    List<Object> reviewCategoryIdList = new ArrayList<Object>();

                    DBObject match = new BasicDBObject("$match",
                            new BasicDBObject("date", new BasicDBObject("$gt", format.parse(fromdate))
                                    .append("$lt", format.parse(todate))));

                    DBObject groupFields = new BasicDBObject("_id", "$business_id");
                    groupFields.put("total1", new BasicDBObject("$sum", "$votes.funny"));
                    groupFields.put("total2", new BasicDBObject("$sum", "$votes.useful"));
                    groupFields.put("total3", new BasicDBObject("$sum", "$votes.cool"));
                    groupFields.put("totalStars", new BasicDBObject("$sum", "$stars"));
                    DBObject group = new BasicDBObject("$group", groupFields);

                    DBObject fields = new BasicDBObject("_id", 1);
                    BasicDBList addFields = new BasicDBList();
                    addFields.add("$total1");
                    addFields.add("$total2");
                    addFields.add("$total3");
                    fields.put("totalVotes", new BasicDBObject("$sum", addFields));
                    fields.put("totalStars", 1);
                    DBObject project = new BasicDBObject("$project", fields);
                    BasicDBObject votes = null;
                    BasicDBObject stars = null;
                    if (operationStar.equals(">")) {
                        stars = new BasicDBObject("totalStars", new BasicDBObject("$gt", starValue));
                    }
                    if (operationStar.equals("<")) {
                        stars = new BasicDBObject("totalStars", new BasicDBObject("$lt", starValue));
                    }
                    if (operationStar.equals("=")) {
                        stars = new BasicDBObject("totalStars", new BasicDBObject("$eq", starValue));
                    }
                    if (operationVote.equals(">")) {
                        votes = new BasicDBObject("totalVotes", new BasicDBObject("$gt", voteValue));
                    }
                    if (operationVote.equals("<")) {
                        votes = new BasicDBObject("totalVotes", new BasicDBObject("$lt", voteValue));
                    }
                    if (operationVote.equals("=")) {
                        votes = new BasicDBObject("totalVotes", new BasicDBObject("$eq", voteValue));
                    }
                    List<BasicDBObject> list1 = new ArrayList<BasicDBObject>();
                    list1.add(new BasicDBObject(votes));
                    list1.add(new BasicDBObject(stars));
                    DBObject votesnStars = new BasicDBObject("$and", list1);
                    DBObject match2 = new BasicDBObject("$match", votesnStars);

                    AggregationOutput cursorForReview = collReview.aggregate(match, group, project, match2);
                    String query33 = match + "\n" + group + "\n" + project + "\n" + match2;
                    finalQuery.append(query33);

                    Iterable<DBObject> list = cursorForReview.results();
                    Iterator<DBObject> resultSet1 = list.iterator();
                    while (resultSet1.hasNext()) {
                        //                            System.out.println(resultSet1.next().get("_id"));
                        reviewCategoryIdList.add(resultSet1.next().get("_id"));
                    }
                    //                            System.out.println(reviewCategoryIdList.size());
                    //                            System.out.println(finalCheckinBid.size());
                    reviewCategoryIdList.retainAll(finalCheckinBid);
                    //                            System.out.println(reviewCategoryIdList.size());
                    //                        for (Object s : reviewCategoryIdList) { 
                    //                        System.out.println(s.toString());
                    //                        }

                    if (!Address.isEmpty() && !proximity.isEmpty()) {

                        if (Address.contains("3799 S Las Vegas Blvd Eastside Las Vegas, NV 89119")) {
                            longitude = -115.16768879999999;
                            latitude = 36.103017899999998;
                        }

                        if (Address.equalsIgnoreCase(
                                "6002 S Durango Dr Ste 100 Spring Valley Las Vegas, NV 89113")) {
                            longitude = -115.27906539999999;
                            latitude = 36.079256100000002;
                        }

                        if (Address.equalsIgnoreCase("1801 E Baseline Rd, #101 Ste 101 Tempe, AZ 85283")) {
                            longitude = -111.90860979259;
                            latitude = 33.377052104372098;
                        }

                        if (Address.equalsIgnoreCase("1033 S Park St Bay Creek Madison, WI 53715")) {
                            longitude = -89.397478300000003;
                            latitude = 43.055539400000001;
                        }

                        if (Address.equalsIgnoreCase("University Center II Lot Phoenix, AZ 85008")) {
                            longitude = -112.02540759999999;
                            latitude = 33.451857400000002;
                        }

                        List<String> pointInterest = new ArrayList<String>();
                        BasicDBList geoCoord = new BasicDBList();

                        geoCoord.add(longitude);
                        geoCoord.add(latitude);

                        BasicDBList geoParams = new BasicDBList();
                        geoParams.add(geoCoord);
                        geoParams.add(Integer.parseInt(proximity) / 1018.59);

                        BasicDBObject query = new BasicDBObject("loc",
                                new BasicDBObject("$geoWithin", new BasicDBObject("$center", geoParams)));

                        DBCursor cursorForBusiness = collBusiness.find(query);
                        finalQuery.append(query);
                        while (cursorForBusiness.hasNext()) {
                            pointInterest.add(cursorForBusiness.next().get("business_id").toString());

                        }
                        //                System.out.println(pointInterest.size());
                        //                System.out.println(reviewCategoryIdList.size());
                        reviewCategoryIdList.retainAll(pointInterest);
                        //                System.out.println(reviewCategoryIdList.size());
                    }

                    List<DBObject> outputMyList = new ArrayList<DBObject>();
                    BasicDBObject whereQuery = new BasicDBObject();
                    for (Object fianlBid2 : reviewCategoryIdList) {
                        //                        System.out.println(fianlBid2);
                        whereQuery.put("business_id", fianlBid2.toString());
                        DBCursor cursor = collBusiness.find(whereQuery);
                        while (cursor.hasNext()) {
                            //System.out.println(cursor.next());
                            outputMyList.add(cursor.next());
                        }
                    }
                    queryLabel.setText("<html><p>" + finalQuery + "</p></html>");
                    resultTable.setModel(dtm);
                    String header[] = new String[] { "B_ID", "Business", "City", "State", "Stars" };
                    // add header in table model     
                    dtm.setColumnIdentifiers(header);
                    for (DBObject temp : outputMyList) {
                        //System.out.println("Business Name : " + temp.get("name") + " Category :  " + temp.get("categories"));
                        Object[] row = new Object[5];
                        row[0] = temp.get("business_id");
                        row[1] = temp.get("name");
                        row[2] = temp.get("city");
                        row[3] = temp.get("state");
                        row[4] = temp.get("stars");

                        dtm.addRow(row);
                    }
                } catch (Exception e) {

                }
            } //review if
              ///////////////////////////////Category and Checkin///////////////////////////////
            else {//Check in with cat not review
                int j = 0;
                int l = 0;

                HashMap<String, Integer> tempCheckin = new HashMap<String, Integer>();
                ArrayList<String> finalCheckinBid = new ArrayList<String>();
                StringBuffer finalQueryCatCheck = new StringBuffer();
                ArrayList<CheckinDetail> checkinList = new ArrayList<CheckinDetail>();
                //System.out.println("I am in checkin box");
                String[] arrayDays = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
                        "Saturday" };
                for (int i = 0; i < arrayDays.length; i++) {
                    if (fromCheckin == arrayDays[i]) {
                        j = i;
                    } else if (toCheckin == arrayDays[i]) {
                        l = i;
                    }
                }
                ArrayList<Integer> days = new ArrayList<Integer>();
                days.add(j);
                int temfromday = j;
                days.add(l);

                //                         System.out.println("Input Data "+j+"  "+fromCheckinHour+"  "+toCheckin+"  "+toCheckinHour+" "+
                //                                        operationCheckin+"  "+valueCheckin);
                //               System.out.println(j);         
                int difference = CheckForDay(fromCheckin, toCheckin);
                if (difference > 0) {
                    for (int k = 0; k < difference; k++) {
                        j = j + 1;
                        if (j == 7) {
                            j = 0;
                        }
                        days.add(j);

                    }
                }
                //                        for(int q:days){
                //                        System.out.println(q);
                //                        }

                List<DBObject> categoryIdList = new ArrayList<DBObject>();
                for (String t : finalCat) {
                    BasicDBObject whereQueryBusiness = new BasicDBObject();
                    BasicDBObject fieldsBusiness = new BasicDBObject();
                    fieldsBusiness.put("business_id", 1);
                    whereQueryBusiness.put("categories", t);
                    DBCursor cursorForBusiness = collBusiness.find(whereQueryBusiness, fieldsBusiness);
                    finalQueryCatCheck.append(whereQueryBusiness);
                    while (cursorForBusiness.hasNext()) {
                        int i = 1;
                        categoryIdList.add(cursorForBusiness.next());
                        i++;
                    }
                } //for FINALCAT
                List<DBObject> checkinCategoryIdList = new ArrayList<DBObject>();
                for (DBObject s : categoryIdList) {
                    //System.out.println(s.get("business_id"));
                    BasicDBObject whereQueryCheckin = new BasicDBObject();
                    whereQueryCheckin.put("business_id", s.get("business_id"));
                    DBCursor cursorForCheckin = collCheckin.find(whereQueryCheckin);
                    while (cursorForCheckin.hasNext()) {
                        int i = 1;
                        checkinCategoryIdList.add(cursorForCheckin.next());
                        i++;
                    }
                } //for DBObject s:categoryIdList
                for (DBObject u : checkinCategoryIdList) {
                    //                                System.out.println(s.get("business_id"));    
                    //                                System.out.println(u.get("checkin_info").toString());

                    String full = u.get("checkin_info").toString();
                    String a = full.replaceAll("[{}]", "");
                    String[] b = a.split(",");
                    for (int x = 0; x < b.length; x++) {
                        CheckinDetail objCheckin = new CheckinDetail();
                        String[] c = b[x].split(":");

                        String d = c[0].replaceAll("[\"]", "");
                        String[] e = d.split("-");
                        objCheckin.b_Id = u.get("business_id").toString();
                        //                                        System.out.println(u.get("business_id").toString());
                        //                                        System.out.println(e[0]);//from time
                        objCheckin.fromTime = Integer.parseInt(e[0].replaceAll("\\s+", ""));
                        //                                        System.out.println(e[1]);//day
                        objCheckin.checkinDay = Integer.parseInt(e[1].replaceAll("\\s+", ""));
                        //                                        System.out.println(c[1]);//value
                        objCheckin.CountValue = Integer.parseInt(c[1].replaceAll("\\s+", ""));
                        ;
                        checkinList.add(objCheckin);
                        //System.out.println(checkinList.size());
                    }
                }

                for (CheckinDetail e : checkinList) {

                    for (int f : days) {

                        if ((f == temfromday && temfromday == e.checkinDay
                                && Integer.parseInt(fromCheckinHour) <= e.fromTime)
                                || (f == l && l == e.checkinDay
                                        && Integer.parseInt(toCheckinHour) >= e.fromTime)
                                || (f == e.checkinDay && f != temfromday && f != l)) {
                            //                                    System.out.println(e.b_Id);
                            //                                    System.out.println(e.CountValue);
                            if (tempCheckin.containsKey(e.b_Id)) {
                                tempCheckin.put(e.b_Id, tempCheckin.get(e.b_Id) + e.CountValue);
                            } else {
                                tempCheckin.put(e.b_Id, e.CountValue);
                            }

                        }
                    }
                }

                Iterator itr = tempCheckin.entrySet().iterator();
                while (itr.hasNext()) {
                    Map.Entry entry = (Map.Entry) itr.next();
                    if ((operationCheckin.contains("="))) {
                        if (entry.getValue() == valueCheckin) {
                            finalCheckinBid.add(entry.getKey().toString());
                        }
                    }
                    if ((operationCheckin.contains("<"))) {
                        if (Integer.parseInt(entry.getValue().toString()) < Integer.parseInt(valueCheckin)) {
                            finalCheckinBid.add(entry.getKey().toString());
                            //System.out.println("in <");
                        }
                    }
                    if ((operationCheckin.contains(">"))) {
                        if (Integer.parseInt(entry.getValue().toString()) > Integer.parseInt(valueCheckin)) {
                            finalCheckinBid.add(entry.getKey().toString());
                            //System.out.println("in >");
                        }
                    }

                    //                            
                }
                finalQueryCatCheck.append(
                        "Stage{name='$match', value=Or Filter{filters=[Operator Filter{fieldName='checkin_info.2-3', operator='$exists', value=BsonBoolean{value=true}}, Operator Filter{fieldName='checkin_info.2-4', operator='$exists', value=BsonBoolean{value=true}}]}}\n"
                                + "Document{{$group=Document{{_id=$business_id, total1=Document{{$sum=$checkin_info.2-4}}, total2=Document{{$sum=$checkin_info.2-3}}}}}}\n"
                                + "Stage{name='$match', value=Operator Filter{fieldName='totalCheckins', operator='$gt', value=4}}");
                if (!Address.isEmpty() && !proximity.isEmpty()) {

                    if (Address.contains("3799 S Las Vegas Blvd Eastside Las Vegas, NV 89119")) {
                        longitude = -115.16768879999999;
                        latitude = 36.103017899999998;
                    }

                    if (Address
                            .equalsIgnoreCase("6002 S Durango Dr Ste 100 Spring Valley Las Vegas, NV 89113")) {
                        longitude = -115.27906539999999;
                        latitude = 36.079256100000002;
                    }

                    if (Address.equalsIgnoreCase("1801 E Baseline Rd, #101 Ste 101 Tempe, AZ 85283")) {
                        longitude = -111.90860979259;
                        latitude = 33.377052104372098;
                    }

                    if (Address.equalsIgnoreCase("1033 S Park St Bay Creek Madison, WI 53715")) {
                        longitude = -89.397478300000003;
                        latitude = 43.055539400000001;
                    }

                    if (Address.equalsIgnoreCase("University Center II Lot Phoenix, AZ 85008")) {
                        longitude = -112.02540759999999;
                        latitude = 33.451857400000002;
                    }

                    List<String> pointInterest = new ArrayList<String>();
                    BasicDBList geoCoord = new BasicDBList();

                    geoCoord.add(longitude);
                    geoCoord.add(latitude);

                    BasicDBList geoParams = new BasicDBList();
                    geoParams.add(geoCoord);
                    geoParams.add(Integer.parseInt(proximity) / 1018.59);

                    BasicDBObject query = new BasicDBObject("loc",
                            new BasicDBObject("$geoWithin", new BasicDBObject("$center", geoParams)));

                    DBCursor cursorForBusiness = collBusiness.find(query);
                    finalQueryCatCheck.append(query);
                    while (cursorForBusiness.hasNext()) {
                        pointInterest.add(cursorForBusiness.next().get("business_id").toString());

                    }
                    //                System.out.println(pointInterest.size());
                    //                System.out.println(reviewCategoryIdList.size());
                    finalCheckinBid.retainAll(pointInterest);
                    //                System.out.println(reviewCategoryIdList.size());
                }

                resultTable.setModel(dtm);
                queryLabel.setText("<html><p>" + finalQueryCatCheck.toString() + "</p></html>");
                String header[] = new String[] { "B_ID", "Business", "City", "State", "Stars" };

                // add header in table model     
                dtm.setColumnIdentifiers(header);
                List<DBObject> outputMyList = new ArrayList<DBObject>();
                BasicDBObject whereQuery = new BasicDBObject();
                for (String fianlBid2 : finalCheckinBid) {
                    whereQuery.put("business_id", fianlBid2);
                    DBCursor cursor = collBusiness.find(whereQuery);
                    while (cursor.hasNext()) {
                        int i = 1;
                        //System.out.println(cursor.next());
                        outputMyList.add(cursor.next());
                        i++;
                    }
                }

                for (DBObject temp : outputMyList) {
                    //System.out.println("Business Name : " + temp.get("name") + " Category :  " + temp.get("categories"));
                    Object[] row = new Object[5];
                    row[0] = temp.get("business_id");
                    row[1] = temp.get("name");
                    row[2] = temp.get("city");
                    row[3] = temp.get("state");
                    row[4] = temp.get("stars");

                    dtm.addRow(row);
                }
                // }
            } //else with no review
        } //if for entire checkin check
        else {//only cat

            /////////////////////////////////////////Cat N Review/////////////////////////////////////////////////////////////////////
            if (!fromReview.isEmpty() && !toReview.isEmpty() && !operationStar.isEmpty() && !valueStar.isEmpty()
                    && !operationVote.isEmpty() && !valueVote.isEmpty()) {
                StringBuffer finalQueryCatReview = new StringBuffer();
                DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
                String fromDate1 = fromReview;
                String fromdate = fromDate1 + "T00:00:00Z";
                String toDate1 = toReview;
                String todate = toDate1 + "T00:00:00Z";
                int starValue = Integer.parseInt(valueStar);
                //int voteValue = 4;
                int voteValue = Integer.parseInt(valueVote);
                DB dbReview = mongoClient.getDB("review");
                DBCollection collReview = dbReview.getCollection("review");

                //abhi tak ki bid is in finalCheckinBid
                //                    for(String a :finalCheckinBid){
                //                    System.out.println(a);
                //                    }
                try {
                    List<Object> finalCatBid = new ArrayList<Object>();
                    List<Object> reviewCategoryIdList = new ArrayList<Object>();
                    for (String a : finalCat) {

                        BasicDBObject whereQueryBusinessReview = new BasicDBObject();
                        //System.out.println(a);
                        whereQueryBusinessReview.put("categories", a);
                        DBCursor cursor = collBusiness.find(whereQueryBusinessReview);
                        finalQueryCatReview.append(whereQueryBusinessReview);
                        while (cursor.hasNext()) {
                            int i = 1;
                            //System.out.println(cursor.next());
                            finalCatBid.add(cursor.next().get("business_id"));
                            i++;
                        }
                    }
                    DBObject match = new BasicDBObject("$match",
                            new BasicDBObject("date", new BasicDBObject("$gt", format.parse(fromdate))
                                    .append("$lt", format.parse(todate))));

                    DBObject groupFields = new BasicDBObject("_id", "$business_id");
                    groupFields.put("total1", new BasicDBObject("$sum", "$votes.funny"));
                    groupFields.put("total2", new BasicDBObject("$sum", "$votes.useful"));
                    groupFields.put("total3", new BasicDBObject("$sum", "$votes.cool"));
                    groupFields.put("totalStars", new BasicDBObject("$sum", "$stars"));
                    DBObject group = new BasicDBObject("$group", groupFields);

                    DBObject fields = new BasicDBObject("_id", 1);
                    BasicDBList addFields = new BasicDBList();
                    addFields.add("$total1");
                    addFields.add("$total2");
                    addFields.add("$total3");
                    fields.put("totalVotes", new BasicDBObject("$sum", addFields));
                    fields.put("totalStars", 1);
                    DBObject project = new BasicDBObject("$project", fields);
                    BasicDBObject votes = null;
                    BasicDBObject stars = null;
                    if (operationStar.equals(">")) {
                        stars = new BasicDBObject("totalStars", new BasicDBObject("$gt", starValue));
                    }
                    if (operationStar.equals("<")) {
                        stars = new BasicDBObject("totalStars", new BasicDBObject("$lt", starValue));
                    }
                    if (operationStar.equals("=")) {
                        stars = new BasicDBObject("totalStars", new BasicDBObject("$eq", starValue));
                    }
                    if (operationVote.equals(">")) {
                        votes = new BasicDBObject("totalVotes", new BasicDBObject("$gt", voteValue));
                    }
                    if (operationVote.equals("<")) {
                        votes = new BasicDBObject("totalVotes", new BasicDBObject("$lt", voteValue));
                    }
                    if (operationVote.equals("=")) {
                        votes = new BasicDBObject("totalVotes", new BasicDBObject("$eq", voteValue));
                    }
                    List<BasicDBObject> list1 = new ArrayList<BasicDBObject>();
                    list1.add(new BasicDBObject(votes));
                    list1.add(new BasicDBObject(stars));
                    DBObject votesnStars = new BasicDBObject("$and", list1);
                    DBObject match2 = new BasicDBObject("$match", votesnStars);

                    AggregationOutput cursorForReview = collReview.aggregate(match, group, project, match2);
                    String query33 = match + "\n" + group + "\n" + project + "\n" + match2;
                    finalQueryCatReview.append(query33);
                    Iterable<DBObject> list = cursorForReview.results();
                    Iterator<DBObject> resultSet1 = list.iterator();
                    while (resultSet1.hasNext()) {
                        //                            System.out.println(resultSet1.next().get("_id"));
                        reviewCategoryIdList.add(resultSet1.next().get("_id"));
                    }
                    //System.out.println(reviewCategoryIdList.size());
                    //System.out.println(finalCatBid.size());
                    reviewCategoryIdList.retainAll(finalCatBid);
                    //System.out.println(reviewCategoryIdList.size());
                    //                        for (Object s : reviewCategoryIdList) { 
                    //                        System.out.println(s.toString());
                    //                        }
                    if (!Address.isEmpty() && !proximity.isEmpty()) {

                        if (Address.contains("3799 S Las Vegas Blvd Eastside Las Vegas, NV 89119")) {
                            longitude = -115.16768879999999;
                            latitude = 36.103017899999998;
                        }

                        if (Address.equalsIgnoreCase(
                                "6002 S Durango Dr Ste 100 Spring Valley Las Vegas, NV 89113")) {
                            longitude = -115.27906539999999;
                            latitude = 36.079256100000002;
                        }

                        if (Address.equalsIgnoreCase("1801 E Baseline Rd, #101 Ste 101 Tempe, AZ 85283")) {
                            longitude = -111.90860979259;
                            latitude = 33.377052104372098;
                        }

                        if (Address.equalsIgnoreCase("1033 S Park St Bay Creek Madison, WI 53715")) {
                            longitude = -89.397478300000003;
                            latitude = 43.055539400000001;
                        }

                        if (Address.equalsIgnoreCase("University Center II Lot Phoenix, AZ 85008")) {
                            longitude = -112.02540759999999;
                            latitude = 33.451857400000002;
                        }

                        List<String> pointInterest = new ArrayList<String>();
                        BasicDBList geoCoord = new BasicDBList();

                        geoCoord.add(longitude);
                        geoCoord.add(latitude);

                        BasicDBList geoParams = new BasicDBList();
                        geoParams.add(geoCoord);
                        geoParams.add(Integer.parseInt(proximity) / 1018.59);

                        BasicDBObject query = new BasicDBObject("loc",
                                new BasicDBObject("$geoWithin", new BasicDBObject("$center", geoParams)));

                        DBCursor cursorForBusiness = collBusiness.find(query);
                        finalQueryCatReview.append(query);
                        while (cursorForBusiness.hasNext()) {
                            pointInterest.add(cursorForBusiness.next().get("business_id").toString());

                        }
                        //                System.out.println(pointInterest.size());
                        //                System.out.println(reviewCategoryIdList.size());
                        reviewCategoryIdList.retainAll(pointInterest);
                        //                System.out.println(reviewCategoryIdList.size());
                    }
                    queryLabel.setText("<html><p>" + finalQueryCatReview.toString() + "</p></html>");
                    resultTable.setModel(dtm);

                    String header[] = new String[] { "B_ID", "Business", "City", "State", "Stars" };

                    // add header in table model     
                    dtm.setColumnIdentifiers(header);
                    List<DBObject> outputMyList = new ArrayList<DBObject>();
                    for (Object fianlBid2 : reviewCategoryIdList) {
                        BasicDBObject whereQuery = new BasicDBObject();

                        //                        System.out.println(fianlBid2);
                        whereQuery.put("business_id", fianlBid2.toString());
                        DBCursor cursor = collBusiness.find(whereQuery);
                        while (cursor.hasNext()) {
                            //System.out.println(cursor.next());
                            outputMyList.add(cursor.next());
                        }
                    }

                    for (DBObject temp : outputMyList) {
                        //System.out.println("Business Name : " + temp.get("name") + " Category :  " + temp.get("categories"));
                        Object[] row = new Object[5];
                        row[0] = temp.get("business_id");
                        row[1] = temp.get("name");
                        row[2] = temp.get("city");
                        row[3] = temp.get("state");
                        row[4] = temp.get("stars");

                        dtm.addRow(row);
                    }
                } catch (Exception e) {

                }
            } //////////////////////////////////////Only Category ////////////////////////////////////////////
            else {
                resultTable.setModel(dtm);
                String header[] = new String[] { "B_ID", "Business", "City", "State", "Stars", "Category" };
                // add header in table model     
                dtm.setColumnIdentifiers(header);
                StringBuffer catOnly = new StringBuffer();
                if (!Address.isEmpty() && !proximity.isEmpty() && finalCat.size() > 0) {
                    if (Address.contains("3799 S Las Vegas Blvd Eastside Las Vegas, NV 89119")) {
                        longitude = -115.16768879999999;
                        latitude = 36.103017899999998;
                    }

                    if (Address
                            .equalsIgnoreCase("6002 S Durango Dr Ste 100 Spring Valley Las Vegas, NV 89113")) {
                        longitude = -115.27906539999999;
                        latitude = 36.079256100000002;
                    }

                    if (Address.equalsIgnoreCase("1801 E Baseline Rd, #101 Ste 101 Tempe, AZ 85283")) {
                        longitude = -111.90860979259;
                        latitude = 33.377052104372098;
                    }

                    if (Address.equalsIgnoreCase("1033 S Park St Bay Creek Madison, WI 53715")) {
                        longitude = -89.397478300000003;
                        latitude = 43.055539400000001;
                    }

                    if (Address.equalsIgnoreCase("University Center II Lot Phoenix, AZ 85008")) {
                        longitude = -112.02540759999999;
                        latitude = 33.451857400000002;
                    }
                    //BasicDBList category = new BasicDBList();
                    for (String a : finalCat) {

                        BasicDBObject andQuery = new BasicDBObject();
                        List<BasicDBObject> obj = new ArrayList<BasicDBObject>();

                        List<DBObject> pointInterest = new ArrayList<DBObject>();
                        BasicDBList geoCoord = new BasicDBList();

                        geoCoord.add(longitude);
                        geoCoord.add(latitude);

                        BasicDBList geoParams = new BasicDBList();
                        geoParams.add(geoCoord);
                        geoParams.add(Integer.parseInt(proximity) / 1018.59);

                        BasicDBObject query = new BasicDBObject("loc",
                                new BasicDBObject("$geoWithin", new BasicDBObject("$center", geoParams)));
                        obj.add(query);
                        obj.add(new BasicDBObject("categories", a));
                        andQuery.put("$and", obj);
                        System.out.println(andQuery);
                        DBCursor cursorForBusiness = collBusiness.find(andQuery);
                        catOnly.append(andQuery);
                        while (cursorForBusiness.hasNext()) {
                            pointInterest.add(cursorForBusiness.next());

                        }
                        for (DBObject temp : pointInterest) {

                            Object[] row = new Object[6];
                            row[0] = temp.get("business_id");
                            row[1] = temp.get("name");
                            row[2] = temp.get("city");
                            row[3] = temp.get("state");
                            row[4] = temp.get("stars");
                            row[5] = a;

                            dtm.addRow(row);
                        }
                    }
                } else {
                    List<DBObject> testMyList = new ArrayList<DBObject>();
                    for (String a : finalCat) {
                        BasicDBObject whereQuery = new BasicDBObject();
                        //System.out.println(a);
                        whereQuery.put("categories", a);
                        DBCursor cursor = collBusiness.find(whereQuery);
                        catOnly.append(whereQuery);
                        while (cursor.hasNext()) {
                            testMyList.add(cursor.next());

                        }

                        for (DBObject temp : testMyList) {
                            //System.out.println("Business Name : " + temp.get("name") + " Category :  " + temp.get("categories"));
                            Object[] row = new Object[6];
                            row[0] = temp.get("business_id");
                            row[1] = temp.get("name");
                            row[2] = temp.get("city");
                            row[3] = temp.get("state");
                            row[4] = temp.get("stars");
                            row[5] = a;

                            dtm.addRow(row);
                        }
                    }

                }
                queryLabel.setText("<html><p>" + catOnly.toString() + "</p></html>");
            }
        } //else
    } //cat and subCat is selected

}

From source file:home.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from   w ww. j a  va  2 s  . c o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    response.setContentType("text/html");
    String username = request.getParameter("username");

    String tweet = request.getParameter("tweet");
    try {
        MongoClient mongo = new MongoClient("localhost", 27017);
        DB db = mongo.getDB("test");
        System.out.println("Connection established");
        DBCollection User = db.getCollection("User");
        DBCollection Tweet = db.getCollection("Tweet");

        DBCursor cursor = Tweet.find();
        int count = 0;
        if (cursor.size() < 1) {
            count = 1;
        } else {
            count = cursor.size() + 1;

        }
        BasicDBObject document = new BasicDBObject();
        document.put("tweet_id", count);
        document.put("username", username);
        document.put("tweet_text", tweet);
        document.put("date", new Date());
        Tweet.insert(document);

        ArrayList<Integer> tweet_id = new ArrayList();
        tweet_id.add(count);
        DBObject searchObject = new BasicDBObject();
        searchObject.put("username", username);

        DBObject modifiedObject = new BasicDBObject();
        modifiedObject.put("$push", new BasicDBObject().append("tweet_id", count));
        User.update(searchObject, modifiedObject);

        out.println(tweet);
    } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
    }
}

From source file:QuestionGUI.java

private JSONObject getCurrentDoc() throws ParseException {
    db = mongo.getDatabase();//  w  w w.ja v  a2  s  .  c o m
    collection = db.getCollection("Users");

    DBObject query = new BasicDBObject();
    query.put("Info.Username", username);

    DBObject fields = new BasicDBObject();
    fields.put(d, 1);

    JSONParser parser = new JSONParser();

    DBCursor cursor = collection.find(query, fields);
    String json = cursor.next().toString();
    JSONObject jsonFile = (JSONObject) parser.parse(json);
    return jsonFile;
}

From source file:Welcome.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    String accno = JOptionPane.showInputDialog(this, "Enter Your Account Number");
    if (isInteger(accno)) {

        int value = JOptionPane.showConfirmDialog(this, "Do You Want to add Account No. " + accno);
        if (value == 0) {
            String Banks[] = { "", "Allahabad Bank", "Andhra Bank", "Bank of Baroda", "Bank of India",
                    "Bank of Maharashtra", "Canara Bank", "Central Bank of India", "Corporation Bank",
                    "Dena Bank", "Indian Bank", "Indian Overseas Bank", "Oriental Bank of Commerce",
                    "Punjab & Sind Bank", "Punjab National Bank", "Syndicate Bank", "UCO Bank",
                    "Union Bank of India", "United Bank of India", "Vijaya Bank", "Axis Bank",
                    "City Union Bank", "Dhanlaxmi Bank", "Federal Bank", "HDFC Bank", "ICICI Bank", "IDFC Bank",
                    "Karnataka Bank", "IndusInd Bank", "ING Vysya Bank", "Jammu and Kashmir Bank",
                    "Karur Vysya Bank", "Kotak Mahindra Bank", "Yes bank", "Citi Bank", "State Bank of India",
                    "State Bank of Patiala", "State Bank of Mysore", "State Bank of Travancore",
                    "State Bank of Bikaner and Jaipur", "State Bank of Hyderabad", "State Bank Of Saurashtra"

            };//from ww w .ja v  a  2  s .c  o  m
            Arrays.sort(Banks);
            JComboBox jcb = new JComboBox(Banks);
            jcb.setEditable(true);
            JOptionPane.showMessageDialog(this, jcb, "Select Your Bank", JOptionPane.QUESTION_MESSAGE);
            while (jcb.getSelectedItem().equals("")) {
                JOptionPane.showMessageDialog(this, "Please Select the Bank");
                JOptionPane.showMessageDialog(this, jcb, "Select Your Bank", JOptionPane.QUESTION_MESSAGE);
            }
            String money = JOptionPane.showInputDialog(this,
                    "Enter the amount present in " + accno + " account");
            String Bank = (String) jcb.getSelectedItem();
            while (!isInteger(money)) {
                JOptionPane.showMessageDialog(this, "You entered a Wrong Value. Please Enter Correct Value");
                money = JOptionPane.showInputDialog(this, "Enter the amount present in " + accno + " account");
            }
            MongoClient client = new MongoClient("localhost", 27017);
            DB db;
            db = client.getDB("ExpenseManager");
            DBCollection reg = (DBCollection) db.getCollection("Registration");
            DBObject query = new BasicDBObject("unm", unm);
            DBObject update = new BasicDBObject();

            DBCursor find = reg.find(query);
            while (find.hasNext()) {
                DBObject next = find.next();
                int count = 1;
                for (int i = 1; i <= 5; i++) {
                    String str1 = "Account" + i;
                    String str2 = "Bank" + i;
                    String str3 = "Money" + i;
                    System.out.println(str1);
                    if (!(next.containsField(str1))) {
                        update.put("$set",
                                new BasicDBObject(str1, accno).append(str2, Bank).append(str3, money));
                        WriteResult result = reg.update(query, update);
                        setListVal();
                        break;
                    }
                }
            }

        }

    } else {
        JOptionPane.showMessageDialog(this, "You Entered a wrong Number");
    }

    // TODO add your handling code here:
}

From source file:achmad.rifai.erp1.beans.Form1.java

public DBObject genComparasion() {
    DBObject o = new com.mongodb.BasicDBObject();
    com.mongodb.BasicDBList l = new com.mongodb.BasicDBList();
    data.forEach((s) -> {//from  w w w  .ja va 2s  . c o m
        l.add(s);
    });
    o.put("berkas", kode);
    o.put("bin", l);
    return o;
}

From source file:achmad.rifai.erp1.beans.Form3.java

public DBObject genComparator() {
    DBObject o = new com.mongodb.BasicDBObject();
    com.mongodb.BasicDBList l = new com.mongodb.BasicDBList();
    data.forEach((s) -> {//  ww w. j  a va 2s.  c o m
        l.add(s);
    });
    o.put("bin", l);
    o.put("berkas1", kode1);
    o.put("berkas2", kode2);
    o.put("berkas3", kode3);
    return o;
}