diff --git a/pom.xml b/pom.xml
index 8c9f860..9f45ad2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,6 +69,11 @@
javafaker1.0.2
+
+ com.h2database
+ h2
+ runtime
+
diff --git a/src/main/java/com/example/proyectofinal/configuration/database/DatabaseTest.java b/src/main/java/com/example/proyectofinal/configuration/database/DatabaseTest.java
deleted file mode 100644
index fc74914..0000000
--- a/src/main/java/com/example/proyectofinal/configuration/database/DatabaseTest.java
+++ /dev/null
@@ -1,112 +0,0 @@
-package com.example.proyectofinal.configuration.database;
-import com.example.proyectofinal.models.empresas.*;
-import com.example.proyectofinal.repositories.empresas.*;
-import com.github.javafaker.Faker;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.CommandLineRunner;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.jdbc.core.JdbcTemplate;
-
-import javax.sql.DataSource;
-import java.util.HashSet;
-import java.util.Random;
-import java.util.Set;
-
-@Configuration
-public class DatabaseTest {
- @Autowired
- private DataSource dataSource;
-
- @Bean
- CommandLineRunner initDatabase(AlumnoRepository alumnoRepository, ContactoRepository contactoRepository, SucursalRepository sucursalRepository, OfertaRepository ofertaRepository, SkillRepository skillRepository, EmpressaRepository empressaRepository, CicloRepository cicloRepository, SectorRepository sectorRepository) {
- return args -> {
- Faker faker = new Faker();
-
- String[] cicloNames = {"DAM", "DAM2", "DAW", "DAW2", "ACI"};
- String[] familiaNames = {"Informatica", "Informatica2", "Informatica3", "Informatica4", "Informatica5"};
- Random random = new Random();
-
- for (int i = 0; i < 30; i++) {
- int randomIndex = random.nextInt(cicloNames.length);
- Familia familia = new Familia(familiaNames[randomIndex]);
- Ciclo ciclo = new Ciclo("Programacion cilclo",cicloNames[randomIndex], familia);
-
- Skill skill = new Skill(faker.lorem().word() + i);
- skillRepository.save(skill);
-
- Set skills = new HashSet<>();
- skills.add(skill);
-
- Alumno alumno = new Alumno(
- faker.name().firstName(),
- faker.name().lastName(),
- faker.name().lastName(),
- faker.date().birthday(),
- faker.demographic().sex(),
- faker.number().digits(8),
- faker.number().digits(8),
- faker.internet().emailAddress(),
- faker.internet().emailAddress(),
- faker.country().name(),
- faker.lorem().word(),
- skills,
- ciclo
- );
- alumnoRepository.save(alumno);
-
- Sector sector = new Sector("Tecnologia" + i);
- //sectorRepository.save(sector);
-
- Empresa empresa = new Empresa(
- faker.company().name(),
- "123456789W" + i,
- faker.internet().emailAddress(),
- faker.phoneNumber().cellPhone(),
- faker.company().profession(),
- sector
- );
- //empressaRepository.save(empresa);
-
- Contacto contacto = new Contacto(
- faker.name().firstName(),
- faker.name().lastName(),
- faker.name().lastName(),
- faker.internet().emailAddress(),
- faker.phoneNumber().cellPhone(),
- empresa
- );
- contactoRepository.save(contacto);
-
- Sucursal sucursal = new Sucursal(
- "Sucursal " + (i + 1),
- "Sevilla",
- "Calle Falsa 123",
- true,
- empresa
- );
- //sucursalRepository.save(sucursal);
-
- Oferta oferta = new Oferta(
- "Oferta " + (i + 1),
- "Descripcion de la oferta",
- "2023-01-11",
- sucursal,
- skills
- );
- ofertaRepository.save(oferta);
- }
-// JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
-// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON empresas(keywords,nombre)");
-// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON alumnos(keywords,nombre,apellido,apellido2,dni,nia,correo,correo2,nacionalidad,genero)");
-// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON ofertas(nombre,fecha)");
-// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON sucursales(nombre,localidad,direccion)");
-// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON sectores(nombre)");
-// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON ciclos(nombre)");
-// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON familias(nombre)");
-// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON skills(nombre)");
-// jdbcTemplate.execute("CREATE FULLTEXT INDEX keywords_index ON contactos(nombre,apellido,apellido2,correo,telefono)");
- };
-
- }
-}
diff --git a/src/main/java/com/example/proyectofinal/controllers/BuscadorController.java b/src/main/java/com/example/proyectofinal/controllers/BuscadorController.java
index 7fdadf1..8af6781 100644
--- a/src/main/java/com/example/proyectofinal/controllers/BuscadorController.java
+++ b/src/main/java/com/example/proyectofinal/controllers/BuscadorController.java
@@ -3,14 +3,20 @@ package com.example.proyectofinal.controllers;
import com.example.proyectofinal.models.empresas.*;
import com.example.proyectofinal.repositories.empresas.*;
-import jakarta.servlet.http.HttpSession;
+import com.example.proyectofinal.servicios.EmpresaService;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
+import javax.servlet.http.HttpServletRequest;
import java.util.*;
@Controller
@@ -37,123 +43,166 @@ public class BuscadorController {
@Autowired
private CicloRepository cicloRepository;
+ @Autowired
+ private EmpresaService empresaService;
+
@GetMapping
public String buscador(){
return "buscador_admin";
}
- @GetMapping("/search")
- public String search(@RequestParam String query, @RequestParam String searchOption, Model model, HttpSession session) {
+ @GetMapping("/empresas/page/{pageNum}")
+ public String seachEmpresasList(@PathVariable int pageNum,
+ @RequestParam(defaultValue = "") String query,
+ Model model,
+ @RequestParam(defaultValue = "10") int size,
+ @RequestParam(defaultValue = "id") String sortField,
+ @RequestParam(defaultValue = "asc") String sortDir){
+
+ String[] word = query.split("\\b(y|o)\\b|[,/]");
+ List empresas;
+ List itemsPage = Arrays.asList(5, 10, 15, 20, 25, 50);
+
+ if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
+ Page page = this.empresaService.finadAllpaginated(pageNum, size, "id", "asc");
+ empresas = page.getContent();
+ } else {
+ Page page = this.empresaService.finadAllpaginated(pageNum, size, sortField, sortDir);
+ empresas = page.getContent();
+ }
+ model.addAttribute("currentSize", size);
+ Map attributes = getPagAtrEmpresas(pageNum, query, size, sortField, sortDir, empresas, itemsPage);
+ for (Map.Entry entry : attributes.entrySet()) {
+ model.addAttribute(entry.getKey(), entry.getValue());
+ }
+
+ return "/list/empresas";
+ }
+
+
+
+ public String searchAlumnosList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
+ Pageable pageable = PageRequest.of(page, size);
+ String[] word = query.split("\\b(y|o)\\b|[,/]");
+ if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todos")) {
+ List alumnos = new ArrayList<>(alumnoRepository.findAll());
+ model.addAttribute("alumnos", alumnos);
+ return "/list/alumnos";
+ }
+ return "/list/alumnos";
+ }
+
+ @GetMapping("/ofertas")
+ public String searchOfertasList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size){
+ Pageable pageable = PageRequest.of(page, size);
+ String[] word = query.split("\\b(y|o)\\b|[,/]");
+ if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
+ List ofertas = new ArrayList<>(ofertaRepository.findAll());
+ model.addAttribute("ofertas", ofertas);
+ return "/list/ofertas";
+ }
+ return "/list/ofertas";
+ }
+
+ @GetMapping("/sectores")
+ public String searchSectoresList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size){
+ Pageable pageable = PageRequest.of(page, size);
+ String[] word = query.split("\\b(y|o)\\b|[,/]");
+ if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
+ List sectores = new ArrayList<>(sectorRepository.findAll());
+ model.addAttribute("sectores", sectores);
+ return "/list/sectores";
+ } else {
+ Sector sector = sectorRepository.findByNombre(word[0]);
+ model.addAttribute("sectores", sector);
+ return "/list/sectores";
+ }
+ }
+
+ @GetMapping("/sucursales")
+ public String searchSucursalesList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size){
+ Pageable pageable = PageRequest.of(page, size);
+ String[] word = query.split("\\b(y|o)\\b|[,/]");
+ if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
+ List sucursalSet = new ArrayList<>(sucursalRepository.findAll());
+ model.addAttribute("sucursales", sucursalSet);
+ return "/list/sucursales";
+ }
+ return "/list/sucursales";
+ }
+
+
+@GetMapping("/contactos")
+ public String searchContactosList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
+ Pageable pageable = PageRequest.of(page, size);
String[] word = query.split("\\b(y|o)\\b|[,/]");
- if (searchOption.equals("OptEmpresa")) {
- if(word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")){
- ArrayList empresas = new ArrayList<>(empressaRepository.findAllAsc());
- model.addAttribute("empresas", empresas);
- return "/list/empresas";
- }
-// if(word.length == 1){
-// ArrayList empresas = new ArrayList<>(empressaRepository.getEmpressaByKeywordsOrName(word[0]));
-// model.addAttribute("empresas", empresas);
-// return "/list/empresas";
-// }else if(word.length == 2){
-// ArrayList empresas = new ArrayList<>(empressaRepository.getEmpressaByKeywordsOrName(word[0]));
-// empresas.addAll(empressaRepository.getEmpressaByKeywordsOrName(word[1]));
-// model.addAttribute("empresas", empresas);
-// return "/list/empresas";
-// }
- } else if (searchOption.equals("OptAlumno")) {
- if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todos")) {
- ArrayList alumnos = new ArrayList<>(alumnoRepository.findAll());
- model.addAttribute("alumnos", alumnos);
- return "/list/alumnos";
- }
-// if (word.length == 1) {
-// System.out.println("Buscando alumnos");
-// ArrayList alumnos = new ArrayList<>(alumnoRepository.getAlumnoByKeywordsOrName(word[0]));
-// model.addAttribute("alumnos", alumnos);
-// return "/list/alumnos";
-// } else if (word.length == 2) {
-// System.out.println("Buscando alumnos");
-// ArrayList alumnos = new ArrayList<>(alumnoRepository.getAlumnoByKeywordsOrName(word[0]));
-// alumnos.addAll(alumnoRepository.getAlumnoByKeywordsOrName(word[1]));
-// model.addAttribute("alumnos", alumnos);
-// return "/list/alumnos";
-// }
- }else if(searchOption.equals("OptOferta")) {
- if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
- ArrayList ofertas = new ArrayList<>(ofertaRepository.findAll());
- model.addAttribute("ofertas", ofertas);
- return "/list/ofertas";
- }
-// if (word.length == 1) {
-// ArrayList ofertas = new ArrayList<>(ofertaRepository.getOfertaFullTextSeach(word[0]));
-// model.addAttribute("ofertas", ofertas);
-// return "/list/ofertas";
-// } else if (word.length == 2) {
-// ArrayList ofertas = new ArrayList<>(ofertaRepository.getOfertaFullTextSeach(word[0]));
-// ofertas.addAll(ofertaRepository.getOfertaFullTextSeach(word[1]));
-// model.addAttribute("ofertas", ofertas);
-// return "/list/ofertas";
-// }
- } else if (searchOption.equals("OptSector")) {
- if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
- ArrayList sectores = new ArrayList<>(sectorRepository.findAll());
- model.addAttribute("sectores", sectores);
- return "/list/sectores";
- } else {
- Sector sector = sectorRepository.findByNombre(word[0]);
- model.addAttribute("sectores", sector);
- return "/list/sectores";
- }
- }else if(searchOption.equals("OptSucursal")) {
- if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
- ArrayList sucursalSet = new ArrayList<>(sucursalRepository.findAll());
- model.addAttribute("sucursales", sucursalSet);
- return "/list/sucursales";
- }
-// } else {
-// ArrayList sucursalSet = new ArrayList<>(sucursalRepository.getSucursalFullTextSeach(word[0]));
-// model.addAttribute("sucursales", sucursalSet);
-// return "/list/sucursales";
-// }
- }else if(searchOption.equals("OptSkill")){
- if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
- ArrayList skills = new ArrayList<>(skillRepository.findAll());
- model.addAttribute("skills", skills);
- return "/list/skills";
- }
-// else{
-// ArrayList skills = new ArrayList<>(skillRepository.getSkillFullTextSeach(word[0]));
-// model.addAttribute("skills", skills);
-// return "/list/skills";
-// }
- }else if(searchOption.equals("OptContactos")) {
- if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
- ArrayList contactos = new ArrayList<>(contactoRepository.findAll());
- model.addAttribute("contactos", contactos);
- return "/list/contactos";
- }
-// else {
-// ArrayList contactos = new ArrayList<>(contactoRepository.getContactoFullTextSeach(word[0]));
-// model.addAttribute("contactos", contactos);
-// return "/list/contactos";
-// }
- }else if(searchOption.equals("OptFamilias")) {
- if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
- ArrayList familias = new ArrayList<>(familiaRepository.findAll());
- model.addAttribute("familias", familias);
- return "/list/familias";
- }
- }else if(searchOption.equals("OptCiclos")){
- if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
- ArrayList ciclos = new ArrayList<>(cicloRepository.findAll());
- model.addAttribute("ciclos", ciclos);
- return "/list/ciclos";
- }
- }else{
- System.out.println("ERROR EN BUSQUEDA DE UNA PALABRA");
- return "error";
+ if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
+ List contactos = new ArrayList<>(contactoRepository.findAll());
+ model.addAttribute("contactos", contactos);
+ return "/list/contactos";
}
- return "error";
+ return "/list/contactos";
+ }
+
+ @GetMapping("/familias")
+ public String searchFamiliasList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
+ Pageable pageable = PageRequest.of(page, size);
+ String[] word = query.split("\\b(y|o)\\b|[,/]");
+ if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
+ List familias = new ArrayList<>(familiaRepository.findAll());
+ model.addAttribute("familias", familias);
+ return "/list/familias";
+ }
+ return "/list/familias";
+ }
+
+ @GetMapping("/ciclos")
+ public String searchCiclosList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
+ Pageable pageable = PageRequest.of(page, size);
+ String[] word = query.split("\\b(y|o)\\b|[,/]");
+ if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
+ List ciclos = new ArrayList<>(cicloRepository.findAll());
+ model.addAttribute("ciclos", ciclos);
+ return "/list/ciclos";
+ }
+ return "/list/ciclos";
+ }
+
+
+
+ @GetMapping("/skills")
+ public String searchSkillsList(@RequestParam String query, @RequestParam String searchOption, @RequestParam(required = false) String filter, Model model, @RequestParam(defaultValue = "0") int page, @RequestParam(defaultValue = "10") int size) {
+ Pageable pageable = PageRequest.of(page, size);
+ String[] word = query.split("\\b(y|o)\\b|[,/]");
+ if (word.length == 1 && word[0].equalsIgnoreCase("all") || word[0].equalsIgnoreCase("todas")) {
+ List skills = new ArrayList<>(skillRepository.findAll());
+ model.addAttribute("skills", skills);
+ return "/list/skills";
+ }
+ return "/list/skills";
+ }
+
+
+ public Map getPagAtrEmpresas(int pageNum, String query, int size, String sortField, String sortDir, List empresas, List itemsPage) {
+ Map attributes = new HashMap<>();
+
+ Page page = this.empresaService.finadAllpaginated(pageNum, size, "id", "asc");
+
+ attributes.put("currentPage", pageNum);
+ attributes.put("totalPages", page.getTotalPages());
+ attributes.put("totalItems", page.getTotalElements());
+ attributes.put("sortField", sortField);
+ attributes.put("sortDir", sortDir);
+ attributes.put("reverseSortDir", sortDir.equals("asc") ? "desc" : "asc");
+ attributes.put("empresas", empresas);
+ attributes.put("query", query);
+ attributes.put("itemsPage", itemsPage);
+ return attributes;
+ }
+
+ @GetMapping("/empresas/search")
+ public ResponseEntity> searchEmpresas(@RequestParam String query) {
+ List empresas = empresaService.search(query);
+ return ResponseEntity.ok(empresas);
}
}
\ No newline at end of file
diff --git a/src/main/java/com/example/proyectofinal/repositories/empresas/EmpressaRepository.java b/src/main/java/com/example/proyectofinal/repositories/empresas/EmpressaRepository.java
index 3dd0ee3..cc42128 100644
--- a/src/main/java/com/example/proyectofinal/repositories/empresas/EmpressaRepository.java
+++ b/src/main/java/com/example/proyectofinal/repositories/empresas/EmpressaRepository.java
@@ -1,18 +1,22 @@
package com.example.proyectofinal.repositories.empresas;
import com.example.proyectofinal.models.empresas.Empresa;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
import java.util.ArrayList;
import java.util.List;
public interface EmpressaRepository extends JpaRepository, JpaSpecificationExecutor {
+ Page findAll(Pageable pageable);
- //there is value = and nativeQuery = true so the query is written in SQL refering to the table in the database
- @Query(value = "SELECT * FROM empresas u WHERE MATCH(u.nombre, u.keywords) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
- public ArrayList getEmpressaByKeywordsOrName(String word);
+// //there is value = and nativeQuery = true so the query is written in SQL refering to the table in the database
+// @Query(value = "SELECT * FROM empresas u WHERE MATCH(u.nombre, u.keywords) AGAINST(?1 IN BOOLEAN MODE)", nativeQuery = true)
+// public ArrayList getEmpressaByKeywordsOrName(String word);
@Query(value = "SELECT * FROM empresas u WHERE u.sector_id = ?1", nativeQuery = true)
public ArrayList findBySector(Long id);
@@ -20,6 +24,10 @@ public interface EmpressaRepository extends JpaRepository, JpaSpe
@Query(value = "SELECT * FROM empresas order by id Asc", nativeQuery = true)
List findAllAsc();
+ @Query("SELECT e FROM Empresa e WHERE e.nombre LIKE %:query% OR e.cif LIKE %:query% OR e.correo LIKE %:query% OR e.telefono LIKE %:query% OR e.keywords LIKE %:query% OR e.sector.nombre LIKE %:query%")
+ List search(@Param("query") String query);
+
+
}
diff --git a/src/main/java/com/example/proyectofinal/servicios/EmpresaService.java b/src/main/java/com/example/proyectofinal/servicios/EmpresaService.java
new file mode 100644
index 0000000..758c070
--- /dev/null
+++ b/src/main/java/com/example/proyectofinal/servicios/EmpresaService.java
@@ -0,0 +1,21 @@
+package com.example.proyectofinal.servicios;
+
+import com.example.proyectofinal.models.empresas.Empresa;
+import org.springframework.data.domain.Page;
+
+import java.util.List;
+
+public interface EmpresaService {
+
+ List findAll();
+
+ Page finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir);
+
+ Empresa findById(Long id);
+
+ Empresa save(Empresa empresa);
+
+ void deleteById(Long id);
+
+ List search(String query);
+}
diff --git a/src/main/java/com/example/proyectofinal/servicios/implemetations/EmpresaServiceImplementation.java b/src/main/java/com/example/proyectofinal/servicios/implemetations/EmpresaServiceImplementation.java
new file mode 100644
index 0000000..0c3ba96
--- /dev/null
+++ b/src/main/java/com/example/proyectofinal/servicios/implemetations/EmpresaServiceImplementation.java
@@ -0,0 +1,58 @@
+package com.example.proyectofinal.servicios.implemetations;
+
+import com.example.proyectofinal.models.empresas.Empresa;
+import com.example.proyectofinal.repositories.empresas.EmpressaRepository;
+import com.example.proyectofinal.servicios.EmpresaService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class EmpresaServiceImplementation implements EmpresaService {
+
+ @Autowired
+ private EmpressaRepository empressaRepository;
+
+ @Override
+ public List findAll() {
+ return empressaRepository.findAll();
+ }
+
+ @Override
+ public Page finadAllpaginated(int pageNum, int pageSize, String sortField, String sortDir) {
+ Sort sort = sortDir.equalsIgnoreCase(Sort.Direction.ASC.name())
+ ? Sort.by(sortField).ascending() :
+ Sort.by(sortField).descending();
+ Pageable pageable = PageRequest.of(pageNum - 1,pageSize,sort);
+ return this.empressaRepository.findAll(pageable);
+ }
+
+ @Override
+ public Empresa findById(Long id) {
+ return empressaRepository.findById(id).orElse(null);
+ }
+
+ @Override
+ public Empresa save(Empresa empresa) {
+ return empressaRepository.save(empresa);
+ }
+
+ @Override
+ public void deleteById(Long id) {
+
+ }
+
+ @Override
+ public List search(String query ) {
+ return empressaRepository.search(query);
+ }
+
+
+
+
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index f973c3a..f4b3c35 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -1,13 +1,15 @@
spring.datasource.url=jdbc:mysql://localhost:3306/projfin
spring.datasource.username=projfin
+spring.h2.console.enabled=true
spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#Configuracion de JPA
-spring.jpa.hibernate.ddl-auto=create-drop
+spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
+
#server
server.port=8080
diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql
index 693e645..e69de29 100644
--- a/src/main/resources/data.sql
+++ b/src/main/resources/data.sql
@@ -1,64 +0,0 @@
-INSERT INTO Familia (nombre) VALUES ('Informatica1');
-INSERT INTO Familia (nombre) VALUES ('Informatica2');
-INSERT INTO Familia (nombre) VALUES ('Informatica3');
-INSERT INTO Familia (nombre) VALUES ('Informatica4');
-INSERT INTO Familia (nombre) VALUES ('Informatica5');
-
--- Insert into Ciclo table
-INSERT INTO Ciclo (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones multiplataforma 1','DAM1', 1);
-INSERT INTO Ciclo (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones multiplataforma','DAM2', 2);
-INSERT INTO Ciclo (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones web 1','DAW2', 3);
-INSERT INTO Ciclo (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones web 2','DAW2', 4);
-INSERT INTO Ciclo (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones anci 1','ANCI2', 5);
-INSERT INTO Ciclo (nombre, codigo, Familia_id) VALUES ('Dessarrollo de aplicaciones anci 2','ANCI2', 5);
-
--- Insert into Skill table
-INSERT INTO Skill (nombre) VALUES ('Java');
-INSERT INTO Skill (nombre) VALUES ('Guitara');
-INSERT INTO Skill (nombre) VALUES ('Eletricista');
-INSERT INTO Skill (nombre) VALUES ('Moviles');
-INSERT INTO Skill (nombre) VALUES ('Deportista');
-INSERT INTO Skill (nombre) VALUES ('Python');
-
--- Insert into Alumno table
-INSERT INTO Alumno (nombre, apellido, apellido2, fechaNacimiento, genero, nia, dni, correo, correo2, nacionalidad, keyword, Ciclo_id) VALUES ('John', 'Doe', , '2000-01-01', 'Male', '123456781', '12345678A', 'john.doe@example.com', 'john.smith@example.com', 'American', 'Java, Python', 1);
-INSERT INTO Alumno (nombre, apellido, apellido2, fechaNacimiento, genero, nia, dni, correo, correo2, nacionalidad, keyword, Ciclo_id) VALUES ('Jane', 'Doe', 'Johnson', '2000-02-02', 'Female', '123456782', '12345678B', 'jane.doe@example.com', 'jane.johnson@example.com', 'American', 'Guitara', 2);
-INSERT INTO Alumno (nombre, apellido, apellido2, fechaNacimiento, genero, nia, dni, correo, correo2, nacionalidad, keyword, Ciclo_id) VALUES ('Robert', 'Smith', , '2000-03-03', 'Male', '123456783', '12345678C', 'robert.smith@example.com', , 'British', 'Eletricista', 3);
-INSERT INTO Alumno (nombre, apellido, apellido2, fechaNacimiento, genero, nia, dni, correo, correo2, nacionalidad, keyword, Ciclo_id) VALUES ('Emily', 'Johnson', 'Smith', '2000-04-04', 'Female', '123456784', '12345678D', 'emily.johnson@example.com', 'emily.smith@example.com', 'British', 'Moviles', 4);
-INSERT INTO Alumno (nombre, apellido, apellido2, fechaNacimiento, genero, nia, dni, correo, correo2, nacionalidad, keyword, Ciclo_id) VALUES ('James', 'Brown', 'Johnson', '2000-05-05', 'Male', '123456785', '12345678E', 'james.brown@example.com', , 'Australian', 'Deportista', 5);
-
-
--- Insert into Sector table
-INSERT INTO Sector (nombre) VALUES ('Electricidad');
-INSERT INTO Sector (nombre) VALUES ('Informatica');
-INSERT INTO Sector (nombre) VALUES ('Deporte');
-INSERT INTO Sector (nombre) VALUES ('Musica');
-INSERT INTO Sector (nombre) VALUES ('Electronica');
-
--- Insert into Empresa table
-INSERT INTO Empresa (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('LuzT', '123456789W1', 'luzt@example.com', '12345678901', 'trabajador,python', 1);
-INSERT INTO Empresa (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('PC R&R', '123456789W2', 'pcrnr@example.com', '12345678902', 'jugador', 2);
-INSERT INTO Empresa (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('Runners', '123456789W3', 'run@example.com', '12345678903', 'bailador', 3);
-INSERT INTO Empresa (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('Keytara', '123456789W4', 'keytara@example.com', '12345678904', 'programador', 4);
-INSERT INTO Empresa (nombre, cif, correo, telefono, keywords, Sector_id) VALUES ('Movil', '123456789W5', 'movil@example.com', '12345678905', 'animales', 5);
-
--- Insert into Contacto table
-INSERT INTO Contacto (nombre, apellido1, apellido2, correo, telefono, Empresa_id) VALUES ('Juan', 'Gonzales','Gonzales' , 'juan@example.com', '12345678901', 1);
-INSERT INTO Contacto (nombre, apellido1, apellido2, correo, telefono, Empresa_id) VALUES ('Estaban', 'Smit', 'Lokasto', '', '12345678902', 2);
-INSERT INTO Contacto (nombre, apellido1, apellido2, correo, telefono, Empresa_id) VALUES ('Pablo', 'Lodrego', , 'pablo@example.com', '12345678903', 3);
-INSERT INTO Contacto (nombre, apellido1, apellido2, correo, telefono, Empresa_id) VALUES ('David', 'Borgia', 'Algosto', 'david4@example.com', '12345678904', 4);
-INSERT INTO Contacto (nombre, apellido1, apellido2, correo, telefono, Empresa_id) VALUES ('Logan', 'Porlot', , 'logan@example.com', '', 5);
-
--- Insert into Sucursal table
-INSERT INTO Sucursal (nombre, localidad, direccion, sede_central, Empresa_id) VALUES ('Sucursal1', 'Denia', 'Calle 123', true, 1);
-INSERT INTO Sucursal (nombre, localidad, direccion, sede_central, Empresa_id) VALUES ('Sucursal2', 'Javea', 'Calle Verdadera 123', true, 2);
-INSERT INTO Sucursal (nombre, localidad, direccion, sede_central, Empresa_id) VALUES ('Sucursal3', 'Teulada', 'Calle Alog 123', true, 3);
-INSERT INTO Sucursal (nombre, localidad, direccion, sede_central, Empresa_id) VALUES ('Sucursal4', 'Benitachell', 'Calle Loco 123', true, 4);
-INSERT INTO Sucursal (nombre, localidad, direccion, sede_central, Empresa_id) VALUES ('Sucursal5', 'Benissa', 'Calle Norm 123', true, 5);
-
--- Insert into Oferta table
-INSERT INTO Oferta (nombre, descripcion, fecha, Sucursal_id) VALUES ('Oferta1', 'Description1', '2023-01-11', 1);
-INSERT INTO Oferta (nombre, descripcion, fecha, Sucursal_id) VALUES ('Oferta2', 'Description2', '2023-01-12', 2);
-INSERT INTO Oferta (nombre, descripcion, fecha, Sucursal_id) VALUES ('Oferta3', 'Description3', '2023-01-13', 3);
-INSERT INTO Oferta (nombre, descripcion, fecha, Sucursal_id) VALUES ('Oferta4', 'Description4', '2023-01-14', 4);
-INSERT INTO Oferta (nombre, descripcion, fecha, Sucursal_id) VALUES ('Oferta5', 'Description5', '2023-01-15', 5);
\ No newline at end of file
diff --git a/src/main/resources/random b/src/main/resources/random
new file mode 100644
index 0000000..e5886ad
--- /dev/null
+++ b/src/main/resources/random
@@ -0,0 +1,23 @@
+function dynamicSearch() {
+ var input, filter, table, tbody, tr, td, i, j, txtValue;
+ input = document.getElementById("myInput");
+ filter = input.value.toUpperCase();
+ table = document.getElementById("table");
+ tbody = table.getElementsByTagName("tbody")[0];
+ tr = tbody.getElementsByTagName("tr");
+
+ for (i = 0; i < tr.length; i++) {
+ for (j = 0; j < tr[i].cells.length; j++) {
+ td = tr[i].cells[j];
+ if (td) {
+ txtValue = td.textContent || td.innerText;
+ if (txtValue.toUpperCase().indexOf(filter) > -1) {
+ tr[i].style.display = "";
+ break;
+ } else {
+ tr[i].style.display = "none";
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/resources/static/orderTable.js b/src/main/resources/static/orderTable.js
index f225502..69e392b 100644
--- a/src/main/resources/static/orderTable.js
+++ b/src/main/resources/static/orderTable.js
@@ -1,64 +1,16 @@
-function myFunction() {
- var input, filter, table, tbody, tr, td, i, j, txtValue;
- input = document.getElementById("myInput");
- filter = input.value.toUpperCase();
- table = document.getElementById("table");
- tbody = table.getElementsByTagName("tbody")[0];
- tr = tbody.getElementsByTagName("tr");
-
- for (i = 0; i < tr.length; i++) {
- for (j = 0; j < tr[i].cells.length; j++) {
- td = tr[i].cells[j];
- if (td) {
- txtValue = td.textContent || td.innerText;
- if (txtValue.toUpperCase().indexOf(filter) > -1) {
- tr[i].style.display = "";
- break;
- } else {
- tr[i].style.display = "none";
- }
- }
- }
+$('#entriesCount').on('change', function(){
+ var entriesCount = $('#entriesCount').val();
+ console.log(entriesCount);
+ var url = window.location.href;
+ var newUrl;
+ if (url.includes('size=')) {
+ newUrl = url.replace(/(size=)[^\&]+/, '$1' + entriesCount);
+ } else {
+ newUrl = url.includes('?') ? url + '&size=' + entriesCount : url + '?size=' + entriesCount;
}
-}
+ window.location.href = newUrl;
+});
+
+
+
-function sortTableCol(n) {
- var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
- table = document.getElementById("table");
- switching = true;
- dir = "asc";
- while (switching) {
- switching = false;
- rows = table.rows;
- for (i = 1; i < (rows.length - 1); i++) {
- shouldSwitch = false;
- x = rows[i].getElementsByTagName("TD")[n].innerHTML.trim();
- y = rows[i + 1].getElementsByTagName("TD")[n].innerHTML.trim();
- var xIsNumber = !isNaN(parseFloat(x)) && isFinite(x);
- var yIsNumber = !isNaN(parseFloat(y)) && isFinite(y);
- if (dir == "asc") {
- if ((xIsNumber && yIsNumber && parseFloat(x) > parseFloat(y)) ||
- (!xIsNumber && !yIsNumber && x.localeCompare(y) > 0)) {
- shouldSwitch = true;
- break;
- }
- } else if (dir == "desc") {
- if ((xIsNumber && yIsNumber && parseFloat(x) < parseFloat(y)) ||
- (!xIsNumber && !yIsNumber && x.localeCompare(y) < 0)) {
- shouldSwitch = true;
- break;
- }
- }
- }
- if (shouldSwitch) {
- rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
- switching = true;
- switchcount++;
- } else {
- if (switchcount === 0 && dir === "asc") {
- dir = "desc";
- switching = true;
- }
- }
- }
-}
diff --git a/src/main/resources/templates/buscador_admin.html b/src/main/resources/templates/buscador_admin.html
index 8912e5f..03ce745 100644
--- a/src/main/resources/templates/buscador_admin.html
+++ b/src/main/resources/templates/buscador_admin.html
@@ -48,28 +48,34 @@
PAGINA PRINCIPAL
+
-
+
-
-
Title
@@ -49,13 +50,27 @@
position: relative;
}
.table {
- padding-top: 5px;
- width: 100%;
- height: 90vh;
- overflow-y: auto;
+ table-layout: fixed; /* This will create a fixed layout for the table */
+ width: 100%; /* This will set the table width to 100% */
+ }
+ .table td, .table th {
+ width: 150px; /* Adjust this value according to your needs */
+ height: 50px; /* Adjust this value according to your needs */
+ overflow: hidden; /* This will hide any content that exceeds the cell size */
+ text-overflow: ellipsis; /* This will add '...' at the end if the content is too long */
+ white-space: nowrap; /* This will prevent the content from wrapping to the next line */
+ }
+ .table thead th {
+ position: sticky;
+ top: 0;
+ background: #fff;
+ z-index: 10;
}
- .cell{
- height: 10px;
+ .table td {
+ width: 150px; /* Adjust this value according to your needs */
+ overflow: hidden; /* This will hide any content that exceeds the cell size */
+ text-overflow: ellipsis; /* This will add '...' at the end if the content is too long */
+ white-space: nowrap; /* This will prevent the content from wrapping to the next line */
}
@media screen and (max-width: 600px) {
.table {
@@ -92,6 +107,23 @@
margin: 0;
padding: 0;
}
+ .page{
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ margin-top: 20px;
+ }
+ .page a{
+ padding:10px;
+ }
+ .inactive {
+ pointer-events: none;
+ color: grey;
+ }
+ .no-link-style {
+ color: inherit;
+ text-decoration: none;
+ }
@@ -108,19 +140,47 @@