Search in sources :

Example 1 with ControllerCounter

use of org.springframework.data.document.analytics.ControllerCounter in project spring-data-document-examples by spring-projects.

the class ChartController method getControllerData.

private DefaultCategoryDataset getControllerData(String controllerName) {
    MongoTemplate mongoTemplate;
    DefaultCategoryDataset ds = null;
    try {
        Mongo m = new Mongo();
        mongoTemplate = new MongoTemplate(m, "mvc");
        List<ControllerCounter> counters;
        ds = new DefaultCategoryDataset();
        if (controllerName != null) {
            counters = mongoTemplate.find(new Query(where("name").is(controllerName)), ControllerCounter.class, "counters");
            for (ControllerCounter controllerCounter : counters) {
                Map<String, Double> methodInvocations = controllerCounter.getMethods();
                Set<Entry<String, Double>> es = methodInvocations.entrySet();
                for (Entry<String, Double> entry : es) {
                    ds.addValue(entry.getValue(), "invoked", entry.getKey());
                }
            }
        } else {
            counters = mongoTemplate.findAll(ControllerCounter.class, "counters");
            for (ControllerCounter controllerCounter : counters) {
                ds.addValue(controllerCounter.getCount(), "invoked (aggregate)", controllerCounter.getName());
            }
        }
        /*
			if (result instanceof BasicDBList) {
				BasicDBList dbList = (BasicDBList) result;
				for (Iterator iterator = dbList.iterator(); iterator.hasNext();) {
					DBObject dbo = (DBObject) iterator.next();
					System.out.println(dbo);
					Restaurant r = restaurantDao.findRestaurant(Long.parseLong(dbo.get("parameters.p1").toString()));
					ds.addValue(Double.parseDouble(dbo.get("count").toString()), "recommended", r.getName());
				}
			}*/
        return ds;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return ds;
}
Also used : Query(org.springframework.data.document.mongodb.query.Query) Mongo(com.mongodb.Mongo) ControllerCounter(org.springframework.data.document.analytics.ControllerCounter) MongoTemplate(org.springframework.data.document.mongodb.MongoTemplate) Entry(java.util.Map.Entry) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Example 2 with ControllerCounter

use of org.springframework.data.document.analytics.ControllerCounter in project spring-data-document-examples by spring-projects.

the class MvcAnalyticsTest method queryCounterData.

@Test
public void queryCounterData() {
    DBObject query = QueryBuilder.start("name").is("SignUpController").get();
    for (DBObject dbo : operations.getCollection("counters").find(query)) {
        System.out.println(dbo);
    }
    List<ControllerCounter> counters = operations.find(new BasicQuery("{ 'name' : 'SignUpController'} "), ControllerCounter.class, "counters");
    for (ControllerCounter controllerCounter : counters) {
        System.out.println(controllerCounter);
    }
}
Also used : BasicQuery(org.springframework.data.document.mongodb.query.BasicQuery) ControllerCounter(org.springframework.data.document.analytics.ControllerCounter) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Aggregations

ControllerCounter (org.springframework.data.document.analytics.ControllerCounter)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 Mongo (com.mongodb.Mongo)1 Entry (java.util.Map.Entry)1 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)1 Test (org.junit.Test)1 MongoTemplate (org.springframework.data.document.mongodb.MongoTemplate)1 BasicQuery (org.springframework.data.document.mongodb.query.BasicQuery)1 Query (org.springframework.data.document.mongodb.query.Query)1