Buisness logic docs updated
This commit is contained in:
parent
8d007c259f
commit
21983fe4f7
@ -12,16 +12,29 @@ import org.apache.poi.ss.usermodel.Row;
|
|||||||
import com.plannaplan.models.FileData;
|
import com.plannaplan.models.FileData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FileReader is used for reading xls file from input stream.
|
* FileReader is used for reading xls file from input stream.
|
||||||
*/
|
*/
|
||||||
public class FileReader {
|
public class FileReader {
|
||||||
|
|
||||||
private InputStream fileInputStream;
|
private InputStream fileInputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param fileInputStream stream of stadarized file contains courses and gropups
|
||||||
|
* to import. File needs to be .xlsx file that has
|
||||||
|
* fields: zaj_cyk_id, typ, sym, nazwa, gr_nr, Mc, dzien,
|
||||||
|
* godz_od, sala, tytul, nazwisko, imie. Order doesn't
|
||||||
|
* have impact on import. Any change name of given field
|
||||||
|
* can be performed in FileToDatabaseMigrator class
|
||||||
|
*/
|
||||||
public FileReader(InputStream fileInputStream) {
|
public FileReader(InputStream fileInputStream) {
|
||||||
this.fileInputStream = fileInputStream;
|
this.fileInputStream = fileInputStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* read data rom file
|
||||||
|
*
|
||||||
|
* @return instance of class FileData
|
||||||
|
*/
|
||||||
public FileData read() {
|
public FileData read() {
|
||||||
|
|
||||||
FileData result = null;
|
FileData result = null;
|
||||||
|
@ -16,99 +16,119 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FileToDatabaseMigrator is used for migrate data from file (it reads line by line) and push it into database
|
* FileToDatabaseMigrator is used for migrate data from file (it reads line by
|
||||||
|
* line) and push it into database
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class FileToDatabaseMigrator {
|
public class FileToDatabaseMigrator {
|
||||||
|
|
||||||
private static final String LECTURER_NAME_STRING = "imie";
|
private static final String LECTURER_NAME_STRING = "imie";
|
||||||
private static final String LECTURER_SURNAME_STRING = "nazwisko";
|
private static final String LECTURER_SURNAME_STRING = "nazwisko";
|
||||||
private static final String LECTURER_TITLE_STRING = "tytul";
|
private static final String LECTURER_TITLE_STRING = "tytul";
|
||||||
|
|
||||||
private static final String COURSE_SYMBOL_STRING = "sym";
|
private static final String COURSE_SYMBOL_STRING = "sym";
|
||||||
private static final String COURSE_NAME_STRING = "nazwa";
|
private static final String COURSE_NAME_STRING = "nazwa";
|
||||||
|
|
||||||
private static final String groupDay_STRING = "dzien";
|
private static final String groupDay_STRING = "dzien";
|
||||||
private static final String GROUP_TIME_STRING = "godz_od";
|
private static final String GROUP_TIME_STRING = "godz_od";
|
||||||
private static final String ROOM_STRING = "sala";
|
private static final String ROOM_STRING = "sala";
|
||||||
private static final String CAPACITY_STRING = "Mc";
|
private static final String CAPACITY_STRING = "Mc";
|
||||||
private static final String TYPE_GROUP= "typ";
|
private static final String TYPE_GROUP = "typ";
|
||||||
|
|
||||||
private static final String ZAJ_CYK_ID = "zaj_cyk_id";
|
private static final String ZAJ_CYK_ID = "zaj_cyk_id";
|
||||||
private static final String GR_NR = "gr_nr";
|
private static final String GR_NR = "gr_nr";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LecturerService lecturerService;
|
private LecturerService lecturerService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CourseService courseService;
|
private CourseService courseService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private GroupService groupService;
|
private GroupService groupService;
|
||||||
|
|
||||||
public FileToDatabaseMigrator() {
|
public FileToDatabaseMigrator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void migrate(FileData data) {
|
/**
|
||||||
Iterator<Row> rows = data.getRows();
|
* insert data to database
|
||||||
int courseNameIndex = data.getIndexOf(FileToDatabaseMigrator.COURSE_NAME_STRING);
|
*
|
||||||
int symbolIndex = data.getIndexOf(FileToDatabaseMigrator.COURSE_SYMBOL_STRING);
|
* @param data FileData imported from file
|
||||||
|
*/
|
||||||
|
public void migrate(FileData data) {
|
||||||
|
Iterator<Row> rows = data.getRows();
|
||||||
|
int courseNameIndex = data.getIndexOf(FileToDatabaseMigrator.COURSE_NAME_STRING);
|
||||||
|
int symbolIndex = data.getIndexOf(FileToDatabaseMigrator.COURSE_SYMBOL_STRING);
|
||||||
|
|
||||||
int titleIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_TITLE_STRING);
|
int titleIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_TITLE_STRING);
|
||||||
int surnameIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_SURNAME_STRING);
|
int surnameIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_SURNAME_STRING);
|
||||||
int nameIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_NAME_STRING);
|
int nameIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_NAME_STRING);
|
||||||
|
|
||||||
int dayIndex = data.getIndexOf(FileToDatabaseMigrator.groupDay_STRING);
|
int dayIndex = data.getIndexOf(FileToDatabaseMigrator.groupDay_STRING);
|
||||||
int timeIndex = data.getIndexOf(FileToDatabaseMigrator.GROUP_TIME_STRING);
|
int timeIndex = data.getIndexOf(FileToDatabaseMigrator.GROUP_TIME_STRING);
|
||||||
int roomIndex = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
int roomIndex = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
||||||
int capacityIndex = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
|
int capacityIndex = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
|
||||||
int typeGroupIndex = data.getIndexOf(FileToDatabaseMigrator.TYPE_GROUP);
|
int typeGroupIndex = data.getIndexOf(FileToDatabaseMigrator.TYPE_GROUP);
|
||||||
|
|
||||||
int zajCykIdIndex = data.getIndexOf(FileToDatabaseMigrator.ZAJ_CYK_ID);
|
int zajCykIdIndex = data.getIndexOf(FileToDatabaseMigrator.ZAJ_CYK_ID);
|
||||||
int grNrIndex = data.getIndexOf(FileToDatabaseMigrator.GR_NR);
|
int grNrIndex = data.getIndexOf(FileToDatabaseMigrator.GR_NR);
|
||||||
|
|
||||||
while (rows.hasNext()) {
|
while (rows.hasNext()) {
|
||||||
Row row = rows.next();
|
Row row = rows.next();
|
||||||
|
|
||||||
String courseName = row.getCell(courseNameIndex).toString().trim();
|
String courseName = row.getCell(courseNameIndex).toString().trim();
|
||||||
String symbol = row.getCell(symbolIndex).toString().trim();
|
String symbol = row.getCell(symbolIndex).toString().trim();
|
||||||
|
|
||||||
String lecturerTitle = row.getCell(titleIndex) != null ? row.getCell(titleIndex).toString().trim() : "";
|
String lecturerTitle = row.getCell(titleIndex) != null
|
||||||
String lecturerName = row.getCell(nameIndex) != null ? row.getCell(nameIndex).toString().trim() : "";
|
? row.getCell(titleIndex).toString().trim()
|
||||||
String lecturerSurname = row.getCell(surnameIndex) != null ? row.getCell(surnameIndex).toString().trim()
|
: "";
|
||||||
: "";
|
String lecturerName = row.getCell(nameIndex) != null ? row.getCell(nameIndex).toString().trim()
|
||||||
|
: "";
|
||||||
|
String lecturerSurname = row.getCell(surnameIndex) != null
|
||||||
|
? row.getCell(surnameIndex).toString().trim()
|
||||||
|
: "";
|
||||||
|
|
||||||
Integer zajCykId = row.getCell(zajCykIdIndex) != null ? (int) Double.parseDouble(row.getCell(zajCykIdIndex).toString().trim())
|
Integer zajCykId = row.getCell(zajCykIdIndex) != null
|
||||||
: null;
|
? (int) Double.parseDouble(row.getCell(zajCykIdIndex).toString().trim())
|
||||||
|
: null;
|
||||||
|
|
||||||
Integer grNr = row.getCell(grNrIndex) != null ? (int) Double.parseDouble(row.getCell(grNrIndex).toString().trim())
|
Integer grNr = row.getCell(grNrIndex) != null
|
||||||
: null;
|
? (int) Double.parseDouble(row.getCell(grNrIndex).toString().trim())
|
||||||
|
: null;
|
||||||
|
|
||||||
int day = row.getCell(dayIndex) != null ? (int) Double.parseDouble(row.getCell(dayIndex).toString()) : 0;
|
int day = row.getCell(dayIndex) != null
|
||||||
WeekDay groupDay = WeekDay.getDay(day - 1);
|
? (int) Double.parseDouble(row.getCell(dayIndex).toString())
|
||||||
int time = parseTimeToInt(row.getCell(timeIndex).toString());
|
: 0;
|
||||||
String room = row.getCell(roomIndex).toString().trim();
|
WeekDay groupDay = WeekDay.getDay(day - 1);
|
||||||
int capacity = (int) Double.parseDouble(row.getCell(capacityIndex).toString());
|
int time = parseTimeToInt(row.getCell(timeIndex).toString());
|
||||||
GroupType typeGroup = GroupType.getType(row.getCell(typeGroupIndex).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)
|
Course course = this.courseService.getCourseByName(courseName)
|
||||||
.orElseGet(() -> this.courseService.save(new Course(courseName, symbol)));
|
.orElseGet(() -> this.courseService.save(new Course(courseName, symbol)));
|
||||||
|
|
||||||
Lecturer lecturer = this.lecturerService.getLecturer(lecturerTitle, lecturerName, lecturerSurname)
|
Lecturer lecturer = this.lecturerService
|
||||||
.orElseGet(() -> this.lecturerService
|
.getLecturer(lecturerTitle, lecturerName, lecturerSurname)
|
||||||
.save(new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
|
.orElseGet(() -> this.lecturerService.save(
|
||||||
|
new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
|
||||||
|
|
||||||
Groups group = this.groupService.find(zajCykId, grNr).orElseGet(
|
Groups group = this.groupService.find(zajCykId, grNr).orElseGet(() -> new Groups(capacity, room,
|
||||||
() -> new Groups(capacity, room, course, time, groupDay, lecturer, zajCykId, grNr, typeGroup));
|
course, time, groupDay, lecturer, zajCykId, grNr, typeGroup));
|
||||||
group.update(capacity, room, course, time, null, groupDay, lecturer, typeGroup);
|
group.update(capacity, room, course, time, null, groupDay, lecturer, typeGroup);
|
||||||
|
|
||||||
this.groupService.save(group);
|
this.groupService.save(group);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
*
|
||||||
|
* @param time time string in formaT hh:mm or hh.mm
|
||||||
|
* @return int time witch is minutes from 00:00
|
||||||
|
*/
|
||||||
|
private static int parseTimeToInt(String time) {
|
||||||
|
String times[] = time.split("\\.|\\:");
|
||||||
|
return times.length == 2 ? Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]) : 0;
|
||||||
|
|
||||||
private static int parseTimeToInt(String time) {
|
}
|
||||||
String times[] = time.split("\\.|\\:");
|
|
||||||
return times.length == 2 ? Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]) : 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -78,6 +78,9 @@ public class Assignment {
|
|||||||
public Assignment() {
|
public Assignment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param commision commision to set
|
||||||
|
*/
|
||||||
public void setCommision(Commision commision) {
|
public void setCommision(Commision commision) {
|
||||||
this.commision = commision;
|
this.commision = commision;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.plannaplan.exceptions;
|
package com.plannaplan.exceptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Excepction to be thrown when provided token is expired
|
||||||
|
*/
|
||||||
public class TokenExpiredException extends RuntimeException {
|
public class TokenExpiredException extends RuntimeException {
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public TokenExpiredException(String message) {
|
public TokenExpiredException(String message) {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.plannaplan.exceptions;
|
package com.plannaplan.exceptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception to be thrown when provided user does not exist in database
|
||||||
|
*/
|
||||||
public class UserNotFoundException extends Exception {
|
public class UserNotFoundException extends Exception {
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
public UserNotFoundException(String message) {
|
public UserNotFoundException(String message) {
|
||||||
|
@ -2,6 +2,9 @@ package com.plannaplan.models;
|
|||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Config data copntainer to keep tours dates and stream of dasta to import
|
||||||
|
*/
|
||||||
public class ConfigData {
|
public class ConfigData {
|
||||||
private TourData firstTour;
|
private TourData firstTour;
|
||||||
private TourData secondTour;
|
private TourData secondTour;
|
||||||
|
@ -4,6 +4,9 @@ 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for data readed from file
|
||||||
|
*/
|
||||||
public class FileData {
|
public class FileData {
|
||||||
|
|
||||||
private HashMap<String, Integer> keys;
|
private HashMap<String, Integer> keys;
|
||||||
@ -13,6 +16,7 @@ public class FileData {
|
|||||||
* FileData
|
* FileData
|
||||||
*
|
*
|
||||||
* @param keys this is a hashmap of String and Integer
|
* @param keys this is a hashmap of String and Integer
|
||||||
|
*
|
||||||
* @param rows this is a iterator of rows.
|
* @param rows this is a iterator of rows.
|
||||||
*/
|
*/
|
||||||
public FileData(HashMap<String, Integer> keys, Iterator<Row> rows) {
|
public FileData(HashMap<String, Integer> keys, Iterator<Row> rows) {
|
||||||
@ -31,6 +35,7 @@ public class FileData {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* setRows
|
* setRows
|
||||||
|
*
|
||||||
* @param rows set the rows to given function
|
* @param rows set the rows to given function
|
||||||
*/
|
*/
|
||||||
public void setRows(Iterator<Row> rows) {
|
public void setRows(Iterator<Row> rows) {
|
||||||
@ -39,6 +44,7 @@ public class FileData {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* getKeys
|
* getKeys
|
||||||
|
*
|
||||||
* @return keys
|
* @return keys
|
||||||
*/
|
*/
|
||||||
public HashMap<String, Integer> getKeys() {
|
public HashMap<String, Integer> getKeys() {
|
||||||
@ -47,6 +53,7 @@ public class FileData {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* setKeys
|
* setKeys
|
||||||
|
*
|
||||||
* @param keys set the key is being a struck of hashmap (String, Integer)
|
* @param keys set the key is being a struck of hashmap (String, Integer)
|
||||||
*/
|
*/
|
||||||
public void setKeys(HashMap<String, Integer> keys) {
|
public void setKeys(HashMap<String, Integer> keys) {
|
||||||
@ -55,6 +62,7 @@ public class FileData {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* getIndexOf
|
* getIndexOf
|
||||||
|
*
|
||||||
* @return index
|
* @return index
|
||||||
*/
|
*/
|
||||||
public int getIndexOf(String key) {
|
public int getIndexOf(String key) {
|
||||||
|
@ -3,64 +3,92 @@ package com.plannaplan.models;
|
|||||||
import com.plannaplan.entities.Assignment;
|
import com.plannaplan.entities.Assignment;
|
||||||
import com.plannaplan.entities.Exchange;
|
import com.plannaplan.entities.Exchange;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Match of users Exchange's to be performed
|
||||||
|
*/
|
||||||
public class MatchData {
|
public class MatchData {
|
||||||
private Exchange exchangeOne;
|
private Exchange exchangeOne;
|
||||||
private Exchange exchangeTwo;
|
private Exchange exchangeTwo;
|
||||||
|
|
||||||
public MatchData(Exchange exchangeOne, Exchange exchangeTwo) {
|
/**
|
||||||
this.exchangeOne = exchangeOne;
|
* create MatchData
|
||||||
this.exchangeTwo = exchangeTwo;
|
*
|
||||||
}
|
* @param exchangeOne first Exchange of found match
|
||||||
|
* @param exchangeTwo second Exchange of found match
|
||||||
public Exchange getExchangeOne() {
|
|
||||||
return this.exchangeOne;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Exchange getExchangeTwo() {
|
|
||||||
return this.exchangeTwo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Assignment getAssignmentTwo() {
|
|
||||||
return this.exchangeTwo.getOwnedAssignment();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Assignment getAssignmentOne() {
|
|
||||||
return this.exchangeOne.getOwnedAssignment();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return this.getAssignmentOne().hashCode() + this.getAssignmentTwo().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
|
|
||||||
// If the object is compared with itself then return true
|
|
||||||
if (o == this) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check if o is an instance of Complex or not "null instanceof [type]" also
|
|
||||||
* returns false
|
|
||||||
*/
|
*/
|
||||||
if (!(o instanceof MatchData)) {
|
public MatchData(Exchange exchangeOne, Exchange exchangeTwo) {
|
||||||
return false;
|
this.exchangeOne = exchangeOne;
|
||||||
|
this.exchangeTwo = exchangeTwo;
|
||||||
}
|
}
|
||||||
|
|
||||||
// typecast o to Complex so that we can compare data members
|
/**
|
||||||
MatchData c = (MatchData) o;
|
* @return first Exchange
|
||||||
|
*/
|
||||||
|
public Exchange getExchangeOne() {
|
||||||
|
return this.exchangeOne;
|
||||||
|
}
|
||||||
|
|
||||||
// Compare the data members and return accordingly
|
/**
|
||||||
return (this.getAssignmentOne().equals(c.getAssignmentOne()) && this.getAssignmentTwo().equals(c.getAssignmentTwo())) || (this.getAssignmentOne().equals(c.getAssignmentTwo()) && this.getAssignmentTwo().equals(c.getAssignmentOne()));
|
* @return second Exchange
|
||||||
}
|
*/
|
||||||
|
public Exchange getExchangeTwo() {
|
||||||
|
return this.exchangeTwo;
|
||||||
|
}
|
||||||
|
|
||||||
public int compare(MatchData m1) {
|
/**
|
||||||
return Long.compare(m1.getExchangesMsValue(), this.getExchangesMsValue());
|
* @return second Exchange's owned assignmetn
|
||||||
}
|
*/
|
||||||
|
public Assignment getAssignmentTwo() {
|
||||||
|
return this.exchangeTwo.getOwnedAssignment();
|
||||||
|
}
|
||||||
|
|
||||||
public long getExchangesMsValue(){
|
/**
|
||||||
return this.exchangeOne.getDataExchange().getTime() + this.exchangeTwo.getDataExchange().getTime();
|
* @return first Exchange's owned assignmetn
|
||||||
}
|
*/
|
||||||
|
public Assignment getAssignmentOne() {
|
||||||
|
return this.exchangeOne.getOwnedAssignment();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return this.getAssignmentOne().hashCode() + this.getAssignmentTwo().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
|
||||||
|
if (o == this) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(o instanceof MatchData)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
MatchData c = (MatchData) o;
|
||||||
|
|
||||||
|
return (this.getAssignmentOne().equals(c.getAssignmentOne())
|
||||||
|
&& this.getAssignmentTwo().equals(c.getAssignmentTwo()))
|
||||||
|
|| (this.getAssignmentOne().equals(c.getAssignmentTwo())
|
||||||
|
&& this.getAssignmentTwo().equals(c.getAssignmentOne()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* comparator for MatchData. It compare it by sum of both exchange's times. For
|
||||||
|
* example MatchData with Exchanges 11:00 and 12:00 will be less than with
|
||||||
|
* Exchanges 12:00 and 12:00
|
||||||
|
*
|
||||||
|
* @param m1 MatchData instance to compare to
|
||||||
|
* @return int <0 if m1 is "less than", 0 if it's equal and >0 otherwise
|
||||||
|
*/
|
||||||
|
public int compare(MatchData m1) {
|
||||||
|
return Long.compare(m1.getExchangesMsValue(), this.getExchangesMsValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return sum of both exchanges java.sql.Timestanp::getTime"
|
||||||
|
*/
|
||||||
|
public long getExchangesMsValue() {
|
||||||
|
return this.exchangeOne.getDataExchange().getTime() + this.exchangeTwo.getDataExchange().getTime();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,9 @@ package com.plannaplan.models;
|
|||||||
|
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Container for Tours dates
|
||||||
|
*/
|
||||||
public class TourData {
|
public class TourData {
|
||||||
|
|
||||||
private Date start;
|
private Date start;
|
||||||
|
@ -11,18 +11,36 @@ public class UserApiResponse {
|
|||||||
public UserApiResponse() {
|
public UserApiResponse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return user's Surname
|
||||||
|
*/
|
||||||
public String getSurname() {
|
public String getSurname() {
|
||||||
return surname;
|
return surname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter for name. Reson to have setters for this class is for case if there
|
||||||
|
* would be name and no surname or otherwise
|
||||||
|
*
|
||||||
|
* @param surname name to set that was obtained by api request
|
||||||
|
*/
|
||||||
public void setSurname(String surname) {
|
public void setSurname(String surname) {
|
||||||
this.surname = surname;
|
this.surname = surname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return user's Name
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* setter for surname. Reson to have setters for this class is for case if there
|
||||||
|
* would be name and no surname or otherwise
|
||||||
|
*
|
||||||
|
* @param surname name to set that was obtained by api request
|
||||||
|
*/
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,13 @@ public class CommisionService {
|
|||||||
public CommisionService() {
|
public CommisionService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* save to database commision. It also checks for missing assignments from
|
||||||
|
* previous commision (you can not get rid of accepted assignment)
|
||||||
|
*
|
||||||
|
* @param commision to save to db
|
||||||
|
* @return Commision instance with id from database
|
||||||
|
*/
|
||||||
public Commision save(Commision commision) {
|
public Commision save(Commision commision) {
|
||||||
Optional<Commision> lastCommision = this.getNewestCommision(commision.getCommisionOwner());
|
Optional<Commision> lastCommision = this.getNewestCommision(commision.getCommisionOwner());
|
||||||
if (lastCommision.isPresent()) {
|
if (lastCommision.isPresent()) {
|
||||||
|
@ -10,7 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service of CourseService which can get(Course By Name, All Courses, Courses Ammount ), save, delete course.
|
* Service of CourseService which can get(Course By Name, All Courses, Courses
|
||||||
|
* Ammount ), save, delete course.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -18,42 +19,46 @@ public class CourseService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CourseRepository repo;
|
private CourseRepository repo;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* getCourseByName
|
* getCourseByName
|
||||||
* Return Course By Name
|
*
|
||||||
|
* @param name
|
||||||
|
* @return Course By Name
|
||||||
*/
|
*/
|
||||||
public Optional<Course> getCourseByName(String name) {
|
public Optional<Course> getCourseByName(String name) {
|
||||||
return this.repo.findByName(name);
|
return this.repo.findByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* getAllCourses
|
*
|
||||||
* Return List of get courses
|
* @return all courses from db
|
||||||
*/
|
*/
|
||||||
public List<Course> getAllCourses() {
|
public List<Course> getAllCourses() {
|
||||||
return this.repo.findAll();
|
return this.repo.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* save
|
* save to db
|
||||||
|
*
|
||||||
* @param course which course you would like to save
|
* @param course which course you would like to save
|
||||||
|
* @return Course instance with id from db
|
||||||
*/
|
*/
|
||||||
public Course save(Course course) {
|
public Course save(Course course) {
|
||||||
this.repo.save(course);
|
this.repo.save(course);
|
||||||
return course;
|
return course;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* delete
|
* delete course from db
|
||||||
|
*
|
||||||
* @param course which course you would like to delete
|
* @param course which course you would like to delete
|
||||||
*/
|
*/
|
||||||
public void delete(Course course) {
|
public void delete(Course course) {
|
||||||
this.repo.delete(course);
|
this.repo.delete(course);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* getCoursesAmmount
|
* @return ammount of courses in db
|
||||||
* Return a ammount of courses
|
|
||||||
*/
|
*/
|
||||||
public int getCoursesAmmount() {
|
public int getCoursesAmmount() {
|
||||||
return (int) this.repo.count();
|
return (int) this.repo.count();
|
||||||
|
@ -12,6 +12,9 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
|||||||
import org.springframework.scheduling.support.CronTrigger;
|
import org.springframework.scheduling.support.CronTrigger;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service to manage app events
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class EventService {
|
public class EventService {
|
||||||
|
|
||||||
@ -29,6 +32,9 @@ public class EventService {
|
|||||||
System.out.println("Checking for groups");
|
System.out.println("Checking for groups");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* perfroms checks for matching exchanges daily
|
||||||
|
*/
|
||||||
@Scheduled(cron = "0 0 0 * * *")
|
@Scheduled(cron = "0 0 0 * * *")
|
||||||
public void performExchangeService() {
|
public void performExchangeService() {
|
||||||
System.out.println("Performing Exchange");
|
System.out.println("Performing Exchange");
|
||||||
@ -53,6 +59,10 @@ public class EventService {
|
|||||||
jobsMap.put(taskId, scheduledTask);
|
jobsMap.put(taskId, scheduledTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* init resources needed for dynamicly creating new tasks (needed to set tours
|
||||||
|
* end events)
|
||||||
|
*/
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
this.scheduler = new ThreadPoolTaskScheduler();
|
this.scheduler = new ThreadPoolTaskScheduler();
|
||||||
|
@ -19,6 +19,9 @@ import com.plannaplan.repositories.ExchangeRepository;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service to manage Exchanges
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ExchangeService {
|
public class ExchangeService {
|
||||||
|
|
||||||
@ -50,6 +53,9 @@ public class ExchangeService {
|
|||||||
return this.repo.findById(id);
|
return this.repo.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list of all exchanges in database
|
||||||
|
*/
|
||||||
public List<Exchange> getAllExchanges() {
|
public List<Exchange> getAllExchanges() {
|
||||||
return this.repo.findAll();
|
return this.repo.findAll();
|
||||||
}
|
}
|
||||||
@ -78,6 +84,12 @@ public class ExchangeService {
|
|||||||
return this.repo.checkForExchange(assignment, group);
|
return this.repo.checkForExchange(assignment, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* method to perform Exchange algorythm. It search for matches and swap
|
||||||
|
* assignments between latests user commisions if it can be performed. After
|
||||||
|
* swap we block users matches that contains switched groups. After algorythm
|
||||||
|
* email is being sent to all users with information about performed exchanges
|
||||||
|
*/
|
||||||
public void performExchange() {
|
public void performExchange() {
|
||||||
final List<MatchData> matchData = this.getMatches();
|
final List<MatchData> matchData = this.getMatches();
|
||||||
final List<Long> performedAssignmentExchanges = new ArrayList<>();
|
final List<Long> performedAssignmentExchanges = new ArrayList<>();
|
||||||
@ -127,6 +139,9 @@ public class ExchangeService {
|
|||||||
this.repo.deleteAll(exchangesToDelete);
|
this.repo.deleteAll(exchangesToDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list of matches found in database
|
||||||
|
*/
|
||||||
public List<MatchData> getMatches() {
|
public List<MatchData> getMatches() {
|
||||||
final List<MatchData> matches = this.repo.getMatches().stream().map(m -> {
|
final List<MatchData> matches = this.repo.getMatches().stream().map(m -> {
|
||||||
final Exchange exchangeOne = (Exchange) m[0];
|
final Exchange exchangeOne = (Exchange) m[0];
|
||||||
|
@ -18,7 +18,6 @@ import org.springframework.stereotype.Service;
|
|||||||
* Service of GroupService which can find(optional), get(By Course, Groups
|
* Service of GroupService which can find(optional), get(By Course, Groups
|
||||||
* Ammount, Group By Id, find Not Existing Group), save, delete group.
|
* Ammount, Group By Id, find Not Existing Group), save, delete group.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GroupService {
|
public class GroupService {
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -27,34 +26,84 @@ public class GroupService {
|
|||||||
public GroupService() {
|
public GroupService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find group with given properties
|
||||||
|
*
|
||||||
|
* @param time scheduled time for group as int of minutes passed from 00:00
|
||||||
|
* @param capacity capacity of group
|
||||||
|
* @param room class room
|
||||||
|
* @return optional with Groups instance if found
|
||||||
|
*/
|
||||||
public Optional<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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find group with given properties
|
||||||
|
*
|
||||||
|
* @param zajCykId proteprty from usos
|
||||||
|
* @param nrGr group number
|
||||||
|
* @return optional with Groups instance if found
|
||||||
|
*/
|
||||||
public Optional<Groups> find(Integer zajCykId, Integer nrGr) {
|
public Optional<Groups> find(Integer zajCykId, Integer nrGr) {
|
||||||
return this.repo.find(zajCykId, nrGr);
|
return this.repo.find(zajCykId, nrGr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find group with given properties
|
||||||
|
*
|
||||||
|
* @param id course id of groups belogns to
|
||||||
|
* @return list of found groups
|
||||||
|
*/
|
||||||
public List<Groups> getGroupsByCourse(Long id) {
|
public List<Groups> getGroupsByCourse(Long id) {
|
||||||
return this.repo.getByCourse(id);
|
return this.repo.getByCourse(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* save group to database
|
||||||
|
*
|
||||||
|
* @param group insatnce to be saved
|
||||||
|
* @return new instance that has id form database
|
||||||
|
*/
|
||||||
public Groups save(Groups group) {
|
public Groups save(Groups group) {
|
||||||
return this.repo.save(group);
|
return this.repo.save(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* delete from database
|
||||||
|
*
|
||||||
|
* @param groups isntance to delete
|
||||||
|
*/
|
||||||
public void delete(Groups groups) {
|
public void delete(Groups groups) {
|
||||||
this.repo.delete(groups);
|
this.repo.delete(groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get hom manyh groups are in database in general
|
||||||
|
*
|
||||||
|
* @return int - groups ammount
|
||||||
|
*/
|
||||||
public int getGroupsAmmount() {
|
public int getGroupsAmmount() {
|
||||||
return (int) this.repo.count();
|
return (int) this.repo.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find group with given properties
|
||||||
|
*
|
||||||
|
* @param id group id
|
||||||
|
* @return optional with group if found
|
||||||
|
*/
|
||||||
public Optional<Groups> getGroupById(Long id) {
|
public Optional<Groups> getGroupById(Long id) {
|
||||||
return this.repo.findById(id);
|
return this.repo.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get wich of provided id is not existind groups
|
||||||
|
*
|
||||||
|
* @param ids list of ids to check
|
||||||
|
* @return optional with id that is not group if found. If there is multiple
|
||||||
|
* will be returned first found
|
||||||
|
*/
|
||||||
public Optional<Long> findNotExistingGroup(List<Long> ids) {
|
public Optional<Long> findNotExistingGroup(List<Long> ids) {
|
||||||
for (Long oneId : ids) {
|
for (Long oneId : ids) {
|
||||||
if (this.repo.existsById(oneId) == false) {
|
if (this.repo.existsById(oneId) == false) {
|
||||||
|
Loading…
Reference in New Issue
Block a user