Compare commits
107 Commits
cors-fixed
...
token-rele
Author | SHA1 | Date | |
---|---|---|---|
acf80cc78d | |||
c34d53d056 | |||
48394d3583 | |||
82200acc06 | |||
f9baed5df7 | |||
3061fb1edf | |||
b412ee2a5b | |||
2037f0bf07
|
|||
b4f23aa5d2 | |||
495098eeed | |||
751d4b1744 | |||
cbe8f96700 | |||
2dd1f70eee
|
|||
c70cac58b2
|
|||
616f782155
|
|||
6dfb99f253
|
|||
b897fce416
|
|||
f4db74b899
|
|||
453907782a
|
|||
3ebfda5316
|
|||
b6c2e43975
|
|||
6298bb4765
|
|||
c24aa73bb0
|
|||
20d261635b
|
|||
1e3cccc991
|
|||
cd96e74c29
|
|||
7d747b60a8
|
|||
c3fd450499 | |||
b966b64fdb
|
|||
1d15d295e0 | |||
f8b12d831b
|
|||
20341d5441
|
|||
3faa228745
|
|||
e6fffba899
|
|||
708cedf7b4
|
|||
96c903ed15
|
|||
160930c3c3
|
|||
823f4af218
|
|||
b2b9178bc1 | |||
7e45da1306 | |||
c2c82b75ba | |||
78ed2f75f3 | |||
082b30133c | |||
25e9571a06 | |||
593084aeba | |||
911f2e54f5
|
|||
13eb8dae77 | |||
7d5522e413
|
|||
9ed4197005
|
|||
dc3a554ed1
|
|||
f6a8953c17
|
|||
2545a0e682 | |||
0130fb77e1 | |||
9d3500c1fb | |||
b4bb13f2dd | |||
e752ad06cd
|
|||
6d9c5a8a5d
|
|||
85052f5728
|
|||
50c1397db2
|
|||
af8e2ced28
|
|||
9ad8db527d
|
|||
bc6c55165e
|
|||
3e7086eab9 | |||
c34ce94fb0 | |||
17e5625315
|
|||
1ddeb83cb4 | |||
b713066a2f | |||
029300815e
|
|||
7c7045c0e1
|
|||
035de011f2
|
|||
1b126c7792 | |||
a30c3af09c
|
|||
62bbf148b2 | |||
8ba148617a | |||
48fdeb726f | |||
bd4591f442 | |||
0fbc6d6baa | |||
feff5c4b9c | |||
d2343acc2d | |||
cbd9074a89 | |||
228969efce | |||
e0df090a0e | |||
6a7fc03e7c | |||
4818905422 | |||
b308373062 | |||
ba26d67cd4 | |||
1a30ac3374 | |||
b4f51d4382 | |||
6ab2ec50dd | |||
9bff6460d6 | |||
1571bccb49 | |||
1327a239e8 | |||
2b59c181e5 | |||
ca01b20221 | |||
956b53439f | |||
b40acf8919 | |||
ed00731654 | |||
3a3e6dc427 | |||
4267fadf62 | |||
41f37ee9ad | |||
4ca2837b59 | |||
953168a452 | |||
d3a2256334 | |||
933e09172b | |||
f0eae82d9f | |||
7073e3b1d8 | |||
bdfed57942 |
5
.gitignore
vendored
5
.gitignore
vendored
@ -29,3 +29,8 @@ build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
|
||||
### Python ###
|
||||
__pycache__
|
||||
.pytest_cache
|
60
README.md
60
README.md
@ -3,28 +3,44 @@
|
||||
Zeby wystartowac aplikacje backendu najpierw nalezy postawic testowa baze danych na naszym komputerze za pomoca dockera. Jesli raz juz go odpalimy przy nastepnym razem bardzo mozliwe, ze wlaczy sie sam. AAby sprawdzic czy docker jesty wystartowany mozna uzyc `docker ps`
|
||||
|
||||
```
|
||||
docker-compose -f stack.yml up
|
||||
```
|
||||
|
||||
Nastepnie w `restservice/src/main/resources/application.properties` nalezy podac ip naszego kontenera.
|
||||
|
||||
```
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/test
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=example
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.jpa.hibernate.ddl-auto=create
|
||||
|
||||
server.port=1285
|
||||
docker-compose -f stack.yml up -d
|
||||
```
|
||||
|
||||
Następnym krokiem jest odpalenie poniższych komend w terminalu.
|
||||
|
||||
```
|
||||
cd restservice
|
||||
mvn spring-boot:run
|
||||
```
|
||||
|
||||
## Token obtaining
|
||||
|
||||
Żeby tesotwać API wpełni potrzebny nam jest token który otrzymujemy na podstawie ticketa z systemu autoryzacyjnego **CAS**. Z tego powodu system autoryzacji działa inaczej niż w "książkowych" restowych aplikacjach i np Postman za nas jej nie dokona. Musimy mu podać już uzyskany token. Aby łatwo go uzyskać odpal skrypt
|
||||
|
||||
```
|
||||
python gettoken.py
|
||||
```
|
||||
|
||||
Na koniec w przęglądarce dostaniesz w odpowiedzi token. W samym pliku można zmienić porty aplikacji jeśli to potrzebne.
|
||||
|
||||
## Profiles
|
||||
|
||||
W aplikacji posiadamy dwa profile. `dev` i `prod`. **Dev** używamy do testowania aplikacji lokalnie. **Pord** służy do stworzenia builda na produkcję.
|
||||
Profil wybieramy w pliku `restservice/src/main/resources/application.properties` wpisując odpowiednią nazwę
|
||||
|
||||
```
|
||||
spring.profiles.active=prod
|
||||
```
|
||||
|
||||
Jeżeli chcemy zmienić jakieś opcję dla pordukcji to robimy to w tym sammym katalogi w pliku `application-prod.properties` i dla dev analogicznie w `application-dev.properties`.
|
||||
W paczce dla proda w protpertiesach poufne dane odczytywane są ze zmiennych środowiskowych systemu na którym odpalana jest aplikacja. Ustawić trzeba następujące zmienne:
|
||||
|
||||
- PLANNAPLAN_MYSQL_DB_HOST - host bazy danych np `localhost`
|
||||
- PLANNAPLAN_MYSQL_DB_PORT - port na którym działa baza
|
||||
- PLANNAPLAN_MYSQL_DB - nazwa bazy dancyh. W profilu **dev** jest to np test
|
||||
- PLANNAPLAN_MYSQL_DB_USERNAME - nazwa użytkownika bazy
|
||||
- PLANNAPLAN_MYSQL_DB_PASSWORD - hasło użytkownika bazy
|
||||
|
||||
## Packaging
|
||||
|
||||
Zeby spakowac apke do `jara` wystarcza dwie komendy zaczynajac z glownego katalogu projektu
|
||||
@ -38,6 +54,22 @@ 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
|
||||
|
||||
### Javadocs
|
||||
|
||||
```bash
|
||||
mvn javadoc:javadoc
|
||||
```
|
||||
|
||||
### Api docs
|
||||
|
||||
Żeby zobaczyć dokumentację api trzeba wejść w przeglądarce na `http://localhost:1285/swagger-ui.html` po odpaleniu aplikacji.
|
||||
|
||||
#### Nazewnictwo odpowiedzi
|
||||
|
||||
Każdą odpowiedź zaczynamy od modelu, który opisuje np. `Courses` a kończymy na `Response`. Między tymi dwoma członami możemy dodawać modyfikatory opisujące dokładniej odpowiedź np. `Default`. W ten sposób możemy otrzymać nazwę `CoursesDefaultResponse.java`
|
||||
|
||||
## 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
|
||||
|
@ -16,8 +16,8 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.14</maven.compiler.source>
|
||||
<maven.compiler.target>1.14</maven.compiler.target>
|
||||
<maven.compiler.source>14</maven.compiler.source>
|
||||
<maven.compiler.target>14</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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
|
||||
@ -18,20 +23,62 @@ public class Assignment {
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "commision_id")
|
||||
private Commision commision;
|
||||
|
||||
public Assignment(Groups group, 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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
@ -11,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
|
||||
@ -21,9 +26,14 @@ public class Commision {
|
||||
private User commisionOwner;
|
||||
private Timestamp commisionDate;
|
||||
|
||||
@OneToMany(mappedBy = "commision")
|
||||
@OneToMany(mappedBy = "commision", fetch = FetchType.EAGER)
|
||||
private List<Assignment> assignments;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param user owner of commission. Can not be null otherwise saving commision
|
||||
* will fail.
|
||||
*/
|
||||
public Commision(User user) {
|
||||
this.commisionDate = new Timestamp(System.currentTimeMillis());
|
||||
this.commisionOwner = user;
|
||||
@ -32,16 +42,36 @@ 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
@ -9,21 +10,37 @@ 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;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
private String name;
|
||||
private String surname;
|
||||
private String email;
|
||||
private String usosId;
|
||||
private UserRoles role;
|
||||
private String token;
|
||||
private Date tokenCreatedDate;
|
||||
private Timestamp tokenUsageDate;
|
||||
|
||||
|
||||
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;
|
||||
@ -31,52 +48,144 @@ public class User {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
/*
|
||||
* User
|
||||
*
|
||||
* @param name name given to the user
|
||||
* @param surname surname given to the user
|
||||
* @param email mail given to the user
|
||||
* @param usosId id in the USOS system
|
||||
* @param role role given to the user
|
||||
*/
|
||||
public User(String name, String surname, String mail, String usosId, UserRoles role){
|
||||
this(name,surname,mail,role);
|
||||
this.usosId = usosId;
|
||||
}
|
||||
|
||||
/*
|
||||
* getusosId
|
||||
*
|
||||
* @return usosId
|
||||
*/
|
||||
public String getUsosId() {
|
||||
return usosId;
|
||||
}
|
||||
|
||||
/*
|
||||
* getEmail
|
||||
*
|
||||
* @return email
|
||||
*/
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
/*
|
||||
* setEmail
|
||||
*
|
||||
* @param email set email to the user
|
||||
*/
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Date getTokenCreatedDate() {
|
||||
return tokenCreatedDate;
|
||||
/*
|
||||
* 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.tokenCreatedDate = new Date(System.currentTimeMillis());
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
if (minutes > TOKEN_EXPIRE_MINUTES) {
|
||||
return false;
|
||||
}
|
||||
this.tokenUsageDate = new Timestamp(System.currentTimeMillis());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.plannaplan.exceptions;
|
||||
|
||||
public class TokenExpiredException extends RuntimeException {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public TokenExpiredException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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> {
|
||||
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
@ -18,4 +31,18 @@ public interface GroupRepository extends JpaRepository<Groups, Long> {
|
||||
@Query("FROM Groups WHERE course_id = ?1")
|
||||
List<Groups> getByCourse(@Param("id") Long id);
|
||||
|
||||
@Query("SELECT COUNT(*) AS assinged_times FROM Assignment WHERE isPastAssignment=false GROUP BY group HAVING group_id=?1")
|
||||
Optional<Number> getAssignedAmount(Long groupId);
|
||||
|
||||
/**
|
||||
* PLAIN SQL QUERY: SELECT group_id, COUNT(*) assinged_times FROM assignment
|
||||
* WHERE is_past_assignment=0 GROUP BY group_id HAVING group_id IN (:ids)")
|
||||
*
|
||||
* @param groupIds list of groups ids
|
||||
* @return list of objects arrays where first object is Groups instance and
|
||||
* second is Long that is taken places value
|
||||
*/
|
||||
@Query("SELECT group, COUNT(*) AS assinged_times FROM Assignment a WHERE a.isPastAssignment=false GROUP BY a.group HAVING group_id IN (:ids)")
|
||||
List<Object[]> getAssignedAmounts(@Param("ids") List<Long> groupIds);
|
||||
|
||||
}
|
@ -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")
|
||||
|
@ -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")
|
||||
@ -24,4 +50,7 @@ public interface UserRepository extends JpaRepository<User, Long> {
|
||||
|
||||
@Query("FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2")
|
||||
List<User> searchForUsers(@Param("query") String query, @Param("role") UserRoles role);
|
||||
|
||||
@Query("FROM User WHERE usosId = ?1")
|
||||
Optional<User> getByUsosId(@Param("usosId") String usosId);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
@ -9,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
|
||||
@ -17,15 +22,37 @@ public class AssignmentService {
|
||||
public AssignmentService() {
|
||||
}
|
||||
|
||||
public void save(Assignment assignment) {
|
||||
this.repo.save(assignment);
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
@ -5,33 +5,66 @@ import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.repositories.AssignmentRepository;
|
||||
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
|
||||
private CommisionRepository repo;
|
||||
@Autowired
|
||||
private AssignmentRepository aRepository;
|
||||
|
||||
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()) {
|
||||
final Commision lastCom = lastCommision.get();
|
||||
lastCom.getAssignments().forEach(assignment -> {
|
||||
assignment.setPastAssignment(true);
|
||||
this.aRepository.save(assignment);
|
||||
});
|
||||
}
|
||||
this.repo.save(commision);
|
||||
return commision;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.repositories.GroupRepository;
|
||||
@ -9,6 +13,11 @@ 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
|
||||
@ -26,8 +35,7 @@ public class GroupService {
|
||||
}
|
||||
|
||||
public Groups save(Groups group) {
|
||||
this.repo.save(group);
|
||||
return group;
|
||||
return this.repo.save(group);
|
||||
}
|
||||
|
||||
public void delete(Groups groups) {
|
||||
@ -41,4 +49,44 @@ public class GroupService {
|
||||
public Optional<Groups> getGroupById(Long id) {
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
|
||||
public Optional<Long> findNotExistingGroup(List<Long> ids) {
|
||||
for (Long oneId : ids) {
|
||||
if (this.repo.existsById(oneId) == false) {
|
||||
return Optional.of(oneId);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param groups list of groups you want to get taken places ammount
|
||||
* @return HashMap<Long, Integer> where Long is group id and Integer is how many
|
||||
* places in gorup is already taken
|
||||
*/
|
||||
public HashMap<Long, Integer> getTakenPlaces(List<Groups> groups) {
|
||||
HashMap<Long, Integer> response = new HashMap<>();
|
||||
|
||||
if (groups.size() == 0) {
|
||||
return response;
|
||||
}
|
||||
|
||||
List<Object[]> respoonses = this.repo
|
||||
.getAssignedAmounts(groups.stream().filter(Objects::nonNull).map(new Function<Groups, Long>() {
|
||||
@Override
|
||||
public Long apply(Groups p) {
|
||||
final Long id = p.getId();
|
||||
response.put(id, 0);
|
||||
return id;
|
||||
}
|
||||
}).collect(Collectors.toList()));
|
||||
|
||||
for (Object[] element : respoonses) {
|
||||
response.put(((Groups) element[0]).getId(), ((Long) element[1]).intValue());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
@ -21,18 +24,39 @@ public class UserService {
|
||||
super();
|
||||
}
|
||||
|
||||
public String login(String authority) throws UserNotFoundException {
|
||||
User user = this.repo.getByAuthority(authority.replace("\n", "").trim())
|
||||
.orElseThrow(() -> new UserNotFoundException("Can not find user with given authority"));
|
||||
|
||||
final String token = UUID.randomUUID().toString();
|
||||
user.setToken(token);
|
||||
this.repo.save(user);
|
||||
return token;
|
||||
public User checkForUser(String email, String usosId) {
|
||||
if (usosId == null) {
|
||||
Optional<User> user = this.repo.getByAuthority(email.replace("\n", "").trim());
|
||||
if (user.isPresent()) {
|
||||
return user.get();
|
||||
} else {
|
||||
final User newUser = new User(null, null, email.replace("\n", "").trim(), UserRoles.STUDENT);
|
||||
return this.repo.save(newUser);
|
||||
}
|
||||
} else {
|
||||
Optional<User> user = this.repo.getByUsosId(usosId.replace("\n", "").trim());
|
||||
if (user.isPresent()) {
|
||||
return user.get();
|
||||
} else {
|
||||
final User newUser = new User(null, null, email.replace("\n", "").trim(), usosId, UserRoles.STUDENT);
|
||||
return this.repo.save(newUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void save(User user) {
|
||||
this.repo.save(user);
|
||||
public User login(User authority) throws UserNotFoundException {
|
||||
final String token = UUID.randomUUID().toString();
|
||||
try {
|
||||
authority.setToken(token);
|
||||
this.repo.save(authority);
|
||||
} catch (Exception e) {
|
||||
throw new UserNotFoundException(e.getMessage());
|
||||
}
|
||||
return authority;
|
||||
}
|
||||
|
||||
public User save(User user) {
|
||||
return this.repo.save(user);
|
||||
}
|
||||
|
||||
public User getUserByEmail(String email) throws UserNotFoundException {
|
||||
@ -49,4 +73,8 @@ public class UserService {
|
||||
return this.repo.searchForUsers(query, UserRoles.STUDENT);
|
||||
}
|
||||
|
||||
public Optional<User> getById(Long userId) {
|
||||
return this.repo.findById(userId);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
package com.plannaplan.types;
|
||||
|
||||
/**
|
||||
* GroupType contains types: LECTURE, CLASS
|
||||
*/
|
||||
|
||||
public enum GroupType {
|
||||
LECTURE, CLASS
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
package com.plannaplan.types;
|
||||
|
||||
/**
|
||||
* UserRoles contains types: STUDENT, DEANERY, ADMIN, TEST_USER
|
||||
*/
|
||||
|
||||
public enum UserRoles {
|
||||
STUDENT, DEANERY, ADMIN, TEST_USER
|
||||
}
|
@ -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);
|
||||
|
||||
|
71
buisnesslogic/src/test/java/com/plannaplan/entities/UserTest.java
Executable file
71
buisnesslogic/src/test/java/com/plannaplan/entities/UserTest.java
Executable file
@ -0,0 +1,71 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class UserTest {
|
||||
|
||||
@Test
|
||||
public void shouldResturnTokenIsNotExpired() {
|
||||
final User user = new User();
|
||||
user.setToken("testowy-bezpieczny-token");
|
||||
assertTrue(user.isCredentialsNonExpired(), "Credential shouldnt expire yet");
|
||||
|
||||
long minutes = this.getMinutesDiff(user.getTokenUsageDate());
|
||||
|
||||
assertTrue(minutes == 0, "Should update last token usage");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldResturnTokenIsNotExpiredWithLessThan15minutes()
|
||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||
|
||||
final User user = new User();
|
||||
user.setToken("testowy-bezpieczny-token");
|
||||
this.setLastTokenUsage(user, new Timestamp(System.currentTimeMillis() - (6 * 60 * 1000)));
|
||||
|
||||
assertTrue(user.isCredentialsNonExpired(), "Credential shouldnt expire yet");
|
||||
|
||||
final long minutes = this.getMinutesDiff(user.getTokenUsageDate());
|
||||
assertTrue(minutes == 0, "Should update last token usage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldResturnTokenIsExpired()
|
||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||
|
||||
final User user = new User();
|
||||
user.setToken("testowy-bezpieczny-token");
|
||||
this.setLastTokenUsage(user, new Timestamp(System.currentTimeMillis() - (25 * 60 * 1000)));
|
||||
|
||||
assertFalse(user.isCredentialsNonExpired(), "Credential should expire");
|
||||
|
||||
final long diffInMilliseconds = Math
|
||||
.abs(user.getTokenUsageDate().getTime() - new Timestamp(System.currentTimeMillis()).getTime());
|
||||
final long minutes = TimeUnit.MILLISECONDS.toMinutes(diffInMilliseconds);
|
||||
|
||||
assertTrue(minutes > 0, "Shouldn't update last token usage");
|
||||
}
|
||||
|
||||
private long getMinutesDiff(Timestamp timestamp) {
|
||||
final long diffInMilliseconds = Math
|
||||
.abs(timestamp.getTime() - new Timestamp(System.currentTimeMillis()).getTime());
|
||||
final long minutes = TimeUnit.MILLISECONDS.toMinutes(diffInMilliseconds);
|
||||
return minutes;
|
||||
}
|
||||
|
||||
private void setLastTokenUsage(User user, Timestamp timestampToSet)
|
||||
throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||
Field reader = User.class.getDeclaredField("tokenUsageDate");
|
||||
reader.setAccessible(true);
|
||||
reader.set(user, timestampToSet);
|
||||
}
|
||||
|
||||
}
|
106
buisnesslogic/src/test/java/com/plannaplan/repositories/GroupRepositoryTest.java
Executable file
106
buisnesslogic/src/test/java/com/plannaplan/repositories/GroupRepositoryTest.java
Executable file
@ -0,0 +1,106 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.CommisionService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.services.UserService;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class GroupRepositoryTest {
|
||||
@Autowired
|
||||
private GroupRepository repository;
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private CommisionService commisionService;
|
||||
|
||||
@Test
|
||||
public void shouldReturnGroupAssignmentTimes() throws InterruptedException {
|
||||
final Groups testGroup = groupService.save(new Groups(43, "A-41", null, 235, WeekDay.MONDAY, null));
|
||||
int startGroupAmmount = this.repository.getAssignedAmount(testGroup.getId()).orElse(Integer.valueOf(0))
|
||||
.intValue();
|
||||
|
||||
final User user = this.userService.save(new User("Luis", "Vita",
|
||||
"shouldReturnGroupAssignmentTimes@grouprepository.test", UserRoles.STUDENT));
|
||||
final Commision commision = this.commisionService.save(new Commision(user));
|
||||
|
||||
this.assignmentService.save(new Assignment(testGroup, commision));
|
||||
Thread.sleep(1000);
|
||||
|
||||
int afterAssignedGroupAmmount = this.repository.getAssignedAmount(testGroup.getId())
|
||||
.orElse(Integer.valueOf(0)).intValue();
|
||||
|
||||
assertTrue(afterAssignedGroupAmmount > startGroupAmmount);
|
||||
|
||||
final Commision recommision = this.commisionService.save(new Commision(user));
|
||||
this.assignmentService.save(new Assignment(testGroup, recommision));
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
int afterreAssignedGroupAmmount = this.repository.getAssignedAmount(testGroup.getId())
|
||||
.orElse(Integer.valueOf(0)).intValue();
|
||||
|
||||
assertTrue(afterAssignedGroupAmmount == afterreAssignedGroupAmmount);
|
||||
|
||||
this.commisionService.save(new Commision(user));
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
int afterdeAssignedGroupAmmount = this.repository.getAssignedAmount(testGroup.getId())
|
||||
.orElse(Integer.valueOf(0)).intValue();
|
||||
|
||||
assertTrue(afterdeAssignedGroupAmmount < afterreAssignedGroupAmmount);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnGroupAssignmentTimesList() throws InterruptedException {
|
||||
final Groups testGroup = groupService.save(new Groups(43, "A-41", null, 645, WeekDay.MONDAY, null));
|
||||
final Groups testGroup2 = groupService.save(new Groups(433, "A-41", null, 235, WeekDay.TUESDAY, null));
|
||||
final Groups testGroup3 = groupService.save(new Groups(23, "A-41", null, 340, WeekDay.MONDAY, null));
|
||||
final User user = this.userService.save(new User("Dare", "Oc",
|
||||
"shouldReturnGroupAssignmentTimesList@grouprepository.test", UserRoles.STUDENT));
|
||||
final Commision commision = this.commisionService.save(new Commision(user));
|
||||
|
||||
this.assignmentService.save(new Assignment(testGroup, commision));
|
||||
this.assignmentService.save(new Assignment(testGroup2, commision));
|
||||
this.assignmentService.save(new Assignment(testGroup3, commision));
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
List<Object[]> response = this.repository
|
||||
.getAssignedAmounts(List.of(testGroup.getId(), testGroup2.getId(), testGroup3.getId()));
|
||||
|
||||
assertTrue("Response should have size 3", response.size() == 3);
|
||||
assertTrue("Instance of firest element should be Group", response.get(0)[0] instanceof Groups);
|
||||
assertTrue("Instance of firest element should be Long", response.get(0)[1] instanceof Long);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -11,8 +11,9 @@ import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
@ -26,24 +27,31 @@ public class AssignmentServiceTest {
|
||||
private AssignmentService service;
|
||||
@Autowired
|
||||
private CommisionService comServie;
|
||||
private Commision com;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
this.com = new Commision();
|
||||
this.comServie.save(this.com);
|
||||
}
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Test
|
||||
public void shouldSaveAssignment() {
|
||||
final User user = new User("Gibi", "Kovalsky", "shouldSaveAssignment@assignmentservice.test",
|
||||
UserRoles.STUDENT);
|
||||
this.userService.save(user);
|
||||
|
||||
long beginState = this.service.getAssignmentsAmmount();
|
||||
this.addAssignmentToCommision(this.com);
|
||||
Commision com = new Commision(user);
|
||||
this.comServie.save(com);
|
||||
this.addAssignmentToCommision(com);
|
||||
assertTrue("Assign ammount should increase", this.service.getAssignmentsAmmount() > beginState);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetCommisionAssignments() {
|
||||
this.addAssignmentToCommision(this.com);
|
||||
final User user = new User("Gibi", "Kovalsky", "shouldGetCommisionAssignments@assignmentservice.test",
|
||||
UserRoles.STUDENT);
|
||||
this.userService.save(user);
|
||||
Commision com = new Commision(user);
|
||||
this.comServie.save(com);
|
||||
this.addAssignmentToCommision(com);
|
||||
|
||||
final List<Assignment> response = this.service.getCommisionAssignments(com);
|
||||
assertTrue("Returned list size should be 1", response.size() == 1);
|
||||
}
|
||||
|
@ -7,8 +7,10 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -24,10 +26,15 @@ public class CommisionServiceTest {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
@Test
|
||||
public void shouldSaveCommision() {
|
||||
User usr = new User();
|
||||
this.userService.save(usr);
|
||||
long beginState = this.service.getCommisionsAmmount();
|
||||
this.service.save(new Commision());
|
||||
this.service.save(new Commision(usr));
|
||||
assertTrue("Commision ammount should have changed", this.service.getCommisionsAmmount() > beginState);
|
||||
}
|
||||
|
||||
@ -57,4 +64,31 @@ public class CommisionServiceTest {
|
||||
assertTrue("Wrong commision was returned", result.getId().equals(newestCommision.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMarkAssignmentsOfPreviousCommisionPast() {
|
||||
final User usr = new User("Trevor", "Hammolt",
|
||||
"shouldMarkAssignmentsOfPreviousCommisionPast@commisionservice.test", UserRoles.STUDENT);
|
||||
this.userService.save(usr);
|
||||
|
||||
final Commision firstCommision = new Commision(usr);
|
||||
this.service.save(firstCommision);
|
||||
|
||||
Assignment firstCommisionAssignment = this.assignmentService.save(new Assignment(null, firstCommision));
|
||||
|
||||
assertTrue("FirstCommisionAssignment should be flaged as present assignment",
|
||||
!firstCommisionAssignment.isPastAssignment());
|
||||
|
||||
final Commision secondCommision = new Commision(usr);
|
||||
this.service.save(secondCommision);
|
||||
|
||||
Assignment secondCommisionAssignment = new Assignment(null, secondCommision);
|
||||
this.assignmentService.save(secondCommisionAssignment);
|
||||
|
||||
assertTrue("SecondCommisionAssignment should be flaged as present assignment",
|
||||
!secondCommisionAssignment.isPastAssignment());
|
||||
assertTrue("FirstCommisionAssignment should be flaged as past assignment",
|
||||
this.assignmentService.getById(firstCommisionAssignment.getId()).get().isPastAssignment());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,15 @@ package com.plannaplan.services;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -18,6 +26,12 @@ public class GroupServiceTest {
|
||||
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
@Autowired
|
||||
private CommisionService commisionService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Test
|
||||
public void createAndDeleteGroup() {
|
||||
@ -31,4 +45,27 @@ public class GroupServiceTest {
|
||||
groupService.delete(group);
|
||||
assertTrue(this.groupService.getGroupsAmmount() == startAmmount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetGroupsAssignmentsAmmounts() throws InterruptedException {
|
||||
final Groups testGroup = groupService.save(new Groups(43, "A-41", null, 645, WeekDay.MONDAY, null));
|
||||
final Groups testGroup2 = groupService.save(new Groups(433, "A-41", null, 235, WeekDay.TUESDAY, null));
|
||||
final Groups testGroup3 = groupService.save(new Groups(23, "A-41", null, 340, WeekDay.MONDAY, null));
|
||||
final User user = this.userService.save(
|
||||
new User("Dare", "Oc", "shouldReturnGroupAssignmentTimesList@grouprepository.test", UserRoles.STUDENT));
|
||||
final Commision commision = this.commisionService.save(new Commision(user));
|
||||
|
||||
this.assignmentService.save(new Assignment(testGroup, commision));
|
||||
this.assignmentService.save(new Assignment(testGroup2, commision));
|
||||
this.assignmentService.save(new Assignment(testGroup3, commision));
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
HashMap<Long, Integer> response = this.groupService.getTakenPlaces(List.of(testGroup, testGroup2, testGroup3));
|
||||
|
||||
assertTrue(response.size() == 3);
|
||||
assertTrue(response.get(testGroup.getId()) == 1);
|
||||
assertTrue(response.get(testGroup2.getId()) == 1);
|
||||
assertTrue(response.get(testGroup3.getId()) == 1);
|
||||
}
|
||||
}
|
||||
|
@ -32,12 +32,12 @@ public class UserServiceTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnToken() {
|
||||
final User testUser = new User(TEST_USER_NAME, TEST_USER_SUERNAME, TEST_USER_MAIL, UserRoles.TEST_USER);
|
||||
this.userService.save(testUser);
|
||||
User testUser = this.userService
|
||||
.save(new User(TEST_USER_NAME, TEST_USER_SUERNAME, TEST_USER_MAIL, UserRoles.TEST_USER));
|
||||
try {
|
||||
final String token = this.userService.login(TEST_USER_MAIL);
|
||||
System.out.println("Returned token: " + token);
|
||||
assertTrue(token != null);
|
||||
testUser = this.userService.login(testUser);
|
||||
System.out.println("Returned token: " + testUser.getToken());
|
||||
assertTrue(testUser.getToken() != null);
|
||||
assertTrue(this.userService.getUserByEmail(TEST_USER_MAIL).getToken() != null);
|
||||
} catch (UserNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
@ -45,16 +45,6 @@ public class UserServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldThrowException() {
|
||||
try {
|
||||
this.userService.login("thiseamilisnotindatabase@gmail.com");
|
||||
assertTrue(false);
|
||||
} catch (UserNotFoundException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindStudents() {
|
||||
this.userService.save(new User("Nemo", "TheFish", "Nemo@shouldFindStudents.test", UserRoles.STUDENT));
|
||||
@ -93,4 +83,21 @@ public class UserServiceTest {
|
||||
private boolean containsName(final List<User> list, final String name) {
|
||||
return list.stream().map(User::getName).filter(name::equals).findFirst().isPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateUser() {
|
||||
|
||||
final User user = this.userService.checkForUser("shouldCreateUser@UserService.test", null);
|
||||
|
||||
assertTrue(user.getId() != null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnExistingUser() {
|
||||
final String email = "shouldReturnExistingUser@UserService.test";
|
||||
this.userService.save(new User("Tom", "Smieszne", email, UserRoles.TEST_USER));
|
||||
final User user = this.userService.checkForUser(email, null);
|
||||
|
||||
assertTrue(user.getName() != "Tom");
|
||||
}
|
||||
}
|
||||
|
@ -7,5 +7,6 @@ spring.jpa.open-in-view=true
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
||||
spring.jackson.serialization.fail-on-empty-beans=false
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
spring.jackson.default-property-inclusion = NON_NULL
|
||||
|
||||
server.port=1285
|
88
docs/api.md
88
docs/api.md
@ -1,88 +0,0 @@
|
||||
# Dokumetacja API
|
||||
|
||||
| Api | Zadania endpointa |
|
||||
| ------------------------------------------------------------- | ---------------------------------------------------------------------------- |
|
||||
| [/api/v1/configurator/config](#config) | Załadowanie konfiguracji startowej do aplikacji PlanNaPlan |
|
||||
| [/api/v1/courses/getCoursesWithGroups](#getcourseswithgroups) | Zwrócenie wszytskich kursów razem z grupami |
|
||||
| [/api/v1/groups/getCourseGroups](#getcoursegroups) | Zwrócenie grup dla danego kursu |
|
||||
| [/api/v1/courses/getCourses](#getcourses) | Zwrócenie wszystkich kursów |
|
||||
| [/token](#token) | Wymienia ticket z CAS-a na token ktorym beda autoryzowane chronione requesty |
|
||||
|
||||
## config
|
||||
|
||||
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/ConfigController.java)
|
||||
|
||||
```
|
||||
POST /config
|
||||
```
|
||||
|
||||
#### Opis
|
||||
|
||||
Endpoint konfigurujacy caly system i importujacy dane do bazy.
|
||||
|
||||
#### Parametry
|
||||
|
||||
| Type | Name | Consumes | Opis | Type |
|
||||
| ---- | ----------------------- | ------------------- | ------------------------------- | ---- |
|
||||
| Body | **file** </br> required | multipart/form-data | Plik .xlsx z potrzebnymi danymi | file |
|
||||
|
||||
## getCoursesWithGroups
|
||||
|
||||
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/getCoursesWithGroups.java)
|
||||
|
||||
```
|
||||
GET /api/v1/courses/getCoursesWithGroups
|
||||
```
|
||||
|
||||
#### Opis
|
||||
|
||||
Zwraca wszystkie dostepne kursy wraz z listą grup.
|
||||
|
||||
## getCourseGroups
|
||||
|
||||
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/GroupController.java)
|
||||
|
||||
```
|
||||
GET /api/v1/groups/getCourseGroups
|
||||
```
|
||||
|
||||
#### Opis
|
||||
|
||||
Zwraca wszytskie grupy dla danego kursu.
|
||||
|
||||
#### Parametry
|
||||
|
||||
| Type | Name | Consumes | Opis | Type |
|
||||
| ----------- | --------------------- | -------- | ----------------------------------------- | ---- |
|
||||
| Query Param | **id** </br> required | - | id kursu dla ktorego chcemy zwrocic grupy | int |
|
||||
| Query Param | **capacity** </br> | - | czy ma zwrocic pole pojemnosci grupy | bool |
|
||||
|
||||
## getCourses
|
||||
|
||||
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/CoursesController.java)
|
||||
|
||||
```
|
||||
GET /api/v1/courses/getCourses
|
||||
```
|
||||
|
||||
#### Opis
|
||||
|
||||
Zwraca wszystkie dostepne kursy.
|
||||
|
||||
## token
|
||||
|
||||
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/TokenController.java)
|
||||
|
||||
```
|
||||
GET /token?ticket=ST-668405-W0gfvSVDRBdMUWLweKzv-cas.amu.edu.pl
|
||||
```
|
||||
|
||||
#### Opis
|
||||
|
||||
Po odpytaniu tego endpointa z podanym ticketem system zrobi nma nim validate i dostanie uzytkownika dla ktorego zostal on wygenerowany. System utworzy dla niego access token i go zwroci w odpowiedzi
|
||||
|
||||
#### Parametry
|
||||
|
||||
| Type | Name | Consumes | Opis | Type |
|
||||
| ----------- | ------------------------- | -------- | --------------------------------------- | ------ |
|
||||
| Query Param | **ticket** </br> required | - | ticket uzyskany z logowania poprzez CAS | string |
|
42
gettoken.py
Executable file
42
gettoken.py
Executable file
@ -0,0 +1,42 @@
|
||||
import webbrowser
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer, SimpleHTTPRequestHandler
|
||||
import urllib.parse as urlparse
|
||||
from urllib.parse import parse_qs
|
||||
import sys
|
||||
import requests as r
|
||||
|
||||
if len(sys.argv) > 1 :
|
||||
API_ADDRESS = "http://" + sys.argv[1] + ":1285"
|
||||
else:
|
||||
API_ADDRESS = "http://localhost:1285"
|
||||
|
||||
PORT = 3000
|
||||
|
||||
|
||||
class S(BaseHTTPRequestHandler):
|
||||
def _set_response(self):
|
||||
self.send_response(200)
|
||||
self.send_header('Content-type', 'text/html')
|
||||
self.end_headers()
|
||||
|
||||
def do_GET(self):
|
||||
parsed = urlparse.urlparse(str(self.path))
|
||||
ticket = str(parse_qs(parsed.query)['ticket'][0])
|
||||
print(ticket)
|
||||
response = r.get(API_ADDRESS + "/token?ticket=" + ticket)
|
||||
self._set_response()
|
||||
self.wfile.write("Your token: {}".format(
|
||||
response.text).encode('utf-8'))
|
||||
|
||||
def wait_for_request(server_class=HTTPServer,
|
||||
handler_class=S):
|
||||
server_address = ('localhost', PORT)
|
||||
httpd = server_class(server_address, handler_class)
|
||||
return httpd.handle_request()
|
||||
|
||||
|
||||
url = 'https://cas.amu.edu.pl/cas/login?service=http://localhost:' + \
|
||||
str(PORT) + '&locale=pl'
|
||||
|
||||
webbrowser.open_new_tab(url)
|
||||
wait_for_request()
|
12
pom.xml
12
pom.xml
@ -2,11 +2,11 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<groupId>com.plannaplan</groupId>
|
||||
<artifactId>backend</artifactId>
|
||||
@ -78,7 +78,7 @@
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
<modules>
|
||||
<modules>
|
||||
<module>buisnesslogic</module>
|
||||
<module>restservice</module>
|
||||
</modules>
|
||||
|
@ -16,11 +16,30 @@
|
||||
<!-- FIXME change it to the project's website -->
|
||||
<url>http://www.example.com</url>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>dev</id>
|
||||
<properties>
|
||||
<activatedProperties>dev</activatedProperties>
|
||||
</properties>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>prod</id>
|
||||
<properties>
|
||||
<activatedProperties>prod</activatedProperties>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.14</maven.compiler.source>
|
||||
<maven.compiler.target>1.14</maven.compiler.target>
|
||||
<maven.compiler.source>14</maven.compiler.source>
|
||||
<maven.compiler.target>14</maven.compiler.target>
|
||||
<start-class>com.plannaplan.App</start-class>
|
||||
<swagger.version>2.9.2</swagger.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -56,6 +75,13 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.jasig.cas.client/cas-client-core -->
|
||||
<dependency>
|
||||
<groupId>org.jasig.cas.client</groupId>
|
||||
<artifactId>cas-client-core</artifactId>
|
||||
<version>3.6.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
@ -85,6 +111,22 @@
|
||||
<groupId>com.plannaplan</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -1,23 +1,35 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.plannaplan.models.ConfigData;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.services.UserService;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
|
||||
import org.springframework.context.event.EventListener;
|
||||
import com.plannaplan.services.ConfiguratorService;
|
||||
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
|
||||
public final static String API_VERSION = "v1";
|
||||
|
||||
@Autowired
|
||||
private ConfiguratorService contrl;
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Value("${plannaplan.dev}")
|
||||
private boolean isDev;
|
||||
|
||||
public static void main(String[] args) {
|
||||
Logo logo = new Logo("beta");
|
||||
System.out.println(logo.getLogo());
|
||||
@ -28,33 +40,78 @@ public class App {
|
||||
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void importData() {
|
||||
User filip = new User();
|
||||
filip.setEmail("filizy@st.amu.edu.pl");
|
||||
filip.setName("Filip");
|
||||
filip.setSurname("Izydorczyk");
|
||||
filip.setRole(UserRoles.DEANERY);
|
||||
this.userService.save(filip);
|
||||
System.out.println(Logo.getInitInfo(isDev));
|
||||
|
||||
User hub = new User();
|
||||
hub.setEmail("hubwrz1@st.amu.edu.pl");
|
||||
hub.setName("Hubert");
|
||||
hub.setSurname("Wrzesiński");
|
||||
hub.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(hub);
|
||||
if (this.isDev) {
|
||||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
|
||||
ConfigData data = new ConfigData(null, null, inputStream);
|
||||
this.contrl.config(data);
|
||||
|
||||
User mac = new User();
|
||||
mac.setEmail("macglo2@st.amu.edu.pl");
|
||||
mac.setName("Maciej");
|
||||
mac.setSurname("Głowacki");
|
||||
mac.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(mac);
|
||||
User newuser = new User();
|
||||
newuser.setEmail("tommy@st.amu.edu.pl");
|
||||
newuser.setName("Tomek");
|
||||
newuser.setSurname("Atomek");
|
||||
newuser.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(newuser);
|
||||
|
||||
User mar = new User();
|
||||
mar.setEmail("marwoz16@st.amu.edu.pl");
|
||||
mar.setName("Marcin");
|
||||
mar.setSurname("Woźniak");
|
||||
mar.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(mar);
|
||||
newuser = new User();
|
||||
newuser.setEmail("robercik@st.amu.edu.pl");
|
||||
newuser.setName("Robert");
|
||||
newuser.setSurname("Głowacki");
|
||||
newuser.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(newuser);
|
||||
|
||||
newuser = new User();
|
||||
newuser.setEmail("mewa@st.amu.edu.pl");
|
||||
newuser.setName("Poznanska");
|
||||
newuser.setSurname("Mewa");
|
||||
newuser.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(newuser);
|
||||
|
||||
newuser = new User();
|
||||
newuser.setEmail("tkul2@st.amu.edu.pl");
|
||||
newuser.setName("Tomasz");
|
||||
newuser.setSurname("Kula");
|
||||
newuser.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(newuser);
|
||||
|
||||
newuser = new User();
|
||||
newuser.setEmail("annana@st.amu.edu.pl");
|
||||
newuser.setName("Anna");
|
||||
newuser.setSurname("Na");
|
||||
newuser.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(newuser);
|
||||
|
||||
newuser = new User();
|
||||
newuser.setEmail("mnart@st.amu.edu.pl");
|
||||
newuser.setName("Marta");
|
||||
newuser.setSurname("Narta");
|
||||
newuser.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(newuser);
|
||||
|
||||
newuser = new User();
|
||||
newuser.setEmail("zmineniane@st.amu.edu.pl");
|
||||
newuser.setName("Tutaj");
|
||||
newuser.setSurname("Koncza");
|
||||
newuser.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(newuser);
|
||||
|
||||
newuser = new User();
|
||||
newuser.setEmail("mi@st.amu.edu.pl");
|
||||
newuser.setName("Mi");
|
||||
newuser.setSurname("Sie");
|
||||
newuser.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(newuser);
|
||||
|
||||
newuser = new User();
|
||||
newuser.setEmail("pms@st.amu.edu.pl");
|
||||
newuser.setName("Pomysly");
|
||||
newuser.setSurname("Sad");
|
||||
newuser.setRole(UserRoles.STUDENT);
|
||||
this.userService.save(newuser);
|
||||
}
|
||||
|
||||
System.out.println(Logo.getStartedInfo(isDev));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,14 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class Logo {
|
||||
|
||||
public static final String ANSI_RESET = "\u001B[0m";
|
||||
public static final String ANSI_YELLOW = "\u001B[33m";
|
||||
public static final String ANSI_BLUE = "\u001B[34m";
|
||||
public static final String ANSI_BLACK = "\u001B[30m";
|
||||
public static final String ANSI_BLACK = "\u001B[37m";
|
||||
private String version;
|
||||
|
||||
public Logo(String version){
|
||||
@ -30,4 +33,25 @@ public class Logo {
|
||||
ANSI_RESET;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static String getInitInfo(boolean isDev){
|
||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
if(isDev){
|
||||
return ANSI_BLACK + dtf.format(now) + ANSI_YELLOW + " plannaplan" + ANSI_RESET + " initializing [" +ANSI_BLUE + "dev" + ANSI_RESET +"]";
|
||||
}
|
||||
return ANSI_BLACK + dtf.format(now) + ANSI_YELLOW + " plannaplan" + ANSI_RESET + " initializing [" +ANSI_BLUE + "prod" + ANSI_RESET +"]";
|
||||
}
|
||||
|
||||
public static String getStartedInfo(boolean isDev){
|
||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
if(isDev){
|
||||
return ANSI_BLACK + dtf.format(now) +ANSI_YELLOW + " plannaplan" + ANSI_RESET + " started [" +ANSI_BLUE + "dev" + ANSI_RESET +"]";
|
||||
}
|
||||
return ANSI_BLACK + dtf.format(now) + ANSI_YELLOW + " plannaplan" + ANSI_RESET + " started [" +ANSI_BLUE + "prod" + ANSI_RESET +"]";
|
||||
}
|
||||
}
|
50
restservice/src/main/java/com/plannaplan/Swagger2Config.java
Executable file
50
restservice/src/main/java/com/plannaplan/Swagger2Config.java
Executable file
@ -0,0 +1,50 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
|
||||
import springfox.documentation.service.Parameter;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.ParameterBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.schema.ModelRef;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class Swagger2Config extends WebMvcConfigurationSupport {
|
||||
|
||||
@Bean
|
||||
public Docket createRestApi() {
|
||||
Parameter authHeader = new ParameterBuilder()
|
||||
.parameterType("header")
|
||||
.name("Authorization")
|
||||
.modelRef(new ModelRef("string"))
|
||||
.build();
|
||||
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.plannaplan")).paths(PathSelectors.any())
|
||||
.build()
|
||||
.globalOperationParameters(Collections.singletonList(authHeader));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
return new ApiInfoBuilder().title("plannaplan").description("Aplikacja do zapisów na zajęcia UAM.")
|
||||
.termsOfServiceUrl("https://plannaplan.pl/")
|
||||
// .contact("")
|
||||
.version("1.0").build();
|
||||
}
|
||||
}
|
@ -4,6 +4,10 @@ import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -12,7 +16,7 @@ import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.responses.mappers.AssignmentResponseMappers;
|
||||
import com.plannaplan.responses.models.GetCurrentAssignmentsResponse;
|
||||
import com.plannaplan.responses.models.AssignmentResponse;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.CommisionService;
|
||||
|
||||
@ -24,6 +28,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/assignments")
|
||||
@Api(tags = {
|
||||
"Assignments" }, value = "Assignments", description = "Assignment is representation of student willing to join given group (lecture or calss)")
|
||||
public class AssignmentsController extends TokenBasedController {
|
||||
|
||||
@Autowired
|
||||
@ -32,8 +38,9 @@ public class AssignmentsController extends TokenBasedController {
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
@GetMapping("/getCurrentAssignments")
|
||||
public ResponseEntity<List<GetCurrentAssignmentsResponse>> getCurrentAssignments() throws Exception {
|
||||
@GetMapping("/user")
|
||||
@ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided.")
|
||||
public ResponseEntity<List<AssignmentResponse>> getCurrentAssignments() throws Exception {
|
||||
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found"));
|
||||
Optional<Commision> com = this.commisionService.getNewestCommision(user);
|
||||
|
||||
@ -42,6 +49,6 @@ public class AssignmentsController extends TokenBasedController {
|
||||
return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone), HttpStatus.OK);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(null, HttpStatus.OK);
|
||||
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,14 @@ package com.plannaplan.controllers;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.entities.Assignment;
|
||||
@ -17,53 +23,95 @@ import com.plannaplan.responses.models.CommisionResponse;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.CommisionService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/commisions")
|
||||
@Api(tags = { "Commisions" }, value = "Commisions", description = "Commision is representation of student selected assignments at time. All assignments are attached to some commision so we can see current assignments and also browse history of changes for given user")
|
||||
public class CommisionController extends TokenBasedController {
|
||||
|
||||
@Autowired
|
||||
private CommisionService commisionService;
|
||||
@Autowired
|
||||
private CommisionService commisionService;
|
||||
|
||||
@Autowired
|
||||
private GroupService groupServcicxe;
|
||||
@Autowired
|
||||
private GroupService groupServcicxe;
|
||||
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
public CommisionController() {
|
||||
}
|
||||
public CommisionController() {
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
public ResponseEntity<String> addCommision(@RequestBody List<Long> groups) throws UserNotFoundException {
|
||||
@PostMapping(value = { "/user", "/user/{id}" })
|
||||
@ApiOperation(value = "Create commision with assignents to given groups. If group doesn't exist error will be thrown")
|
||||
public ResponseEntity<String> addCommision(
|
||||
@RequestBody @ApiParam(value = "List of groups ids user want to assign to. If group doesnt exisit error will be thrown") List<Long> groups,
|
||||
@PathVariable(name = "id", required = false) Long userId) {
|
||||
|
||||
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
|
||||
Commision com = new Commision(user);
|
||||
this.commisionService.save(com);
|
||||
try {
|
||||
|
||||
groups.stream().forEach((groupId) -> {
|
||||
Groups group = this.groupServcicxe.getGroupById(groupId).orElseThrow(() -> new NullPointerException());
|
||||
Assignment a = new Assignment(group, com);
|
||||
this.assignmentService.save(a);
|
||||
});
|
||||
final User asker = this.getCurrentUser()
|
||||
.orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
||||
|
||||
return new ResponseEntity<>("Succes", HttpStatus.OK);
|
||||
}
|
||||
final User user = userId != null
|
||||
? userService.getById(userId).orElseThrow(
|
||||
() -> new UserNotFoundException("Given user id not exist"))
|
||||
: asker;
|
||||
|
||||
@GetMapping("/getAllCommisions")
|
||||
public ResponseEntity<List<CommisionResponse>> getAlCommisions() throws UserNotFoundException {
|
||||
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
|
||||
List<CommisionResponse> result = CommisionResponseMappers
|
||||
.mapToResponse(this.commisionService.getUsersCommisions(user));
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
}
|
||||
Assert.isTrue((asker.getRole() == UserRoles.DEANERY && user.getRole() == UserRoles.STUDENT
|
||||
|| (asker.getId().equals(user.getId()) && user.getRole() == UserRoles.STUDENT)),
|
||||
"Incorrect attempt to change plan");
|
||||
|
||||
Optional<Long> notExistingGroup = this.groupServcicxe.findNotExistingGroup(groups);
|
||||
Assert.isTrue(!notExistingGroup.isPresent(), "Group "
|
||||
+ notExistingGroup.orElse(Long.MIN_VALUE).toString() + "doesn't exist");
|
||||
|
||||
final Commision com = new Commision(user);
|
||||
this.commisionService.save(com);
|
||||
|
||||
groups.stream().forEach((groupId) -> {
|
||||
Groups group = this.groupServcicxe.getGroupById(groupId)
|
||||
.orElseThrow(() -> new NullPointerException());
|
||||
Assignment a = new Assignment(group, com);
|
||||
this.assignmentService.save(a);
|
||||
});
|
||||
|
||||
return new ResponseEntity<>("Succes", HttpStatus.OK);
|
||||
} catch (UserNotFoundException exception) {
|
||||
return new ResponseEntity<>(exception.getMessage(), HttpStatus.NOT_FOUND);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
return new ResponseEntity<>(exception.getMessage(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/user")
|
||||
@ApiOperation("Return list of user all commisions (history of schedules)")
|
||||
public ResponseEntity<List<CommisionResponse>> getAlCommisions() throws UserNotFoundException {
|
||||
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
|
||||
List<CommisionResponse> result = CommisionResponseMappers
|
||||
.mapToResponse(this.commisionService.getUsersCommisions(user));
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@GetMapping("/user/{id}")
|
||||
@ApiOperation("Return list of commisions for given user. To be able to access this data u need to provide DEANERY token")
|
||||
public ResponseEntity<List<CommisionResponse>> getCommision(@PathVariable(name = "id") Long userId)
|
||||
throws UserNotFoundException {
|
||||
User user = this.userService.getById(userId).orElseThrow(() -> new NullPointerException());
|
||||
List<CommisionResponse> result = CommisionResponseMappers
|
||||
.mapToResponse(this.commisionService.getUsersCommisions(user));
|
||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,10 +19,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/configurator")
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
@Api(tags = { "ConfigController" }, value = "ConfigController", description = "All endpoints to configure an app")
|
||||
public class ConfigController {
|
||||
|
||||
@Autowired
|
||||
@ -30,8 +35,9 @@ public class ConfigController {
|
||||
|
||||
@PostMapping("/config")
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
|
||||
public ResponseEntity<String> configApp(@RequestParam("file") MultipartFile file) {
|
||||
@ApiOperation("Imports data to system. To call you need to provide ADMIN token")
|
||||
public ResponseEntity<String> configApp(
|
||||
@RequestParam("file") @ApiParam(value = "file .xlsx that contains courses and groups with apoinnted rules") MultipartFile file) {
|
||||
try {
|
||||
final ConfigData data = new ConfigData(null, null, file.getInputStream());
|
||||
this.contrl.config(data);
|
||||
|
@ -1,43 +1,82 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.responses.mappers.CoursesResponseMappers;
|
||||
import com.plannaplan.responses.models.GetCoursesResponse;
|
||||
import com.plannaplan.responses.models.GetCoursesWithGroupsResponse;
|
||||
import com.plannaplan.responses.models.CoursesDefaultResponse;
|
||||
import com.plannaplan.responses.models.CoursesWithGroupsResponse;
|
||||
import com.plannaplan.responses.models.GroupDefaultResponse;
|
||||
import com.plannaplan.services.CourseService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import com.plannaplan.responses.models.abstracts.CoursesResponse;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/courses")
|
||||
@Api(tags = {
|
||||
"Course" }, value = "Course", description = "Endpoints to deal with courses. All courses can have classes, lectures or both.")
|
||||
public class CoursesController {
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@GetMapping("/getCourses")
|
||||
public ResponseEntity<List<GetCoursesResponse>> getMethodName() {
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
@GetMapping("/all")
|
||||
@ApiOperation(value = "Return all courses")
|
||||
public ResponseEntity<List<? extends CoursesResponse>> getMethodName(
|
||||
@RequestParam(name = "groups", defaultValue = "false") @ApiParam(value = "Boolean if you want to have resopnse with associated groups or without") Boolean groups,
|
||||
@RequestParam(name = "takenPlaces", defaultValue = "false") @ApiParam(value = "Boolean if we want to have respoonse with information about taken places by other students. Needs to be set groups true first") Boolean takenPlaces) {
|
||||
List<Course> courses = this.courseService.getAllCourses();
|
||||
List<GetCoursesResponse> response = CoursesResponseMappers.mapToGetCoursesResponse(courses);
|
||||
if (groups) {
|
||||
if (takenPlaces) {
|
||||
|
||||
final List<CoursesWithGroupsResponse> response = new ArrayList<>();
|
||||
|
||||
courses.forEach(course -> {
|
||||
final List<GroupDefaultResponse> lectures = new ArrayList<>();
|
||||
final List<GroupDefaultResponse> classes = new ArrayList<>();
|
||||
|
||||
final HashMap<Long, Integer> ammounts = this.groupService.getTakenPlaces(course.getGroups());
|
||||
|
||||
course.getGroups().stream().forEach(group -> {
|
||||
if (group.getType() == GroupType.CLASS) {
|
||||
classes.add(new GroupDefaultResponse(group, ammounts.get(group.getId())));
|
||||
} else {
|
||||
lectures.add(new GroupDefaultResponse(group, ammounts.get(group.getId())));
|
||||
}
|
||||
});
|
||||
|
||||
response.add(new CoursesWithGroupsResponse(course, lectures, classes));
|
||||
});
|
||||
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
final List<CoursesWithGroupsResponse> response = CoursesResponseMappers
|
||||
.mapToGetCoursesWithGroupsResponse(courses);
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
final List<CoursesDefaultResponse> response = CoursesResponseMappers.mapToGetCoursesResponse(courses);
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/getCoursesWithGroups")
|
||||
public ResponseEntity<List<GetCoursesWithGroupsResponse>> getCoursesWithGroups() {
|
||||
final List<Course> courses = this.courseService.getAllCourses();
|
||||
final List<GetCoursesWithGroupsResponse> response = CoursesResponseMappers
|
||||
.mapToGetCoursesWithGroupsResponse(courses);
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.responses.mappers.GroupsMappers;
|
||||
import com.plannaplan.responses.models.DefaultGroupResponse;
|
||||
import com.plannaplan.responses.models.GetCourseGroupsResponse;
|
||||
import com.plannaplan.responses.models.GroupDefaultResponse;
|
||||
import com.plannaplan.responses.models.CourseWithGroupsResponse;
|
||||
import com.plannaplan.services.GroupService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -14,21 +15,43 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/groups")
|
||||
@Api(tags = {
|
||||
"Group" }, value = "Group", description = "Enpoints to deal with gorups. Group is related directly to course and can be either class and lecture")
|
||||
public class GroupController {
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
@GetMapping("/getCourseGroups")
|
||||
public ResponseEntity<GetCourseGroupsResponse<? extends DefaultGroupResponse>> getCourses(@RequestParam("id") Long id,
|
||||
@RequestParam(name = "capacity", defaultValue = "true") Boolean capacity) {
|
||||
@GetMapping("/course/{id}")
|
||||
@ApiOperation(value = "Return list of lectures and classes (if present) given course")
|
||||
public ResponseEntity<CourseWithGroupsResponse<? extends GroupDefaultResponse>> getCourses(
|
||||
@PathVariable(name = "id") Long id,
|
||||
@RequestParam(name = "capacity", defaultValue = "true") @ApiParam(value = "Boolean if we want to have capacity field in response") Boolean capacity,
|
||||
@RequestParam(name = "takenPlaces", defaultValue = "false") @ApiParam(value = "Boolean if we want to have respoonse with information about taken places by other students") Boolean takenPlaces) {
|
||||
List<Groups> groups = this.groupService.getGroupsByCourse(id);
|
||||
|
||||
if (takenPlaces) {
|
||||
HashMap<Long, Integer> ammounts = this.groupService.getTakenPlaces(groups);
|
||||
if (capacity) {
|
||||
return new ResponseEntity<>(GroupsMappers.mapToGetCourseGroupsWithCapacityResponse(groups, ammounts),
|
||||
HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity<>(GroupsMappers.mapToGetCourseGroupsDefaultResponse(groups, ammounts),
|
||||
HttpStatus.OK);
|
||||
}
|
||||
|
||||
if (capacity) {
|
||||
return new ResponseEntity<>(GroupsMappers.mapToGetCourseGroupsWithCapacityResponse(groups), HttpStatus.OK);
|
||||
}
|
||||
|
@ -1,11 +1,17 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.exceptions.UserNotFoundException;
|
||||
import com.plannaplan.security.CasValidationExcepiton;
|
||||
import com.plannaplan.security.CasValidator;
|
||||
import com.plannaplan.responses.models.TokenResponse;
|
||||
import com.plannaplan.security.cas.CasUserIdentity;
|
||||
import com.plannaplan.security.cas.CasValidationExcepiton;
|
||||
import com.plannaplan.security.cas.CasValidator;
|
||||
import com.plannaplan.security.cas.CustomUAMCasValidator;
|
||||
import com.plannaplan.security.cas.DefaultUAMCasValidator;
|
||||
import com.plannaplan.services.UserService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
@ -13,29 +19,45 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@Api(tags = { "Token" }, value = "Token", description = "Enpoints to get authorization.")
|
||||
public class TokenController {
|
||||
|
||||
private final static String SERVICE_URL = "http://localhost:3000";
|
||||
@Value("${plannaplan.frontendUrl}")
|
||||
private String serviceUrl;
|
||||
|
||||
@Value("${plannaplan.dev}")
|
||||
private boolean isDev;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@GetMapping("/token")
|
||||
public ResponseEntity<String> getToken(@RequestParam("ticket") final String ticket) {
|
||||
final CasValidator validator = new CasValidator(SERVICE_URL, ticket);
|
||||
@ApiOperation(value = "Endpoint to access token required to call secured endpoints. In order to access token we need to provide access token comming from unviersity CAS system")
|
||||
public ResponseEntity<TokenResponse> getToken(
|
||||
@RequestParam("ticket") @ApiParam(value = "Ticket get from CAS system. It should look like ST-1376572-wo41gty5R0JCZFKMMie2-cas.amu.edu.psl") final String ticket) {
|
||||
final CasValidator validator = isDev ? new DefaultUAMCasValidator(serviceUrl, ticket)
|
||||
: new CustomUAMCasValidator(serviceUrl, ticket);
|
||||
|
||||
try {
|
||||
String authority = validator.validate();
|
||||
String token = this.userService.login(authority);
|
||||
return new ResponseEntity<>(token, HttpStatus.OK);
|
||||
final CasUserIdentity casUserIdentity = validator.validate();
|
||||
final String usosId = casUserIdentity.getUsosId();
|
||||
final String authority = casUserIdentity.getEmail();
|
||||
User user = this.userService.checkForUser(authority, usosId);
|
||||
user = this.userService.login(user);
|
||||
|
||||
return new ResponseEntity<>(new TokenResponse(user), HttpStatus.OK);
|
||||
} catch (CasValidationExcepiton e) {
|
||||
return new ResponseEntity<>("Wrong ticket", HttpStatus.UNAUTHORIZED);
|
||||
return new ResponseEntity<>(null, HttpStatus.UNAUTHORIZED);
|
||||
} catch (UserNotFoundException e) {
|
||||
return new ResponseEntity<>("User not found", HttpStatus.NOT_FOUND);
|
||||
return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);
|
||||
} catch (Exception e) {
|
||||
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import java.util.List;
|
||||
import com.plannaplan.App;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.responses.mappers.UserResponseMappers;
|
||||
import com.plannaplan.responses.models.SearchForStudentsResponse;
|
||||
import com.plannaplan.responses.models.UserResponse;
|
||||
import com.plannaplan.services.UserService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -15,6 +15,11 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@ -23,16 +28,27 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
@CrossOrigin
|
||||
@RequestMapping("/api/" + App.API_VERSION + "/users")
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
@Api(tags = { "Users" }, value = "Users", description = "Endpoints to deal with users.")
|
||||
public class UsersController {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@GetMapping("/searchForStudents")
|
||||
@GetMapping("/student/search")
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
|
||||
public ResponseEntity<List<SearchForStudentsResponse>> configApp(@RequestParam("query") String query) {
|
||||
@ApiOperation(value = "Serch for user by providing query. If query is empty it will return all students. You need token with DEANERY role to call this")
|
||||
public ResponseEntity<List<UserResponse>> searchForStudent(
|
||||
@RequestParam("query") @ApiParam(value = "Query to filter all students. If empty will match everyone") String query) {
|
||||
final List<User> searches = this.userService.searchForStudents(query);
|
||||
final List<SearchForStudentsResponse> response = UserResponseMappers.mapToDefaultResponse(searches);
|
||||
final List<UserResponse> response = UserResponseMappers.mapToDefaultResponse(searches);
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/students")
|
||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||
@ApiOperation(value = "Gets all students. You need token with DEANERY role to call this")
|
||||
public ResponseEntity<List<UserResponse>> getAllStudents() {
|
||||
final List<User> searches = this.userService.searchForStudents("");
|
||||
final List<UserResponse> response = UserResponseMappers.mapToDefaultResponse(searches);
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,45 @@
|
||||
package com.plannaplan.responses.mappers;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.responses.models.GetCurrentAssignmentsResponse;
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.responses.models.AssignmentResponse;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
public class AssignmentResponseMappers {
|
||||
|
||||
public static final List<GetCurrentAssignmentsResponse> mapToResponse(List<Assignment> assignments) {
|
||||
return assignments.stream().filter(Objects::nonNull).map(GetCurrentAssignmentsResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
public static final List<AssignmentResponse> mapToResponse(List<Assignment> assignments) {
|
||||
List<AssignmentResponse> response = new ArrayList<>();
|
||||
HashMap<Course, List<Groups>> courses = new HashMap<>();
|
||||
assignments.stream().forEach((Assignment assignment) -> {
|
||||
final Groups group = assignment.getGroup();
|
||||
final Course course = group.getCourseId();
|
||||
if (courses.get(course) == null) {
|
||||
courses.put(course, new ArrayList<>());
|
||||
}
|
||||
courses.get(course).add(group);
|
||||
});
|
||||
|
||||
for (Map.Entry<Course, List<Groups>> entry : courses.entrySet()) {
|
||||
final Course course = entry.getKey();
|
||||
final List<Groups> courseGroups = entry.getValue();
|
||||
if (courseGroups.size() == 1) {
|
||||
response.add(new AssignmentResponse(course, courseGroups.get(0)));
|
||||
}
|
||||
if (courseGroups.size() == 2) {
|
||||
final Groups lecture = courseGroups.stream().filter(o -> o.getType() == GroupType.LECTURE).findFirst()
|
||||
.get();
|
||||
final Groups classes = courseGroups.stream().filter(o -> o.getType() == GroupType.CLASS).findFirst()
|
||||
.get();
|
||||
response.add(new AssignmentResponse(course, lecture, classes));
|
||||
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
@ -5,16 +5,16 @@ import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.responses.models.GetCoursesResponse;
|
||||
import com.plannaplan.responses.models.GetCoursesWithGroupsResponse;
|
||||
import com.plannaplan.responses.models.CoursesDefaultResponse;
|
||||
import com.plannaplan.responses.models.CoursesWithGroupsResponse;
|
||||
|
||||
public class CoursesResponseMappers {
|
||||
public static final List<GetCoursesResponse> mapToGetCoursesResponse(List<Course> courses) {
|
||||
return courses.stream().filter(Objects::nonNull).map(GetCoursesResponse::new).collect(Collectors.toList());
|
||||
public static final List<CoursesDefaultResponse> mapToGetCoursesResponse(List<Course> courses) {
|
||||
return courses.stream().filter(Objects::nonNull).map(CoursesDefaultResponse::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static final List<GetCoursesWithGroupsResponse> mapToGetCoursesWithGroupsResponse(List<Course> courses) {
|
||||
return courses.stream().filter(Objects::nonNull).map(GetCoursesWithGroupsResponse::new)
|
||||
public static final List<CoursesWithGroupsResponse> mapToGetCoursesWithGroupsResponse(List<Course> courses) {
|
||||
return courses.stream().filter(Objects::nonNull).map(CoursesWithGroupsResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -1,58 +1,113 @@
|
||||
package com.plannaplan.responses.mappers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.responses.models.DefaultGroupResponse;
|
||||
import com.plannaplan.responses.models.GetCourseGroupsResponse;
|
||||
import com.plannaplan.responses.models.WithCapacityGroupResponse;
|
||||
import com.plannaplan.responses.models.GroupDefaultResponse;
|
||||
import com.plannaplan.responses.models.CourseWithGroupsResponse;
|
||||
import com.plannaplan.responses.models.GroupWithCapacityResponse;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
public class GroupsMappers {
|
||||
public static List<DefaultGroupResponse> mapToDefaultResponse(List<Groups> groups) {
|
||||
return groups.stream().filter(Objects::nonNull).map(DefaultGroupResponse::new).collect(Collectors.toList());
|
||||
public static List<GroupDefaultResponse> mapToDefaultResponse(List<Groups> groups, HashMap<Long, Integer> taken) {
|
||||
return groups.stream().filter(Objects::nonNull).map(new Function<Groups, GroupDefaultResponse>() {
|
||||
@Override
|
||||
public GroupDefaultResponse apply(Groups p) {
|
||||
if (taken != null) {
|
||||
return new GroupDefaultResponse(p, taken.get(p.getId()));
|
||||
} else {
|
||||
return new GroupDefaultResponse(p);
|
||||
}
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<WithCapacityGroupResponse> mapToCapacityResponse(List<Groups> groups) {
|
||||
return groups.stream().filter(Objects::nonNull).map(WithCapacityGroupResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
public static List<GroupDefaultResponse> mapToDefaultResponse(List<Groups> groups) {
|
||||
return GroupsMappers.mapToDefaultResponse(groups, null);
|
||||
}
|
||||
|
||||
public static GetCourseGroupsResponse<DefaultGroupResponse> mapToGetCourseGroupsDefaultResponse (List<Groups> groups){
|
||||
|
||||
List<DefaultGroupResponse> lectures = new ArrayList<>();
|
||||
List<DefaultGroupResponse> classes = new ArrayList<>();
|
||||
public static List<GroupWithCapacityResponse> mapToCapacityResponse(List<Groups> groups,
|
||||
HashMap<Long, Integer> taken) {
|
||||
return groups.stream().filter(Objects::nonNull).map(new Function<Groups, GroupWithCapacityResponse>() {
|
||||
@Override
|
||||
public GroupWithCapacityResponse apply(Groups p) {
|
||||
if (taken != null) {
|
||||
return new GroupWithCapacityResponse(p, taken.get(p.getId()));
|
||||
} else {
|
||||
return new GroupWithCapacityResponse(p);
|
||||
}
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<GroupWithCapacityResponse> mapToCapacityResponse(List<Groups> groups) {
|
||||
return GroupsMappers.mapToCapacityResponse(groups, null);
|
||||
}
|
||||
|
||||
public static CourseWithGroupsResponse<GroupDefaultResponse> mapToGetCourseGroupsDefaultResponse(
|
||||
List<Groups> groups, HashMap<Long, Integer> taken) {
|
||||
|
||||
List<GroupDefaultResponse> lectures = new ArrayList<>();
|
||||
List<GroupDefaultResponse> classes = new ArrayList<>();
|
||||
|
||||
groups.stream().forEach(group -> {
|
||||
if (group.getType() == GroupType.CLASS) {
|
||||
classes.add(new DefaultGroupResponse(group));
|
||||
if (taken != null) {
|
||||
classes.add(new GroupDefaultResponse(group, taken.get(group.getId())));
|
||||
} else {
|
||||
classes.add(new GroupDefaultResponse(group));
|
||||
}
|
||||
} else {
|
||||
lectures.add(new DefaultGroupResponse(group));
|
||||
if (taken != null) {
|
||||
lectures.add(new GroupDefaultResponse(group, taken.get(group.getId())));
|
||||
} else {
|
||||
lectures.add(new GroupDefaultResponse(group));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return new GetCourseGroupsResponse<>(classes, lectures);
|
||||
return new CourseWithGroupsResponse<>(classes, lectures);
|
||||
}
|
||||
|
||||
public static GetCourseGroupsResponse<WithCapacityGroupResponse> mapToGetCourseGroupsWithCapacityResponse (List<Groups> groups){
|
||||
public static CourseWithGroupsResponse<GroupDefaultResponse> mapToGetCourseGroupsDefaultResponse(
|
||||
List<Groups> groups) {
|
||||
return GroupsMappers.mapToGetCourseGroupsDefaultResponse(groups, null);
|
||||
}
|
||||
|
||||
List<WithCapacityGroupResponse> lectures = new ArrayList<>();
|
||||
List<WithCapacityGroupResponse> classes = new ArrayList<>();
|
||||
public static CourseWithGroupsResponse<GroupWithCapacityResponse> mapToGetCourseGroupsWithCapacityResponse(
|
||||
List<Groups> groups, HashMap<Long, Integer> taken) {
|
||||
|
||||
List<GroupWithCapacityResponse> lectures = new ArrayList<>();
|
||||
List<GroupWithCapacityResponse> classes = new ArrayList<>();
|
||||
|
||||
groups.stream().forEach(group -> {
|
||||
if (group.getType() == GroupType.CLASS) {
|
||||
classes.add(new WithCapacityGroupResponse(group));
|
||||
if (taken != null) {
|
||||
classes.add(new GroupWithCapacityResponse(group, taken.get(group.getId())));
|
||||
} else {
|
||||
classes.add(new GroupWithCapacityResponse(group));
|
||||
}
|
||||
|
||||
} else {
|
||||
lectures.add(new WithCapacityGroupResponse(group));
|
||||
if (taken != null) {
|
||||
lectures.add(new GroupWithCapacityResponse(group, taken.get(group.getId())));
|
||||
} else {
|
||||
lectures.add(new GroupWithCapacityResponse(group));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return new CourseWithGroupsResponse<>(classes, lectures);
|
||||
}
|
||||
|
||||
return new GetCourseGroupsResponse<>(classes, lectures);
|
||||
public static CourseWithGroupsResponse<GroupWithCapacityResponse> mapToGetCourseGroupsWithCapacityResponse(
|
||||
List<Groups> groups) {
|
||||
return GroupsMappers.mapToGetCourseGroupsWithCapacityResponse(groups, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,11 +5,11 @@ import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.responses.models.SearchForStudentsResponse;
|
||||
import com.plannaplan.responses.models.UserResponse;
|
||||
|
||||
public class UserResponseMappers {
|
||||
public static List<SearchForStudentsResponse> mapToDefaultResponse(List<User> groups) {
|
||||
return groups.stream().filter(Objects::nonNull).map(SearchForStudentsResponse::new)
|
||||
public static List<UserResponse> mapToDefaultResponse(List<User> groups) {
|
||||
return groups.stream().filter(Objects::nonNull).map(UserResponse::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
@ApiModel(description = "Response shows information about given assigment to course.", value = "AssignmentResponse")
|
||||
public class AssignmentResponse {
|
||||
private Long id;
|
||||
private String name;
|
||||
private GroupWithCapacityResponse classes;
|
||||
private GroupWithCapacityResponse lecture;
|
||||
|
||||
public AssignmentResponse(Course course, Groups lecture, Groups classes) {
|
||||
this.id = course.getId();
|
||||
this.name = course.getName();
|
||||
this.lecture = lecture == null ? null : new GroupWithCapacityResponse(lecture);
|
||||
this.classes = classes == null ? null : new GroupWithCapacityResponse(classes);
|
||||
}
|
||||
|
||||
public AssignmentResponse(Course course, Groups group) {
|
||||
this(course, group.getType() == GroupType.LECTURE ? group : null,
|
||||
group.getType() == GroupType.CLASS ? group : null);
|
||||
}
|
||||
|
||||
public GroupWithCapacityResponse getLecture() {
|
||||
return this.lecture;
|
||||
}
|
||||
|
||||
public GroupWithCapacityResponse getClasses() {
|
||||
return this.classes;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
}
|
@ -4,8 +4,15 @@ import java.sql.Timestamp;
|
||||
|
||||
import com.plannaplan.entities.Commision;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@ApiModel(description = "Response shows information about commision.", value = "CommisionResponse")
|
||||
public class CommisionResponse {
|
||||
@ApiModelProperty(value = "ID created by database")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "Timestamp where the user commit the commision")
|
||||
private Timestamp commisionDate;
|
||||
|
||||
public CommisionResponse(Commision commision) {
|
||||
|
@ -3,12 +3,15 @@ package com.plannaplan.responses.models;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GetCourseGroupsResponse <T> {
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
@ApiModel(description = "Response shows information about groups to given course.", value = "CourseWithGroupsResponse")
|
||||
public class CourseWithGroupsResponse <T> {
|
||||
|
||||
private List<T> lectures = new ArrayList<>();
|
||||
private List<T> classes = new ArrayList<>();
|
||||
|
||||
public GetCourseGroupsResponse(List<T> classes, List<T> lectures ){
|
||||
public CourseWithGroupsResponse(List<T> classes, List<T> lectures ){
|
||||
this.lectures = lectures;
|
||||
this.classes = classes;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.responses.models.abstracts.CoursesResponse;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
@ApiModel(description = "Response shows information about course.", value = "CoursesDefaultResponse")
|
||||
public class CoursesDefaultResponse extends CoursesResponse {
|
||||
|
||||
public CoursesDefaultResponse(Course course) {
|
||||
super(course);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.responses.models.abstracts.CoursesResponse;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
@ApiModel(description = "Response shows information about groups to given course.", value = "CoursesWithGroupsResponse")
|
||||
public class CoursesWithGroupsResponse extends CoursesResponse {
|
||||
|
||||
private List<GroupDefaultResponse> lectures = new ArrayList<>();
|
||||
private List<GroupDefaultResponse> classes = new ArrayList<>();
|
||||
|
||||
public CoursesWithGroupsResponse(Course course) {
|
||||
super(course);
|
||||
course.getGroups().stream().forEach(group -> {
|
||||
if (group.getType() == GroupType.CLASS) {
|
||||
this.classes.add(new GroupDefaultResponse(group));
|
||||
} else {
|
||||
this.lectures.add(new GroupDefaultResponse(group));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public CoursesWithGroupsResponse(Course course, List<GroupDefaultResponse> lectures,
|
||||
List<GroupDefaultResponse> classes) {
|
||||
super(course);
|
||||
this.lectures = lectures;
|
||||
this.classes = classes;
|
||||
}
|
||||
|
||||
public List<GroupDefaultResponse> getClasses() {
|
||||
return this.classes;
|
||||
}
|
||||
|
||||
public List<GroupDefaultResponse> getLectures() {
|
||||
return this.lectures;
|
||||
}
|
||||
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
public class DefaultGroupResponse {
|
||||
|
||||
private Long id;
|
||||
private int day;
|
||||
private String time;
|
||||
private String lecturer;
|
||||
private String room;
|
||||
private GroupType type;
|
||||
|
||||
public DefaultGroupResponse(Groups group) {
|
||||
this.id = group.getId() != null ? group.getId() : null;
|
||||
this.day = group.getDay() != null ? group.getDay().label : -1;
|
||||
this.time = group.getTimeString() != null ? group.getTimeString() : "";
|
||||
this.lecturer = group.getLecturer() != null ? group.getLecturer().toString() : "";
|
||||
this.room = group.getRoom() != null ? group.getRoom() : "";
|
||||
this.type = group.getType() != null ? group.getType() : null;
|
||||
}
|
||||
|
||||
public DefaultGroupResponse(Assignment assignment) {
|
||||
this(assignment.getGroup());
|
||||
}
|
||||
|
||||
public GroupType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
public String getLecturer() {
|
||||
return lecturer;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public int getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.responses.models.abstracts.CoursesResponse;
|
||||
|
||||
public class GetCoursesResponse extends CoursesResponse {
|
||||
|
||||
public GetCoursesResponse(Course course) {
|
||||
super(course);
|
||||
}
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.responses.models.abstracts.CoursesResponse;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
public class GetCoursesWithGroupsResponse extends CoursesResponse {
|
||||
|
||||
private List<DefaultGroupResponse> lectures = new ArrayList<>();
|
||||
private List<DefaultGroupResponse> classes = new ArrayList<>();
|
||||
|
||||
public GetCoursesWithGroupsResponse(Course course) {
|
||||
super(course);
|
||||
course.getGroups().stream().forEach(group -> {
|
||||
if (group.getType() == GroupType.CLASS) {
|
||||
this.classes.add(new DefaultGroupResponse(group));
|
||||
} else {
|
||||
this.lectures.add(new DefaultGroupResponse(group));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<DefaultGroupResponse> getClasses() {
|
||||
return this.classes;
|
||||
}
|
||||
|
||||
public List<DefaultGroupResponse> getLectures() {
|
||||
return this.lectures;
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
|
||||
public class GetCurrentAssignmentsResponse extends WithCapacityGroupResponse {
|
||||
|
||||
public GetCurrentAssignmentsResponse(Assignment assignment) {
|
||||
super(assignment);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.types.GroupType;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@ApiModel(description = "Response shows information about given group.", value = "GroupDefaultResponse")
|
||||
public class GroupDefaultResponse {
|
||||
|
||||
@ApiModelProperty(value = "ID created by database.")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "Value shows what day when the course is. Example 0 is Monday.")
|
||||
private int day;
|
||||
|
||||
@ApiModelProperty(value = "Value shows time when the course takes.")
|
||||
private String time;
|
||||
|
||||
@ApiModelProperty(value = "Value shows degree, name and surname.")
|
||||
private String lecturer;
|
||||
|
||||
@ApiModelProperty(value = "Value shows room where the class takes.")
|
||||
private String room;
|
||||
|
||||
@ApiModelProperty(value = "Value shows kind of group. The types are LECTURE or CLASS.")
|
||||
private GroupType type;
|
||||
|
||||
@ApiModelProperty(value = "Value shows how many places is already taken by other students.")
|
||||
private Integer takenPlaces;
|
||||
|
||||
public GroupDefaultResponse(Groups group) {
|
||||
this.id = group.getId() != null ? group.getId() : null;
|
||||
this.day = group.getDay() != null ? group.getDay().label : -1;
|
||||
this.time = group.getTimeString() != null ? group.getTimeString() : "";
|
||||
this.lecturer = group.getLecturer() != null ? group.getLecturer().toString() : "";
|
||||
this.room = group.getRoom() != null ? group.getRoom() : "";
|
||||
this.type = group.getType() != null ? group.getType() : null;
|
||||
}
|
||||
|
||||
public GroupDefaultResponse(Groups group, int takenPlaces) {
|
||||
this(group);
|
||||
this.takenPlaces = takenPlaces;
|
||||
}
|
||||
|
||||
public GroupDefaultResponse(Assignment assignment) {
|
||||
this(assignment.getGroup());
|
||||
}
|
||||
|
||||
public GroupType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
public String getLecturer() {
|
||||
return lecturer;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public int getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Integer getTakenPlaces() {
|
||||
return this.takenPlaces;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
@ApiModel(description = "Response shows information about group with included capacity.", value = "GroupWithCapacityResponse")
|
||||
public class GroupWithCapacityResponse extends GroupDefaultResponse {
|
||||
|
||||
private int capacity;
|
||||
|
||||
public GroupWithCapacityResponse(Groups group) {
|
||||
super(group);
|
||||
this.capacity = group.getCapacity();
|
||||
}
|
||||
|
||||
public GroupWithCapacityResponse(Groups group, int takenPlaces) {
|
||||
super(group, takenPlaces);
|
||||
this.capacity = group.getCapacity();
|
||||
}
|
||||
|
||||
public GroupWithCapacityResponse(Assignment assignment) {
|
||||
this(assignment.getGroup());
|
||||
}
|
||||
|
||||
public GroupWithCapacityResponse(Assignment assignment, int takenPlaces) {
|
||||
this(assignment.getGroup(), takenPlaces);
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
}
|
42
restservice/src/main/java/com/plannaplan/responses/models/TokenResponse.java
Executable file
42
restservice/src/main/java/com/plannaplan/responses/models/TokenResponse.java
Executable file
@ -0,0 +1,42 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@ApiModel(description = "Response shows information about logged user.", value = "TokenResponse")
|
||||
public class TokenResponse {
|
||||
@ApiModelProperty(value = "user token used to verify requests")
|
||||
private String token;
|
||||
@ApiModelProperty(value = "user id in database")
|
||||
private Long id;
|
||||
@ApiModelProperty(value = "user app role")
|
||||
private String authorityRole;
|
||||
@ApiModelProperty(value = "user unviersity email")
|
||||
private String email;
|
||||
|
||||
public TokenResponse(User user) {
|
||||
this.id = user.getId();
|
||||
this.authorityRole = user.getRole().toString();
|
||||
this.email = user.getEmail();
|
||||
this.token = user.getToken();
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public String getAuthorityRole() {
|
||||
return authorityRole;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
}
|
@ -2,14 +2,17 @@ package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
|
||||
public class SearchForStudentsResponse {
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
||||
@ApiModel(description = "Response shows information about user.", value = "UserResponse")
|
||||
public class UserResponse {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String surname;
|
||||
private String email;
|
||||
|
||||
public SearchForStudentsResponse(User user) {
|
||||
public UserResponse(User user) {
|
||||
this.id = user.getId();
|
||||
this.name = user.getName();
|
||||
this.surname = user.getSurname();
|
@ -1,23 +0,0 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Groups;
|
||||
|
||||
public class WithCapacityGroupResponse extends DefaultGroupResponse {
|
||||
|
||||
private int capacity;
|
||||
|
||||
public WithCapacityGroupResponse(Groups group) {
|
||||
super(group);
|
||||
this.capacity = group.getCapacity();
|
||||
}
|
||||
|
||||
public WithCapacityGroupResponse(Assignment assignment) {
|
||||
this(assignment.getGroup());
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
}
|
@ -70,8 +70,11 @@ public class AuthenticationProvider extends AbstractUserDetailsAuthenticationPro
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
// is being done in other task
|
||||
return true;
|
||||
if (user.isCredentialsNonExpired()) {
|
||||
userService.save(user);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,45 +0,0 @@
|
||||
package com.plannaplan.security;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
public class CasValidator {
|
||||
private static String CAS_URL = "https://cas.amu.edu.pl/cas";
|
||||
private final CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
private String service;
|
||||
private String ticket;
|
||||
|
||||
public CasValidator(String service, String ticket) {
|
||||
this.service = service;
|
||||
this.ticket = ticket;
|
||||
}
|
||||
|
||||
public String validate() throws Exception, CasValidationExcepiton {
|
||||
HttpGet request = new HttpGet(CasValidator.CAS_URL + "/validate?service="
|
||||
+ URLEncoder.encode(this.service, "UTF-8") + "&ticket=" + URLEncoder.encode(this.ticket, "UTF-8"));
|
||||
try (CloseableHttpResponse response = httpClient.execute(request)) {
|
||||
|
||||
HttpEntity entity = response.getEntity();
|
||||
|
||||
String result = null;
|
||||
if (entity != null) {
|
||||
// return it as a String
|
||||
result = EntityUtils.toString(entity);
|
||||
if (result.replace("\n", "").trim().equals("no")) {
|
||||
throw new CasValidationExcepiton("Validation failed");
|
||||
}
|
||||
}
|
||||
|
||||
String res = result.substring(result.indexOf('\n') + 1);
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ import org.springframework.security.web.authentication.HttpStatusEntryPoint;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
|
||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
private static final RequestMatcher PROTECTED_URLS = new OrRequestMatcher(new AntPathRequestMatcher("/api/**"));
|
||||
@ -36,8 +37,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
public void configure(final WebSecurity webSecurity) {
|
||||
webSecurity.ignoring().antMatchers("/token**").antMatchers("/api/v1/courses/getCourses")
|
||||
.antMatchers("/api/v1/groups/getCourseGroups").antMatchers("/api/v1/courses/getCoursesWithGroups");
|
||||
webSecurity.ignoring().antMatchers("/token**").antMatchers("/api/v1/courses/all")
|
||||
.antMatchers("/api/v1/groups/course/{id}").antMatchers("/v2/api-docs", "/configuration/ui",
|
||||
"/swagger-resources/**", "/configuration/security", "/swagger-ui.html", "/webjars/**");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
19
restservice/src/main/java/com/plannaplan/security/cas/CasUserIdentity.java
Executable file
19
restservice/src/main/java/com/plannaplan/security/cas/CasUserIdentity.java
Executable file
@ -0,0 +1,19 @@
|
||||
package com.plannaplan.security.cas;
|
||||
|
||||
public class CasUserIdentity {
|
||||
private String usosId;
|
||||
private String email;
|
||||
|
||||
public CasUserIdentity(String usosId, String email){
|
||||
this.usosId = usosId;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getUsosId() {
|
||||
return usosId;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.plannaplan.security;
|
||||
package com.plannaplan.security.cas;
|
||||
|
||||
public class CasValidationExcepiton extends RuntimeException {
|
||||
/**
|
6
restservice/src/main/java/com/plannaplan/security/cas/CasValidator.java
Executable file
6
restservice/src/main/java/com/plannaplan/security/cas/CasValidator.java
Executable file
@ -0,0 +1,6 @@
|
||||
package com.plannaplan.security.cas;
|
||||
|
||||
public interface CasValidator {
|
||||
|
||||
CasUserIdentity validate();
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.plannaplan.security.cas;
|
||||
|
||||
import org.jasig.cas.client.validation.Assertion;
|
||||
import org.jasig.cas.client.validation.Cas20ServiceTicketValidator;
|
||||
import org.jasig.cas.client.validation.TicketValidationException;
|
||||
|
||||
public class CustomUAMCasValidator implements CasValidator {
|
||||
private static String CAS_URL = "https://cas.amu.edu.pl/cas";
|
||||
private static String EMAIL_FIELD = "mail";
|
||||
private static String USOS_ID = "usos_id";
|
||||
private String service;
|
||||
private String ticket;
|
||||
|
||||
public CustomUAMCasValidator(String service, String ticket){
|
||||
this.service = service;
|
||||
this.ticket = ticket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CasUserIdentity validate() {
|
||||
/*
|
||||
* TO DO
|
||||
* Dodać case z CAS10/CAS20/CAS30
|
||||
*/
|
||||
final Cas20ServiceTicketValidator validator = new Cas20ServiceTicketValidator(CustomUAMCasValidator.CAS_URL);
|
||||
|
||||
try {
|
||||
final Assertion assertion = validator.validate(this.ticket, this.service);
|
||||
|
||||
if (assertion == null) {
|
||||
throw new CasValidationExcepiton("Validation failed. Assertion could not be retrieved for ticket " + "");
|
||||
}
|
||||
|
||||
final String usosid = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.USOS_ID).toString();
|
||||
|
||||
final String mail = assertion.getPrincipal().getAttributes().get(CustomUAMCasValidator.EMAIL_FIELD).toString();
|
||||
|
||||
return new CasUserIdentity(usosid,mail);
|
||||
|
||||
} catch (TicketValidationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.plannaplan.security.cas;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
public class DefaultUAMCasValidator implements CasValidator {
|
||||
private static String CAS_URL = "https://cas.amu.edu.pl/cas";
|
||||
private final CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
private String service;
|
||||
private String ticket;
|
||||
|
||||
public DefaultUAMCasValidator(String service, String ticket) {
|
||||
this.service = service;
|
||||
this.ticket = ticket;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CasUserIdentity validate() {
|
||||
try {
|
||||
HttpGet request = new HttpGet(DefaultUAMCasValidator.CAS_URL + "/validate?service="
|
||||
+ URLEncoder.encode(this.service, "UTF-8") + "&ticket=" + URLEncoder.encode(this.ticket, "UTF-8"));
|
||||
try (CloseableHttpResponse response = httpClient.execute(request)) {
|
||||
|
||||
HttpEntity entity = response.getEntity();
|
||||
|
||||
String result = null;
|
||||
if (entity != null) {
|
||||
// return it as a String
|
||||
result = EntityUtils.toString(entity);
|
||||
if (result.replace("\n", "").trim().equals("no")) {
|
||||
throw new CasValidationExcepiton("Validation failed");
|
||||
}
|
||||
}
|
||||
|
||||
String res = result.substring(result.indexOf('\n') + 1);
|
||||
return new CasUserIdentity(null,res);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception e) {
|
||||
throw new CasValidationExcepiton("Cas Validation has failed.");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"name": "plannaplan.dev",
|
||||
"type": "java.lang.String",
|
||||
"description": "Should application create resorces for development or not"
|
||||
},
|
||||
{
|
||||
"name": "plannaplan.frontendUrl",
|
||||
"type": "java.lang.String",
|
||||
"description": "Url where frontend app is located"
|
||||
}
|
||||
]
|
||||
}
|
BIN
restservice/src/main/resources/Zajecia.xlsx
Executable file
BIN
restservice/src/main/resources/Zajecia.xlsx
Executable file
Binary file not shown.
13
restservice/src/main/resources/application-dev.properties
Executable file
13
restservice/src/main/resources/application-dev.properties
Executable file
@ -0,0 +1,13 @@
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=yes&characterEncoding=UTF-8
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=example
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.jpa.open-in-view=true
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
||||
spring.jackson.serialization.fail-on-empty-beans=false
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
spring.jackson.default-property-inclusion = NON_NULL
|
||||
server.port=1285
|
||||
plannaplan.dev = true
|
||||
plannaplan.frontendUrl= http://localhost:3000
|
20
restservice/src/main/resources/application-prod.properties
Executable file
20
restservice/src/main/resources/application-prod.properties
Executable file
@ -0,0 +1,20 @@
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
|
||||
spring.datasource.url = jdbc:mysql://${PLANNAPLAN_MYSQL_DB_HOST}:${PLANNAPLAN_MYSQL_DB_PORT}/${PLANNAPLAN_MYSQL_DB}?useUnicode=yes&characterEncoding=UTF-8
|
||||
spring.datasource.username = ${PLANNAPLAN_MYSQL_DB_USERNAME}
|
||||
spring.datasource.password = ${PLANNAPLAN_MYSQL_DB_PASSWORD}
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.jpa.open-in-view=true
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.jackson.serialization.fail-on-empty-beans=false
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
spring.jackson.default-property-inclusion = NON_NULL
|
||||
|
||||
server.port=1285
|
||||
|
||||
plannaplan.dev = false
|
||||
plannaplan.frontendUrl= https://wmi.plannaplan.pl
|
||||
security.require-ssl=true
|
||||
server.ssl.key-store=/keys/keystore.p12
|
||||
server.ssl.key-store-password=
|
||||
server.ssl.keyStoreType=PKCS12
|
||||
server.ssl.keyAlias=tomcat
|
@ -1,11 +1 @@
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=yes&characterEncoding=UTF-8
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=example
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.jpa.open-in-view=true
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
||||
spring.jackson.serialization.fail-on-empty-beans=false
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
|
||||
server.port=1285
|
||||
spring.profiles.active=dev
|
@ -0,0 +1,10 @@
|
||||
package com.plannaplan.controllers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
public abstract class AbstractControllerTest {
|
||||
@Autowired
|
||||
protected WebApplicationContext webApplicationContext;
|
||||
|
||||
}
|
@ -12,7 +12,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||
@ -21,14 +20,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class AssignmentsControllerTest {
|
||||
public class AssignmentsControllerTest extends AbstractControllerTest {
|
||||
|
||||
private static final String ASSIGFNMENTS_ENDPOINT = "/api/v1/assignments/getCurrentAssignments";
|
||||
private static final String ASSIGFNMENTS_ENDPOINT = "/api/v1/assignments/user";
|
||||
private static final String TEST_MAIL = "notexistingassignmentuser@mail.domain";
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext webApplicationContext;
|
||||
|
||||
@Autowired
|
||||
private UserService service;
|
||||
|
||||
@ -40,8 +36,8 @@ public class AssignmentsControllerTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnOk() throws Exception {
|
||||
this.service.save(new User(null, null, TEST_MAIL, UserRoles.TEST_USER));
|
||||
final String token = this.service.login(TEST_MAIL);
|
||||
final User newuser = this.service.save(new User(null, null, TEST_MAIL, UserRoles.TEST_USER));
|
||||
final String token = this.service.login(newuser).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(ASSIGFNMENTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
|
@ -9,7 +9,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@ -26,19 +25,25 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class CommisionControllerTest {
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext webApplicationContext;
|
||||
public class CommisionControllerTest extends AbstractControllerTest {
|
||||
|
||||
@Autowired
|
||||
private UserService service;
|
||||
|
||||
private static User user;
|
||||
private static User otherUser;
|
||||
private static User asker;
|
||||
private static User otherAsker;
|
||||
|
||||
private static final String TEST_COMMISIONS_STUDENT_EMAIL = "commisions.student@notexisting.domain";
|
||||
private static final String TEST_COMMISIONS_OTHER_STUDENT_EMAIL = "commisions.student2@notexisting.domain";
|
||||
private static final String TEST_COMMISIONS_DEANERY_EMAIL = "commisions.deanery@notexisting.domain";
|
||||
private static final String TEST_COMMISIONS_OTHER_DEANERY_EMAIL = "commisions.deanery2@notexisting.domain";
|
||||
|
||||
private static final String ADD_COMMISION_ENDPOINT = "/api/v1/commisions/user";
|
||||
private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
||||
private static final String GET_SOMEONE_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
||||
|
||||
private static final String ADD_COMMISION_ENDPOINT = "/api/v1/commisions/add";
|
||||
private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/getAllCommisions";
|
||||
private static final String TEST_COMMISIONS_EMAIL = "commisions@notexisting.domain";
|
||||
private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
|
||||
MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
|
||||
|
||||
@ -51,8 +56,9 @@ public class CommisionControllerTest {
|
||||
|
||||
@Test
|
||||
public void shouldFailedAddingCommisionDueToNoArgs() throws Exception {
|
||||
this.checkUser();
|
||||
final String token = this.service.login(TEST_COMMISIONS_EMAIL);
|
||||
this.checkUsers();
|
||||
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
@ -61,8 +67,9 @@ public class CommisionControllerTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnOkAddingCommision() throws Exception {
|
||||
this.checkUser();
|
||||
final String token = this.service.login(TEST_COMMISIONS_EMAIL);
|
||||
this.checkUsers();
|
||||
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token)
|
||||
@ -77,18 +84,130 @@ public class CommisionControllerTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnOkGettingAllCommisions() throws Exception {
|
||||
this.checkUser();
|
||||
final String token = this.service.login(TEST_COMMISIONS_EMAIL);
|
||||
this.checkUsers();
|
||||
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(GET_COMMISIONS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
private void checkUser() {
|
||||
@Test
|
||||
public void shouldAddCommisionWithSelfIdPrivided() throws Exception {
|
||||
this.checkUsers();
|
||||
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.user.getId().toString())
|
||||
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailCommisionWithSomeoneIdPrividedAsStudent() throws Exception {
|
||||
this.checkUsers();
|
||||
|
||||
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.otherUser.getId().toString())
|
||||
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
||||
.andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailCommisionAsDeanaryWithNoId() throws Exception {
|
||||
this.checkUsers();
|
||||
final User user = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token)
|
||||
.contentType(APPLICATION_JSON_UTF8).content("[]")).andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailCommisionWithSelfIdPrividedAsDeanary() throws Exception {
|
||||
final User user = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.asker.getId().toString())
|
||||
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
||||
.andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAddCommisionWithSomeoneIdPrividedAsDeanary() throws Exception {
|
||||
this.checkUsers();
|
||||
|
||||
final User user = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.otherUser.getId().toString())
|
||||
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailCommisionWithOtherDeanaryIdPrividedAsDeanary() throws Exception {
|
||||
this.checkUsers();
|
||||
|
||||
final User user = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT + "/" + CommisionControllerTest.otherAsker.getId().toString())
|
||||
.header("Authorization", "Bearer " + token).contentType(APPLICATION_JSON_UTF8).content("[]"))
|
||||
.andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetStudentCommisionsListByDeanary() throws Exception {
|
||||
this.checkUsers();
|
||||
|
||||
final User user = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(GET_SOMEONE_COMMISIONS_ENDPOINT + "/" + CommisionControllerTest.user.getId().toString())
|
||||
.header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailStudentCommisionsListByOtherStudent() throws Exception {
|
||||
this.checkUsers();
|
||||
|
||||
final User user = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(GET_SOMEONE_COMMISIONS_ENDPOINT + "/" + CommisionControllerTest.user.getId().toString())
|
||||
.header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
private void checkUsers() {
|
||||
if (CommisionControllerTest.user == null) {
|
||||
CommisionControllerTest.user = new User(null, null, TEST_COMMISIONS_EMAIL, UserRoles.TEST_USER);
|
||||
CommisionControllerTest.user = new User(null, null, TEST_COMMISIONS_STUDENT_EMAIL, UserRoles.STUDENT);
|
||||
this.service.save(user);
|
||||
}
|
||||
if (CommisionControllerTest.otherUser == null) {
|
||||
CommisionControllerTest.otherUser = new User(null, null, TEST_COMMISIONS_OTHER_STUDENT_EMAIL,
|
||||
UserRoles.STUDENT);
|
||||
this.service.save(otherUser);
|
||||
}
|
||||
if (CommisionControllerTest.asker == null) {
|
||||
CommisionControllerTest.asker = new User(null, null, TEST_COMMISIONS_DEANERY_EMAIL, UserRoles.DEANERY);
|
||||
this.service.save(asker);
|
||||
}
|
||||
if (CommisionControllerTest.otherAsker == null) {
|
||||
CommisionControllerTest.otherAsker = new User(null, null, TEST_COMMISIONS_OTHER_DEANERY_EMAIL,
|
||||
UserRoles.DEANERY);
|
||||
this.service.save(otherAsker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,19 +20,14 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class ConfigControllerTest {
|
||||
public class ConfigControllerTest extends AbstractControllerTest {
|
||||
|
||||
private static final String FILE_NAME = "Zajecia.xlsx";
|
||||
private static final String CONFIG_ENDPOINT = "/api/v1/configurator/config";
|
||||
private static final String TEST_MAIL = "notexisting@mail.domain";
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext webApplicationContext;
|
||||
|
||||
@Autowired
|
||||
private UserService service;
|
||||
@ -49,12 +44,12 @@ public class ConfigControllerTest {
|
||||
|
||||
@Test
|
||||
public void shouldReturnOKAuthorized() throws Exception {
|
||||
final User usr = new User(null, null, TEST_MAIL, UserRoles.ADMIN);
|
||||
this.service.save(usr);
|
||||
final String mail = "shouldReturnOKAuthorized@ConfigController.test";
|
||||
final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN));
|
||||
|
||||
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME);
|
||||
final MockMultipartFile file = new MockMultipartFile("file", inputStream);
|
||||
final String token = this.service.login(TEST_MAIL);
|
||||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).header("Authorization", "Bearer " + token))
|
||||
@ -62,4 +57,19 @@ public class ConfigControllerTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnDenyNoAdminAuthorized() throws Exception {
|
||||
final String mail = "shouldReturnDenyNoAdminAuthorized@ConfigController.test";
|
||||
final User usr = this.service.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||
|
||||
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME);
|
||||
final MockMultipartFile file = new MockMultipartFile("file", inputStream);
|
||||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,13 +2,11 @@ package com.plannaplan.controllers;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
@ -16,13 +14,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class CoursesControllerTest {
|
||||
public class CoursesControllerTest extends AbstractControllerTest {
|
||||
|
||||
private static final String COURSES_ENDPOINT = "/api/v1/courses/getCourses";
|
||||
private static final String COURSESGROUPS_ENDPOINT = "/api/v1/courses/getCoursesWithGroups";
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext webApplicationContext;
|
||||
private static final String COURSES_ENDPOINT = "/api/v1/courses/all";
|
||||
private static final String COURSESGROUPS_ENDPOINT = "/api/v1/courses/all?groups=true";
|
||||
|
||||
@Test
|
||||
public void shouldReturnAllCoursesOk() throws Exception {
|
||||
|
@ -2,13 +2,11 @@ package com.plannaplan.controllers;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
@ -16,21 +14,19 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class GroupControllerTest {
|
||||
private static final String GROUPS_BY_COURSE_ENDPOINT = "/api/v1/groups/getCourseGroups";
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext webApplicationContext;
|
||||
public class GroupControllerTest extends AbstractControllerTest {
|
||||
private static final String GROUPS_BY_COURSE_ENDPOINT = "/api/v1/groups/course";
|
||||
|
||||
@Test
|
||||
public void shouldFailWithNoParaeter() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||
mockMvc.perform(get(GROUPS_BY_COURSE_ENDPOINT)).andExpect(status().isBadRequest());
|
||||
mockMvc.perform(get(GROUPS_BY_COURSE_ENDPOINT)).andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnGroupsOk() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||
mockMvc.perform(get(GROUPS_BY_COURSE_ENDPOINT).param("id", "2")).andExpect(status().isOk());
|
||||
mockMvc.perform(get(GROUPS_BY_COURSE_ENDPOINT + "/2")).andExpect(status().isOk());
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,11 @@ package com.plannaplan.controllers;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
@ -17,10 +15,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class TokenControllerTest {
|
||||
public class TokenControllerTest extends AbstractControllerTest {
|
||||
private final String TOKEN_ENDPOINT = "/token";
|
||||
@Autowired
|
||||
private WebApplicationContext webApplicationContext;
|
||||
|
||||
@Test
|
||||
public void shouldFailWithNoParameter() throws Exception {
|
||||
|
@ -12,7 +12,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||
@ -21,40 +20,71 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class UsersControllerTest {
|
||||
private static final String ENDPOINT = "/api/v1/users/searchForStudents";
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext webApplicationContext;
|
||||
public class UsersControllerTest extends AbstractControllerTest {
|
||||
private static final String SEARCH_ENDPOINT = "/api/v1/users/student/search";
|
||||
private static final String ALL_USERS_ENDPOINT = "/api/v1/users/students";
|
||||
|
||||
@Autowired
|
||||
private UserService service;
|
||||
|
||||
/* SEARCH_ENDPOINT */
|
||||
|
||||
@Test
|
||||
public void shouldRestrun200OK() throws Exception {
|
||||
final String email = "notexistingassignmentuser@shouldRestrun200OK.test";
|
||||
this.service.save(new User(null, null, email, UserRoles.DEANERY));
|
||||
final String token = this.service.login(email);
|
||||
final User user = this.service.save(new User(null, null, email, UserRoles.DEANERY));
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(ENDPOINT).param("query", "").header("Authorization", "Bearer " + token))
|
||||
mockMvc.perform(get(SEARCH_ENDPOINT).param("query", "").header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRestrunForbiden() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
mockMvc.perform(get(SEARCH_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailedDueToMissingParam() throws Exception {
|
||||
final String email = "notexistingassignmentuser@shouldFailedDueToMissingParam.test";
|
||||
this.service.save(new User(null, null, email, UserRoles.DEANERY));
|
||||
final String token = this.service.login(email);
|
||||
final User user = this.service.save(new User(null, null, email, UserRoles.DEANERY));
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
mockMvc.perform(get(SEARCH_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
/* ALL_USERS_ENDPOINT */
|
||||
|
||||
@Test
|
||||
public void shouldRestrunAllStudents200OK() throws Exception {
|
||||
final String email = "notexistingassignmentuser@shouldRestrunAllStudents200OK.test";
|
||||
final User user = this.service.save(new User(null, null, email, UserRoles.DEANERY));
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(ALL_USERS_ENDPOINT).header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRestrunAllStudentsForbiden() throws Exception {
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(ALL_USERS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDenyAllStudentsTryByStudent() throws Exception {
|
||||
final String email = "notexistingassignmentuser@shouldDenyAllStudentsTryByStudent.test";
|
||||
final User user = this.service.save(new User(null, null, email, UserRoles.STUDENT));
|
||||
final String token = this.service.login(user).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(get(ALL_USERS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().is4xxClientError());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,8 +7,11 @@ import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.responses.models.GetCurrentAssignmentsResponse;
|
||||
import com.plannaplan.responses.models.AssignmentResponse;
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@ -16,12 +19,15 @@ public class AssignmentResponseMappersTest {
|
||||
@Test
|
||||
public void shouldReturnNewList() {
|
||||
final Commision com = new Commision();
|
||||
final List<Assignment> groups = Arrays.asList(new Assignment(new Groups(), com),
|
||||
new Assignment(new Groups(), com));
|
||||
final List<GetCurrentAssignmentsResponse> response = AssignmentResponseMappers.mapToResponse(groups);
|
||||
final Course course = new Course("Kurs", "TES-T");
|
||||
final List<Assignment> groups = Arrays.asList(
|
||||
new Assignment(new Groups(142, "A4-1", course, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki")), com),
|
||||
new Assignment(new Groups(32, "A4-1", course, 420, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki")), com));
|
||||
final List<AssignmentResponse> response = AssignmentResponseMappers.mapToResponse(groups);
|
||||
|
||||
assertTrue(response.size() == 2);
|
||||
assertTrue(response instanceof List);
|
||||
assertTrue(response.get(0) instanceof GetCurrentAssignmentsResponse);
|
||||
assertTrue(response.size() == 1);
|
||||
assertTrue(response.get(0) instanceof AssignmentResponse);
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.responses.models.GetCoursesResponse;
|
||||
import com.plannaplan.responses.models.GetCoursesWithGroupsResponse;
|
||||
import com.plannaplan.responses.models.CoursesDefaultResponse;
|
||||
import com.plannaplan.responses.models.CoursesWithGroupsResponse;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@ -15,21 +15,21 @@ public class CoursesResponseMappersTest {
|
||||
@Test
|
||||
public void shouldMapListCoursesToResponseList() {
|
||||
final List<Course> courses = Arrays.asList(new Course(), new Course());
|
||||
final List<GetCoursesResponse> response = CoursesResponseMappers.mapToGetCoursesResponse(courses);
|
||||
final List<CoursesDefaultResponse> response = CoursesResponseMappers.mapToGetCoursesResponse(courses);
|
||||
|
||||
assertTrue(response.size() == 2);
|
||||
assertTrue(response.get(0) instanceof GetCoursesResponse);
|
||||
assertTrue(response.get(0) instanceof CoursesDefaultResponse);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapListCoursesToResponseWithGroupsList() {
|
||||
final List<Course> courses = Arrays.asList(new Course(), new Course());
|
||||
final List<GetCoursesWithGroupsResponse> response = CoursesResponseMappers
|
||||
final List<CoursesWithGroupsResponse> response = CoursesResponseMappers
|
||||
.mapToGetCoursesWithGroupsResponse(courses);
|
||||
|
||||
assertTrue(response.size() == 2);
|
||||
assertTrue(response.get(0) instanceof GetCoursesWithGroupsResponse);
|
||||
assertTrue(response.get(0) instanceof CoursesWithGroupsResponse);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,51 +2,166 @@ package com.plannaplan.responses.mappers;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
import com.plannaplan.responses.models.DefaultGroupResponse;
|
||||
import com.plannaplan.responses.models.GetCourseGroupsResponse;
|
||||
import com.plannaplan.responses.models.WithCapacityGroupResponse;
|
||||
import com.plannaplan.responses.models.GroupDefaultResponse;
|
||||
import com.plannaplan.responses.models.CourseWithGroupsResponse;
|
||||
import com.plannaplan.responses.models.GroupWithCapacityResponse;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class GroupsMappersTest {
|
||||
@Test
|
||||
public void shouldMapToResponseIncludingCapacity() {
|
||||
final List<Groups> gropus = Arrays.asList(
|
||||
new Groups(42, "A4-1", null, 520, WeekDay.MONDAY, new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
||||
final List<WithCapacityGroupResponse> response = GroupsMappers.mapToCapacityResponse(gropus);
|
||||
@Test
|
||||
public void shouldMapToResponseIncludingCapacity() {
|
||||
final List<Groups> gropus = Arrays.asList(new Groups(42, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
||||
final List<GroupWithCapacityResponse> response = GroupsMappers.mapToCapacityResponse(gropus);
|
||||
|
||||
assert (response.get(0).getCapacity() == 42);
|
||||
assert (response.get(0) instanceof WithCapacityGroupResponse);
|
||||
assert (response.size() == 1);
|
||||
}
|
||||
assert (response.get(0).getCapacity() == 42);
|
||||
assert (response.get(0) instanceof GroupWithCapacityResponse);
|
||||
assert (response.size() == 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapToResponseWiothoutCapacity() {
|
||||
final List<Groups> gropus = Arrays.asList(
|
||||
new Groups(42, "A4-1", null, 520, WeekDay.MONDAY, new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
||||
final List<DefaultGroupResponse> response = GroupsMappers.mapToDefaultResponse(gropus);
|
||||
@Test
|
||||
public void shouldMapToResponseWiothoutCapacity() {
|
||||
final List<Groups> gropus = Arrays.asList(new Groups(42, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
||||
final List<GroupDefaultResponse> response = GroupsMappers.mapToDefaultResponse(gropus);
|
||||
|
||||
assert (response.get(0) instanceof DefaultGroupResponse);
|
||||
assert (response.size() == 1);
|
||||
}
|
||||
assert (response.get(0) instanceof GroupDefaultResponse);
|
||||
assert (response.size() == 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapToGetCourseGroupsResponse(){
|
||||
final List<Groups> groups = Arrays.asList(
|
||||
new Groups(150, "A4-1", null, 520, WeekDay.MONDAY, new Lecturer("krul.", "Wladyslaw", "Potocki")), new Groups(24, "A4-1", null, 520, WeekDay.MONDAY, new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
||||
|
||||
final GetCourseGroupsResponse<DefaultGroupResponse> response = GroupsMappers.mapToGetCourseGroupsDefaultResponse(groups);
|
||||
@Test
|
||||
public void shouldMapToGetCourseGroupsResponse() {
|
||||
final List<Groups> groups = Arrays.asList(
|
||||
new Groups(150, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki")),
|
||||
new Groups(24, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
||||
|
||||
assertTrue(response.getClasses().size() == 1);
|
||||
assertTrue(response.getLectures().size() == 1);
|
||||
final CourseWithGroupsResponse<GroupDefaultResponse> response = GroupsMappers
|
||||
.mapToGetCourseGroupsDefaultResponse(groups);
|
||||
|
||||
assertTrue(response.getClasses().size() == 1);
|
||||
assertTrue(response.getLectures().size() == 1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapToGetCourseGroupsResponseWithTakenPlaces() throws NoSuchFieldException, SecurityException,
|
||||
IllegalArgumentException, IllegalAccessException {
|
||||
final Field reader = Groups.class.getDeclaredField("id");
|
||||
reader.setAccessible(true);
|
||||
|
||||
final List<Groups> groups = Arrays.asList(
|
||||
new Groups(150, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki")),
|
||||
new Groups(24, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
||||
reader.set(groups.get(0), Long.valueOf(0));
|
||||
reader.set(groups.get(1), Long.valueOf(1));
|
||||
|
||||
final HashMap<Long, Integer> placeMap = new HashMap<>();
|
||||
placeMap.put(Long.valueOf(0), 0);
|
||||
placeMap.put(Long.valueOf(1), 21);
|
||||
|
||||
final CourseWithGroupsResponse<GroupDefaultResponse> response = GroupsMappers
|
||||
.mapToGetCourseGroupsDefaultResponse(groups, placeMap);
|
||||
|
||||
assertTrue(response.getClasses().size() == 1);
|
||||
assertTrue(response.getLectures().size() == 1);
|
||||
assertTrue(response.getLectures().get(0).getTakenPlaces() == 0);
|
||||
assertTrue(response.getClasses().get(0).getTakenPlaces() == 21);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapToGetCourseCapacityGroupsResponseWithTakenPlaces() throws NoSuchFieldException,
|
||||
SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||
final Field reader = Groups.class.getDeclaredField("id");
|
||||
reader.setAccessible(true);
|
||||
|
||||
final List<Groups> groups = Arrays.asList(
|
||||
new Groups(150, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki")),
|
||||
new Groups(24, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki")));
|
||||
reader.set(groups.get(0), Long.valueOf(0));
|
||||
reader.set(groups.get(1), Long.valueOf(1));
|
||||
|
||||
final HashMap<Long, Integer> placeMap = new HashMap<>();
|
||||
placeMap.put(Long.valueOf(0), 0);
|
||||
placeMap.put(Long.valueOf(1), 21);
|
||||
|
||||
final CourseWithGroupsResponse<GroupWithCapacityResponse> response = GroupsMappers
|
||||
.mapToGetCourseGroupsWithCapacityResponse(groups, placeMap);
|
||||
|
||||
assertTrue(response.getClasses().size() == 1);
|
||||
assertTrue(response.getLectures().size() == 1);
|
||||
assertTrue(response.getLectures().get(0).getTakenPlaces() == 0);
|
||||
assertTrue(response.getLectures().get(0).getCapacity() == 150);
|
||||
assertTrue(response.getClasses().get(0).getTakenPlaces() == 21);
|
||||
assertTrue(response.getClasses().get(0).getCapacity() == 24);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapToDefaultResponseWithTakenPlace() throws NoSuchFieldException, SecurityException,
|
||||
IllegalArgumentException, IllegalAccessException {
|
||||
final Field reader = Groups.class.getDeclaredField("id");
|
||||
reader.setAccessible(true);
|
||||
|
||||
final Groups group1 = new Groups(150, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
final Groups group2 = new Groups(24, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
|
||||
reader.set(group1, Long.valueOf(0));
|
||||
reader.set(group2, Long.valueOf(1));
|
||||
|
||||
final HashMap<Long, Integer> placeMap = new HashMap<>();
|
||||
placeMap.put(Long.valueOf(0), 5);
|
||||
placeMap.put(Long.valueOf(1), 56);
|
||||
|
||||
final List<GroupDefaultResponse> response = GroupsMappers.mapToDefaultResponse(List.of(group1, group2),
|
||||
placeMap);
|
||||
|
||||
assertTrue(response.size() == 2);
|
||||
assertTrue(response.get(0).getTakenPlaces() == 5);
|
||||
assertTrue(response.get(1).getTakenPlaces() == 56);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapToCapacityResponseWithTakenPlace() throws NoSuchFieldException, SecurityException,
|
||||
IllegalArgumentException, IllegalAccessException {
|
||||
final Field reader = Groups.class.getDeclaredField("id");
|
||||
reader.setAccessible(true);
|
||||
|
||||
final Groups group1 = new Groups(150, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
final Groups group2 = new Groups(24, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
|
||||
reader.set(group1, Long.valueOf(0));
|
||||
reader.set(group2, Long.valueOf(1));
|
||||
|
||||
final HashMap<Long, Integer> placeMap = new HashMap<>();
|
||||
placeMap.put(Long.valueOf(0), 5);
|
||||
placeMap.put(Long.valueOf(1), 56);
|
||||
|
||||
final List<GroupWithCapacityResponse> response = GroupsMappers
|
||||
.mapToCapacityResponse(List.of(group1, group2), placeMap);
|
||||
|
||||
assertTrue(response.size() == 2);
|
||||
assertTrue(response.get(0).getTakenPlaces() == 5);
|
||||
assertTrue(response.get(0).getCapacity() == 150);
|
||||
assertTrue(response.get(1).getTakenPlaces() == 56);
|
||||
assertTrue(response.get(1).getCapacity() == 24);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
import com.plannaplan.responses.models.SearchForStudentsResponse;
|
||||
import com.plannaplan.responses.models.UserResponse;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@ -25,8 +25,8 @@ public class UserResponseMappersTest {
|
||||
final List<User> users = Arrays.asList(new User(F_NAME, F_SURNAMENAME, F_EMAIL, UserRoles.TEST_USER),
|
||||
new User(S_NAME, S_SURNAMENAME, S_EMAIL, UserRoles.TEST_USER));
|
||||
|
||||
final List<SearchForStudentsResponse> resposne = UserResponseMappers.mapToDefaultResponse(users);
|
||||
final List<UserResponse> resposne = UserResponseMappers.mapToDefaultResponse(users);
|
||||
assertTrue(resposne.size() == 2);
|
||||
assertTrue(resposne.get(0) instanceof SearchForStudentsResponse);
|
||||
assertTrue(resposne.get(0) instanceof UserResponse);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class AssignmentResponseTest {
|
||||
|
||||
@Test
|
||||
public void shouldMapGroupsToResponse() {
|
||||
final Course course = new Course("Kurs", "tst.");
|
||||
final Groups lecture = new Groups(142, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
final Groups classes = new Groups(22, "A4-2", null, 580, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
|
||||
final AssignmentResponse response = new AssignmentResponse(course, lecture, classes);
|
||||
assertTrue(response.getName() == "Kurs");
|
||||
assertTrue(response.getLecture() instanceof GroupWithCapacityResponse);
|
||||
assertTrue(response.getClasses() instanceof GroupWithCapacityResponse);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapLectureToResponse() {
|
||||
final Course course = new Course("Kurs", "tst.");
|
||||
final Groups lecture = new Groups(142, "A4-1", null, 520, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
|
||||
final AssignmentResponse response = new AssignmentResponse(course, lecture);
|
||||
assertTrue(response.getName() == "Kurs");
|
||||
assertTrue(response.getLecture() instanceof GroupWithCapacityResponse);
|
||||
assertTrue(response.getClasses() == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapClassToResponse() {
|
||||
final Course course = new Course("Kurs", "tst.");
|
||||
final Groups classes = new Groups(22, "A4-2", null, 580, WeekDay.MONDAY,
|
||||
new Lecturer("krul.", "Wladyslaw", "Potocki"));
|
||||
|
||||
final AssignmentResponse response = new AssignmentResponse(course, classes);
|
||||
assertTrue(response.getName() == "Kurs");
|
||||
assertTrue(response.getLecture() == null);
|
||||
assertTrue(response.getClasses() instanceof GroupWithCapacityResponse);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CourseWithGroupsResponseTest {
|
||||
|
||||
@Test public void shouldCreateInstance(){
|
||||
|
||||
final List<GroupDefaultResponse> classes = Arrays.asList(new GroupDefaultResponse(new Groups()));
|
||||
|
||||
final List<GroupDefaultResponse> lectures = Arrays.asList(new GroupDefaultResponse(new Groups()));
|
||||
|
||||
final CourseWithGroupsResponse<GroupDefaultResponse> instance = new CourseWithGroupsResponse<>(classes,lectures);
|
||||
|
||||
assertTrue(instance.getClasses().get(0) instanceof GroupDefaultResponse);
|
||||
assertTrue(instance.getLectures().get(0) instanceof GroupDefaultResponse);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -6,11 +6,11 @@ import com.plannaplan.entities.Course;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class GetCoursesResponseTest {
|
||||
public class CoursesDefaultResponseTest {
|
||||
@Test
|
||||
public void shouldMapFilledCourse() {
|
||||
final Course course = new Course("Test", "XD");
|
||||
final GetCoursesResponse response = new GetCoursesResponse(course);
|
||||
final CoursesDefaultResponse response = new CoursesDefaultResponse(course);
|
||||
|
||||
assertTrue(response.getId() == null);
|
||||
assertTrue(response.getName().equals("Test"));
|
||||
@ -19,7 +19,7 @@ public class GetCoursesResponseTest {
|
||||
@Test
|
||||
public void shouldMapEmptyCourse() {
|
||||
final Course course = new Course();
|
||||
final GetCoursesResponse response = new GetCoursesResponse(course);
|
||||
final CoursesDefaultResponse response = new CoursesDefaultResponse(course);
|
||||
|
||||
assertTrue(response.getId() == null);
|
||||
assertTrue(response.getName().equals(""));
|
@ -6,11 +6,11 @@ import com.plannaplan.entities.Course;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class GetCoursesWithGroupsResponseTest {
|
||||
public class CoursesWithGroupsResponseTest {
|
||||
|
||||
@Test
|
||||
public void shouldMapCourseToResponseWithGroupsIncluded() {
|
||||
final GetCoursesWithGroupsResponse response = new GetCoursesWithGroupsResponse(
|
||||
final CoursesWithGroupsResponse response = new CoursesWithGroupsResponse(
|
||||
new Course("Programowanie funkcyjne", "xd"));
|
||||
|
||||
assertTrue(response.getName() == "Programowanie funkcyjne");
|
@ -1,28 +0,0 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class GetCourseGroupsResponseTest {
|
||||
|
||||
@Test public void shouldCreateInstance(){
|
||||
|
||||
final List<DefaultGroupResponse> classes = Arrays.asList(new DefaultGroupResponse(new Groups()));
|
||||
|
||||
final List<DefaultGroupResponse> lectures = Arrays.asList(new DefaultGroupResponse(new Groups()));
|
||||
|
||||
final GetCourseGroupsResponse<DefaultGroupResponse> instance = new GetCourseGroupsResponse<>(classes,lectures);
|
||||
|
||||
assertTrue(instance.getClasses().get(0) instanceof DefaultGroupResponse);
|
||||
assertTrue(instance.getLectures().get(0) instanceof DefaultGroupResponse);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.plannaplan.responses.models;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
import com.plannaplan.types.GroupType;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class GetCurrentAssignmentsResponseTest {
|
||||
|
||||
@Test
|
||||
public void shouldMapAssignmentClassToResponse() {
|
||||
final Assignment assignment = new Assignment(
|
||||
new Groups(42, "A4-1", null, 520, WeekDay.MONDAY, new Lecturer("krul.", "Wladyslaw", "Potocki")), null);
|
||||
|
||||
final GetCurrentAssignmentsResponse response = new GetCurrentAssignmentsResponse(assignment);
|
||||
assertTrue(response.getCapacity() == 42);
|
||||
assertTrue(response.getDay() == 0);
|
||||
assertTrue(response.getLecturer().equals("krul. Wladyslaw Potocki"));
|
||||
assertTrue(response.getRoom().equals("A4-1"));
|
||||
assertTrue(response.getTime().equals("8.40"));
|
||||
assertTrue(response.getType() == GroupType.CLASS);
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user