ContactFormController extends BasicController { @Override public void event(final UserRequest ureq, final Controller source, final Event event) { if (source == noUsersErrorCtr) { if (event.equals(Event.CANCELLED_EVENT)) { fireEvent(ureq, Event.CANCELLED_EVENT); } else { final int pos = DialogBoxUIFactory.getButtonPos(event); if (pos == 0) { fireEvent(ureq, Event.CANCELLED_EVENT); } } } else if (contactView.is(source)) { if (event == Event.DONE_EVENT) { ContactMessage newContactMessage = createContactMessageFromViewData(); contactUIModel.setContactMessage(newContactMessage); contactUIModel.setAttachements(contactView.getAttachments()); MessageSendStatus sendMessageStatus = contactUIModel.sendCurrentMessageToRecipients(); if (contactView.isTcpFrom()) { sendMessageStatus = contactUIModel.sendCurrentMessageAsCopyToSender(); } MessageSendStatusCode sendMessageStatusCode = sendMessageStatus.getStatusCode(); boolean isAddressFailure = sendMessageStatusCode.isAddressFailedCase(); boolean isSendFailed = sendMessageStatusCode.isSendFailedCase(); boolean isMessageContentProblem = sendMessageStatusCode.isMessageFailedCase(); boolean isWarn = sendMessageStatus.isSeverityWarn(); boolean isError = sendMessageStatus.isSeverityError(); if (isAddressFailure) { showFeedbackToUserAndAddToLogFile(isWarn, isError, sendMessageStatus); } else if (isSendFailed) { showFeedbackToUserAndAddToLogFile(isWarn, isError, sendMessageStatus); fireEvent(ureq, Event.FAILED_EVENT); return; } else if (isMessageContentProblem) { showFeedbackToUserAndAddToLogFile(isWarn, isError, sendMessageStatus); return; } boolean success = sendMessageStatusCode.isSuccessfullSentMails(); contactView.setDisplayOnly(true); if (success) { showInfo("msg.send.ok"); ThreadLocalUserActivityLogger.log(MailLoggingAction.MAIL_SENT, getClass()); fireEvent(ureq, Event.DONE_EVENT); } else { showInfo("error.msg.send.nok"); fireEvent(ureq, Event.FAILED_EVENT); } } else if (event == Event.CANCELLED_EVENT) { fireEvent(ureq, Event.CANCELLED_EVENT); } } } ContactFormController(final UserRequest ureq, final WindowControl windowControl, final boolean useDefaultTitle, final boolean isCanceable,
            final boolean isReadonly, final boolean hasRecipientsEditable, final ContactMessage cmsg);  ContactFormController(final ContactFormView contactFormView, final ContactUIModel contactUIModel); @Override void event(final UserRequest ureq, final Controller source, final Event event); @Override void event(final UserRequest ureq, final Component source, final Event event);  }
@Test public void shouldSendMailToRecipientsAndCopyToSenderWithoutException() { configureViewForSuccessfullSentMessage(); setCopyToSenderCheckbox(true); ContactFormController contactFormController = new ContactFormController(contactFormView, contactUIModel); contactFormController.event(ureq, source, Event.DONE_EVENT); verifySendingToRecipientsAndCopyToSender(); verifySuccessFullSendingInfoMessageSet(); }
@Test public void shouldSendMailToRecipientsOnlyWithoutException() { configureViewForSuccessfullSentMessage(); setCopyToSenderCheckbox(false); ContactFormController contactFormController = new ContactFormController(contactFormView, contactUIModel); contactFormController.event(ureq, source, Event.DONE_EVENT); verifySendingToRecipientsOnly(); verifySuccessFullSendingInfoMessageSet(); }