Example usage for com.mongodb DBObject toMap

List of usage examples for com.mongodb DBObject toMap

Introduction

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

Prototype

Map toMap();

Source Link

Document

Returns a map representing this BSONObject.

Usage

From source file:com.kurniakue.trxreader.data.TransactionD.java

public List<Transaction> getTransactionsNonRkapByDate(String dateStr) {
    List<Transaction> list = new ArrayList<>();
    if (dateStr == null) {
        return list;
    }//from  ww w  .  ja  va 2 s  .c  om
    DBCursor cursor;
    if ("".equals(dateStr)) {
        cursor = transactions.find();
    } else {
        cursor = transactions.find(new BasicDBObject(F.Date.name(), dateStr).append(F.ItemNo.name(),
                new BasicDBObject("$ne", "RKAP")));
    }
    cursor.sort(new BasicDBObject(F.ItemNo.name(), 1).append(F.TransactionID.name(), 1));

    while (cursor.hasNext()) {
        DBObject dbobject = cursor.next();
        Transaction transaction = new Transaction();
        transaction.putAll(dbobject.toMap());
        list.add(transaction); //filter by itemno and item name RKAP - saldo, fix amount to + instead of -
    }

    return list;
}

From source file:com.kurniakue.trxreader.data.TransactionD.java

public List<Transaction> getTransactionsOfTheMonth(String yearMonth) {
    List<Transaction> transactionList = new ArrayList<>();
    //getQuery.put("employeeId", new BasicDBObject("$gt", 2).append("$lt", 5));
    DBCursor cursor = transactions/*from   w  w  w  .j a  va2 s . com*/
            .find(new BasicDBObject("Date",
                    new BasicDBObject("$regex", yearMonth + ".*").append("$options", "i")))
            .sort(new BasicDBObject("Date", 1));
    while (cursor.hasNext()) {
        DBObject result = cursor.next();
        Transaction transaction = new Transaction();
        transaction.putAll(result.toMap());
        transactionList.add(transaction);
        System.out.println(
                transaction.getString(Transaction.F.Date) + transaction.getString(Transaction.F.ItemName)
                        + transaction.getString(Transaction.F.CustomerName));
    }

    return transactionList;
}

From source file:com.kurniakue.trxreader.data.TransactionD.java

public void printCustomerAtMonth(String customerName, String yearMonth) {
    DBCursor cursor = transactions.find(b("Date", b("$regex", yearMonth + ".*").append("$options", "i"))
            .append("CustomerName", customerName)).sort(b("Date", 1));

    int total = 0;
    while (cursor.hasNext()) {
        DBObject result = cursor.next();
        Transaction transaction = new Transaction();
        transaction.putAll(result.toMap());

        int count = transaction.getInt(Transaction.F.Count);
        int amount = -transaction.getInt(Transaction.F.Amount);
        int dcflag = transaction.getInt(Transaction.F.DCFlag);
        total += (amount * dcflag);// w  w w . j a v a2  s  .  co m
        String samount;
        if (count > 1) {
            samount = count + " x @" + Tool.formatNumber(transaction.getInt(Transaction.F.Price)) + " = "
                    + Tool.formatNumber(amount * dcflag);
        } else {
            samount = Tool.formatNumber(amount * dcflag);
        }
        System.out.println(transaction.getString(Transaction.F.Date) + " "
                + transaction.getString(Transaction.F.ItemName) + ": " + samount);
    }

    System.out.println("Total: " + Tool.formatMoney(total));
}

From source file:com.linuxbox.enkive.statistics.services.retrieval.mongodb.MongoStatsQuery.java

License:Open Source License

public Map<String, Object> getQuery() {
    Map<String, Object> mongoQuery = new BasicDBObject();

    if (gathererName != null) {
        mongoQuery.put(STAT_GATHERER_NAME, gathererName);
    }//from   w  w  w .j a v  a2  s . com

    if (grainType != null) {
        if (grainType == 0) {
            mongoQuery.put(CONSOLIDATION_TYPE, null);
        } else {
            mongoQuery.put(CONSOLIDATION_TYPE, grainType);
        }
    }

    DBObject time = new BasicDBObject();
    String tsKey;
    if (isPointQuery) {
        tsKey = STAT_TIMESTAMP + "." + STAT_TS_POINT;
    } else {
        tsKey = STAT_TIMESTAMP + "." + CONSOLIDATION_MIN;
    }

    if (startTimestamp != null) {
        time.put("$gte", startTimestamp);
    }
    if (endTimestamp != null) {
        time.put("$lt", endTimestamp);
    }

    if (!time.toMap().isEmpty()) {
        mongoQuery.put(tsKey, time);
    }

    return mongoQuery;
}

From source file:com.linuxbox.enkive.statistics.services.retrieval.mongodb.MongoStatsRetrievalService.java

License:Open Source License

/**
 * Takes a DBObject, extracts the map from it, and inserts that map into the
 * given set. NOTE: warnings are suppressed because they are being activated
 * because the actual type of the map is not specified in the dbObject but
 * it should not matter so long as it conforms to Mongo's key:value format
 * /*from   w ww.j  a v a  2s.  com*/
 * @param entry
 *            -dbObject to extract map from
 * @param stats
 *            -set to add map to
 */
@SuppressWarnings("unchecked")
private void addMapToSet(DBObject entry, Set<Map<String, Object>> stats) {
    stats.add(entry.toMap());
}

From source file:com.linuxbox.enkive.statistics.services.retrieval.mongodb.MongoStatsRetrievalService.java

License:Open Source License

@SuppressWarnings("unchecked")
private void addMapToList(DBObject entry, List<Map<String, Object>> stats) {
    stats.add(entry.toMap());
}

From source file:com.mobileman.kuravis.core.services.treatment_review.impl.TreatmentReviewServiceImpl.java

License:Apache License

/**
 * @param treatmentReview// ww w. j  av  a2 s .com
 * @param user
 */
private void processUserOnCreateOrUpdate(DBObject treatmentReview, DBObject user) {
    DBObject newUserData = new BasicDBObject();
    for (String userProperty : new String[] { User.ATTR_YEAR_OF_BIRTH, User.ATTR_GENDER }) {
        if (treatmentReview.containsField(userProperty)) {
            newUserData.put(userProperty, treatmentReview.get(userProperty));
        }
    }

    if (newUserData.toMap().size() > 0) {
        this.userService.updateUser((String) user.get(EntityUtils.ID), newUserData);
    }

    treatmentReview.removeField(User.ATTR_YEAR_OF_BIRTH);
    treatmentReview.removeField(User.ATTR_GENDER);
}

From source file:com.paradigma.recommender.db.MongoDBDataModel.java

License:Apache License

/**
 * <p>// ww  w .  j  av a2  s.  c o m
 * Translates the MongoDB identifier to Mahout/MongoDBDataModel's internal
 * identifier, if required.
 * </p>
 * <p>
 * If MongoDB identifiers are long datatypes, it returns the id.
 * </p>
 * <p>
 * This conversion is needed since Mahout uses the long datatype to feed the
 * recommender, and MongoDB uses 12 bytes to create its identifiers.
 * </p>
 *
 * @param id     MongoDB identifier
 * @param isUser
 * @return String containing the translation of the external MongoDB ID to
 *         internal long ID (mapping).
 * @see #fromLongToId(long)
 * @see <a href="http://www.mongodb.org/display/DOCS/Object%20IDs">
 *      Mongo Object IDs</a>
 */
public String fromIdToLong(String id, boolean isUser) {
    DBObject objectIdLong = collectionMap.findOne(new BasicDBObject("element_id", id));
    if (objectIdLong != null) {
        Map<String, Object> idLong = (Map<String, Object>) objectIdLong.toMap();
        return (String) idLong.get("long_value");
    } else {
        objectIdLong = new BasicDBObject();
        String longValue = Long.toString(idCounter++);
        objectIdLong.put("element_id", id);
        objectIdLong.put("long_value", longValue);
        collectionMap.insert(objectIdLong);
        log.info("Adding Translation {}: {} long_value: {}",
                new Object[] { isUser ? "User ID" : "Item ID", id, longValue });
        return longValue;
    }
}

From source file:com.paradigma.recommender.db.MongoDBDataModel.java

License:Apache License

/**
 * <p>// ww w  . j a  v  a2 s.c om
 * Translates the Mahout/MongoDBDataModel's internal identifier to MongoDB
 * identifier, if required.
 * </p>
 * <p>
 * If MongoDB identifiers are long datatypes, it returns the id in String
 * format.
 * </p>
 * <p>
 * This conversion is needed since Mahout uses the long datatype to feed the
 * recommender, and MongoDB uses 12 bytes to create its identifiers.
 * </p>
 *
 * @param id Mahout's internal identifier
 * @return String containing the translation of the internal long ID to
 *         external MongoDB ID (mapping).
 * @see #fromIdToLong(String, boolean)
 * @see <a href="http://www.mongodb.org/display/DOCS/Object%20IDs">
 *      Mongo Object IDs</a>
 */
public String fromLongToId(long id) {
    DBObject objectIdLong = collectionMap.findOne(new BasicDBObject("long_value", Long.toString(id)));
    Map<String, Object> idLong = (Map<String, Object>) objectIdLong.toMap();
    return (String) idLong.get("element_id");
}

From source file:com.redhat.lightblue.mongo.crud.BsonMerge.java

License:Open Source License

@Override
protected Iterator<Map.Entry<String, Object>> getFields(DBObject node) {
    return node.toMap().entrySet().iterator();
}