Merge pull request 'Changing-file-xls' (#40) from Changing-file-xls into master
Reviewed-on: http://git.plannaplan.pl/filipizydorczyk/backend/pulls/40
This commit is contained in:
commit
3b80a70921
@ -8,6 +8,7 @@ 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.Row;
|
||||
@ -31,6 +32,7 @@ public class FileToDatabaseMigrator {
|
||||
private static final String GROUP_TIME_STRING = "godz_od";
|
||||
private static final String ROOM_STRING = "sala";
|
||||
private static final String CAPACITY_STRING = "Mc";
|
||||
private static final String TYPE_GROUP= "typ";
|
||||
|
||||
private static final String ZAJ_CYK_ID = "zaj_cyk_id";
|
||||
private static final String GR_NR = "gr_nr";
|
||||
@ -58,6 +60,7 @@ public class FileToDatabaseMigrator {
|
||||
int timeIndex = data.getIndexOf(FileToDatabaseMigrator.GROUP_TIME_STRING);
|
||||
int roomIndex = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
||||
int capacityIndex = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
|
||||
int typeGroupIndex = data.getIndexOf(FileToDatabaseMigrator.TYPE_GROUP);
|
||||
|
||||
int zajCykIdIndex = data.getIndexOf(FileToDatabaseMigrator.ZAJ_CYK_ID);
|
||||
int grNrIndex = data.getIndexOf(FileToDatabaseMigrator.GR_NR);
|
||||
@ -79,11 +82,12 @@ public class FileToDatabaseMigrator {
|
||||
Integer grNr = row.getCell(grNrIndex) != null ? (int) Double.parseDouble(row.getCell(grNrIndex).toString().trim())
|
||||
: null;
|
||||
|
||||
int day = (int) Double.parseDouble(row.getCell(dayIndex).toString());
|
||||
int day = row.getCell(dayIndex) != null ? (int) Double.parseDouble(row.getCell(dayIndex).toString()) : 0;
|
||||
WeekDay groupDay = WeekDay.getDay(day - 1);
|
||||
int time = parseTimeToInt(row.getCell(timeIndex).toString());
|
||||
String room = row.getCell(roomIndex).toString().trim();
|
||||
int capacity = (int) Double.parseDouble(row.getCell(capacityIndex).toString());
|
||||
GroupType typeGroup = GroupType.getType(row.getCell(typeGroupIndex).toString());
|
||||
|
||||
Course course = this.courseService.getCourseByName(courseName)
|
||||
.orElseGet(() -> this.courseService.save(new Course(courseName, symbol)));
|
||||
@ -93,9 +97,8 @@ public class FileToDatabaseMigrator {
|
||||
.save(new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
|
||||
|
||||
Groups group = this.groupService.find(zajCykId, grNr).orElseGet(
|
||||
() -> new Groups(capacity, room, course, time, groupDay, lecturer, zajCykId, grNr));
|
||||
|
||||
group.update(capacity, room, course, time, null, groupDay, lecturer);
|
||||
() -> new Groups(capacity, room, course, time, capacity, groupDay, lecturer, zajCykId, grNr, typeGroup));
|
||||
group.update(capacity, room, course, time, null, groupDay, lecturer, typeGroup);
|
||||
|
||||
this.groupService.save(group);
|
||||
|
||||
|
@ -96,6 +96,26 @@ public class Groups {
|
||||
this.type = capacity >= 50 ? GroupType.LECTURE : GroupType.CLASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups
|
||||
*
|
||||
* @param capacity capacity given to the groups
|
||||
* @param room room given to the groups
|
||||
* @param course course given to the groups
|
||||
* @param time time given to the groups
|
||||
* @param endTime end time of class in minutes
|
||||
* @param day day given to the groups
|
||||
* @param lecturer lecturer given to the groups
|
||||
* @param zajCykId number of class in the term
|
||||
* @param grNr Number of class/course
|
||||
* @param type type of class/cource
|
||||
*/
|
||||
public Groups(int capacity, String room, Course course, int time, int endTime, WeekDay day, Lecturer lecturer,
|
||||
Integer zajCykId, Integer grNr, GroupType type) {
|
||||
this(capacity, room, course, time, endTime, day, lecturer, zajCykId, grNr);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups
|
||||
*
|
||||
@ -159,9 +179,10 @@ public class Groups {
|
||||
* @param endTime end time of class in minutes
|
||||
* @param day day given to the groups
|
||||
* @param lecturer lecturer given to the groups
|
||||
* @param type type given to the groups
|
||||
*/
|
||||
public void update(Integer capacity, String room, Course course, Integer time, Integer endTime, WeekDay day,
|
||||
Lecturer lecturer) {
|
||||
Lecturer lecturer, GroupType type) {
|
||||
if (capacity != null) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
@ -189,6 +210,10 @@ public class Groups {
|
||||
if (lecturer != null) {
|
||||
this.lecturer = lecturer;
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -126,6 +126,7 @@ public class ConfiguratorService {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("Performing event");
|
||||
if (localDate.getYear() == LocalDate.now().getYear()) {
|
||||
assignmentService.callAcceptAlgorythm();
|
||||
}
|
||||
|
@ -1,9 +1,23 @@
|
||||
package com.plannaplan.types;
|
||||
|
||||
/**
|
||||
* GroupType contains types: LECTURE, CLASS
|
||||
* GroupType contains types: LECTURE, CLASS, LAB, SEMINAR, CONSERVATORY, PRATICE
|
||||
*/
|
||||
|
||||
public enum GroupType {
|
||||
LECTURE, CLASS
|
||||
LECTURE("Wykład"), CLASS("Ćwiczenia"), LAB("Laboratorium"), SEMINAR("Seminarium"),CONSERVATORY("Konwersatorium"), PRATICE("Praktyka");
|
||||
|
||||
public final String type;
|
||||
private GroupType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public final static GroupType getType(String type) {
|
||||
for (GroupType d : values()) {
|
||||
if (d.type.equals(type)) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -10,12 +10,11 @@ import org.junit.Test;
|
||||
|
||||
public class FileReaderTest {
|
||||
@Test
|
||||
public void shoulReturnNull() {
|
||||
public void shouldNotReturnNull() {
|
||||
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
|
||||
final FileReader r = new FileReader(inputStream);
|
||||
final FileData d = r.read();
|
||||
assertTrue(d.getRows().next().getCell(0).toString().equals("1.0"));
|
||||
assertTrue(d.getKeys().size() == 24);
|
||||
assertTrue(d.getKeys().size() == 12);
|
||||
assertTrue(d != null);
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user