CurriculumsearchApplication.java 2.57 KB
Newer Older
Heti Abhishek Shah committed
1 2
package com.roshka;

Joel Florentin committed
3 4 5 6 7 8
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
9 10
import com.roshka.modelo.Ciudad;
import com.roshka.modelo.Departamento;
Joel Florentin committed
11 12 13
import com.roshka.modelo.Postulante;
import com.roshka.modelo.PostulanteTecnologia;
import com.roshka.modelo.Tecnologia;
14 15
import com.roshka.repositorio.CiudadRepository;
import com.roshka.repositorio.DepartamentoRepository;
Joel Florentin committed
16 17 18 19
import com.roshka.repositorio.PostulanteRepository;
import com.roshka.repositorio.TecnologiaRepository;

import org.springframework.boot.CommandLineRunner;
Heti Abhishek Shah committed
20 21
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
willgonzz committed
22
import org.springframework.boot.autoconfigure.domain.EntityScan;
Joel Florentin committed
23
import org.springframework.context.annotation.Bean;
willgonzz committed
24
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
Heti Abhishek Shah committed
25 26

@SpringBootApplication
willgonzz committed
27 28
@EnableJpaRepositories("com.roshka.repositorio")
@EntityScan("com.roshka.modelo")
Heti Abhishek Shah committed
29 30 31 32 33 34
public class CurriculumsearchApplication {

	public static void main(String[] args) {
		SpringApplication.run(CurriculumsearchApplication.class, args);
	}

Joel Florentin committed
35
	@Bean
36
	CommandLineRunner runner(PostulanteRepository postRepo,TecnologiaRepository tecRepo,DepartamentoRepository depR, CiudadRepository ciudR) {
Joel Florentin committed
37 38
		return args -> {
			try {
39 40 41 42 43 44 45 46 47 48 49 50 51 52
				// read json and write to db
				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>>(){};
				inputStream = TypeReference.class.getResourceAsStream("/json/postulante.json");
Joel Florentin committed
53 54 55
				List<Postulante> postulantes = mapper.readValue(inputStream,typeReference);
				postRepo.saveAll(postulantes);
				System.out.println("postulantes Saved!");
56
				
Joel Florentin committed
57 58 59 60 61 62 63 64 65 66
			} catch (IOException e){
				System.out.println("Unable to save tecnologias: " + e.getMessage());
			}

			
			
			
		};
	}

67
	
Heti Abhishek Shah committed
68
}