use of com.hack23.cia.service.api.action.admin.SendEmailRequest in project cia by Hack23.
the class SendEmailServiceITest method sendEmailSuccessTest.
/**
* Test.
*
* @throws Exception
* the exception
*/
@Test
public void sendEmailSuccessTest() throws Exception {
final CreateApplicationSessionRequest createSessionRequest = createTestApplicationSession();
final SendEmailRequest serviceRequest = new SendEmailRequest();
serviceRequest.setSessionId(createSessionRequest.getSessionId());
serviceRequest.setEmail("info@hack23.com");
serviceRequest.setSubject("Test Email SendEmailServiceITest");
serviceRequest.setContent("Test content");
final SendEmailResponse response = (SendEmailResponse) applicationManager.service(serviceRequest);
assertNotNull(EXPECT_A_RESULT, response);
final List<SmtpMessage> emails = dumbster.getReceivedEmails();
assertEquals(1, emails.size());
final SmtpMessage email = emails.get(0);
assertEquals(email.getHeaderValue("Subject"), serviceRequest.getSubject());
assertEquals(email.getBody(), serviceRequest.getContent());
assertEquals(email.getHeaderValue("To"), serviceRequest.getEmail());
}
use of com.hack23.cia.service.api.action.admin.SendEmailRequest in project cia by Hack23.
the class SendEmailClickListener method buttonClick.
@Override
public void buttonClick(final ClickEvent event) {
final ServiceResponse response = ApplicationMangerAccess.getApplicationManager().service(sendEmailRequest);
if (ServiceResult.SUCCESS == response.getResult()) {
LOGGER.info(LOG_MSG_SEND_EMAIL, sendEmailRequest.getEmail());
Notification.show(EMAIL_SENT);
} else {
Notification.show(SEND_EMAIL_FAILEDFAILED, response.getErrorMessage(), Notification.Type.WARNING_MESSAGE);
LOGGER.info(SEND_EMAIL_FAILURE, sendEmailRequest.getEmail());
}
}
use of com.hack23.cia.service.api.action.admin.SendEmailRequest in project cia by Hack23.
the class EmailPageModContentFactoryImpl method createContent.
@Secured({ "ROLE_ADMIN" })
@Override
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
final VerticalLayout content = createPanelContent();
final String pageId = getPageId(parameters);
getMenuItemFactory().createMainPageMenuBar(menuBar);
LabelFactory.createHeader2Label(content, ADMIN_EMAIL);
final VerticalLayout emailLayout = new VerticalLayout();
emailLayout.setSizeFull();
final Panel formPanel = new Panel();
formPanel.setSizeFull();
emailLayout.addComponent(formPanel);
final FormLayout formContent = new FormLayout();
formPanel.setContent(formContent);
final SendEmailRequest sendEmailRequest = new SendEmailRequest();
sendEmailRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
sendEmailRequest.setEmail("");
sendEmailRequest.setSubject("");
sendEmailRequest.setContent("");
final ClickListener sendEmailListener = new SendEmailClickListener(sendEmailRequest);
getFormFactory().addRequestInputFormFields(formContent, sendEmailRequest, SendEmailRequest.class, SEND_EMAIL_REQUEST_FORM_FIELDS, EMAIL, sendEmailListener);
content.addComponent(emailLayout);
content.setExpandRatio(emailLayout, ContentRatio.LARGE_FORM);
panel.setCaption(NAME + "::" + ADMIN_EMAIL);
getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_EMAIL_VIEW, ApplicationEventGroup.ADMIN, NAME, null, pageId);
return content;
}
use of com.hack23.cia.service.api.action.admin.SendEmailRequest in project cia by Hack23.
the class SendEmailService method createApplicationEventForService.
@Override
protected CreateApplicationEventRequest createApplicationEventForService(final SendEmailRequest serviceRequest) {
final CreateApplicationEventRequest eventRequest = new CreateApplicationEventRequest();
eventRequest.setEventGroup(ApplicationEventGroup.ADMIN);
eventRequest.setApplicationOperation(ApplicationOperationType.CREATE);
eventRequest.setActionName(SendEmailRequest.class.getSimpleName());
eventRequest.setSessionId(serviceRequest.getSessionId());
return eventRequest;
}
use of com.hack23.cia.service.api.action.admin.SendEmailRequest in project cia by Hack23.
the class SendEmailService method processService.
@Override
@Secured({ "ROLE_ADMIN" })
public SendEmailResponse processService(final SendEmailRequest serviceRequest) {
final SendEmailResponse inputValidation = inputValidation(serviceRequest);
if (inputValidation != null) {
return inputValidation;
}
final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
final UserAccount userAccount = getUserAccountFromSecurityContext();
if (userAccount != null) {
LOGGER.info("{} started:{}", serviceRequest.getClass().getSimpleName(), userAccount.getEmail());
eventRequest.setUserId(userAccount.getUserId());
}
SendEmailResponse response;
if (isValidEmailAddress(serviceRequest.getEmail())) {
emailService.sendEmail(serviceRequest.getEmail(), serviceRequest.getSubject(), serviceRequest.getContent());
response = new SendEmailResponse(ServiceResult.SUCCESS);
} else {
response = new SendEmailResponse(ServiceResult.FAILURE);
response.setErrorMessage(EMAIL_IS_NOT_A_VALID_EMAIL_ADDRESS);
}
eventRequest.setApplicationMessage(response.getResult().toString());
createApplicationEventService.processService(eventRequest);
return response;
}
Aggregations