Example usage for com.mongodb BasicDBObject getLong

List of usage examples for com.mongodb BasicDBObject getLong

Introduction

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

Prototype

public long getLong(final String key) 

Source Link

Document

Returns the value of a field as a long .

Usage

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

License:Apache License

private BasicDBObject getMostRecentEntryFromEvents(List<BasicDBObject> events) {
    if (events == null) {
        return null;
    }//  w w w. j  a v  a 2  s .c o  m
    BasicDBObject mostRecent = null;
    for (BasicDBObject event : events) {
        if (event == null) {
            continue;
        }
        if (mostRecent == null) {
            mostRecent = event;
            continue;
        }
        if (event.getLong("timestamp") > mostRecent.getLong("timestamp")) {
            mostRecent = event;
        }
    }
    return mostRecent;
}

From source file:controllers.FilterController.java

License:Apache License

public static Statistics getStatisticsFromResult(BasicDBObject aggregation) {
    if (aggregation == null)
        return null;

    final DecimalFormat df = new DecimalFormat("#.##");
    Statistics stats = new Statistics();
    stats.setCount(aggregation.getInt("count") + " objects");
    stats.setSize(df.format(aggregation.getLong("sum") / 1024D / 1024) + " MB");
    stats.setAvg(df.format(aggregation.getDouble("avg") / 1024 / 1024) + " MB");
    stats.setMin(aggregation.getLong("min") + " B");
    stats.setMax(df.format(aggregation.getLong("max") / 1024D / 1024) + " MB");
    stats.setSd(df.format(aggregation.getDouble("stddev") / 1024 / 1024) + " MB");
    stats.setVar(df.format(aggregation.getDouble("variance") / 1024 / 1024 / 1024 / 1024) + " MB");
    // because of sd^2
    return stats;
}

From source file:controllers.FilterController.java

License:Apache License

private static Graph getFixedWidthHistogram(Filter filter, String property, int width) {
    BasicDBObject query = Application.getFilterQuery(filter);
    MapReduceJob job = new NumericAggregationJob(filter.getCollection(), property);
    job.setFilterquery(query);//from w w w. j  ava  2  s  .c om

    MapReduceOutput output = job.execute();
    List<BasicDBObject> results = (List<BasicDBObject>) output.getCommandResult().get("results");
    Graph g = null;
    if (!results.isEmpty()) {
        BasicDBObject aggregation = (BasicDBObject) results.get(0).get("value");
        long min = aggregation.getLong("min");
        long max = aggregation.getLong("max");

        int bins = (int) ((max - min) / width);
        Map<String, String> config = new HashMap<String, String>();
        config.put("bin_width", width + "");

        job = new HistogramJob(filter.getCollection(), property);
        job.setFilterquery(query);
        job.setConfig(config);
        output = job.execute();
        results = (List<BasicDBObject>) output.getCommandResult().get("results");
        List<String> keys = new ArrayList<String>();
        List<String> values = new ArrayList<String>();

        calculateNumericHistogramResults(output, keys, values, width);

        g = new Graph(property, keys, values);
    }

    return g;

}

From source file:controllers.FilterController.java

License:Apache License

private static Graph getSturgesHistogramm(Filter f, String property) {
    BasicDBObject query = Application.getFilterQuery(f);
    DBCursor cursor = Configurator.getDefaultConfigurator().getPersistence().find(Constants.TBL_ELEMENTS,
            query);/*from   w  w  w .j a va 2  s.c  o m*/
    int n = cursor.size();
    int bins = (int) ((Math.log(n) / Math.log(2)) + 1);
    MapReduceJob job = new NumericAggregationJob(f.getCollection(), property);
    job.setFilterquery(query);

    MapReduceOutput output = job.execute();
    List<BasicDBObject> results = (List<BasicDBObject>) output.getCommandResult().get("results");
    Graph g = null;
    if (!results.isEmpty()) {
        BasicDBObject aggregation = (BasicDBObject) results.get(0).get("value");
        long max = aggregation.getLong("max");
        int width = (int) (max / bins);
        Map<String, String> config = new HashMap<String, String>();
        config.put("bin_width", width + "");

        job = new HistogramJob(f.getCollection(), property);
        job.setFilterquery(query);
        job.setConfig(config);
        output = job.execute();
        List<String> keys = new ArrayList<String>();
        List<String> values = new ArrayList<String>();

        calculateNumericHistogramResults(output, keys, values, width);

        g = new Graph(property, keys, values);
    }

    return g;
}

From source file:controllers.FilterController.java

License:Apache License

private static Graph getSquareRootHistogram(Filter f, String property) {
    BasicDBObject query = Application.getFilterQuery(f);
    DBCursor cursor = Configurator.getDefaultConfigurator().getPersistence().find(Constants.TBL_ELEMENTS,
            query);//from www .j a  va2s  .c o m
    int n = cursor.size();
    int bins = (int) Math.sqrt(n);
    MapReduceJob job = new NumericAggregationJob(f.getCollection(), property);
    job.setFilterquery(query);

    MapReduceOutput output = job.execute();
    List<BasicDBObject> results = (List<BasicDBObject>) output.getCommandResult().get("results");
    Graph g = null;
    if (!results.isEmpty()) {
        BasicDBObject aggregation = (BasicDBObject) results.get(0).get("value");
        long max = aggregation.getLong("max");
        int width = (int) (max / bins);
        Map<String, String> config = new HashMap<String, String>();
        config.put("bin_width", width + "");

        job = new HistogramJob(f.getCollection(), property);
        job.setFilterquery(query);
        job.setConfig(config);
        output = job.execute();
        List<String> keys = new ArrayList<String>();
        List<String> values = new ArrayList<String>();

        calculateNumericHistogramResults(output, keys, values, width);

        g = new Graph(property, keys, values);
    }

    return g;
}

From source file:edu.slu.mongoEntity.Agent.java

public Agent(BasicDBObject dbo) {
    this.objectID = dbo.getObjectId("_id").toString();
    this.aID = dbo.getString("@id");
    this.mbox = dbo.getString("mbox");
    this.mbox_sha1sum = dbo.getString("mbox_sha1sum");
    this.type = dbo.getString("type");
    this.created = dbo.getLong("created");
    this.modified = dbo.getLong("modified");
    this.group = JSONArray.fromObject(dbo.get("group"));
    this.personID = dbo.getString("personID");
    this.organization = JSONArray.fromObject(dbo.get("organization"));
}

From source file:edu.slu.mongoEntity.Person.java

public Person(BasicDBObject dbo) {
    this.objectID = dbo.getObjectId("_id").toString();
    this.email = dbo.getString("email");
    this.surname = dbo.getString("surname");
    this.familyname = dbo.getString("familyname");
    this.pwd = dbo.getString("pwd");
    this.aID = dbo.getString("@id");
    this.dateCreated = dbo.getLong("date_created");
    this.dateUpdated = dbo.getLong("date_updated");
}

From source file:edu.slu.mongoEntity.ProjectUserProfile.java

public ProjectUserProfile(BasicDBObject dbo) {
    this.objectID = dbo.getObjectId("_id").toString();
    if (null != dbo.getString("userObjectID")) {
        this.objectID = dbo.getString("userObjectID");
    }// w  w w  .j  a  v a 2 s .com
    if (null != dbo.getString("alias")) {
        this.alias = dbo.getString("alias");
    }
    if (null != dbo.getString("server_ip")) {
        JSONArray ja = (JSONArray) dbo.get("ls_serverIP");
        this.ls_serverIP = ja.subList(0, ja.size() - 1);
    }
    this.dateCreated = dbo.getLong("date_created");
    this.dateUpdated = dbo.getLong("date_updated");
    if (null != dbo.getString("config")) {
        this.config = dbo.getString("config");
    }
}

From source file:entity.Annotation.java

public Annotation(BasicDBObject dbo) {
    this.objectID = dbo.getObjectId("_id").toString();
    this.namespace = dbo.getString("namespace");
    this.content = dbo.getString("content");
    this.selector = dbo.getString("selector");
    this.title = dbo.getString("title");
    this.resource = dbo.getString("resource");
    this.resourceType = dbo.getString("resourceType");
    this.outterRelative = dbo.getString("outterRelative");
    this.addedTime = dbo.getLong("addedTime");
    this.fontColor = dbo.getString("fontColor");
    this.fontType = dbo.getString("fontType");
    this.permission = dbo.getInt("permission");
    this.originalAnnoID = dbo.getString("originalAnnoID");
    this.versionNum = dbo.getInt("versionNum");
    this.forkFromID = dbo.getString("forkFromID");
}

From source file:ezbake.data.mongo.EzMongoHandler.java

License:Apache License

@Override
public long getCountFromQuery(String collectionName, String jsonQuery, EzSecurityToken security)
        throws TException, EzMongoBaseException {
    try {/*from www. ja  v a 2s  .  c om*/
        HashMap<String, String> auditParamsMap = new HashMap<>();
        auditParamsMap.put("action", "getCountFromQuery");
        auditParamsMap.put("collectionName", collectionName);
        auditParamsMap.put("jsonQuery", jsonQuery);
        auditLog(security, AuditEventType.FileObjectAccess, auditParamsMap);

        TokenUtils.validateSecurityToken(security, this.getConfigurationProperties());

        if (StringUtils.isEmpty(collectionName)) {
            throw new EzMongoBaseException("collectionName is required.");
        }

        final DBObject queryCommand = (DBObject) JSON.parse(jsonQuery);

        final DBObject query = new BasicDBObject("$match", queryCommand);

        final String finalCollectionName = getCollectionName(collectionName);

        appLog.info("getCountFromQuery, finalCollectionName: {}, {}", finalCollectionName, jsonQuery);

        final DBObject[] aggregationCommandsArray = mongoFindHelper
                .getFindAggregationCommandsArray_withcounter(0, 0, null, null, security, true, READ_OPERATION);
        final AggregationOutput aggregationOutput = db.getCollection(finalCollectionName).aggregate(query,
                aggregationCommandsArray);

        final BasicDBList resultsList = (BasicDBList) aggregationOutput.getCommandResult().get("result");
        long count = 0;
        if (resultsList.size() > 0) {
            final BasicDBObject resultsObj = (BasicDBObject) resultsList.get(0);
            count = resultsObj.getLong("count");
        }

        return count;
    } catch (final Exception e) {
        throw enrichException("getCountFromQuery", e);
    }
}