Example usage for com.mongodb BasicDBObject getString

List of usage examples for com.mongodb BasicDBObject getString

Introduction

In this page you can find the example usage for com.mongodb BasicDBObject getString.

Prototype

public String getString(final String key) 

Source Link

Document

Returns the value of a field as a string

Usage

From source file:com.streamreduce.storm.spouts.EventSpout.java

License:Apache License

/**
 * {@inheritDoc}//from  ww w .j ava2 s  .c  om
 */
@Override
public void handleDBEntry(SpoutOutputCollector collector, BasicDBObject entry) {
    BasicDBObject metadata = entry.containsField("metadata") ? (BasicDBObject) entry.get("metadata")
            : new BasicDBObject();
    String eventType = metadata.getString("targetType");

    // Just in case
    if (eventType == null) {
        // TODO: Figure out the best way to handle this

        // Log the inability to process further
        logger.error("Event with id of " + entry.get("_id") + " has no target type.  Unable to process.");

        // Early return to avoid emitting the event
        return;
    }

    String v = (String) metadata.get("targetVisibility");
    if (v != null) {
        Visibility visibility = Visibility.valueOf(v);
        if (visibility == Visibility.SELF) {
            // do not process private information
            return;
        }
    }

    MongoClient.mapMongoToPlainJavaTypes(entry);
    // Emit the entry to the type-specific stream
    collector.emit(eventType, new Values(entry.toMap()));
    ack(entry);
}

From source file:com.tml.pathummoto.Dao.BillDao.java

public ArrayList<Bill> searchBill(String no) {

    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Now connect to your databases
    DB db = mongoClient.getDB("pathumdb");
    System.out.println("Connect to database successfully");

    DBCollection coll = db.getCollection("Bill");
    System.out.println("Collection user selected successfully");

    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("vehicleNo", no);
    DBCursor cursor = coll.find(whereQuery);

    ArrayList<Bill> bills = new ArrayList<Bill>();

    while (cursor.hasNext()) {
        BasicDBObject doc = (BasicDBObject) cursor.next();

        if (doc != null) {
            Bill bill = new Bill();
            bill.setDate(doc.getDate("Date"));
            bill.setKm(doc.getInt("km"));
            bill.setPayment(doc.getInt("payment"));
            bill.setService(doc.getInt("service"));
            bill.setTotalCost(doc.getInt("total"));
            String array = "";
            int partSize = doc.getInt("partsSize");
            for (int i = 0; i < partSize; i++) {
                String parts = "part" + i;
                String quentity = "quant" + i;
                array = array + doc.getString(parts) + " : " + doc.getInt(quentity) + "\n";

            }/*www .jav a  2s  .  c  o  m*/
            bill.setParts(array);
            bills.add(bill);
        }
    }
    return bills;
}

From source file:com.tml.pathummoto.Dao.CustomDao.java

public Customer searchCustomer(String no) {
    Customer customer = new Customer();
    // To connect to mongodb server
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Now connect to your databases
    DB db = mongoClient.getDB("pathumdb");
    System.out.println("Connect to database successfully");

    DBCollection coll = db.getCollection("customer");
    System.out.println("Collection user selected successfully");

    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("_id", no);
    DBCursor cursor = coll.find(whereQuery);
    while (cursor.hasNext()) {
        System.out.println(cursor.next());
    }/* ww w  . j ava  2  s .com*/
    BasicDBObject doc = (BasicDBObject) cursor.curr();
    System.out.println("doc" + doc);
    if (doc != null) {
        customer.setVehicleNo(doc.getString("_id"));
        customer.setName(doc.getString("name"));
        customer.setPayment(doc.getInt("payment"));
        customer.setFreeServiceNo(doc.getInt("freeServiceNo"));
        customer.setServiceNo(doc.getInt("serviceNo"));
        customer.setDateOfDelivery(doc.getDate("dateOfDelivery"));
        customer.setLastKm(doc.getInt("lastKm"));

    }

    return customer;
}

From source file:com.tml.pathummoto.Dao.PartDao.java

public Part singlePart(String partNumber) {
    Part part = new Part();
    // To connect to mongodb server
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Now connect to your databases
    DB db = mongoClient.getDB("pathumdb");
    System.out.println("Connect to database successfully");

    DBCollection coll = db.getCollection("part");
    System.out.println("Collection user selected successfully");

    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("_id", partNumber);
    DBCursor cursor = coll.find(whereQuery);
    while (cursor.hasNext()) {
        System.out.println(cursor.next());
    }/*from w w w . j a  v  a2 s .c  o m*/
    BasicDBObject doc = (BasicDBObject) cursor.curr();
    if (doc != null) {
        part.setPartName(doc.getString("Part Name"));
        part.setPartNo(doc.getString("_id"));

    }

    return part;
}

From source file:com.tml.pathummoto.Dao.PartDao.java

public ArrayList<String> getModelData() {
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Now connect to your databases
    DB db = mongoClient.getDB("pathumdb");
    System.out.println("Connect to database successfully");

    BasicDBObject query = new BasicDBObject();
    BasicDBObject field = new BasicDBObject();
    field.put("_id", 1);
    DBCursor cursor = db.getCollection("model").find(query, field);
    ArrayList arr = new ArrayList();
    while (cursor.hasNext()) {
        BasicDBObject obj = (BasicDBObject) cursor.next();
        arr.add(obj.getString("_id"));
    }//from   w  w w.  j ava2s .c o  m
    return (arr);
}

From source file:com.tml.pathummoto.Dao.PartDao.java

public ArrayList getMainPartData(String name) {
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Now connect to your databases
    DB db = mongoClient.getDB("pathumdb");
    System.out.println("Connect to database successfully");

    DBCollection coll = db.getCollection("mainpart");
    System.out.println("Collection user selected successfully");

    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("Model Name", name);
    DBCursor cursor = coll.find(whereQuery);
    ArrayList arr = new ArrayList();
    while (cursor.hasNext()) {
        BasicDBObject obj = (BasicDBObject) cursor.next();
        arr.add(obj.getString("Part Type"));
    }//from w w  w.j av  a 2  s . co m
    return (arr);
}

From source file:com.tml.pathummoto.Dao.PartDao.java

public String getImage(String model, String mainPart) {
    String path = "C:\\Users\\Tishan Madhawa\\Pictures\\WP_20160118_17_31_47_Pro.jpg";
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Now connect to your databases
    DB db = mongoClient.getDB("pathumdb");
    System.out.println("Connect to database successfully");

    DBCollection coll = db.getCollection("mainpart");
    System.out.println("Collection user selected successfully");

    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("Model Name", model);
    whereQuery.put("Part Type", mainPart);
    DBCursor cursor = coll.find(whereQuery);

    while (cursor.hasNext()) {
        BasicDBObject obj = (BasicDBObject) cursor.next();

        path = obj.getString("path");

    }//w w w .  j av  a2s .c  o m

    System.out.println(path);
    return path;
}

From source file:com.tml.pathummoto.Dao.PartDao.java

public ArrayList searchParts(String model, String mainPart) {
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Now connect to your databases
    DB db = mongoClient.getDB("pathumdb");
    System.out.println("Connect to database successfully");

    DBCollection coll = db.getCollection("part");
    System.out.println("Collection user selected successfully");

    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("Model Name", model);
    whereQuery.put("Part Type", mainPart);

    DBCursor cursor = coll.find(whereQuery);
    ArrayList<Part> arr = new ArrayList<Part>();
    while (cursor.hasNext()) {
        BasicDBObject obj = (BasicDBObject) cursor.next();
        Part part = new Part(obj.getString("Image No"), obj.getString("_id"), obj.getString("Part Name"));

        arr.add(part);/*w  w w .  j av a 2  s  .  c o  m*/
        System.out.println(arr);
    }
    return (arr);
}

From source file:com.tml.pathummoto.Dao.PartDao.java

public ArrayList<String> getMainPart() {
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Now connect to your databases
    DB db = mongoClient.getDB("pathumdb");
    System.out.println("Connect to database successfully");

    BasicDBObject query = new BasicDBObject();
    BasicDBObject field = new BasicDBObject();
    field.put("Part Type", 1);
    DBCursor cursor = db.getCollection("mainpart").find(query, field);
    ArrayList arr = new ArrayList();
    while (cursor.hasNext()) {
        BasicDBObject obj = (BasicDBObject) cursor.next();
        arr.add(obj.getString("Part Type"));
    }/*from  w w w . ja v  a 2 s  .com*/
    return (arr);
}

From source file:com.tml.pathummoto.Dao.PartDao.java

public ArrayList searchpart3(String modelName, String PartType) {
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Now connect to your databases
    DB db = mongoClient.getDB("pathumdb");
    System.out.println("Connect to database successfully");

    DBCollection coll = db.getCollection("part");
    System.out.println("Collection user selected successfully");
    System.out.println(modelName);
    System.out.println(PartType);
    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("Model Name", modelName);
    whereQuery.put("Part Type", PartType);
    DBCursor cursor = coll.find(whereQuery);
    ArrayList<Part> arr = new ArrayList<Part>();
    while (cursor.hasNext()) {
        BasicDBObject obj = (BasicDBObject) cursor.next();
        Part part = new Part(obj.getString("Part Name"), obj.getString("_id"), obj.getString("Part Type"),
                obj.getInt("quant"));
        // System.out.println(obj.getString("Image No").toString());
        arr.add(part);/*from   w  w w .  j a  v  a2 s.  c o  m*/

    }
    return (arr);

}