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);
}
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);
}
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));
}
}
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));
}
}
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));
}
Aggregations