Maciek refactor works + delete unnecesery interface (conception changed)
This commit is contained in:
commit
bf6e1fc2b1
@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>14</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>14</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package com.plannaplan;
|
package com.plannaplan;
|
||||||
|
|
||||||
import com.plannaplan.interfaces.Historable;
|
import com.plannaplan.interfaces.Historable;
|
||||||
import com.plannaplan.interfaces.ProtectedAction;
|
|
||||||
|
|
||||||
public class Assigner implements Historable, ProtectedAction {
|
public class Assigner implements Historable {
|
||||||
|
|
||||||
public Assigner() {
|
public Assigner() {
|
||||||
}
|
}
|
||||||
@ -11,12 +10,6 @@ public class Assigner implements Historable, ProtectedAction {
|
|||||||
public void assing() {
|
public void assing() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validateAction() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addActionToHistory() {
|
public void addActionToHistory() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
package com.plannaplan;
|
package com.plannaplan;
|
||||||
|
|
||||||
import com.plannaplan.interfaces.ProtectedAction;
|
|
||||||
import com.plannaplan.models.ConfigData;
|
import com.plannaplan.models.ConfigData;
|
||||||
import com.plannaplan.models.FileData;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -13,16 +9,10 @@ import org.springframework.stereotype.Component;
|
|||||||
import com.plannaplan.configutils.*;
|
import com.plannaplan.configutils.*;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class Configurator implements ProtectedAction {
|
public class Configurator {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LecturerService lecturerService;
|
FileToDatabaseMigrator migrator;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private CourseService courseService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private GroupService groupService;
|
|
||||||
|
|
||||||
public Configurator() {
|
public Configurator() {
|
||||||
}
|
}
|
||||||
@ -30,14 +20,7 @@ public class Configurator implements ProtectedAction {
|
|||||||
public void config(ConfigData data) {
|
public void config(ConfigData data) {
|
||||||
FileReader reader = new FileReader(data.getFilestream());
|
FileReader reader = new FileReader(data.getFilestream());
|
||||||
FileData coursesData = reader.read();
|
FileData coursesData = reader.read();
|
||||||
FileToDatabaseMigrator mgtr = new FileToDatabaseMigrator(lecturerService, courseService, groupService);
|
migrator.migrate(coursesData);
|
||||||
mgtr.migrate(coursesData);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validateAction() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,9 +1,8 @@
|
|||||||
package com.plannaplan;
|
package com.plannaplan;
|
||||||
|
|
||||||
import com.plannaplan.interfaces.Historable;
|
import com.plannaplan.interfaces.Historable;
|
||||||
import com.plannaplan.interfaces.ProtectedAction;
|
|
||||||
|
|
||||||
public class GroupAdder implements Historable, ProtectedAction {
|
public class GroupAdder implements Historable {
|
||||||
|
|
||||||
public GroupAdder() {
|
public GroupAdder() {
|
||||||
}
|
}
|
||||||
@ -17,10 +16,4 @@ public class GroupAdder implements Historable, ProtectedAction {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validateAction() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,8 +1,6 @@
|
|||||||
package com.plannaplan;
|
package com.plannaplan;
|
||||||
|
|
||||||
import com.plannaplan.interfaces.ProtectedAction;
|
public class GroupEditor {
|
||||||
|
|
||||||
public class GroupEditor implements ProtectedAction {
|
|
||||||
|
|
||||||
public GroupEditor() {
|
public GroupEditor() {
|
||||||
}
|
}
|
||||||
@ -10,10 +8,4 @@ public class GroupEditor implements ProtectedAction {
|
|||||||
public void setNewCapacity(int capaity) {
|
public void setNewCapacity(int capaity) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validateAction() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,8 +1,6 @@
|
|||||||
package com.plannaplan;
|
package com.plannaplan;
|
||||||
|
|
||||||
import com.plannaplan.interfaces.ProtectedAction;
|
public class HistoryResolver {
|
||||||
|
|
||||||
public class HistoryResolver implements ProtectedAction {
|
|
||||||
|
|
||||||
public HistoryResolver() {
|
public HistoryResolver() {
|
||||||
}
|
}
|
||||||
@ -13,10 +11,4 @@ public class HistoryResolver implements ProtectedAction {
|
|||||||
public void reproduce() {
|
public void reproduce() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validateAction() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,9 +1,8 @@
|
|||||||
package com.plannaplan;
|
package com.plannaplan;
|
||||||
|
|
||||||
import com.plannaplan.interfaces.Historable;
|
import com.plannaplan.interfaces.Historable;
|
||||||
import com.plannaplan.interfaces.ProtectedAction;
|
|
||||||
|
|
||||||
public class TransferCreator implements Historable, ProtectedAction {
|
public class TransferCreator implements Historable {
|
||||||
|
|
||||||
public TransferCreator() {
|
public TransferCreator() {
|
||||||
}
|
}
|
||||||
@ -11,12 +10,6 @@ public class TransferCreator implements Historable, ProtectedAction {
|
|||||||
public void createTransfer() {
|
public void createTransfer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validateAction() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addActionToHistory() {
|
public void addActionToHistory() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package com.plannaplan;
|
package com.plannaplan;
|
||||||
|
|
||||||
import com.plannaplan.interfaces.Historable;
|
import com.plannaplan.interfaces.Historable;
|
||||||
import com.plannaplan.interfaces.ProtectedAction;
|
|
||||||
|
|
||||||
public class UnavailabilityAdder implements Historable, ProtectedAction {
|
public class UnavailabilityAdder implements Historable {
|
||||||
|
|
||||||
public UnavailabilityAdder() {
|
public UnavailabilityAdder() {
|
||||||
}
|
}
|
||||||
@ -11,12 +10,6 @@ public class UnavailabilityAdder implements Historable, ProtectedAction {
|
|||||||
public void add() {
|
public void add() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validateAction() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addActionToHistory() {
|
public void addActionToHistory() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -20,7 +20,7 @@ public abstract class EventWatcher {
|
|||||||
public void detach(EventCreator creator) {
|
public void detach(EventCreator creator) {
|
||||||
this.creators.remove(creator);
|
this.creators.remove(creator);
|
||||||
}
|
}
|
||||||
|
//why update method is both in eventwatcher and eventcreator???
|
||||||
public void update() {
|
public void update() {
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,7 @@ package com.plannaplan.configutils;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Hashtable;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
@ -33,12 +33,12 @@ public class FileReader {
|
|||||||
Row row = rowIt.next();
|
Row row = rowIt.next();
|
||||||
Iterator<Cell> cellIt = row.cellIterator();
|
Iterator<Cell> cellIt = row.cellIterator();
|
||||||
|
|
||||||
Hashtable<String, Integer> keys = new Hashtable<>();
|
HashMap<String, Integer> keys = new HashMap<>();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (cellIt.hasNext()) {
|
while (cellIt.hasNext()) {
|
||||||
Cell c = cellIt.next();
|
Cell c = cellIt.next();
|
||||||
keys.put(c.toString(), index);
|
keys.put(c.toString(), index);
|
||||||
index+=1;
|
index += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rowIt.remove();
|
rowIt.remove();
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.plannaplan.configutils;
|
package com.plannaplan.configutils;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import com.plannaplan.entities.Course;
|
import com.plannaplan.entities.Course;
|
||||||
import com.plannaplan.entities.Groups;
|
import com.plannaplan.entities.Groups;
|
||||||
import com.plannaplan.entities.Lecturer;
|
import com.plannaplan.entities.Lecturer;
|
||||||
@ -9,140 +8,85 @@ import com.plannaplan.models.FileData;
|
|||||||
import com.plannaplan.services.CourseService;
|
import com.plannaplan.services.CourseService;
|
||||||
import com.plannaplan.services.GroupService;
|
import com.plannaplan.services.GroupService;
|
||||||
import com.plannaplan.services.LecturerService;
|
import com.plannaplan.services.LecturerService;
|
||||||
import com.plannaplan.types.GroupType;
|
|
||||||
import com.plannaplan.types.WeekDay;
|
import com.plannaplan.types.WeekDay;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class FileToDatabaseMigrator {
|
public class 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";
|
private static final String LECTURER_NAME_STRING = "imie";
|
||||||
public static String COURSE_NAME_STRING = "nazwa";
|
private static final String LECTURER_SURNAME_STRING = "nazwisko";
|
||||||
|
private static final String LECTURER_TITLE_STRING = "tytul";
|
||||||
|
|
||||||
public static String GROUP_DAY_STRING = "dzien";
|
private static final String COURSE_SYMBOL_STRING = "sym";
|
||||||
public static String GROUP_TIME_STRING = "godz_od";
|
private static final String COURSE_NAME_STRING = "nazwa";
|
||||||
public static String ROOM_STRING = "sala";
|
|
||||||
public static String CAPACITY_STRING = "Mc";
|
|
||||||
|
|
||||||
LecturerService lecturerService;
|
private static final String groupDay_STRING = "dzien";
|
||||||
CourseService courseService;
|
private static final String GROUP_TIME_STRING = "godz_od";
|
||||||
GroupService groupService;
|
private static final String ROOM_STRING = "sala";
|
||||||
|
private static final String CAPACITY_STRING = "Mc";
|
||||||
|
|
||||||
public FileToDatabaseMigrator(LecturerService lecturerService, CourseService courseService,
|
@Autowired
|
||||||
GroupService groupService) {
|
private LecturerService lecturerService;
|
||||||
this.lecturerService = lecturerService;
|
@Autowired
|
||||||
this.groupService = groupService;
|
private CourseService courseService;
|
||||||
this.courseService = courseService;
|
@Autowired
|
||||||
|
private GroupService groupService;
|
||||||
|
|
||||||
|
public FileToDatabaseMigrator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void migrate(FileData data) {
|
public void migrate(FileData data) {
|
||||||
Iterator<Row> rows = data.getRows();
|
Iterator<Row> rows = data.getRows();
|
||||||
|
int courseNameIndex = data.getIndexOf(FileToDatabaseMigrator.COURSE_NAME_STRING);
|
||||||
|
int symbolIndex = data.getIndexOf(FileToDatabaseMigrator.COURSE_SYMBOL_STRING);
|
||||||
|
|
||||||
int course_name_index = data.getIndexOf(FileToDatabaseMigrator.COURSE_NAME_STRING);
|
int titleIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_TITLE_STRING);
|
||||||
int sym_index = data.getIndexOf(FileToDatabaseMigrator.COURSE_SYMBOL_STRING);
|
int surnameIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_SURNAME_STRING);
|
||||||
|
int nameIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_NAME_STRING);
|
||||||
|
|
||||||
int title_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_TITLE_STRING);
|
int dayIndex = data.getIndexOf(FileToDatabaseMigrator.groupDay_STRING);
|
||||||
int surname_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_SURNAME_STRING);
|
int timeIndex = data.getIndexOf(FileToDatabaseMigrator.GROUP_TIME_STRING);
|
||||||
int name_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_NAME_STRING);
|
int roomIndex = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
||||||
|
int capacityIndex = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_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()) {
|
while (rows.hasNext()) {
|
||||||
Row row = rows.next();
|
Row row = rows.next();
|
||||||
|
|
||||||
Cell course_name_cell = row.getCell(course_name_index);
|
String courseName = row.getCell(courseNameIndex).toString().trim();
|
||||||
Cell sym = row.getCell(sym_index);
|
String symbol = row.getCell(symbolIndex).toString().trim();
|
||||||
|
|
||||||
Cell title_cell = row.getCell(title_index);
|
String lecturerTitle = row.getCell(titleIndex) != null ? row.getCell(titleIndex).toString().trim() : "";
|
||||||
Cell name_cell = row.getCell(name_index);
|
String lecturerName = row.getCell(nameIndex) != null ? row.getCell(nameIndex).toString().trim() : "";
|
||||||
Cell surname_cell = row.getCell(surname_index);
|
String lecturerSurname = row.getCell(surnameIndex) != null ? row.getCell(surnameIndex).toString().trim()
|
||||||
|
: "";
|
||||||
|
|
||||||
Cell day_cell = row.getCell(day_index);
|
int day = (int) Double.parseDouble(row.getCell(dayIndex).toString());
|
||||||
Cell time_cell = row.getCell(time_index);
|
WeekDay groupDay = WeekDay.getDay(day - 1);
|
||||||
Cell room_cell = row.getCell(room_index);
|
int time = parseTimeToInt(row.getCell(timeIndex).toString());
|
||||||
Cell capacity_cell = row.getCell(capacity_index);
|
String room = row.getCell(roomIndex).toString().trim();
|
||||||
|
int capacity = (int) Double.parseDouble(row.getCell(capacityIndex).toString());
|
||||||
|
|
||||||
String lecturer_title = "";
|
Course course = this.courseService.getCourseByName(courseName)
|
||||||
String lecturer_surname = "";
|
.orElseGet(() -> this.courseService.save(new Course(courseName, symbol)));
|
||||||
String lecturer_name = "";
|
|
||||||
|
|
||||||
String course_name = course_name_cell.toString().trim();
|
Lecturer lecturer = this.lecturerService.getLecturer(lecturerTitle, lecturerName, lecturerSurname)
|
||||||
String sym_str = sym.toString().trim();
|
.orElseGet(() -> this.lecturerService
|
||||||
|
.save(new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
|
||||||
|
|
||||||
int day = (int) Double.parseDouble(day_cell.toString());
|
this.groupService.find(time, capacity, room).orElseGet(
|
||||||
WeekDay group_day = WeekDay.getDay(day - 1);
|
() -> this.groupService.save(new Groups(capacity, room, course, time, groupDay, lecturer)));
|
||||||
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) {
|
private static int parseTimeToInt(String time) {
|
||||||
String times[] = time.split("\\.");
|
String times[] = time.split("\\.|\\:");
|
||||||
if (times.length == 2) {
|
return times.length == 2 ? Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]) : 0;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,12 +17,17 @@ public class Course {
|
|||||||
private Long id;
|
private Long id;
|
||||||
private String name;
|
private String name;
|
||||||
private String symbol;
|
private String symbol;
|
||||||
@OneToMany(mappedBy = "courseId", fetch = FetchType.EAGER)
|
@OneToMany(mappedBy = "course", fetch = FetchType.EAGER)
|
||||||
private List<Groups> groups = new ArrayList<>();
|
private List<Groups> groups = new ArrayList<>();
|
||||||
|
|
||||||
public Course() {
|
public Course() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Course(String name, String symbol) {
|
||||||
|
this.name = name;
|
||||||
|
this.symbol = symbol;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
@ -43,7 +48,7 @@ public class Course {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Groups> getGroups(){
|
public List<Groups> getGroups() {
|
||||||
return this.groups;
|
return this.groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ import javax.persistence.ManyToOne;
|
|||||||
import com.plannaplan.types.GroupType;
|
import com.plannaplan.types.GroupType;
|
||||||
import com.plannaplan.types.WeekDay;
|
import com.plannaplan.types.WeekDay;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Groups {
|
public class Groups {
|
||||||
@Id
|
@Id
|
||||||
@ -17,7 +19,7 @@ public class Groups {
|
|||||||
private Long id;
|
private Long id;
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "course_id")
|
@JoinColumn(name = "course_id")
|
||||||
private Course courseId;
|
private Course course;
|
||||||
private int time;
|
private int time;
|
||||||
private String room;
|
private String room;
|
||||||
private int capacity;
|
private int capacity;
|
||||||
@ -30,6 +32,16 @@ public class Groups {
|
|||||||
public Groups() {
|
public Groups() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Groups(int capacity, String room, Course course, int time, WeekDay day, Lecturer lecturer) {
|
||||||
|
this.capacity = capacity;
|
||||||
|
this.room = room;
|
||||||
|
this.course = course;
|
||||||
|
this.time = time;
|
||||||
|
this.day = day;
|
||||||
|
this.lecturer = lecturer;
|
||||||
|
this.type = capacity >= 50 ? GroupType.LECTURE : GroupType.CLASS;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
@ -83,11 +95,11 @@ public class Groups {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Course getCourseId() {
|
public Course getCourseId() {
|
||||||
return courseId;
|
return course;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCourseId(Course courseId) {
|
public void setCourseId(Course courseId) {
|
||||||
this.courseId = courseId;
|
this.course = courseId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTimeString() {
|
public String getTimeString() {
|
||||||
|
@ -8,7 +8,7 @@ import javax.persistence.GenerationType;
|
|||||||
import javax.persistence.Id;
|
import javax.persistence.Id;
|
||||||
|
|
||||||
import com.plannaplan.types.UserRoles;
|
import com.plannaplan.types.UserRoles;
|
||||||
|
//should setter be public?
|
||||||
@Entity
|
@Entity
|
||||||
public class User {
|
public class User {
|
||||||
@Id
|
@Id
|
||||||
@ -68,4 +68,5 @@ public class User {
|
|||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,5 +0,0 @@
|
|||||||
package com.plannaplan.interfaces;
|
|
||||||
|
|
||||||
public interface ProtectedAction {
|
|
||||||
void validateAction();
|
|
||||||
}
|
|
@ -1,20 +1,25 @@
|
|||||||
package com.plannaplan.models;
|
package com.plannaplan.models;
|
||||||
|
|
||||||
import java.util.Dictionary;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
|
||||||
|
//dictionary is deprecated use hashmap instead
|
||||||
public class FileData {
|
public class FileData {
|
||||||
|
|
||||||
private Dictionary<String, Integer> keys;
|
private HashMap<String, Integer> keys;
|
||||||
private Iterator<Row> rows;
|
private Iterator<Row> rows;
|
||||||
|
|
||||||
public FileData(Dictionary<String, Integer> keys, Iterator<Row> rows) {
|
//why variable is called keys2, could it be more specific???
|
||||||
this.setKeys(keys);
|
//why use setters in constructor here instead of assignments???
|
||||||
this.setRows(rows);
|
// thought that setters are used to change values in runtime
|
||||||
|
public FileData(HashMap<String, Integer> keys, Iterator<Row> rows) {
|
||||||
|
this.keys = keys;
|
||||||
|
this.rows = rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Iterator<Row> getRows() {
|
public Iterator<Row> getRows() {
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
@ -23,11 +28,11 @@ public class FileData {
|
|||||||
this.rows = rows;
|
this.rows = rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Dictionary<String, Integer> getKeys() {
|
public HashMap<String, Integer> getKeys() {
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeys(Dictionary<String, Integer> keys) {
|
public void setKeys(HashMap<String, Integer> keys) {
|
||||||
this.keys = keys;
|
this.keys = keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.plannaplan.repositories;
|
package com.plannaplan.repositories;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.plannaplan.entities.Course;
|
import com.plannaplan.entities.Course;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
@ -10,5 +12,5 @@ import org.springframework.stereotype.Repository;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface CourseRepository extends JpaRepository<Course, Long> {
|
public interface CourseRepository extends JpaRepository<Course, Long> {
|
||||||
@Query("FROM Course WHERE name = ?1")
|
@Query("FROM Course WHERE name = ?1")
|
||||||
Course findByName(@Param("name") String name);
|
Optional<Course> findByName(@Param("name") String name);
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.plannaplan.repositories;
|
package com.plannaplan.repositories;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.plannaplan.entities.Groups;
|
import com.plannaplan.entities.Groups;
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ import org.springframework.stereotype.Repository;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface GroupRepository extends JpaRepository<Groups, Long> {
|
public interface GroupRepository extends JpaRepository<Groups, Long> {
|
||||||
@Query("FROM Groups WHERE time = ?1 AND room = ?2 AND capacity = ?3")
|
@Query("FROM Groups WHERE time = ?1 AND room = ?2 AND capacity = ?3")
|
||||||
Groups find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity);
|
Optional<Groups> find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity);
|
||||||
|
|
||||||
@Query("FROM Groups WHERE course_id = ?1")
|
@Query("FROM Groups WHERE course_id = ?1")
|
||||||
List<Groups> getByCourse(@Param("id") Long id);
|
List<Groups> getByCourse(@Param("id") Long id);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.plannaplan.repositories;
|
package com.plannaplan.repositories;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.plannaplan.entities.Lecturer;
|
import com.plannaplan.entities.Lecturer;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
@ -10,5 +12,5 @@ import org.springframework.stereotype.Repository;
|
|||||||
@Repository
|
@Repository
|
||||||
public interface LecturerRepository extends JpaRepository<Lecturer, Long> {
|
public interface LecturerRepository extends JpaRepository<Lecturer, Long> {
|
||||||
@Query("FROM Lecturer WHERE title = ?1 AND name = ?2 AND surname = ?3")
|
@Query("FROM Lecturer WHERE title = ?1 AND name = ?2 AND surname = ?3")
|
||||||
Lecturer find(@Param("title") String title, @Param("name") String name, @Param("surname") String surname);
|
Optional<Lecturer> find(@Param("title") String title, @Param("name") String name, @Param("surname") String surname);
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package com.plannaplan.repositories;
|
package com.plannaplan.repositories;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.plannaplan.entities.User;
|
import com.plannaplan.entities.User;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
@ -7,10 +9,11 @@ import org.springframework.data.jpa.repository.Query;
|
|||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
//if result could be null, should we wrapped in optional
|
||||||
@Repository
|
@Repository
|
||||||
public interface UserRepository extends JpaRepository<User, Long> {
|
public interface UserRepository extends JpaRepository<User, Long> {
|
||||||
@Query("FROM User WHERE email = ?1")
|
@Query("FROM User WHERE email = ?1")
|
||||||
User getByAuthority(@Param("authority") String authority);
|
Optional<User> getByAuthority(@Param("authority") String authority);
|
||||||
|
|
||||||
@Query("FROM User WHERE token = ?1")
|
@Query("FROM User WHERE token = ?1")
|
||||||
User getByToken(@Param("token") String token);
|
User getByToken(@Param("token") String token);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.plannaplan.services;
|
package com.plannaplan.services;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.plannaplan.entities.Course;
|
import com.plannaplan.entities.Course;
|
||||||
import com.plannaplan.repositories.CourseRepository;
|
import com.plannaplan.repositories.CourseRepository;
|
||||||
@ -13,7 +14,7 @@ public class CourseService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CourseRepository repo;
|
private CourseRepository repo;
|
||||||
|
|
||||||
public Course getCourseByName(String name) {
|
public Optional<Course> getCourseByName(String name) {
|
||||||
return this.repo.findByName(name);
|
return this.repo.findByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,15 +22,16 @@ public class CourseService {
|
|||||||
return this.repo.findAll();
|
return this.repo.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(Course course) {
|
public Course save(Course course) {
|
||||||
this.repo.save(course);
|
this.repo.save(course);
|
||||||
|
return course;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(Course course){
|
public void delete(Course course) {
|
||||||
this.repo.delete(course);
|
this.repo.delete(course);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCoursesAmmount(){
|
public int getCoursesAmmount() {
|
||||||
return (int)this.repo.count();
|
return (int) this.repo.count();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.plannaplan.services;
|
package com.plannaplan.services;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.plannaplan.entities.Groups;
|
import com.plannaplan.entities.Groups;
|
||||||
import com.plannaplan.repositories.GroupRepository;
|
import com.plannaplan.repositories.GroupRepository;
|
||||||
@ -16,7 +17,7 @@ public class GroupService {
|
|||||||
public GroupService() {
|
public GroupService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Groups find(int time, int capacity, String room) {
|
public Optional<Groups> find(int time, int capacity, String room) {
|
||||||
return this.repo.find(time, room, capacity);
|
return this.repo.find(time, room, capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,15 +25,16 @@ public class GroupService {
|
|||||||
return this.repo.getByCourse(id);
|
return this.repo.getByCourse(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(Groups group) {
|
public Groups save(Groups group) {
|
||||||
this.repo.save(group);
|
this.repo.save(group);
|
||||||
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(Groups groups){
|
public void delete(Groups groups) {
|
||||||
this.repo.delete(groups);
|
this.repo.delete(groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getGroupsAmmount(){
|
public int getGroupsAmmount() {
|
||||||
return (int)this.repo.count();
|
return (int) this.repo.count();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package com.plannaplan.services;
|
package com.plannaplan.services;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.plannaplan.entities.Lecturer;
|
import com.plannaplan.entities.Lecturer;
|
||||||
import com.plannaplan.repositories.LecturerRepository;
|
import com.plannaplan.repositories.LecturerRepository;
|
||||||
|
|
||||||
@ -11,19 +13,20 @@ public class LecturerService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private LecturerRepository repo;
|
private LecturerRepository repo;
|
||||||
|
|
||||||
public Lecturer getLecturer(String title, String name, String surname) {
|
public Optional<Lecturer> getLecturer(String title, String name, String surname) {
|
||||||
return repo.find(title, name, surname);
|
return repo.find(title, name, surname);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(Lecturer lecturer) {
|
public Lecturer save(Lecturer lecturer) {
|
||||||
repo.save(lecturer);
|
repo.save(lecturer);
|
||||||
|
return lecturer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(Lecturer lecturer) {
|
public void delete(Lecturer lecturer) {
|
||||||
repo.delete(lecturer);
|
repo.delete(lecturer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLecturersAmmount(){
|
public int getLecturersAmmount() {
|
||||||
return (int)this.repo.count();
|
return (int) this.repo.count();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,11 +19,11 @@ public class UserService extends EventWatcher {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this code is more idiomatic to java using java 8 stream API
|
||||||
public String login(String authority) throws UserNotFoundException {
|
public String login(String authority) throws UserNotFoundException {
|
||||||
User user = this.repo.getByAuthority(authority.replace("\n", "").trim());
|
User user = this.repo.getByAuthority(authority.replace("\n", "").trim())
|
||||||
if (user == null) {
|
.orElseThrow(() -> new UserNotFoundException("Can not find user with given authority"));
|
||||||
throw new UserNotFoundException("Can not find user with given authority");
|
|
||||||
}
|
|
||||||
String token = UUID.randomUUID().toString();
|
String token = UUID.randomUUID().toString();
|
||||||
user.setToken(token);
|
user.setToken(token);
|
||||||
this.repo.save(user);
|
this.repo.save(user);
|
||||||
@ -34,10 +34,14 @@ public class UserService extends EventWatcher {
|
|||||||
this.repo.save(user);
|
this.repo.save(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUserByEmail(String email) {
|
// this code is more idiomatic to java
|
||||||
return this.repo.getByAuthority(email.replace("\n", "").trim());
|
public User getUserByEmail(String email) throws UserNotFoundException {
|
||||||
|
return this.repo.getByAuthority(email.replace("\n", "").trim())
|
||||||
|
.orElseThrow(() -> new UserNotFoundException("Cannot find user with given authority"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// why is not throwing exception?
|
||||||
public User getByToken(String token) {
|
public User getByToken(String token) {
|
||||||
return this.repo.getByToken(token);
|
return this.repo.getByToken(token);
|
||||||
}
|
}
|
||||||
|
4
pom.xml
4
pom.xml
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>14</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>14</maven.compiler.target>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>14</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>14</maven.compiler.target>
|
||||||
<start-class>com.plannaplan.App</start-class>
|
<start-class>com.plannaplan.App</start-class>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user