Search in sources :

Example 1 with Restaurant

use of com.springone.myrestaurants.domain.Restaurant in project spring-data-document-examples by spring-projects.

the class ChartController method getFavoritesData.

private DefaultCategoryDataset getFavoritesData() {
    MongoTemplate mongoTemplate;
    DefaultCategoryDataset ds = null;
    try {
        Mongo m = new Mongo();
        mongoTemplate = new MongoTemplate(m, "mvc");
        DBObject result = getTopRecommendedRestaurants(mongoTemplate);
        /* Example data.
			 * [ { "parameters.p1" : "1" , "count" : 5.0} , 
			 *   { "parameters.p1" : "2" , "count" : 6.0} , 
			 *   { "parameters.p1" : "3" , "count" : 3.0} , 
			 *   { "parameters.p1" : "4" , "count" : 8.0}]
			 */
        ds = new DefaultCategoryDataset();
        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 : BasicDBList(com.mongodb.BasicDBList) Restaurant(com.springone.myrestaurants.domain.Restaurant) Mongo(com.mongodb.Mongo) Iterator(java.util.Iterator) MongoTemplate(org.springframework.data.document.mongodb.MongoTemplate) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 2 with Restaurant

use of com.springone.myrestaurants.domain.Restaurant in project spring-data-document-examples by spring-projects.

the class RestaurantController method addFavoriteRestaurant.

@RequestMapping(value = "/{id}/{userId}", params = "favorite", method = RequestMethod.PUT)
public String addFavoriteRestaurant(@PathVariable("id") String id, @PathVariable("userId") String userId, Model model) {
    Restaurant restaurant = this.restaurantDao.findRestaurant(id);
    //TODO will always return demo user.
    UserAccount account = this.userAccountDao.findUserAccount(314L);
    account.getFavorites().add(restaurant.getId());
    this.userAccountDao.persist(account);
    addDateTimeFormatPatterns(model);
    model.addAttribute("useraccount", account);
    model.addAttribute("itemId", id);
    //TODO converted to return 'getUserName' instead of 'getId'
    return "redirect:/useraccounts/" + account.getUserName();
}
Also used : Restaurant(com.springone.myrestaurants.domain.Restaurant) UserAccount(com.springone.myrestaurants.domain.UserAccount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Restaurant

use of com.springone.myrestaurants.domain.Restaurant in project spring-data-document-examples by spring-projects.

the class RestaurantDaoTests method readRestaurants.

@Test
public void readRestaurants() {
    //List<Restaurant> response = (List<Restaurant>) restTemplate.getForObject("http://localhost:5984/spring_demo/_design/demo/_view/all", Restaurant.class);
    List<Restaurant> response = restaurantDao.findAllRestaurants();
    Assert.assertEquals(50, response.size());
    System.out.println(response.get(0));
    Restaurant r = restaurantDao.findRestaurant(response.get(0).getId());
    Assert.assertNotNull(r);
    System.out.println(r);
    response = restaurantDao.findRestaurantEntries(1, 10);
    //TODO does not respect limits..
    Assert.assertEquals(50, response.size());
}
Also used : Restaurant(com.springone.myrestaurants.domain.Restaurant) Test(org.junit.Test)

Example 4 with Restaurant

use of com.springone.myrestaurants.domain.Restaurant in project spring-data-document-examples by spring-projects.

the class RestaurantController method addFavoriteRestaurant.

@RequestMapping(value = "/{id}/{userId}", params = "favorite", method = RequestMethod.PUT)
public String addFavoriteRestaurant(@PathVariable("id") Long id, @PathVariable("userId") Long userId, Model model) {
    Restaurant restaurant = this.restaurantDao.findRestaurant(id);
    UserAccount account = this.userAccountDao.findUserAccount(userId);
    account.getFavorites().add(restaurant);
    this.userAccountDao.persist(account);
    addDateTimeFormatPatterns(model);
    model.addAttribute("useraccount", account);
    model.addAttribute("itemId", id);
    return "redirect:/useraccounts/" + account.getId();
}
Also used : Restaurant(com.springone.myrestaurants.domain.Restaurant) UserAccount(com.springone.myrestaurants.domain.UserAccount) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Restaurant (com.springone.myrestaurants.domain.Restaurant)4 UserAccount (com.springone.myrestaurants.domain.UserAccount)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 BasicDBList (com.mongodb.BasicDBList)1 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 Mongo (com.mongodb.Mongo)1 Iterator (java.util.Iterator)1 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)1 Test (org.junit.Test)1 MongoTemplate (org.springframework.data.document.mongodb.MongoTemplate)1