Search in sources :

Example 6 with Mail

use of com.artezio.arttime.services.mailing.Mail in project ART-TIME by Artezio.

the class NotificationManagerTest method testNotifyAboutIncorrectTimesheet_oneEmployee.

@Test
public void testNotifyAboutIncorrectTimesheet_oneEmployee() throws Exception {
    setMockServices(notificationManager);
    Employee employee = new Employee("user_name");
    String employeeEmail = "user_name@mail.com";
    employee.setEmail(employeeEmail);
    Period period = mock(Period.class);
    HourType actualTime = new HourType("actual");
    String senderEmail = "sender@mail.com";
    String body = "mail_body";
    String subject = "mail_subject";
    Mail mail = new Mail(subject, body, senderEmail, employeeEmail);
    String applicationBaseUrl = "url";
    Map<String, Object> mailParameters = new HashMap<>();
    mailParameters.put("hourType", actualTime);
    mailParameters.put("period", period);
    mailParameters.put("appHost", applicationBaseUrl);
    expect(hourTypeService.findActualTime()).andReturn(actualTime);
    expect(settings.getSmtpSender()).andReturn(senderEmail);
    expect(settings.getApplicationBaseUrl()).andReturn(applicationBaseUrl);
    expect(mailTemplateManager.getTemplateText(MailTemplate.INCORRECT_TIMESHEET_BODY.getFileName(), mailParameters)).andReturn(body);
    expect(mailTemplateManager.getTemplateText(MailTemplate.INCORRECT_TIMESHEET_SUBJECT.getFileName(), mailParameters)).andReturn(subject);
    mailingEngine.send(mail);
    replay(hourTypeService, settings, mailTemplateManager, mailingEngine);
    notificationManager.notifyAboutIncorrectTimesheet(employee, period);
    verify(hourTypeService, settings, mailTemplateManager, mailingEngine);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Mail(com.artezio.arttime.services.mailing.Mail) HashMap(java.util.HashMap) Period(com.artezio.arttime.datamodel.Period) Test(org.junit.Test)

Example 7 with Mail

use of com.artezio.arttime.services.mailing.Mail in project ART-TIME by Artezio.

the class NotificationManagerTest method testRequestReport.

@Test
public void testRequestReport() throws Exception {
    setMockServices(notificationManager);
    expect(mailTemplateManager.getTemplateText(eq(MailTemplate.REQUEST_REPORT_BODY.getFileName()), anyObject(Map.class))).andReturn("body");
    expect(mailTemplateManager.getTemplateText(eq(MailTemplate.REQUEST_REPORT_SUBJECT.getFileName()), anyObject(Map.class))).andReturn("subject");
    Period period = new Period();
    Employee pm = new Employee("ppetrov");
    pm.setEmail("ppetrov@mail.com");
    mailingEngine.send(new Mail("subject", "body", "ppetrov@mail.com", "iivanov@mail.com"));
    String principalName = "someuser";
    Principal principal = Mockito.mock(Principal.class);
    Mockito.when(principal.getName()).thenReturn(principalName);
    expect(sessionContext.getCallerPrincipal()).andReturn(principal);
    expect(employeeRepository.get(principalName)).andReturn(pm);
    expect(settings.getApplicationBaseUrl()).andReturn("appHost");
    replay(mailTemplateManager, mailingEngine, employeeRepository, settings, sessionContext);
    notificationManager.requestWorkTimeReport("iivanov@mail.com", period);
    verify(mailTemplateManager, mailingEngine);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) Mail(com.artezio.arttime.services.mailing.Mail) Period(com.artezio.arttime.datamodel.Period) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Principal(java.security.Principal) Test(org.junit.Test)

Example 8 with Mail

use of com.artezio.arttime.services.mailing.Mail in project ART-TIME by Artezio.

the class NotificationManager method notificatePmAboutTimeProblems.

protected void notificatePmAboutTimeProblems(List<Employee> employees, Period period, String comment) throws MessagingException {
    List<Project> projects = getProjects(employees);
    Set<Employee> projectManagers = getProjectManagers(projects);
    Map<Employee, Map<Date, BigDecimal>> timeProblems = workTimeService.getApprovedWorkTimeProblems(period, employees);
    HourType actualTime = hourTypeRepository.findActual();
    for (Employee projectManager : projectManagers) {
        Map<String, Object> params = new HashMap<>();
        params.put("recipient", projectManager);
        params.put("hourType", actualTime);
        params.put("period", period);
        params.put("comment", comment);
        Set<SubordinateProblem> subordinateProblems = getSubordinateProblems(projectManager, projects, timeProblems);
        params.put("subordinateProblems", subordinateProblems);
        params.put("appHost", settings.getApplicationBaseUrl());
        params.put("userNames", getSubordinatesAsString(subordinateProblems));
        String body = mailTemplateManager.getTemplateText(MailTemplate.TIME_PROBLEM_BODY_FOR_PM.getFileName(), params);
        String subject = mailTemplateManager.getTemplateText(MailTemplate.TIME_PROBLEM_SUBJECT.getFileName(), params);
        mailingEngine.sendAsync(projectManager.getEmail(), new Mail(subject, body));
    }
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) HashMap(java.util.HashMap) Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Mail(com.artezio.arttime.services.mailing.Mail) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with Mail

use of com.artezio.arttime.services.mailing.Mail in project ART-TIME by Artezio.

the class NotificationManager method notificateAboutOwnTimeProblems.

protected void notificateAboutOwnTimeProblems(List<Employee> employees, Period period, String comment) throws MessagingException {
    Map<Employee, Map<Date, BigDecimal>> timeProblems = workTimeService.getApprovedWorkTimeProblems(period, employees);
    HourType actualTime = hourTypeRepository.findActual();
    for (Employee employee : employees) {
        Map<Date, BigDecimal> approvedWorkTimeProblems = timeProblems.get(employee);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("recipient", employee);
        params.put("hourType", actualTime);
        params.put("deviation", sumDeviation(approvedWorkTimeProblems.values()));
        params.put("period", period);
        params.put("comment", comment);
        params.put("deviationDetails", approvedWorkTimeProblems.entrySet().toArray());
        params.put("appHost", settings.getApplicationBaseUrl());
        String body = mailTemplateManager.getTemplateText(MailTemplate.TIME_PROBLEM_BODY.getFileName(), params);
        String subject = mailTemplateManager.getTemplateText(MailTemplate.TIME_PROBLEM_SUBJECT.getFileName(), params);
        mailingEngine.sendAsync(employee.getEmail(), new Mail(subject, body));
    }
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) HourType(com.artezio.arttime.datamodel.HourType) Mail(com.artezio.arttime.services.mailing.Mail) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Example 10 with Mail

use of com.artezio.arttime.services.mailing.Mail in project ART-TIME by Artezio.

the class NotificationManager method requestReport.

public void requestReport(Employee requester, String recipientEmail, Period period) throws MessagingException {
    Map<String, Object> params = new HashMap<>();
    params.put("period", period);
    params.put("appHost", settings.getApplicationBaseUrl());
    String body = mailTemplateManager.getTemplateText(MailTemplate.REQUEST_REPORT_BODY.getFileName(), params);
    String subject = mailTemplateManager.getTemplateText(MailTemplate.REQUEST_REPORT_SUBJECT.getFileName(), params);
    mailingEngine.send(requester.getEmail(), recipientEmail, new Mail(subject, body));
}
Also used : Mail(com.artezio.arttime.services.mailing.Mail) HashMap(java.util.HashMap)

Aggregations

Mail (com.artezio.arttime.services.mailing.Mail)12 HashMap (java.util.HashMap)12 Employee (com.artezio.arttime.datamodel.Employee)11 Map (java.util.Map)8 Test (org.junit.Test)8 HourType (com.artezio.arttime.datamodel.HourType)7 Period (com.artezio.arttime.datamodel.Period)7 AbstractMap (java.util.AbstractMap)6 TreeMap (java.util.TreeMap)6 Project (com.artezio.arttime.datamodel.Project)4 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Principal (java.security.Principal)2 List (java.util.List)2