Commit b44ae606 by willgonzz

Creacion de modelos y repositorios de Cuidad y departamento

parent 7b2e1fe1
...@@ -6,9 +6,13 @@ import java.util.List; ...@@ -6,9 +6,13 @@ import java.util.List;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.roshka.modelo.Ciudad;
import com.roshka.modelo.Departamento;
import com.roshka.modelo.Postulante; import com.roshka.modelo.Postulante;
import com.roshka.modelo.PostulanteTecnologia; import com.roshka.modelo.PostulanteTecnologia;
import com.roshka.modelo.Tecnologia; import com.roshka.modelo.Tecnologia;
import com.roshka.repositorio.CiudadRepository;
import com.roshka.repositorio.DepartamentoRepository;
import com.roshka.repositorio.PostulanteRepository; import com.roshka.repositorio.PostulanteRepository;
import com.roshka.repositorio.TecnologiaRepository; import com.roshka.repositorio.TecnologiaRepository;
...@@ -29,16 +33,27 @@ public class CurriculumsearchApplication { ...@@ -29,16 +33,27 @@ public class CurriculumsearchApplication {
} }
@Bean @Bean
CommandLineRunner runner(PostulanteRepository postRepo,TecnologiaRepository tecRepo) { CommandLineRunner runner(PostulanteRepository postRepo,TecnologiaRepository tecRepo,DepartamentoRepository depR, CiudadRepository ciudR) {
return args -> { return args -> {
try {
// read json and write to db // read json and write to db
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
TypeReference<List<Departamento>> typeReference1 = new TypeReference<List<Departamento>>(){};
InputStream inputStream = TypeReference.class.getResourceAsStream("/json/Departamento.json");
List<Departamento> departamento= mapper.readValue(inputStream,typeReference1);
depR.saveAll(departamento);
System.out.println("Departamentos Saved!");
TypeReference<List<Ciudad>> typeReference2 = new TypeReference<List<Ciudad>>(){};
inputStream = TypeReference.class.getResourceAsStream("/json/Ciudad.json");
List<Ciudad> ciudades= mapper.readValue(inputStream,typeReference2);
ciudR.saveAll(ciudades);
System.out.println("Cuidad Saved!");
TypeReference<List<Postulante>> typeReference = new TypeReference<List<Postulante>>(){}; TypeReference<List<Postulante>> typeReference = new TypeReference<List<Postulante>>(){};
InputStream inputStream = TypeReference.class.getResourceAsStream("/json/postulante.json"); inputStream = TypeReference.class.getResourceAsStream("/json/postulante.json");
try {
List<Postulante> postulantes = mapper.readValue(inputStream,typeReference); List<Postulante> postulantes = mapper.readValue(inputStream,typeReference);
postRepo.saveAll(postulantes); postRepo.saveAll(postulantes);
System.out.println("postulantes Saved!"); System.out.println("postulantes Saved!");
} catch (IOException e){ } catch (IOException e){
System.out.println("Unable to save tecnologias: " + e.getMessage()); System.out.println("Unable to save tecnologias: " + e.getMessage());
} }
......
package com.roshka.modelo;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name="ciudad")
public class Ciudad{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Long id;
@Column(name="nombre")
public String nombre;
@Column(name="departamento_id")
private Long departamentoId;
public Long getDepartamentoId() {
return this.departamentoId;
}
public void setDepartamentoId(Long departamentoId) {
this.departamentoId = departamentoId;
}
@ManyToOne(targetEntity = Departamento.class,fetch = FetchType.EAGER)
@JoinColumn(name="departamento_id",insertable = false, updatable = false)
private Departamento departamento;
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getNombre() {
return this.nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public Departamento getDepartamento() {
return this.departamento;
}
public void setDepartamento(Departamento departamento) {
this.departamento = departamento;
}
}
package com.roshka.modelo;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name="departamento")
public class Departamento {
@Id
private Long id;
@Column(name="nombre")
private String nombre;
@OneToMany(mappedBy = "departamento",cascade = CascadeType.ALL)
private List<Ciudad> ciudad;
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getNombre() {
return this.nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public List<Ciudad> getCiudad() {
return this.ciudad;
}
public void setCiudad(List<Ciudad> ciudad) {
this.ciudad = ciudad;
}
}
\ No newline at end of file
...@@ -39,10 +39,28 @@ public class Postulante { ...@@ -39,10 +39,28 @@ public class Postulante {
@Email(message = "Formato incorrecto de correo") @Email(message = "Formato incorrecto de correo")
private String correo; private String correo;
@Column(name = "ciudad") @ManyToOne(targetEntity = Ciudad.class,fetch = FetchType.EAGER)
@NotBlank(message = "Este campo no puede estar vacio") @JoinColumn(name="ciudad_id",insertable = false, updatable = false)
@Size(max = 120) private Ciudad ciudad;
private String ciudad; @Column(name="ciudad_id")
private Long ciudadId;
public Ciudad getCiudad() {
return this.ciudad;
}
public void setCiudad(Ciudad ciudad) {
this.ciudad = ciudad;
}
public Long getCiudadId() {
return this.ciudadId;
}
public void setCiudadId(Long ciudadId) {
this.ciudadId = ciudadId;
}
@Column(name = "telefono") @Column(name = "telefono")
@NotBlank(message = "Este campo no puede estar vacio") @NotBlank(message = "Este campo no puede estar vacio")
...@@ -124,14 +142,6 @@ public class Postulante { ...@@ -124,14 +142,6 @@ public class Postulante {
this.correo = correo; this.correo = correo;
} }
public String getCiudad() {
return ciudad;
}
public void setCiudad(String ciudad) {
this.ciudad = ciudad;
}
public String getTelefono() { public String getTelefono() {
return telefono; return telefono;
} }
......
...@@ -12,7 +12,7 @@ import javax.persistence.Table; ...@@ -12,7 +12,7 @@ import javax.persistence.Table;
import javax.persistence.UniqueConstraint; import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Max; import javax.validation.constraints.Max;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonBackReference;
@Entity @Entity
...@@ -37,6 +37,7 @@ public class PostulanteTecnologia { ...@@ -37,6 +37,7 @@ public class PostulanteTecnologia {
@JoinColumn @JoinColumn
@JsonBackReference @JsonBackReference
private Postulante postulante; private Postulante postulante;
public long getId() { public long getId() {
return id; return id;
} }
......
...@@ -7,7 +7,7 @@ import javax.persistence.GenerationType; ...@@ -7,7 +7,7 @@ import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.util.Locale;
@Entity @Entity
@Table(name="tecnologia") @Table(name="tecnologia")
......
package com.roshka.repositorio;
import com.roshka.modelo.Ciudad;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CiudadRepository extends JpaRepository<Ciudad,Long> {
}
package com.roshka.repositorio;
import com.roshka.modelo.Departamento;
import org.springframework.data.jpa.repository.JpaRepository;
public interface DepartamentoRepository extends JpaRepository<Departamento,Long> {
}
...@@ -6,7 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository; ...@@ -6,7 +6,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import com.roshka.modelo.Postulante; import com.roshka.modelo.Postulante;
import com.roshka.modelo.PostulanteTecnologia;
public interface PostulanteRepository extends JpaRepository<Postulante,Long> { public interface PostulanteRepository extends JpaRepository<Postulante,Long> {
......
package com.roshka.repositorio; package com.roshka.repositorio;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import com.roshka.modelo.PostulanteTecnologia; import com.roshka.modelo.PostulanteTecnologia;
......
[
{
"id": 0,
"nombre": "ASUNCION"
},
{
"id": 1,
"nombre": "CONCEPCION"
},
{
"id": 2,
"nombre": "SAN PEDRO"
},
{
"id": 3,
"nombre": "CORDILLERA"
},
{
"id": 4,
"nombre": "GUAIRA"
},
{
"id": 5,
"nombre": "CAAGUAZU"
},
{
"id": 6,
"nombre": "CAAZAPA"
},
{
"id": 7,
"nombre": "ITAPUA"
},
{
"id": 8,
"nombre": "MISIONES"
},
{
"id": 9,
"nombre": "PARAGUARI"
},
{
"id": 10,
"nombre": "ALTO PARANA"
},
{
"id": 11,
"nombre": "CENTRAL"
},
{
"id": 12,
"nombre": "NEEMBUCU"
},
{
"id": 13,
"nombre": "AMAMBAY"
},
{
"id": 14,
"nombre": "CANINDEYU"
},
{
"id": 15,
"nombre": "PRESIDENTE HAYES"
},
{
"id": 16,
"nombre": "BOQUERON"
},
{
"id": 17,
"nombre": "ALTO PARAGUAY"
}
]
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment