Search in sources :

Example 1 with EmailTemplateDTO

use of uk.ac.cam.cl.dtg.isaac.dto.content.EmailTemplateDTO in project isaac-api by isaacphysics.

the class UserAccountManager method sendVerificationEmailsForEmailChange.

/**
 * Sends a notice email for email change to the user's current email address and then creates a copy of the user
 * with the new email to send to the sendVerificationEmailForCurrentEmail method.
 *
 * @param userDTO - initial user where the notice of change is to be sent.
 * @param newEmail - the new email which has been requested to change to.
 * @param newEmailToken - the generated HMAC token for the new email.
 * @throws ContentManagerException - if the email template does not exist.
 * @throws SegueDatabaseException - if there is a database exception during the processing of the email.
 */
private void sendVerificationEmailsForEmailChange(final RegisteredUserDTO userDTO, final String newEmail, final String newEmailToken) throws ContentManagerException, SegueDatabaseException {
    EmailTemplateDTO emailChangeTemplate = emailManager.getEmailTemplateDTO("email-verification-change");
    Map<String, Object> emailTokens = ImmutableMap.of("requestedemail", newEmail);
    log.info(String.format("Sending email for email address change for user (%s)" + " from email (%s) to email (%s)", userDTO.getId(), userDTO.getEmail(), newEmail));
    emailManager.sendTemplatedEmailToUser(userDTO, emailChangeTemplate, emailTokens, EmailType.SYSTEM);
    // Defensive copy to ensure old email address is preserved (shouldn't change until new email is verified)
    RegisteredUserDTO temporaryUser = this.dtoMapper.map(userDTO, RegisteredUserDTO.class);
    temporaryUser.setEmail(newEmail);
    temporaryUser.setEmailVerificationStatus(EmailVerificationStatus.NOT_VERIFIED);
    this.sendVerificationEmailForCurrentEmail(temporaryUser, newEmailToken);
}
Also used : EmailTemplateDTO(uk.ac.cam.cl.dtg.isaac.dto.content.EmailTemplateDTO) RegisteredUserDTO(uk.ac.cam.cl.dtg.isaac.dto.users.RegisteredUserDTO)

Example 2 with EmailTemplateDTO

use of uk.ac.cam.cl.dtg.isaac.dto.content.EmailTemplateDTO in project isaac-api by isaacphysics.

the class UserAccountManager method sendVerificationEmailForCurrentEmail.

/**
 * Sends verification email for the user's current email address. The destination will match the userDTO's email.
 *
 * @param userDTO - user to which the email is to be sent.
 * @param emailVerificationToken - the generated email verification token.
 * @throws ContentManagerException - if the email template does not exist.
 * @throws SegueDatabaseException - if there is a database exception during the processing of the email.
 */
private void sendVerificationEmailForCurrentEmail(final RegisteredUserDTO userDTO, final String emailVerificationToken) throws ContentManagerException, SegueDatabaseException {
    EmailTemplateDTO emailVerificationTemplate = emailManager.getEmailTemplateDTO("email-template-email-verification");
    Map<String, Object> emailTokens = ImmutableMap.of("verificationURL", this.generateEmailVerificationURL(userDTO, emailVerificationToken));
    log.info(String.format("Sending email verification message to %s", userDTO.getEmail()));
    emailManager.sendTemplatedEmailToUser(userDTO, emailVerificationTemplate, emailTokens, EmailType.SYSTEM);
}
Also used : EmailTemplateDTO(uk.ac.cam.cl.dtg.isaac.dto.content.EmailTemplateDTO)

Example 3 with EmailTemplateDTO

use of uk.ac.cam.cl.dtg.isaac.dto.content.EmailTemplateDTO in project isaac-api by isaacphysics.

the class EventBookingManagerTest method requestBooking_checkTeacherAllowedOnStudentEventDespiteCapacityFull_noExceptionThrown.

@Test
public void requestBooking_checkTeacherAllowedOnStudentEventDespiteCapacityFull_noExceptionThrown() throws Exception {
    EventBookingManager ebm = this.buildEventBookingManager();
    IsaacEventPageDTO testEvent = new IsaacEventPageDTO();
    testEvent.setId("someEventId");
    testEvent.setNumberOfPlaces(1);
    testEvent.setTags(ImmutableSet.of("student", "physics"));
    testEvent.setEmailEventDetails("Some Details");
    testEvent.setDate(someFutureDate);
    RegisteredUserDTO someUser = new RegisteredUserDTO();
    someUser.setId(6L);
    someUser.setEmailVerificationStatus(EmailVerificationStatus.VERIFIED);
    someUser.setRole(Role.TEACHER);
    RegisteredUserDTO someStudentUser = new RegisteredUserDTO();
    someStudentUser.setId(1L);
    someStudentUser.setEmailVerificationStatus(EmailVerificationStatus.VERIFIED);
    someStudentUser.setRole(Role.STUDENT);
    EventBookingDTO firstBooking = new EventBookingDTO();
    UserSummaryDTO firstUser = new UserSummaryDTO();
    firstUser.setRole(Role.STUDENT);
    firstUser.setId(someStudentUser.getId());
    firstBooking.setUserBooked(firstUser);
    firstBooking.setBookingStatus(BookingStatus.CONFIRMED);
    Map<BookingStatus, Map<Role, Long>> placesAvailableMap = generatePlacesAvailableMap();
    placesAvailableMap.get(BookingStatus.CONFIRMED).put(Role.STUDENT, 1L);
    expect(dummyEventBookingPersistenceManager.getEventBookingStatusCounts(testEvent.getId(), false)).andReturn(placesAvailableMap).atLeastOnce();
    expect(dummyEventBookingPersistenceManager.getBookingByEventIdAndUserId(testEvent.getId(), someUser.getId())).andReturn(null).once();
    dummyEventBookingPersistenceManager.lockEventUntilTransactionComplete(dummyTransaction, testEvent.getId());
    expectLastCall().once();
    expect(dummyTransactionManager.getTransaction()).andReturn(dummyTransaction).once();
    dummyTransaction.commit();
    expectLastCall().once();
    dummyTransaction.close();
    expectLastCall().once();
    expect(dummyEventBookingPersistenceManager.createBooking(dummyTransaction, testEvent.getId(), someUser.getId(), BookingStatus.CONFIRMED, someAdditionalInformation)).andReturn(firstBooking).atLeastOnce();
    expect(dummyEmailManager.getEmailTemplateDTO("email-event-booking-confirmed")).andReturn(new EmailTemplateDTO()).atLeastOnce();
    dummyEmailManager.sendTemplatedEmailToUser(anyObject(), anyObject(), anyObject(), anyObject(), anyObject());
    expectLastCall().atLeastOnce();
    replay(mockedObjects);
    ebm.requestBooking(testEvent, someUser, someAdditionalInformation);
    verify(mockedObjects);
}
Also used : EmailTemplateDTO(uk.ac.cam.cl.dtg.isaac.dto.content.EmailTemplateDTO) UserSummaryDTO(uk.ac.cam.cl.dtg.isaac.dto.users.UserSummaryDTO) RegisteredUserDTO(uk.ac.cam.cl.dtg.isaac.dto.users.RegisteredUserDTO) IsaacEventPageDTO(uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO) EventBookingDTO(uk.ac.cam.cl.dtg.isaac.dto.eventbookings.EventBookingDTO) DetailedEventBookingDTO(uk.ac.cam.cl.dtg.isaac.dto.eventbookings.DetailedEventBookingDTO) BookingStatus(uk.ac.cam.cl.dtg.isaac.dos.eventbookings.BookingStatus) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 4 with EmailTemplateDTO

use of uk.ac.cam.cl.dtg.isaac.dto.content.EmailTemplateDTO in project isaac-api by isaacphysics.

the class EventBookingManagerTest method requestBooking_cancelledSpaceAndSomeWaitingList_Success.

@Test
public void requestBooking_cancelledSpaceAndSomeWaitingList_Success() throws Exception {
    EventBookingManager ebm = this.buildEventBookingManager();
    IsaacEventPageDTO testEvent = new IsaacEventPageDTO();
    testEvent.setId("someEventId");
    testEvent.setNumberOfPlaces(2);
    testEvent.setTags(ImmutableSet.of("teacher", "physics"));
    testEvent.setEmailEventDetails("Some Details");
    testEvent.setDate(someFutureDate);
    RegisteredUserDTO firstUserFull = new RegisteredUserDTO();
    firstUserFull.setId(6L);
    firstUserFull.setEmailVerificationStatus(EmailVerificationStatus.VERIFIED);
    firstUserFull.setRole(Role.TEACHER);
    DetailedEventBookingDTO firstBooking = new DetailedEventBookingDTO();
    UserSummaryDTO firstUser = new UserSummaryDTO();
    firstUser.setId(firstUserFull.getId());
    firstUser.setRole(Role.TEACHER);
    firstBooking.setUserBooked(firstUser);
    firstBooking.setBookingStatus(BookingStatus.WAITING_LIST);
    EventBookingDTO secondBooking = new EventBookingDTO();
    UserSummaryDTO secondUser = new UserSummaryDTO();
    secondUser.setRole(Role.TEACHER);
    secondUser.setId(7L);
    secondBooking.setUserBooked(firstUser);
    secondBooking.setBookingStatus(BookingStatus.CANCELLED);
    List<EventBookingDTO> currentBookings = Arrays.asList(firstBooking, secondBooking);
    Map<BookingStatus, Map<Role, Long>> placesAvailableMap = generatePlacesAvailableMap();
    placesAvailableMap.get(BookingStatus.CANCELLED).put(Role.TEACHER, 1L);
    placesAvailableMap.get(BookingStatus.WAITING_LIST).put(Role.TEACHER, 1L);
    expect(dummyEventBookingPersistenceManager.getEventBookingStatusCounts(testEvent.getId(), false)).andReturn(placesAvailableMap).atLeastOnce();
    expect(dummyEventBookingPersistenceManager.getBookingByEventIdAndUserId(testEvent.getId(), firstUserFull.getId())).andReturn(firstBooking).once();
    dummyEventBookingPersistenceManager.lockEventUntilTransactionComplete(dummyTransaction, testEvent.getId());
    expectLastCall().once();
    expect(dummyTransactionManager.getTransaction()).andReturn(dummyTransaction).once();
    dummyTransaction.commit();
    expectLastCall().once();
    dummyTransaction.close();
    expectLastCall().once();
    expect(dummyEventBookingPersistenceManager.createBooking(dummyTransaction, testEvent.getId(), firstUserFull.getId(), BookingStatus.CONFIRMED, someAdditionalInformation)).andReturn(secondBooking).atLeastOnce();
    dummyEmailManager.sendTemplatedEmailToUser(anyObject(), anyObject(), anyObject(), anyObject(), anyObject());
    expectLastCall().atLeastOnce();
    expect(dummyEmailManager.getEmailTemplateDTO("email-event-booking-confirmed")).andReturn(new EmailTemplateDTO()).atLeastOnce();
    replay(mockedObjects);
    try {
        ebm.requestBooking(testEvent, firstUserFull, someAdditionalInformation);
    // success
    } catch (EventIsFullException e) {
        fail("Expected successful booking as no waiting list bookings.");
    }
    verify(mockedObjects);
}
Also used : EmailTemplateDTO(uk.ac.cam.cl.dtg.isaac.dto.content.EmailTemplateDTO) UserSummaryDTO(uk.ac.cam.cl.dtg.isaac.dto.users.UserSummaryDTO) RegisteredUserDTO(uk.ac.cam.cl.dtg.isaac.dto.users.RegisteredUserDTO) DetailedEventBookingDTO(uk.ac.cam.cl.dtg.isaac.dto.eventbookings.DetailedEventBookingDTO) IsaacEventPageDTO(uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO) EventBookingDTO(uk.ac.cam.cl.dtg.isaac.dto.eventbookings.EventBookingDTO) DetailedEventBookingDTO(uk.ac.cam.cl.dtg.isaac.dto.eventbookings.DetailedEventBookingDTO) BookingStatus(uk.ac.cam.cl.dtg.isaac.dos.eventbookings.BookingStatus) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 5 with EmailTemplateDTO

use of uk.ac.cam.cl.dtg.isaac.dto.content.EmailTemplateDTO in project isaac-api by isaacphysics.

the class EventBookingManagerTest method requestBooking_userIsAbleToPromoteBookingReservation_Success.

@Test
public void requestBooking_userIsAbleToPromoteBookingReservation_Success() throws Exception {
    EventBookingManager eventBookingManager = this.buildEventBookingManager();
    ReservationTestDefaults testCase = new ReservationTestDefaults();
    testCase.event.setNumberOfPlaces(1);
    RegisteredUserDTO reservedStudent = testCase.student1;
    DetailedEventBookingDTO reservedStudentBooking = new DetailedEventBookingDTO() {

        {
            setEventId(testCase.event.getId());
            setBookingStatus(BookingStatus.RESERVED);
            setUserBooked(new UserSummaryDTO() {

                {
                    setId(reservedStudent.getId());
                }
            });
        }
    };
    DetailedEventBookingDTO reservedStudentBookingAfterConfirmation = new DetailedEventBookingDTO() {

        {
            setEventId(testCase.event.getId());
            setBookingStatus(BookingStatus.CONFIRMED);
            setUserBooked(new UserSummaryDTO() {

                {
                    setId(reservedStudent.getId());
                }
            });
        }
    };
    // Expected external calls
    dummyEventBookingPersistenceManager.lockEventUntilTransactionComplete(dummyTransaction, testCase.event.getId());
    expectLastCall().once();
    expect(dummyTransactionManager.getTransaction()).andReturn(dummyTransaction).once();
    dummyTransaction.commit();
    expectLastCall().once();
    dummyTransaction.close();
    expectLastCall().once();
    expect(dummyEventBookingPersistenceManager.getBookingByEventIdAndUserId(testCase.event.getId(), reservedStudent.getId())).andReturn(reservedStudentBooking).once();
    // As a reserved booking exists, expect an update to the booking
    expect(dummyEventBookingPersistenceManager.updateBookingStatus(eq(dummyTransaction), eq(testCase.event.getId()), eq(reservedStudent.getId()), eq(BookingStatus.CONFIRMED), anyObject())).andReturn(reservedStudentBookingAfterConfirmation).once();
    // Send emails
    EmailTemplateDTO emailTemplate = new EmailTemplateDTO();
    expect(dummyEmailManager.getEmailTemplateDTO("email-event-booking-confirmed")).andReturn(emailTemplate).once();
    dummyEmailManager.sendTemplatedEmailToUser(eq(reservedStudent), eq(emailTemplate), anyObject(), eq(EmailType.SYSTEM), anyObject());
    expectLastCall().once();
    replay(mockedObjects);
    eventBookingManager.requestBooking(testCase.event, reservedStudent, someAdditionalInformation);
    verify(mockedObjects);
}
Also used : EmailTemplateDTO(uk.ac.cam.cl.dtg.isaac.dto.content.EmailTemplateDTO) UserSummaryDTO(uk.ac.cam.cl.dtg.isaac.dto.users.UserSummaryDTO) RegisteredUserDTO(uk.ac.cam.cl.dtg.isaac.dto.users.RegisteredUserDTO) DetailedEventBookingDTO(uk.ac.cam.cl.dtg.isaac.dto.eventbookings.DetailedEventBookingDTO) Test(org.junit.Test)

Aggregations

EmailTemplateDTO (uk.ac.cam.cl.dtg.isaac.dto.content.EmailTemplateDTO)21 Test (org.junit.Test)13 RegisteredUserDTO (uk.ac.cam.cl.dtg.isaac.dto.users.RegisteredUserDTO)12 ContentManagerException (uk.ac.cam.cl.dtg.segue.dao.content.ContentManagerException)10 ContentDTO (uk.ac.cam.cl.dtg.isaac.dto.content.ContentDTO)9 SegueDatabaseException (uk.ac.cam.cl.dtg.segue.dao.SegueDatabaseException)8 ImmutableMap (com.google.common.collect.ImmutableMap)6 Map (java.util.Map)6 DetailedEventBookingDTO (uk.ac.cam.cl.dtg.isaac.dto.eventbookings.DetailedEventBookingDTO)5 UserSummaryDTO (uk.ac.cam.cl.dtg.isaac.dto.users.UserSummaryDTO)5 BookingStatus (uk.ac.cam.cl.dtg.isaac.dos.eventbookings.BookingStatus)4 IsaacEventPageDTO (uk.ac.cam.cl.dtg.isaac.dto.IsaacEventPageDTO)4 EventBookingDTO (uk.ac.cam.cl.dtg.isaac.dto.eventbookings.EventBookingDTO)4 HashMap (java.util.HashMap)3 Properties (java.util.Properties)3 ApiOperation (io.swagger.annotations.ApiOperation)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 GZIP (org.jboss.resteasy.annotations.GZIP)2 UserPreference (uk.ac.cam.cl.dtg.isaac.dos.UserPreference)2