backend/restservice/src/main/java/com/plannaplan/App.java

154 lines
6.7 KiB
Java
Raw Normal View History

2020-06-09 18:14:49 +02:00
package com.plannaplan;
2020-12-05 16:28:02 +01:00
import java.io.InputStream;
2020-12-09 16:43:29 +01:00
import java.sql.Date;
2021-01-02 13:45:03 +01:00
import java.util.Random;
2020-12-05 16:28:02 +01:00
import com.plannaplan.models.ConfigData;
2020-12-09 16:43:29 +01:00
import com.plannaplan.models.TourData;
import com.plannaplan.entities.User;
import com.plannaplan.services.UserService;
import com.plannaplan.types.UserRoles;
import org.springframework.beans.factory.annotation.Autowired;
2020-12-05 16:28:02 +01:00
import org.springframework.beans.factory.annotation.Value;
2020-06-09 18:14:49 +02:00
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
2020-11-04 15:06:24 +01:00
import org.springframework.context.event.EventListener;
2020-12-21 17:12:10 +01:00
import org.springframework.scheduling.annotation.EnableScheduling;
2020-12-05 16:28:02 +01:00
import com.plannaplan.services.ConfiguratorService;
2020-06-09 18:14:49 +02:00
2021-01-15 17:45:29 +01:00
/**
* Root class of Application.
*/
2020-06-09 18:14:49 +02:00
@SpringBootApplication
2020-12-21 17:12:10 +01:00
@EnableScheduling
2020-06-09 18:14:49 +02:00
public class App {
2020-06-10 10:53:22 +02:00
2020-10-01 16:46:45 +02:00
public final static String API_VERSION = "v1";
2020-12-05 16:28:02 +01:00
@Autowired
private ConfiguratorService contrl;
2020-10-01 16:46:45 +02:00
@Autowired
2021-01-02 13:45:03 +01:00
private UserService userService;
2020-10-01 16:46:45 +02:00
2020-12-05 16:28:02 +01:00
@Value("${plannaplan.dev}")
private boolean isDev;
2020-10-01 16:46:45 +02:00
public static void main(String[] args) {
Logo logo = new Logo("beta");
System.out.println(logo.getLogo());
System.out.println(
"|=============================================================================================|");
SpringApplication.run(App.class, args);
}
2020-12-11 16:18:43 +01:00
/**
* method to import mocked data to testing app after startz. It is called only
2021-01-14 14:51:22 +01:00
* in dev profile. Note that tests are written to this app state so if you
* change ConfigData it can have an impact to other tests like
* CommisionControllerTest
2020-12-11 16:18:43 +01:00
*/
2020-10-01 16:46:45 +02:00
@EventListener(ApplicationReadyEvent.class)
public void importData() {
2020-12-05 16:28:02 +01:00
System.out.println(Logo.getInitInfo(isDev));
if (this.isDev) {
2021-01-02 13:45:03 +01:00
final Random generator = new Random();
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
final ConfigData data = new ConfigData(
new TourData(new Date(System.currentTimeMillis() - 86400000),
new Date(System.currentTimeMillis())),
2020-12-11 15:27:38 +01:00
new TourData(new Date(System.currentTimeMillis() + 86400000),
new Date(System.currentTimeMillis() + 2 * 86400000)),
2020-12-09 16:43:29 +01:00
inputStream);
2020-12-05 16:28:02 +01:00
this.contrl.config(data);
User newuser = new User();
newuser.setEmail("tommy@st.amu.edu.pl");
newuser.setName("Tomek");
newuser.setSurname("Atomek");
2021-01-02 13:45:03 +01:00
newuser.setRanking(generator.nextInt(400) + 100);
2020-12-05 16:28:02 +01:00
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");
2021-01-02 13:45:03 +01:00
newuser.setRanking(generator.nextInt(400) + 100);
2020-12-05 16:28:02 +01:00
newuser.setRole(UserRoles.STUDENT);
this.userService.save(newuser);
newuser = new User();
newuser.setEmail("mewa@st.amu.edu.pl");
newuser.setName("Poznanska");
newuser.setSurname("Mewa");
2021-01-02 13:45:03 +01:00
newuser.setRanking(generator.nextInt(400) + 100);
2020-12-05 16:28:02 +01:00
newuser.setRole(UserRoles.STUDENT);
this.userService.save(newuser);
newuser = new User();
newuser.setEmail("tkul2@st.amu.edu.pl");
newuser.setName("Tomasz");
newuser.setSurname("Kula");
2021-01-02 13:45:03 +01:00
newuser.setRanking(generator.nextInt(400) + 100);
2020-12-05 16:28:02 +01:00
newuser.setRole(UserRoles.STUDENT);
this.userService.save(newuser);
newuser = new User();
newuser.setEmail("annana@st.amu.edu.pl");
newuser.setName("Anna");
newuser.setSurname("Na");
2021-01-02 13:45:03 +01:00
newuser.setRanking(generator.nextInt(400) + 100);
2020-12-05 16:28:02 +01:00
newuser.setRole(UserRoles.STUDENT);
this.userService.save(newuser);
newuser = new User();
newuser.setEmail("mnart@st.amu.edu.pl");
newuser.setName("Marta");
newuser.setSurname("Narta");
2021-01-02 13:45:03 +01:00
newuser.setRanking(generator.nextInt(400) + 100);
2020-12-05 16:28:02 +01:00
newuser.setRole(UserRoles.STUDENT);
this.userService.save(newuser);
newuser = new User();
newuser.setEmail("zmineniane@st.amu.edu.pl");
newuser.setName("Tutaj");
newuser.setSurname("Koncza");
2021-01-02 13:45:03 +01:00
newuser.setRanking(generator.nextInt(400) + 100);
2020-12-05 16:28:02 +01:00
newuser.setRole(UserRoles.STUDENT);
this.userService.save(newuser);
newuser = new User();
newuser.setEmail("mi@st.amu.edu.pl");
newuser.setName("Mi");
newuser.setSurname("Sie");
2021-01-02 13:45:03 +01:00
newuser.setRanking(generator.nextInt(400) + 100);
2020-12-05 16:28:02 +01:00
newuser.setRole(UserRoles.STUDENT);
this.userService.save(newuser);
newuser = new User();
newuser.setEmail("pms@st.amu.edu.pl");
newuser.setName("Pomysly");
newuser.setSurname("Sad");
2021-01-02 13:45:03 +01:00
newuser.setRanking(generator.nextInt(400) + 100);
2020-12-05 16:28:02 +01:00
newuser.setRole(UserRoles.STUDENT);
this.userService.save(newuser);
2020-12-18 15:24:01 +01:00
newuser = new User();
newuser.setEmail("iamnull@st.amu.edu.pl");
2021-01-02 13:45:03 +01:00
newuser.setRanking(generator.nextInt(400) + 100);
2020-12-18 15:24:01 +01:00
newuser.setRole(UserRoles.STUDENT);
this.userService.save(newuser);
2020-12-05 16:28:02 +01:00
}
System.out.println(Logo.getStartedInfo(isDev));
2020-10-01 16:46:45 +02:00
}
2020-06-09 18:14:49 +02:00
}