CurriculumsearchApplication.java 2.72 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.*;
import com.roshka.repositorio.*;
Joel Florentin committed
11 12

import org.springframework.boot.CommandLineRunner;
Heti Abhishek Shah committed
13 14
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
willgonzz committed
15
import org.springframework.boot.autoconfigure.domain.EntityScan;
Joel Florentin committed
16
import org.springframework.context.annotation.Bean;
willgonzz committed
17
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
18
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
Heti Abhishek Shah committed
19 20

@SpringBootApplication
willgonzz committed
21 22
@EnableJpaRepositories("com.roshka.repositorio")
@EntityScan("com.roshka.modelo")
Heti Abhishek Shah committed
23 24 25 26 27 28
public class CurriculumsearchApplication {

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

Joel Florentin committed
29
	@Bean
30 31
	CommandLineRunner runner(PostulanteRepository postRepo, TecnologiaRepository tecRepo, DepartamentoRepository depR,
							 CiudadRepository ciudR, RRHHUserRepository rrhhUserRepository) {
Joel Florentin committed
32 33
		return args -> {
			try {
34 35 36 37 38 39 40 41 42 43 44 45 46 47
				// 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
48 49 50
				List<Postulante> postulantes = mapper.readValue(inputStream,typeReference);
				postRepo.saveAll(postulantes);
				System.out.println("postulantes Saved!");
51 52 53 54 55 56 57 58
				String password = new BCryptPasswordEncoder().encode("test");
				RRHHUser testuser = new RRHHUser();
				testuser.setEmail("test@test.com");
				testuser.setFirstName("test");
				testuser.setLastName("test");
				testuser.setPassword(password);
				rrhhUserRepository.save(testuser);
				System.out.println("Usuario Test: \nEmail: test@test.com\nPassword: test");
59
				
Joel Florentin committed
60 61 62 63 64 65 66 67 68 69
			} catch (IOException e){
				System.out.println("Unable to save tecnologias: " + e.getMessage());
			}

			
			
			
		};
	}

70
	
Heti Abhishek Shah committed
71
}