Search in sources :

Example 1 with SendEmailRequest

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());
}
Also used : SendEmailResponse(com.hack23.cia.service.api.action.admin.SendEmailResponse) CreateApplicationSessionRequest(com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest) SmtpMessage(com.dumbster.smtp.SmtpMessage) SendEmailRequest(com.hack23.cia.service.api.action.admin.SendEmailRequest) Test(org.junit.Test) AbstractServiceFunctionalIntegrationTest(com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)

Example 2 with SendEmailRequest

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());
    }
}
Also used : ServiceResponse(com.hack23.cia.service.api.action.common.ServiceResponse)

Example 3 with SendEmailRequest

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;
}
Also used : FormLayout(com.vaadin.ui.FormLayout) SendEmailClickListener(com.hack23.cia.web.impl.ui.application.views.pageclicklistener.SendEmailClickListener) Panel(com.vaadin.ui.Panel) VerticalLayout(com.vaadin.ui.VerticalLayout) ClickListener(com.vaadin.ui.Button.ClickListener) SendEmailClickListener(com.hack23.cia.web.impl.ui.application.views.pageclicklistener.SendEmailClickListener) SendEmailRequest(com.hack23.cia.service.api.action.admin.SendEmailRequest) Secured(org.springframework.security.access.annotation.Secured)

Example 4 with SendEmailRequest

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;
}
Also used : CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) SendEmailRequest(com.hack23.cia.service.api.action.admin.SendEmailRequest)

Example 5 with SendEmailRequest

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;
}
Also used : SendEmailResponse(com.hack23.cia.service.api.action.admin.SendEmailResponse) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

SendEmailRequest (com.hack23.cia.service.api.action.admin.SendEmailRequest)4 SendEmailResponse (com.hack23.cia.service.api.action.admin.SendEmailResponse)3 CreateApplicationEventRequest (com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)2 CreateApplicationSessionRequest (com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest)2 AbstractServiceFunctionalIntegrationTest (com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)2 Test (org.junit.Test)2 Secured (org.springframework.security.access.annotation.Secured)2 SmtpMessage (com.dumbster.smtp.SmtpMessage)1 UserAccount (com.hack23.cia.model.internal.application.user.impl.UserAccount)1 ServiceResponse (com.hack23.cia.service.api.action.common.ServiceResponse)1 SendEmailClickListener (com.hack23.cia.web.impl.ui.application.views.pageclicklistener.SendEmailClickListener)1 ClickListener (com.vaadin.ui.Button.ClickListener)1 FormLayout (com.vaadin.ui.FormLayout)1 Panel (com.vaadin.ui.Panel)1 VerticalLayout (com.vaadin.ui.VerticalLayout)1