diff --git a/pom.xml b/pom.xml
index f11fb7d..fdebaeb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -68,6 +68,10 @@
org.springframework.boot
spring-boot-starter-data-jpa
+
+ org.springframework.boot
+ spring-boot-starter-mail
+
org.springframework.boot
spring-boot-starter-security
diff --git a/src/main/java/com/primefactorsolutions/service/AssessmentService.java b/src/main/java/com/primefactorsolutions/service/AssessmentService.java
index 0cb4d80..87fceb4 100644
--- a/src/main/java/com/primefactorsolutions/service/AssessmentService.java
+++ b/src/main/java/com/primefactorsolutions/service/AssessmentService.java
@@ -5,7 +5,10 @@ import com.primefactorsolutions.repositories.AssessmentRepository;
import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional;
import lombok.Data;
+import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
+import org.springframework.mail.SimpleMailMessage;
+import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
import javax.swing.text.html.Option;
@@ -18,10 +21,12 @@ import java.util.stream.Collectors;
@Service
@Data
+@Slf4j
public class AssessmentService {
private final AssessmentRepository assessmentRepository;
private final EntityManager entityManager;
+ private final JavaMailSender emailSender;
public Assessment createOrUpdate(final Assessment assessment) {
final Assessment saved = assessmentRepository.save(assessment);
@@ -29,6 +34,26 @@ public class AssessmentService {
return saved;
}
+ public void sendEmail(final Assessment assessment) {
+ try {
+ final String evaluationLink = String.format("https://careers.primefactorsolutions.com/evaluation/%s", assessment.getId());
+ final SimpleMailMessage message = new SimpleMailMessage();
+ message.setFrom("no-reply@primefactorsolutions.com");
+ message.setTo(assessment.getAppUser().getEmail());
+ message.setSubject("PFS - Evaluacion Tecnica");
+ message.setText(String.format("Estimado candidato,\n\nGracias por su candidatura. En esta etapa del proceso de seleccion, usted debe completar "
+ + "una evaluacion tecnica de programacion en JAVA. La prueba tiene una duracion de 30 minutos y puede completarla cuando tenga una buena "
+ + "conexion de internet.\n\n"
+ + "Haga click aca: " + evaluationLink + "\n\n"
+ + "Exito!"));
+
+ emailSender.send(message);
+ } catch (Exception e) {
+ log.error("Error sending email", e);
+ throw e;
+ }
+ }
+
public List getAssessments() {
return assessmentRepository.findAll();
}
diff --git a/src/main/java/com/primefactorsolutions/views/AssessmentsListView.java b/src/main/java/com/primefactorsolutions/views/AssessmentsListView.java
index 8455b84..fcac787 100644
--- a/src/main/java/com/primefactorsolutions/views/AssessmentsListView.java
+++ b/src/main/java/com/primefactorsolutions/views/AssessmentsListView.java
@@ -5,10 +5,10 @@ import com.primefactorsolutions.service.AssessmentService;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.html.Main;
+import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.data.provider.DataProvider;
import com.vaadin.flow.data.provider.DataProviderListener;
import com.vaadin.flow.data.provider.Query;
-import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.function.ValueProvider;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
@@ -34,6 +34,13 @@ public class AssessmentsListView extends Main {
grid.addComponentColumn((ValueProvider) assessment -> new Button("Copy", event ->
ClientsideClipboard.writeToClipboard(String.format("https://localhost:8080/evaluation/%s", assessment.getId()))
));
+ grid.addComponentColumn((ValueProvider) assessment -> new Button("Send", event -> {
+ try {
+ assessmentService.sendEmail(assessment);
+ } catch (Exception e) {
+ Notification.show("Error sending email: " + e.getMessage(), 10_000, Notification.Position.TOP_CENTER);
+ }
+ }));
grid.setDataProvider(new DataProvider<>() {
@Override
diff --git a/src/main/java/com/primefactorsolutions/views/MainLayout.java b/src/main/java/com/primefactorsolutions/views/MainLayout.java
index abdcfee..b57e8d2 100644
--- a/src/main/java/com/primefactorsolutions/views/MainLayout.java
+++ b/src/main/java/com/primefactorsolutions/views/MainLayout.java
@@ -8,17 +8,23 @@ import com.vaadin.flow.component.html.Header;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.orderedlayout.Scroller;
import com.vaadin.flow.component.sidenav.SideNav;
+import com.vaadin.flow.component.sidenav.SideNavItem;
import com.vaadin.flow.router.PageTitle;
+import com.vaadin.flow.spring.security.AuthenticationContext;
import com.vaadin.flow.theme.lumo.LumoUtility;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.vaadin.lineawesome.LineAwesomeIcon;
/**
* The main view is a top-level placeholder for other views.
*/
public class MainLayout extends AppLayout {
+ private final transient AuthenticationContext authContext;
private H1 viewTitle;
- public MainLayout() {
+ public MainLayout(AuthenticationContext authContext) {
+ this.authContext = authContext;
setPrimarySection(Section.DRAWER);
addDrawerContent();
addHeaderContent();
@@ -47,7 +53,12 @@ public class MainLayout extends AppLayout {
private SideNav createNavigation() {
SideNav nav = new SideNav();
- //nav.addItem(new SideNavItem("CodeEditor", CodeEditorView.class, LineAwesomeIcon.EDIT.create()));
+ authContext.getAuthenticatedUser(UserDetails.class).ifPresent(u -> {
+ nav.addItem(new SideNavItem("Home", MainView.class, LineAwesomeIcon.HOME_SOLID.create()));
+ nav.addItem(new SideNavItem("Assessments", AssessmentsListView.class, LineAwesomeIcon.RIBBON_SOLID.create()));
+ nav.addItem(new SideNavItem("Users", UsersListView.class, LineAwesomeIcon.USER.create()));
+ nav.addItem(new SideNavItem("Questions", QuestionsListView.class, LineAwesomeIcon.QUESTION_SOLID.create()));
+ });
return nav;
}
diff --git a/src/main/java/com/primefactorsolutions/views/MainView.java b/src/main/java/com/primefactorsolutions/views/MainView.java
index 2d219d7..8b26aa6 100644
--- a/src/main/java/com/primefactorsolutions/views/MainView.java
+++ b/src/main/java/com/primefactorsolutions/views/MainView.java
@@ -6,7 +6,7 @@ import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import jakarta.annotation.security.PermitAll;
-@PageTitle("Assessment")
+@PageTitle("Home")
@Route(value = "", layout = MainLayout.class)
@PermitAll
public class MainView extends Main {
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index d80372f..d456784 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -8,6 +8,14 @@ vaadin.launch-browser=true
# For more information https://vaadin.com/docs/latest/integrations/spring/configuration#special-configuration-parameters
vaadin.allowed-packages = com.vaadin,org.vaadin,com.primefactorsolutions,com.hilerio.ace,com.flowingcode.vaadin,org.vaadin.firitin,org.vaadin.addons.stefan
+spring.mail.host=smtp.primefactorsolutions.com
+spring.mail.username=${SMTP_USER}
+spring.mail.password=${SMTP_PASS}
+spring.mail.properties.mail.transport.protocol=smtp
+spring.mail.properties.mail.smtp.port=587
+spring.mail.properties.mail.smtp.auth=true
+spring.mail.properties.mail.smtp.starttls.enable=true
+spring.mail.properties.mail.smtp.starttls.required=true
# spring.datasource.url=jdbc:h2:mem:testdb
# spring.datasource.url=jdbc:h2:file:./db