Added init test data on dev profile
This commit is contained in:
		| @@ -1,24 +1,35 @@ | |||||||
| package com.plannaplan; | package com.plannaplan; | ||||||
|  |  | ||||||
|  | import java.io.InputStream; | ||||||
|  |  | ||||||
|  | import com.plannaplan.models.ConfigData; | ||||||
| import com.plannaplan.entities.User; | import com.plannaplan.entities.User; | ||||||
| import com.plannaplan.services.UserService; | import com.plannaplan.services.UserService; | ||||||
| import com.plannaplan.types.UserRoles; | import com.plannaplan.types.UserRoles; | ||||||
|  |  | ||||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||||
|  | import org.springframework.beans.factory.annotation.Value; | ||||||
| import org.springframework.boot.SpringApplication; | import org.springframework.boot.SpringApplication; | ||||||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||||
| import org.springframework.boot.context.event.ApplicationReadyEvent; | import org.springframework.boot.context.event.ApplicationReadyEvent; | ||||||
|  |  | ||||||
| import org.springframework.context.event.EventListener; | import org.springframework.context.event.EventListener; | ||||||
|  | import com.plannaplan.services.ConfiguratorService; | ||||||
|  |  | ||||||
| @SpringBootApplication | @SpringBootApplication | ||||||
| public class App { | public class App { | ||||||
|  |  | ||||||
|         public final static String API_VERSION = "v1"; |         public final static String API_VERSION = "v1"; | ||||||
|  |  | ||||||
|  |         @Autowired | ||||||
|  |         private ConfiguratorService contrl; | ||||||
|  |  | ||||||
|         @Autowired |         @Autowired | ||||||
|         UserService userService; |         UserService userService; | ||||||
|  |  | ||||||
|  |         @Value("${plannaplan.dev}") | ||||||
|  |         private boolean isDev; | ||||||
|  |  | ||||||
|         public static void main(String[] args) { |         public static void main(String[] args) { | ||||||
|                 Logo logo = new Logo("beta"); |                 Logo logo = new Logo("beta"); | ||||||
|                 System.out.println(logo.getLogo()); |                 System.out.println(logo.getLogo()); | ||||||
| @@ -29,6 +40,26 @@ public class App { | |||||||
|  |  | ||||||
|         @EventListener(ApplicationReadyEvent.class) |         @EventListener(ApplicationReadyEvent.class) | ||||||
|         public void importData() { |         public void importData() { | ||||||
|  |                 System.out.println(Logo.getInitInfo(isDev)); | ||||||
|  |  | ||||||
|  |                 if (this.isDev) { | ||||||
|  |                         InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx"); | ||||||
|  |                         ConfigData data = new ConfigData(null, null, inputStream); | ||||||
|  |                         this.contrl.config(data); | ||||||
|  |  | ||||||
|  |                         User filip = new User(); | ||||||
|  |                         filip.setEmail("filizy@st.amu.edu.pl"); | ||||||
|  |                         filip.setName("Filip"); | ||||||
|  |                         filip.setSurname("Izydorczyk"); | ||||||
|  |                         filip.setRole(UserRoles.ADMIN); | ||||||
|  |                         this.userService.save(filip); | ||||||
|  |  | ||||||
|  |                         User hub = new User(); | ||||||
|  |                         hub.setEmail("hubwrz1@st.amu.edu.pl"); | ||||||
|  |                         hub.setName("Hubert"); | ||||||
|  |                         hub.setSurname("Wrzesiński"); | ||||||
|  |                         hub.setRole(UserRoles.DEANERY); | ||||||
|  |                         this.userService.save(hub); | ||||||
|  |  | ||||||
|                         User mac = new User(); |                         User mac = new User(); | ||||||
|                         mac.setEmail("macglo2@st.amu.edu.pl"); |                         mac.setEmail("macglo2@st.amu.edu.pl"); | ||||||
| @@ -36,5 +67,79 @@ public class App { | |||||||
|                         mac.setSurname("Głowacki"); |                         mac.setSurname("Głowacki"); | ||||||
|                         mac.setRole(UserRoles.STUDENT); |                         mac.setRole(UserRoles.STUDENT); | ||||||
|                         this.userService.save(mac); |                         this.userService.save(mac); | ||||||
|  |  | ||||||
|  |                         User mar = new User(); | ||||||
|  |                         mar.setEmail("marwoz16@st.amu.edu.pl"); | ||||||
|  |                         mar.setName("Marcin"); | ||||||
|  |                         mar.setSurname("Woźniak"); | ||||||
|  |                         mar.setRole(UserRoles.ADMIN); | ||||||
|  |                         this.userService.save(mar); | ||||||
|  |  | ||||||
|  |                         User newuser = new User(); | ||||||
|  |                         newuser.setEmail("tommy@st.amu.edu.pl"); | ||||||
|  |                         newuser.setName("Tomek"); | ||||||
|  |                         newuser.setSurname("Atomek"); | ||||||
|  |                         newuser.setRole(UserRoles.STUDENT); | ||||||
|  |                         this.userService.save(newuser); | ||||||
|  |  | ||||||
|  |                         newuser = new User(); | ||||||
|  |                         newuser.setEmail("robercik@st.amu.edu.pl"); | ||||||
|  |                         newuser.setName("Robert"); | ||||||
|  |                         newuser.setSurname("Głowacki"); | ||||||
|  |                         newuser.setRole(UserRoles.STUDENT); | ||||||
|  |                         this.userService.save(newuser); | ||||||
|  |  | ||||||
|  |                         newuser = new User(); | ||||||
|  |                         newuser.setEmail("mewa@st.amu.edu.pl"); | ||||||
|  |                         newuser.setName("Poznanska"); | ||||||
|  |                         newuser.setSurname("Mewa"); | ||||||
|  |                         newuser.setRole(UserRoles.STUDENT); | ||||||
|  |                         this.userService.save(newuser); | ||||||
|  |  | ||||||
|  |                         newuser = new User(); | ||||||
|  |                         newuser.setEmail("tkul2@st.amu.edu.pl"); | ||||||
|  |                         newuser.setName("Tomasz"); | ||||||
|  |                         newuser.setSurname("Kula"); | ||||||
|  |                         newuser.setRole(UserRoles.STUDENT); | ||||||
|  |                         this.userService.save(newuser); | ||||||
|  |  | ||||||
|  |                         newuser = new User(); | ||||||
|  |                         newuser.setEmail("annana@st.amu.edu.pl"); | ||||||
|  |                         newuser.setName("Anna"); | ||||||
|  |                         newuser.setSurname("Na"); | ||||||
|  |                         newuser.setRole(UserRoles.STUDENT); | ||||||
|  |                         this.userService.save(newuser); | ||||||
|  |  | ||||||
|  |                         newuser = new User(); | ||||||
|  |                         newuser.setEmail("mnart@st.amu.edu.pl"); | ||||||
|  |                         newuser.setName("Marta"); | ||||||
|  |                         newuser.setSurname("Narta"); | ||||||
|  |                         newuser.setRole(UserRoles.STUDENT); | ||||||
|  |                         this.userService.save(newuser); | ||||||
|  |  | ||||||
|  |                         newuser = new User(); | ||||||
|  |                         newuser.setEmail("zmineniane@st.amu.edu.pl"); | ||||||
|  |                         newuser.setName("Tutaj"); | ||||||
|  |                         newuser.setSurname("Koncza"); | ||||||
|  |                         newuser.setRole(UserRoles.STUDENT); | ||||||
|  |                         this.userService.save(newuser); | ||||||
|  |  | ||||||
|  |                         newuser = new User(); | ||||||
|  |                         newuser.setEmail("mi@st.amu.edu.pl"); | ||||||
|  |                         newuser.setName("Mi"); | ||||||
|  |                         newuser.setSurname("Sie"); | ||||||
|  |                         newuser.setRole(UserRoles.STUDENT); | ||||||
|  |                         this.userService.save(newuser); | ||||||
|  |  | ||||||
|  |                         newuser = new User(); | ||||||
|  |                         newuser.setEmail("pms@st.amu.edu.pl"); | ||||||
|  |                         newuser.setName("Pomysly"); | ||||||
|  |                         newuser.setSurname("Sad"); | ||||||
|  |                         newuser.setRole(UserRoles.STUDENT); | ||||||
|  |                         this.userService.save(newuser); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|  |                 System.out.println(Logo.getStartedInfo(isDev)); | ||||||
|  |  | ||||||
|         } |         } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,11 +1,14 @@ | |||||||
| package com.plannaplan; | package com.plannaplan; | ||||||
|  |  | ||||||
|  | import java.time.LocalDateTime; | ||||||
|  | import java.time.format.DateTimeFormatter; | ||||||
|  |  | ||||||
| public class Logo { | public class Logo { | ||||||
|  |  | ||||||
|     public static final String ANSI_RESET = "\u001B[0m"; |     public static final String ANSI_RESET = "\u001B[0m"; | ||||||
|     public static final String ANSI_YELLOW = "\u001B[33m"; |     public static final String ANSI_YELLOW = "\u001B[33m"; | ||||||
|     public static final String ANSI_BLUE = "\u001B[34m"; |     public static final String ANSI_BLUE = "\u001B[34m"; | ||||||
|     public static final String ANSI_BLACK = "\u001B[30m"; |     public static final String ANSI_BLACK = "\u001B[37m"; | ||||||
|     private String version; |     private String version; | ||||||
|  |  | ||||||
|     public Logo(String version){ |     public Logo(String version){ | ||||||
| @@ -30,4 +33,25 @@ public class Logo { | |||||||
| ANSI_RESET; | ANSI_RESET; | ||||||
|         return result; |         return result; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
|  |     public static String getInitInfo(boolean isDev){ | ||||||
|  |         DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");   | ||||||
|  |         LocalDateTime now = LocalDateTime.now();  | ||||||
|  |  | ||||||
|  |         if(isDev){ | ||||||
|  |             return ANSI_BLACK + dtf.format(now) + ANSI_YELLOW + "  plannaplan" + ANSI_RESET + " initializing [" +ANSI_BLUE + "dev" + ANSI_RESET +"]"; | ||||||
|  |         } | ||||||
|  |         return ANSI_BLACK + dtf.format(now) + ANSI_YELLOW + "  plannaplan" + ANSI_RESET + " initializing [" +ANSI_BLUE + "prod" + ANSI_RESET +"]"; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static String getStartedInfo(boolean isDev){ | ||||||
|  |         DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");   | ||||||
|  |         LocalDateTime now = LocalDateTime.now();  | ||||||
|  |  | ||||||
|  |         if(isDev){ | ||||||
|  |             return ANSI_BLACK + dtf.format(now) +ANSI_YELLOW + "  plannaplan" + ANSI_RESET + " started [" +ANSI_BLUE + "dev" + ANSI_RESET +"]"; | ||||||
|  |         } | ||||||
|  |         return ANSI_BLACK + dtf.format(now) + ANSI_YELLOW + "  plannaplan" + ANSI_RESET + " started [" +ANSI_BLUE + "prod" + ANSI_RESET +"]"; | ||||||
|  |     } | ||||||
| } | } | ||||||
							
								
								
									
										
											BIN
										
									
								
								restservice/src/main/resources/Zajecia.xlsx
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								restservice/src/main/resources/Zajecia.xlsx
									
									
									
									
									
										Executable file
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -1 +1 @@ | |||||||
| spring.profiles.active=prod | spring.profiles.active=dev | ||||||
		Reference in New Issue
	
	Block a user