package etunicorn; import etunicorn.entity.Permission; import etunicorn.entity.Personne; import etunicorn.entity.Role; import etunicorn.entity.Session; 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.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import javax.sql.DataSource; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * etunicorn-server * Copyright © 2017 Le Club Info Polytech Lille * Tous droits réservés */ @SpringBootApplication @EnableAutoConfiguration 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("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("carte", new Date(), "gbontoux", roleRepository.findByNom("admin"))); sessionRepository.save(new Session(personneRepository.findByLogin("gbontoux"), "A", new Date(new Date().getTime() + 1000 * 60 * 10))); }; } @Bean public DataSource dataSource() { DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create(); dataSourceBuilder.driverClassName("org.sqlite.JDBC"); dataSourceBuilder.url("jdbc:sqlite:etunicorn.db"); return dataSourceBuilder.build(); } }