/**
   * Method to delete meal by using meal ID which is unique for each meal.
   *
   * @return
   */
  @Security.Authenticated(RestaurantFilter.class)
  public static Result deleteMeal(int id) {
    Meal m = Meal.find(id);
    Restaurant r = m.restaurant;

    m.restaurant = null;
    List<Meal> rMeals = r.meals;
    Iterator<Meal> it = rMeals.iterator();

    while (it.hasNext()) {
      int index = 0;
      Meal current = it.next();
      if (current.id == id) {
        rMeals.remove(index);
        break;
      }
      index++;
    }
    try {
      Meal.delete(m);
      Logger.info("Restaurant " + r.name + " just deleted meal.");
      flash("deletedMeal", "You have successfully deleted your meal");
    } catch (Exception e) {
      Logger.info("Restaurant " + r.name + " just failed to delete meal.");
    }
    return redirect("/restaurantOwner/" + Session.getCurrentUser(ctx()).email);
  }
Exemple #2
0
 @Override
 public String toString() {
   String rtn = "~* Name: " + name + ", Place: " + place + " *~";
   for (int i = 0; i < meals.length; i++) {
     rtn += "\n" + DayOfWeek.values()[i];
     for (Meal m : meals[i]) rtn += "\n" + m.toString();
   }
   return rtn;
 }
 public static void main(String[] args) {
   Meal meal1 = new HamburgerMeal();
   System.out.println("HAMBURGER MEAL:");
   meal1.doMeal();
   System.out.println("");
   Meal meal2 = new CheeseBurgerMeal();
   System.out.println("CHEESE BURGER MEAL:");
   meal2.doMeal();
 }
 public void deleteMeal(String id) {
   Meal meal = getMealWithId(id);
   File file = new File(meal.getPathToPic());
   if (file.exists()) file.delete();
   for (Ingredient i : meal.getIngredientList()) {
     deleteIngredient(i);
   }
   mDatabase.delete(
       DbSchema.MealTable.NAME, DbSchema.MealTable.Cols.MEAL_ID + " = " + "\"" + id + "\"", null);
   return;
 }
 @Security.Authenticated(RestaurantFilter.class)
 public static Result editMealURL(int id) {
   String userEmail = Session.getCurrentUser(ctx()).email;
   Meal oldMeal = Meal.find(id);
   User user = Session.getCurrentUser(ctx());
   Restaurant restaurant = user.restaurant;
   return ok(views.html.restaurant.restaurantOwnerEditMeal.render(oldMeal, userEmail, restaurant));
 }
  /**
   * scans textfile and returns and ArrayList of Meals
   *
   * @param path - path of the textfile
   * @return ArrayList of Meals
   */
  public ArrayList<Meal> loadMeal(String path) {
    // ArrayList<Meal> mealList = new ArrayList<Meal>();
    File file = new File(path);

    try {
      Scanner in = new Scanner(file);
      while (in.hasNext()) {
        String line = in.nextLine();
        String[] m = line.split(",");
        Boolean courseExists = false;
        Boolean mealExists = false;

        if (m.length == 3) {
          m[0] = m[0].toLowerCase().trim();
          m[1] = m[1].toLowerCase().trim();
          int order = Integer.parseInt(m[2].trim());

          // check if course exists

          for (Course course : courseList) {
            if (course.getName().equals(m[0])) {
              for (Meal meal : mealList) {
                if (meal.course.getName().equals(m[0])
                    && meal.getOrder() == order
                    && meal.getMealType().equals(m[1])) {
                  System.out.println(meal.course.getName() + " restriction already exist");
                  mealExists = true;
                  break;
                }
              }

              System.out.println("!");
              courseExists = true;
              // if(doesMealExists(m[1],course)){
              //	System.out.println(m[1]+" is "+m[0]);
              // }
              if (!mealExists) {
                Meal meal = new Meal();
                meal.setMealType(m[1]);
                meal.addCourse(course);
                meal.setOrder(order);

                mealList.add(meal);
              }
              break;
            }
          }
          if (!courseExists) {
            System.out.println("the course: " + m[0] + " doesnt exist");
          }
        }
      }

      in.close();
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return mealList;
  }
 private Meal getMealWithCursor(Cursor c) {
   Meal meal = new Meal();
   meal.setId(c.getString(c.getColumnIndex(DbSchema.MealTable.Cols.MEAL_ID)));
   meal.setName(c.getString(c.getColumnIndex(DbSchema.MealTable.Cols.NAME)));
   meal.setRecipe(c.getString(c.getColumnIndex(DbSchema.MealTable.Cols.RECIPE)));
   meal.setPathToPic(c.getString(c.getColumnIndex(DbSchema.MealTable.Cols.PIC_PATH)));
   meal.setIngredientList(getIngredientsForMeal(meal.getId()));
   return meal;
 }
  @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 Result editMeal(int id) {

    String userEmail = Session.getCurrentUser(ctx()).email;

    Meal oldMeal = Meal.find(id);

    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);

    try {
      Meal.modifyMeal(oldMeal, mealName, price, mealCategory, mealDescription);
      flash("successEdited", "You have successfully edited your meal");
      Logger.info("User " + userEmail + " just edited meal " + oldMeal.id);
    } catch (Exception e) {
      Logger.error("User " + userEmail + " failed to edit meal " + oldMeal.id);
    }
    return redirect("/restaurantOwner/" + userEmail);
  }
  /**
   * 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;
  }
 @Override
 public void buildSide() {
   meal.setSide("McFlurry");
 }
Exemple #12
0
 /**
  * 非蔬果餐(鸡肉汉堡+百事可乐)
  *
  * @return
  */
 public Meal prepareNonVegMeal() {
   Meal meal = new Meal();
   meal.addItem(new ChickenBurger());
   meal.addItem(new Pepsi());
   return meal;
 }
Exemple #13
0
 /**
  * 蔬果餐(蔬菜汉堡+可口可乐)
  *
  * @return
  */
 public Meal prepareVegMeal() {
   Meal meal = new Meal();
   meal.addItem(new VegBurger());
   meal.addItem(new Coke());
   return meal;
 }
 /**
  * Return the weight <i>(in grams)</i> of simple carbohydrate that can be consumed by the patient.
  *
  * @param meal, The meal to compute simple carbohydrate.
  * @return The weight <i>(in grams)</i> of simple carbohydrate that can be consumed by the
  *     patient.
  */
 public double getSimpleCarbohydrate(Meal meal) {
   return energyNeeds * meal.getPercentageOfNRJNeeds() * carbohydratePercentage * 0.45 / 17.0;
 }
 /**
  * Return the weight <i>(in grams)</i> of vegetable lipid that can be consumed by the patient.
  *
  * @param meal, The meal to compute vegetable lipid.
  * @return The weight <i>(in grams)</i> of vegetable lipid that can be consumed by the patient.
  */
 public double getVegetableLipidInGrams(Meal meal) {
   return (energyNeeds * meal.getPercentageOfNRJNeeds() * lipidPercentage / 2.0) / 38.0;
 }
 /**
  * Return the weight <i>(in grams)</i> of vegetable proteins that can be consumed by the patient.
  *
  * @param meal, The meal to compute vegetable proteins.
  * @return The weight <i>(in grams)</i> of animal proteins that can be consumed by the patient.
  */
 public double getVegetableProteinsInGrams(Meal meal) {
   return (energyNeeds * meal.getPercentageOfNRJNeeds() * proteinPercentage / 2.0) / 17.0;
 }
 @Override
 public void buildMainCourse() {
   meal.setMainCourse("Large Big Mac");
 }
 @Override
 public void buildDrink() {
   meal.setDrink("Coke");
 }