Exemplo n.º 1
0
 public Message sendTutorShipConfirmedMessage(User sender, User receiver) {
   Message acceptanceMessage = new Message();
   String messageText =
       new StringBuilder()
           .append("Your Tutorship for " + sender.getFirstName() + " was accepted by him!\n")
           .append("This message is auto generated. Do not answer")
           .toString();
   acceptanceMessage.setMessageText(messageText);
   acceptanceMessage.setMessageSubject("Tutorship accepted!");
   acceptanceMessage.setReceiver(receiver);
   acceptanceMessage.setSender(sender);
   return send(acceptanceMessage);
 }
Exemplo n.º 2
0
  public Message sendContactDetails(User sender, User receiver) {
    assert (!sender.equals(receiver));
    Message contactDetails = new Message();

    String allContactInformations =
        new StringBuilder()
            .append("You can contact me as follows: \n")
            .append("<br>Full name: " + sender.getFirstName() + " " + sender.getLastName() + " \n")
            .append("<br>Email: " + sender.getEmail() + " \n")
            .append("<br>This message is auto generated. Do not answer")
            .toString();
    contactDetails.setMessageSubject("Contact Details");
    contactDetails.setMessageText(allContactInformations);
    contactDetails.setReceiver(receiver);
    contactDetails.setSender(sender);
    return send(contactDetails);
  }
  /**
   * Serve model with signupForm.
   *
   * @param principal the logged in principal.
   * @return a signupForm with filled name and biography fields.
   */
  @ModelAttribute("signupForm")
  public SignupForm getSignupForm(Principal principal) {
    User user = userService.getPrincipalUser();

    SignupForm form = new SignupForm();
    form.setFirstName(user.getFirstName());
    form.setLastName(user.getLastName());
    form.setBiography(user.getBiography());

    try {
      AutoPopulatingList<UserCourseFormAttribute> userCourseList =
          new AutoPopulatingList<UserCourseFormAttribute>(new UserCourseFormAttributeFactory());
      Iterator<UserCourse> itr = userCourseDao.findByUser(user).iterator();
      while (itr.hasNext()) {
        UserCourse tmpUserCourse = itr.next();
        UserCourseFormAttribute formAttr = new UserCourseFormAttribute();
        formAttr.setUniversity(tmpUserCourse.getCourse().getSubject().getUniversity().toString());
        formAttr.setSubject(tmpUserCourse.getCourse().getSubject().toString());
        formAttr.setCourse(tmpUserCourse.getCourse().toString());
        formAttr.setGrade(String.valueOf(tmpUserCourse.getGrade()));
        formAttr.setTeaching(tmpUserCourse.isTeaching());
        userCourseList.add(formAttr);
      }
      form.setUserCourseList(userCourseList);
    } catch (Exception e) {
    }

    try {
      AutoPopulatingList<TimeSlot> timeSlotList =
          new AutoPopulatingList<TimeSlot>(new TimeSlotFactory());
      ListIterator<TimeSlot> iter = user.getTimeSlots().listIterator();
      while (iter.hasNext()) {
        timeSlotList.add(iter.next());
      }
      form.setTimeSlots(timeSlotList);
    } catch (Exception e) {
    }

    return form;
  }
Exemplo n.º 4
0
  @Test
  public void testTheBasicUserServiceUserSaving() {
    updatedUser = userService.saveFrom(signupForm);
    Iterator<UserRole> roleItr = updatedUser.getUserRole().iterator();

    assertEquals("Capitain", updatedUser.getFirstName());
    assertEquals("Awesome", updatedUser.getLastName());
    assertEquals("*****@*****.**", updatedUser.getEmail());
    assertEquals("I try to be .......... awesome...", updatedUser.getBiography());

    assertTrue(roleItr.hasNext());
    assertEquals("ROLE_USER", roleItr.next().getRole());
    assertFalse(roleItr.hasNext());

    assertTrue(updatedUser.isEnabled());
    assertTrue(passwordEncoder.matches("123456", updatedUser.getPassword()));

    assertEquals(
        expectedTimeSlotArrayList.toString(),
        updatedUser
            .getTimeSlots()
            .toString()); // don't compare references but string representation
  }
Exemplo n.º 5
0
 public String getMessageReceiverFirstName(String mail) {
   User receiver = userDao.findByEmailLike(mail);
   if (receiver != null) return receiver.getFirstName();
   return null;
 }