コード例 #1
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);
  }
コード例 #2
0
  /**
   * 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;
  }
コード例 #3
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
  }