Merge pull request 'ZPI-163: Dodanie dokumentacji do kodu + javadoc' (#24) from ZPI-163 into master

Reviewed-on: http://git.plannaplan.pl/filipizydorczyk/backend/pulls/24
This commit is contained in:
filipizydorczyk 2020-12-02 12:28:38 +01:00
commit c3fd450499
28 changed files with 546 additions and 35 deletions

View File

@ -57,6 +57,12 @@ 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)
## Generowanie dokumentacji - javadoc
```bash
mvn javadoc:javadoc
```
## 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

View File

@ -84,6 +84,15 @@
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>

View File

@ -11,6 +11,9 @@ import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import com.plannaplan.models.FileData;
/**
* FileReader is used for reading xls file from input stream.
*/
public class FileReader {
private InputStream fileInputStream;
@ -22,7 +25,7 @@ public class FileReader {
public FileData read() {
FileData result = null;
try {
InputStream fis = this.fileInputStream;
XSSFWorkbook workbook = new XSSFWorkbook(fis);
@ -53,4 +56,4 @@ public class FileReader {
return result;
}
}
}

View File

@ -14,6 +14,9 @@ import org.apache.poi.ss.usermodel.Row;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* FileToDatabaseMigrator is used for migrate data from file (it reads line by line) and push it into database
*/
@Component
public class FileToDatabaseMigrator {

View File

@ -7,6 +7,11 @@ import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
/**
* Entity of Assignment grouping of state associated about group_id and commision_id
*
*/
@Entity
public class Assignment {
@Id
@ -19,12 +24,23 @@ public class Assignment {
@JoinColumn(name = "commision_id")
private Commision commision;
private boolean isPastAssignment;
/**
* Assignment
* @param group group we would like to assign
* @param commision commision that assignment belongs to
* @param isPastAssignment is assignment past or no
*/
public Assignment(Groups group, Commision commision, boolean isPastAssignment) {
this.commision = commision;
this.group = group;
}
/**
* Assignment
* @param group group we would like to assign
* @param commision commision that assignment belongs to
*/
public Assignment(Groups group, Commision commision) {
this(group, commision, false);
}
@ -32,18 +48,36 @@ public class Assignment {
public Assignment() {
}
/**
* Id getter
* @return id id of assignment
*/
public Long getId() {
return this.id;
}
/**
* getGroup
*
* @return group
*/
public Groups getGroup() {
return this.group;
}
/**
* isPastAssignment getter
* @return isPastAssignment
*/
public boolean isPastAssignment() {
return isPastAssignment;
}
/**
* setter isPastAssignment
* @param isPastAssignment
*/
public void setPastAssignment(boolean isPastAssignment) {
this.isPastAssignment = isPastAssignment;
}

View File

@ -12,6 +12,10 @@ import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
/**
* Entity of Commision grouping of state associated about commison and owner_id
*/
@Entity
public class Commision {
@Id
@ -38,18 +42,34 @@ public class Commision {
public Commision() {
}
/**
* Id getter
* @return id id of commision
*/
public Long getId() {
return this.id;
}
/**
* CommisionDate getter
* @return commisionDate
*/
public Timestamp getCommisionDate() {
return commisionDate;
}
/**
* User of given commision getter
* @return User commisionOwner
*/
public User getCommisionOwner() {
return commisionOwner;
}
/**
* Assigments getter
* @return List of assignments
*/
public List<Assignment> getAssignments() {
return this.assignments;
}

View File

@ -10,6 +10,10 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
/**
* Entity of Course grouping of state of course
*/
@Entity
public class Course {
@Id
@ -23,31 +27,61 @@ public class Course {
public Course() {
}
/**
* Course
*
* @param name name given to the course
* @param symbol symbol given to the course
*/
public Course(String name, String symbol) {
this.name = name;
this.symbol = symbol;
}
/**
* getId
* @return id
*/
public Long getId() {
return this.id;
}
/**
* getName
* @return name
*/
public String getName() {
return name;
}
/**
* getSymbol
* @return symbol
*/
public String getSymbol() {
return symbol;
}
/**
* setSymbol
* @param symbol set symbol in the course
*/
public void setSymbol(String symbol) {
this.symbol = symbol;
}
/**
* setName
* @param name set name in the course
*/
public void setName(String name) {
this.name = name;
}
/**
* getGroups
* @return groups return list groups
*/
public List<Groups> getGroups() {
return this.groups;
}

View File

@ -10,7 +10,9 @@ import javax.persistence.ManyToOne;
import com.plannaplan.types.GroupType;
import com.plannaplan.types.WeekDay;
/**
* Entity of Groups grouping of state ssociated about course,time,room,capacity,type,day
*/
@Entity
public class Groups {
@ -32,6 +34,16 @@ public class Groups {
public Groups() {
}
/**
* 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 day day given to the groups
* @param lecturer lecturer given to the groups
*/
public Groups(int capacity, String room, Course course, int time, WeekDay day, Lecturer lecturer) {
this.capacity = capacity;
this.room = room;
@ -42,66 +54,130 @@ public class Groups {
this.type = capacity >= 50 ? GroupType.LECTURE : GroupType.CLASS;
}
/**
* getId
* @return id
*/
public Long getId() {
return this.id;
}
/**
* getLecturer
* @return lecturer
*/
public Lecturer getLecturer() {
return lecturer;
}
/**
* setLecturer
* @param lecturer set lecturer into groups
*/
public void setLecturer(Lecturer lecturer) {
this.lecturer = lecturer;
}
/**
* WeekDay
* @return day
*/
public WeekDay getDay() {
return day;
}
/**
* setLecturer
* @param day set day into groups
*/
public void setDay(WeekDay day) {
this.day = day;
}
/**
* GroupType
* @return type
*/
public GroupType getType() {
return type;
}
/**
* setType
* @param type set type into groups
*/
public void setType(GroupType type) {
this.type = type;
}
/**
* getCapacity
* @return capacity
*/
public int getCapacity() {
return capacity;
}
/**
* setCapacity
* @param capacity set capacity into groups
*/
public void setCapacity(int capacity) {
this.capacity = capacity;
}
/**
* getRoom
* @return room
*/
public String getRoom() {
return room;
}
/**
* setRoom
* @param room set room into groups
*/
public void setRoom(String room) {
this.room = room;
}
/**
* getTime
* @return time
*/
public int getTime() {
return time;
}
/**
* setTime
* @param time set time into groups
*/
public void setTime(int time) {
this.time = time;
}
/**
* getCourseId
* @return course
*/
public Course getCourseId() {
return course;
}
/**
* setCourseId
* @param courseId set courseId into groups
*/
public void setCourseId(Course courseId) {
this.course = courseId;
}
/**
* getTimeString
* @return time as formated String
*/
public String getTimeString() {
int minutes = this.getTime() % 60;
String hoursString = Integer.toString(this.getTime() / 60);

View File

@ -5,6 +5,10 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
* Entity of Lecturer grouping of state ssociated about id,title,name,surname
*/
@Entity
public class Lecturer {
@Id
@ -14,30 +18,14 @@ public class Lecturer {
private String name;
private String surname;
public String getTitle() {
return title;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setTitle(String title) {
this.title = title;
}
/**
* Lecturer
*
* @param title title given to the lecturer
* @param name name given to the lecturer
* @param surname surname given to the lecturer
*/
public Lecturer(String title, String name, String surname) {
this.title = title;
this.name = name;
@ -47,9 +35,63 @@ public class Lecturer {
public Lecturer() {
}
/**
* getTitle
* @return title
*
*/
public String getTitle() {
return title;
}
/**
* getSurname
* @return surname
*
*/
public String getSurname() {
return surname;
}
/**
* setSurname
* @param surname set surname to the lecturer
*
*/
public void setSurname(String surname) {
this.surname = surname;
}
/**
* getName
* @return name
*
*/
public String getName() {
return name;
}
/**
* setName
* @param name set name to the lecturer
*
*/
public void setName(String name) {
this.name = name;
}
/**
* setTitle
* @param title set title to the lecturer
*
*/
public void setTitle(String title) {
this.title = title;
}
@Override
public String toString() {
return String.format("%s %s %s", this.title, this.name, this.surname);
}
}
}

View File

@ -10,6 +10,10 @@ import javax.persistence.Id;
import com.plannaplan.types.UserRoles;
/**
* Entity of User grouping of state ssociated about id,name,surname,email,role,token,tokenCreatedDate
*/
@Entity
public class User {
private static final float TOKEN_EXPIRE_MINUTES = 15;
@ -27,6 +31,14 @@ public class User {
public User() {
}
/*
* User
*
* @param name name given to the user
* @param surname surname given to the user
* @param email mail given to the user
* @param role role given to the user
*/
public User(String name, String surname, String mail, UserRoles role) {
this.name = name;
this.surname = surname;
@ -34,56 +46,113 @@ public class User {
this.role = role;
}
/*
* getEmail
*
* @return email
*/
public String getEmail() {
return email;
}
/*
* setEmail
*
* @param email set email to the user
*/
public void setEmail(String email) {
this.email = email;
}
/*
* getTokenUsageDate
*
* @return tokenUsageDate
*/
public Timestamp getTokenUsageDate() {
return tokenUsageDate;
}
/*
* getToken
*
* @return token
*/
public String getToken() {
return token;
}
/*
* setToken
*
* @param token set token to the entity
*/
public void setToken(String token) {
this.tokenUsageDate = new Timestamp(System.currentTimeMillis());
this.token = token;
}
/* getName
*
* @return name
*/
public String getName() {
return name;
}
/* getRole
*
* @return role
*/
public UserRoles getRole() {
return role;
}
/* setRole
*
* @param role set role to the entity
*/
public void setRole(UserRoles role) {
this.role = role;
}
/*
* getSurname
* @return surname
*/
public String getSurname() {
return surname;
}
/*
* setSurname
* @param surname set surname into entity user
*/
public void setSurname(String surname) {
this.surname = surname;
}
/*
* setName
* @param name set name into entity user
*/
public void setName(String name) {
this.name = name;
}
/*
* getId
* @return id
*/
public Long getId() {
return this.id;
}
public boolean isCredentialsNonExpired() {
/*
* isCredentialsNonExpired
* Returns TRUE if is Credentials Non Expired in the otherwise it returns false
*/
public boolean isCredentialsNonExpired() {
final long diffInMilliseconds = Math
.abs(this.tokenUsageDate.getTime() - new Timestamp(System.currentTimeMillis()).getTime());
final long minutes = TimeUnit.MILLISECONDS.toMinutes(diffInMilliseconds);
@ -94,4 +163,4 @@ public class User {
this.tokenUsageDate = new Timestamp(System.currentTimeMillis());
return true;
}
}
}

View File

@ -8,22 +8,44 @@ public class ConfigData {
private Date end;
private InputStream filestream;
/*
* ConfigData
*
* @param start when the configdata begins
* @param end when the configdata ends
* @param filestream where the filestream is
*/
public ConfigData(Date start, Date end, InputStream filestream) {
this.start = start;
this.end = end;
this.filestream = filestream;
}
/*
* getFilestream
*
* @return filestream
*/
public InputStream getFilestream() {
return filestream;
}
/*
* getEnd
*
* @return end
*/
public Date getEnd() {
return end;
}
/*
* getStart
*
* @return start
*/
public Date getStart() {
return start;
}
}
}

View File

@ -9,30 +9,57 @@ public class FileData {
private HashMap<String, Integer> keys;
private Iterator<Row> rows;
/*
* FileData
*
* @param keys this is a hashmap of String and Integer
* @param rows this is a iterator of rows.
*/
public FileData(HashMap<String, Integer> keys, Iterator<Row> rows) {
this.keys = keys;
this.rows = rows;
}
/*
* getRows
*
* @return rows
*/
public Iterator<Row> getRows() {
return rows;
}
/*
* setRows
* @param rows set the rows to given function
*/
public void setRows(Iterator<Row> rows) {
this.rows = rows;
}
/*
* getKeys
* @return keys
*/
public HashMap<String, Integer> getKeys() {
return keys;
}
/*
* setKeys
* @param keys set the key is being a struck of hashmap (String, Integer)
*/
public void setKeys(HashMap<String, Integer> keys) {
this.keys = keys;
}
/*
* getIndexOf
* @return index
*/
public int getIndexOf(String key) {
int index = this.keys.get(key);
return index;
}
}
}

View File

@ -9,6 +9,13 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* AssignmentRepository.getByCommision:
* Return list of:
* SELECT * FROM Assignment WHERE commision_id = i .
*
* Where i, ?1 are equale to variables.
*/
@Repository
public interface AssignmentRepository extends JpaRepository<Assignment, Long> {

View File

@ -9,6 +9,19 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* CommisionRepository.getUsers:
* Return list of:
* SELECT * FROM Commision WHERE owner_id = i .
*
* Where i, ?1 are equale to variables.
*
* CommisionRepository.getNewestCommision
* Return list of:
* SELECT * FROM Commision WHERE owner_id = i Order by commisionDate desc.
*
* Where i, ?1 are equale to variables.
*/
@Repository
public interface CommisionRepository extends JpaRepository<Commision, Long> {
@Query("FROM Commision WHERE owner_id = ?1")

View File

@ -9,6 +9,13 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* CourseRepository.findByName:
* Return list of:
* SELECT * FROM Course WHERE name = i .
*
* Where i, ?1 are equale to variables.
*/
@Repository
public interface CourseRepository extends JpaRepository<Course, Long> {
@Query("FROM Course WHERE name = ?1")

View File

@ -10,6 +10,19 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* GroupRepository.find:
* Return list of:
* SELECT * FROM Groups WHERE time = i AND room = j AND capacity = k .
*
* Where i, j, k, ?1, ?2, ?3 are equale to variables.
*
* GroupRepository.getByCourse:
* Return list of:
* SELECT * FROM Groups WHERE course_id = i .
*
* Where i, ?1 are equale to variables.
*/
@Repository
public interface GroupRepository extends JpaRepository<Groups, Long> {
@Query("FROM Groups WHERE time = ?1 AND room = ?2 AND capacity = ?3")

View File

@ -9,6 +9,13 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* LecturerRepository.find:
* Return list of:
* SELECT * FROM Lecturer WHERE title = i AND name = j AND surname = k.
*
* Where i, j, k, ?1, ?2, ?3 are equale to variables.
*/
@Repository
public interface LecturerRepository extends JpaRepository<Lecturer, Long> {
@Query("FROM Lecturer WHERE title = ?1 AND name = ?2 AND surname = ?3")

View File

@ -11,6 +11,32 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
/**
* UserRepository.getByAuthority:
* Return list of:
* SELECT * FROM User WHERE email = i.
*
* Where i, ?1 are equale to variables.
*
* UserRepository.getByToken:
* Return list of:
* SELECT * FROM User WHERE token = i.
*
* Where i, ?1 are equale to variables.
*
* UserRepository.searchForUsers:
* Return list of:
* SELECT * FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%).
*
* Where i, ?1 are equale to variables.
*
* UserRepository.searchForUsers with role:
* Return list of:
* SELECT * FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2").
*
* Where i, ?1 are equale to variables.
*/
@Repository
public interface UserRepository extends JpaRepository<User, Long> {
@Query("FROM User WHERE email = ?1")

View File

@ -10,6 +10,10 @@ import com.plannaplan.repositories.AssignmentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Service of Assignment which can save assignments, diplay assignments, get ammount of assigments.
*/
@Service
public class AssignmentService {
@Autowired
@ -18,19 +22,37 @@ public class AssignmentService {
public AssignmentService() {
}
/**
* Save given assignment
* @param assignment assignment to save
* @return assignment saved assignment with database id
*/
public Assignment save(Assignment assignment) {
return this.repo.save(assignment);
}
/*
* getCommisionAssignments
* Return id of the commision
*/
public List<Assignment> getCommisionAssignments(Commision com) {
return this.repo.getByCommision(com.getId());
}
/*
* getAssignmentsAmmount
* Return count assignments ammount
*/
public long getAssignmentsAmmount() {
return this.repo.count();
}
/**
* Get assigmnent by id
* @param id id of assigmnent
* @return Optional of assignment
*/
public Optional<Assignment> getById(Long id) {
return this.repo.findById(id);
}
}
}

View File

@ -11,6 +11,10 @@ import com.plannaplan.repositories.CommisionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Service of CommisionService which can save commision, get user's commisions, get newest user's commision, get ammount of commisions.
*/
@Service
public class CommisionService {
@Autowired
@ -21,6 +25,12 @@ public class CommisionService {
public CommisionService() {
}
/*
* save
*
* @param commision which assignment should be save in service
* @return commision
*/
public Commision save(Commision commision) {
Optional<Commision> lastCommision = this.getNewestCommision(commision.getCommisionOwner());
if (lastCommision.isPresent()) {
@ -35,14 +45,26 @@ public class CommisionService {
}
/*
* getUsersCommisions
* Return given users id
*/
public List<Commision> getUsersCommisions(User user) {
return this.repo.getUsers(user.getId());
}
/*
* getNewestCommision
* Return the newest commision of the user
*/
public Optional<Commision> getNewestCommision(User user) {
return this.repo.getNewestCommision(user.getId()).stream().findFirst();
}
/*
* getCommisionsAmmount
* Return ammount of commisions
*/
public long getCommisionsAmmount() {
return this.repo.count();
}

View File

@ -8,6 +8,9 @@ import org.springframework.stereotype.Component;
import com.plannaplan.configutils.*;
/**
* FileReader is used for reading xls file from input stream.
*/
@Component
public class ConfiguratorService {

View File

@ -9,29 +9,53 @@ import com.plannaplan.repositories.CourseRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Service of CourseService which can get(Course By Name, All Courses, Courses Ammount ), save, delete course.
*/
@Service
public class CourseService {
@Autowired
private CourseRepository repo;
/*
* getCourseByName
* Return Course By Name
*/
public Optional<Course> getCourseByName(String name) {
return this.repo.findByName(name);
}
/*
* getAllCourses
* Return List of get courses
*/
public List<Course> getAllCourses() {
return this.repo.findAll();
}
/*
* save
* @param course which course you would like to save
*/
public Course save(Course course) {
this.repo.save(course);
return course;
}
/*
* delete
* @param course which course you would like to delete
*/
public void delete(Course course) {
this.repo.delete(course);
}
/*
* getCoursesAmmount
* Return a ammount of courses
*/
public int getCoursesAmmount() {
return (int) this.repo.count();
}
}
}

View File

@ -13,6 +13,10 @@ import com.plannaplan.repositories.GroupRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Service of GroupService which can find(optional), get(By Course, Groups Ammount, Group By Id, find Not Existing Group), save, delete group.
*/
@Service
public class GroupService {
@Autowired

View File

@ -8,6 +8,9 @@ import com.plannaplan.repositories.LecturerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Service of LecturerService which can get(Lecturer, Lecturers Ammount), save, delete lecturers.
*/
@Service
public class LecturerService {
@Autowired

View File

@ -12,6 +12,9 @@ import com.plannaplan.types.UserRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Service of UserService which can get(By Email), login, save user.
*/
@Service
public class UserService {
@Autowired

View File

@ -1,5 +1,9 @@
package com.plannaplan.types;
/**
* GroupType contains types: LECTURE, CLASS
*/
public enum GroupType {
LECTURE, CLASS
}

View File

@ -1,5 +1,9 @@
package com.plannaplan.types;
/**
* UserRoles contains types: STUDENT, DEANERY, ADMIN, TEST_USER
*/
public enum UserRoles {
STUDENT, DEANERY, ADMIN, TEST_USER
}

View File

@ -1,5 +1,9 @@
package com.plannaplan.types;
/**
* WeekDay contains types: MONDAY(0), TUESDAY(1), WEDNESDAY(2), THURSDAY(3), FRIDAY(4), SATURDAY(5), SUNDAY(6).
*/
public enum WeekDay {
MONDAY(0), TUESDAY(1), WEDNESDAY(2), THURSDAY(3), FRIDAY(4), SATURDAY(5), SUNDAY(6);