Preparacion para pruebas de mandar coreros cuando aparecen ofertas nuevas. Y ediciones pequeñas en las listas

master
vicsash 6 months ago
parent cdbd05aa25
commit 1680d87945

@ -74,6 +74,11 @@
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
</dependencies>
<build>

@ -0,0 +1,7 @@
package com.example.proyectofinal.controllers;
import org.springframework.stereotype.Controller;
@Controller
public class EmailController {
}

@ -1,6 +1,7 @@
package com.example.proyectofinal.controllers.modelControllers;
import com.example.proyectofinal.models.empresas.*;
import com.example.proyectofinal.servicios.MailService;
import com.example.proyectofinal.servicios.empresa.CicloService;
import com.example.proyectofinal.servicios.empresa.OfertaService;
import com.example.proyectofinal.servicios.empresa.SkillService;
@ -35,7 +36,6 @@ public class OfertaController {
@Autowired
private CicloService cicloService;
@GetMapping("/admin/oferta/create")
public String showCreateForm(Model model, Authentication authentication) {
Collection<? extends GrantedAuthority> authorities = authentication.getAuthorities();
@ -70,6 +70,7 @@ public class OfertaController {
return new ResponseEntity<>("Esta oferta ya existe en la base de datos", HttpStatus.BAD_REQUEST);
}else {
ofertaService.save(oferta);
ofertaService.mailOferta(oferta);
return new ResponseEntity<>("La oferta fue guadada con exito", HttpStatus.OK);
}
}catch (Exception e) {
@ -100,7 +101,6 @@ public class OfertaController {
@PostMapping("/oferta/update")
public ResponseEntity<String> updateOferta(Oferta oferta, @RequestParam("ciclo") Long ciclo, @RequestParam("sucursal") Long sucursal, @RequestParam("skills") List<Long> skills){
System.out.println("UPDATE TEST");
try{
Ciclo cicloEntity = cicloService.findById(ciclo);
Sucursal sucursalEntity = sucursalService.findById(sucursal);
@ -126,7 +126,7 @@ public class OfertaController {
}
try{
ofertaService.deleteById(id);
return new ResponseEntity<>("La oferta ha sido eliminado", HttpStatus.OK);
return new ResponseEntity<>("La oferta ha sido eliminada", HttpStatus.OK);
}catch (Exception e){
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}

@ -135,7 +135,6 @@ INSERT INTO Ofertas (nombre, descripcion, fecha, fk_sucursal,fk_ciclo) VALUES ('
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (1, 1); -- Jorge with Java
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (2, 10); -- Jane with ...
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (3, 2); -- Robert with Microsoft XL
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (4, 14); -- Emily with Marketing
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (5, 13); -- James with SQL
@ -149,6 +148,7 @@ INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (12, 1); -- Angelina with
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (13, 7); -- Leonardo with C++
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (14, 11); -- Scarlett with PHP
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (15, 10); -- Hugh with JavaScript
INSERT INTO Alumno_Skill (fk_alumno, fk_skills) VALUES (2, 10);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (1, 1);
INSERT INTO Oferta_Skill (fk_oferta, fk_skills) VALUES (2, 2);

@ -2,6 +2,7 @@ package com.example.proyectofinal.repositories.empresas;
import com.example.proyectofinal.models.empresas.Alumno;
import com.example.proyectofinal.models.empresas.Skill;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@ -89,5 +90,8 @@ public interface AlumnoRepository extends JpaRepository<Alumno, Long> {
@Query("SELECT a FROM Alumno a WHERE lower(a.correo) LIKE %:query%")
Alumno findByCorreo(String query);
@Query("SELECT a FROM Alumno a JOIN a.skills s WHERE s IN :skills GROUP BY a HAVING COUNT(s) >= :count")
List<Alumno> findBySkillsIn(@Param("skills") Collection<Skill> skills, @Param("count") long count);
}

@ -0,0 +1,45 @@
package com.example.proyectofinal.servicios;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
@Service
public class MailService {
private static final Logger LOGGER = LoggerFactory.getLogger(MailService.class);
private final JavaMailSender emailSender;
public MailService(JavaMailSender emailSender) {
this.emailSender = emailSender;
}
public boolean sendEmail(String to, String subject, String text) {
LOGGER.info("Sending email...");
return sendEmailTool(text, to, subject);
}
private boolean sendEmailTool(String textMessage, String email, String subject ) {
String cc = "empresas@ies.edu.es";
boolean send = false;
MimeMessage message = emailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
try {
helper.setTo(email);
helper.setText(textMessage, true);
helper.setSubject(subject);
helper.setCc(cc);
emailSender.send(message);
send = true;
LOGGER.info("Mail sent!");
} catch (MessagingException e) {
LOGGER.error("There was an error while sending the mail: {}", e.getMessage());
}
return send;
}
}

@ -1,6 +1,7 @@
package com.example.proyectofinal.servicios.empresa;
import com.example.proyectofinal.models.empresas.Alumno;
import com.example.proyectofinal.models.empresas.Skill;
import com.example.proyectofinal.repositories.empresas.AlumnoRepository;
import com.example.proyectofinal.servicios.implemetations.empresas.IAlumno;
import org.springframework.beans.factory.annotation.Autowired;
@ -11,6 +12,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
@Service
public class AlumnoService implements IAlumno{
@ -167,4 +169,7 @@ public class AlumnoService implements IAlumno{
return alumnoRepository.findByCorreo(email);
}
public List<Alumno> findBySkillsIn(List<Skill> skills) {
return alumnoRepository.findBySkillsIn(skills,skills.size());
}
}

@ -1,9 +1,11 @@
package com.example.proyectofinal.servicios.empresa;
import com.example.proyectofinal.models.empresas.Alumno;
import com.example.proyectofinal.models.empresas.Oferta;
import com.example.proyectofinal.models.empresas.Skill;
import com.example.proyectofinal.models.empresas.Sucursal;
import com.example.proyectofinal.repositories.empresas.OfertaRepository;
import com.example.proyectofinal.servicios.MailService;
import com.example.proyectofinal.servicios.implemetations.empresas.IOferta;
import jakarta.persistence.EntityManager;
import org.springframework.beans.factory.annotation.Autowired;
@ -18,11 +20,13 @@ import java.util.*;
@Service
public class OfertaService implements IOferta {
@Autowired
private EntityManager entityManager;
@Autowired
private OfertaRepository ofertaRepository;
@Autowired
private MailService mailService;
@Autowired
private AlumnoService alumnoService;
@Override
@ -205,4 +209,26 @@ public class OfertaService implements IOferta {
return listEmpPrime;
}
@Override
public void mailOferta(Oferta oferta) {
Set<Skill> listSkill = oferta.getSkills();
List<Skill> skillArray = new ArrayList<>(listSkill);
List<Alumno> alumnos = alumnoService.findBySkillsIn(skillArray);
StringBuilder sbMessage = new StringBuilder();
for (Alumno alumno : alumnos) {
sbMessage.append("Hola ").append(alumno.getNombre()).append(" ").append(alumno.getApellido()).append(",\n");
sbMessage.append("Hemos encontrado una oferta que puede interesarte:\n");
sbMessage.append("Nombre de la oferta: ").append(oferta.getNombre()).append("\n");
sbMessage.append("Empresa: ").append(oferta.getSucursal().getEmpresa().getNombre()).append("\n");
System.out.println("TEST " + alumno.getNombre());
System.out.println("TEST CORREO " + alumno.getCorreo());
//mailService.sendEmail(alumno.getCorreo(), "Nueva oferta de practicas", sbMessage.toString());
if(alumno.getCorreo2() != null){
//mailService.sendEmail(alumno.getCorreo2(), "Nueva oferta de practicas", sbMessage.toString());
}
}
}
}

@ -28,4 +28,6 @@ public interface IOferta extends IPagination<Oferta> {
Page<Oferta> getPage(int pageNum, int size, String sortField, String sortDir, String query, String secondaryOption) throws ParseException;
List<Oferta> searchCustom(String querySearchBar, String query, String secondaryOption);
void mailOferta(Oferta oferta);
}

@ -16,4 +16,24 @@ server.port=8080
#Dialecto
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
#EMAIL DATA
spring.mail.host=135.125.201.208
spring.mail.port=587
spring.mail.protocol=smtp
spring.mail.username=empresas@ies.edu.es
spring.mail.password=1234
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=false
spring.mail.properties.mail.smtp.starttls.required=false
spring.mail.properties.mail.smtp.quitwait=false

@ -74,7 +74,7 @@
<div class ="form-group row">
<label class="col-sm-3 col-form-label" for="apellido2">Apellido2</label>
<div class = "col-sm-9">
<input type="text" th:field="*{apellido2}" required minlength="1" maxlength="100" class="form-control" id="apellido2">
<input type="text" th:field="*{apellido2}" minlength="1" maxlength="100" class="form-control" id="apellido2">
</div>
</div>

@ -28,7 +28,7 @@
margin-right: 5px;
width: 120px;
height: 40px;
font-family: Verdana;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}
form input[type="submit"], form input[type="button"] {
width: 100px;

@ -154,8 +154,6 @@
}
function handleDelete(event) {
//console.log("handleDelete function called");
//console.log("Delete icon clicked");
const row = event.target.closest('tr');
const rowId = row.dataset.id;
var modal = document.getElementById("modalDelete");
@ -177,6 +175,8 @@
success: function(response) {
if (response === "La oferta ha sido eliminada") {
alert("Oferta borrada con exito");
modal.style.display = "none"; // Add this line to hide the modal
document.body.style.pointerEvents = 'auto';
window.location.reload();
} else {
alert("Error al borrar oferta");

Loading…
Cancel
Save

Powered by INFORMATICA.FP.EDU.ES.