backend/restservice/src/main/java/com/plannaplan/App.java
2021-01-15 17:45:29 +01:00

154 lines
6.7 KiB
Java
Executable File

package com.plannaplan;
import java.io.InputStream;
import java.sql.Date;
import java.util.Random;
import com.plannaplan.models.ConfigData;
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;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.EnableScheduling;
import com.plannaplan.services.ConfiguratorService;
/**
* Root class of Application.
*/
@SpringBootApplication
@EnableScheduling
public class App {
public final static String API_VERSION = "v1";
@Autowired
private ConfiguratorService contrl;
@Autowired
private UserService userService;
@Value("${plannaplan.dev}")
private boolean isDev;
public static void main(String[] args) {
Logo logo = new Logo("beta");
System.out.println(logo.getLogo());
System.out.println(
"|=============================================================================================|");
SpringApplication.run(App.class, args);
}
/**
* method to import mocked data to testing app after startz. It is called only
* 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
*/
@EventListener(ApplicationReadyEvent.class)
public void importData() {
System.out.println(Logo.getInitInfo(isDev));
if (this.isDev) {
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())),
new TourData(new Date(System.currentTimeMillis() + 86400000),
new Date(System.currentTimeMillis() + 2 * 86400000)),
inputStream);
this.contrl.config(data);
User newuser = new User();
newuser.setEmail("tommy@st.amu.edu.pl");
newuser.setName("Tomek");
newuser.setSurname("Atomek");
newuser.setRanking(generator.nextInt(400) + 100);
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.setRanking(generator.nextInt(400) + 100);
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.setRanking(generator.nextInt(400) + 100);
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.setRanking(generator.nextInt(400) + 100);
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.setRanking(generator.nextInt(400) + 100);
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.setRanking(generator.nextInt(400) + 100);
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.setRanking(generator.nextInt(400) + 100);
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.setRanking(generator.nextInt(400) + 100);
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.setRanking(generator.nextInt(400) + 100);
newuser.setRole(UserRoles.STUDENT);
this.userService.save(newuser);
newuser = new User();
newuser.setEmail("iamnull@st.amu.edu.pl");
newuser.setRanking(generator.nextInt(400) + 100);
newuser.setRole(UserRoles.STUDENT);
this.userService.save(newuser);
}
System.out.println(Logo.getStartedInfo(isDev));
}
}