@Override public void deleteCarouselImage(Long id) throws NotFoundException { // We use explicit transactions, since we are going to execute more than // 1 query in the same transaction Ebean.beginTransaction(); try { // We see if the carouselImage really exists if (finder.byId(id) == null) throw new NotFoundException("La imagen no existe asi que no se puede borrar"); // We delete it finder.byId(id).delete(); // Now we need to reorder all the carouselImages for (CarouselImage ci : finder.orderBy("id").findList()) { if (ci.getId() > id) { // We insert a copy of the ci in the previous position CarouselImage ciCopy = (CarouselImage) ci._ebean_createCopy(); ciCopy.setId(ci.getId() - 1); ciCopy.save(); // Then we delete the ci ci.delete(); } } Ebean.commitTransaction(); } finally { Ebean.endTransaction(); } }
@Override public CarouselImage findCarouselImage(Long id) throws NotFoundException { CarouselImage ci = finder.byId(id); if (ci == null) throw new NotFoundException("La imagen no existe"); return ci; }
@Override public void addCarouselImage(CarouselImage carouselImage) { // We use explicit transactions, since we are going to execute more than // 1 query in the same transaction Ebean.beginTransaction(); try { // We set atomatically the caroueselImage id, in order to be the // first one carouselImage.setId((long) 1); List<CarouselImage> carouselImages = finder.orderBy().desc("id").findList(); for (CarouselImage ci : carouselImages) { // We insert a copy of the ci in the next position CarouselImage ciCopy = (CarouselImage) ci._ebean_createCopy(); ciCopy.setId(ci.getId() + 1); ciCopy.save(); // Then we delete the ci ci.delete(); } // Then we save carouselImage.save(); Ebean.commitTransaction(); } finally { Ebean.endTransaction(); } }
public static List<Proxy> allProxies() { List<Proxy> proxies = new ArrayList<Proxy>(); List<Choco> chocos = find.all(); for (Choco choco : chocos) { proxies.add(choco.toProxy()); } return proxies; }
/** Verifica se inicializa a lista de usuários. */ @Test public void test() { // O usuário 'usuario' não está cadastrado inicialmente CadastroDeUsuario c = new CadastroDeUsuario(); assertFalse(c.existeUsuario("usuario")); // Confirma que não há usuários cadastrados Finder<Long, Usuario> find = new Finder<Long, Usuario>(Long.class, Usuario.class); assertTrue(find.all() == null || find.all().size() == 0); // Inicializa, e confirma que 'usuario' foi cadastrado InicializadorDeUsuarios i = new InicializadorDeUsuarios(); i.inicializarUsuarios(); assertTrue(c.existeUsuario("usuario")); // Confirma que há 30 ou mais usuários cadastrados assertTrue(find.all().size() >= 30); }
@Security.Authenticated(RestaurantFilter.class) public static Result restaurant(String email) { List<Restaurant> restaurants = findR.all(); User u = User.find(email); List<Meal> meals = Meal.allById(u); Restaurant restaurant = u.restaurant; List<TransactionU> tobeapproved = restaurant.toBeApproved; return ok( views.html.restaurant.restaurantOwner.render( email, meals, restaurant, restaurants, tobeapproved)); }
public static List<Choco> getByIds(List<Long> ids) { StringBuffer strIds = new StringBuffer(); Iterator<Long> IterIds = ids.iterator(); strIds.append("("); while (IterIds.hasNext()) { Long id = IterIds.next(); strIds.append(id); if (IterIds.hasNext()) strIds.append(","); } strIds.append(")"); return find.where("id IN " + strIds).findList(); }
/** * Method to create meal. Use Meal.create method from models. * * @return */ @Security.Authenticated(RestaurantFilter.class) public static Result createMeal() { User u = Session.getCurrentUser(ctx()); if (!u.role.equalsIgnoreCase("RESTAURANT")) { return ok(views.html.admin.wrong.render("Cannot create meal if you're not reastaurant! ")); } String mealName = inputForm.bindFromRequest().field("name").value(); String mealPrice = inputForm.bindFromRequest().field("price").value(); String mealCategory = inputForm.bindFromRequest().field("category").value(); String mealDescription = inputForm.bindFromRequest().field("description").value(); mealPrice = mealPrice.replace(',', '.'); Double price = Double.parseDouble(mealPrice); Restaurant currentUser = u.restaurant; if ((Meal.create(mealName, price, mealCategory, currentUser, mealDescription)) == true) { Meal m = findM .where() .eq("name", mealName) .eq("price", mealPrice) .eq("restaurant_id", u.restaurant.id) .findUnique(); String userEmail = Session.getCurrentUser(ctx()).email; Logger.debug(m.name); session("email", userEmail); flash("successMeal", "Succesfully created meal!"); Logger.info("Restaurant " + currentUser.name + " just created meal"); return ok( views.html.restaurant.fileUploadMeal.render("", userEmail, m, Restaurant.all(), m.image)); // return redirect("/restaurantOwner/" + userEmail); } Logger.error("Restaurant " + currentUser.name + " failed to create meal."); return TODO; }
public static Boolean delete(Long id) { find.ref(id).delete(); Logger.debug("Choco DELETE : " + id); return find.ref(id) == null; }
public static List<Choco> all() { return find.all(); }
public static int count() { int size = find.all().size(); return size; }
public static List<Choco> rows(int rowId, int nbElemByRow) { Logger.debug("ChocoServices rows : " + find.all().size()); Page<Choco> chocos = find.where().findPagingList(nbElemByRow).getPage(rowId); return chocos.getList(); }
public static Choco getById(Long id) { return find.byId(id); }
@Override public List<CarouselImage> findAllCarouselImage() { return finder.orderBy("id").findList(); }