Merge pull request 'config' (#4) from config into master
Reviewed-on: http://git.plannaplan.pl/filipizydorczyk/backend/pulls/4
This commit is contained in:
commit
6bbabd2d78
12
README.md
12
README.md
@ -46,6 +46,18 @@ cd restservice
|
||||
mvn spring-boot:run
|
||||
```
|
||||
|
||||
## Packaging
|
||||
|
||||
Zeby spakowac apke do `jara` wystarcza dwie komendy
|
||||
|
||||
```
|
||||
cd restservice
|
||||
mvn clean package spring-boot:repackage
|
||||
|
||||
```
|
||||
|
||||
Utworzony zostanie jar w `restservice/target/restservice-1.0-SNAPSHOT.jar`. Oczywiscie zeby jar zadzialal kontenery dockerowe musza byc odpalone (lub baza danych na serwerze jesli zmienialismy propertisy z localhost)
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
Spring chyba cacheuje jakies dane dotyczace polaczenia wiec jesli spring wywali Ci blad `Connection Refused`, a wiesz, ze ta baza stoi na podanym ip i porcie to sprobuj
|
||||
|
@ -36,19 +36,35 @@
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.18</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.18</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- dependency used for XLSX file format -->
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>3.17</version>
|
||||
</dependency>
|
||||
|
||||
<!-- dependency used for XLS older file format
|
||||
(added for information) -->
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>3.17</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||
<pluginManagement>
|
||||
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||
<plugins>
|
||||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||
<plugin>
|
||||
|
@ -2,13 +2,36 @@ package com.plannaplan;
|
||||
|
||||
import com.plannaplan.interfaces.ProtectedAction;
|
||||
import com.plannaplan.models.ConfigData;
|
||||
import com.plannaplan.models.FileData;
|
||||
import com.plannaplan.services.CourseService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.services.LecturerService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.plannaplan.configutils.*;
|
||||
|
||||
@Component
|
||||
public class Configurator implements ProtectedAction {
|
||||
|
||||
@Autowired
|
||||
private LecturerService lecturerService;
|
||||
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
public Configurator() {
|
||||
}
|
||||
|
||||
public void config(ConfigData data) {
|
||||
FileReader reader = new FileReader(data.getFilestream());
|
||||
FileData coursesData = reader.read();
|
||||
FileToDatabaseMigrator mgtr = new FileToDatabaseMigrator(lecturerService, courseService, groupService);
|
||||
mgtr.migrate(coursesData);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,16 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import com.plannaplan.models.ConfigData;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Controller {
|
||||
|
||||
@Autowired
|
||||
private Configurator configurator;
|
||||
|
||||
public Controller() {
|
||||
}
|
||||
|
||||
@ -22,7 +32,8 @@ public class Controller {
|
||||
public void getHistoryAtPoint() {
|
||||
}
|
||||
|
||||
public void config() {
|
||||
public void config(ConfigData data) {
|
||||
configurator.config(data);
|
||||
}
|
||||
|
||||
public void createTransfer() {
|
||||
|
@ -0,0 +1,56 @@
|
||||
package com.plannaplan.configutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import com.plannaplan.models.FileData;
|
||||
|
||||
public class FileReader {
|
||||
|
||||
private InputStream fileInputStream;
|
||||
|
||||
public FileReader(InputStream fileInputStream) {
|
||||
this.fileInputStream = fileInputStream;
|
||||
}
|
||||
|
||||
public FileData read() {
|
||||
|
||||
FileData result = null;
|
||||
|
||||
try {
|
||||
InputStream fis = this.fileInputStream;
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(fis);
|
||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||
|
||||
Iterator<Row> rowIt = sheet.iterator();
|
||||
|
||||
Row row = rowIt.next();
|
||||
Iterator<Cell> cellIt = row.cellIterator();
|
||||
|
||||
Hashtable<String, Integer> keys = new Hashtable<>();
|
||||
int index = 0;
|
||||
while (cellIt.hasNext()) {
|
||||
Cell c = cellIt.next();
|
||||
keys.put(c.toString(), index);
|
||||
index+=1;
|
||||
}
|
||||
|
||||
rowIt.remove();
|
||||
result = new FileData(keys, rowIt);
|
||||
workbook.close();
|
||||
fis.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,148 @@
|
||||
package com.plannaplan.configutils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
import com.plannaplan.models.FileData;
|
||||
import com.plannaplan.services.CourseService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.services.LecturerService;
|
||||
import com.plannaplan.types.GroupType;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
|
||||
public class FileToDatabaseMigrator {
|
||||
public FileToDatabaseMigrator() {
|
||||
public static String LECTURER_NAME_STRING = "imie";
|
||||
public static String LECTURER_SURNAME_STRING = "nazwisko";
|
||||
public static String LECTURER_TITLE_STRING = "tytul";
|
||||
|
||||
public static String COURSE_SYMBOL_STRING = "sym";
|
||||
public static String COURSE_NAME_STRING = "nazwa";
|
||||
|
||||
public static String GROUP_DAY_STRING = "dzien";
|
||||
public static String GROUP_TIME_STRING = "godz_od";
|
||||
public static String ROOM_STRING = "sala";
|
||||
public static String CAPACITY_STRING = "Mc";
|
||||
|
||||
LecturerService lecturerService;
|
||||
CourseService courseService;
|
||||
GroupService groupService;
|
||||
|
||||
public FileToDatabaseMigrator(LecturerService lecturerService, CourseService courseService,
|
||||
GroupService groupService) {
|
||||
this.lecturerService = lecturerService;
|
||||
this.groupService = groupService;
|
||||
this.courseService = courseService;
|
||||
}
|
||||
|
||||
public void migrate(File file) {
|
||||
public void migrate(FileData data) {
|
||||
Iterator<Row> rows = data.getRows();
|
||||
|
||||
int course_name_index = data.getIndexOf(FileToDatabaseMigrator.COURSE_NAME_STRING);
|
||||
int sym_index = data.getIndexOf(FileToDatabaseMigrator.COURSE_SYMBOL_STRING);
|
||||
|
||||
int title_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_TITLE_STRING);
|
||||
int surname_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_SURNAME_STRING);
|
||||
int name_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_NAME_STRING);
|
||||
|
||||
int day_index = data.getIndexOf(FileToDatabaseMigrator.GROUP_DAY_STRING);
|
||||
int time_index = data.getIndexOf(FileToDatabaseMigrator.GROUP_TIME_STRING);
|
||||
int room_index = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
||||
int capacity_index = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
|
||||
|
||||
while (rows.hasNext()) {
|
||||
Row row = rows.next();
|
||||
|
||||
Cell course_name_cell = row.getCell(course_name_index);
|
||||
Cell sym = row.getCell(sym_index);
|
||||
|
||||
Cell title_cell = row.getCell(title_index);
|
||||
Cell name_cell = row.getCell(name_index);
|
||||
Cell surname_cell = row.getCell(surname_index);
|
||||
|
||||
Cell day_cell = row.getCell(day_index);
|
||||
Cell time_cell = row.getCell(time_index);
|
||||
Cell room_cell = row.getCell(room_index);
|
||||
Cell capacity_cell = row.getCell(capacity_index);
|
||||
|
||||
String lecturer_title = "";
|
||||
String lecturer_surname = "";
|
||||
String lecturer_name = "";
|
||||
|
||||
String course_name = course_name_cell.toString().trim();
|
||||
String sym_str = sym.toString().trim();
|
||||
|
||||
int day = (int) Double.parseDouble(day_cell.toString());
|
||||
WeekDay group_day = WeekDay.getDay(day);
|
||||
String room = room_cell.toString().trim();
|
||||
int time = this.parseTimeToInt(time_cell.toString());
|
||||
|
||||
int capacity = (int) Double.parseDouble(capacity_cell.toString());
|
||||
|
||||
Groups group = groupService.find(time, capacity, room);
|
||||
|
||||
Course course = this.courseService.getCourseByName(course_name);
|
||||
|
||||
if (course == null) {
|
||||
course = new Course();
|
||||
course.setName(course_name);
|
||||
course.setSymbol(sym_str);
|
||||
}
|
||||
|
||||
courseService.save(course);
|
||||
|
||||
if (title_cell != null) {
|
||||
lecturer_title = title_cell.toString().trim();
|
||||
}
|
||||
if (name_cell != null) {
|
||||
lecturer_name = name_cell.toString().trim();
|
||||
}
|
||||
if (surname_cell != null) {
|
||||
lecturer_surname = surname_cell.toString().trim();
|
||||
}
|
||||
|
||||
Lecturer lecturer = lecturerService.getLecturer(lecturer_title, lecturer_name, lecturer_surname);
|
||||
|
||||
if (lecturer == null) {
|
||||
lecturer = new Lecturer(lecturer_title, lecturer_name, lecturer_surname);
|
||||
lecturerService.save(lecturer);
|
||||
}
|
||||
|
||||
if (group == null) {
|
||||
group = new Groups();
|
||||
group.setCapacity(capacity);
|
||||
group.setRoom(room);
|
||||
group.setCourseId(course);
|
||||
group.setTime(time);
|
||||
if (capacity >= 50) {
|
||||
group.setType(GroupType.LECTURE);
|
||||
} else {
|
||||
group.setType(GroupType.CLASS);
|
||||
}
|
||||
group.setDay(group_day);
|
||||
group.setLecturer(lecturer);
|
||||
|
||||
groupService.save(group);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Integer parseTimeToInt(String time) {
|
||||
String times[] = time.split("\\.");
|
||||
if (times.length == 2) {
|
||||
return Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]);
|
||||
}
|
||||
times = time.split("\\:");
|
||||
if (times.length == 2) {
|
||||
return Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
@ -16,12 +17,16 @@ public class Course {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String symbol;
|
||||
@OneToMany(mappedBy = "id")
|
||||
@OneToMany(mappedBy = "courseId", fetch = FetchType.EAGER)
|
||||
private List<Groups> groups = new ArrayList<>();
|
||||
|
||||
public Course() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@ -38,4 +43,8 @@ public class Course {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Groups> getGroups(){
|
||||
return this.groups;
|
||||
}
|
||||
|
||||
}
|
@ -30,6 +30,10 @@ public class Groups {
|
||||
public Groups() {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public Lecturer getLecturer() {
|
||||
return lecturer;
|
||||
}
|
||||
@ -85,4 +89,14 @@ public class Groups {
|
||||
public void setCourseId(Course courseId) {
|
||||
this.courseId = courseId;
|
||||
}
|
||||
|
||||
public String getTimeString() {
|
||||
int minutes = this.getTime() % 60;
|
||||
String hoursString = Integer.toString(this.getTime() / 60);
|
||||
String minutesString = Integer.toString(minutes);
|
||||
if (minutes < 10) {
|
||||
minutesString = "0" + minutesString;
|
||||
}
|
||||
return String.format("%s.%s", hoursString, minutesString);
|
||||
}
|
||||
}
|
@ -14,9 +14,6 @@ public class Lecturer {
|
||||
private String name;
|
||||
private String surname;
|
||||
|
||||
public Lecturer() {
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
@ -41,4 +38,18 @@ public class Lecturer {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public Lecturer(String title, String name, String surname) {
|
||||
this.title = title;
|
||||
this.name = name;
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
public Lecturer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s %s %s", this.title, this.name, this.surname);
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +1,21 @@
|
||||
package com.plannaplan.models;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ConfigData {
|
||||
private Date start;
|
||||
private Date end;
|
||||
private File file;
|
||||
private InputStream filestream;
|
||||
|
||||
public ConfigData(Date start, Date end, File file) {
|
||||
public ConfigData(Date start, Date end, InputStream filestream) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.file = file;
|
||||
this.filestream = filestream;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
public InputStream getFilestream() {
|
||||
return filestream;
|
||||
}
|
||||
|
||||
public Date getEnd() {
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.plannaplan.models;
|
||||
|
||||
import java.util.Dictionary;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
|
||||
public class FileData {
|
||||
|
||||
private Dictionary<String, Integer> keys;
|
||||
private Iterator<Row> rows;
|
||||
|
||||
public FileData(Dictionary<String, Integer> keys, Iterator<Row> rows) {
|
||||
this.setKeys(keys);
|
||||
this.setRows(rows);
|
||||
}
|
||||
|
||||
public Iterator<Row> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
public void setRows(Iterator<Row> rows) {
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
public Dictionary<String, Integer> getKeys() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
public void setKeys(Dictionary<String, Integer> keys) {
|
||||
this.keys = keys;
|
||||
}
|
||||
|
||||
public int getIndexOf(String key) {
|
||||
int index = this.keys.get(key);
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
@ -3,9 +3,12 @@ package com.plannaplan.repositories;
|
||||
import com.plannaplan.entities.Course;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface CourseRepository extends JpaRepository<Course, Long> {
|
||||
|
||||
@Query(value = "SELECT * FROM course WHERE name = :name", nativeQuery = true)
|
||||
Course findByName(@Param("name") String name);
|
||||
}
|
@ -1,11 +1,20 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface GroupRepository extends JpaRepository<Groups, Long> {
|
||||
@Query(value = "SELECT * FROM groups WHERE time = :time AND room = :room AND capacity = :capacity ", nativeQuery = true)
|
||||
Groups find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity);
|
||||
|
||||
@Query(value = "SELECT * FROM groups WHERE course_id = :id", nativeQuery = true)
|
||||
List<Groups> getByCourse(@Param("id") Long id);
|
||||
|
||||
}
|
@ -3,10 +3,12 @@ package com.plannaplan.repositories;
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
|
||||
public interface LecturerRepository extends JpaRepository<Lecturer, Long> {
|
||||
|
||||
@Query(value = "SELECT * FROM lecturer WHERE name = :name AND surname = :surname AND title = :title ", nativeQuery = true)
|
||||
Lecturer find(@Param("title") String title, @Param("name") String name, @Param("surname") String surname);
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.repositories.CourseRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -9,4 +12,16 @@ import org.springframework.stereotype.Service;
|
||||
public class CourseService {
|
||||
@Autowired
|
||||
private CourseRepository repo;
|
||||
|
||||
public Course getCourseByName(String name) {
|
||||
return this.repo.findByName(name);
|
||||
}
|
||||
|
||||
public List<Course> getAllCourses() {
|
||||
return this.repo.findAll();
|
||||
}
|
||||
|
||||
public void save(Course course) {
|
||||
this.repo.save(course);
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.repositories.GroupRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -9,4 +12,19 @@ import org.springframework.stereotype.Service;
|
||||
public class GroupService {
|
||||
@Autowired
|
||||
private GroupRepository repo;
|
||||
|
||||
public GroupService() {
|
||||
}
|
||||
|
||||
public Groups find(int time, int capacity, String room) {
|
||||
return this.repo.find(time, room, capacity);
|
||||
}
|
||||
|
||||
public List<Groups> getGroupsByCourse(Long id) {
|
||||
return this.repo.getByCourse(id);
|
||||
}
|
||||
|
||||
public void save(Groups group) {
|
||||
this.repo.save(group);
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
import com.plannaplan.repositories.LecturerRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -9,4 +10,12 @@ import org.springframework.stereotype.Service;
|
||||
public class LecturerService {
|
||||
@Autowired
|
||||
private LecturerRepository repo;
|
||||
|
||||
public Lecturer getLecturer(String title, String name, String surname) {
|
||||
return repo.find(title, name, surname);
|
||||
}
|
||||
|
||||
public void save(Lecturer lecturer) {
|
||||
repo.save(lecturer);
|
||||
}
|
||||
}
|
@ -8,4 +8,13 @@ public enum WeekDay {
|
||||
private WeekDay(int label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public static WeekDay getDay(int index) {
|
||||
for (WeekDay d : values()) {
|
||||
if (d.label == index) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.plannaplan.configutils;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.plannaplan.models.FileData;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class FileReaderTest {
|
||||
@Test
|
||||
public void shoulReturnNull() {
|
||||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
|
||||
FileReader r = new FileReader(inputStream);
|
||||
FileData d = r.read();
|
||||
assertTrue(d.getRows().next().getCell(0).toString().equals("1.0"));
|
||||
assertTrue(d.getKeys().size() == 22);
|
||||
assertTrue(d != null);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.plannaplan.configutils;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.plannaplan.models.FileData;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class FileToDatabaseMigratorTest {
|
||||
@Test
|
||||
public void shouldInsertToDatabase() {
|
||||
// FileToDatabaseMigrator migrator = new FileToDatabaseMigrator();
|
||||
// InputStream inputStream =
|
||||
// getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
|
||||
// FileReader r = new FileReader(inputStream);
|
||||
// FileData d = r.read();
|
||||
// migrator.migrate(d);
|
||||
}
|
||||
}
|
BIN
buisnesslogic/src/test/resources/Zajecia.xlsx
Normal file
BIN
buisnesslogic/src/test/resources/Zajecia.xlsx
Normal file
Binary file not shown.
@ -1,6 +1,10 @@
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
|
||||
spring.datasource.url=jdbc:mysql://172.20.0.2:3306/test
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=yes&characterEncoding=UTF-8
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=example
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.jpa.open-in-view=true
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
||||
spring.jackson.serialization.fail-on-empty-beans=false
|
||||
|
||||
server.port=1285
|
56
docs/api.md
Normal file
56
docs/api.md
Normal file
@ -0,0 +1,56 @@
|
||||
# Dokumetacja API
|
||||
|
||||
| Api | Zadania tej klasy |
|
||||
| ---------------------------------------------- | ---------------------------------------------------------------- |
|
||||
| [/config](#config) | Załadowanie konfiguracji startowej do aplikacji PlanNaPlan |
|
||||
| [/getCoursesWithGroups](#getCoursesWithGroups) | Zwrócenie wszytskich kursów (ćwiczenia, wykłady) razem z grupami |
|
||||
| [/getCourseGroups](#getCourseGroups) | Zwrócenie grup dla danego kursu |
|
||||
|
||||
## config
|
||||
|
||||
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/ConfigController.java)
|
||||
|
||||
```
|
||||
POST /config
|
||||
```
|
||||
|
||||
#### Description
|
||||
|
||||
Endpoint konfigurujacy caly system i importujacy dane do bazy.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Type | Name | Consumes | Description | Type |
|
||||
| ---- | ----------------------- | ------------------- | ------------------------------- | ---- |
|
||||
| Body | **file** </br> required | multipart/form-data | Plik .xlsx z potrzebnymi danymi | file |
|
||||
|
||||
## getCoursesWithGroups
|
||||
|
||||
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/getCoursesWithGroups.java)
|
||||
|
||||
```
|
||||
GET /getCoursesWithGroups
|
||||
```
|
||||
|
||||
#### Description
|
||||
|
||||
Zwraca wszystkie dostepne kursy wraz z lista grup dla poszczegolnych kursow.
|
||||
|
||||
## getCourseGroups
|
||||
|
||||
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/GroupController.java)
|
||||
|
||||
```
|
||||
GET /getCourseGroups
|
||||
```
|
||||
|
||||
#### Description
|
||||
|
||||
Endpoint konfigurujacy caly system i importujacy dane do bazy.
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Type | Name | Consumes | Description | Type |
|
||||
| ----------- | --------------------- | -------- | ----------------------------------------- | ---- |
|
||||
| Query Param | **id** </br> required | - | id kursu dla ktorego chcemy zwrocic grupy | int |
|
||||
| Query Param | **capacity** </br> | - | czy ma zwrocic pole pojemnosci grupy | bool |
|
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,7 @@
|
||||
<artifactId>backend</artifactId>
|
||||
<groupId>com.plannaplan</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
</parent>
|
||||
|
||||
<groupId>com.plannaplan</groupId>
|
||||
@ -19,6 +20,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<start-class>com.plannaplan.App</start-class>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -28,23 +30,23 @@
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<artifactId>buisnesslogic</artifactId>
|
||||
@ -54,7 +56,8 @@
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||
<pluginManagement>
|
||||
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
|
||||
<plugins>
|
||||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
|
||||
<plugin>
|
||||
|
@ -7,7 +7,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
Logo logo = new Logo("beta");
|
||||
System.out.println(logo.getLogo());
|
||||
System.out.println("|=============================================================================================|");
|
||||
SpringApplication.run(App.class, args);
|
||||
}
|
||||
}
|
||||
|
33
restservice/src/main/java/com/plannaplan/Logo.java
Normal file
33
restservice/src/main/java/com/plannaplan/Logo.java
Normal file
@ -0,0 +1,33 @@
|
||||
package com.plannaplan;
|
||||
|
||||
public class Logo {
|
||||
|
||||
public static final String ANSI_RESET = "\u001B[0m";
|
||||
public static final String ANSI_YELLOW = "\u001B[33m";
|
||||
public static final String ANSI_BLUE = "\u001B[34m";
|
||||
public static final String ANSI_BLACK = "\u001B[30m";
|
||||
private String version;
|
||||
|
||||
public Logo(String version){
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getLogo(){
|
||||
String result = ANSI_YELLOW +
|
||||
" .,,,,, \n"+
|
||||
" .,,,,,,,,,,,,, \n" +
|
||||
" .,,,,,,,,,,,,,,,,,,,,, \n" +
|
||||
" .,,,,,,,(,,,,,,,,,,,,,,,,,,,,, \n" +
|
||||
" ,,,,,,,(,,,,,,,,,,,,,,,,,,,,,,,,,,,,. \n" +
|
||||
" ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,. " + ANSI_RESET + " _ _ \n"+
|
||||
" * " + ANSI_YELLOW +",,,,,,,,,,,,,,,,,,,,. " + ANSI_RESET + " | | | | \n" +
|
||||
" * " + ANSI_BLUE + "%%%. " + ANSI_YELLOW +",,,,,,,,,,,,. "+ ANSI_BLUE+"(%%# " + ANSI_RESET + " _ __ | | __ _ _ __ _ __ __ _ _ __ | | __ _ _ __ \n" +
|
||||
" * " + ANSI_BLUE + "%%%%%%%. " + ANSI_YELLOW + ",,,,. "+ ANSI_BLUE +"#%%%%%%# " + ANSI_RESET + "| '_ \\| |/ _` | '_ \\| '_ \\ / _` | '_ \\| |/ _` | '_ \\ \n" +
|
||||
" * " + ANSI_BLUE +"%%%%%%%%%%%#%%%%%%%%%%# " + ANSI_RESET + "| |_) | | (_| | | | | | | | (_| | |_) | | (_| | | | |\n" +
|
||||
" * " + ANSI_BLUE +"/%%%%%%%%%%%%%%%%%%% " + ANSI_RESET + "| .__/|_|\\__,_|_| |_|_| |_|\\__,_| .__/|_|\\__,_|_| |_|\n" +
|
||||
" ( / " + ANSI_BLUE +"#%%%%%%%%%%%. " + ANSI_RESET + "| | | | "+ ANSI_BLUE +"(" +this.version + ")" +"\n" + ANSI_BLUE +
|
||||
" %%%%/ " + ANSI_RESET + "|_| |_| \n" +
|
||||
ANSI_RESET;
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
public class TestController {
|
||||
@GetMapping("/")
|
||||
public String xd() {
|
||||
return "<h1>xd</h1>";
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.plannaplan.Controller;
|
||||
import com.plannaplan.models.ConfigData;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
public class ConfigController {
|
||||
|
||||
@Autowired
|
||||
private Controller contrl;
|
||||
|
||||
@PostMapping("/config")
|
||||
public ResponseEntity<String> configApp(@RequestParam("file") MultipartFile file) {
|
||||
try {
|
||||
ConfigData data = new ConfigData(null, null, file.getInputStream());
|
||||
this.contrl.config(data);
|
||||
return new ResponseEntity<>("Sucess", HttpStatus.OK);
|
||||
} catch (IOException e) {
|
||||
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.services.CourseService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
public class CoursesController {
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@GetMapping("/getCourses")
|
||||
public ResponseEntity<List<Dictionary<String,Object>>> getMethodName() {
|
||||
List<Course> courses = this.courseService.getAllCourses();
|
||||
List<Dictionary<String,Object>> response = new ArrayList<>();
|
||||
for(Course c : courses){
|
||||
Dictionary<String, Object> element = new Hashtable<>();
|
||||
element.put("id", c.getId());
|
||||
element.put("name",c.getName());
|
||||
response.add(element);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/getCoursesWithGroups")
|
||||
public ResponseEntity<List<Dictionary<String,Object>>> getCoursesWithGroups() {
|
||||
List<Course> courses = this.courseService.getAllCourses();
|
||||
List<Dictionary<String,Object>> response = new ArrayList<>();
|
||||
for(Course c : courses){
|
||||
Dictionary<String, Object> element = new Hashtable<>();
|
||||
element.put("id", c.getId());
|
||||
element.put("name",c.getName());
|
||||
List<Dictionary<String,Object>> groups = new ArrayList<>();
|
||||
for(Groups g : c.getGroups()){
|
||||
Dictionary<String,Object> group = new Hashtable<>();
|
||||
group.put("id", g.getId());
|
||||
group.put("day", g.getDay().label);
|
||||
group.put("time", g.getTimeString());
|
||||
group.put("lecturer", g.getLecturer().toString());
|
||||
group.put("room", g.getRoom());
|
||||
group.put("type", g.getType());
|
||||
groups.add(group);
|
||||
}
|
||||
|
||||
element.put("groups", groups);
|
||||
response.add(element);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.services.GroupService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
public class GroupController {
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
@GetMapping("/getCourseGroups")
|
||||
public ResponseEntity<List<Dictionary<String, Object>>> getCourses(@RequestParam("id") Long id, @RequestParam(name="capacity", defaultValue="true") Boolean capacity){
|
||||
List<Groups> groups = this.groupService.getGroupsByCourse(id);
|
||||
List<Dictionary<String, Object>> response = new ArrayList<>();
|
||||
|
||||
|
||||
for (Groups g : groups) {
|
||||
Dictionary<String, Object> group = new Hashtable<>();
|
||||
group.put("id", g.getId());
|
||||
group.put("day", g.getDay().label);
|
||||
group.put("time", g.getTimeString());
|
||||
group.put("lecturer", g.getLecturer().toString());
|
||||
group.put("room", g.getRoom());
|
||||
if (capacity) {
|
||||
group.put("capacity", g.getCapacity());
|
||||
}
|
||||
group.put("type", g.getType());
|
||||
|
||||
response.add(group);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user