public static void showUpcomingBirthdays(Long id) { User current = User.findById(id); Date today = new Date(); int day = today.getDate(); Date weekLater = new Date(); weekLater.setDate(day + 7); Date almostWeekLater = new Date(); almostWeekLater.setDate(day + 6); List<Relationship> friends = current.confirmedFriends(); List<User> birthdayPeople = new ArrayList<User>(); for (Relationship x : friends) { Date friendBirthday = x.to.getProfile().birthday; if (friendBirthday == null) // The user's friend did not set a birthday date field { // x.to.getProfile().birthday = almostWeekLater; // friendBirthday = almostWeekLater; continue; } friendBirthday.setYear(today.getYear()); if (friendBirthday.before(weekLater)) birthdayPeople.add(x.to); } render(birthdayPeople, today, weekLater, almostWeekLater, day); }
public static void initFriends() { List<User> users = User.findAll(); for (User u : users) { u.friends.add(u); u.save(); } User bob = User.findById(2L); User alice = User.findById(3L); User jeff = User.findById(4L); bob.friends.add(jeff); alice.friends.add(jeff); jeff.friends.add(bob); jeff.friends.add(alice); jeff.save(); }
public static void projects() { Long id = Long.parseLong(Session.current().get("user_id")); User u = User.findById(id); List<Project> projects = Project.find("owner = ?", u).fetch(); render(projects); }
public static Result nutritionSchedule() { TDEERule tdeeRule = new TDEERule(); CalEatingRule calEatingRule = new CalEatingRule(); NutritionRule nuRule = new NutritionRule(); MeatRule meatRule = new MeatRule(); VegetableRule vegetableRule = new VegetableRule(); DrinkRule drinkRule = new DrinkRule(); User thisUser = User.findById(Long.parseLong(session("userId"))); double weight = thisUser.getWeight(); boolean isGain = thisUser.isGain(); double height = thisUser.getHeight(); if (weight == 0 || height == 0) { flash("error", "Please fill your information."); return redirect(routes.Profile.index()); } nuRule.setInput(weight, isGain); RulesEngine rulesEngine = aNewRulesEngine().withSilentMode(true).build(); rulesEngine.registerRule(nuRule); meatRule.setInput(true); vegetableRule.setInput(true); drinkRule.setInput(true); rulesEngine.registerRule(meatRule); rulesEngine.registerRule(vegetableRule); rulesEngine.registerRule(drinkRule); rulesEngine.fireRules(); List<Nutrition> nuList = nuRule.getResult(); List<RawMaterial> meatList = meatRule.getResult().getAll(); List<RawMaterial> vetList = vegetableRule.getResult().getAll(); List<RawMaterial> drinkList = drinkRule.getResult().getAll(); List<RawMaterial> rawMaterialList = new ArrayList<RawMaterial>(meatList); rawMaterialList.addAll(vetList); rawMaterialList.addAll(drinkList); List<String> tdees = new ArrayList<String>(); List<String> eatingCals = new ArrayList<String>(); RulesEngine rulesEngine_tdee = aNewRulesEngine().withSilentMode(true).build(); RulesEngine rulesEngine_cal = aNewRulesEngine().withSilentMode(true).build(); rulesEngine_tdee.registerRule(tdeeRule); rulesEngine_cal.registerRule(calEatingRule); for (int i = 0; i < 5; i++) { tdeeRule.setInput(weight, height, thisUser.getGender(), thisUser.getAge(), 1.2 + (i * 0.2)); rulesEngine_tdee.fireRules(); tdees.add(tdeeRule.getResult()); calEatingRule.setInput(Double.parseDouble(tdees.get(i)), isGain); rulesEngine_cal.fireRules(); eatingCals.add(calEatingRule.getResult()); } return ok(nutrition_schedule.render(nuList, rawMaterialList, tdees, eatingCals)); }
public static void ajaxEditDocument(Long documentId, String newTitle, String newContent) { Document document = Document.findById(documentId); document.changeSubject(newTitle); Config config = Config.getInstance(); User currentUser = User.findById(config.getSingedInUserId()); Version newVersion = new Version(currentUser, document, newContent).save(); System.out.println("* A new version is successfully created."); document.addVersion(newVersion); document.save(); }
public static void project(Long id) { Project project = Project.findById(id); Long UID = Long.parseLong(Session.current().get("user_id")); User u = User.findById(UID); if (project.canBeSeenBy(u)) { render(project); } else { projects(); } }
public static void createproject(String projectname, String projectdescription) { if (projectname != null && projectdescription != null) { Long id = Long.parseLong(Session.current().get("user_id")); User u = User.findById(id); Project p = new Project(projectname, projectdescription, u); p.save(); projects(); } else { render(); } }
/* * Create a document and save using Ajax */ public static void ajaxCreateDocument(String subject, String content, Long parentId) { /* * Create a document and save * Create first version of the document * Create permalink of that version */ // By creating a document, I assume that the document is created by the // program, and versions in the document are created by users // Create a new document for current user, current user is defined in Config Document document = new Document(subject, parentId).save(); System.out.println("* A new document is successfully created."); Config config = Config.getInstance(); User currentUser = User.findById(config.getSingedInUserId()); Version aversion = new Version(currentUser, document, content).save(); System.out.println("* A new version is successfully created."); document.addVersion(aversion); Documents.ajaxAllDocuments(); }
public static Result workoutSchedule() { ExerciseScheduleRule exSchRule = new ExerciseScheduleRule(); CardioRule caRule = new CardioRule(); User thisUser = User.findById(Long.parseLong(session("userId"))); int userWorkoutDays = thisUser.getUserWorkoutDays(); int age = thisUser.getAge(); boolean workoutIsIntense = thisUser.isWorkoutIsIntense(); boolean cardioIsIntense = thisUser.isCardioIsIntense(); String gender = thisUser.getGender(); if (userWorkoutDays == 0) { flash("error", "Please setting your plan."); return redirect(routes.Profile.index()); } exSchRule.setInput(userWorkoutDays, false, gender); caRule.setInput(age, false); RulesEngine rulesEngine = aNewRulesEngine().withSilentMode(true).build(); rulesEngine.registerRule(exSchRule); rulesEngine.registerRule(caRule); rulesEngine.fireRules(); List<Day> workoutScheduleList = exSchRule.getResult(); List<Cardio> cardiotScheduleList = caRule.getResult(); exSchRule.setInput(userWorkoutDays, true, gender); caRule.setInput(age, true); rulesEngine = aNewRulesEngine().withSilentMode(true).build(); rulesEngine.registerRule(exSchRule); rulesEngine.registerRule(caRule); rulesEngine.fireRules(); List<Day> workoutScheduleIntenseList = exSchRule.getResult(); List<Cardio> cardiotScheduleIntenseList = caRule.getResult(); return ok( workout_schedule.render( workoutScheduleList, cardiotScheduleList, cardioIsIntense, workoutScheduleIntenseList, cardiotScheduleIntenseList, thisUser.isGain())); }
public static User connectedUser() { String userId = session.get("logged"); return userId == null ? null : (User) User.findById(Long.parseLong(userId)); }