-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
593 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.perales.sepomex.model; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import java.time.LocalDateTime; | ||
import java.util.Objects; | ||
|
||
@Entity(name = "archivo") | ||
public class Archivo { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private int id; | ||
|
||
private LocalDateTime fechaCarga; | ||
|
||
@Column(columnDefinition = "TEXT") | ||
private String contenido; | ||
|
||
// Constructor vacío requerido por JPA | ||
public Archivo() { | ||
} | ||
|
||
// Constructor con todos los atributos | ||
public Archivo(int id, LocalDateTime fechaCarga, String contenido) { | ||
this.id = id; | ||
this.fechaCarga = fechaCarga; | ||
this.contenido = contenido; | ||
} | ||
|
||
// Getters y setters | ||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public LocalDateTime getFechaCarga() { | ||
return fechaCarga; | ||
} | ||
|
||
public void setFechaCarga(LocalDateTime fechaCarga) { | ||
this.fechaCarga = fechaCarga; | ||
} | ||
|
||
public String getContenido() { | ||
return contenido; | ||
} | ||
|
||
public void setContenido(String contenido) { | ||
this.contenido = contenido; | ||
} | ||
|
||
// Método equals generado automáticamente por IntelliJ IDEA | ||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Archivo archivo = (Archivo) o; | ||
return id == archivo.id && Objects.equals(fechaCarga, archivo.fechaCarga) && Objects.equals(contenido, archivo.contenido); | ||
} | ||
|
||
// Método hashCode generado automáticamente por IntelliJ IDEA | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, fechaCarga, contenido); | ||
} | ||
|
||
// Método toString generado automáticamente por IntelliJ IDEA | ||
@Override | ||
public String toString() { | ||
return "Archivo{" + | ||
"id=" + id + | ||
", fechaCarga=" + fechaCarga + | ||
", contenido='" + contenido + '\'' + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/perales/sepomex/repository/ArchivoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.perales.sepomex.repository; | ||
|
||
import com.perales.sepomex.model.Archivo; | ||
import com.perales.sepomex.model.AsentamientoTipo; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ArchivoRepository extends JpaRepository<Archivo, Integer> { | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/perales/sepomex/repository/ColoniaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
package com.perales.sepomex.repository; | ||
|
||
import com.perales.sepomex.model.Colonia; | ||
import com.perales.sepomex.model.Municipio; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.EntityGraph; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface ColoniaRepository extends JpaRepository<Colonia, Long> { | ||
|
||
Page<Colonia> findByMunicipioId(Integer municipioId, Pageable pageable); | ||
|
||
@EntityGraph(value = "Colonia.detail", type = EntityGraph.EntityGraphType.LOAD) | ||
Colonia findOneById(Long id); | ||
|
||
@Query("SELECT c FROM colonia c JOIN FETCH c.estado JOIN FETCH c.municipio WHERE c.codigoPostal.nombre = :codigoPostal") | ||
List<Colonia> findByCodigoPostal_Nombre(@Param("codigoPostal") String codigoPostal); | ||
|
||
List<Colonia> findByNombreAndMunicipioIdAndEstadoId(String nombreColonia, | ||
Integer municipioId, | ||
Integer estadoId); | ||
|
||
|
||
@Query("SELECT c FROM colonia c JOIN FETCH c.municipio m JOIN FETCH m.estado") | ||
List<Colonia> findAllColoniasWithEstadoAndMunicipio(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/perales/sepomex/repository/MunicipioRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,31 @@ | ||
package com.perales.sepomex.repository; | ||
|
||
import com.perales.sepomex.model.Estado; | ||
import com.perales.sepomex.model.Municipio; | ||
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.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
public interface MunicipioRepository extends JpaRepository<Municipio, Integer> { | ||
|
||
Municipio findFirstByNombreAndEstadoId(String nombre, Integer estadoId); | ||
|
||
Page<Municipio> findByEstadoIdOrderByNombre(Integer estadoId, Pageable pageable); | ||
|
||
@Query("SELECT m FROM municipio m JOIN FETCH m.estado WHERE m.nombre = :nombre") | ||
List<Municipio> findFirstByNombre(String nombre); | ||
|
||
@Query("SELECT m FROM municipio m JOIN FETCH m.estado e WHERE m.nombre = :nombreMunicipio AND e.nombre = :nombreEstado") | ||
Municipio findFirstByNombreAndNombreEstado(String nombreMunicipio, String nombreEstado); | ||
|
||
@Query("SELECT m FROM municipio m JOIN FETCH m.estado e WHERE m.nombre = :nombreMunicipio AND e.id = :idEstado") | ||
Municipio findFirstByNombreAndIdEstado(String nombreMunicipio, Integer idEstado); | ||
|
||
@Query("SELECT m FROM municipio m JOIN FETCH m.estado") | ||
List<Municipio> findAllMunicipiosWithEstado(); | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/perales/sepomex/service/ArchivoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.perales.sepomex.service; | ||
|
||
import com.perales.sepomex.contract.ServiceGeneric; | ||
import com.perales.sepomex.model.Archivo; | ||
import com.perales.sepomex.model.Archivo; | ||
import com.perales.sepomex.repository.ArchivoRepository; | ||
import org.apache.lucene.search.Query; | ||
import org.hibernate.search.jpa.FullTextEntityManager; | ||
import org.hibernate.search.jpa.Search; | ||
import org.hibernate.search.query.dsl.QueryBuilder; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
@Service | ||
public class ArchivoService implements ServiceGeneric<Archivo, Integer> { | ||
|
||
@Autowired | ||
private ArchivoRepository ArchivoRepository; | ||
|
||
@PersistenceContext | ||
private EntityManager em; | ||
|
||
@Transactional(readOnly = true) | ||
public Archivo buscarPorId(Integer id) { | ||
return ArchivoRepository.findById(id).get(); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public Page<Archivo> buscarTodos(int page, int size) { | ||
int firstResult = page * size; | ||
return ArchivoRepository.findAll( PageRequest.of( firstResult, size) ); | ||
} | ||
|
||
@Transactional | ||
public Archivo guardar(Archivo entity) { | ||
return ArchivoRepository.save(entity); | ||
} | ||
|
||
@Transactional | ||
public Archivo actualizar(Archivo entity) { | ||
return ArchivoRepository.saveAndFlush(entity); | ||
} | ||
|
||
@Transactional | ||
public Archivo borrar(Integer id) { | ||
Archivo Archivo = ArchivoRepository.findById(id).get(); | ||
ArchivoRepository.deleteById(id); | ||
return Archivo; | ||
} | ||
} |
Oops, something went wrong.