Compare commits
69 Commits
token-rele
...
poprawki-2
Author | SHA1 | Date | |
---|---|---|---|
9f1e21a29f | |||
a0570a055f | |||
eecb1a6d36 | |||
389e934035 | |||
4cec07e369 | |||
817350e85e
|
|||
da4e683248
|
|||
09cc994d92
|
|||
c3d78505c8
|
|||
f51979484f
|
|||
038d0b95d2
|
|||
4758c505c4
|
|||
7a62c8d7d8
|
|||
9e6ee6dbb3
|
|||
2ba4082373
|
|||
2ec3699978
|
|||
507d9fddc0
|
|||
e647698591
|
|||
da46582fc0
|
|||
165dee5bd2
|
|||
76cf5c8e96 | |||
6eac8e6266 | |||
61c5a43192 | |||
7f630ccdac | |||
64447b61c8 | |||
7584f3600f | |||
e18f285dd6 | |||
28c09bea6e | |||
a294ecac37 | |||
0d6ad184bc | |||
dfae6d7c78 | |||
c62674b9d8 | |||
8dc94f84c0 | |||
48c23ad4f8 | |||
b93d44346c | |||
4a12dceab6 | |||
ce0d63d7f9 | |||
300130af7e | |||
5ef7c19ade | |||
ca440a3fd5 | |||
ffc4f4709b | |||
84d7ed8e65 | |||
e02523b4f4 | |||
5a1108e1bf | |||
15533525af | |||
d2a679fb22 | |||
e9927f832d | |||
98bbc1aac6 | |||
a6acab932c | |||
831358128e | |||
dfe534a835 | |||
7c457ce232 | |||
f31a50aa06 | |||
52abb281ff | |||
0b807e355c | |||
062b02da6c | |||
0cee454356 | |||
f08e7cf1e5 | |||
7c0c22e790 | |||
1cdb301adf
|
|||
c1dce7d3bb | |||
2921c98c35
|
|||
181d93082c
|
|||
b495fd7f65
|
|||
086e4be458
|
|||
0c471162f2
|
|||
9f3e41e601
|
|||
d85cdb9b22
|
|||
b1091cd3bc |
.gitignore.gitlab-ci.ymlREADME.md
buisnesslogic
pom.xml
init.sqlsrc
main
java
META-INF
com
plannaplan
configutils
entities
models
repositories
services
types
test
java
com
plannaplan
configutils
entities
repositories
services
resources
restservice
pom.xml
stack.ymlsrc
main
java
com
plannaplan
resources
test
java
com
plannaplan
resources
3
.gitignore
vendored
3
.gitignore
vendored
@ -34,3 +34,6 @@ build/
|
|||||||
### Python ###
|
### Python ###
|
||||||
__pycache__
|
__pycache__
|
||||||
.pytest_cache
|
.pytest_cache
|
||||||
|
|
||||||
|
### Parser ###
|
||||||
|
parser/
|
42
.gitlab-ci.yml
Executable file
42
.gitlab-ci.yml
Executable file
@ -0,0 +1,42 @@
|
|||||||
|
stages:
|
||||||
|
- build
|
||||||
|
- deploy
|
||||||
|
|
||||||
|
build:
|
||||||
|
stage: build
|
||||||
|
image: maven
|
||||||
|
script:
|
||||||
|
- echo "Start building App"
|
||||||
|
- echo "spring.profiles.active=prod" > restservice/src/main/resources/application.properties
|
||||||
|
- mvn clean
|
||||||
|
- mvn install
|
||||||
|
- cd restservice
|
||||||
|
- mvn clean package spring-boot:repackage
|
||||||
|
- echo "Build successfully!"
|
||||||
|
artifacts:
|
||||||
|
expire_in: 1 hour
|
||||||
|
paths:
|
||||||
|
- restservice/target/
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
|
||||||
|
deploy_production:
|
||||||
|
stage: deploy
|
||||||
|
before_script:
|
||||||
|
- apt-get update
|
||||||
|
- apt-get --yes --force-yes install rsync
|
||||||
|
script:
|
||||||
|
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
|
||||||
|
- eval $(ssh-agent -s)
|
||||||
|
- ssh-add <(echo "$SSH_PRIVATE_KEY")
|
||||||
|
- mkdir -p ~/.ssh
|
||||||
|
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
|
||||||
|
- echo "Deploying to server"
|
||||||
|
- ssh backend@wmi-backend-gc.plannaplan.pl -t "sudo systemctl stop plannaplan-backend"
|
||||||
|
- ssh backend@wmi-backend-gc.plannaplan.pl -t "rm -rf /opt/plannaplan-backend/backend.jar"
|
||||||
|
- rsync --progress restservice/target/*.jar backend@wmi-backend-gc.plannaplan.pl:/opt/plannaplan-backend/backend.jar
|
||||||
|
- sleep 5
|
||||||
|
- ssh backend@wmi-backend-gc.plannaplan.pl -t "sudo systemctl start plannaplan-backend"
|
||||||
|
- echo "Deployed"
|
||||||
|
only:
|
||||||
|
- master
|
20
README.md
20
README.md
@ -35,21 +35,23 @@ 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`.
|
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:
|
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_HOST` - host bazy danych np `localhost`
|
||||||
- PLANNAPLAN_MYSQL_DB_PORT - port na którym działa baza
|
- `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` - nazwa bazy dancyh. W profilu **dev** jest to np test
|
||||||
- PLANNAPLAN_MYSQL_DB_USERNAME - nazwa użytkownika bazy
|
- `PLANNAPLAN_MYSQL_DB_USERNAME` - nazwa użytkownika bazy
|
||||||
- PLANNAPLAN_MYSQL_DB_PASSWORD - hasło użytkownika bazy
|
- `PLANNAPLAN_MYSQL_DB_PASSWORD` - hasło użytkownika bazy
|
||||||
|
- `PLANNAPLAN_EMAIL_HOST` - host naszego dostawcy maila z którego będziemy wssyłać wiadomości
|
||||||
|
- `PLANNAPLAN_EMAIL_PORT` - port naszego dostawcy maila
|
||||||
|
- `PLANNAPLAN_EMAIL_USERNAME` - login naszego maila
|
||||||
|
- `PLANNAPLAN_EMAIL_PASSWORD` - hasło naszego maila
|
||||||
|
- `PLANNAPLAN_EMAIL` - nasz adres maila
|
||||||
|
|
||||||
## Packaging
|
## Packaging
|
||||||
|
|
||||||
Zeby spakowac apke do `jara` wystarcza dwie komendy zaczynajac z glownego katalogu projektu
|
Zeby spakowac apke do `jara` wystarcza dwie komendy zaczynajac z glownego katalogu projektu
|
||||||
|
|
||||||
```
|
```
|
||||||
mvn clean
|
mvn clean; mvn install; cd restservice; mvn clean package spring-boot:repackage
|
||||||
mvn install
|
|
||||||
cd restservice
|
|
||||||
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)
|
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)
|
||||||
|
@ -68,6 +68,12 @@
|
|||||||
<version>3.17</version>
|
<version>3.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-mail</artifactId>
|
||||||
|
<version>2.2.5.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
9
buisnesslogic/src/main/java/META-INF/additional-spring-configuration-metadata.json
Executable file
9
buisnesslogic/src/main/java/META-INF/additional-spring-configuration-metadata.json
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "plannaplan.email",
|
||||||
|
"type": "java.lang.String",
|
||||||
|
"description": "Email from which app sends message"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -32,6 +32,9 @@ public class FileToDatabaseMigrator {
|
|||||||
private static final String ROOM_STRING = "sala";
|
private static final String ROOM_STRING = "sala";
|
||||||
private static final String CAPACITY_STRING = "Mc";
|
private static final String CAPACITY_STRING = "Mc";
|
||||||
|
|
||||||
|
private static final String ZAJ_CYK_ID = "zaj_cyk_id";
|
||||||
|
private static final String GR_NR = "gr_nr";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LecturerService lecturerService;
|
private LecturerService lecturerService;
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -56,6 +59,9 @@ public class FileToDatabaseMigrator {
|
|||||||
int roomIndex = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
int roomIndex = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
||||||
int capacityIndex = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
|
int capacityIndex = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
|
||||||
|
|
||||||
|
int zajCykIdIndex = data.getIndexOf(FileToDatabaseMigrator.ZAJ_CYK_ID);
|
||||||
|
int grNrIndex = data.getIndexOf(FileToDatabaseMigrator.GR_NR);
|
||||||
|
|
||||||
while (rows.hasNext()) {
|
while (rows.hasNext()) {
|
||||||
Row row = rows.next();
|
Row row = rows.next();
|
||||||
|
|
||||||
@ -67,6 +73,12 @@ public class FileToDatabaseMigrator {
|
|||||||
String lecturerSurname = row.getCell(surnameIndex) != null ? row.getCell(surnameIndex).toString().trim()
|
String lecturerSurname = row.getCell(surnameIndex) != null ? row.getCell(surnameIndex).toString().trim()
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
|
Integer zajCykId = row.getCell(zajCykIdIndex) != null ? (int) Double.parseDouble(row.getCell(zajCykIdIndex).toString().trim())
|
||||||
|
: null;
|
||||||
|
|
||||||
|
Integer grNr = row.getCell(grNrIndex) != null ? (int) Double.parseDouble(row.getCell(grNrIndex).toString().trim())
|
||||||
|
: null;
|
||||||
|
|
||||||
int day = (int) Double.parseDouble(row.getCell(dayIndex).toString());
|
int day = (int) Double.parseDouble(row.getCell(dayIndex).toString());
|
||||||
WeekDay groupDay = WeekDay.getDay(day - 1);
|
WeekDay groupDay = WeekDay.getDay(day - 1);
|
||||||
int time = parseTimeToInt(row.getCell(timeIndex).toString());
|
int time = parseTimeToInt(row.getCell(timeIndex).toString());
|
||||||
@ -80,8 +92,12 @@ public class FileToDatabaseMigrator {
|
|||||||
.orElseGet(() -> this.lecturerService
|
.orElseGet(() -> this.lecturerService
|
||||||
.save(new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
|
.save(new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
|
||||||
|
|
||||||
this.groupService.find(time, capacity, room).orElseGet(
|
Groups group = this.groupService.find(zajCykId, grNr).orElseGet(
|
||||||
() -> this.groupService.save(new Groups(capacity, room, course, time, groupDay, lecturer)));
|
() -> new Groups(capacity, room, course, time, groupDay, lecturer, zajCykId, grNr));
|
||||||
|
|
||||||
|
group.update(capacity, room, course, time, null, groupDay, lecturer);
|
||||||
|
|
||||||
|
this.groupService.save(group);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
118
buisnesslogic/src/main/java/com/plannaplan/entities/AppConfig.java
Executable file
118
buisnesslogic/src/main/java/com/plannaplan/entities/AppConfig.java
Executable file
@ -0,0 +1,118 @@
|
|||||||
|
package com.plannaplan.entities;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
import com.plannaplan.models.TourData;
|
||||||
|
import com.plannaplan.types.AppState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* entity that keeps app configurations
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
public class AppConfig {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
private Date firstTourStart;
|
||||||
|
private Date firstTourEnd;
|
||||||
|
private Date secondTourStart;
|
||||||
|
private Date secondTourEnd;
|
||||||
|
private Timestamp configDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* no parameter construcotor
|
||||||
|
*/
|
||||||
|
public AppConfig() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor
|
||||||
|
*
|
||||||
|
* @param firstTour first TourData instacne
|
||||||
|
* @param scondTour second TourData instacne
|
||||||
|
*/
|
||||||
|
public AppConfig(TourData firstTour, TourData scondTour) {
|
||||||
|
this.firstTourStart = firstTour.getStart();
|
||||||
|
this.firstTourEnd = firstTour.getEnd();
|
||||||
|
this.secondTourStart = scondTour.getStart();
|
||||||
|
this.secondTourEnd = scondTour.getEnd();
|
||||||
|
this.configDate = new Timestamp(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* second tour end getter
|
||||||
|
*
|
||||||
|
* @return Date inforamtion when second tour ends
|
||||||
|
*/
|
||||||
|
public Date getSecondTourEnd() {
|
||||||
|
return secondTourEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* first second start getter
|
||||||
|
*
|
||||||
|
* @return Date inforamtion when second tour start
|
||||||
|
*/
|
||||||
|
public Date getSecondTourStart() {
|
||||||
|
return secondTourStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* first tour end getter
|
||||||
|
*
|
||||||
|
* @return Date inforamtion when first tour end
|
||||||
|
*/
|
||||||
|
public Date getFirstTourEnd() {
|
||||||
|
return firstTourEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* first tour start getter
|
||||||
|
*
|
||||||
|
* @return Date inforamtion when first tour start
|
||||||
|
*/
|
||||||
|
public Date getFirstTourStart() {
|
||||||
|
return firstTourStart;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* config date getter
|
||||||
|
*
|
||||||
|
* @return Timestamp when configuration took place
|
||||||
|
*/
|
||||||
|
public Timestamp getConfigDate() {
|
||||||
|
return configDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* current state getter
|
||||||
|
*
|
||||||
|
* @return AppState of app at the moment of calling method
|
||||||
|
*/
|
||||||
|
public AppState getCurrentState() {
|
||||||
|
final Date now = new Date(System.currentTimeMillis());
|
||||||
|
if (this.secondTourEnd.before(now)) {
|
||||||
|
return AppState.NO_TOUR;
|
||||||
|
}
|
||||||
|
if (this.secondTourStart.before(now)) {
|
||||||
|
return AppState.SECOND_TOUR;
|
||||||
|
}
|
||||||
|
if (this.firstTourEnd.before(now)) {
|
||||||
|
return AppState.NO_TOUR;
|
||||||
|
}
|
||||||
|
if (this.firstTourStart.before(now)) {
|
||||||
|
return AppState.FIRST_TOUR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return AppState.NO_TOUR;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -24,6 +24,9 @@ public class Commision {
|
|||||||
@OneToOne
|
@OneToOne
|
||||||
@JoinColumn(name = "owner_id")
|
@JoinColumn(name = "owner_id")
|
||||||
private User commisionOwner;
|
private User commisionOwner;
|
||||||
|
@OneToOne
|
||||||
|
@JoinColumn(name = "commiter_id")
|
||||||
|
private User commisionCommiter;
|
||||||
private Timestamp commisionDate;
|
private Timestamp commisionDate;
|
||||||
|
|
||||||
@OneToMany(mappedBy = "commision", fetch = FetchType.EAGER)
|
@OneToMany(mappedBy = "commision", fetch = FetchType.EAGER)
|
||||||
@ -37,6 +40,17 @@ public class Commision {
|
|||||||
public Commision(User user) {
|
public Commision(User user) {
|
||||||
this.commisionDate = new Timestamp(System.currentTimeMillis());
|
this.commisionDate = new Timestamp(System.currentTimeMillis());
|
||||||
this.commisionOwner = user;
|
this.commisionOwner = user;
|
||||||
|
this.commisionCommiter = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param user user whose shedule is being commited
|
||||||
|
* @param commiter user that commited new schedule
|
||||||
|
*/
|
||||||
|
public Commision(User user, User commiter) {
|
||||||
|
this(user);
|
||||||
|
this.commisionCommiter = commiter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Commision() {
|
public Commision() {
|
||||||
@ -44,6 +58,7 @@ public class Commision {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Id getter
|
* Id getter
|
||||||
|
*
|
||||||
* @return id id of commision
|
* @return id id of commision
|
||||||
*/
|
*/
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
@ -52,6 +67,7 @@ public class Commision {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* CommisionDate getter
|
* CommisionDate getter
|
||||||
|
*
|
||||||
* @return commisionDate
|
* @return commisionDate
|
||||||
*/
|
*/
|
||||||
public Timestamp getCommisionDate() {
|
public Timestamp getCommisionDate() {
|
||||||
@ -60,14 +76,26 @@ public class Commision {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* User of given commision getter
|
* User of given commision getter
|
||||||
|
*
|
||||||
* @return User commisionOwner
|
* @return User commisionOwner
|
||||||
*/
|
*/
|
||||||
public User getCommisionOwner() {
|
public User getCommisionOwner() {
|
||||||
return commisionOwner;
|
return commisionOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return User entity that created commision (can be owner or deanery user)
|
||||||
|
*/
|
||||||
|
public User getCommisionCommiter() {
|
||||||
|
if (commisionCommiter == null) {
|
||||||
|
return commisionOwner;
|
||||||
|
}
|
||||||
|
return commisionCommiter;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assigments getter
|
* Assigments getter
|
||||||
|
*
|
||||||
* @return List of assignments
|
* @return List of assignments
|
||||||
*/
|
*/
|
||||||
public List<Assignment> getAssignments() {
|
public List<Assignment> getAssignments() {
|
||||||
|
@ -11,11 +11,14 @@ import com.plannaplan.types.GroupType;
|
|||||||
import com.plannaplan.types.WeekDay;
|
import com.plannaplan.types.WeekDay;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity of Groups grouping of state ssociated about course,time,room,capacity,type,day
|
* Entity of Groups grouping of state ssociated about
|
||||||
|
* course,time,room,capacity,type,day
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Groups {
|
public class Groups {
|
||||||
|
private static final int DEFAULT_CLASS_TIME = 90;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
@ -23,6 +26,7 @@ public class Groups {
|
|||||||
@JoinColumn(name = "course_id")
|
@JoinColumn(name = "course_id")
|
||||||
private Course course;
|
private Course course;
|
||||||
private int time;
|
private int time;
|
||||||
|
private int endTime;
|
||||||
private String room;
|
private String room;
|
||||||
private int capacity;
|
private int capacity;
|
||||||
private GroupType type;
|
private GroupType type;
|
||||||
@ -30,10 +34,70 @@ public class Groups {
|
|||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "lecturer_id")
|
@JoinColumn(name = "lecturer_id")
|
||||||
private Lecturer lecturer;
|
private Lecturer lecturer;
|
||||||
|
private Integer zajCykId;
|
||||||
|
private Integer grNr;
|
||||||
|
|
||||||
public Groups() {
|
public Groups() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getGr_nr() {
|
||||||
|
return grNr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGr_nr(Integer grNr) {
|
||||||
|
this.grNr = grNr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getZaj_cyk_id() {
|
||||||
|
return zajCykId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZaj_cyk_id(Integer zajCykId) {
|
||||||
|
this.zajCykId = zajCykId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Groups
|
||||||
|
*
|
||||||
|
* @param capacity capacity given to the groups
|
||||||
|
* @param room room given to the groups
|
||||||
|
* @param course course given to the groups
|
||||||
|
* @param time time given to the groups
|
||||||
|
* @param endTime end time of class in minutes
|
||||||
|
* @param day day given to the groups
|
||||||
|
* @param lecturer lecturer given to the groups
|
||||||
|
*/
|
||||||
|
public Groups(int capacity, String room, Course course, int time, int endTime, WeekDay day, Lecturer lecturer) {
|
||||||
|
this.capacity = capacity;
|
||||||
|
this.room = room;
|
||||||
|
this.course = course;
|
||||||
|
this.time = time;
|
||||||
|
this.endTime = endTime;
|
||||||
|
this.day = day;
|
||||||
|
this.lecturer = lecturer;
|
||||||
|
this.type = capacity >= 50 ? GroupType.LECTURE : GroupType.CLASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Groups
|
||||||
|
*
|
||||||
|
* @param capacity capacity given to the groups
|
||||||
|
* @param room room given to the groups
|
||||||
|
* @param course course given to the groups
|
||||||
|
* @param time time given to the groups
|
||||||
|
* @param endTime end time of class in minutes
|
||||||
|
* @param day day given to the groups
|
||||||
|
* @param lecturer lecturer given to the groups
|
||||||
|
* @param zajCykId number of class in the term
|
||||||
|
* @param gr_nr Number of class/course
|
||||||
|
*/
|
||||||
|
public Groups(int capacity, String room, Course course, int time, int endTime, WeekDay day, Lecturer lecturer, Integer zajCykId, Integer grNr) {
|
||||||
|
this(capacity, room, course, time, endTime, day, lecturer);
|
||||||
|
this.zajCykId = zajCykId;
|
||||||
|
this.grNr = grNr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Groups
|
* Groups
|
||||||
*
|
*
|
||||||
@ -43,19 +107,82 @@ public class Groups {
|
|||||||
* @param time time given to the groups
|
* @param time time given to the groups
|
||||||
* @param day day given to the groups
|
* @param day day given to the groups
|
||||||
* @param lecturer lecturer given to the groups
|
* @param lecturer lecturer given to the groups
|
||||||
|
* @param zajCykId number of class in the term
|
||||||
|
* @param grNr Number of class/course
|
||||||
|
*/
|
||||||
|
public Groups(int capacity, String room, Course course, int time, WeekDay day, Lecturer lecturer, Integer zajCykId, Integer grNr) {
|
||||||
|
this(capacity, room, course, time, time + DEFAULT_CLASS_TIME, day, lecturer);
|
||||||
|
this.zajCykId = zajCykId;
|
||||||
|
this.grNr = grNr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create groups with default class duration
|
||||||
|
*
|
||||||
|
* @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) {
|
public Groups(int capacity, String room, Course course, int time, WeekDay day, Lecturer lecturer) {
|
||||||
|
this(capacity, room, course, time, time + DEFAULT_CLASS_TIME, day, lecturer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates given values other that are not null
|
||||||
|
*
|
||||||
|
* @param capacity capacity given to the groups
|
||||||
|
* @param room room given to the groups
|
||||||
|
* @param course course given to the groups
|
||||||
|
* @param time time given to the groups
|
||||||
|
* @param endTime end time of class in minutes
|
||||||
|
* @param day day given to the groups
|
||||||
|
* @param lecturer lecturer given to the groups
|
||||||
|
*/
|
||||||
|
public void update(Integer capacity, String room, Course course, Integer time, Integer endTime, WeekDay day, Lecturer lecturer){
|
||||||
|
if (capacity != null){
|
||||||
this.capacity = capacity;
|
this.capacity = capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (room != null){
|
||||||
this.room = room;
|
this.room = room;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (course != null){
|
||||||
this.course = course;
|
this.course = course;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (time != null){
|
||||||
this.time = time;
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (endTime != null){
|
||||||
|
this.endTime = endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (day != null){
|
||||||
this.day = day;
|
this.day = day;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lecturer != null){
|
||||||
this.lecturer = lecturer;
|
this.lecturer = lecturer;
|
||||||
this.type = capacity >= 50 ? GroupType.LECTURE : GroupType.CLASS;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get time of class end
|
||||||
|
*
|
||||||
|
* @return hour of class finish time in minutes
|
||||||
|
*/
|
||||||
|
public int getEndTime() {
|
||||||
|
return endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getId
|
* getId
|
||||||
|
*
|
||||||
* @return id
|
* @return id
|
||||||
*/
|
*/
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
@ -64,6 +191,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getLecturer
|
* getLecturer
|
||||||
|
*
|
||||||
* @return lecturer
|
* @return lecturer
|
||||||
*/
|
*/
|
||||||
public Lecturer getLecturer() {
|
public Lecturer getLecturer() {
|
||||||
@ -72,6 +200,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setLecturer
|
* setLecturer
|
||||||
|
*
|
||||||
* @param lecturer set lecturer into groups
|
* @param lecturer set lecturer into groups
|
||||||
*/
|
*/
|
||||||
public void setLecturer(Lecturer lecturer) {
|
public void setLecturer(Lecturer lecturer) {
|
||||||
@ -80,6 +209,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* WeekDay
|
* WeekDay
|
||||||
|
*
|
||||||
* @return day
|
* @return day
|
||||||
*/
|
*/
|
||||||
public WeekDay getDay() {
|
public WeekDay getDay() {
|
||||||
@ -88,6 +218,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setLecturer
|
* setLecturer
|
||||||
|
*
|
||||||
* @param day set day into groups
|
* @param day set day into groups
|
||||||
*/
|
*/
|
||||||
public void setDay(WeekDay day) {
|
public void setDay(WeekDay day) {
|
||||||
@ -96,6 +227,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* GroupType
|
* GroupType
|
||||||
|
*
|
||||||
* @return type
|
* @return type
|
||||||
*/
|
*/
|
||||||
public GroupType getType() {
|
public GroupType getType() {
|
||||||
@ -104,6 +236,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setType
|
* setType
|
||||||
|
*
|
||||||
* @param type set type into groups
|
* @param type set type into groups
|
||||||
*/
|
*/
|
||||||
public void setType(GroupType type) {
|
public void setType(GroupType type) {
|
||||||
@ -112,6 +245,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getCapacity
|
* getCapacity
|
||||||
|
*
|
||||||
* @return capacity
|
* @return capacity
|
||||||
*/
|
*/
|
||||||
public int getCapacity() {
|
public int getCapacity() {
|
||||||
@ -120,6 +254,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setCapacity
|
* setCapacity
|
||||||
|
*
|
||||||
* @param capacity set capacity into groups
|
* @param capacity set capacity into groups
|
||||||
*/
|
*/
|
||||||
public void setCapacity(int capacity) {
|
public void setCapacity(int capacity) {
|
||||||
@ -128,6 +263,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getRoom
|
* getRoom
|
||||||
|
*
|
||||||
* @return room
|
* @return room
|
||||||
*/
|
*/
|
||||||
public String getRoom() {
|
public String getRoom() {
|
||||||
@ -136,6 +272,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setRoom
|
* setRoom
|
||||||
|
*
|
||||||
* @param room set room into groups
|
* @param room set room into groups
|
||||||
*/
|
*/
|
||||||
public void setRoom(String room) {
|
public void setRoom(String room) {
|
||||||
@ -144,6 +281,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getTime
|
* getTime
|
||||||
|
*
|
||||||
* @return time
|
* @return time
|
||||||
*/
|
*/
|
||||||
public int getTime() {
|
public int getTime() {
|
||||||
@ -152,6 +290,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setTime
|
* setTime
|
||||||
|
*
|
||||||
* @param time set time into groups
|
* @param time set time into groups
|
||||||
*/
|
*/
|
||||||
public void setTime(int time) {
|
public void setTime(int time) {
|
||||||
@ -160,6 +299,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getCourseId
|
* getCourseId
|
||||||
|
*
|
||||||
* @return course
|
* @return course
|
||||||
*/
|
*/
|
||||||
public Course getCourseId() {
|
public Course getCourseId() {
|
||||||
@ -168,6 +308,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* setCourseId
|
* setCourseId
|
||||||
|
*
|
||||||
* @param courseId set courseId into groups
|
* @param courseId set courseId into groups
|
||||||
*/
|
*/
|
||||||
public void setCourseId(Course courseId) {
|
public void setCourseId(Course courseId) {
|
||||||
@ -176,6 +317,7 @@ public class Groups {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getTimeString
|
* getTimeString
|
||||||
|
*
|
||||||
* @return time as formated String
|
* @return time as formated String
|
||||||
*/
|
*/
|
||||||
public String getTimeString() {
|
public String getTimeString() {
|
||||||
@ -187,4 +329,19 @@ public class Groups {
|
|||||||
}
|
}
|
||||||
return String.format("%s.%s", hoursString, minutesString);
|
return String.format("%s.%s", hoursString, minutesString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets end time formated strins
|
||||||
|
*
|
||||||
|
* @return end time as formated String
|
||||||
|
*/
|
||||||
|
public String getEndTimeString() {
|
||||||
|
int minutes = this.getEndTime() % 60;
|
||||||
|
String hoursString = Integer.toString(this.getEndTime() / 60);
|
||||||
|
String minutesString = Integer.toString(minutes);
|
||||||
|
if (minutes < 10) {
|
||||||
|
minutesString = "0" + minutesString;
|
||||||
|
}
|
||||||
|
return String.format("%s.%s", hoursString, minutesString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.plannaplan.entities;
|
package com.plannaplan.entities;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
@ -11,7 +12,8 @@ import javax.persistence.Id;
|
|||||||
import com.plannaplan.types.UserRoles;
|
import com.plannaplan.types.UserRoles;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity of User grouping of state ssociated about id,name,surname,email,role,token,tokenCreatedDate
|
* Entity of User grouping of state ssociated about
|
||||||
|
* id,name,surname,email,role,token,tokenCreatedDate
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@ -27,19 +29,18 @@ public class User {
|
|||||||
private String usosId;
|
private String usosId;
|
||||||
private UserRoles role;
|
private UserRoles role;
|
||||||
private String token;
|
private String token;
|
||||||
|
private String refreshToken;
|
||||||
private Timestamp tokenUsageDate;
|
private Timestamp tokenUsageDate;
|
||||||
|
|
||||||
|
|
||||||
public User() {
|
public User() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* User
|
|
||||||
*
|
*
|
||||||
* @param name name given to the user
|
* @param name name given to the user
|
||||||
* @param surname surname given to the user
|
* @param surname surname given to the user
|
||||||
* @param email mail given to the user
|
* @param mail mail given to the user
|
||||||
* @param role role given to the user
|
* @param role
|
||||||
*/
|
*/
|
||||||
public User(String name, String surname, String mail, UserRoles role) {
|
public User(String name, String surname, String mail, UserRoles role) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -48,134 +49,150 @@ public class User {
|
|||||||
this.role = role;
|
this.role = role;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* User
|
|
||||||
*
|
*
|
||||||
* @param name name given to the user
|
* @param name name given to the user
|
||||||
* @param surname surname given to the user
|
* @param surname surname given to the user
|
||||||
* @param email mail given to the user
|
* @param mail mail given to the user
|
||||||
* @param usosId id in the USOS system
|
* @param usosId id in the USOS system
|
||||||
* @param role role given to the user
|
* @param role
|
||||||
*/
|
*/
|
||||||
public User(String name, String surname, String mail, String usosId, UserRoles role) {
|
public User(String name, String surname, String mail, String usosId, UserRoles role) {
|
||||||
this(name, surname, mail, role);
|
this(name, surname, mail, role);
|
||||||
this.usosId = usosId;
|
this.usosId = usosId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* getusosId
|
* usos id getter
|
||||||
*
|
*
|
||||||
* @return usosId
|
* @return usosid
|
||||||
*/
|
*/
|
||||||
public String getUsosId() {
|
public String getUsosId() {
|
||||||
return usosId;
|
return usosId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* getEmail
|
* email getter
|
||||||
*
|
*
|
||||||
* @return email
|
* @return mailof user
|
||||||
*/
|
*/
|
||||||
public String getEmail() {
|
public String getEmail() {
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* setEmail
|
* email setter
|
||||||
*
|
*
|
||||||
* @param email set email to the user
|
* @param email user email
|
||||||
*/
|
*/
|
||||||
public void setEmail(String email) {
|
public void setEmail(String email) {
|
||||||
this.email = email;
|
this.email = email;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* getTokenUsageDate
|
* token usage getter
|
||||||
*
|
*
|
||||||
* @return tokenUsageDate
|
* @return Timestamp when token was used
|
||||||
*/
|
*/
|
||||||
public Timestamp getTokenUsageDate() {
|
public Timestamp getTokenUsageDate() {
|
||||||
return tokenUsageDate;
|
return tokenUsageDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* getToken
|
* token getter
|
||||||
*
|
*
|
||||||
* @return token
|
* @return user token
|
||||||
*/
|
*/
|
||||||
public String getToken() {
|
public String getToken() {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* setToken
|
* @return token needed to call refresh token after it expired
|
||||||
|
*/
|
||||||
|
public String getRefreshToken() {
|
||||||
|
return refreshToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token seter. Sets token and automaticly set time when was set
|
||||||
*
|
*
|
||||||
* @param token set token to the entity
|
* @param token token to set
|
||||||
*/
|
*/
|
||||||
public void setToken(String token) {
|
public void setToken(String token) {
|
||||||
this.tokenUsageDate = new Timestamp(System.currentTimeMillis());
|
this.tokenUsageDate = new Timestamp(System.currentTimeMillis());
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
this.refreshToken = UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* getName
|
/**
|
||||||
|
* name setter
|
||||||
*
|
*
|
||||||
* @return name
|
* @return String user name
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* getRole
|
/**
|
||||||
|
* user rolse getter
|
||||||
*
|
*
|
||||||
* @return role
|
* @return UserRoles of user
|
||||||
*/
|
*/
|
||||||
public UserRoles getRole() {
|
public UserRoles getRole() {
|
||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* setRole
|
/**
|
||||||
|
* user role setter
|
||||||
*
|
*
|
||||||
* @param role set role to the entity
|
* @param role to be set
|
||||||
*/
|
*/
|
||||||
public void setRole(UserRoles role) {
|
public void setRole(UserRoles role) {
|
||||||
this.role = role;
|
this.role = role;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* getSurname
|
* surname getter
|
||||||
* @return surname
|
*
|
||||||
|
* @return string surname
|
||||||
*/
|
*/
|
||||||
public String getSurname() {
|
public String getSurname() {
|
||||||
return surname;
|
return surname;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* setSurname
|
* surname setter
|
||||||
* @param surname set surname into entity user
|
*
|
||||||
|
* @param surname string to be set as surnames
|
||||||
*/
|
*/
|
||||||
public void setSurname(String surname) {
|
public void setSurname(String surname) {
|
||||||
this.surname = surname;
|
this.surname = surname;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* setName
|
* name stter
|
||||||
* @param name set name into entity user
|
*
|
||||||
|
* @param name stirng to be set as name
|
||||||
*/
|
*/
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* getId
|
* id getter
|
||||||
* @return id
|
*
|
||||||
|
* @return id in database
|
||||||
*/
|
*/
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* isCredentialsNonExpired
|
* it checks if given ammount of time passed since last token usage. If not
|
||||||
* Returns TRUE if is Credentials Non Expired in the otherwise it returns false
|
* retunr true and reset time otherwise return false and token won work anymore
|
||||||
|
*
|
||||||
|
* @return boolena if credentials (token) is expired or not
|
||||||
*/
|
*/
|
||||||
public boolean isCredentialsNonExpired() {
|
public boolean isCredentialsNonExpired() {
|
||||||
final long diffInMilliseconds = Math
|
final long diffInMilliseconds = Math
|
||||||
|
@ -1,51 +1,50 @@
|
|||||||
package com.plannaplan.models;
|
package com.plannaplan.models;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class ConfigData {
|
public class ConfigData {
|
||||||
private Date start;
|
private TourData firstTour;
|
||||||
private Date end;
|
private TourData secondTour;
|
||||||
private InputStream filestream;
|
private InputStream filestream;
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* ConfigData
|
* constructor
|
||||||
*
|
*
|
||||||
* @param start when the configdata begins
|
* @param firstTour date of first tours
|
||||||
* @param end when the configdata ends
|
* @param secondTour date of second tours
|
||||||
* @param filestream where the filestream is
|
* @param filestream filestram with data to import
|
||||||
*/
|
*/
|
||||||
public ConfigData(Date start, Date end, InputStream filestream) {
|
public ConfigData(TourData firstTour, TourData secondTour, InputStream filestream) {
|
||||||
this.start = start;
|
this.firstTour = firstTour;
|
||||||
this.end = end;
|
this.secondTour = secondTour;
|
||||||
this.filestream = filestream;
|
this.filestream = filestream;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* getFilestream
|
* second tour getter
|
||||||
*
|
*
|
||||||
* @return filestream
|
* @return TourData second tour
|
||||||
|
*/
|
||||||
|
public TourData getSecondTour() {
|
||||||
|
return secondTour;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* first tour getter
|
||||||
|
*
|
||||||
|
* @return TourData first tour
|
||||||
|
*/
|
||||||
|
public TourData getFirstTour() {
|
||||||
|
return firstTour;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* filestream getter
|
||||||
|
*
|
||||||
|
* @return InputStream with data to import
|
||||||
*/
|
*/
|
||||||
public InputStream getFilestream() {
|
public InputStream getFilestream() {
|
||||||
return filestream;
|
return filestream;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* getEnd
|
|
||||||
*
|
|
||||||
* @return end
|
|
||||||
*/
|
|
||||||
public Date getEnd() {
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* getStart
|
|
||||||
*
|
|
||||||
* @return start
|
|
||||||
*/
|
|
||||||
public Date getStart() {
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
49
buisnesslogic/src/main/java/com/plannaplan/models/TourData.java
Executable file
49
buisnesslogic/src/main/java/com/plannaplan/models/TourData.java
Executable file
@ -0,0 +1,49 @@
|
|||||||
|
package com.plannaplan.models;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
|
||||||
|
public class TourData {
|
||||||
|
|
||||||
|
private Date start;
|
||||||
|
private Date end;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* construcotr for java.sql.Date
|
||||||
|
*
|
||||||
|
* @param start Date when tour start
|
||||||
|
* @param end Date when tour end
|
||||||
|
*/
|
||||||
|
public TourData(Date start, Date end) {
|
||||||
|
this.start = start;
|
||||||
|
this.end = end;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor construcotr for java.util.Date
|
||||||
|
*
|
||||||
|
* @param start Date when tour start
|
||||||
|
* @param end Date when tour end
|
||||||
|
*/
|
||||||
|
public TourData(java.util.Date start, java.util.Date end) {
|
||||||
|
this.start = new Date(start.getTime());
|
||||||
|
this.end = new Date(end.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tour end getter
|
||||||
|
*
|
||||||
|
* @return Date end of tour
|
||||||
|
*/
|
||||||
|
public Date getEnd() {
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tour start getter
|
||||||
|
*
|
||||||
|
* @return Date beginning of tour
|
||||||
|
*/
|
||||||
|
public Date getStart() {
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.plannaplan.repositories;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.AppConfig;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface AppConfigRepository extends JpaRepository<AppConfig, Long> {
|
||||||
|
}
|
@ -28,6 +28,9 @@ public interface GroupRepository extends JpaRepository<Groups, Long> {
|
|||||||
@Query("FROM Groups WHERE time = ?1 AND room = ?2 AND capacity = ?3")
|
@Query("FROM Groups WHERE time = ?1 AND room = ?2 AND capacity = ?3")
|
||||||
Optional<Groups> find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity);
|
Optional<Groups> find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity);
|
||||||
|
|
||||||
|
@Query("FROM Groups WHERE zajCykId = ?1 AND grNr = ?2")
|
||||||
|
Optional<Groups> find(@Param("zajCykId") Integer zaj_cyk_id, @Param("grNr") Integer gr_nr);
|
||||||
|
|
||||||
@Query("FROM Groups WHERE course_id = ?1")
|
@Query("FROM Groups WHERE course_id = ?1")
|
||||||
List<Groups> getByCourse(@Param("id") Long id);
|
List<Groups> getByCourse(@Param("id") Long id);
|
||||||
|
|
||||||
|
@ -12,36 +12,38 @@ import org.springframework.data.repository.query.Param;
|
|||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UserRepository.getByAuthority:
|
* UserRepository.getByAuthority: Return list of: SELECT * FROM User WHERE email
|
||||||
* Return list of:
|
* = i.
|
||||||
* SELECT * FROM User WHERE email = i.
|
|
||||||
*
|
*
|
||||||
* Where i, ?1 are equale to variables.
|
* Where i, ?1 are equale to variables.
|
||||||
*
|
*
|
||||||
* UserRepository.getByToken:
|
* UserRepository.getByToken: Return list of: SELECT * FROM User WHERE token =
|
||||||
* Return list of:
|
* i.
|
||||||
* SELECT * FROM User WHERE token = i.
|
|
||||||
*
|
*
|
||||||
* Where i, ?1 are equale to variables.
|
* Where i, ?1 are equale to variables.
|
||||||
*
|
*
|
||||||
* UserRepository.searchForUsers:
|
* UserRepository.searchForUsers: Return list of: SELECT * FROM User WHERE (name
|
||||||
* Return list of:
|
* LIKE %?1% OR surname LIKE %?1%).
|
||||||
* SELECT * FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%).
|
|
||||||
*
|
*
|
||||||
* Where i, ?1 are equale to variables.
|
* Where i, ?1 are equale to variables.
|
||||||
*
|
*
|
||||||
* UserRepository.searchForUsers with role:
|
* UserRepository.searchForUsers with role: Return list of: SELECT * FROM User
|
||||||
* Return list of:
|
* WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2").
|
||||||
* SELECT * FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2").
|
|
||||||
*
|
*
|
||||||
* Where i, ?1 are equale to variables.
|
* Where i, ?1 are equale to variables.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface UserRepository extends JpaRepository<User, Long> {
|
public interface UserRepository extends JpaRepository<User, Long> {
|
||||||
@Query("FROM User WHERE email = ?1")
|
@Query("FROM User WHERE email = ?1 OR usosId = ?1")
|
||||||
Optional<User> getByAuthority(@Param("authority") String authority);
|
Optional<User> getByAuthority(@Param("authority") String authority);
|
||||||
|
|
||||||
|
@Query("FROM User WHERE email = ?1")
|
||||||
|
Optional<User> getByEmail(@Param("authority") String authority);
|
||||||
|
|
||||||
|
@Query("FROM User WHERE refreshToken = ?1")
|
||||||
|
Optional<User> getByRefreshToken(@Param("refreshToken") String refreshToken);
|
||||||
|
|
||||||
@Query("FROM User WHERE token = ?1")
|
@Query("FROM User WHERE token = ?1")
|
||||||
Optional<User> getByToken(@Param("token") String token);
|
Optional<User> getByToken(@Param("token") String token);
|
||||||
|
|
||||||
@ -51,6 +53,9 @@ public interface UserRepository extends JpaRepository<User, Long> {
|
|||||||
@Query("FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2")
|
@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);
|
List<User> searchForUsers(@Param("query") String query, @Param("role") UserRoles role);
|
||||||
|
|
||||||
|
@Query("FROM User WHERE role=?1")
|
||||||
|
List<User> getAllByRole(@Param("role") UserRoles role);
|
||||||
|
|
||||||
@Query("FROM User WHERE usosId = ?1")
|
@Query("FROM User WHERE usosId = ?1")
|
||||||
Optional<User> getByUsosId(@Param("usosId") String usosId);
|
Optional<User> getByUsosId(@Param("usosId") String usosId);
|
||||||
}
|
}
|
@ -2,11 +2,19 @@ package com.plannaplan.services;
|
|||||||
|
|
||||||
import com.plannaplan.models.ConfigData;
|
import com.plannaplan.models.ConfigData;
|
||||||
import com.plannaplan.models.FileData;
|
import com.plannaplan.models.FileData;
|
||||||
|
import com.plannaplan.models.TourData;
|
||||||
|
import com.plannaplan.repositories.AppConfigRepository;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.plannaplan.configutils.*;
|
import com.plannaplan.configutils.*;
|
||||||
|
import com.plannaplan.entities.AppConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FileReader is used for reading xls file from input stream.
|
* FileReader is used for reading xls file from input stream.
|
||||||
@ -16,14 +24,63 @@ public class ConfiguratorService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FileToDatabaseMigrator migrator;
|
private FileToDatabaseMigrator migrator;
|
||||||
|
@Autowired
|
||||||
|
private AppConfigRepository configRepo;
|
||||||
|
|
||||||
public ConfiguratorService() {
|
public ConfiguratorService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* methoid to config system
|
||||||
|
*
|
||||||
|
* @param data ConfigData containng system configs
|
||||||
|
*/
|
||||||
public void config(ConfigData data) {
|
public void config(ConfigData data) {
|
||||||
FileReader reader = new FileReader(data.getFilestream());
|
FileReader reader = new FileReader(data.getFilestream());
|
||||||
FileData coursesData = reader.read();
|
FileData coursesData = reader.read();
|
||||||
|
this.configRepo.save(new AppConfig(data.getFirstTour(), data.getSecondTour()));
|
||||||
migrator.migrate(coursesData);
|
migrator.migrate(coursesData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save tours to DataBase
|
||||||
|
* @param firstTour First tour period.
|
||||||
|
* @param secondTour Second tour period.
|
||||||
|
*/
|
||||||
|
public void saveTours(TourData firstTour, TourData secondTour) {
|
||||||
|
this.configRepo.save(new AppConfig(firstTour, secondTour));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* current config getter
|
||||||
|
*
|
||||||
|
* @return AppConfig with newest config_date
|
||||||
|
*/
|
||||||
|
public AppConfig getCurrentConfig() {
|
||||||
|
final List<AppConfig> repsonse = this.configRepo.findAll().stream().sorted(new Comparator<AppConfig>() {
|
||||||
|
@Override
|
||||||
|
public int compare(AppConfig i1, AppConfig i2) {
|
||||||
|
if (i1.getConfigDate().after(i2.getConfigDate())) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (i1.getConfigDate().before(i2.getConfigDate())) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
return repsonse.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param inputStream This input stream contains new courses to import.
|
||||||
|
*/
|
||||||
|
public void importCoursesStream(InputStream inputStream) {
|
||||||
|
FileReader reader = new FileReader(inputStream);
|
||||||
|
FileData coursesData = reader.read();
|
||||||
|
migrator.migrate(coursesData);
|
||||||
|
}
|
||||||
}
|
}
|
38
buisnesslogic/src/main/java/com/plannaplan/services/EmailService.java
Executable file
38
buisnesslogic/src/main/java/com/plannaplan/services/EmailService.java
Executable file
@ -0,0 +1,38 @@
|
|||||||
|
package com.plannaplan.services;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.mail.SimpleMailMessage;
|
||||||
|
import org.springframework.mail.javamail.JavaMailSender;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service to send emails
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class EmailService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JavaMailSender emailSender;
|
||||||
|
|
||||||
|
@Value("${plannaplan.email}")
|
||||||
|
private String appEmail;
|
||||||
|
|
||||||
|
public EmailService() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send simple text email
|
||||||
|
*
|
||||||
|
* @param destination destitnaion mail
|
||||||
|
* @param message text to be send
|
||||||
|
*/
|
||||||
|
public void sendMail(String destination, String message) {
|
||||||
|
SimpleMailMessage mailMessage = new SimpleMailMessage();
|
||||||
|
mailMessage.setFrom(appEmail);
|
||||||
|
mailMessage.setTo(destination);
|
||||||
|
mailMessage.setSubject("[Plan na plan] INFO");
|
||||||
|
mailMessage.setText(message);
|
||||||
|
emailSender.send(mailMessage);
|
||||||
|
}
|
||||||
|
}
|
17
buisnesslogic/src/main/java/com/plannaplan/services/EventService.java
Executable file
17
buisnesslogic/src/main/java/com/plannaplan/services/EventService.java
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
package com.plannaplan.services;
|
||||||
|
|
||||||
|
// import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class EventService {
|
||||||
|
|
||||||
|
// @Autowired
|
||||||
|
// private EmailService emailService;
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 2 17 * * *")
|
||||||
|
public void collectGroupLosses() {
|
||||||
|
System.out.println("Checking for groups");
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@ import java.util.Optional;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.Assignment;
|
||||||
import com.plannaplan.entities.Groups;
|
import com.plannaplan.entities.Groups;
|
||||||
import com.plannaplan.repositories.GroupRepository;
|
import com.plannaplan.repositories.GroupRepository;
|
||||||
|
|
||||||
@ -30,6 +31,10 @@ public class GroupService {
|
|||||||
return this.repo.find(time, room, capacity);
|
return this.repo.find(time, room, capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<Groups> find(Integer zajCykId, Integer nrGr) {
|
||||||
|
return this.repo.find(zajCykId, nrGr);
|
||||||
|
}
|
||||||
|
|
||||||
public List<Groups> getGroupsByCourse(Long id) {
|
public List<Groups> getGroupsByCourse(Long id) {
|
||||||
return this.repo.getByCourse(id);
|
return this.repo.getByCourse(id);
|
||||||
}
|
}
|
||||||
@ -60,6 +65,16 @@ public class GroupService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param assingemnts list of assingemnts 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> getTakenPlacesOfAssignments(List<Assignment> assignments) {
|
||||||
|
return getTakenPlaces(assignments.stream().map(Assignment::getGroup).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param groups list of groups you want to get taken places ammount
|
* @param groups list of groups you want to get taken places ammount
|
||||||
|
@ -25,12 +25,16 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public User checkForUser(String email, String usosId) {
|
public User checkForUser(String email, String usosId) {
|
||||||
|
return this.checkForUser(email, usosId, UserRoles.STUDENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public User checkForUser(String email, String usosId, UserRoles roleIfNotExist) {
|
||||||
if (usosId == null) {
|
if (usosId == null) {
|
||||||
Optional<User> user = this.repo.getByAuthority(email.replace("\n", "").trim());
|
Optional<User> user = this.repo.getByEmail(email.replace("\n", "").trim());
|
||||||
if (user.isPresent()) {
|
if (user.isPresent()) {
|
||||||
return user.get();
|
return user.get();
|
||||||
} else {
|
} else {
|
||||||
final User newUser = new User(null, null, email.replace("\n", "").trim(), UserRoles.STUDENT);
|
final User newUser = new User(null, null, email.replace("\n", "").trim(), roleIfNotExist);
|
||||||
return this.repo.save(newUser);
|
return this.repo.save(newUser);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -38,7 +42,7 @@ public class UserService {
|
|||||||
if (user.isPresent()) {
|
if (user.isPresent()) {
|
||||||
return user.get();
|
return user.get();
|
||||||
} else {
|
} else {
|
||||||
final User newUser = new User(null, null, email.replace("\n", "").trim(), usosId, UserRoles.STUDENT);
|
final User newUser = new User(null, null, email.replace("\n", "").trim(), usosId, roleIfNotExist);
|
||||||
return this.repo.save(newUser);
|
return this.repo.save(newUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -60,11 +64,15 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public User getUserByEmail(String email) throws UserNotFoundException {
|
public User getUserByEmail(String email) throws UserNotFoundException {
|
||||||
return this.repo.getByAuthority(email.replace("\n", "").trim())
|
return this.repo.getByEmail(email.replace("\n", "").trim())
|
||||||
.orElseThrow(() -> new UserNotFoundException("Cannot find user with given authority"));
|
.orElseThrow(() -> new UserNotFoundException("Cannot find user with given authority"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<User> getByAuthority(String authority) {
|
||||||
|
return this.repo.getByAuthority(authority);
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<User> getByToken(String token) {
|
public Optional<User> getByToken(String token) {
|
||||||
return this.repo.getByToken(token);
|
return this.repo.getByToken(token);
|
||||||
}
|
}
|
||||||
@ -77,4 +85,16 @@ public class UserService {
|
|||||||
return this.repo.findById(userId);
|
return this.repo.findById(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<User> getAllStudents() {
|
||||||
|
return this.repo.getAllByRole(UserRoles.STUDENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<User> getUserByRefreshToken(String refreshToken) {
|
||||||
|
return this.repo.getByRefreshToken(refreshToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean adminExists(){
|
||||||
|
return this.repo.getAllByRole(UserRoles.ADMIN).size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
5
buisnesslogic/src/main/java/com/plannaplan/types/AppState.java
Executable file
5
buisnesslogic/src/main/java/com/plannaplan/types/AppState.java
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
package com.plannaplan.types;
|
||||||
|
|
||||||
|
public enum AppState {
|
||||||
|
FIRST_TOUR, SECOND_TOUR, NO_TOUR
|
||||||
|
}
|
@ -15,7 +15,7 @@ public class FileReaderTest {
|
|||||||
final FileReader r = new FileReader(inputStream);
|
final FileReader r = new FileReader(inputStream);
|
||||||
final FileData d = r.read();
|
final FileData d = r.read();
|
||||||
assertTrue(d.getRows().next().getCell(0).toString().equals("1.0"));
|
assertTrue(d.getRows().next().getCell(0).toString().equals("1.0"));
|
||||||
assertTrue(d.getKeys().size() == 22);
|
assertTrue(d.getKeys().size() == 24);
|
||||||
assertTrue(d != null);
|
assertTrue(d != null);
|
||||||
}
|
}
|
||||||
}
|
}
|
141
buisnesslogic/src/test/java/com/plannaplan/entities/AppConfigTest.java
Executable file
141
buisnesslogic/src/test/java/com/plannaplan/entities/AppConfigTest.java
Executable file
@ -0,0 +1,141 @@
|
|||||||
|
package com.plannaplan.entities;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.sql.Date;
|
||||||
|
|
||||||
|
import com.plannaplan.models.TourData;
|
||||||
|
import com.plannaplan.types.AppState;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class AppConfigTest {
|
||||||
|
|
||||||
|
private static long ONE_DAY = 86400000;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnNoTourDueToTooEarly() {
|
||||||
|
final Date firtstTourStart = new Date(System.currentTimeMillis() + ONE_DAY);
|
||||||
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() + 2 * ONE_DAY);
|
||||||
|
final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY);
|
||||||
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
||||||
|
|
||||||
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||||
|
new TourData(secondTourStart, secondTourEnd));
|
||||||
|
assertTrue(config.getCurrentState() == AppState.NO_TOUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnFirstTourDueToStart() throws InterruptedException {
|
||||||
|
final Date firtstTourStart = new Date(System.currentTimeMillis());
|
||||||
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() + 2 * ONE_DAY);
|
||||||
|
final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY);
|
||||||
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
||||||
|
|
||||||
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||||
|
new TourData(secondTourStart, secondTourEnd));
|
||||||
|
Thread.sleep(1000);
|
||||||
|
assertTrue(config.getCurrentState() == AppState.FIRST_TOUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnFirstTourDueToInBetween() {
|
||||||
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - ONE_DAY);
|
||||||
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() + 2 * ONE_DAY);
|
||||||
|
final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY);
|
||||||
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
||||||
|
|
||||||
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||||
|
new TourData(secondTourStart, secondTourEnd));
|
||||||
|
assertTrue(config.getCurrentState() == AppState.FIRST_TOUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnNoTourInLastDay() throws InterruptedException {
|
||||||
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - ONE_DAY);
|
||||||
|
final Date firtstTourEnd = new Date(System.currentTimeMillis());
|
||||||
|
final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY);
|
||||||
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
||||||
|
|
||||||
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||||
|
new TourData(secondTourStart, secondTourEnd));
|
||||||
|
Thread.sleep(1000);
|
||||||
|
assertTrue(config.getCurrentState() == AppState.NO_TOUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnNoTourInBetween() {
|
||||||
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - 2 * ONE_DAY);
|
||||||
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() - ONE_DAY);
|
||||||
|
final Date secondTourStart = new Date(System.currentTimeMillis() + 3 * ONE_DAY);
|
||||||
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
||||||
|
|
||||||
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||||
|
new TourData(secondTourStart, secondTourEnd));
|
||||||
|
assertTrue(config.getCurrentState() == AppState.NO_TOUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnSecondTourInStart() throws InterruptedException {
|
||||||
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - 2 * ONE_DAY);
|
||||||
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() - ONE_DAY);
|
||||||
|
final Date secondTourStart = new Date(System.currentTimeMillis());
|
||||||
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
||||||
|
|
||||||
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||||
|
new TourData(secondTourStart, secondTourEnd));
|
||||||
|
Thread.sleep(1000);
|
||||||
|
assertTrue(config.getCurrentState() == AppState.SECOND_TOUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnSecondTourInBetween() {
|
||||||
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - 3 * ONE_DAY);
|
||||||
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() - 2 * ONE_DAY);
|
||||||
|
final Date secondTourStart = new Date(System.currentTimeMillis() - ONE_DAY);
|
||||||
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + 4 * ONE_DAY);
|
||||||
|
|
||||||
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||||
|
new TourData(secondTourStart, secondTourEnd));
|
||||||
|
assertTrue(config.getCurrentState() == AppState.SECOND_TOUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnNoTourDueToEndSecond() throws InterruptedException {
|
||||||
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - 3 * ONE_DAY);
|
||||||
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() - 2 * ONE_DAY);
|
||||||
|
final Date secondTourStart = new Date(System.currentTimeMillis() - ONE_DAY);
|
||||||
|
final Date secondTourEnd = new Date(System.currentTimeMillis());
|
||||||
|
|
||||||
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||||
|
new TourData(secondTourStart, secondTourEnd));
|
||||||
|
Thread.sleep(1000);
|
||||||
|
assertTrue(config.getCurrentState() == AppState.NO_TOUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnNoTourAfterSecondEnd() {
|
||||||
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - 4 * ONE_DAY);
|
||||||
|
final Date firtstTourEnd = new Date(System.currentTimeMillis() - 3 * ONE_DAY);
|
||||||
|
final Date secondTourStart = new Date(System.currentTimeMillis() - 2 * ONE_DAY);
|
||||||
|
final Date secondTourEnd = new Date(System.currentTimeMillis() - ONE_DAY);
|
||||||
|
|
||||||
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||||
|
new TourData(secondTourStart, secondTourEnd));
|
||||||
|
assertTrue(config.getCurrentState() == AppState.NO_TOUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnSecondTourWhereThereIsABrake() throws InterruptedException {
|
||||||
|
final Date firtstTourStart = new Date(System.currentTimeMillis() - 4 * ONE_DAY);
|
||||||
|
final Date firtstTourEnd = new Date(System.currentTimeMillis());
|
||||||
|
final Date secondTourStart = new Date(System.currentTimeMillis());
|
||||||
|
final Date secondTourEnd = new Date(System.currentTimeMillis() + ONE_DAY);
|
||||||
|
|
||||||
|
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||||
|
new TourData(secondTourStart, secondTourEnd));
|
||||||
|
Thread.sleep(1000);
|
||||||
|
assertTrue(config.getCurrentState() == AppState.SECOND_TOUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.plannaplan.repositories;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.User;
|
||||||
|
import com.plannaplan.services.UserService;
|
||||||
|
import com.plannaplan.types.UserRoles;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
@ContextConfiguration
|
||||||
|
public class UserRepositoryTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnByAuthorityWithGivenEmail(){
|
||||||
|
final String email = "shouldReturnByAuthorityWithGivenEmail@UserRepository.Test";
|
||||||
|
final String usosId = "45678";
|
||||||
|
final User user = this.userService.save(new User("shouldReturnByAuthority", "WithGivenEmail", email, usosId, UserRoles.TEST_USER));
|
||||||
|
|
||||||
|
final Optional<User> response = this.userRepository.getByAuthority(email);
|
||||||
|
assertTrue(response.get().getEmail().equals(email));
|
||||||
|
assertTrue(response.get().getUsosId().equals(usosId));
|
||||||
|
assertTrue(response.get().getId().equals(user.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnByAuthorityWithUsosId(){
|
||||||
|
final String email = "shouldReturnByAuthorityWithUsosId@UserRepository.Test";
|
||||||
|
final String usosId = "45678";
|
||||||
|
final User user = this.userService.save(new User("shouldReturnByAuthority", "WithGivenEmail", email, usosId, UserRoles.TEST_USER));
|
||||||
|
|
||||||
|
final Optional<User> response = this.userRepository.getByAuthority(usosId);
|
||||||
|
assertTrue(response.get().getEmail().equals(email));
|
||||||
|
assertTrue(response.get().getUsosId().equals(usosId));
|
||||||
|
assertTrue(response.get().getId().equals(user.getId()));
|
||||||
|
}
|
||||||
|
}
|
@ -2,15 +2,23 @@ package com.plannaplan.services;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext.MethodMode;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.sql.Date;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.plannaplan.TestApplication;
|
import com.plannaplan.TestApplication;
|
||||||
|
import com.plannaplan.entities.AppConfig;
|
||||||
|
import com.plannaplan.entities.Groups;
|
||||||
import com.plannaplan.models.ConfigData;
|
import com.plannaplan.models.ConfigData;
|
||||||
|
import com.plannaplan.models.TourData;
|
||||||
|
import com.plannaplan.repositories.AppConfigRepository;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -20,6 +28,9 @@ import org.junit.runner.RunWith;
|
|||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class ConfiguratorServiceTest {
|
public class ConfiguratorServiceTest {
|
||||||
|
|
||||||
|
private final static String BEFORE_UPDATE_FILE = "ZajeciaBeforeUpdate.xlsx";
|
||||||
|
private final static String AFTER_UPDATE_FILE = "ZajeciaAfterUpdate.xlsx";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ConfiguratorService configuratorService;
|
private ConfiguratorService configuratorService;
|
||||||
|
|
||||||
@ -32,11 +43,18 @@ public class ConfiguratorServiceTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private LecturerService lecturerService;
|
private LecturerService lecturerService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AppConfigRepository appConfigRepo;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldImportDataToDataBase() {
|
public void shouldImportDataToDataBase() {
|
||||||
final InputStream inputStream = getClass().getClassLoader()
|
final InputStream inputStream = getClass().getClassLoader()
|
||||||
.getResourceAsStream(TestApplication.TEST_CONFIG_FILE);
|
.getResourceAsStream(TestApplication.TEST_CONFIG_FILE);
|
||||||
final ConfigData data = new ConfigData(null, null, inputStream);
|
final ConfigData data = new ConfigData(
|
||||||
|
new TourData(new Date(System.currentTimeMillis()), new Date(System.currentTimeMillis() + 86400000)),
|
||||||
|
new TourData(new Date(System.currentTimeMillis() + 86400000),
|
||||||
|
new Date(System.currentTimeMillis() + 2 * 86400000)),
|
||||||
|
inputStream);
|
||||||
this.configuratorService.config(data);
|
this.configuratorService.config(data);
|
||||||
|
|
||||||
int courses_ammount = this.courseService.getCoursesAmmount();
|
int courses_ammount = this.courseService.getCoursesAmmount();
|
||||||
@ -46,4 +64,41 @@ public class ConfiguratorServiceTest {
|
|||||||
assertTrue(courses_ammount > 0 && groups_ammount > 0 && lecturers_ammount > 0);
|
assertTrue(courses_ammount > 0 && groups_ammount > 0 && lecturers_ammount > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||||
|
public void shouldUpdatePreviousImport(){
|
||||||
|
final InputStream inputStream = getClass().getClassLoader()
|
||||||
|
.getResourceAsStream(ConfiguratorServiceTest.BEFORE_UPDATE_FILE);
|
||||||
|
this.configuratorService.importCoursesStream(inputStream);
|
||||||
|
int groups_ammount = this.groupService.getGroupsAmmount();
|
||||||
|
|
||||||
|
assertTrue(groups_ammount == 2);
|
||||||
|
|
||||||
|
final InputStream inputStream2 = getClass().getClassLoader()
|
||||||
|
.getResourceAsStream(ConfiguratorServiceTest.AFTER_UPDATE_FILE);
|
||||||
|
this.configuratorService.importCoursesStream(inputStream2);
|
||||||
|
int groups_ammount2 = this.groupService.getGroupsAmmount();
|
||||||
|
|
||||||
|
Optional<Groups> newGroup = this.groupService.find(456458, 3);
|
||||||
|
Optional<Groups> updateGroup = this.groupService.find(456457, 2);
|
||||||
|
|
||||||
|
assertTrue(groups_ammount2 == 3);
|
||||||
|
assertTrue(newGroup.isPresent());
|
||||||
|
assertTrue(updateGroup.get().getLecturer().getSurname().equals("Murawski"));
|
||||||
|
assertTrue(updateGroup.get().getLecturer().getName().equals("Roman"));
|
||||||
|
assertTrue(updateGroup.get().getLecturer().getTitle().equals("prof. dr hab."));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRetrunNewestConfig() throws InterruptedException {
|
||||||
|
final Date dateToCheck = new Date(System.currentTimeMillis());
|
||||||
|
this.appConfigRepo.save(new AppConfig(new TourData(null, null), new TourData(null, null)));
|
||||||
|
Thread.sleep(2000);
|
||||||
|
this.appConfigRepo.save(new AppConfig(new TourData(dateToCheck, null), new TourData(null, null)));
|
||||||
|
|
||||||
|
AppConfig response = this.configuratorService.getCurrentConfig();
|
||||||
|
assertTrue(response.getFirstTourStart() != null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
29
buisnesslogic/src/test/java/com/plannaplan/services/EmailServiceTest.java
Executable file
29
buisnesslogic/src/test/java/com/plannaplan/services/EmailServiceTest.java
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
package com.plannaplan.services;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
@ContextConfiguration
|
||||||
|
public class EmailServiceTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmailService service;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
/**
|
||||||
|
* This test is ignored because we don't have way to check if email has arrived.
|
||||||
|
* Check mailchater to check this manually
|
||||||
|
*/
|
||||||
|
public void shouldSendSimpleEmail() {
|
||||||
|
this.service.sendMail("shouldSendSimpleEmail@EmailService.test", "This is totally simple message");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,8 @@ package com.plannaplan.services;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext.MethodMode;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
@ -100,4 +102,20 @@ public class UserServiceTest {
|
|||||||
|
|
||||||
assertTrue(user.getName() != "Tom");
|
assertTrue(user.getName() != "Tom");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnAdminExists() {
|
||||||
|
final String email = "shouldReturnAdminExists@UserService.test";
|
||||||
|
this.userService.save(new User("AdminTom", "Smieszny", email, UserRoles.ADMIN));
|
||||||
|
assertTrue(userService.adminExists());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||||
|
public void shouldReturnNotAdminExists() {
|
||||||
|
final String email = "shouldReturnNotAdminExists@UserService.test";
|
||||||
|
this.userService.save(new User("StudentTom", "Smieszny", email, UserRoles.STUDENT));
|
||||||
|
assertTrue(userService.adminExists() == false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
BIN
buisnesslogic/src/test/resources/ZajeciaAfterUpdate.xlsx
Executable file
BIN
buisnesslogic/src/test/resources/ZajeciaAfterUpdate.xlsx
Executable file
Binary file not shown.
BIN
buisnesslogic/src/test/resources/ZajeciaBeforeUpdate.xlsx
Executable file
BIN
buisnesslogic/src/test/resources/ZajeciaBeforeUpdate.xlsx
Executable file
Binary file not shown.
@ -8,5 +8,11 @@ spring.jpa.hibernate.ddl-auto=create-drop
|
|||||||
spring.jackson.serialization.fail-on-empty-beans=false
|
spring.jackson.serialization.fail-on-empty-beans=false
|
||||||
spring.main.allow-bean-definition-overriding=true
|
spring.main.allow-bean-definition-overriding=true
|
||||||
spring.jackson.default-property-inclusion = NON_NULL
|
spring.jackson.default-property-inclusion = NON_NULL
|
||||||
|
spring.mail.host=localhost
|
||||||
|
spring.mail.port=1025
|
||||||
|
spring.mail.properties.mail.smtp.auth=false
|
||||||
|
spring.mail.properties.mail.smtp.starttls.enable=false
|
||||||
|
|
||||||
|
plannaplan.email = plannaplan.kontakt@gmail.com
|
||||||
|
|
||||||
server.port=1285
|
server.port=1285
|
1
init.sql
1
init.sql
@ -1 +1,2 @@
|
|||||||
CREATE DATABASE IF NOT EXISTS test;
|
CREATE DATABASE IF NOT EXISTS test;
|
||||||
|
SET GLOBAL time_zone = '+1:00';
|
@ -1,8 +1,10 @@
|
|||||||
package com.plannaplan;
|
package com.plannaplan;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.sql.Date;
|
||||||
|
|
||||||
import com.plannaplan.models.ConfigData;
|
import com.plannaplan.models.ConfigData;
|
||||||
|
import com.plannaplan.models.TourData;
|
||||||
import com.plannaplan.entities.User;
|
import com.plannaplan.entities.User;
|
||||||
import com.plannaplan.services.UserService;
|
import com.plannaplan.services.UserService;
|
||||||
import com.plannaplan.types.UserRoles;
|
import com.plannaplan.types.UserRoles;
|
||||||
@ -14,9 +16,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
|
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
import com.plannaplan.services.ConfiguratorService;
|
import com.plannaplan.services.ConfiguratorService;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableScheduling
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
public final static String API_VERSION = "v1";
|
public final static String API_VERSION = "v1";
|
||||||
@ -38,13 +43,22 @@ public class App {
|
|||||||
SpringApplication.run(App.class, args);
|
SpringApplication.run(App.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* method to import mocked data to testing app after startz. It is called only
|
||||||
|
* in dev profile
|
||||||
|
*/
|
||||||
@EventListener(ApplicationReadyEvent.class)
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
public void importData() {
|
public void importData() {
|
||||||
System.out.println(Logo.getInitInfo(isDev));
|
System.out.println(Logo.getInitInfo(isDev));
|
||||||
|
|
||||||
if (this.isDev) {
|
if (this.isDev) {
|
||||||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
|
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
|
||||||
ConfigData data = new ConfigData(null, null, inputStream);
|
ConfigData data = new ConfigData(
|
||||||
|
new TourData(new Date(System.currentTimeMillis()),
|
||||||
|
new Date(System.currentTimeMillis() + 86400000)),
|
||||||
|
new TourData(new Date(System.currentTimeMillis() + 86400000),
|
||||||
|
new Date(System.currentTimeMillis() + 2 * 86400000)),
|
||||||
|
inputStream);
|
||||||
this.contrl.config(data);
|
this.contrl.config(data);
|
||||||
|
|
||||||
User newuser = new User();
|
User newuser = new User();
|
||||||
@ -109,6 +123,11 @@ public class App {
|
|||||||
newuser.setSurname("Sad");
|
newuser.setSurname("Sad");
|
||||||
newuser.setRole(UserRoles.STUDENT);
|
newuser.setRole(UserRoles.STUDENT);
|
||||||
this.userService.save(newuser);
|
this.userService.save(newuser);
|
||||||
|
|
||||||
|
newuser = new User();
|
||||||
|
newuser.setEmail("iamnull@st.amu.edu.pl");
|
||||||
|
newuser.setRole(UserRoles.STUDENT);
|
||||||
|
this.userService.save(newuser);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(Logo.getStartedInfo(isDev));
|
System.out.println(Logo.getStartedInfo(isDev));
|
||||||
|
@ -24,14 +24,10 @@ public class Swagger2Config extends WebMvcConfigurationSupport {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Docket createRestApi() {
|
public Docket createRestApi() {
|
||||||
Parameter authHeader = new ParameterBuilder()
|
Parameter authHeader = new ParameterBuilder().parameterType("header").name("Authorization")
|
||||||
.parameterType("header")
|
.modelRef(new ModelRef("string")).build();
|
||||||
.name("Authorization")
|
|
||||||
.modelRef(new ModelRef("string"))
|
|
||||||
.build();
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
|
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
|
||||||
.apis(RequestHandlerSelectors.basePackage("com.plannaplan")).paths(PathSelectors.any())
|
.apis(RequestHandlerSelectors.basePackage("com.plannaplan")).paths(PathSelectors.any()).build()
|
||||||
.build()
|
|
||||||
.globalOperationParameters(Collections.singletonList(authHeader));
|
.globalOperationParameters(Collections.singletonList(authHeader));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@RequestMapping("/api/" + App.API_VERSION + "/assignments")
|
@RequestMapping("/api/" + App.API_VERSION + "/assignments")
|
||||||
@Api(tags = {
|
@Api(tags = {
|
||||||
"Assignments" }, value = "Assignments", description = "Assignment is representation of student willing to join given group (lecture or calss)")
|
"Assignments" }, value = "Assignments", description = "Assignment is representation of student willing to join given group (lecture or calss). This comtroller is depreaceted. Use commission instead")
|
||||||
|
@Deprecated
|
||||||
public class AssignmentsController extends TokenBasedController {
|
public class AssignmentsController extends TokenBasedController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -39,7 +40,8 @@ public class AssignmentsController extends TokenBasedController {
|
|||||||
private AssignmentService assignmentService;
|
private AssignmentService assignmentService;
|
||||||
|
|
||||||
@GetMapping("/user")
|
@GetMapping("/user")
|
||||||
@ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided.")
|
@ApiOperation(value = "Return user current assignemts (from newest commision). STUDENT Token needs to be provided. This method is depreaceted. Use `/api/v1/commisions/user/schedule` instead.")
|
||||||
|
@Deprecated
|
||||||
public ResponseEntity<List<AssignmentResponse>> getCurrentAssignments() throws Exception {
|
public ResponseEntity<List<AssignmentResponse>> getCurrentAssignments() throws Exception {
|
||||||
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found"));
|
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException("User not found"));
|
||||||
Optional<Commision> com = this.commisionService.getNewestCommision(user);
|
Optional<Commision> com = this.commisionService.getNewestCommision(user);
|
||||||
|
@ -33,6 +33,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import com.plannaplan.responses.mappers.AssignmentResponseMappers;
|
||||||
|
import com.plannaplan.responses.models.AssignmentResponse;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@ -76,7 +83,7 @@ public class CommisionController extends TokenBasedController {
|
|||||||
Assert.isTrue(!notExistingGroup.isPresent(), "Group "
|
Assert.isTrue(!notExistingGroup.isPresent(), "Group "
|
||||||
+ notExistingGroup.orElse(Long.MIN_VALUE).toString() + "doesn't exist");
|
+ notExistingGroup.orElse(Long.MIN_VALUE).toString() + "doesn't exist");
|
||||||
|
|
||||||
final Commision com = new Commision(user);
|
final Commision com = new Commision(user, asker);
|
||||||
this.commisionService.save(com);
|
this.commisionService.save(com);
|
||||||
|
|
||||||
groups.stream().forEach((groupId) -> {
|
groups.stream().forEach((groupId) -> {
|
||||||
@ -96,22 +103,78 @@ public class CommisionController extends TokenBasedController {
|
|||||||
|
|
||||||
@GetMapping("/user")
|
@GetMapping("/user")
|
||||||
@ApiOperation("Return list of user all commisions (history of schedules)")
|
@ApiOperation("Return list of user all commisions (history of schedules)")
|
||||||
public ResponseEntity<List<CommisionResponse>> getAlCommisions() throws UserNotFoundException {
|
public ResponseEntity<List<? extends CommisionResponse>> getAlCommisions(
|
||||||
|
@RequestParam(name = "groups", defaultValue = "false") @ApiParam(value = "Boolean if we want to display wiht commision's group ids") Boolean groups)
|
||||||
|
throws UserNotFoundException {
|
||||||
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
|
User user = this.getCurrentUser().orElseThrow(() -> new NullPointerException());
|
||||||
List<CommisionResponse> result = CommisionResponseMappers
|
|
||||||
.mapToResponse(this.commisionService.getUsersCommisions(user));
|
List<? extends CommisionResponse> result;
|
||||||
|
|
||||||
|
if (!groups) {
|
||||||
|
result = CommisionResponseMappers.mapToResponse(this.commisionService.getUsersCommisions(user));
|
||||||
|
} else {
|
||||||
|
result = CommisionResponseMappers
|
||||||
|
.mapToResponseWithGroups(this.commisionService.getUsersCommisions(user));
|
||||||
|
}
|
||||||
|
|
||||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/user/schedule")
|
||||||
|
@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);
|
||||||
|
|
||||||
|
if (com.isPresent()) {
|
||||||
|
List<Assignment> respone = this.assignmentService.getCommisionAssignments(com.get());
|
||||||
|
final HashMap<Long, Integer> ammounts = this.groupServcicxe
|
||||||
|
.getTakenPlacesOfAssignments(respone);
|
||||||
|
return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone, ammounts),
|
||||||
|
HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||||
@GetMapping("/user/{id}")
|
@GetMapping("/user/{id}")
|
||||||
@ApiOperation("Return list of commisions for given user. To be able to access this data u need to provide DEANERY token")
|
@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)
|
public ResponseEntity<List<? extends CommisionResponse>> getCommision(@PathVariable(name = "id") Long userId,
|
||||||
|
@RequestParam(name = "groups", defaultValue = "false") @ApiParam(value = "Boolean if we want to display wiht commision's group ids") Boolean groups)
|
||||||
throws UserNotFoundException {
|
throws UserNotFoundException {
|
||||||
User user = this.userService.getById(userId).orElseThrow(() -> new NullPointerException());
|
User user = this.userService.getById(userId).orElseThrow(() -> new NullPointerException());
|
||||||
List<CommisionResponse> result = CommisionResponseMappers
|
List<? extends CommisionResponse> result;
|
||||||
.mapToResponse(this.commisionService.getUsersCommisions(user));
|
|
||||||
|
if (!groups) {
|
||||||
|
result = CommisionResponseMappers.mapToResponse(this.commisionService.getUsersCommisions(user));
|
||||||
|
} else {
|
||||||
|
result = CommisionResponseMappers
|
||||||
|
.mapToResponseWithGroups(this.commisionService.getUsersCommisions(user));
|
||||||
|
}
|
||||||
|
|
||||||
return new ResponseEntity<>(result, HttpStatus.OK);
|
return new ResponseEntity<>(result, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||||
|
@GetMapping("/user/{id}/schedule")
|
||||||
|
@ApiOperation(value = "Return given user current assignemts (from newest commision). DEANERY Token needs to be provided.")
|
||||||
|
public ResponseEntity<List<AssignmentResponse>> getCurrentAssignmentsDeanery(
|
||||||
|
@PathVariable(name = "id") Long userId) throws Exception {
|
||||||
|
User user = this.userService.getById(userId).orElseThrow(() -> new NullPointerException());
|
||||||
|
|
||||||
|
if (user.getRole() == UserRoles.DEANERY) {
|
||||||
|
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<Commision> com = this.commisionService.getNewestCommision(user);
|
||||||
|
|
||||||
|
if (com.isPresent()) {
|
||||||
|
List<Assignment> respone = this.assignmentService.getCommisionAssignments(com.get());
|
||||||
|
return new ResponseEntity<>(AssignmentResponseMappers.mapToResponse(respone), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResponseEntity<>(new ArrayList<>(), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,24 @@ import org.springframework.web.bind.annotation.CrossOrigin;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import com.plannaplan.App;
|
import com.plannaplan.App;
|
||||||
|
import com.plannaplan.entities.User;
|
||||||
import com.plannaplan.models.ConfigData;
|
import com.plannaplan.models.ConfigData;
|
||||||
|
import com.plannaplan.models.TourData;
|
||||||
|
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.ConfiguratorService;
|
import com.plannaplan.services.ConfiguratorService;
|
||||||
|
import com.plannaplan.services.UserService;
|
||||||
|
import com.plannaplan.types.UserRoles;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@ -30,16 +42,39 @@ import io.swagger.annotations.ApiParam;
|
|||||||
@Api(tags = { "ConfigController" }, value = "ConfigController", description = "All endpoints to configure an app")
|
@Api(tags = { "ConfigController" }, value = "ConfigController", description = "All endpoints to configure an app")
|
||||||
public class ConfigController {
|
public class ConfigController {
|
||||||
|
|
||||||
|
@Value("${plannaplan.frontendUrl}")
|
||||||
|
private String serviceUrl;
|
||||||
|
|
||||||
|
@Value("${plannaplan.dev}")
|
||||||
|
private boolean isDev;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ConfiguratorService contrl;
|
private ConfiguratorService contrl;
|
||||||
|
|
||||||
@PostMapping("/config")
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path = "/config", consumes = { "multipart/form-data" })
|
||||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
@ApiOperation("Imports data to system. To call you need to provide ADMIN token")
|
@ApiOperation("Imports data to system. To call you need to provide ADMIN token")
|
||||||
public ResponseEntity<String> configApp(
|
public ResponseEntity<String> configApp(
|
||||||
@RequestParam("file") @ApiParam(value = "file .xlsx that contains courses and groups with apoinnted rules") MultipartFile file) {
|
@RequestParam("file") @ApiParam(value = "file .xlsx that contains courses and groups with apoinnted rules") MultipartFile file,
|
||||||
|
@RequestParam("firstTourBegin") @DateTimeFormat(pattern = "dd.MM.yyyy") @ApiParam(value = "Date when first tour begin in format dd.MM.yyyy") Date firstTourBegin,
|
||||||
|
@RequestParam("firstTourEnd") @DateTimeFormat(pattern = "dd.MM.yyyy") @ApiParam(value = "Date when first tour ends in format dd.MM.yyyy") Date firstTourEnd,
|
||||||
|
@RequestParam("secondTourBegin") @DateTimeFormat(pattern = "dd.MM.yyyy") @ApiParam(value = "Date when second tour begin in format dd.MM.yyyy") Date secondTourBegin,
|
||||||
|
@RequestParam("secondTourEnd") @DateTimeFormat(pattern = "dd.MM.yyyy") @ApiParam(value = "Date when second tour ends in format dd.MM.yyyy") Date secondTourEnd) {
|
||||||
try {
|
try {
|
||||||
final ConfigData data = new ConfigData(null, null, file.getInputStream());
|
if (!(firstTourBegin.before(firstTourEnd)
|
||||||
|
&& (firstTourEnd.before(secondTourBegin) || firstTourEnd.equals(secondTourBegin))
|
||||||
|
&& secondTourBegin.before(secondTourEnd))) {
|
||||||
|
return new ResponseEntity<>("Bad dates", HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
final TourData firstTour = new TourData(firstTourBegin, firstTourEnd);
|
||||||
|
final TourData secondTour = new TourData(secondTourBegin, secondTourEnd);
|
||||||
|
|
||||||
|
final ConfigData data = new ConfigData(firstTour, secondTour, file.getInputStream());
|
||||||
this.contrl.config(data);
|
this.contrl.config(data);
|
||||||
return new ResponseEntity<>("Sucess", HttpStatus.OK);
|
return new ResponseEntity<>("Sucess", HttpStatus.OK);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -47,4 +82,63 @@ public class ConfigController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path = "/config/tours")
|
||||||
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
|
@ApiOperation("Set tours dates. To call you need to provide ADMIN token")
|
||||||
|
public ResponseEntity<String> configToursApp(
|
||||||
|
@RequestParam("firstTourBegin") @DateTimeFormat(pattern = "dd.MM.yyyy") @ApiParam(value = "Date when first tour begin in format dd.MM.yyyy") Date firstTourBegin,
|
||||||
|
@RequestParam("firstTourEnd") @DateTimeFormat(pattern = "dd.MM.yyyy") @ApiParam(value = "Date when first tour ends in format dd.MM.yyyy") Date firstTourEnd,
|
||||||
|
@RequestParam("secondTourBegin") @DateTimeFormat(pattern = "dd.MM.yyyy") @ApiParam(value = "Date when second tour begin in format dd.MM.yyyy") Date secondTourBegin,
|
||||||
|
@RequestParam("secondTourEnd") @DateTimeFormat(pattern = "dd.MM.yyyy") @ApiParam(value = "Date when second tour ends in format dd.MM.yyyy") Date secondTourEnd) {
|
||||||
|
if (!(firstTourBegin.before(firstTourEnd)
|
||||||
|
&& (firstTourEnd.before(secondTourBegin) || firstTourEnd.equals(secondTourBegin))
|
||||||
|
&& secondTourBegin.before(secondTourEnd))) {
|
||||||
|
return new ResponseEntity<>("Bad dates", HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
final TourData firstTour = new TourData(firstTourBegin, firstTourEnd);
|
||||||
|
final TourData secondTour = new TourData(secondTourBegin, secondTourEnd);
|
||||||
|
|
||||||
|
this.contrl.saveTours(firstTour, secondTour);
|
||||||
|
return new ResponseEntity<>("Sucess", HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(path = "/config/courses", consumes = { "multipart/form-data" })
|
||||||
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
|
@ApiOperation("Imports data to system. To call you need to provide ADMIN token")
|
||||||
|
public ResponseEntity<String> configAppChangeCources(
|
||||||
|
@RequestParam("file") @ApiParam(value = "file .xlsx that contains courses and groups with apoinnted rules") MultipartFile file)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
this.contrl.importCoursesStream(file.getInputStream());
|
||||||
|
return new ResponseEntity<>("Sucess", HttpStatus.OK);
|
||||||
|
} catch (IOException e) {
|
||||||
|
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(path = "/admin/init")
|
||||||
|
@ApiOperation("It can be run only in the initialization of the application. It will create admin user to manage the application.")
|
||||||
|
public ResponseEntity<String> initAdmin(@RequestParam("ticket") @ApiParam(value = "Ticket for validation.") String ticket){
|
||||||
|
if (this.userService.adminExists()){
|
||||||
|
return new ResponseEntity<>("Admin had been already created.", HttpStatus.FORBIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
final CasValidator validator = isDev ? new DefaultUAMCasValidator(serviceUrl, ticket)
|
||||||
|
: new CustomUAMCasValidator(serviceUrl, ticket);
|
||||||
|
|
||||||
|
try {
|
||||||
|
final CasUserIdentity casUserIdentity = validator.validate();
|
||||||
|
final String usosId = casUserIdentity.getUsosId();
|
||||||
|
final String authority = casUserIdentity.getEmail();
|
||||||
|
this.userService.save(new User(null, null, authority, usosId, UserRoles.ADMIN));
|
||||||
|
|
||||||
|
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||||
|
} catch (CasValidationExcepiton e) {
|
||||||
|
return new ResponseEntity<>("CAS validation failed", HttpStatus.UNAUTHORIZED);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return new ResponseEntity<>("Internal Server Error", HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -9,7 +9,7 @@ import com.plannaplan.entities.Course;
|
|||||||
import com.plannaplan.responses.mappers.CoursesResponseMappers;
|
import com.plannaplan.responses.mappers.CoursesResponseMappers;
|
||||||
import com.plannaplan.responses.models.CoursesDefaultResponse;
|
import com.plannaplan.responses.models.CoursesDefaultResponse;
|
||||||
import com.plannaplan.responses.models.CoursesWithGroupsResponse;
|
import com.plannaplan.responses.models.CoursesWithGroupsResponse;
|
||||||
import com.plannaplan.responses.models.GroupDefaultResponse;
|
import com.plannaplan.responses.models.GroupWithCapacityResponse;
|
||||||
import com.plannaplan.services.CourseService;
|
import com.plannaplan.services.CourseService;
|
||||||
import com.plannaplan.services.GroupService;
|
import com.plannaplan.services.GroupService;
|
||||||
import com.plannaplan.types.GroupType;
|
import com.plannaplan.types.GroupType;
|
||||||
@ -53,16 +53,16 @@ public class CoursesController {
|
|||||||
final List<CoursesWithGroupsResponse> response = new ArrayList<>();
|
final List<CoursesWithGroupsResponse> response = new ArrayList<>();
|
||||||
|
|
||||||
courses.forEach(course -> {
|
courses.forEach(course -> {
|
||||||
final List<GroupDefaultResponse> lectures = new ArrayList<>();
|
final List<GroupWithCapacityResponse> lectures = new ArrayList<>();
|
||||||
final List<GroupDefaultResponse> classes = new ArrayList<>();
|
final List<GroupWithCapacityResponse> classes = new ArrayList<>();
|
||||||
|
|
||||||
final HashMap<Long, Integer> ammounts = this.groupService.getTakenPlaces(course.getGroups());
|
final HashMap<Long, Integer> ammounts = this.groupService.getTakenPlaces(course.getGroups());
|
||||||
|
|
||||||
course.getGroups().stream().forEach(group -> {
|
course.getGroups().stream().forEach(group -> {
|
||||||
if (group.getType() == GroupType.CLASS) {
|
if (group.getType() == GroupType.CLASS) {
|
||||||
classes.add(new GroupDefaultResponse(group, ammounts.get(group.getId())));
|
classes.add(new GroupWithCapacityResponse(group, ammounts.get(group.getId())));
|
||||||
} else {
|
} else {
|
||||||
lectures.add(new GroupDefaultResponse(group, ammounts.get(group.getId())));
|
lectures.add(new GroupWithCapacityResponse(group, ammounts.get(group.getId())));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package com.plannaplan.controllers;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.plannaplan.App;
|
import com.plannaplan.App;
|
||||||
import com.plannaplan.entities.Groups;
|
import com.plannaplan.entities.Groups;
|
||||||
@ -13,9 +14,11 @@ import com.plannaplan.services.GroupService;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@ -57,4 +60,20 @@ public class GroupController {
|
|||||||
}
|
}
|
||||||
return new ResponseEntity<>(GroupsMappers.mapToGetCourseGroupsDefaultResponse(groups), HttpStatus.OK);
|
return new ResponseEntity<>(GroupsMappers.mapToGetCourseGroupsDefaultResponse(groups), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}/capacity")
|
||||||
|
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||||
|
@ApiOperation(value = "Change capacity of given group. You need to provide DEANERY token to be ale to change capacity")
|
||||||
|
public ResponseEntity<String> updateCapacity(
|
||||||
|
@PathVariable(name = "id", required = true) @ApiParam(value = "id of group to change capacity") Long id,
|
||||||
|
@RequestParam(name = "newcapacity", required = true) Integer newcapacity) {
|
||||||
|
final Optional<Groups> group = this.groupService.getGroupById(id);
|
||||||
|
if (group.isEmpty()) {
|
||||||
|
return new ResponseEntity<>("Given group doens't exist", HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
final Groups gr = group.get();
|
||||||
|
gr.setCapacity(newcapacity);
|
||||||
|
this.groupService.save(gr);
|
||||||
|
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,5 +1,8 @@
|
|||||||
package com.plannaplan.controllers;
|
package com.plannaplan.controllers;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.plannaplan.entities.User;
|
import com.plannaplan.entities.User;
|
||||||
import com.plannaplan.exceptions.UserNotFoundException;
|
import com.plannaplan.exceptions.UserNotFoundException;
|
||||||
import com.plannaplan.responses.models.TokenResponse;
|
import com.plannaplan.responses.models.TokenResponse;
|
||||||
@ -59,6 +62,21 @@ public class TokenController {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/token/refresh")
|
||||||
|
@ApiOperation(value = "Endpoint to access new token based on refresh token. It's needed when request with provided token fail with code 403")
|
||||||
|
public ResponseEntity<TokenResponse> getRefreshToken(
|
||||||
|
@RequestParam("refreshToken") @ApiParam(value = "Refresh token obtained in /token request") final String refreshToken)
|
||||||
|
throws NullPointerException {
|
||||||
|
Optional<User> userResult = this.userService.getUserByRefreshToken(refreshToken);
|
||||||
|
if (userResult.isEmpty()) {
|
||||||
|
return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
User user = userResult.get();
|
||||||
|
user.setToken(UUID.randomUUID().toString());
|
||||||
|
user = this.userService.save(user);
|
||||||
|
return new ResponseEntity<>(new TokenResponse(user), HttpStatus.OK);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package com.plannaplan.controllers;
|
package com.plannaplan.controllers;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.plannaplan.App;
|
import com.plannaplan.App;
|
||||||
import com.plannaplan.entities.User;
|
import com.plannaplan.entities.User;
|
||||||
import com.plannaplan.responses.mappers.UserResponseMappers;
|
import com.plannaplan.responses.mappers.UserResponseMappers;
|
||||||
import com.plannaplan.responses.models.UserResponse;
|
import com.plannaplan.responses.models.UserResponse;
|
||||||
import com.plannaplan.services.UserService;
|
import com.plannaplan.services.UserService;
|
||||||
|
import com.plannaplan.types.UserRoles;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -21,6 +23,7 @@ import io.swagger.annotations.ApiOperation;
|
|||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
@ -47,8 +50,30 @@ public class UsersController {
|
|||||||
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
@PreAuthorize("hasRole('ROLE_DEANERY')")
|
||||||
@ApiOperation(value = "Gets all students. You need token with DEANERY role to call this")
|
@ApiOperation(value = "Gets all students. You need token with DEANERY role to call this")
|
||||||
public ResponseEntity<List<UserResponse>> getAllStudents() {
|
public ResponseEntity<List<UserResponse>> getAllStudents() {
|
||||||
final List<User> searches = this.userService.searchForStudents("");
|
final List<User> searches = this.userService.getAllStudents();
|
||||||
final List<UserResponse> response = UserResponseMappers.mapToDefaultResponse(searches);
|
final List<UserResponse> response = UserResponseMappers.mapToDefaultResponse(searches);
|
||||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(path = "/admin")
|
||||||
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
|
@ApiOperation(value = "Adds new admin user.")
|
||||||
|
public ResponseEntity<String> addAdmin(@RequestParam("authority") @ApiParam(value = "USOS ID or E-mail. If user does not exist it should be USOS ID") String authority) {
|
||||||
|
final Optional<User> userResponse = this.userService.getByAuthority(authority);
|
||||||
|
final User user = userResponse.orElseGet(() -> new User(null, null, null, authority, UserRoles.ADMIN));
|
||||||
|
user.setRole(UserRoles.ADMIN);
|
||||||
|
this.userService.save(user);
|
||||||
|
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(path = "/deanery")
|
||||||
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
|
@ApiOperation(value = "Adds new deanery user.")
|
||||||
|
public ResponseEntity<String> addDeanery(@RequestParam("authority") @ApiParam(value = "USOS ID or E-mail. If user does not exist it should be USOS ID") String authority) {
|
||||||
|
final Optional<User> userResponse = this.userService.getByAuthority(authority);
|
||||||
|
final User user = userResponse.orElseGet(() -> new User(null, null, null, authority, UserRoles.DEANERY));
|
||||||
|
user.setRole(UserRoles.DEANERY);
|
||||||
|
this.userService.save(user);
|
||||||
|
return new ResponseEntity<>("Success", HttpStatus.OK);
|
||||||
|
}
|
||||||
}
|
}
|
@ -14,6 +14,11 @@ import com.plannaplan.types.GroupType;
|
|||||||
public class AssignmentResponseMappers {
|
public class AssignmentResponseMappers {
|
||||||
|
|
||||||
public static final List<AssignmentResponse> mapToResponse(List<Assignment> assignments) {
|
public static final List<AssignmentResponse> mapToResponse(List<Assignment> assignments) {
|
||||||
|
return mapToResponse(assignments, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final List<AssignmentResponse> mapToResponse(List<Assignment> assignments,
|
||||||
|
HashMap<Long, Integer> ammounts) {
|
||||||
List<AssignmentResponse> response = new ArrayList<>();
|
List<AssignmentResponse> response = new ArrayList<>();
|
||||||
HashMap<Course, List<Groups>> courses = new HashMap<>();
|
HashMap<Course, List<Groups>> courses = new HashMap<>();
|
||||||
assignments.stream().forEach((Assignment assignment) -> {
|
assignments.stream().forEach((Assignment assignment) -> {
|
||||||
@ -29,14 +34,23 @@ public class AssignmentResponseMappers {
|
|||||||
final Course course = entry.getKey();
|
final Course course = entry.getKey();
|
||||||
final List<Groups> courseGroups = entry.getValue();
|
final List<Groups> courseGroups = entry.getValue();
|
||||||
if (courseGroups.size() == 1) {
|
if (courseGroups.size() == 1) {
|
||||||
|
if (ammounts != null) {
|
||||||
|
response.add(new AssignmentResponse(course, courseGroups.get(0), ammounts));
|
||||||
|
} else {
|
||||||
response.add(new AssignmentResponse(course, courseGroups.get(0)));
|
response.add(new AssignmentResponse(course, courseGroups.get(0)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (courseGroups.size() == 2) {
|
if (courseGroups.size() == 2) {
|
||||||
final Groups lecture = courseGroups.stream().filter(o -> o.getType() == GroupType.LECTURE).findFirst()
|
final Groups lecture = courseGroups.stream().filter(o -> o.getType() == GroupType.LECTURE).findFirst()
|
||||||
.get();
|
.get();
|
||||||
final Groups classes = courseGroups.stream().filter(o -> o.getType() == GroupType.CLASS).findFirst()
|
final Groups classes = courseGroups.stream().filter(o -> o.getType() == GroupType.CLASS).findFirst()
|
||||||
.get();
|
.get();
|
||||||
|
|
||||||
|
if (ammounts != null) {
|
||||||
|
response.add(new AssignmentResponse(course, lecture, classes, ammounts));
|
||||||
|
} else {
|
||||||
response.add(new AssignmentResponse(course, lecture, classes));
|
response.add(new AssignmentResponse(course, lecture, classes));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,15 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import com.plannaplan.entities.Commision;
|
import com.plannaplan.entities.Commision;
|
||||||
import com.plannaplan.responses.models.CommisionResponse;
|
import com.plannaplan.responses.models.CommisionResponse;
|
||||||
|
import com.plannaplan.responses.models.CommisionWithGroupsResponse;
|
||||||
|
|
||||||
public class CommisionResponseMappers {
|
public class CommisionResponseMappers {
|
||||||
public static final List<CommisionResponse> mapToResponse(List<Commision> commisions) {
|
public static final List<CommisionResponse> mapToResponse(List<Commision> commisions) {
|
||||||
return commisions.stream().filter(Objects::nonNull).map(CommisionResponse::new).collect(Collectors.toList());
|
return commisions.stream().filter(Objects::nonNull).map(CommisionResponse::new).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final List<CommisionWithGroupsResponse> mapToResponseWithGroups(List<Commision> commisions) {
|
||||||
|
return commisions.stream().filter(Objects::nonNull).map(CommisionWithGroupsResponse::new)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.plannaplan.responses.models;
|
package com.plannaplan.responses.models;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import com.plannaplan.entities.Course;
|
import com.plannaplan.entities.Course;
|
||||||
import com.plannaplan.entities.Groups;
|
import com.plannaplan.entities.Groups;
|
||||||
import com.plannaplan.types.GroupType;
|
import com.plannaplan.types.GroupType;
|
||||||
@ -20,11 +22,23 @@ public class AssignmentResponse {
|
|||||||
this.classes = classes == null ? null : new GroupWithCapacityResponse(classes);
|
this.classes = classes == null ? null : new GroupWithCapacityResponse(classes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AssignmentResponse(Course course, Groups lecture, Groups classes, HashMap<Long, Integer> ammounts) {
|
||||||
|
this.id = course.getId();
|
||||||
|
this.name = course.getName();
|
||||||
|
this.lecture = lecture == null ? null : new GroupWithCapacityResponse(lecture, ammounts.get(lecture.getId()));
|
||||||
|
this.classes = classes == null ? null : new GroupWithCapacityResponse(classes, ammounts.get(classes.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
public AssignmentResponse(Course course, Groups group) {
|
public AssignmentResponse(Course course, Groups group) {
|
||||||
this(course, group.getType() == GroupType.LECTURE ? group : null,
|
this(course, group.getType() == GroupType.LECTURE ? group : null,
|
||||||
group.getType() == GroupType.CLASS ? group : null);
|
group.getType() == GroupType.CLASS ? group : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AssignmentResponse(Course course, Groups group, HashMap<Long, Integer> ammounts) {
|
||||||
|
this(course, group.getType() == GroupType.LECTURE ? group : null,
|
||||||
|
group.getType() == GroupType.CLASS ? group : null, ammounts);
|
||||||
|
}
|
||||||
|
|
||||||
public GroupWithCapacityResponse getLecture() {
|
public GroupWithCapacityResponse getLecture() {
|
||||||
return this.lecture;
|
return this.lecture;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.plannaplan.responses.models;
|
package com.plannaplan.responses.models;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
|
|
||||||
import com.plannaplan.entities.Commision;
|
import com.plannaplan.entities.Commision;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
@ -12,15 +10,32 @@ public class CommisionResponse {
|
|||||||
@ApiModelProperty(value = "ID created by database")
|
@ApiModelProperty(value = "ID created by database")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "ID of user that commision belongs to")
|
||||||
|
private UserResponse owner;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "ID of user that created commision")
|
||||||
|
private UserResponse commiter;
|
||||||
|
|
||||||
@ApiModelProperty(value = "Timestamp where the user commit the commision")
|
@ApiModelProperty(value = "Timestamp where the user commit the commision")
|
||||||
private Timestamp commisionDate;
|
private String commisionDate;
|
||||||
|
|
||||||
public CommisionResponse(Commision commision) {
|
public CommisionResponse(Commision commision) {
|
||||||
this.id = commision.getId();
|
this.id = commision.getId();
|
||||||
this.commisionDate = commision.getCommisionDate();
|
this.commisionDate = commision.getCommisionDate().toString();
|
||||||
|
this.owner = commision.getCommisionOwner() != null ? new UserResponse(commision.getCommisionOwner()) : null;
|
||||||
|
this.commiter = commision.getCommisionCommiter() != null ? new UserResponse(commision.getCommisionCommiter())
|
||||||
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Timestamp getCommisionDate() {
|
public UserResponse getCommiter() {
|
||||||
|
return commiter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserResponse getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCommisionDate() {
|
||||||
return commisionDate;
|
return commisionDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
36
restservice/src/main/java/com/plannaplan/responses/models/CommisionWithGroupsResponse.java
Executable file
36
restservice/src/main/java/com/plannaplan/responses/models/CommisionWithGroupsResponse.java
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
package com.plannaplan.responses.models;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.Assignment;
|
||||||
|
import com.plannaplan.entities.Commision;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
@ApiModel(description = "Response shows information about commision and its groups.", value = "CommisionWithGroupsResponse")
|
||||||
|
public class CommisionWithGroupsResponse extends CommisionResponse {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "List of groups ids in databse that belongs to commision")
|
||||||
|
private List<Long> groups;
|
||||||
|
|
||||||
|
public CommisionWithGroupsResponse(Commision commision) {
|
||||||
|
super(commision);
|
||||||
|
this.groups = commision.getAssignments().stream().filter(Objects::nonNull)
|
||||||
|
.map(new Function<Assignment, Long>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long apply(Assignment arg0) {
|
||||||
|
return arg0.getGroup().getId();
|
||||||
|
}
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Long> getGroups() {
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -12,32 +12,32 @@ import io.swagger.annotations.ApiModel;
|
|||||||
@ApiModel(description = "Response shows information about groups to given course.", value = "CoursesWithGroupsResponse")
|
@ApiModel(description = "Response shows information about groups to given course.", value = "CoursesWithGroupsResponse")
|
||||||
public class CoursesWithGroupsResponse extends CoursesResponse {
|
public class CoursesWithGroupsResponse extends CoursesResponse {
|
||||||
|
|
||||||
private List<GroupDefaultResponse> lectures = new ArrayList<>();
|
private List<GroupWithCapacityResponse> lectures = new ArrayList<>();
|
||||||
private List<GroupDefaultResponse> classes = new ArrayList<>();
|
private List<GroupWithCapacityResponse> classes = new ArrayList<>();
|
||||||
|
|
||||||
public CoursesWithGroupsResponse(Course course) {
|
public CoursesWithGroupsResponse(Course course) {
|
||||||
super(course);
|
super(course);
|
||||||
course.getGroups().stream().forEach(group -> {
|
course.getGroups().stream().forEach(group -> {
|
||||||
if (group.getType() == GroupType.CLASS) {
|
if (group.getType() == GroupType.CLASS) {
|
||||||
this.classes.add(new GroupDefaultResponse(group));
|
this.classes.add(new GroupWithCapacityResponse(group));
|
||||||
} else {
|
} else {
|
||||||
this.lectures.add(new GroupDefaultResponse(group));
|
this.lectures.add(new GroupWithCapacityResponse(group));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public CoursesWithGroupsResponse(Course course, List<GroupDefaultResponse> lectures,
|
public CoursesWithGroupsResponse(Course course, List<GroupWithCapacityResponse> lectures,
|
||||||
List<GroupDefaultResponse> classes) {
|
List<GroupWithCapacityResponse> classes) {
|
||||||
super(course);
|
super(course);
|
||||||
this.lectures = lectures;
|
this.lectures = lectures;
|
||||||
this.classes = classes;
|
this.classes = classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GroupDefaultResponse> getClasses() {
|
public List<GroupWithCapacityResponse> getClasses() {
|
||||||
return this.classes;
|
return this.classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GroupDefaultResponse> getLectures() {
|
public List<GroupWithCapacityResponse> getLectures() {
|
||||||
return this.lectures;
|
return this.lectures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,9 @@ public class GroupDefaultResponse {
|
|||||||
@ApiModelProperty(value = "Value shows time when the course takes.")
|
@ApiModelProperty(value = "Value shows time when the course takes.")
|
||||||
private String time;
|
private String time;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "Value shows time when the course ends.")
|
||||||
|
private String endTime;
|
||||||
|
|
||||||
@ApiModelProperty(value = "Value shows degree, name and surname.")
|
@ApiModelProperty(value = "Value shows degree, name and surname.")
|
||||||
private String lecturer;
|
private String lecturer;
|
||||||
|
|
||||||
@ -37,6 +40,7 @@ public class GroupDefaultResponse {
|
|||||||
this.id = group.getId() != null ? group.getId() : null;
|
this.id = group.getId() != null ? group.getId() : null;
|
||||||
this.day = group.getDay() != null ? group.getDay().label : -1;
|
this.day = group.getDay() != null ? group.getDay().label : -1;
|
||||||
this.time = group.getTimeString() != null ? group.getTimeString() : "";
|
this.time = group.getTimeString() != null ? group.getTimeString() : "";
|
||||||
|
this.endTime = group.getEndTimeString() != null ? group.getEndTimeString() : "";
|
||||||
this.lecturer = group.getLecturer() != null ? group.getLecturer().toString() : "";
|
this.lecturer = group.getLecturer() != null ? group.getLecturer().toString() : "";
|
||||||
this.room = group.getRoom() != null ? group.getRoom() : "";
|
this.room = group.getRoom() != null ? group.getRoom() : "";
|
||||||
this.type = group.getType() != null ? group.getType() : null;
|
this.type = group.getType() != null ? group.getType() : null;
|
||||||
@ -67,6 +71,10 @@ public class GroupDefaultResponse {
|
|||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getEndTime() {
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
public int getDay() {
|
public int getDay() {
|
||||||
return day;
|
return day;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ import io.swagger.annotations.ApiModelProperty;
|
|||||||
public class TokenResponse {
|
public class TokenResponse {
|
||||||
@ApiModelProperty(value = "user token used to verify requests")
|
@ApiModelProperty(value = "user token used to verify requests")
|
||||||
private String token;
|
private String token;
|
||||||
|
@ApiModelProperty(value = "user token needed to refresh")
|
||||||
|
private String refreshToken;
|
||||||
@ApiModelProperty(value = "user id in database")
|
@ApiModelProperty(value = "user id in database")
|
||||||
private Long id;
|
private Long id;
|
||||||
@ApiModelProperty(value = "user app role")
|
@ApiModelProperty(value = "user app role")
|
||||||
@ -21,6 +23,7 @@ public class TokenResponse {
|
|||||||
this.authorityRole = user.getRole().toString();
|
this.authorityRole = user.getRole().toString();
|
||||||
this.email = user.getEmail();
|
this.email = user.getEmail();
|
||||||
this.token = user.getToken();
|
this.token = user.getToken();
|
||||||
|
this.refreshToken = user.getRefreshToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEmail() {
|
public String getEmail() {
|
||||||
@ -39,4 +42,8 @@ public class TokenResponse {
|
|||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRefreshToken() {
|
||||||
|
return this.refreshToken;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ public class UserResponse {
|
|||||||
|
|
||||||
public UserResponse(User user) {
|
public UserResponse(User user) {
|
||||||
this.id = user.getId();
|
this.id = user.getId();
|
||||||
this.name = user.getName();
|
this.name = user.getName() != null ? user.getName() : "";
|
||||||
this.surname = user.getSurname();
|
this.surname = user.getSurname() != null ? user.getSurname() : "";
|
||||||
this.email = user.getEmail();
|
this.email = user.getEmail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,9 +37,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure(final WebSecurity webSecurity) {
|
public void configure(final WebSecurity webSecurity) {
|
||||||
webSecurity.ignoring().antMatchers("/token**").antMatchers("/api/v1/courses/all")
|
webSecurity.ignoring().antMatchers("/token**").antMatchers("/token/refresh**")
|
||||||
.antMatchers("/api/v1/groups/course/{id}").antMatchers("/v2/api-docs", "/configuration/ui",
|
.antMatchers("/api/v1/courses/all").antMatchers("/api/v1/groups/course/{id}")
|
||||||
"/swagger-resources/**", "/configuration/security", "/swagger-ui.html", "/webjars/**");
|
.antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources/**", "/configuration/security",
|
||||||
|
"/swagger-ui.html", "/webjars/**");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,6 +9,11 @@
|
|||||||
"name": "plannaplan.frontendUrl",
|
"name": "plannaplan.frontendUrl",
|
||||||
"type": "java.lang.String",
|
"type": "java.lang.String",
|
||||||
"description": "Url where frontend app is located"
|
"description": "Url where frontend app is located"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "plannaplan.email",
|
||||||
|
"type": "java.lang.String",
|
||||||
|
"description": "Email from which app sends message"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -8,6 +8,14 @@ spring.jpa.hibernate.ddl-auto=create-drop
|
|||||||
spring.jackson.serialization.fail-on-empty-beans=false
|
spring.jackson.serialization.fail-on-empty-beans=false
|
||||||
spring.main.allow-bean-definition-overriding=true
|
spring.main.allow-bean-definition-overriding=true
|
||||||
spring.jackson.default-property-inclusion = NON_NULL
|
spring.jackson.default-property-inclusion = NON_NULL
|
||||||
|
spring.mail.host=localhost
|
||||||
|
spring.mail.port=1025
|
||||||
|
# spring.mail.username=<login user to smtp server>
|
||||||
|
# spring.mail.password=<login password to smtp server>
|
||||||
|
spring.mail.properties.mail.smtp.auth=false
|
||||||
|
spring.mail.properties.mail.smtp.starttls.enable=false
|
||||||
|
logging.level.io.swagger.models.parameters.AbstractSerializableParameter=ERROR
|
||||||
server.port=1285
|
server.port=1285
|
||||||
plannaplan.dev = true
|
plannaplan.dev = true
|
||||||
plannaplan.frontendUrl = http://localhost:3000
|
plannaplan.frontendUrl = http://localhost:3000
|
||||||
|
plannaplan.email = plannaplan.kontakt@gmail.com
|
@ -8,9 +8,16 @@ spring.jpa.hibernate.ddl-auto=update
|
|||||||
spring.jackson.serialization.fail-on-empty-beans=false
|
spring.jackson.serialization.fail-on-empty-beans=false
|
||||||
spring.main.allow-bean-definition-overriding=true
|
spring.main.allow-bean-definition-overriding=true
|
||||||
spring.jackson.default-property-inclusion = NON_NULL
|
spring.jackson.default-property-inclusion = NON_NULL
|
||||||
|
logging.level.io.swagger.models.parameters.AbstractSerializableParameter=ERROR
|
||||||
|
spring.mail.host=${PLANNAPLAN_EMAIL_HOST}
|
||||||
|
spring.mail.port=${PLANNAPLAN_EMAIL_PORT}
|
||||||
|
spring.mail.username=${PLANNAPLAN_EMAIL_USERNAME}
|
||||||
|
spring.mail.password=${PLANNAPLAN_EMAIL_PASSWORD}
|
||||||
|
spring.mail.properties.mail.smtp.auth=true
|
||||||
|
spring.mail.properties.mail.smtp.starttls.enable=true
|
||||||
server.port=1285
|
server.port=1285
|
||||||
|
|
||||||
|
plannaplan.email = ${PLANNAPLAN_EMAIL}
|
||||||
plannaplan.dev = false
|
plannaplan.dev = false
|
||||||
plannaplan.frontendUrl= https://wmi.plannaplan.pl
|
plannaplan.frontendUrl= https://wmi.plannaplan.pl
|
||||||
security.require-ssl=true
|
security.require-ssl=true
|
||||||
|
@ -43,6 +43,7 @@ public class CommisionControllerTest extends AbstractControllerTest {
|
|||||||
private static final String ADD_COMMISION_ENDPOINT = "/api/v1/commisions/user";
|
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_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
||||||
private static final String GET_SOMEONE_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
private static final String GET_SOMEONE_COMMISIONS_ENDPOINT = "/api/v1/commisions/user";
|
||||||
|
private static final String GET_USER_SCHEDULE_ENDPOINT = "/api/v1/commisions/user/schedule";
|
||||||
|
|
||||||
private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
|
private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(),
|
||||||
MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
|
MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
|
||||||
@ -190,6 +191,58 @@ public class CommisionControllerTest extends AbstractControllerTest {
|
|||||||
.header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError());
|
.header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturn4xxInScheduleEndpoint() throws Exception {
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(get(GET_USER_SCHEDULE_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnOkInScheduleEdnpoint() throws Exception {
|
||||||
|
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_USER_SCHEDULE_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnOkInScheduleEdnpointByDeanery() throws Exception {
|
||||||
|
this.checkUsers();
|
||||||
|
final User user = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
||||||
|
final User student = 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 + "/" + student.getId() + "/schedule").header("Authorization",
|
||||||
|
"Bearer " + token)).andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailInScheduleEdnpointByOtherStudent() throws Exception {
|
||||||
|
this.checkUsers();
|
||||||
|
final User student = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
||||||
|
final User otherStudent = this.service.checkForUser(TEST_COMMISIONS_OTHER_STUDENT_EMAIL, null);
|
||||||
|
final String token = this.service.login(student).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(get(GET_COMMISIONS_ENDPOINT + "/" + otherStudent.getId() + "/schedule").header("Authorization",
|
||||||
|
"Bearer " + token)).andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailInScheduleEdnpointByDeaneryDeaneryRelation() throws Exception {
|
||||||
|
this.checkUsers();
|
||||||
|
final User deanery = this.service.checkForUser(TEST_COMMISIONS_DEANERY_EMAIL, null);
|
||||||
|
final User otherDeanery = this.service.checkForUser(TEST_COMMISIONS_OTHER_DEANERY_EMAIL, null);
|
||||||
|
final String token = this.service.login(deanery).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(get(GET_COMMISIONS_ENDPOINT + "/" + otherDeanery.getId() + "/schedule").header("Authorization",
|
||||||
|
"Bearer " + token)).andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
private void checkUsers() {
|
private void checkUsers() {
|
||||||
if (CommisionControllerTest.user == null) {
|
if (CommisionControllerTest.user == null) {
|
||||||
CommisionControllerTest.user = new User(null, null, TEST_COMMISIONS_STUDENT_EMAIL, UserRoles.STUDENT);
|
CommisionControllerTest.user = new User(null, null, TEST_COMMISIONS_STUDENT_EMAIL, UserRoles.STUDENT);
|
||||||
|
@ -2,20 +2,29 @@ package com.plannaplan.controllers;
|
|||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.sql.Date;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.AppConfig;
|
||||||
import com.plannaplan.entities.User;
|
import com.plannaplan.entities.User;
|
||||||
|
import com.plannaplan.services.ConfiguratorService;
|
||||||
import com.plannaplan.services.UserService;
|
import com.plannaplan.services.UserService;
|
||||||
import com.plannaplan.types.UserRoles;
|
import com.plannaplan.types.UserRoles;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.mock.web.MockMultipartFile;
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext.MethodMode;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
@ -28,9 +37,18 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
|||||||
|
|
||||||
private static final String FILE_NAME = "Zajecia.xlsx";
|
private static final String FILE_NAME = "Zajecia.xlsx";
|
||||||
private static final String CONFIG_ENDPOINT = "/api/v1/configurator/config";
|
private static final String CONFIG_ENDPOINT = "/api/v1/configurator/config";
|
||||||
|
private static final String COURSE_ENDPOINT = "/api/v1/configurator/config/courses";
|
||||||
|
private static final String TOURS_ENDPOINT = "/api/v1/configurator/config/tours";
|
||||||
|
private static final String ADMIN_INIT_ENDPOINT = "/api/v1/configurator/admin/init";
|
||||||
|
private static final String FIRST_TOUR_START = "firstTourBegin";
|
||||||
|
private static final String FIRST_TOUR_END = "firstTourEnd";
|
||||||
|
private static final String SECOND_TOUR_START = "secondTourBegin";
|
||||||
|
private static final String SECOND_TOUR_END = "secondTourEnd";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService service;
|
private UserService service;
|
||||||
|
@Autowired
|
||||||
|
private ConfiguratorService configService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnNoAuthorized() throws Exception {
|
public void shouldReturnNoAuthorized() throws Exception {
|
||||||
@ -52,11 +70,40 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
|||||||
final String token = this.service.login(usr).getToken();
|
final String token = this.service.login(usr).getToken();
|
||||||
|
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).header("Authorization", "Bearer " + token))
|
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).param(FIRST_TOUR_START, "12.12.2020")
|
||||||
|
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||||
|
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||||
.andExpect(status().isOk());
|
.andExpect(status().isOk());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldInsertedDataBeSameInDatabase() throws Exception {
|
||||||
|
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(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).param(FIRST_TOUR_START, "12.12.2020")
|
||||||
|
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||||
|
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
|
||||||
|
final AppConfig config = this.configService.getCurrentConfig();
|
||||||
|
assertTrue(config.getFirstTourStart().compareTo(Date.valueOf("2020-12-12")) == 0,
|
||||||
|
"Date in database is wrong. Perhabs database has wrong timezone set.");
|
||||||
|
assertTrue(config.getFirstTourEnd().compareTo(Date.valueOf("2020-12-14")) == 0,
|
||||||
|
"Date in database is wrong. Perhabs database has wrong timezone set.");
|
||||||
|
assertTrue(config.getSecondTourStart().compareTo(Date.valueOf("2020-12-16")) == 0,
|
||||||
|
"Date in database is wrong. Perhabs database has wrong timezone set.");
|
||||||
|
assertTrue(config.getSecondTourEnd().compareTo(Date.valueOf("2020-12-20")) == 0,
|
||||||
|
"Date in database is wrong. Perhabs database has wrong timezone set.");
|
||||||
|
// yyyy-mm-dd
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnDenyNoAdminAuthorized() throws Exception {
|
public void shouldReturnDenyNoAdminAuthorized() throws Exception {
|
||||||
final String mail = "shouldReturnDenyNoAdminAuthorized@ConfigController.test";
|
final String mail = "shouldReturnDenyNoAdminAuthorized@ConfigController.test";
|
||||||
@ -72,4 +119,228 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailDueToWrongFirstTour() throws Exception {
|
||||||
|
final String mail = "shouldFailDueToWrongFirstTour@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(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).param(FIRST_TOUR_START, "12.12.2020")
|
||||||
|
.param(FIRST_TOUR_END, "12.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||||
|
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailDueToWrongSecondTour() throws Exception {
|
||||||
|
final String mail = "shouldFailDueToWrongSecondTour@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(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).param(FIRST_TOUR_START, "12.12.2020")
|
||||||
|
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||||
|
.param(SECOND_TOUR_END, "16.12.2020").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailDueToWrongBothTour() throws Exception {
|
||||||
|
final String mail = "shouldFailDueToWrongBothTour@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(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).param(FIRST_TOUR_START, "12.12.2020")
|
||||||
|
.param(FIRST_TOUR_END, "12.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||||
|
.param(SECOND_TOUR_END, "16.12.2020").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailDueToWrongTourTransition() throws Exception {
|
||||||
|
final String mail = "shouldFailDueToWrongTourTransition@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(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).param(FIRST_TOUR_START, "12.12.2020")
|
||||||
|
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "13.12.2020")
|
||||||
|
.param(SECOND_TOUR_END, "16.12.2020").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailDueToWrongDateFormat() throws Exception {
|
||||||
|
final String mail = "shouldFailDueToWrongDateFormat@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(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).param(FIRST_TOUR_START, "12.12.2020")
|
||||||
|
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||||
|
.param(SECOND_TOUR_END, "20/12/2020").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailDueToNoDate() throws Exception {
|
||||||
|
final String mail = "shouldFailDueToNoDate@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(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailDueToNoFile() throws Exception {
|
||||||
|
final String mail = "shouldFailDueToNoFile@ConfigController.test";
|
||||||
|
final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN));
|
||||||
|
|
||||||
|
final String token = this.service.login(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(multipart(CONFIG_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||||
|
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||||
|
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Ignore
|
||||||
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||||
|
public void shouldCreateAdminBecouseOfEmptyDatabase() throws Exception{
|
||||||
|
// have no idea how to make this test independent from user that run this
|
||||||
|
final String ticket = "";
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||||
|
mockMvc.perform(get(ADMIN_INIT_ENDPOINT).param("ticket", ticket)).andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailDueToExistingAdmin() throws Exception{
|
||||||
|
this.service.save(new User(null, null, "shouldFailDueToExistingAdmin@ConfigController.Test", UserRoles.ADMIN));
|
||||||
|
final String ticket = "hfewlhfjlewhipfqwehipqwef";
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||||
|
mockMvc.perform(get(ADMIN_INIT_ENDPOINT).param("ticket", ticket)).andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnOKAuthorizedForCourses() throws Exception {
|
||||||
|
final String mail = "shouldReturnOKAuthorizedForCourses@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(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(multipart(COURSE_ENDPOINT).file(file).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDenyForCoursesDueToWrongRole() throws Exception {
|
||||||
|
final String mail = "shouldReturnOKAuthorizedForCourses@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(COURSE_ENDPOINT).file(file).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldReturnOKAuthorizedForTours() throws Exception {
|
||||||
|
final String mail = "shouldReturnOKAuthorizedForTours@ConfigController.test";
|
||||||
|
final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN));
|
||||||
|
final String token = this.service.login(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||||
|
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||||
|
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailWithWrongSecondTour() throws Exception {
|
||||||
|
final String mail = "shouldFailToursWithWrongSecondTour@ConfigController.test";
|
||||||
|
final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN));
|
||||||
|
final String token = this.service.login(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||||
|
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||||
|
.param(SECOND_TOUR_END, "13.12.2020").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailWithWrongFirstTour() throws Exception {
|
||||||
|
final String mail = "shouldFailWithWrongFirstTour@ConfigController.test";
|
||||||
|
final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN));
|
||||||
|
final String token = this.service.login(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||||
|
.param(FIRST_TOUR_END, "10.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||||
|
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailWithWrongSecondTourBegin() throws Exception {
|
||||||
|
final String mail = "shouldFailWithWrongSecondTourBegin@ConfigController.test";
|
||||||
|
final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN));
|
||||||
|
final String token = this.service.login(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||||
|
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "13.12.2020")
|
||||||
|
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDenyForTours() throws Exception {
|
||||||
|
final String mail = "shouldDenyForTours@ConfigController.test";
|
||||||
|
final User usr = this.service.save(new User(null, null, mail, UserRoles.TEST_USER));
|
||||||
|
final String token = this.service.login(usr).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(TOURS_ENDPOINT).param(FIRST_TOUR_START, "12.12.2020")
|
||||||
|
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||||
|
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,6 +2,7 @@ package com.plannaplan.controllers;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
@ -9,7 +10,17 @@ import org.springframework.test.web.servlet.MockMvc;
|
|||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.Groups;
|
||||||
|
import com.plannaplan.entities.User;
|
||||||
|
import com.plannaplan.services.GroupService;
|
||||||
|
import com.plannaplan.services.UserService;
|
||||||
|
import com.plannaplan.types.UserRoles;
|
||||||
|
import com.plannaplan.types.WeekDay;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ -17,6 +28,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
|
|
||||||
public class GroupControllerTest extends AbstractControllerTest {
|
public class GroupControllerTest extends AbstractControllerTest {
|
||||||
private static final String GROUPS_BY_COURSE_ENDPOINT = "/api/v1/groups/course";
|
private static final String GROUPS_BY_COURSE_ENDPOINT = "/api/v1/groups/course";
|
||||||
|
private static final String UPDATE_GROUPS_ENDPOINT = "/api/v1/groups/521/capacity";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService service;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GroupService groupService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFailWithNoParaeter() throws Exception {
|
public void shouldFailWithNoParaeter() throws Exception {
|
||||||
@ -29,4 +47,59 @@ public class GroupControllerTest extends AbstractControllerTest {
|
|||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||||
mockMvc.perform(get(GROUPS_BY_COURSE_ENDPOINT + "/2")).andExpect(status().isOk());
|
mockMvc.perform(get(GROUPS_BY_COURSE_ENDPOINT + "/2")).andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailWithNoToken() throws Exception {
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(put(UPDATE_GROUPS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailWithStudentToken() throws Exception {
|
||||||
|
final User user = this.service
|
||||||
|
.save(new User(null, null, "shouldFailWithStudentToken@GroupController.test", UserRoles.STUDENT));
|
||||||
|
final String token = this.service.login(user).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(put(UPDATE_GROUPS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailWithNoParams() throws Exception {
|
||||||
|
final User user = this.service
|
||||||
|
.save(new User(null, null, "shouldFailWithNoParams@GroupController.test", UserRoles.DEANERY));
|
||||||
|
final String token = this.service.login(user).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(put(UPDATE_GROUPS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailWithWrongId() throws Exception {
|
||||||
|
final User user = this.service
|
||||||
|
.save(new User(null, null, "shouldFailWithWrongId@GroupController.test", UserRoles.DEANERY));
|
||||||
|
final String token = this.service.login(user).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(put("/api/v1/groups/" + user.getId() + "/capacity").param("newcapacity", "23")
|
||||||
|
.header("Authorization", "Bearer " + token)).andExpect(status().isNotFound());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldChangeCapacity() throws Exception {
|
||||||
|
final User user = this.service
|
||||||
|
.save(new User(null, null, "shouldChangeCapacity@GroupController.test", UserRoles.DEANERY));
|
||||||
|
final String token = this.service.login(user).getToken();
|
||||||
|
final Groups newGroup = this.groupService.save(new Groups(43, "A-Nigzdie", null, 436, WeekDay.FRIDAY, null));
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(put("/api/v1/groups/" + newGroup.getId() + "/capacity").param("newcapacity", "23")
|
||||||
|
.header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||||
|
|
||||||
|
assertTrue(this.groupService.getGroupById(newGroup.getId()).get().getCapacity() == 23);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.plannaplan.controllers;
|
|||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
@ -12,11 +13,22 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.User;
|
||||||
|
import com.plannaplan.services.UserService;
|
||||||
|
import com.plannaplan.types.UserRoles;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class TokenControllerTest extends AbstractControllerTest {
|
public class TokenControllerTest extends AbstractControllerTest {
|
||||||
private final String TOKEN_ENDPOINT = "/token";
|
private final String TOKEN_ENDPOINT = "/token";
|
||||||
|
private final String REFRESH_TOKEN_ENDPOINT = "/token/refresh";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService service;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFailWithNoParameter() throws Exception {
|
public void shouldFailWithNoParameter() throws Exception {
|
||||||
@ -39,4 +51,39 @@ public class TokenControllerTest extends AbstractControllerTest {
|
|||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||||
mockMvc.perform(get(TOKEN_ENDPOINT).param("ticket", ticket)).andExpect(status().isOk());
|
mockMvc.perform(get(TOKEN_ENDPOINT).param("ticket", ticket)).andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailWithWrongRefreshToken() throws Exception {
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||||
|
mockMvc.perform(get(REFRESH_TOKEN_ENDPOINT).param("refreshToken", "totaly-wrong-refresh-token"))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRetrunTokenBeforeExpirationOfOldOne() throws Exception {
|
||||||
|
User user = new User("Eren", "Yager", "shouldRetrunTokenBeforeExpirationOfOldOne@TokenController.test",
|
||||||
|
UserRoles.TEST_USER);
|
||||||
|
user.setToken("Totalnie-bezpieczny-token");
|
||||||
|
this.service.save(user);
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||||
|
mockMvc.perform(get(REFRESH_TOKEN_ENDPOINT).param("refreshToken", user.getRefreshToken()))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldRetrunTokenAfterExpirationOfOldOne() throws Exception {
|
||||||
|
final Field reader = User.class.getDeclaredField("tokenUsageDate");
|
||||||
|
reader.setAccessible(true);
|
||||||
|
|
||||||
|
User user = new User("Mikasa", "Ackerman", "shouldRetrunTokenAfterExpirationOfOldOne@TokenController.test",
|
||||||
|
UserRoles.TEST_USER);
|
||||||
|
user.setToken("Totalnie-bezpieczny-token");
|
||||||
|
reader.set(user, new Timestamp(System.currentTimeMillis() - 86400000));
|
||||||
|
this.service.save(user);
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||||
|
mockMvc.perform(get(REFRESH_TOKEN_ENDPOINT).param("refreshToken", user.getRefreshToken()))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,13 @@ import org.springframework.test.web.servlet.MockMvc;
|
|||||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
|
|
||||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
@ -24,6 +28,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||||||
public class UsersControllerTest extends AbstractControllerTest {
|
public class UsersControllerTest extends AbstractControllerTest {
|
||||||
private static final String SEARCH_ENDPOINT = "/api/v1/users/student/search";
|
private static final String SEARCH_ENDPOINT = "/api/v1/users/student/search";
|
||||||
private static final String ALL_USERS_ENDPOINT = "/api/v1/users/students";
|
private static final String ALL_USERS_ENDPOINT = "/api/v1/users/students";
|
||||||
|
private static final String ADD_ADMIN_ENDPOINT = "/api/v1/users/admin";
|
||||||
|
private static final String ADD_DEANERY_ENDPOINT = "/api/v1/users/deanery";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService service;
|
private UserService service;
|
||||||
@ -87,4 +93,117 @@ public class UsersControllerTest extends AbstractControllerTest {
|
|||||||
.andExpect(status().is4xxClientError());
|
.andExpect(status().is4xxClientError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDenyNewAdminWithWrongRole() throws Exception {
|
||||||
|
final String email = "shouldDenyNewAdminWithWrongRole@shouldDenyAllStudentsTryByStudent.test";
|
||||||
|
final User user = this.service.save(new User(null, null, email, UserRoles.TEST_USER));
|
||||||
|
final String token = this.service.login(user).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_ADMIN_ENDPOINT).param("authority","45611").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDenyNewAdminWithNoParams() throws Exception {
|
||||||
|
final String email = "shouldDenyNewAdminWithNoParams@shouldDenyAllStudentsTryByStudent.test";
|
||||||
|
final User user = this.service.save(new User(null, null, email, UserRoles.ADMIN));
|
||||||
|
final String token = this.service.login(user).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_ADMIN_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCreateNewAdmin() throws Exception {
|
||||||
|
final String email = "shouldCreateNewAdmin@shouldDenyAllStudentsTryByStudent.test";
|
||||||
|
final String usosId = "121321";
|
||||||
|
final User user = this.service.save(new User(null, null, email, UserRoles.ADMIN));
|
||||||
|
final String token = this.service.login(user).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_ADMIN_ENDPOINT).param("authority",usosId).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
|
||||||
|
final Optional<User> reponse = this.service.getByAuthority(usosId);
|
||||||
|
assertTrue(reponse.get().getUsosId().equals(usosId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldChangeExistingUserIntoAdmin() throws Exception {
|
||||||
|
final String email = "shouldChangeExistingUserIntoAdmin@shouldDenyAllStudentsTryByStudent.test";
|
||||||
|
final String email2 = "shouldChangeExistingUserIntoAdmin2@shouldDenyAllStudentsTryByStudent.test";
|
||||||
|
final String usosId = "121327";
|
||||||
|
final User user = this.service.save(new User(null, null, email, UserRoles.ADMIN));
|
||||||
|
|
||||||
|
this.service.save(new User(null, null, email2, usosId, UserRoles.TEST_USER));
|
||||||
|
|
||||||
|
final String token = this.service.login(user).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_ADMIN_ENDPOINT).param("authority",usosId).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
|
||||||
|
final Optional<User> reponse = this.service.getByAuthority(usosId);
|
||||||
|
assertTrue(reponse.get().getUsosId().equals(usosId));
|
||||||
|
assertTrue(reponse.get().getRole().equals(UserRoles.ADMIN));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDenyNewDeaneryWithWrongRole() throws Exception {
|
||||||
|
final String email = "shouldDenyNewDeaneryWithWrongRole@shouldDenyAllStudentsTryByStudent.test";
|
||||||
|
final User user = this.service.save(new User(null, null, email, UserRoles.TEST_USER));
|
||||||
|
final String token = this.service.login(user).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_DEANERY_ENDPOINT).param("authority","45611").header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDenyNewDeaneryWithNoParams() throws Exception {
|
||||||
|
final String email = "shouldDenyNewDeaneryWithNoParams@shouldDenyAllStudentsTryByStudent.test";
|
||||||
|
final User user = this.service.save(new User(null, null, email, UserRoles.ADMIN));
|
||||||
|
final String token = this.service.login(user).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_DEANERY_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCreateNewDeanery() throws Exception {
|
||||||
|
final String email = "shouldCreateNewDeanery@shouldDenyAllStudentsTryByStudent.test";
|
||||||
|
final String usosId = "121322";
|
||||||
|
final User user = this.service.save(new User(null, null, email, UserRoles.ADMIN));
|
||||||
|
final String token = this.service.login(user).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_DEANERY_ENDPOINT).param("authority",usosId).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
|
||||||
|
final Optional<User> reponse = this.service.getByAuthority(usosId);
|
||||||
|
assertTrue(reponse.get().getUsosId().equals(usosId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldChangeExistingUserIntoDeanery() throws Exception {
|
||||||
|
final String email = "shouldChangeExistingUserIntoDeanery@shouldDenyAllStudentsTryByStudent.test";
|
||||||
|
final String email2 = "shouldChangeExistingUserIntoDeanery2@shouldDenyAllStudentsTryByStudent.test";
|
||||||
|
final String usosId = "121328";
|
||||||
|
final User user = this.service.save(new User(null, null, email, UserRoles.ADMIN));
|
||||||
|
|
||||||
|
this.service.save(new User(null, null, email2, usosId, UserRoles.TEST_USER));
|
||||||
|
|
||||||
|
final String token = this.service.login(user).getToken();
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(post(ADD_DEANERY_ENDPOINT).param("authority",usosId).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().isOk());
|
||||||
|
|
||||||
|
final Optional<User> reponse = this.service.getByAuthority(usosId);
|
||||||
|
assertTrue(reponse.get().getUsosId().equals(usosId));
|
||||||
|
assertTrue(reponse.get().getRole().equals(UserRoles.DEANERY));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,16 @@ package com.plannaplan.responses.mappers;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.Assignment;
|
||||||
import com.plannaplan.entities.Commision;
|
import com.plannaplan.entities.Commision;
|
||||||
|
import com.plannaplan.entities.Groups;
|
||||||
import com.plannaplan.responses.models.CommisionResponse;
|
import com.plannaplan.responses.models.CommisionResponse;
|
||||||
|
import com.plannaplan.responses.models.CommisionWithGroupsResponse;
|
||||||
|
import com.plannaplan.types.WeekDay;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -17,7 +22,36 @@ public class CommisionResponseMappersTest {
|
|||||||
final List<CommisionResponse> resposne = CommisionResponseMappers.mapToResponse(coms);
|
final List<CommisionResponse> resposne = CommisionResponseMappers.mapToResponse(coms);
|
||||||
|
|
||||||
assertTrue(resposne.get(0) instanceof CommisionResponse);
|
assertTrue(resposne.get(0) instanceof CommisionResponse);
|
||||||
assertTrue(resposne.get(0).getCommisionDate().equals(coms.get(0).getCommisionDate()));
|
assertTrue(resposne.get(0).getCommisionDate().equals(coms.get(0).getCommisionDate().toString()));
|
||||||
assertTrue(resposne.get(1).getCommisionDate().equals(coms.get(1).getCommisionDate()));
|
assertTrue(resposne.get(1).getCommisionDate().equals(coms.get(1).getCommisionDate().toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldMapListWithEntityToListOfResponsesWithGroups()
|
||||||
|
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||||
|
|
||||||
|
final Field reader = Commision.class.getDeclaredField("assignments");
|
||||||
|
final Field groupReader = Groups.class.getDeclaredField("id");
|
||||||
|
reader.setAccessible(true);
|
||||||
|
groupReader.setAccessible(true);
|
||||||
|
|
||||||
|
final Commision com1 = new Commision(null);
|
||||||
|
final Groups group1 = new Groups(43, "BRAK", null, 840, WeekDay.MONDAY, null);
|
||||||
|
|
||||||
|
groupReader.set(group1, Long.valueOf(8));
|
||||||
|
reader.set(com1, Arrays.asList(new Assignment(group1, com1)));
|
||||||
|
|
||||||
|
final Commision com2 = new Commision(null);
|
||||||
|
final Groups group2 = new Groups(124, "BRAK", null, 900, WeekDay.WEDNESDAY, null);
|
||||||
|
|
||||||
|
groupReader.set(group2, Long.valueOf(9));
|
||||||
|
reader.set(com2, Arrays.asList(new Assignment(group2, com2)));
|
||||||
|
|
||||||
|
final List<CommisionWithGroupsResponse> resposne = CommisionResponseMappers
|
||||||
|
.mapToResponseWithGroups(Arrays.asList(com1, com2));
|
||||||
|
|
||||||
|
assertTrue(resposne.size() == 2);
|
||||||
|
assertTrue(resposne.get(0).getGroups().get(0) == 8);
|
||||||
|
assertTrue(resposne.get(1).getGroups().get(0) == 9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,6 @@ public class CommisionResponseTest {
|
|||||||
final Commision com = new Commision(null);
|
final Commision com = new Commision(null);
|
||||||
final CommisionResponse comResponse = new CommisionResponse(com);
|
final CommisionResponse comResponse = new CommisionResponse(com);
|
||||||
|
|
||||||
assertTrue(comResponse.getCommisionDate().equals(com.getCommisionDate()));
|
assertTrue(comResponse.getCommisionDate().equals(com.getCommisionDate().toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
restservice/src/test/java/com/plannaplan/responses/models/CommisionWithGroupsResponseTest.java
Executable file
34
restservice/src/test/java/com/plannaplan/responses/models/CommisionWithGroupsResponseTest.java
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
package com.plannaplan.responses.models;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.Assignment;
|
||||||
|
import com.plannaplan.entities.Commision;
|
||||||
|
import com.plannaplan.entities.Groups;
|
||||||
|
import com.plannaplan.types.WeekDay;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class CommisionWithGroupsResponseTest {
|
||||||
|
@Test
|
||||||
|
public void shouldMapCommisionToResponse()
|
||||||
|
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||||
|
final Field reader = Commision.class.getDeclaredField("assignments");
|
||||||
|
final Field groupReader = Groups.class.getDeclaredField("id");
|
||||||
|
reader.setAccessible(true);
|
||||||
|
groupReader.setAccessible(true);
|
||||||
|
|
||||||
|
final Commision com = new Commision(null);
|
||||||
|
final Groups group = new Groups(43, "BRAK", null, 840, WeekDay.MONDAY, null);
|
||||||
|
|
||||||
|
groupReader.set(group, Long.valueOf(8));
|
||||||
|
reader.set(com, Arrays.asList(new Assignment(group, com)));
|
||||||
|
|
||||||
|
final CommisionWithGroupsResponse comResponse = new CommisionWithGroupsResponse(com);
|
||||||
|
|
||||||
|
assertTrue(comResponse.getGroups().get(0) == 8);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.plannaplan.security.cas;
|
package com.plannaplan.security.cas;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
||||||
@ -9,12 +10,15 @@ public class CustomUAMCasValidatorTest {
|
|||||||
private String serviceUrl;
|
private String serviceUrl;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Ignore
|
||||||
public void shouldValidateWithDomain() {
|
public void shouldValidateWithDomain() {
|
||||||
|
// you need to privide fresh ticket to make this test pass that's why it is
|
||||||
|
// marked as ignored
|
||||||
|
|
||||||
CustomUAMCasValidator validator = new CustomUAMCasValidator(serviceUrl, "ST-54649-5x4h09vzUpEIyAGmf1sz-cas.amu.edu.pl");
|
CustomUAMCasValidator validator = new CustomUAMCasValidator(serviceUrl,
|
||||||
|
"ST-54649-5x4h09vzUpEIyAGmf1sz-cas.amu.edu.pl");
|
||||||
|
|
||||||
validator.validate();
|
validator.validate();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -20,3 +20,9 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- 8080:8080
|
- 8080:8080
|
||||||
|
|
||||||
|
mailcatcher:
|
||||||
|
image: schickling/mailcatcher:latest
|
||||||
|
ports:
|
||||||
|
- "127.0.0.1:1080:1080"
|
||||||
|
- "127.0.0.1:1025:1025"
|
||||||
|
Reference in New Issue
Block a user