package etunicorn; import etunicorn.entity.Permission; import etunicorn.repository.PermissionRepository; import etunicorn.repository.PersonneRepository; import etunicorn.repository.RoleRepository; import etunicorn.repository.SessionRepository; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.DriverManagerDataSource; import javax.sql.DataSource; /** * etunicorn-server * Copyright © 2017 Le Club Info Polytech Lille * Tous droits réservés */ @SpringBootApplication @EnableAutoConfiguration @Configuration public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @Bean public CommandLineRunner demo(PermissionRepository permissionRepository, RoleRepository roleRepository, PersonneRepository personneRepository, SessionRepository sessionRepository) { return (args) -> { permissionRepository.save(new Permission("PERSONNE_ADD")); permissionRepository.save(new Permission("PERSONNE_EDIT")); permissionRepository.save(new Permission("PERSONNE_GET")); permissionRepository.save(new Permission("PERSONNE_LIST")); permissionRepository.save(new Permission("PERSONNE_REMOVE")); permissionRepository.save(new Permission("PERSONNE_ROLE")); permissionRepository.save(new Permission("ROLE_ADD")); permissionRepository.save(new Permission("ROLE_DELETE")); permissionRepository.save(new Permission("ROLE_PERMISSION_ADD")); permissionRepository.save(new Permission("ROLE_PERMISSION_LIST")); permissionRepository.save(new Permission("ROLE_PERMISSION_REMOVE")); // ... //roleRepository.save(new Role("admin", (List) permissionRepository.findAll())); //roleRepository.save(new Role("etudiant", new ArrayList<>())); //personneRepository.save(new Personne("546848", new Date(), "bverhaeg", roleRepository.findByNom("admin"))); //sessionRepository.save(new Session(personneRepository.findByLogin("bverhaeg"), "B", new Date(new Date().getTime() + 1000 * 60 * 10))); }; } @Bean public DataSource dataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://192.168.0.28:3306/bade"); dataSource.setUsername("bade"); dataSource.setPassword("bade"); return dataSource; } // Properties additionalProperties() { // Properties properties = new Properties(); // properties.setProperty("spring.jpa.hibernate.ddl-auto", "update"); // properties.setProperty("spring.jpa.database-platform", "org.hibernate.dialect.MySQL5Dialect"); // return properties; // } }