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;
}
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();
}
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());
}
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();
}
Aggregations