Search in sources :

Example 1 with Mail

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

the class TeamSynchronizer method notifyPM.

protected void notifyPM(Project project, List<Employee> closedEmployees, List<Employee> newEmployees) throws MessagingException {
    Map<String, Object> params = new HashMap<>();
    params.put("managedProject", project);
    params.put("newEmployees", newEmployees);
    params.put("closedEmployees", closedEmployees);
    params.put("appUrl", settings.getApplicationBaseUrl());
    String body = mailTemplateManager.getTemplateText(MailTemplate.TEAM_SYNCHRONIZATION_BODY.getFileName(), params);
    String subject = mailTemplateManager.getTemplateText(MailTemplate.TEAM_SYNCHRONIZATION_SUBJECT.getFileName(), params);
    Mail mail = new Mail(subject, body);
    for (Employee manager : project.getManagers()) {
        mailingEngine.send(manager.getEmail(), mail);
    }
}
Also used : Mail(com.artezio.arttime.services.mailing.Mail) Employee(com.artezio.arttime.datamodel.Employee) HashMap(java.util.HashMap)

Example 2 with Mail

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

the class NotificationManagerTest method testNotificatePmAboutTimeProblems.

@Test
public void testNotificatePmAboutTimeProblems() throws MessagingException, NoSuchFieldException {
    notificationManager = createMockBuilder(NotificationManager.class).addMockedMethod("getProjects", List.class).addMockedMethod("getProjectManagers", Collection.class).createMock();
    setMockServices(notificationManager);
    Employee employee = new Employee("iivanov");
    Employee pm = new Employee("ppetrov");
    pm.setEmail("ppetrov@mail.com");
    Project project = createProject(1L, employee);
    List<Employee> employees = Arrays.asList(employee);
    List<Project> projects = Arrays.asList(project);
    Map<Employee, Map<Date, BigDecimal>> timeProblems = new HashMap<Employee, Map<Date, BigDecimal>>();
    timeProblems.put(employee, new HashMap<Date, BigDecimal>());
    Period period = new Period();
    String comment = "comment";
    String subject = "subject";
    String body = "body";
    expect(notificationManager.getProjects(employees)).andReturn(projects);
    expect(notificationManager.getProjectManagers(projects)).andReturn(Sets.newHashSet(pm));
    expect(hourTypeRepository.findActual()).andReturn(new HourType());
    expect(workTimeService.getApprovedWorkTimeProblems(period, employees)).andReturn(timeProblems);
    expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_BODY_FOR_PM.getFileName()), anyObject(Map.class))).andReturn(body);
    expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_SUBJECT.getFileName()), anyObject(Map.class))).andReturn(subject);
    mailingEngine.sendAsync("ppetrov@mail.com", new Mail(subject, body));
    replay(notificationManager, hourTypeRepository, workTimeService, mailTemplateManager, mailingEngine);
    notificationManager.notificatePmAboutTimeProblems(employees, period, comment);
    verify(notificationManager, hourTypeRepository, workTimeService, mailTemplateManager, mailingEngine);
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) HashMap(java.util.HashMap) Period(com.artezio.arttime.datamodel.Period) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Mail(com.artezio.arttime.services.mailing.Mail) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 3 with Mail

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

the class NotificationManagerTest method testNotificateAboutOwnTimeProblems.

@Test
public void testNotificateAboutOwnTimeProblems() throws MessagingException, NoSuchFieldException {
    setMockServices(notificationManager);
    Employee employee = new Employee("iivanov");
    employee.setEmail("iivanov@mail.com");
    List<Employee> employees = Arrays.asList(employee);
    Map<Employee, Map<Date, BigDecimal>> timeProblems = new HashMap<Employee, Map<Date, BigDecimal>>();
    timeProblems.put(employee, new HashMap<Date, BigDecimal>());
    Period period = new Period();
    String comment = "comment";
    String subject = "subject";
    String body = "body";
    expect(hourTypeRepository.findActual()).andReturn(new HourType());
    expect(workTimeService.getApprovedWorkTimeProblems(period, employees)).andReturn(timeProblems);
    expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_BODY.getFileName()), anyObject(Map.class))).andReturn(body);
    expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_SUBJECT.getFileName()), anyObject(Map.class))).andReturn(subject);
    mailingEngine.sendAsync("iivanov@mail.com", new Mail(subject, body));
    replay(hourTypeRepository, workTimeService, mailTemplateManager, mailingEngine);
    notificationManager.notificateAboutOwnTimeProblems(employees, period, comment);
    verify(hourTypeRepository, workTimeService, 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) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with Mail

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

the class NotificationManagerTest method testNotifyPmAboutTimeProblems.

@Test
public void testNotifyPmAboutTimeProblems() throws NoSuchFieldException {
    notificationManager = createMockBuilder(NotificationManager.class).addMockedMethod("getProjects", List.class).addMockedMethod("getProjectManagers", Collection.class).createMock();
    setMockServices(notificationManager);
    Employee sender = new Employee("sender", "sender", "sender", "sender");
    Employee employee = new Employee("iivanov");
    Employee pm = new Employee("ppetrov");
    pm.setEmail("ppetrov@mail.com");
    Project project = createProject(1L, employee);
    List<Employee> employees = Arrays.asList(employee);
    List<Project> projects = Arrays.asList(project);
    Map<Employee, Map<Date, BigDecimal>> timeProblems = new HashMap<>();
    timeProblems.put(employee, new HashMap<>());
    Period period = new Period();
    String comment = "comment";
    String subject = "subject";
    String body = "body";
    EasyMock.expect(notificationManager.getProjects(employees)).andReturn(projects);
    EasyMock.expect(notificationManager.getProjectManagers(projects)).andReturn(Lists.newArrayList(pm));
    EasyMock.expect(hourTypeService.findActualTime()).andReturn(new HourType());
    EasyMock.expect(workTimeService.getWorkTimeDeviations(period, employees)).andReturn(timeProblems);
    EasyMock.expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_BODY_FOR_PM.getFileName()), anyObject(Map.class))).andReturn(body);
    EasyMock.expect(mailTemplateManager.getTemplateText(eq(MailTemplate.TIME_PROBLEM_SUBJECT.getFileName()), anyObject(Map.class))).andReturn(subject);
    EasyMock.expect(settings.getSmtpUsername()).andReturn("testSmtpUsername");
    EasyMock.expect(settings.getSmtpSender()).andReturn("sender");
    EasyMock.expect(settings.getApplicationBaseUrl()).andReturn("appHost");
    mailingEngine.send(new Mail(subject, body, sender.getEmail(), pm.getEmail()));
    EasyMock.replay(notificationManager, hourTypeService, workTimeService, mailTemplateManager, mailingEngine, settings);
    notificationManager.notifyProjectManagers(employees, period, comment);
    EasyMock.verify(notificationManager, hourTypeService, workTimeService, mailTemplateManager, mailingEngine);
}
Also used : HourType(com.artezio.arttime.datamodel.HourType) HashMap(java.util.HashMap) Period(com.artezio.arttime.datamodel.Period) Project(com.artezio.arttime.datamodel.Project) Employee(com.artezio.arttime.datamodel.Employee) Mail(com.artezio.arttime.services.mailing.Mail) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 5 with Mail

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

the class NotificationManagerTest method testNotifyAboutUnapprovedHours_oneEmployee.

@Test
public void testNotifyAboutUnapprovedHours_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);
    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("period", period);
    mailParameters.put("appHost", applicationBaseUrl);
    expect(settings.getSmtpSender()).andReturn(senderEmail);
    expect(settings.getApplicationBaseUrl()).andReturn(applicationBaseUrl);
    expect(mailTemplateManager.getTemplateText(MailTemplate.UNAPPROVED_HOURS_BODY.getFileName(), mailParameters)).andReturn(body);
    expect(mailTemplateManager.getTemplateText(MailTemplate.UNAPPROVED_HOURS_SUBJECT.getFileName(), mailParameters)).andReturn(subject);
    mailingEngine.send(mail);
    replay(settings, mailTemplateManager, mailingEngine);
    notificationManager.notifyAboutUnapprovedHours(employee, period);
    verify(settings, mailTemplateManager, mailingEngine);
}
Also used : Employee(com.artezio.arttime.datamodel.Employee) Mail(com.artezio.arttime.services.mailing.Mail) HashMap(java.util.HashMap) Period(com.artezio.arttime.datamodel.Period) Test(org.junit.Test)

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