Compare commits
303 Commits
auth-save-
...
exchanges
Author | SHA1 | Date | |
---|---|---|---|
9c1a148e20 | |||
ab32ad8561 | |||
1506270dec | |||
75a3bc46f2
|
|||
986407b8f8
|
|||
11469e9314
|
|||
d1641277ac
|
|||
ed528ad9a0
|
|||
f9a27abb32
|
|||
1e1160736d
|
|||
bc8f7407fc
|
|||
1c12a778af
|
|||
3583d30b26
|
|||
76faedc40d
|
|||
5e459ac429
|
|||
b18f9cd50e
|
|||
6311ecee92
|
|||
6fe72465b9
|
|||
00f639ad55
|
|||
81f870eaa1
|
|||
2e6f373997
|
|||
c7feb10997
|
|||
b0a1d929e4
|
|||
3335155cd8
|
|||
df90a57715
|
|||
2320d66a35
|
|||
11d21be627
|
|||
756e854f31
|
|||
bbf14b0ff9
|
|||
a25843ebfd
|
|||
149796c42a
|
|||
c6c67e7e29
|
|||
ad0d9e40c1
|
|||
1682448627
|
|||
e24938dfce
|
|||
842e38898a
|
|||
56120c4724
|
|||
c8c8b62263
|
|||
ebacbe892d
|
|||
90f154f23b
|
|||
b633d2c2df
|
|||
df7701ebc8
|
|||
f24e62a335
|
|||
3bcc35e75b
|
|||
6e65c26e3c
|
|||
cfc1e3eba7
|
|||
3b80a70921 | |||
5edec5aa71
|
|||
5b0097e6c7
|
|||
fddd5b757d
|
|||
7813f148eb
|
|||
8c0b880412
|
|||
fe06243bda
|
|||
f9fc7fa7bd
|
|||
68dfd2473a | |||
ddabc1a0b9 | |||
463af01dc6 | |||
0b40d3729c | |||
3485dff86f | |||
2141f35e3f | |||
a6e6618202 | |||
44f8c610d9 | |||
95cc34c676 | |||
61d035e342 | |||
0f8b4eafb5 | |||
2c0008afe1 | |||
4b096a50bf | |||
ff9aa64470 | |||
a41c6f2583 | |||
ef896e9c12
|
|||
3bce1f91ec | |||
665807240f | |||
cd0f4bccd9 | |||
ccb0161609 | |||
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 | |||
acf80cc78d | |||
c34d53d056 | |||
48394d3583 | |||
82200acc06 | |||
f9baed5df7 | |||
3061fb1edf | |||
b412ee2a5b | |||
2037f0bf07
|
|||
b4f23aa5d2 | |||
495098eeed | |||
751d4b1744 | |||
cbe8f96700 | |||
2dd1f70eee
|
|||
c70cac58b2
|
|||
616f782155
|
|||
6dfb99f253
|
|||
b897fce416
|
|||
f4db74b899
|
|||
453907782a
|
|||
3ebfda5316
|
|||
b6c2e43975
|
|||
6298bb4765
|
|||
c24aa73bb0
|
|||
20d261635b
|
|||
1e3cccc991
|
|||
cd96e74c29
|
|||
7d747b60a8
|
|||
c3fd450499 | |||
b966b64fdb
|
|||
1d15d295e0 | |||
f8b12d831b
|
|||
20341d5441
|
|||
3faa228745
|
|||
e6fffba899
|
|||
708cedf7b4
|
|||
96c903ed15
|
|||
160930c3c3
|
|||
823f4af218
|
|||
b2b9178bc1 | |||
7e45da1306 | |||
c2c82b75ba | |||
78ed2f75f3 | |||
082b30133c | |||
25e9571a06 | |||
593084aeba | |||
911f2e54f5
|
|||
13eb8dae77 | |||
7d5522e413
|
|||
9ed4197005
|
|||
dc3a554ed1
|
|||
f6a8953c17
|
|||
2545a0e682 | |||
0130fb77e1 | |||
9d3500c1fb | |||
b4bb13f2dd | |||
e752ad06cd
|
|||
6d9c5a8a5d
|
|||
85052f5728
|
|||
50c1397db2
|
|||
af8e2ced28
|
|||
9ad8db527d
|
|||
bc6c55165e
|
|||
3e7086eab9 | |||
c34ce94fb0 | |||
17e5625315
|
|||
1ddeb83cb4 | |||
b713066a2f | |||
029300815e
|
|||
7c7045c0e1
|
|||
035de011f2
|
|||
1b126c7792 | |||
a30c3af09c
|
|||
62bbf148b2 | |||
8ba148617a | |||
48fdeb726f | |||
bd4591f442 | |||
0fbc6d6baa | |||
feff5c4b9c | |||
d2343acc2d | |||
cbd9074a89 | |||
228969efce | |||
e0df090a0e | |||
6a7fc03e7c | |||
4818905422 | |||
b308373062 | |||
ba26d67cd4 | |||
1a30ac3374 | |||
b4f51d4382 | |||
6ab2ec50dd | |||
9bff6460d6 | |||
1571bccb49 | |||
1327a239e8 | |||
2b59c181e5 | |||
ca01b20221 | |||
956b53439f | |||
b40acf8919 | |||
ed00731654 | |||
3a3e6dc427 | |||
4267fadf62 | |||
41f37ee9ad | |||
4ca2837b59 | |||
953168a452 | |||
d3a2256334 | |||
933e09172b | |||
f0eae82d9f | |||
7073e3b1d8 | |||
bdfed57942 | |||
db0115280f | |||
f71715fd6b | |||
9dba639674 | |||
4614a11a8b | |||
a1f17d271f | |||
6384f3d9b9 | |||
7d57157078 | |||
468b6e6b87 | |||
c003198aa1 | |||
603dadd9c1 | |||
4b07793849 | |||
67c8b9bf25 | |||
0ad97a8e3f | |||
5fd688fc7a | |||
a20bc89fc6 | |||
9c02a0b596 | |||
2b067f63fc | |||
010f0b4566 | |||
cb60b17389 | |||
3e8bfe85d6 | |||
932e1a8830 | |||
148d7a31c6 | |||
bdd0278880 | |||
29851dac0d | |||
f97e22fa5f | |||
9d97306e5c | |||
f9706e0e01 | |||
f9dd6e38c3 | |||
73104850fe | |||
fe5d2d20c3 | |||
30222d6856 | |||
95fcfc4e06 | |||
e9ae1a0ed0 | |||
bb9ea7529f | |||
398a84854f | |||
51ea557a06 | |||
fa74965504 | |||
b503ebcbcc | |||
b4d1c87461 | |||
3ad4d3a84b | |||
4efedf7f35 | |||
917a4e3535 | |||
15a4c526b4 | |||
44bcc24110 | |||
ce4a5942d5 | |||
9cec5a902c | |||
305b86945d | |||
3d1269037b | |||
694fe74690 | |||
9599d58543 | |||
bf6e1fc2b1 | |||
ec77fa782b | |||
c449bc22e1 |
11
.gitignore
vendored
Normal file → Executable file
11
.gitignore
vendored
Normal file → Executable file
@ -29,3 +29,14 @@ build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
|
||||
### Python ###
|
||||
__pycache__
|
||||
.pytest_cache
|
||||
|
||||
### Parser ###
|
||||
parser/
|
||||
|
||||
|
||||
envs.sh
|
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
|
117
README.md
Normal file → Executable file
117
README.md
Normal file → Executable file
@ -1,44 +1,94 @@
|
||||
## Start aplikacji
|
||||
# Start aplikacji
|
||||
|
||||
Zeby wystartowac aplikacje backendu najpierw nalezy postawic testowa baze danych na naszym komputerze za pomoca dockera. Jesli raz juz go odpalimy przy nastepnym razem bardzo mozliwe, ze wlaczy sie sam. AAby sprawdzic czy docker jesty wystartowany mozna uzyc `docker ps`
|
||||
|
||||
```
|
||||
docker-compose -f stack.yml up
|
||||
```
|
||||
|
||||
Nastepnie w `restservice/src/main/resources/application.properties` nalezy podac ip naszego kontenera.
|
||||
|
||||
```
|
||||
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/test
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=example
|
||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
spring.jpa.hibernate.ddl-auto=create
|
||||
|
||||
server.port=1285
|
||||
docker-compose -f stack.yml up -d
|
||||
```
|
||||
|
||||
Następnym krokiem jest odpalenie poniższych komend w terminalu.
|
||||
|
||||
```
|
||||
cd restservice
|
||||
mvn spring-boot:run
|
||||
```
|
||||
|
||||
## Packaging
|
||||
# Token obtaining
|
||||
|
||||
Żeby tesotwać API wpełni potrzebny nam jest token który otrzymujemy na podstawie ticketa z systemu autoryzacyjnego **CAS**. Z tego powodu system autoryzacji działa inaczej niż w "książkowych" restowych aplikacjach i np Postman za nas jej nie dokona. Musimy mu podać już uzyskany token. Aby łatwo go uzyskać odpal skrypt
|
||||
|
||||
```bash
|
||||
python gettoken.py
|
||||
```
|
||||
|
||||
Jeżeli chcesz używać skryptu zmiejaniąc gdzie znajduje się backend wpisz:
|
||||
|
||||
```bash
|
||||
python gettoken.py 192.168.0.212
|
||||
```
|
||||
|
||||
Jeżeli chcesz używać skryptu bez uruchamiania przeglądarki wpisz:
|
||||
|
||||
```bash
|
||||
python gettoken.py no-browser
|
||||
```
|
||||
|
||||
Na koniec w przęglądarce dostaniesz w odpowiedzi token. W samym pliku można zmienić porty aplikacji jeśli to potrzebne.
|
||||
|
||||
# Profiles
|
||||
|
||||
W aplikacji posiadamy dwa profile. `dev` i `prod`. **Dev** używamy do testowania aplikacji lokalnie. **Pord** służy do stworzenia builda na produkcję.
|
||||
Profil wybieramy w pliku `restservice/src/main/resources/application.properties` wpisując odpowiednią nazwę
|
||||
|
||||
```
|
||||
spring.profiles.active=prod
|
||||
```
|
||||
|
||||
Jeżeli chcemy zmienić jakieś opcję dla pordukcji to robimy to w tym sammym katalogi w pliku `application-prod.properties` i dla dev analogicznie w `application-dev.properties`.
|
||||
W paczce dla proda w protpertiesach poufne dane odczytywane są ze zmiennych środowiskowych systemu na którym odpalana jest aplikacja. Ustawić trzeba następujące zmienne:
|
||||
|
||||
- `PLANNAPLAN_MYSQL_DB_HOST` - host bazy danych np `localhost`
|
||||
- `PLANNAPLAN_MYSQL_DB_PORT` - port na którym działa baza
|
||||
- `PLANNAPLAN_MYSQL_DB` - nazwa bazy dancyh. W profilu **dev** jest to np test
|
||||
- `PLANNAPLAN_MYSQL_DB_USERNAME` - nazwa użytkownika bazy
|
||||
- `PLANNAPLAN_MYSQL_DB_PASSWORD` - hasło użytkownika bazy
|
||||
- `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
|
||||
- `PLANNAPLAN_CONSUMER_KEY` - nasz klucz do usos api
|
||||
- `PLANNAPLAN_CONSUMER_SECRET` - secret naszego klucza
|
||||
|
||||
Należy też pamiętać, że zmienne `PLANNAPLAN_CONSUMER_KEY` oraz `PLANNAPLAN_CONSUMER_SECRET` są potrzebne również w profilu `dev` więc trzeba je dodać w celu tesotowania do zmiennych we własnym systemie
|
||||
|
||||
# Packaging
|
||||
|
||||
Zeby spakowac apke do `jara` wystarcza dwie komendy zaczynajac z glownego katalogu projektu
|
||||
|
||||
```
|
||||
mvn clean
|
||||
mvn install
|
||||
cd restservice
|
||||
mvn clean package spring-boot:repackage
|
||||
mvn clean; 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)
|
||||
|
||||
## Troubleshooting
|
||||
# Generowanie dokumentacji
|
||||
|
||||
## Javadocs
|
||||
|
||||
```bash
|
||||
mvn javadoc:javadoc
|
||||
```
|
||||
|
||||
## Api docs
|
||||
|
||||
Żeby zobaczyć dokumentację api trzeba wejść w przeglądarce na `http://localhost:1285/swagger-ui.html` po odpaleniu aplikacji.
|
||||
|
||||
### Nazewnictwo odpowiedzi
|
||||
|
||||
Każdą odpowiedź zaczynamy od modelu, który opisuje np. `Courses` a kończymy na `Response`. Między tymi dwoma członami możemy dodawać modyfikatory opisujące dokładniej odpowiedź np. `Default`. W ten sposób możemy otrzymać nazwę `CoursesDefaultResponse.java`
|
||||
|
||||
# Troubleshooting
|
||||
|
||||
Spring chyba cacheuje jakies dane dotyczace polaczenia wiec jesli spring wywali Ci blad `Connection Refused`, a wiesz, ze ta baza stoi na podanym ip i porcie to sprobuj
|
||||
|
||||
@ -46,3 +96,28 @@ Spring chyba cacheuje jakies dane dotyczace polaczenia wiec jesli spring wywali
|
||||
mvn clean
|
||||
mvn install
|
||||
```
|
||||
|
||||
Jeżeli używasz VSCode i testy, które wymagają podanych zmiennych środowiskowych (testy odpytywania usos api) trzeba podać te zmienne w pliku `.vscode/settings.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"files.exclude": {
|
||||
"**/.classpath": true,
|
||||
"**/.project": true,
|
||||
"**/.settings": true,
|
||||
"**/.factorypath": true
|
||||
},
|
||||
"java.configuration.updateBuildConfiguration": "disabled",
|
||||
"java.format.settings.url": "eclipse-formatter.xml",
|
||||
"java.test.config": [
|
||||
{
|
||||
"name": "myConfiguration",
|
||||
"workingDirectory": "${workspaceFolder}",
|
||||
"env": {
|
||||
"PLANNAPLAN_CONSUMER_KEY": "value",
|
||||
"PLANNAPLAN_CONSUMER_SECRET": "value"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
46
buisnesslogic/pom.xml
Normal file → Executable file
46
buisnesslogic/pom.xml
Normal file → Executable file
@ -16,8 +16,8 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>14</maven.compiler.source>
|
||||
<maven.compiler.target>14</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -57,7 +57,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>3.17</version>
|
||||
<version>4.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- dependency used for XLS older file format
|
||||
@ -68,6 +68,37 @@
|
||||
<version>3.17</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
<version>2.2.5.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.social/spring-social-core -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.12</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.scribejava</groupId>
|
||||
<artifactId>scribejava-core</artifactId>
|
||||
<version>8.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.8</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -84,6 +115,15 @@
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
|
@ -0,0 +1,24 @@
|
||||
{
|
||||
"properties": [
|
||||
{
|
||||
"name": "plannaplan.email",
|
||||
"type": "java.lang.String",
|
||||
"description": "Email from which app sends message"
|
||||
},
|
||||
{
|
||||
"name": "plannaplan.apiurl",
|
||||
"type": "java.lang.String",
|
||||
"description": "Url to usos api endpoints"
|
||||
},
|
||||
{
|
||||
"name": "plannaplan.apikey",
|
||||
"type": "java.lang.String",
|
||||
"description": "Api consumer key"
|
||||
},
|
||||
{
|
||||
"name": "plannaplan.apisecret",
|
||||
"type": "java.lang.String",
|
||||
"description": "Api consumer secret"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
public class Acceptor {
|
||||
public Acceptor() {
|
||||
}
|
||||
|
||||
public void run() {
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.plannaplan.types.AppStates;
|
||||
|
||||
public class App {
|
||||
private static App instance;
|
||||
private Date round1;
|
||||
private Date round2;
|
||||
private AppStates state;
|
||||
|
||||
private App() {
|
||||
}
|
||||
|
||||
public AppStates getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(AppStates state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public Date getRound2() {
|
||||
return round2;
|
||||
}
|
||||
|
||||
public void setRound2(Date round2) {
|
||||
this.round2 = round2;
|
||||
}
|
||||
|
||||
public Date getRound1() {
|
||||
return round1;
|
||||
}
|
||||
|
||||
public void setRound1(Date round1) {
|
||||
this.round1 = round1;
|
||||
}
|
||||
|
||||
public App getInstance() {
|
||||
if (App.instance == null) {
|
||||
App.instance = new App();
|
||||
}
|
||||
return App.instance;
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import com.plannaplan.interfaces.Historable;
|
||||
import com.plannaplan.interfaces.ProtectedAction;
|
||||
|
||||
public class Assigner implements Historable, ProtectedAction {
|
||||
|
||||
public Assigner() {
|
||||
}
|
||||
|
||||
public void assing() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateAction() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addActionToHistory() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import com.plannaplan.interfaces.ProtectedAction;
|
||||
import com.plannaplan.models.ConfigData;
|
||||
import com.plannaplan.models.FileData;
|
||||
import com.plannaplan.services.CourseService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.services.LecturerService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.plannaplan.configutils.*;
|
||||
|
||||
@Component
|
||||
public class Configurator implements ProtectedAction {
|
||||
|
||||
@Autowired
|
||||
private LecturerService lecturerService;
|
||||
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
public Configurator() {
|
||||
}
|
||||
|
||||
public void config(ConfigData data) {
|
||||
FileReader reader = new FileReader(data.getFilestream());
|
||||
FileData coursesData = reader.read();
|
||||
FileToDatabaseMigrator mgtr = new FileToDatabaseMigrator(lecturerService, courseService, groupService);
|
||||
mgtr.migrate(coursesData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateAction() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import com.plannaplan.models.ConfigData;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Controller {
|
||||
|
||||
@Autowired
|
||||
private Configurator configurator;
|
||||
|
||||
public Controller() {
|
||||
}
|
||||
|
||||
public void startApp() {
|
||||
}
|
||||
|
||||
public void assignCourse() {
|
||||
}
|
||||
|
||||
public void addUnavailibility() {
|
||||
}
|
||||
|
||||
public void addGroup() {
|
||||
}
|
||||
|
||||
public void editGroup() {
|
||||
}
|
||||
|
||||
public void getHistoryAtPoint() {
|
||||
}
|
||||
|
||||
public void config(ConfigData data) {
|
||||
configurator.config(data);
|
||||
}
|
||||
|
||||
public void createTransfer() {
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
public class Emailer {
|
||||
public Emailer() {
|
||||
}
|
||||
|
||||
public void performAllMails() {
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import com.plannaplan.interfaces.EventCreator;
|
||||
|
||||
public class EventChcker implements EventCreator {
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import com.plannaplan.interfaces.Historable;
|
||||
import com.plannaplan.interfaces.ProtectedAction;
|
||||
|
||||
public class GroupAdder implements Historable, ProtectedAction {
|
||||
|
||||
public GroupAdder() {
|
||||
}
|
||||
|
||||
public void addGroup() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addActionToHistory() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateAction() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import com.plannaplan.interfaces.ProtectedAction;
|
||||
|
||||
public class GroupEditor implements ProtectedAction {
|
||||
|
||||
public GroupEditor() {
|
||||
}
|
||||
|
||||
public void setNewCapacity(int capaity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateAction() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import com.plannaplan.interfaces.ProtectedAction;
|
||||
|
||||
public class HistoryResolver implements ProtectedAction {
|
||||
|
||||
public HistoryResolver() {
|
||||
}
|
||||
|
||||
public void getHistoryAtPoint() {
|
||||
}
|
||||
|
||||
public void reproduce() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateAction() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import com.plannaplan.interfaces.Historable;
|
||||
import com.plannaplan.interfaces.ProtectedAction;
|
||||
|
||||
public class TransferCreator implements Historable, ProtectedAction {
|
||||
|
||||
public TransferCreator() {
|
||||
}
|
||||
|
||||
public void createTransfer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateAction() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addActionToHistory() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import com.plannaplan.interfaces.Historable;
|
||||
|
||||
public class TransferValidator implements Historable {
|
||||
|
||||
public TransferValidator() {
|
||||
}
|
||||
|
||||
public void performAllTransfers() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addActionToHistory() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.plannaplan;
|
||||
|
||||
import com.plannaplan.interfaces.Historable;
|
||||
import com.plannaplan.interfaces.ProtectedAction;
|
||||
|
||||
public class UnavailabilityAdder implements Historable, ProtectedAction {
|
||||
|
||||
public UnavailabilityAdder() {
|
||||
}
|
||||
|
||||
public void add() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateAction() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addActionToHistory() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.plannaplan.abstracts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.interfaces.EventCreator;
|
||||
|
||||
public abstract class EventWatcher {
|
||||
|
||||
protected List<EventCreator> creators;
|
||||
|
||||
public EventWatcher() {
|
||||
this.creators = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void attach(EventCreator creator) {
|
||||
this.creators.add(creator);
|
||||
}
|
||||
|
||||
public void detach(EventCreator creator) {
|
||||
this.creators.remove(creator);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
}
|
||||
}
|
61
buisnesslogic/src/main/java/com/plannaplan/api/UsosOauth1Service.java
Executable file
61
buisnesslogic/src/main/java/com/plannaplan/api/UsosOauth1Service.java
Executable file
@ -0,0 +1,61 @@
|
||||
package com.plannaplan.api;
|
||||
|
||||
import com.github.scribejava.core.builder.api.DefaultApi10a;
|
||||
|
||||
/**
|
||||
* singleton class to sign usos api requests with oauth
|
||||
*/
|
||||
public class UsosOauth1Service extends DefaultApi10a {
|
||||
|
||||
private static final String AUTHORIZE_URL = "https://usosapidemo.amu.edu.pl/services/oauth/authorize";
|
||||
private static final String REQUEST_TOKEN_URL = "https://usosapidemo.amu.edu.pl/services/oauth/request_token";
|
||||
|
||||
private final String scopesAsString;
|
||||
|
||||
protected UsosOauth1Service() {
|
||||
scopesAsString = null;
|
||||
}
|
||||
|
||||
protected UsosOauth1Service(String... scopes) {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (String scope : scopes) {
|
||||
builder.append('+').append(scope);
|
||||
}
|
||||
scopesAsString = "?scope=" + builder.substring(1);
|
||||
}
|
||||
|
||||
private static class InstanceHolder {
|
||||
|
||||
private static final UsosOauth1Service INSTANCE = new UsosOauth1Service();
|
||||
}
|
||||
|
||||
public static UsosOauth1Service instance() {
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* get instance withj scopes
|
||||
*
|
||||
* @param scopes to get instance with
|
||||
* @return UsosOauth1Service instance
|
||||
*/
|
||||
public static UsosOauth1Service instance(String... scopes) {
|
||||
return scopes == null || scopes.length == 0 ? instance() : new UsosOauth1Service(scopes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequestTokenEndpoint() {
|
||||
return scopesAsString == null ? REQUEST_TOKEN_URL : REQUEST_TOKEN_URL + scopesAsString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessTokenEndpoint() {
|
||||
return "https://usosapidemo.amu.edu.pl/services/oauth/access_token";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getAuthorizationBaseUrl() {
|
||||
return AUTHORIZE_URL;
|
||||
}
|
||||
|
||||
}
|
7
buisnesslogic/src/main/java/com/plannaplan/configutils/FileReader.java
Normal file → Executable file
7
buisnesslogic/src/main/java/com/plannaplan/configutils/FileReader.java
Normal file → Executable file
@ -2,7 +2,7 @@ package com.plannaplan.configutils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Hashtable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
@ -11,6 +11,9 @@ import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import com.plannaplan.models.FileData;
|
||||
|
||||
/**
|
||||
* FileReader is used for reading xls file from input stream.
|
||||
*/
|
||||
public class FileReader {
|
||||
|
||||
private InputStream fileInputStream;
|
||||
@ -33,7 +36,7 @@ public class FileReader {
|
||||
Row row = rowIt.next();
|
||||
Iterator<Cell> cellIt = row.cellIterator();
|
||||
|
||||
Hashtable<String, Integer> keys = new Hashtable<>();
|
||||
HashMap<String, Integer> keys = new HashMap<>();
|
||||
int index = 0;
|
||||
while (cellIt.hasNext()) {
|
||||
Cell c = cellIt.next();
|
||||
|
168
buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java
Normal file → Executable file
168
buisnesslogic/src/main/java/com/plannaplan/configutils/FileToDatabaseMigrator.java
Normal file → Executable file
@ -1,7 +1,6 @@
|
||||
package com.plannaplan.configutils;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
@ -12,137 +11,104 @@ import com.plannaplan.services.LecturerService;
|
||||
import com.plannaplan.types.GroupType;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* FileToDatabaseMigrator is used for migrate data from file (it reads line by line) and push it into database
|
||||
*/
|
||||
@Component
|
||||
public class FileToDatabaseMigrator {
|
||||
public static String LECTURER_NAME_STRING = "imie";
|
||||
public static String LECTURER_SURNAME_STRING = "nazwisko";
|
||||
public static String LECTURER_TITLE_STRING = "tytul";
|
||||
|
||||
public static String COURSE_SYMBOL_STRING = "sym";
|
||||
public static String COURSE_NAME_STRING = "nazwa";
|
||||
private static final String LECTURER_NAME_STRING = "imie";
|
||||
private static final String LECTURER_SURNAME_STRING = "nazwisko";
|
||||
private static final String LECTURER_TITLE_STRING = "tytul";
|
||||
|
||||
public static String GROUP_DAY_STRING = "dzien";
|
||||
public static String GROUP_TIME_STRING = "godz_od";
|
||||
public static String ROOM_STRING = "sala";
|
||||
public static String CAPACITY_STRING = "Mc";
|
||||
private static final String COURSE_SYMBOL_STRING = "sym";
|
||||
private static final String COURSE_NAME_STRING = "nazwa";
|
||||
|
||||
LecturerService lecturerService;
|
||||
CourseService courseService;
|
||||
GroupService groupService;
|
||||
private static final String groupDay_STRING = "dzien";
|
||||
private static final String GROUP_TIME_STRING = "godz_od";
|
||||
private static final String ROOM_STRING = "sala";
|
||||
private static final String CAPACITY_STRING = "Mc";
|
||||
private static final String TYPE_GROUP= "typ";
|
||||
|
||||
public FileToDatabaseMigrator(LecturerService lecturerService, CourseService courseService,
|
||||
GroupService groupService) {
|
||||
this.lecturerService = lecturerService;
|
||||
this.groupService = groupService;
|
||||
this.courseService = courseService;
|
||||
private static final String ZAJ_CYK_ID = "zaj_cyk_id";
|
||||
private static final String GR_NR = "gr_nr";
|
||||
|
||||
@Autowired
|
||||
private LecturerService lecturerService;
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
public FileToDatabaseMigrator() {
|
||||
}
|
||||
|
||||
public void migrate(FileData data) {
|
||||
Iterator<Row> rows = data.getRows();
|
||||
int courseNameIndex = data.getIndexOf(FileToDatabaseMigrator.COURSE_NAME_STRING);
|
||||
int symbolIndex = data.getIndexOf(FileToDatabaseMigrator.COURSE_SYMBOL_STRING);
|
||||
|
||||
int course_name_index = data.getIndexOf(FileToDatabaseMigrator.COURSE_NAME_STRING);
|
||||
int sym_index = data.getIndexOf(FileToDatabaseMigrator.COURSE_SYMBOL_STRING);
|
||||
int titleIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_TITLE_STRING);
|
||||
int surnameIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_SURNAME_STRING);
|
||||
int nameIndex = data.getIndexOf(FileToDatabaseMigrator.LECTURER_NAME_STRING);
|
||||
|
||||
int title_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_TITLE_STRING);
|
||||
int surname_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_SURNAME_STRING);
|
||||
int name_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_NAME_STRING);
|
||||
int dayIndex = data.getIndexOf(FileToDatabaseMigrator.groupDay_STRING);
|
||||
int timeIndex = data.getIndexOf(FileToDatabaseMigrator.GROUP_TIME_STRING);
|
||||
int roomIndex = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
||||
int capacityIndex = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
|
||||
int typeGroupIndex = data.getIndexOf(FileToDatabaseMigrator.TYPE_GROUP);
|
||||
|
||||
int day_index = data.getIndexOf(FileToDatabaseMigrator.GROUP_DAY_STRING);
|
||||
int time_index = data.getIndexOf(FileToDatabaseMigrator.GROUP_TIME_STRING);
|
||||
int room_index = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
|
||||
int capacity_index = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
|
||||
int zajCykIdIndex = data.getIndexOf(FileToDatabaseMigrator.ZAJ_CYK_ID);
|
||||
int grNrIndex = data.getIndexOf(FileToDatabaseMigrator.GR_NR);
|
||||
|
||||
while (rows.hasNext()) {
|
||||
Row row = rows.next();
|
||||
|
||||
Cell course_name_cell = row.getCell(course_name_index);
|
||||
Cell sym = row.getCell(sym_index);
|
||||
String courseName = row.getCell(courseNameIndex).toString().trim();
|
||||
String symbol = row.getCell(symbolIndex).toString().trim();
|
||||
|
||||
Cell title_cell = row.getCell(title_index);
|
||||
Cell name_cell = row.getCell(name_index);
|
||||
Cell surname_cell = row.getCell(surname_index);
|
||||
String lecturerTitle = row.getCell(titleIndex) != null ? row.getCell(titleIndex).toString().trim() : "";
|
||||
String lecturerName = row.getCell(nameIndex) != null ? row.getCell(nameIndex).toString().trim() : "";
|
||||
String lecturerSurname = row.getCell(surnameIndex) != null ? row.getCell(surnameIndex).toString().trim()
|
||||
: "";
|
||||
|
||||
Cell day_cell = row.getCell(day_index);
|
||||
Cell time_cell = row.getCell(time_index);
|
||||
Cell room_cell = row.getCell(room_index);
|
||||
Cell capacity_cell = row.getCell(capacity_index);
|
||||
Integer zajCykId = row.getCell(zajCykIdIndex) != null ? (int) Double.parseDouble(row.getCell(zajCykIdIndex).toString().trim())
|
||||
: null;
|
||||
|
||||
String lecturer_title = "";
|
||||
String lecturer_surname = "";
|
||||
String lecturer_name = "";
|
||||
Integer grNr = row.getCell(grNrIndex) != null ? (int) Double.parseDouble(row.getCell(grNrIndex).toString().trim())
|
||||
: null;
|
||||
|
||||
String course_name = course_name_cell.toString().trim();
|
||||
String sym_str = sym.toString().trim();
|
||||
int day = row.getCell(dayIndex) != null ? (int) Double.parseDouble(row.getCell(dayIndex).toString()) : 0;
|
||||
WeekDay groupDay = WeekDay.getDay(day - 1);
|
||||
int time = parseTimeToInt(row.getCell(timeIndex).toString());
|
||||
String room = row.getCell(roomIndex).toString().trim();
|
||||
int capacity = (int) Double.parseDouble(row.getCell(capacityIndex).toString());
|
||||
GroupType typeGroup = GroupType.getType(row.getCell(typeGroupIndex).toString());
|
||||
|
||||
int day = (int) Double.parseDouble(day_cell.toString());
|
||||
WeekDay group_day = WeekDay.getDay(day - 1);
|
||||
String room = room_cell.toString().trim();
|
||||
int time = this.parseTimeToInt(time_cell.toString());
|
||||
Course course = this.courseService.getCourseByName(courseName)
|
||||
.orElseGet(() -> this.courseService.save(new Course(courseName, symbol)));
|
||||
|
||||
int capacity = (int) Double.parseDouble(capacity_cell.toString());
|
||||
Lecturer lecturer = this.lecturerService.getLecturer(lecturerTitle, lecturerName, lecturerSurname)
|
||||
.orElseGet(() -> this.lecturerService
|
||||
.save(new Lecturer(lecturerTitle, lecturerName, lecturerSurname)));
|
||||
|
||||
Groups group = groupService.find(time, capacity, room);
|
||||
Groups group = this.groupService.find(zajCykId, grNr).orElseGet(
|
||||
() -> new Groups(capacity, room, course, time, groupDay, lecturer, zajCykId, grNr, typeGroup));
|
||||
group.update(capacity, room, course, time, null, groupDay, lecturer, typeGroup);
|
||||
|
||||
Course course = this.courseService.getCourseByName(course_name);
|
||||
|
||||
if (course == null) {
|
||||
course = new Course();
|
||||
course.setName(course_name);
|
||||
course.setSymbol(sym_str);
|
||||
}
|
||||
|
||||
courseService.save(course);
|
||||
|
||||
if (title_cell != null) {
|
||||
lecturer_title = title_cell.toString().trim();
|
||||
}
|
||||
if (name_cell != null) {
|
||||
lecturer_name = name_cell.toString().trim();
|
||||
}
|
||||
if (surname_cell != null) {
|
||||
lecturer_surname = surname_cell.toString().trim();
|
||||
}
|
||||
|
||||
Lecturer lecturer = lecturerService.getLecturer(lecturer_title, lecturer_name, lecturer_surname);
|
||||
|
||||
if (lecturer == null) {
|
||||
lecturer = new Lecturer(lecturer_title, lecturer_name, lecturer_surname);
|
||||
lecturerService.save(lecturer);
|
||||
}
|
||||
|
||||
if (group == null) {
|
||||
group = new Groups();
|
||||
group.setCapacity(capacity);
|
||||
group.setRoom(room);
|
||||
group.setCourseId(course);
|
||||
group.setTime(time);
|
||||
if (capacity >= 50) {
|
||||
group.setType(GroupType.LECTURE);
|
||||
} else {
|
||||
group.setType(GroupType.CLASS);
|
||||
}
|
||||
group.setDay(group_day);
|
||||
group.setLecturer(lecturer);
|
||||
|
||||
groupService.save(group);
|
||||
}
|
||||
this.groupService.save(group);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Integer parseTimeToInt(String time) {
|
||||
String times[] = time.split("\\.");
|
||||
if (times.length == 2) {
|
||||
return Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]);
|
||||
}
|
||||
times = time.split("\\:");
|
||||
if (times.length == 2) {
|
||||
return Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]);
|
||||
}
|
||||
private static int parseTimeToInt(String time) {
|
||||
String times[] = time.split("\\.|\\:");
|
||||
return times.length == 2 ? Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]) : 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
171
buisnesslogic/src/main/java/com/plannaplan/entities/AppConfig.java
Executable file
171
buisnesslogic/src/main/java/com/plannaplan/entities/AppConfig.java
Executable file
@ -0,0 +1,171 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDate;
|
||||
import java.util.TimeZone;
|
||||
|
||||
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;
|
||||
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* get cron expression of first tour end
|
||||
*
|
||||
* @return spring cron expression
|
||||
*/
|
||||
public CronTrigger getFirstTourEndCron() {
|
||||
return getCron(this.firstTourEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* get cron expression of second tour end
|
||||
*
|
||||
* @return spring cron expression
|
||||
*/
|
||||
public CronTrigger getSecondTourEndCron() {
|
||||
return getCron(this.secondTourEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* get cron expression of first tour start
|
||||
*
|
||||
* @return spring cron expression
|
||||
*/
|
||||
public CronTrigger getFirstTourStartCron() {
|
||||
return getCron(this.firstTourStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* get cron expression of second tour start
|
||||
*
|
||||
* @return spring cron expression
|
||||
*/
|
||||
public CronTrigger getSecondTourStartCron() {
|
||||
return getCron(this.secondTourStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* create spring cron expression
|
||||
*
|
||||
* @param date date to create cron exp from
|
||||
* @return spring cron expression. Remember that spring's cron deosn't contain
|
||||
* year in it.
|
||||
*/
|
||||
private CronTrigger getCron(Date date) {
|
||||
final LocalDate tourEnd = date.toLocalDate();
|
||||
return new CronTrigger("0 0 0 " + tourEnd.getDayOfMonth() + " " + tourEnd.getMonthValue() + " ?",
|
||||
TimeZone.getTimeZone(TimeZone.getDefault().getID()));
|
||||
}
|
||||
|
||||
}
|
90
buisnesslogic/src/main/java/com/plannaplan/entities/Assignment.java
Normal file → Executable file
90
buisnesslogic/src/main/java/com/plannaplan/entities/Assignment.java
Normal file → Executable file
@ -7,6 +7,12 @@ import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
/**
|
||||
* Entity of Assignment grouping of state associated about group_id and
|
||||
* commision_id
|
||||
*
|
||||
*/
|
||||
|
||||
@Entity
|
||||
public class Assignment {
|
||||
@Id
|
||||
@ -16,9 +22,89 @@ public class Assignment {
|
||||
@JoinColumn(name = "group_id")
|
||||
private Groups group;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id")
|
||||
private User user;
|
||||
@JoinColumn(name = "commision_id")
|
||||
private Commision commision;
|
||||
private boolean isPastAssignment;
|
||||
|
||||
/**
|
||||
* Assignment
|
||||
*
|
||||
* @param group group we would like to assign
|
||||
* @param commision commision that assignment belongs to
|
||||
* @param isPastAssignment is assignment past or no
|
||||
*/
|
||||
public Assignment(Groups group, Commision commision, boolean isPastAssignment) {
|
||||
this.commision = commision;
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* If it returns trues it mesans u are assigned to group accepted by algorythm
|
||||
*
|
||||
* @return boolean isAccepted
|
||||
*/
|
||||
public boolean isAccepted() {
|
||||
return this.group.getRegisteredStudents().contains(this.commision.getCommisionOwner());
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter of commision
|
||||
* @return Commision Commision of given assignments
|
||||
*/
|
||||
public Commision getCommision(){
|
||||
return this.commision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignment
|
||||
*
|
||||
* @param group group we would like to assign
|
||||
* @param commision commision that assignment belongs to
|
||||
*/
|
||||
public Assignment(Groups group, Commision commision) {
|
||||
this(group, commision, false);
|
||||
}
|
||||
|
||||
public Assignment() {
|
||||
}
|
||||
|
||||
public void setCommision(Commision commision) {
|
||||
this.commision = commision;
|
||||
}
|
||||
/**
|
||||
* Id getter
|
||||
*
|
||||
* @return id id of assignment
|
||||
*/
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* getGroup
|
||||
*
|
||||
* @return group
|
||||
*/
|
||||
public Groups getGroup() {
|
||||
return this.group;
|
||||
}
|
||||
|
||||
/**
|
||||
* isPastAssignment getter
|
||||
*
|
||||
* @return isPastAssignment
|
||||
*/
|
||||
public boolean isPastAssignment() {
|
||||
return isPastAssignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* setter isPastAssignment
|
||||
*
|
||||
* @param isPastAssignment is assignment past or not
|
||||
*/
|
||||
public void setPastAssignment(boolean isPastAssignment) {
|
||||
this.isPastAssignment = isPastAssignment;
|
||||
}
|
||||
}
|
105
buisnesslogic/src/main/java/com/plannaplan/entities/Commision.java
Executable file
105
buisnesslogic/src/main/java/com/plannaplan/entities/Commision.java
Executable file
@ -0,0 +1,105 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
/**
|
||||
* Entity of Commision grouping of state associated about commison and owner_id
|
||||
*/
|
||||
|
||||
@Entity
|
||||
public class Commision {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@OneToOne
|
||||
@JoinColumn(name = "owner_id")
|
||||
private User commisionOwner;
|
||||
@OneToOne
|
||||
@JoinColumn(name = "commiter_id")
|
||||
private User commisionCommiter;
|
||||
private Timestamp commisionDate;
|
||||
|
||||
@OneToMany(mappedBy = "commision", fetch = FetchType.EAGER)
|
||||
private List<Assignment> assignments;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param user owner of commission. Can not be null otherwise saving commision
|
||||
* will fail.
|
||||
*/
|
||||
public Commision(User user) {
|
||||
this.commisionDate = new Timestamp(System.currentTimeMillis());
|
||||
this.commisionOwner = user;
|
||||
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() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Id getter
|
||||
*
|
||||
* @return id id of commision
|
||||
*/
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* CommisionDate getter
|
||||
*
|
||||
* @return commisionDate
|
||||
*/
|
||||
public Timestamp getCommisionDate() {
|
||||
return commisionDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* User of given commision getter
|
||||
*
|
||||
* @return User commisionOwner
|
||||
*/
|
||||
public User getCommisionOwner() {
|
||||
return commisionOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User entity that created commision (can be owner or deanery user)
|
||||
*/
|
||||
public User getCommisionCommiter() {
|
||||
if (commisionCommiter == null) {
|
||||
return commisionOwner;
|
||||
}
|
||||
return commisionCommiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigments getter
|
||||
*
|
||||
* @return List of assignments
|
||||
*/
|
||||
public List<Assignment> getAssignments() {
|
||||
return this.assignments;
|
||||
}
|
||||
|
||||
}
|
41
buisnesslogic/src/main/java/com/plannaplan/entities/Course.java
Normal file → Executable file
41
buisnesslogic/src/main/java/com/plannaplan/entities/Course.java
Normal file → Executable file
@ -10,6 +10,10 @@ import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
/**
|
||||
* Entity of Course grouping of state of course
|
||||
*/
|
||||
|
||||
@Entity
|
||||
public class Course {
|
||||
@Id
|
||||
@ -17,32 +21,67 @@ public class Course {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String symbol;
|
||||
@OneToMany(mappedBy = "courseId", fetch = FetchType.EAGER)
|
||||
@OneToMany(mappedBy = "course", fetch = FetchType.EAGER)
|
||||
private List<Groups> groups = new ArrayList<>();
|
||||
|
||||
public Course() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Course
|
||||
*
|
||||
* @param name name given to the course
|
||||
* @param symbol symbol given to the course
|
||||
*/
|
||||
public Course(String name, String symbol) {
|
||||
this.name = name;
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* getId
|
||||
* @return id
|
||||
*/
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* getName
|
||||
* @return name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* getSymbol
|
||||
* @return symbol
|
||||
*/
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* setSymbol
|
||||
* @param symbol set symbol in the course
|
||||
*/
|
||||
public void setSymbol(String symbol) {
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* setName
|
||||
* @param name set name in the course
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* getGroups
|
||||
* @return groups return list groups
|
||||
*/
|
||||
public List<Groups> getGroups() {
|
||||
return this.groups;
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
import com.plannaplan.types.EventTypes;
|
||||
|
||||
@Entity
|
||||
public class Event {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
private EventTypes type;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id")
|
||||
private User user;
|
||||
|
||||
public Event() {
|
||||
}
|
||||
|
||||
public EventTypes getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(EventTypes type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
102
buisnesslogic/src/main/java/com/plannaplan/entities/Exchange.java
Executable file
102
buisnesslogic/src/main/java/com/plannaplan/entities/Exchange.java
Executable file
@ -0,0 +1,102 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
/**
|
||||
* Entity that keeps user exchange offer.
|
||||
*/
|
||||
@Entity
|
||||
public class Exchange {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "owned_id")
|
||||
private Assignment ownedAssignment;
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "desired_id")
|
||||
private Groups desiredAssignment;
|
||||
|
||||
private Long ownerId;
|
||||
|
||||
private Timestamp dateExchange;
|
||||
|
||||
public Exchange(){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Long ID of exchange trader
|
||||
*/
|
||||
public Long getOwnerId() {
|
||||
return ownerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ownerId ID of exchange trader
|
||||
*/
|
||||
public void setOwnerId(Long ownerId) {
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
|
||||
public Timestamp getDataExchange() {
|
||||
return this.dateExchange;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ownedAssignment Assignment which owner would like to trade
|
||||
* @param desiredAssignment Groups instance that trader wants
|
||||
*/
|
||||
public Exchange(Assignment ownedAssignment, Groups desiredAssignment) {
|
||||
this.ownedAssignment = ownedAssignment;
|
||||
this.desiredAssignment = desiredAssignment;
|
||||
this.ownerId = this.ownedAssignment != null ? this.ownedAssignment.getCommision().getCommisionOwner().getId() : null;
|
||||
this.dateExchange = new Timestamp(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Long ID in database
|
||||
*/
|
||||
public Long getId(){
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Groups Target group
|
||||
*/
|
||||
public Groups getDesiredAssignment() {
|
||||
return desiredAssignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param desiredAssignment Target group
|
||||
*/
|
||||
public void setDesiredAssignment(Groups desiredAssignment) {
|
||||
this.desiredAssignment = desiredAssignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Assignment Owned assignment
|
||||
*/
|
||||
public Assignment getOwnedAssignment() {
|
||||
return ownedAssignment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ownedAssignment Owned assignment
|
||||
*/
|
||||
public void setOwnedAssignment(Assignment ownedAssignment) {
|
||||
this.ownedAssignment = ownedAssignment;
|
||||
}
|
||||
}
|
315
buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java
Normal file → Executable file
315
buisnesslogic/src/main/java/com/plannaplan/entities/Groups.java
Normal file → Executable file
@ -1,24 +1,37 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
import com.plannaplan.types.GroupType;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
/**
|
||||
* Entity of Groups grouping of state ssociated about
|
||||
* course,time,room,capacity,type,day
|
||||
*/
|
||||
|
||||
@Entity
|
||||
public class Groups {
|
||||
private static final int DEFAULT_CLASS_TIME = 90;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "course_id")
|
||||
private Course courseId;
|
||||
private Course course;
|
||||
private int time;
|
||||
private int endTime;
|
||||
private String room;
|
||||
private int capacity;
|
||||
private GroupType type;
|
||||
@ -26,70 +39,351 @@ public class Groups {
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "lecturer_id")
|
||||
private Lecturer lecturer;
|
||||
private Integer zajCykId;
|
||||
private Integer grNr;
|
||||
@ManyToMany(mappedBy = "studentRegisteredGrups", fetch = FetchType.EAGER)
|
||||
private Set<User> registeredStudents;
|
||||
|
||||
public Set<User> getRegisteredStudents() {
|
||||
return this.registeredStudents;
|
||||
}
|
||||
|
||||
public void assignUser(User user) {
|
||||
if (this.registeredStudents == null) {
|
||||
this.registeredStudents = new HashSet<>();
|
||||
}
|
||||
this.registeredStudents.add(user);
|
||||
}
|
||||
|
||||
public Groups() {
|
||||
}
|
||||
|
||||
public Integer getGrNr() {
|
||||
return grNr;
|
||||
}
|
||||
|
||||
public void setGrNr(Integer grNr) {
|
||||
this.grNr = grNr;
|
||||
}
|
||||
|
||||
public Integer getZajCykId() {
|
||||
return zajCykId;
|
||||
}
|
||||
|
||||
public void setZajCykId(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 grNr Number of class/course
|
||||
* @param type type of class/cource
|
||||
*/
|
||||
public Groups(int capacity, String room, Course course, int time, int endTime, WeekDay day, Lecturer lecturer,
|
||||
Integer zajCykId, Integer grNr, GroupType type) {
|
||||
this(capacity, room, course, time, endTime, day, lecturer, zajCykId, grNr);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups
|
||||
*
|
||||
* @param capacity capacity given to the groups
|
||||
* @param room room given to the groups
|
||||
* @param course course given to the groups
|
||||
* @param time time given to the groups
|
||||
* @param day day given to the groups
|
||||
* @param lecturer lecturer given to the groups
|
||||
* @param zajCykId number of class in the term
|
||||
* @param grNr Number of class/course
|
||||
* @param type type of class/cource
|
||||
*/
|
||||
public Groups(int capacity, String room, Course course, int time, WeekDay day, Lecturer lecturer,
|
||||
Integer zajCykId, Integer grNr, GroupType type) {
|
||||
this(capacity, room, course, time, time + DEFAULT_CLASS_TIME, day, lecturer, zajCykId, grNr);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 grNr 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
|
||||
*
|
||||
* @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
|
||||
* @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) {
|
||||
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
|
||||
* @param type type given to the groups
|
||||
*/
|
||||
public void update(Integer capacity, String room, Course course, Integer time, Integer endTime, WeekDay day,
|
||||
Lecturer lecturer, GroupType type) {
|
||||
if (capacity != null) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
if (room != null) {
|
||||
this.room = room;
|
||||
}
|
||||
|
||||
if (course != null) {
|
||||
this.course = course;
|
||||
}
|
||||
|
||||
if (time != null) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
if (endTime != null) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
if (day != null) {
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
if (lecturer != null) {
|
||||
this.lecturer = lecturer;
|
||||
}
|
||||
|
||||
if (type != null) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get time of class end
|
||||
*
|
||||
* @return hour of class finish time in minutes
|
||||
*/
|
||||
public int getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* getId
|
||||
*
|
||||
* @return id
|
||||
*/
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* getLecturer
|
||||
*
|
||||
* @return lecturer
|
||||
*/
|
||||
public Lecturer getLecturer() {
|
||||
return lecturer;
|
||||
}
|
||||
|
||||
/**
|
||||
* setLecturer
|
||||
*
|
||||
* @param lecturer set lecturer into groups
|
||||
*/
|
||||
public void setLecturer(Lecturer lecturer) {
|
||||
this.lecturer = lecturer;
|
||||
}
|
||||
|
||||
/**
|
||||
* WeekDay
|
||||
*
|
||||
* @return day
|
||||
*/
|
||||
public WeekDay getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
/**
|
||||
* setLecturer
|
||||
*
|
||||
* @param day set day into groups
|
||||
*/
|
||||
public void setDay(WeekDay day) {
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
/**
|
||||
* GroupType
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
public GroupType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* setType
|
||||
*
|
||||
* @param type set type into groups
|
||||
*/
|
||||
public void setType(GroupType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCapacity
|
||||
*
|
||||
* @return capacity
|
||||
*/
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* setCapacity
|
||||
*
|
||||
* @param capacity set capacity into groups
|
||||
*/
|
||||
public void setCapacity(int capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* getRoom
|
||||
*
|
||||
* @return room
|
||||
*/
|
||||
public String getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
/**
|
||||
* setRoom
|
||||
*
|
||||
* @param room set room into groups
|
||||
*/
|
||||
public void setRoom(String room) {
|
||||
this.room = room;
|
||||
}
|
||||
|
||||
/**
|
||||
* getTime
|
||||
*
|
||||
* @return time
|
||||
*/
|
||||
public int getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* setTime
|
||||
*
|
||||
* @param time set time into groups
|
||||
*/
|
||||
public void setTime(int time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCourseId
|
||||
*
|
||||
* @return course
|
||||
*/
|
||||
public Course getCourseId() {
|
||||
return courseId;
|
||||
return course;
|
||||
}
|
||||
|
||||
/**
|
||||
* setCourseId
|
||||
*
|
||||
* @param courseId set courseId into groups
|
||||
*/
|
||||
public void setCourseId(Course courseId) {
|
||||
this.courseId = courseId;
|
||||
this.course = courseId;
|
||||
}
|
||||
|
||||
/**
|
||||
* getTimeString
|
||||
*
|
||||
* @return time as formated String
|
||||
*/
|
||||
public String getTimeString() {
|
||||
int minutes = this.getTime() % 60;
|
||||
String hoursString = Integer.toString(this.getTime() / 60);
|
||||
@ -99,4 +393,19 @@ public class Groups {
|
||||
}
|
||||
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,25 +0,0 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
public class HistoryElement {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id")
|
||||
private User user;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "incoming_id")
|
||||
private Groups incoming;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "outcoming_id")
|
||||
private Groups outcoming;
|
||||
|
||||
}
|
88
buisnesslogic/src/main/java/com/plannaplan/entities/Lecturer.java
Normal file → Executable file
88
buisnesslogic/src/main/java/com/plannaplan/entities/Lecturer.java
Normal file → Executable file
@ -5,6 +5,10 @@ import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* Entity of Lecturer grouping of state ssociated about id,title,name,surname
|
||||
*/
|
||||
|
||||
@Entity
|
||||
public class Lecturer {
|
||||
@Id
|
||||
@ -14,30 +18,14 @@ public class Lecturer {
|
||||
private String name;
|
||||
private String surname;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lecturer
|
||||
*
|
||||
* @param title title given to the lecturer
|
||||
* @param name name given to the lecturer
|
||||
* @param surname surname given to the lecturer
|
||||
*/
|
||||
public Lecturer(String title, String name, String surname) {
|
||||
this.title = title;
|
||||
this.name = name;
|
||||
@ -47,6 +35,60 @@ public class Lecturer {
|
||||
public Lecturer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* getTitle
|
||||
* @return title
|
||||
*
|
||||
*/
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* getSurname
|
||||
* @return surname
|
||||
*
|
||||
*/
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
/**
|
||||
* setSurname
|
||||
* @param surname set surname to the lecturer
|
||||
*
|
||||
*/
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
/**
|
||||
* getName
|
||||
* @return name
|
||||
*
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* setName
|
||||
* @param name set name to the lecturer
|
||||
*
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* setTitle
|
||||
* @param title set title to the lecturer
|
||||
*
|
||||
*/
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s %s %s", this.title, this.name, this.surname);
|
||||
|
@ -1,28 +0,0 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
public class Transfer {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "owner_id")
|
||||
private User ownerUser;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "group_id")
|
||||
private Groups ownerGroup;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "target_id")
|
||||
private Groups targetGroup;
|
||||
|
||||
public Transfer() {
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
public class Unavailability {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id")
|
||||
private User lecturer;
|
||||
private int time;
|
||||
|
||||
public Unavailability() {
|
||||
}
|
||||
|
||||
public int getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(int time) {
|
||||
this.time = time;
|
||||
}
|
||||
}
|
222
buisnesslogic/src/main/java/com/plannaplan/entities/User.java
Normal file → Executable file
222
buisnesslogic/src/main/java/com/plannaplan/entities/User.java
Normal file → Executable file
@ -1,71 +1,279 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import java.sql.Date;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
|
||||
import com.plannaplan.models.UserApiResponse;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
/**
|
||||
* Entity of User grouping of state ssociated about
|
||||
* id,name,surname,email,role,token,tokenCreatedDate
|
||||
*/
|
||||
|
||||
@Entity
|
||||
public class User {
|
||||
private static final float TOKEN_EXPIRE_MINUTES = 15;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
private String name;
|
||||
private String surname;
|
||||
private String email;
|
||||
private String usosId;
|
||||
private UserRoles role;
|
||||
private String token;
|
||||
private Date tokenCreatedDate;
|
||||
private String refreshToken;
|
||||
private Timestamp tokenUsageDate;
|
||||
private Integer ranking;
|
||||
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JoinTable
|
||||
private Set<Groups> studentRegisteredGrups;
|
||||
|
||||
public Set<Groups> getStudentRegisteredGrups() {
|
||||
return this.studentRegisteredGrups;
|
||||
}
|
||||
|
||||
public void removeGroup(Long id) {
|
||||
final Groups groupToDelete = this.studentRegisteredGrups.stream().filter(e -> e.getId().equals(id)).findFirst().get();
|
||||
this.studentRegisteredGrups.remove(groupToDelete);
|
||||
}
|
||||
|
||||
public void claimGroup(Groups group) {
|
||||
if (this.studentRegisteredGrups == null) {
|
||||
this.studentRegisteredGrups = new HashSet<>();
|
||||
}
|
||||
this.studentRegisteredGrups.add(group);
|
||||
}
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name name given to the user
|
||||
* @param surname surname given to the user
|
||||
* @param mail mail given to the user
|
||||
* @param role user's role
|
||||
*/
|
||||
public User(String name, String surname, String mail, UserRoles role) {
|
||||
this.name = name;
|
||||
this.surname = surname;
|
||||
this.email = mail;
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name name given to the user
|
||||
* @param surname surname given to the user
|
||||
* @param mail mail given to the user
|
||||
* @param usosId id in the USOS system
|
||||
* @param role user's role
|
||||
*/
|
||||
public User(String name, String surname, String mail, String usosId, UserRoles role) {
|
||||
this(name, surname, mail, role);
|
||||
this.usosId = usosId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name name given to the user
|
||||
* @param surname surname given to the user
|
||||
* @param mail mail given to the user
|
||||
* @param usosId id in the USOS system
|
||||
* @param role user's role
|
||||
* @param ranking ranking points [100;500]. It's calculated by
|
||||
* gradesAvg*100*studiesYear
|
||||
*/
|
||||
public User(String name, String surname, String mail, String usosId, UserRoles role, Integer ranking) {
|
||||
this(name, surname, mail, usosId, role);
|
||||
this.ranking = ranking;
|
||||
}
|
||||
|
||||
/**
|
||||
* usos id getter
|
||||
*
|
||||
* @return usosid
|
||||
*/
|
||||
public String getUsosId() {
|
||||
return usosId;
|
||||
}
|
||||
|
||||
/**
|
||||
* email getter
|
||||
*
|
||||
* @return mailof user
|
||||
*/
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
/**
|
||||
* email setter
|
||||
*
|
||||
* @param email user email
|
||||
*/
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Date getTokenCreatedDate() {
|
||||
return tokenCreatedDate;
|
||||
/**
|
||||
* token usage getter
|
||||
*
|
||||
* @return Timestamp when token was used
|
||||
*/
|
||||
public Timestamp getTokenUsageDate() {
|
||||
return tokenUsageDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* token getter
|
||||
*
|
||||
* @return user token
|
||||
*/
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.tokenCreatedDate = new Date(System.currentTimeMillis());
|
||||
this.token = token;
|
||||
/**
|
||||
* @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 token to set
|
||||
*/
|
||||
public void setToken(String token) {
|
||||
this.tokenUsageDate = new Timestamp(System.currentTimeMillis());
|
||||
this.token = token;
|
||||
this.refreshToken = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* name setter
|
||||
*
|
||||
* @return String user name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* user rolse getter
|
||||
*
|
||||
* @return UserRoles of user
|
||||
*/
|
||||
public UserRoles getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
/**
|
||||
* user role setter
|
||||
*
|
||||
* @param role to be set
|
||||
*/
|
||||
public void setRole(UserRoles role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
/**
|
||||
* surname getter
|
||||
*
|
||||
* @return string surname
|
||||
*/
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
/**
|
||||
* surname setter
|
||||
*
|
||||
* @param surname string to be set as surnames
|
||||
*/
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
/**
|
||||
* name stter
|
||||
*
|
||||
* @param name stirng to be set as name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* id getter
|
||||
*
|
||||
* @return id in database
|
||||
*/
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ranking points are [100;500]. It's calculated by gradesAvg*100*studiesYear
|
||||
*
|
||||
* @return ranking points [100;500]
|
||||
*/
|
||||
public Integer getRanking() {
|
||||
return ranking;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ranking points setter. Ranking points are [100;500]. It's calculated by
|
||||
* gradesAvg*100*studiesYear
|
||||
*
|
||||
* @param ranking ranking points [100;500]
|
||||
*/
|
||||
public void setRanking(Integer ranking) {
|
||||
this.ranking = ranking;
|
||||
}
|
||||
|
||||
/**
|
||||
* updates user entity with data got by UsosApiService::getUserData
|
||||
*
|
||||
* @param usosData UserApiResponse model with needed data
|
||||
*/
|
||||
public void updateWithUsosData(UserApiResponse usosData) {
|
||||
this.name = usosData.getName();
|
||||
this.surname = usosData.getSurname();
|
||||
}
|
||||
|
||||
/**
|
||||
* it checks if given ammount of time passed since last token usage. If not
|
||||
* 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() {
|
||||
final long diffInMilliseconds = Math
|
||||
.abs(this.tokenUsageDate.getTime() - new Timestamp(System.currentTimeMillis()).getTime());
|
||||
final long minutes = TimeUnit.MILLISECONDS.toMinutes(diffInMilliseconds);
|
||||
|
||||
if (minutes > TOKEN_EXPIRE_MINUTES) {
|
||||
return false;
|
||||
}
|
||||
this.tokenUsageDate = new Timestamp(System.currentTimeMillis());
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.plannaplan.exceptions;
|
||||
|
||||
public class TokenExpiredException extends RuntimeException {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public TokenExpiredException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
0
buisnesslogic/src/main/java/com/plannaplan/exceptions/UserNotFoundException.java
Normal file → Executable file
0
buisnesslogic/src/main/java/com/plannaplan/exceptions/UserNotFoundException.java
Normal file → Executable file
@ -1,5 +0,0 @@
|
||||
package com.plannaplan.interfaces;
|
||||
|
||||
public interface EventCreator {
|
||||
void update();
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.plannaplan.interfaces;
|
||||
|
||||
public interface Historable {
|
||||
void addActionToHistory();
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.plannaplan.interfaces;
|
||||
|
||||
public interface ProtectedAction {
|
||||
void validateAction();
|
||||
}
|
49
buisnesslogic/src/main/java/com/plannaplan/models/ConfigData.java
Normal file → Executable file
49
buisnesslogic/src/main/java/com/plannaplan/models/ConfigData.java
Normal file → Executable file
@ -1,29 +1,50 @@
|
||||
package com.plannaplan.models;
|
||||
|
||||
import java.util.Date;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ConfigData {
|
||||
private Date start;
|
||||
private Date end;
|
||||
private TourData firstTour;
|
||||
private TourData secondTour;
|
||||
private InputStream filestream;
|
||||
|
||||
public ConfigData(Date start, Date end, InputStream filestream) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
* @param firstTour date of first tours
|
||||
* @param secondTour date of second tours
|
||||
* @param filestream filestram with data to import
|
||||
*/
|
||||
public ConfigData(TourData firstTour, TourData secondTour, InputStream filestream) {
|
||||
this.firstTour = firstTour;
|
||||
this.secondTour = secondTour;
|
||||
this.filestream = filestream;
|
||||
}
|
||||
|
||||
/**
|
||||
* second tour getter
|
||||
*
|
||||
* @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() {
|
||||
return filestream;
|
||||
}
|
||||
|
||||
public Date getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public Date getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
}
|
97
buisnesslogic/src/main/java/com/plannaplan/models/EmailAcceptedData.java
Executable file
97
buisnesslogic/src/main/java/com/plannaplan/models/EmailAcceptedData.java
Executable file
@ -0,0 +1,97 @@
|
||||
package com.plannaplan.models;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
|
||||
/**
|
||||
* Instance to keep data to send in mail about accepted courses results
|
||||
*/
|
||||
public class EmailAcceptedData {
|
||||
private List<Groups> accepted;
|
||||
private List<Groups> removed;
|
||||
|
||||
public EmailAcceptedData() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* creates instance of class
|
||||
*
|
||||
* @param accepted list of groups that user joined to
|
||||
* @param removed lsit of groups that user failed to join
|
||||
*/
|
||||
public EmailAcceptedData(List<Groups> accepted, List<Groups> removed) {
|
||||
this.accepted = accepted;
|
||||
this.removed = removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* get list of removed assignments
|
||||
*
|
||||
* @return removed assingments
|
||||
*/
|
||||
public List<Groups> getRemoved() {
|
||||
return removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* set list of removed assignments
|
||||
*
|
||||
* @param removed list of removed assignments
|
||||
*/
|
||||
public void setRemoved(List<Groups> removed) {
|
||||
this.removed = removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* get list of accepted assignments
|
||||
*
|
||||
* @return accepted assingments
|
||||
*/
|
||||
public List<Groups> getAccepted() {
|
||||
return accepted;
|
||||
}
|
||||
|
||||
/**
|
||||
* set list of accepted assignments
|
||||
*
|
||||
* @param accepted list of accepted assignments
|
||||
*/
|
||||
public void setAccepted(List<Groups> accepted) {
|
||||
this.accepted = accepted;
|
||||
}
|
||||
|
||||
/**
|
||||
* it creates and return email message body
|
||||
*
|
||||
* @return string with emiale massage
|
||||
*/
|
||||
public String getEmailMessage() {
|
||||
String response = "Akceptacja Twoich przedmiotów właśnie dobiegła końca.\n\n";
|
||||
if (this.accepted != null && this.accepted.size() > 0) {
|
||||
response += "Zatwierdzone grupy: \n";
|
||||
Iterator<Groups> iterator = accepted.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Groups gorup = iterator.next();
|
||||
final String courseName = gorup.getCourseId() != null ? gorup.getCourseId().getName()
|
||||
: "Nieznana grupa";
|
||||
response += (" - " + courseName + " - " + gorup.getType() + "\n");
|
||||
}
|
||||
|
||||
}
|
||||
if (this.removed != null && this.removed.size() > 0) {
|
||||
response += "Usunięte grupy: \n";
|
||||
Iterator<Groups> iterator = removed.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Groups gorup = iterator.next();
|
||||
final String courseName = gorup.getCourseId() != null ? gorup.getCourseId().getName()
|
||||
: "Nieznana grupa";
|
||||
response += (" - " + courseName + " - " + gorup.getType() + "\n");
|
||||
}
|
||||
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
45
buisnesslogic/src/main/java/com/plannaplan/models/EmailExchangesData.java
Executable file
45
buisnesslogic/src/main/java/com/plannaplan/models/EmailExchangesData.java
Executable file
@ -0,0 +1,45 @@
|
||||
package com.plannaplan.models;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.plannaplan.entities.Exchange;
|
||||
import com.plannaplan.entities.User;
|
||||
|
||||
/**
|
||||
* Class to keepm data to be send after exchanges being accept
|
||||
*/
|
||||
public class EmailExchangesData {
|
||||
private Map<Long, List<Exchange>> data;
|
||||
|
||||
public EmailExchangesData() {
|
||||
this.data = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* method to add user and his event to data to be send
|
||||
*
|
||||
* @param user owner of exchange being performed
|
||||
* @param data exchange that was executed
|
||||
*/
|
||||
public void addExchange(User user, Exchange data) {
|
||||
final Long id = user.getId();
|
||||
if (this.data.get(id) == null) {
|
||||
this.data.put(id, new ArrayList<>());
|
||||
}
|
||||
this.data.get(id).add(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* get datas entry set
|
||||
*
|
||||
* @return set with entries that contains Long that is user id and list of hiss
|
||||
* performed Exchanges
|
||||
*/
|
||||
public Set<Map.Entry<Long, List<Exchange>>> getDataEntry() {
|
||||
return this.data.entrySet();
|
||||
}
|
||||
}
|
42
buisnesslogic/src/main/java/com/plannaplan/models/FileData.java
Normal file → Executable file
42
buisnesslogic/src/main/java/com/plannaplan/models/FileData.java
Normal file → Executable file
@ -1,36 +1,62 @@
|
||||
package com.plannaplan.models;
|
||||
|
||||
import java.util.Dictionary;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
|
||||
public class FileData {
|
||||
|
||||
private Dictionary<String, Integer> keys;
|
||||
private HashMap<String, Integer> keys;
|
||||
private Iterator<Row> rows;
|
||||
|
||||
public FileData(Dictionary<String, Integer> keys, Iterator<Row> rows) {
|
||||
this.setKeys(keys);
|
||||
this.setRows(rows);
|
||||
/*
|
||||
* FileData
|
||||
*
|
||||
* @param keys this is a hashmap of String and Integer
|
||||
* @param rows this is a iterator of rows.
|
||||
*/
|
||||
public FileData(HashMap<String, Integer> keys, Iterator<Row> rows) {
|
||||
this.keys = keys;
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
/*
|
||||
* getRows
|
||||
*
|
||||
* @return rows
|
||||
*/
|
||||
public Iterator<Row> getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
/*
|
||||
* setRows
|
||||
* @param rows set the rows to given function
|
||||
*/
|
||||
public void setRows(Iterator<Row> rows) {
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
public Dictionary<String, Integer> getKeys() {
|
||||
/*
|
||||
* getKeys
|
||||
* @return keys
|
||||
*/
|
||||
public HashMap<String, Integer> getKeys() {
|
||||
return keys;
|
||||
}
|
||||
|
||||
public void setKeys(Dictionary<String, Integer> keys) {
|
||||
/*
|
||||
* setKeys
|
||||
* @param keys set the key is being a struck of hashmap (String, Integer)
|
||||
*/
|
||||
public void setKeys(HashMap<String, Integer> keys) {
|
||||
this.keys = keys;
|
||||
}
|
||||
|
||||
/*
|
||||
* getIndexOf
|
||||
* @return index
|
||||
*/
|
||||
public int getIndexOf(String key) {
|
||||
int index = this.keys.get(key);
|
||||
return index;
|
||||
|
66
buisnesslogic/src/main/java/com/plannaplan/models/MatchData.java
Executable file
66
buisnesslogic/src/main/java/com/plannaplan/models/MatchData.java
Executable file
@ -0,0 +1,66 @@
|
||||
package com.plannaplan.models;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Exchange;
|
||||
|
||||
public class MatchData {
|
||||
private Exchange exchangeOne;
|
||||
private Exchange exchangeTwo;
|
||||
|
||||
public MatchData(Exchange exchangeOne, Exchange exchangeTwo) {
|
||||
this.exchangeOne = exchangeOne;
|
||||
this.exchangeTwo = exchangeTwo;
|
||||
}
|
||||
|
||||
public Exchange getExchangeOne() {
|
||||
return this.exchangeOne;
|
||||
}
|
||||
|
||||
public Exchange getExchangeTwo() {
|
||||
return this.exchangeTwo;
|
||||
}
|
||||
|
||||
public Assignment getAssignmentTwo() {
|
||||
return this.exchangeTwo.getOwnedAssignment();
|
||||
}
|
||||
|
||||
public Assignment getAssignmentOne() {
|
||||
return this.exchangeOne.getOwnedAssignment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.getAssignmentOne().hashCode() + this.getAssignmentTwo().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
// If the object is compared with itself then return true
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if o is an instance of Complex or not "null instanceof [type]" also
|
||||
* returns false
|
||||
*/
|
||||
if (!(o instanceof MatchData)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// typecast o to Complex so that we can compare data members
|
||||
MatchData c = (MatchData) o;
|
||||
|
||||
// Compare the data members and return accordingly
|
||||
return (this.getAssignmentOne().equals(c.getAssignmentOne()) && this.getAssignmentTwo().equals(c.getAssignmentTwo())) || (this.getAssignmentOne().equals(c.getAssignmentTwo()) && this.getAssignmentTwo().equals(c.getAssignmentOne()));
|
||||
}
|
||||
|
||||
public int compare(MatchData m1) {
|
||||
return Long.compare(m1.getExchangesMsValue(), this.getExchangesMsValue());
|
||||
}
|
||||
|
||||
public long getExchangesMsValue(){
|
||||
return this.exchangeOne.getDataExchange().getTime() + this.exchangeTwo.getDataExchange().getTime();
|
||||
}
|
||||
}
|
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;
|
||||
}
|
||||
}
|
29
buisnesslogic/src/main/java/com/plannaplan/models/UserApiResponse.java
Executable file
29
buisnesslogic/src/main/java/com/plannaplan/models/UserApiResponse.java
Executable file
@ -0,0 +1,29 @@
|
||||
package com.plannaplan.models;
|
||||
|
||||
/**
|
||||
* Model to keep data from /services/users/user response called in
|
||||
* UsosApiService
|
||||
*/
|
||||
public class UserApiResponse {
|
||||
private String name;
|
||||
private String surname;
|
||||
|
||||
public UserApiResponse() {
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
@ -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> {
|
||||
}
|
14
buisnesslogic/src/main/java/com/plannaplan/repositories/AssignmentRepository.java
Normal file → Executable file
14
buisnesslogic/src/main/java/com/plannaplan/repositories/AssignmentRepository.java
Normal file → Executable file
@ -1,11 +1,25 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* AssignmentRepository.getByCommision:
|
||||
* Return list of:
|
||||
* SELECT * FROM Assignment WHERE commision_id = i .
|
||||
*
|
||||
* Where i, ?1 are equale to variables.
|
||||
*/
|
||||
@Repository
|
||||
public interface AssignmentRepository extends JpaRepository<Assignment, Long> {
|
||||
|
||||
@Query("FROM Assignment WHERE commision_id = ?1")
|
||||
List<Assignment> getByCommision(@Param("commision_id") Long id);
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Commision;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* CommisionRepository.getUsers:
|
||||
* Return list of:
|
||||
* SELECT * FROM Commision WHERE owner_id = i .
|
||||
*
|
||||
* Where i, ?1 are equale to variables.
|
||||
*
|
||||
* CommisionRepository.getNewestCommision
|
||||
* Return list of:
|
||||
* SELECT * FROM Commision WHERE owner_id = i Order by commisionDate desc.
|
||||
*
|
||||
* Where i, ?1 are equale to variables.
|
||||
*/
|
||||
@Repository
|
||||
public interface CommisionRepository extends JpaRepository<Commision, Long> {
|
||||
@Query("FROM Commision WHERE owner_id = ?1")
|
||||
List<Commision> getUsers(@Param("owner_id") Long id);
|
||||
|
||||
@Query("FROM Commision WHERE owner_id = ?1 order by commisionDate desc")
|
||||
List<Commision> getNewestCommision(@Param("owner_id") Long id);
|
||||
|
||||
}
|
11
buisnesslogic/src/main/java/com/plannaplan/repositories/CourseRepository.java
Normal file → Executable file
11
buisnesslogic/src/main/java/com/plannaplan/repositories/CourseRepository.java
Normal file → Executable file
@ -1,5 +1,7 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
@ -7,8 +9,15 @@ import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* CourseRepository.findByName:
|
||||
* Return list of:
|
||||
* SELECT * FROM Course WHERE name = i .
|
||||
*
|
||||
* Where i, ?1 are equale to variables.
|
||||
*/
|
||||
@Repository
|
||||
public interface CourseRepository extends JpaRepository<Course, Long> {
|
||||
@Query("FROM Course WHERE name = ?1")
|
||||
Course findByName(@Param("name") String name);
|
||||
Optional<Course> findByName(@Param("name") String name);
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import com.plannaplan.entities.Event;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface EventRepository extends JpaRepository<Event, Long> {
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Exchange;
|
||||
import com.plannaplan.entities.Groups;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ExchangeRepository extends JpaRepository<Exchange, Long>{
|
||||
|
||||
@Query("FROM Exchange WHERE owned_id = ?1 AND desired_id = ?2")
|
||||
Optional<Exchange> checkForExchange(@Param("owned_id") Assignment assignment, @Param("desired_id") Groups group);
|
||||
|
||||
@Query("FROM Exchange WHERE ownerId = ?1")
|
||||
List<Exchange> getByUserId(@Param("id") Long id);
|
||||
|
||||
@Query("Select e1,e2 FROM Exchange e1, Exchange e2 WHERE e1.ownedAssignment.group.id = e2.desiredAssignment.id")
|
||||
List<Object[]> getMatches();
|
||||
}
|
33
buisnesslogic/src/main/java/com/plannaplan/repositories/GroupRepository.java
Normal file → Executable file
33
buisnesslogic/src/main/java/com/plannaplan/repositories/GroupRepository.java
Normal file → Executable file
@ -1,6 +1,7 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Groups;
|
||||
|
||||
@ -9,12 +10,42 @@ import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* GroupRepository.find:
|
||||
* Return list of:
|
||||
* SELECT * FROM Groups WHERE time = i AND room = j AND capacity = k .
|
||||
*
|
||||
* Where i, j, k, ?1, ?2, ?3 are equale to variables.
|
||||
*
|
||||
* GroupRepository.getByCourse:
|
||||
* Return list of:
|
||||
* SELECT * FROM Groups WHERE course_id = i .
|
||||
*
|
||||
* Where i, ?1 are equale to variables.
|
||||
*/
|
||||
@Repository
|
||||
public interface GroupRepository extends JpaRepository<Groups, Long> {
|
||||
@Query("FROM Groups WHERE time = ?1 AND room = ?2 AND capacity = ?3")
|
||||
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")
|
||||
List<Groups> getByCourse(@Param("id") Long id);
|
||||
|
||||
@Query("SELECT COUNT(*) AS assinged_times FROM Assignment WHERE isPastAssignment=false GROUP BY group HAVING group_id=?1")
|
||||
Optional<Number> getAssignedAmount(Long groupId);
|
||||
|
||||
/**
|
||||
* PLAIN SQL QUERY: SELECT group_id, COUNT(*) assinged_times FROM assignment
|
||||
* WHERE is_past_assignment=0 GROUP BY group_id HAVING group_id IN (:ids)")
|
||||
*
|
||||
* @param groupIds list of groups ids
|
||||
* @return list of objects arrays where first object is Groups instance and
|
||||
* second is Long that is taken places value
|
||||
*/
|
||||
@Query("SELECT group, COUNT(*) AS assinged_times FROM Assignment a WHERE a.isPastAssignment=false GROUP BY a.group HAVING group_id IN (:ids)")
|
||||
List<Object[]> getAssignedAmounts(@Param("ids") List<Long> groupIds);
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import com.plannaplan.entities.HistoryElement;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface HistoryRepository extends JpaRepository<HistoryElement, Long> {
|
||||
|
||||
}
|
11
buisnesslogic/src/main/java/com/plannaplan/repositories/LecturerRepository.java
Normal file → Executable file
11
buisnesslogic/src/main/java/com/plannaplan/repositories/LecturerRepository.java
Normal file → Executable file
@ -1,5 +1,7 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
@ -7,8 +9,15 @@ import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* LecturerRepository.find:
|
||||
* Return list of:
|
||||
* SELECT * FROM Lecturer WHERE title = i AND name = j AND surname = k.
|
||||
*
|
||||
* Where i, j, k, ?1, ?2, ?3 are equale to variables.
|
||||
*/
|
||||
@Repository
|
||||
public interface LecturerRepository extends JpaRepository<Lecturer, Long> {
|
||||
@Query("FROM Lecturer WHERE title = ?1 AND name = ?2 AND surname = ?3")
|
||||
Lecturer find(@Param("title") String title, @Param("name") String name, @Param("surname") String surname);
|
||||
Optional<Lecturer> find(@Param("title") String title, @Param("name") String name, @Param("surname") String surname);
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import com.plannaplan.entities.Transfer;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface TransferRepository extends JpaRepository<Transfer, Long> {
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import com.plannaplan.entities.Unavailability;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface UnavailabilityRepository extends JpaRepository<Unavailability, Long> {
|
||||
|
||||
}
|
61
buisnesslogic/src/main/java/com/plannaplan/repositories/UserRepository.java
Normal file → Executable file
61
buisnesslogic/src/main/java/com/plannaplan/repositories/UserRepository.java
Normal file → Executable file
@ -1,17 +1,74 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* UserRepository.getByAuthority: Return list of: SELECT * FROM User WHERE email
|
||||
* = i.
|
||||
*
|
||||
* Where i, ?1 are equale to variables.
|
||||
*
|
||||
* UserRepository.getByToken: Return list of: SELECT * FROM User WHERE token =
|
||||
* i.
|
||||
*
|
||||
* Where i, ?1 are equale to variables.
|
||||
*
|
||||
* UserRepository.searchForUsers: Return list of: SELECT * FROM User WHERE (name
|
||||
* LIKE %?1% OR surname LIKE %?1%).
|
||||
*
|
||||
* Where i, ?1 are equale to variables.
|
||||
*
|
||||
* UserRepository.searchForUsers with role: Return list of: SELECT * FROM User
|
||||
* WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2").
|
||||
*
|
||||
* Where i, ?1 are equale to variables.
|
||||
*/
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
/**
|
||||
* return user by given authority
|
||||
*
|
||||
* @param authority user usosId or email
|
||||
* @return optional with user if found
|
||||
*/
|
||||
@Query("FROM User WHERE email = ?1 OR usosId = ?1")
|
||||
Optional<User> getByAuthority(@Param("authority") String authority);
|
||||
|
||||
@Query("FROM User WHERE email = ?1")
|
||||
User getByAuthority(@Param("authority") String authority);
|
||||
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")
|
||||
User getByToken(@Param("token") String token);
|
||||
Optional<User> getByToken(@Param("token") String token);
|
||||
|
||||
@Query("FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%)")
|
||||
List<User> searchForUsers(@Param("query") String query);
|
||||
|
||||
/**
|
||||
* search for user with given query
|
||||
*
|
||||
* @param query string that will be matched to users name and surname
|
||||
* @param role limits results by role
|
||||
* @return list opf results
|
||||
*/
|
||||
@Query("FROM User WHERE (name LIKE %?1% OR surname LIKE %?1%) AND role=?2")
|
||||
List<User> searchForUsers(@Param("query") String query, @Param("role") UserRoles role);
|
||||
|
||||
@Query("FROM User WHERE role=?1")
|
||||
List<User> getAllByRole(@Param("role") UserRoles role);
|
||||
|
||||
@Query("FROM User WHERE usosId = ?1")
|
||||
Optional<User> getByUsosId(@Param("usosId") String usosId);
|
||||
}
|
96
buisnesslogic/src/main/java/com/plannaplan/services/AssignmentService.java
Normal file → Executable file
96
buisnesslogic/src/main/java/com/plannaplan/services/AssignmentService.java
Normal file → Executable file
@ -1,17 +1,107 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import com.plannaplan.abstracts.EventWatcher;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.models.EmailAcceptedData;
|
||||
import com.plannaplan.repositories.AssignmentRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Service of Assignment which can save assignments, diplay assignments, get
|
||||
* ammount of assigments.
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class AssignmentService extends EventWatcher {
|
||||
public class AssignmentService {
|
||||
@Autowired
|
||||
private AssignmentRepository repo;
|
||||
|
||||
@Autowired
|
||||
private CommisionService service;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
|
||||
public AssignmentService() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save given assignment
|
||||
*
|
||||
* @param assignment assignment to save
|
||||
* @return assignment saved assignment with database id
|
||||
*/
|
||||
public Assignment save(Assignment assignment) {
|
||||
return this.repo.save(assignment);
|
||||
}
|
||||
|
||||
/**
|
||||
* gets list of assignments of given commision
|
||||
*
|
||||
* @param com Commision to get assinments from
|
||||
* @return list of assignments
|
||||
*/
|
||||
public List<Assignment> getCommisionAssignments(Commision com) {
|
||||
return this.repo.getByCommision(com.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* get ammount of all assignments (not only for selected commision)
|
||||
*
|
||||
* @return long - ammount of assingments
|
||||
*/
|
||||
public long getAssignmentsAmmount() {
|
||||
return this.repo.count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get assigmnent by id
|
||||
*
|
||||
* @param id id of assigmnent
|
||||
* @return Optional of assignment
|
||||
*/
|
||||
public Optional<Assignment> getById(Long id) {
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* this method will activate accept algorythm for all students. Algorythm is
|
||||
* takeing each student in order defined by ranking and accept for him groups
|
||||
* that are joinable for him
|
||||
*/
|
||||
public void callAcceptAlgorythm() {
|
||||
final List<User> students = this.userService.getStudentsSortedByRanking();
|
||||
|
||||
students.forEach(e -> {
|
||||
final Optional<Commision> com = this.service.getNewestCommision(e);
|
||||
final List<Groups> accepted = new ArrayList<>();
|
||||
final List<Groups> removed = new ArrayList<>();
|
||||
|
||||
if (com.isPresent()) {
|
||||
final List<Assignment> assignments = this.getCommisionAssignments(com.get());
|
||||
assignments.forEach(a -> {
|
||||
final Groups group = a.getGroup();
|
||||
if (group.getCapacity() > group.getRegisteredStudents().size()) {
|
||||
e.claimGroup(group);
|
||||
accepted.add(group);
|
||||
} else {
|
||||
removed.add(group);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.userService.save(e);
|
||||
this.emailService.sendAcceptationResult(e, new EmailAcceptedData(accepted, removed));
|
||||
});
|
||||
}
|
||||
}
|
72
buisnesslogic/src/main/java/com/plannaplan/services/CommisionService.java
Executable file
72
buisnesslogic/src/main/java/com/plannaplan/services/CommisionService.java
Executable file
@ -0,0 +1,72 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.repositories.AssignmentRepository;
|
||||
import com.plannaplan.repositories.CommisionRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Service of CommisionService which can save commision, get user's commisions,
|
||||
* get newest user's commision, get ammount of commisions.
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class CommisionService {
|
||||
@Autowired
|
||||
private CommisionRepository repo;
|
||||
@Autowired
|
||||
private AssignmentRepository aRepository;
|
||||
|
||||
public CommisionService() {
|
||||
}
|
||||
|
||||
public Commision save(Commision commision) {
|
||||
Optional<Commision> lastCommision = this.getNewestCommision(commision.getCommisionOwner());
|
||||
if (lastCommision.isPresent()) {
|
||||
final Commision lastCom = lastCommision.get();
|
||||
lastCom.getAssignments().forEach(assignment -> {
|
||||
assignment.setPastAssignment(true);
|
||||
this.aRepository.save(assignment);
|
||||
});
|
||||
}
|
||||
this.repo.save(commision);
|
||||
return commision;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* gets user commisions
|
||||
*
|
||||
* @param user owner of commisions
|
||||
* @return list of user commisions
|
||||
*/
|
||||
public List<Commision> getUsersCommisions(User user) {
|
||||
return this.repo.getUsers(user.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* get newest commision ov given user
|
||||
*
|
||||
* @param user owener of commision we attemp to get
|
||||
* @return optional if commition was found
|
||||
*/
|
||||
public Optional<Commision> getNewestCommision(User user) {
|
||||
return this.repo.getNewestCommision(user.getId()).stream().findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* get ammpounts of commisions
|
||||
*
|
||||
* @return long - ammounts of commisions (all even from history, not only
|
||||
* cutrrent one)
|
||||
*/
|
||||
public long getCommisionsAmmount() {
|
||||
return this.repo.count();
|
||||
}
|
||||
}
|
137
buisnesslogic/src/main/java/com/plannaplan/services/ConfiguratorService.java
Executable file
137
buisnesslogic/src/main/java/com/plannaplan/services/ConfiguratorService.java
Executable file
@ -0,0 +1,137 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import com.plannaplan.models.ConfigData;
|
||||
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.stereotype.Component;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.configutils.*;
|
||||
import com.plannaplan.entities.AppConfig;
|
||||
|
||||
/**
|
||||
* FileReader is used for reading xls file from input stream.
|
||||
*/
|
||||
@Component
|
||||
public class ConfiguratorService {
|
||||
|
||||
@Autowired
|
||||
private FileToDatabaseMigrator migrator;
|
||||
@Autowired
|
||||
private AppConfigRepository configRepo;
|
||||
@Autowired
|
||||
private EventService eventService;
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
public ConfiguratorService() {
|
||||
}
|
||||
|
||||
/**
|
||||
* methoid to config system. it shedules PerformAcceptAlgorythmTask as a side
|
||||
* effect
|
||||
*
|
||||
* @param data ConfigData containng system configs
|
||||
*/
|
||||
public void config(ConfigData data) {
|
||||
FileReader reader = new FileReader(data.getFilestream());
|
||||
FileData coursesData = reader.read();
|
||||
final AppConfig config = new AppConfig(data.getFirstTour(), data.getSecondTour());
|
||||
this.configRepo.save(config);
|
||||
migrator.migrate(coursesData);
|
||||
this.shceduleTaskAfterToursDateChange(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save tours to DataBase and shedule PerformAcceptAlgorythmTask as a side
|
||||
* effect
|
||||
*
|
||||
* @param firstTour First tour period.
|
||||
* @param secondTour Second tour period.
|
||||
*/
|
||||
public void saveTours(TourData firstTour, TourData secondTour) {
|
||||
final AppConfig config = new AppConfig(firstTour, secondTour);
|
||||
this.configRepo.save(config);
|
||||
this.shceduleTaskAfterToursDateChange(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
private void shceduleTaskAfterToursDateChange(AppConfig config) {
|
||||
|
||||
this.eventService.scheduleTask(EventService.FIRST_TOUR_SCHEDULE,
|
||||
new AlgorythmAcceptTask(config.getFirstTourEnd()), config.getFirstTourEndCron());
|
||||
|
||||
this.eventService.scheduleTask(EventService.SECOND_TOUR_SCHEDULE,
|
||||
new AlgorythmAcceptTask(config.getSecondTourEnd()), config.getSecondTourEndCron());
|
||||
}
|
||||
|
||||
/**
|
||||
* It's local class to perform accept Task. It's needed to be here due to have
|
||||
* acces to AssignmentService.
|
||||
*/
|
||||
private class AlgorythmAcceptTask implements Runnable {
|
||||
|
||||
private LocalDate localDate;
|
||||
|
||||
/**
|
||||
* create instance of AlgorythmAcceptTask
|
||||
*
|
||||
* @param date date of algorythm perform. Needed to check if ti's being called
|
||||
* in correct year
|
||||
*/
|
||||
public AlgorythmAcceptTask(Date date) {
|
||||
this.localDate = date.toLocalDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("Performing event");
|
||||
if (localDate.getYear() == LocalDate.now().getYear()) {
|
||||
assignmentService.callAcceptAlgorythm();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
30
buisnesslogic/src/main/java/com/plannaplan/services/CourseService.java
Normal file → Executable file
30
buisnesslogic/src/main/java/com/plannaplan/services/CourseService.java
Normal file → Executable file
@ -1,6 +1,7 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Course;
|
||||
import com.plannaplan.repositories.CourseRepository;
|
||||
@ -8,27 +9,52 @@ import com.plannaplan.repositories.CourseRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Service of CourseService which can get(Course By Name, All Courses, Courses Ammount ), save, delete course.
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class CourseService {
|
||||
@Autowired
|
||||
private CourseRepository repo;
|
||||
|
||||
public Course getCourseByName(String name) {
|
||||
/*
|
||||
* getCourseByName
|
||||
* Return Course By Name
|
||||
*/
|
||||
public Optional<Course> getCourseByName(String name) {
|
||||
return this.repo.findByName(name);
|
||||
}
|
||||
|
||||
/*
|
||||
* getAllCourses
|
||||
* Return List of get courses
|
||||
*/
|
||||
public List<Course> getAllCourses() {
|
||||
return this.repo.findAll();
|
||||
}
|
||||
|
||||
public void save(Course course) {
|
||||
/*
|
||||
* save
|
||||
* @param course which course you would like to save
|
||||
*/
|
||||
public Course save(Course course) {
|
||||
this.repo.save(course);
|
||||
return course;
|
||||
}
|
||||
|
||||
/*
|
||||
* delete
|
||||
* @param course which course you would like to delete
|
||||
*/
|
||||
public void delete(Course course) {
|
||||
this.repo.delete(course);
|
||||
}
|
||||
|
||||
/*
|
||||
* getCoursesAmmount
|
||||
* Return a ammount of courses
|
||||
*/
|
||||
public int getCoursesAmmount() {
|
||||
return (int) this.repo.count();
|
||||
}
|
||||
|
101
buisnesslogic/src/main/java/com/plannaplan/services/EmailService.java
Executable file
101
buisnesslogic/src/main/java/com/plannaplan/services/EmailService.java
Executable file
@ -0,0 +1,101 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.plannaplan.entities.Exchange;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.models.EmailAcceptedData;
|
||||
import com.plannaplan.models.EmailExchangesData;
|
||||
|
||||
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;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
/**
|
||||
* sends email with infromation about accepted groups
|
||||
*
|
||||
* @param user user to send a mail
|
||||
* @param data EmailAcceptedData instance containing informations about accepted
|
||||
* and removed groups
|
||||
*/
|
||||
public void sendAcceptationResult(User user, EmailAcceptedData data) {
|
||||
SimpleMailMessage mailMessage = new SimpleMailMessage();
|
||||
mailMessage.setFrom(appEmail);
|
||||
mailMessage.setTo(user.getEmail());
|
||||
mailMessage.setSubject("[PlanNaPlan] Akceptacja przedmiotów");
|
||||
mailMessage.setText(data.getEmailMessage());
|
||||
emailSender.send(mailMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* method to send email for students whose groups were swaped
|
||||
*
|
||||
* @param data EmailExchangesData instance that contains pair of datas user and
|
||||
* list of performed exhanges
|
||||
*/
|
||||
public void sendExchangesResults(EmailExchangesData data) {
|
||||
for (Map.Entry<Long, List<Exchange>> entry : data.getDataEntry()) {
|
||||
final User user = this.userService.getById(entry.getKey()).get();
|
||||
String response = "Znaleźliśmy dla Ciebie osobę, która zamieniła się z Tobą przedmiotami!!!\n Zamienione przedmioty: \n";
|
||||
|
||||
final Iterator<Exchange> interator = entry.getValue().iterator();
|
||||
|
||||
while (interator.hasNext()) {
|
||||
final Exchange exchange = interator.next();
|
||||
final String courseFrom = exchange.getDesiredAssignment().getCourseId() != null
|
||||
? exchange.getDesiredAssignment().getCourseId().getName()
|
||||
: "Nieznane zajęcie";
|
||||
final String courseTo = exchange.getOwnedAssignment().getGroup().getCourseId() != null
|
||||
? exchange.getOwnedAssignment().getGroup().getCourseId().getName()
|
||||
: "Nieznane zajęcie";
|
||||
|
||||
response += (" - " + courseFrom + " za " + courseTo.toLowerCase());
|
||||
}
|
||||
|
||||
SimpleMailMessage mailMessage = new SimpleMailMessage();
|
||||
mailMessage.setFrom(appEmail);
|
||||
mailMessage.setTo(user.getEmail());
|
||||
mailMessage.setSubject("[PlanNaPlan] Zamiana przedmiotów");
|
||||
mailMessage.setText(response);
|
||||
emailSender.send(mailMessage);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
53
buisnesslogic/src/main/java/com/plannaplan/services/EventService.java
Normal file → Executable file
53
buisnesslogic/src/main/java/com/plannaplan/services/EventService.java
Normal file → Executable file
@ -1,12 +1,61 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import com.plannaplan.repositories.EventRepository;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class EventService {
|
||||
|
||||
@Autowired
|
||||
private EventRepository repo;
|
||||
private ExchangeService exchangeService;
|
||||
|
||||
public static final int FIRST_TOUR_SCHEDULE = 0;
|
||||
public static final int SECOND_TOUR_SCHEDULE = 1;
|
||||
|
||||
private ThreadPoolTaskScheduler scheduler;
|
||||
private Map<Integer, ScheduledFuture<?>> jobsMap = new HashMap<>();
|
||||
|
||||
@Scheduled(cron = "0 24 17 * * *")
|
||||
public void collectGroupLosses() {
|
||||
System.out.println("Checking for groups");
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 0 * * *")
|
||||
public void performExchangeService() {
|
||||
System.out.println("Performing Exchange");
|
||||
this.exchangeService.performExchange();
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule provided task to perform
|
||||
*
|
||||
* @param taskId static filed of this class that represents to what event
|
||||
* we want to assign task
|
||||
* @param task runnable class that perform task in implemented run method
|
||||
* @param cronTrigger CronTrigger instance with date to perform
|
||||
*/
|
||||
public void scheduleTask(int taskId, Runnable task, CronTrigger cronTrigger) {
|
||||
ScheduledFuture<?> scheduledTask = jobsMap.get(taskId);
|
||||
if (scheduledTask != null) {
|
||||
scheduledTask.cancel(true);
|
||||
jobsMap.put(taskId, null);
|
||||
}
|
||||
scheduledTask = this.scheduler.schedule(task, cronTrigger);
|
||||
jobsMap.put(taskId, scheduledTask);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
this.scheduler = new ThreadPoolTaskScheduler();
|
||||
this.scheduler.initialize();
|
||||
}
|
||||
}
|
143
buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java
Executable file
143
buisnesslogic/src/main/java/com/plannaplan/services/ExchangeService.java
Executable file
@ -0,0 +1,143 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Exchange;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.models.EmailExchangesData;
|
||||
import com.plannaplan.models.MatchData;
|
||||
import com.plannaplan.repositories.ExchangeRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ExchangeService {
|
||||
|
||||
@Autowired
|
||||
private ExchangeRepository repo;
|
||||
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
|
||||
/**
|
||||
* @param exchange Instance to save in database
|
||||
* @return Exchange Instance contains database id
|
||||
*/
|
||||
public Exchange save(Exchange exchange) {
|
||||
return this.repo.save(exchange);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id Id of exchange in database
|
||||
* @return Optional Exchange if found
|
||||
*/
|
||||
public Optional<Exchange> getById(Long id) {
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
|
||||
public List<Exchange> getAllExchanges() {
|
||||
return this.repo.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id Id of user
|
||||
* @return List of exchanges that belong to user
|
||||
*/
|
||||
public List<Exchange> getByUserId(Long id) {
|
||||
return this.repo.getByUserId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param entity Exchange entity which we would like to delete
|
||||
*/
|
||||
public void deleteExchange(Exchange entity) {
|
||||
this.repo.delete(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param assignment Assignment to trade for
|
||||
* @param group Desired group
|
||||
* @return Optional with Exchange if exist
|
||||
*/
|
||||
public Optional<Exchange> checkForExchange(Assignment assignment, Groups group) {
|
||||
return this.repo.checkForExchange(assignment, group);
|
||||
}
|
||||
|
||||
public void performExchange() {
|
||||
final List<MatchData> matchData = this.getMatches();
|
||||
final List<Long> performedAssignmentExchanges = new ArrayList<>();
|
||||
final EmailExchangesData emailData = new EmailExchangesData();
|
||||
final List<Exchange> exchangesToDelete = new ArrayList<>();
|
||||
|
||||
matchData.forEach(m -> {
|
||||
final Assignment assignmentOne = m.getAssignmentOne();
|
||||
final Assignment assignmentTwo = m.getAssignmentTwo();
|
||||
|
||||
final Exchange exchange1 = m.getExchangeOne();
|
||||
final Exchange exchange2 = m.getExchangeTwo();
|
||||
|
||||
if (!(performedAssignmentExchanges.contains(assignmentOne.getId())
|
||||
|| performedAssignmentExchanges.contains(assignmentTwo.getId()))) {
|
||||
final Commision commisionOne = assignmentOne.getCommision();
|
||||
final User userOne = commisionOne.getCommisionOwner();
|
||||
final Commision commisionTwo = assignmentTwo.getCommision();
|
||||
final User userTwo = commisionTwo.getCommisionOwner();
|
||||
|
||||
assignmentOne.setCommision(commisionTwo);
|
||||
assignmentTwo.setCommision(commisionOne);
|
||||
|
||||
userOne.removeGroup(assignmentOne.getGroup().getId());
|
||||
userTwo.removeGroup(assignmentTwo.getGroup().getId());
|
||||
|
||||
userOne.claimGroup(assignmentTwo.getGroup());
|
||||
userTwo.claimGroup(assignmentOne.getGroup());
|
||||
|
||||
this.assignmentService.save(assignmentOne);
|
||||
this.assignmentService.save(assignmentTwo);
|
||||
|
||||
this.userService.save(userOne);
|
||||
this.userService.save(userTwo);
|
||||
|
||||
performedAssignmentExchanges.add(assignmentOne.getId());
|
||||
performedAssignmentExchanges.add(assignmentTwo.getId());
|
||||
|
||||
emailData.addExchange(exchange1.getOwnedAssignment().getCommision().getCommisionOwner(), exchange1);
|
||||
emailData.addExchange(exchange2.getOwnedAssignment().getCommision().getCommisionOwner(), exchange2);
|
||||
}
|
||||
|
||||
exchangesToDelete.add(exchange1);
|
||||
exchangesToDelete.add(exchange2);
|
||||
});
|
||||
this.emailService.sendExchangesResults(emailData);
|
||||
this.repo.deleteAll(exchangesToDelete);
|
||||
}
|
||||
|
||||
public List<MatchData> getMatches() {
|
||||
final List<MatchData> matches = this.repo.getMatches().stream().map(m -> {
|
||||
final Exchange exchangeOne = (Exchange) m[0];
|
||||
final Exchange exchangeTwo = (Exchange) m[1];
|
||||
return new MatchData(exchangeOne, exchangeTwo);
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
final Set<MatchData> uniqData = new HashSet<>(matches);
|
||||
final List<MatchData> matchDataListSorted = uniqData.stream().sorted((m1, m2) -> -1 * m1.compare(m2))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return matchDataListSorted;
|
||||
}
|
||||
}
|
75
buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java
Normal file → Executable file
75
buisnesslogic/src/main/java/com/plannaplan/services/GroupService.java
Normal file → Executable file
@ -1,13 +1,24 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.repositories.GroupRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Service of GroupService which can find(optional), get(By Course, Groups
|
||||
* Ammount, Group By Id, find Not Existing Group), save, delete group.
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class GroupService {
|
||||
@Autowired
|
||||
@ -16,16 +27,20 @@ public class GroupService {
|
||||
public GroupService() {
|
||||
}
|
||||
|
||||
public Groups find(int time, int capacity, String room) {
|
||||
public Optional<Groups> find(int time, int capacity, String room) {
|
||||
return this.repo.find(time, room, capacity);
|
||||
}
|
||||
|
||||
public Optional<Groups> find(Integer zajCykId, Integer nrGr) {
|
||||
return this.repo.find(zajCykId, nrGr);
|
||||
}
|
||||
|
||||
public List<Groups> getGroupsByCourse(Long id) {
|
||||
return this.repo.getByCourse(id);
|
||||
}
|
||||
|
||||
public void save(Groups group) {
|
||||
this.repo.save(group);
|
||||
public Groups save(Groups group) {
|
||||
return this.repo.save(group);
|
||||
}
|
||||
|
||||
public void delete(Groups groups) {
|
||||
@ -35,4 +50,58 @@ public class GroupService {
|
||||
public int getGroupsAmmount() {
|
||||
return (int) this.repo.count();
|
||||
}
|
||||
|
||||
public Optional<Groups> getGroupById(Long id) {
|
||||
return this.repo.findById(id);
|
||||
}
|
||||
|
||||
public Optional<Long> findNotExistingGroup(List<Long> ids) {
|
||||
for (Long oneId : ids) {
|
||||
if (this.repo.existsById(oneId) == false) {
|
||||
return Optional.of(oneId);
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param assignments list of assignments you want to get taken places ammount
|
||||
* @return HashMap of Long to 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
|
||||
* @return HashMap of Long to Integer where Long is group id and Integer is how
|
||||
* many places in gorup is already taken
|
||||
*/
|
||||
public HashMap<Long, Integer> getTakenPlaces(List<Groups> groups) {
|
||||
HashMap<Long, Integer> response = new HashMap<>();
|
||||
|
||||
if (groups.size() == 0) {
|
||||
return response;
|
||||
}
|
||||
|
||||
List<Object[]> respoonses = this.repo
|
||||
.getAssignedAmounts(groups.stream().filter(Objects::nonNull).map(new Function<Groups, Long>() {
|
||||
@Override
|
||||
public Long apply(Groups p) {
|
||||
final Long id = p.getId();
|
||||
response.put(id, 0);
|
||||
return id;
|
||||
}
|
||||
}).collect(Collectors.toList()));
|
||||
|
||||
for (Object[] element : respoonses) {
|
||||
response.put(((Groups) element[0]).getId(), ((Long) element[1]).intValue());
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import com.plannaplan.repositories.HistoryRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class HistoryService {
|
||||
@Autowired
|
||||
private HistoryRepository repo;
|
||||
}
|
10
buisnesslogic/src/main/java/com/plannaplan/services/LecturerService.java
Normal file → Executable file
10
buisnesslogic/src/main/java/com/plannaplan/services/LecturerService.java
Normal file → Executable file
@ -1,22 +1,28 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.plannaplan.entities.Lecturer;
|
||||
import com.plannaplan.repositories.LecturerRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Service of LecturerService which can get(Lecturer, Lecturers Ammount), save, delete lecturers.
|
||||
*/
|
||||
@Service
|
||||
public class LecturerService {
|
||||
@Autowired
|
||||
private LecturerRepository repo;
|
||||
|
||||
public Lecturer getLecturer(String title, String name, String surname) {
|
||||
public Optional<Lecturer> getLecturer(String title, String name, String surname) {
|
||||
return repo.find(title, name, surname);
|
||||
}
|
||||
|
||||
public void save(Lecturer lecturer) {
|
||||
public Lecturer save(Lecturer lecturer) {
|
||||
repo.save(lecturer);
|
||||
return lecturer;
|
||||
}
|
||||
|
||||
public void delete(Lecturer lecturer) {
|
||||
|
@ -1,17 +0,0 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import com.plannaplan.abstracts.EventWatcher;
|
||||
import com.plannaplan.repositories.TransferRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class TransferService extends EventWatcher {
|
||||
@Autowired
|
||||
private TransferRepository repo;
|
||||
|
||||
public TransferService() {
|
||||
super();
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import com.plannaplan.repositories.UnavailabilityRepository;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UnavailabilityService {
|
||||
@Autowired
|
||||
private UnavailabilityRepository repos;
|
||||
}
|
159
buisnesslogic/src/main/java/com/plannaplan/services/UserService.java
Normal file → Executable file
159
buisnesslogic/src/main/java/com/plannaplan/services/UserService.java
Normal file → Executable file
@ -1,45 +1,172 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.abstracts.EventWatcher;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.exceptions.UserNotFoundException;
|
||||
import com.plannaplan.models.UserApiResponse;
|
||||
import com.plannaplan.repositories.UserRepository;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Service of UserService which can get(By Email), login, save user.
|
||||
*/
|
||||
@Service
|
||||
public class UserService extends EventWatcher {
|
||||
public class UserService {
|
||||
@Autowired
|
||||
private UserRepository repo;
|
||||
|
||||
@Autowired
|
||||
private UsosApiService service;
|
||||
|
||||
public UserService() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String login(String authority) throws UserNotFoundException {
|
||||
User user = this.repo.getByAuthority(authority.replace("\n", "").trim());
|
||||
if (user == null) {
|
||||
throw new UserNotFoundException("Can not find user with given authority");
|
||||
}
|
||||
String token = UUID.randomUUID().toString();
|
||||
user.setToken(token);
|
||||
this.repo.save(user);
|
||||
return token;
|
||||
/**
|
||||
* checks if user exist and return him or creates new one with student role
|
||||
* otherwise
|
||||
*
|
||||
* @param email user email in usos
|
||||
* @param usosId user id in usos
|
||||
* @return user entity instace containing changes saved in database
|
||||
*/
|
||||
public User checkForUser(String email, String usosId) {
|
||||
return this.checkForUser(email, usosId, UserRoles.STUDENT);
|
||||
}
|
||||
|
||||
public void save(User user) {
|
||||
this.repo.save(user);
|
||||
/**
|
||||
* checks if user exist and creates new one if doesn't
|
||||
*
|
||||
* @param email user email in usos
|
||||
* @param usosId user id in usos
|
||||
* @param roleIfNotExist role to be set in case user is not in database yet
|
||||
* @return user entity instace containing changes saved in database
|
||||
*/
|
||||
public User checkForUser(String email, String usosId, UserRoles roleIfNotExist) {
|
||||
if (usosId == null) {
|
||||
Optional<User> user = this.repo.getByEmail(email.replace("\n", "").trim());
|
||||
if (user.isPresent()) {
|
||||
return user.get();
|
||||
} else {
|
||||
final User newUser = new User(null, null, email.replace("\n", "").trim(), roleIfNotExist);
|
||||
return this.repo.save(newUser);
|
||||
}
|
||||
} else {
|
||||
Optional<User> user = this.repo.getByUsosId(usosId.replace("\n", "").trim());
|
||||
if (user.isPresent()) {
|
||||
return user.get();
|
||||
} else {
|
||||
final User newUser = new User(null, null, email.replace("\n", "").trim(), usosId, roleIfNotExist);
|
||||
return this.repo.save(newUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public User getUserByEmail(String email) {
|
||||
return this.repo.getByAuthority(email.replace("\n", "").trim());
|
||||
/**
|
||||
* generates token for user and if user don't have name in database it will
|
||||
* attemp to obtain these from usos api and saves changes in database
|
||||
*
|
||||
* @param authority user we want to login
|
||||
* @return user with changed values after save in db
|
||||
* @throws UserNotFoundException throwed if user doesn't exist
|
||||
*/
|
||||
public User login(User authority) throws UserNotFoundException {
|
||||
final String token = UUID.randomUUID().toString();
|
||||
if ((authority.getName() == null || authority.getSurname() == null) && authority.getUsosId() != null) {
|
||||
final UserApiResponse resp = this.service.getUserData(authority.getUsosId());
|
||||
authority.updateWithUsosData(resp);
|
||||
}
|
||||
try {
|
||||
authority.setToken(token);
|
||||
this.repo.save(authority);
|
||||
} catch (Exception e) {
|
||||
throw new UserNotFoundException(e.getMessage());
|
||||
}
|
||||
return authority;
|
||||
}
|
||||
|
||||
public User getByToken(String token) {
|
||||
/**
|
||||
* sacves user to databse and return instatnce with id
|
||||
*
|
||||
* @param user to be saved
|
||||
* @return instatnce with bd id
|
||||
*/
|
||||
public User save(User user) {
|
||||
return this.repo.save(user);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param email of user to be find
|
||||
* @return user with given mail
|
||||
* @throws UserNotFoundException throwed if user doesn't exist
|
||||
*/
|
||||
public User getUserByEmail(String email) throws UserNotFoundException {
|
||||
return this.repo.getByEmail(email.replace("\n", "").trim())
|
||||
.orElseThrow(() -> new UserNotFoundException("Cannot find user with given authority"));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* return user by given authority
|
||||
*
|
||||
* @param authority user usosId or email
|
||||
* @return optional with user if found
|
||||
*/
|
||||
public Optional<User> getByAuthority(String authority) {
|
||||
return this.repo.getByAuthority(authority);
|
||||
}
|
||||
|
||||
public Optional<User> getByToken(String token) {
|
||||
return this.repo.getByToken(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* search for user with given query
|
||||
*
|
||||
* @param query string that will be matched to users name and surname
|
||||
* @return list opf results
|
||||
*/
|
||||
public List<User> searchForStudents(String query) {
|
||||
return this.repo.searchForUsers(query, UserRoles.STUDENT);
|
||||
}
|
||||
|
||||
public Optional<User> getById(Long 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;
|
||||
}
|
||||
|
||||
public void saveAll(List<User> users) {
|
||||
this.repo.saveAll(users);
|
||||
}
|
||||
|
||||
/**
|
||||
* get students sorted by their ranking
|
||||
*
|
||||
* @return list of students
|
||||
*/
|
||||
public List<User> getStudentsSortedByRanking() {
|
||||
return this.repo.getAllByRole(UserRoles.STUDENT).stream().sorted((u1, u2) -> {
|
||||
return -1 * u1.getRanking().compareTo(u2.getRanking());
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
75
buisnesslogic/src/main/java/com/plannaplan/services/UsosApiService.java
Executable file
75
buisnesslogic/src/main/java/com/plannaplan/services/UsosApiService.java
Executable file
@ -0,0 +1,75 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import com.github.scribejava.core.builder.ServiceBuilder;
|
||||
import com.github.scribejava.core.model.OAuth1AccessToken;
|
||||
import com.github.scribejava.core.model.OAuthRequest;
|
||||
import com.github.scribejava.core.model.Response;
|
||||
import com.github.scribejava.core.model.Verb;
|
||||
import com.github.scribejava.core.oauth.OAuth10aService;
|
||||
import com.plannaplan.api.UsosOauth1Service;
|
||||
import com.plannaplan.models.UserApiResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* service to call usos api endpoints
|
||||
*/
|
||||
@Service
|
||||
public class UsosApiService {
|
||||
|
||||
private static final String NAME_FIELD = "first_name";
|
||||
private static final String SURNAME_FIELD = "last_name";
|
||||
|
||||
@Value("${plannaplan.apiurl}")
|
||||
private String apiUrl;
|
||||
|
||||
@Value("${plannaplan.apikey}")
|
||||
private String apikey;
|
||||
|
||||
@Value("${plannaplan.apisecret}")
|
||||
private String apisecret;
|
||||
|
||||
public UsosApiService() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* /services/users/user
|
||||
*
|
||||
* @param usosId user id in usos
|
||||
* @return UserApiResponse modle contatining desired values
|
||||
*/
|
||||
public UserApiResponse getUserData(String usosId) {
|
||||
final UserApiResponse apiResponse = new UserApiResponse();
|
||||
try {
|
||||
final OAuth10aService service = new ServiceBuilder(apikey).apiSecret(apisecret)
|
||||
.build(UsosOauth1Service.instance());
|
||||
|
||||
final OAuthRequest request = new OAuthRequest(Verb.GET, apiUrl + "/services/users/user?user_id=" + usosId);
|
||||
service.signRequest(new OAuth1AccessToken("", ""), request);
|
||||
try (Response response = service.execute(request)) {
|
||||
final String json = response.getBody();
|
||||
if (!json.equals("null")){
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
Map<String, String> map = mapper.readValue(json, new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
apiResponse.setName(map.get(NAME_FIELD));
|
||||
apiResponse.setSurname(map.get(SURNAME_FIELD));
|
||||
}
|
||||
}
|
||||
} catch (IOException | InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.plannaplan.statisticutils;
|
||||
|
||||
public class Statistics {
|
||||
|
||||
public Statistics() {
|
||||
}
|
||||
|
||||
public void getAll() {
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.plannaplan.transferutils;
|
||||
|
||||
public class TransferMatcher {
|
||||
public TransferMatcher() {
|
||||
}
|
||||
|
||||
public void findMatches() {
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.plannaplan.transferutils;
|
||||
|
||||
public class TransfersExecuter {
|
||||
public TransfersExecuter() {
|
||||
}
|
||||
|
||||
public void execute() {
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.plannaplan.types;
|
||||
|
||||
public enum ActionTypes {
|
||||
ADD, DELETE, REPLACE
|
||||
}
|
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
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.plannaplan.types;
|
||||
|
||||
public enum AppStates {
|
||||
STOPPED, RUNNING, PAUSED
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.plannaplan.types;
|
||||
|
||||
public enum EventTypes {
|
||||
DROPPED_OUT, TOUR_STARTED, TRANSFER_FOUND, TOUR_FINISHED, COURSES_ACCEPTED
|
||||
}
|
20
buisnesslogic/src/main/java/com/plannaplan/types/GroupType.java
Normal file → Executable file
20
buisnesslogic/src/main/java/com/plannaplan/types/GroupType.java
Normal file → Executable file
@ -1,5 +1,23 @@
|
||||
package com.plannaplan.types;
|
||||
|
||||
/**
|
||||
* GroupType contains types: LECTURE, CLASS, LAB, SEMINAR, CONSERVATORY, PRATICE
|
||||
*/
|
||||
|
||||
public enum GroupType {
|
||||
LECTURE, CLASS
|
||||
LECTURE("Wykład"), CLASS("Ćwiczenia"), LAB("Laboratorium"), SEMINAR("Seminarium"),CONSERVATORY("Konwersatorium"), PRATICE("Praktyka");
|
||||
|
||||
public final String type;
|
||||
private GroupType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public final static GroupType getType(String type) {
|
||||
for (GroupType d : values()) {
|
||||
if (d.type.equals(type)) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
4
buisnesslogic/src/main/java/com/plannaplan/types/UserRoles.java
Normal file → Executable file
4
buisnesslogic/src/main/java/com/plannaplan/types/UserRoles.java
Normal file → Executable file
@ -1,5 +1,9 @@
|
||||
package com.plannaplan.types;
|
||||
|
||||
/**
|
||||
* UserRoles contains types: STUDENT, DEANERY, ADMIN, TEST_USER
|
||||
*/
|
||||
|
||||
public enum UserRoles {
|
||||
STUDENT, DEANERY, ADMIN, TEST_USER
|
||||
}
|
4
buisnesslogic/src/main/java/com/plannaplan/types/WeekDay.java
Normal file → Executable file
4
buisnesslogic/src/main/java/com/plannaplan/types/WeekDay.java
Normal file → Executable file
@ -1,5 +1,9 @@
|
||||
package com.plannaplan.types;
|
||||
|
||||
/**
|
||||
* WeekDay contains types: MONDAY(0), TUESDAY(1), WEDNESDAY(2), THURSDAY(3), FRIDAY(4), SATURDAY(5), SUNDAY(6).
|
||||
*/
|
||||
|
||||
public enum WeekDay {
|
||||
MONDAY(0), TUESDAY(1), WEDNESDAY(2), THURSDAY(3), FRIDAY(4), SATURDAY(5), SUNDAY(6);
|
||||
|
||||
|
2
buisnesslogic/src/test/java/com/plannaplan/TestApplication.java
Normal file → Executable file
2
buisnesslogic/src/test/java/com/plannaplan/TestApplication.java
Normal file → Executable file
@ -4,5 +4,5 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class TestApplication {
|
||||
|
||||
public final static String TEST_CONFIG_FILE = "Zajecia.xlsx";
|
||||
}
|
||||
|
11
buisnesslogic/src/test/java/com/plannaplan/configutils/FileReaderTest.java
Normal file → Executable file
11
buisnesslogic/src/test/java/com/plannaplan/configutils/FileReaderTest.java
Normal file → Executable file
@ -10,12 +10,11 @@ import org.junit.Test;
|
||||
|
||||
public class FileReaderTest {
|
||||
@Test
|
||||
public void shoulReturnNull() {
|
||||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
|
||||
FileReader r = new FileReader(inputStream);
|
||||
FileData d = r.read();
|
||||
assertTrue(d.getRows().next().getCell(0).toString().equals("1.0"));
|
||||
assertTrue(d.getKeys().size() == 22);
|
||||
public void shouldNotReturnNull() {
|
||||
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
|
||||
final FileReader r = new FileReader(inputStream);
|
||||
final FileData d = r.read();
|
||||
assertTrue(d.getKeys().size() == 12);
|
||||
assertTrue(d != null);
|
||||
}
|
||||
}
|
15
buisnesslogic/src/test/java/com/plannaplan/configutils/FileToDatabaseMigratorTest.java
Normal file → Executable file
15
buisnesslogic/src/test/java/com/plannaplan/configutils/FileToDatabaseMigratorTest.java
Normal file → Executable file
@ -9,8 +9,7 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.plannaplan.Configurator;
|
||||
import com.plannaplan.models.ConfigData;
|
||||
import com.plannaplan.TestApplication;
|
||||
import com.plannaplan.services.CourseService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.services.LecturerService;
|
||||
@ -18,16 +17,13 @@ import com.plannaplan.services.LecturerService;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class FileToDatabaseMigratorTest {
|
||||
|
||||
private static String FILE_NAME = "Zajecia.xlsx";
|
||||
|
||||
@Autowired
|
||||
private Configurator restTemplate;
|
||||
private FileToDatabaseMigrator migrator;
|
||||
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
@ -40,9 +36,10 @@ public class FileToDatabaseMigratorTest {
|
||||
|
||||
@Test
|
||||
public void shouldImportDataFromFileToDatabase() throws Exception {
|
||||
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME);
|
||||
final ConfigData data = new ConfigData(null, null, inputStream);
|
||||
this.restTemplate.config(data);
|
||||
final InputStream inputStream = getClass().getClassLoader()
|
||||
.getResourceAsStream(TestApplication.TEST_CONFIG_FILE);
|
||||
final FileReader reader = new FileReader(inputStream);
|
||||
this.migrator.migrate(reader.read());
|
||||
int courses_ammount = this.courseService.getCoursesAmmount();
|
||||
int groups_ammount = this.groupService.getGroupsAmmount();
|
||||
int lecturers_ammount = this.lecturerService.getLecturersAmmount();
|
||||
|
189
buisnesslogic/src/test/java/com/plannaplan/entities/AppConfigTest.java
Executable file
189
buisnesslogic/src/test/java/com/plannaplan/entities/AppConfigTest.java
Executable file
@ -0,0 +1,189 @@
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnFirstStartDatesCorns() {
|
||||
final Date firtstTourStart = Date.valueOf("2020-11-12");
|
||||
final Date firtstTourEnd = Date.valueOf("2020-11-13");
|
||||
final Date secondTourStart = Date.valueOf("2020-11-14");
|
||||
final Date secondTourEnd = Date.valueOf("2020-11-15");
|
||||
|
||||
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||
new TourData(secondTourStart, secondTourEnd));
|
||||
assertTrue(config.getFirstTourStartCron().getExpression().equals("0 0 0 12 11 ?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSecondStartDatesCorns() {
|
||||
final Date firtstTourStart = Date.valueOf("2020-11-12");
|
||||
final Date firtstTourEnd = Date.valueOf("2020-11-13");
|
||||
final Date secondTourStart = Date.valueOf("2020-11-14");
|
||||
final Date secondTourEnd = Date.valueOf("2020-11-15");
|
||||
|
||||
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||
new TourData(secondTourStart, secondTourEnd));
|
||||
assertTrue(config.getSecondTourStartCron().getExpression().equals("0 0 0 14 11 ?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnFirstEndDatesCorns() {
|
||||
final Date firtstTourStart = Date.valueOf("2020-11-12");
|
||||
final Date firtstTourEnd = Date.valueOf("2020-11-13");
|
||||
final Date secondTourStart = Date.valueOf("2020-11-14");
|
||||
final Date secondTourEnd = Date.valueOf("2020-11-15");
|
||||
|
||||
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||
new TourData(secondTourStart, secondTourEnd));
|
||||
assertTrue(config.getFirstTourEndCron().getExpression().equals("0 0 0 13 11 ?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSecondEndDatesCorns() {
|
||||
final Date firtstTourStart = Date.valueOf("2020-11-12");
|
||||
final Date firtstTourEnd = Date.valueOf("2020-11-13");
|
||||
final Date secondTourStart = Date.valueOf("2020-11-14");
|
||||
final Date secondTourEnd = Date.valueOf("2020-11-15");
|
||||
|
||||
final AppConfig config = new AppConfig(new TourData(firtstTourStart, firtstTourEnd),
|
||||
new TourData(secondTourStart, secondTourEnd));
|
||||
assertTrue(config.getSecondTourEndCron().getExpression().equals("0 0 0 15 11 ?"));
|
||||
}
|
||||
|
||||
}
|
71
buisnesslogic/src/test/java/com/plannaplan/entities/UserTest.java
Executable file
71
buisnesslogic/src/test/java/com/plannaplan/entities/UserTest.java
Executable file
@ -0,0 +1,71 @@
|
||||
package com.plannaplan.entities;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class UserTest {
|
||||
|
||||
@Test
|
||||
public void shouldResturnTokenIsNotExpired() {
|
||||
final User user = new User();
|
||||
user.setToken("testowy-bezpieczny-token");
|
||||
assertTrue(user.isCredentialsNonExpired(), "Credential shouldnt expire yet");
|
||||
|
||||
long minutes = this.getMinutesDiff(user.getTokenUsageDate());
|
||||
|
||||
assertTrue(minutes == 0, "Should update last token usage");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldResturnTokenIsNotExpiredWithLessThan15minutes()
|
||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||
|
||||
final User user = new User();
|
||||
user.setToken("testowy-bezpieczny-token");
|
||||
this.setLastTokenUsage(user, new Timestamp(System.currentTimeMillis() - (6 * 60 * 1000)));
|
||||
|
||||
assertTrue(user.isCredentialsNonExpired(), "Credential shouldnt expire yet");
|
||||
|
||||
final long minutes = this.getMinutesDiff(user.getTokenUsageDate());
|
||||
assertTrue(minutes == 0, "Should update last token usage");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldResturnTokenIsExpired()
|
||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||
|
||||
final User user = new User();
|
||||
user.setToken("testowy-bezpieczny-token");
|
||||
this.setLastTokenUsage(user, new Timestamp(System.currentTimeMillis() - (25 * 60 * 1000)));
|
||||
|
||||
assertFalse(user.isCredentialsNonExpired(), "Credential should expire");
|
||||
|
||||
final long diffInMilliseconds = Math
|
||||
.abs(user.getTokenUsageDate().getTime() - new Timestamp(System.currentTimeMillis()).getTime());
|
||||
final long minutes = TimeUnit.MILLISECONDS.toMinutes(diffInMilliseconds);
|
||||
|
||||
assertTrue(minutes > 0, "Shouldn't update last token usage");
|
||||
}
|
||||
|
||||
private long getMinutesDiff(Timestamp timestamp) {
|
||||
final long diffInMilliseconds = Math
|
||||
.abs(timestamp.getTime() - new Timestamp(System.currentTimeMillis()).getTime());
|
||||
final long minutes = TimeUnit.MILLISECONDS.toMinutes(diffInMilliseconds);
|
||||
return minutes;
|
||||
}
|
||||
|
||||
private void setLastTokenUsage(User user, Timestamp timestampToSet)
|
||||
throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
|
||||
Field reader = User.class.getDeclaredField("tokenUsageDate");
|
||||
reader.setAccessible(true);
|
||||
reader.set(user, timestampToSet);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Exchange;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.services.UserService;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class ExchangeRepositoryTest{
|
||||
@Autowired
|
||||
private ExchangeRepository exchangeRepository;
|
||||
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private CommisionRepository commisionRepository;
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldReturnMatches() {
|
||||
final User user1 = this.userService.save(
|
||||
new User(null, null, "shouldReturnMatches@ExchangeRepository.test", "123454", UserRoles.STUDENT, 451));
|
||||
final Groups group1 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.MONDAY, null));
|
||||
final Commision commision1 = this.commisionRepository.save(new Commision(user1));
|
||||
final User user2 = this.userService.save(
|
||||
new User(null, null, "shouldReturnMatches@ExchangeRepository.test", "123454", UserRoles.STUDENT, 451));
|
||||
final Groups group2 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.MONDAY, null));
|
||||
final Commision commision2 = this.commisionRepository.save(new Commision(user2));
|
||||
final Assignment assignmentUser1 = this.assignmentService.save(new Assignment(group1, commision1));
|
||||
final Assignment assignmentUser2 = this.assignmentService.save(new Assignment(group2, commision2));
|
||||
|
||||
this.assignmentService.callAcceptAlgorythm();
|
||||
|
||||
this.exchangeRepository.save(new Exchange(assignmentUser1, group2));
|
||||
this.exchangeRepository.save(new Exchange(assignmentUser2, group1));
|
||||
|
||||
final List<Object[]> exchangeRepoMatches = this.exchangeRepository.getMatches();
|
||||
assertTrue(exchangeRepoMatches.size() == 2);
|
||||
}
|
||||
}
|
106
buisnesslogic/src/test/java/com/plannaplan/repositories/GroupRepositoryTest.java
Executable file
106
buisnesslogic/src/test/java/com/plannaplan/repositories/GroupRepositoryTest.java
Executable file
@ -0,0 +1,106 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.services.AssignmentService;
|
||||
import com.plannaplan.services.CommisionService;
|
||||
import com.plannaplan.services.GroupService;
|
||||
import com.plannaplan.services.UserService;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class GroupRepositoryTest {
|
||||
@Autowired
|
||||
private GroupRepository repository;
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private CommisionService commisionService;
|
||||
|
||||
@Test
|
||||
public void shouldReturnGroupAssignmentTimes() throws InterruptedException {
|
||||
final Groups testGroup = groupService.save(new Groups(43, "A-41", null, 235, WeekDay.MONDAY, null));
|
||||
int startGroupAmmount = this.repository.getAssignedAmount(testGroup.getId()).orElse(Integer.valueOf(0))
|
||||
.intValue();
|
||||
|
||||
final User user = this.userService.save(new User("Luis", "Vita",
|
||||
"shouldReturnGroupAssignmentTimes@grouprepository.test", UserRoles.STUDENT));
|
||||
final Commision commision = this.commisionService.save(new Commision(user));
|
||||
|
||||
this.assignmentService.save(new Assignment(testGroup, commision));
|
||||
Thread.sleep(1000);
|
||||
|
||||
int afterAssignedGroupAmmount = this.repository.getAssignedAmount(testGroup.getId())
|
||||
.orElse(Integer.valueOf(0)).intValue();
|
||||
|
||||
assertTrue(afterAssignedGroupAmmount > startGroupAmmount);
|
||||
|
||||
final Commision recommision = this.commisionService.save(new Commision(user));
|
||||
this.assignmentService.save(new Assignment(testGroup, recommision));
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
int afterreAssignedGroupAmmount = this.repository.getAssignedAmount(testGroup.getId())
|
||||
.orElse(Integer.valueOf(0)).intValue();
|
||||
|
||||
assertTrue(afterAssignedGroupAmmount == afterreAssignedGroupAmmount);
|
||||
|
||||
this.commisionService.save(new Commision(user));
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
int afterdeAssignedGroupAmmount = this.repository.getAssignedAmount(testGroup.getId())
|
||||
.orElse(Integer.valueOf(0)).intValue();
|
||||
|
||||
assertTrue(afterdeAssignedGroupAmmount < afterreAssignedGroupAmmount);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnGroupAssignmentTimesList() throws InterruptedException {
|
||||
final Groups testGroup = groupService.save(new Groups(43, "A-41", null, 645, WeekDay.MONDAY, null));
|
||||
final Groups testGroup2 = groupService.save(new Groups(433, "A-41", null, 235, WeekDay.TUESDAY, null));
|
||||
final Groups testGroup3 = groupService.save(new Groups(23, "A-41", null, 340, WeekDay.MONDAY, null));
|
||||
final User user = this.userService.save(new User("Dare", "Oc",
|
||||
"shouldReturnGroupAssignmentTimesList@grouprepository.test", UserRoles.STUDENT));
|
||||
final Commision commision = this.commisionService.save(new Commision(user));
|
||||
|
||||
this.assignmentService.save(new Assignment(testGroup, commision));
|
||||
this.assignmentService.save(new Assignment(testGroup2, commision));
|
||||
this.assignmentService.save(new Assignment(testGroup3, commision));
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
List<Object[]> response = this.repository
|
||||
.getAssignedAmounts(List.of(testGroup.getId(), testGroup2.getId(), testGroup3.getId()));
|
||||
|
||||
assertTrue("Response should have size 3", response.size() == 3);
|
||||
assertTrue("Instance of firest element should be Group", response.get(0)[0] instanceof Groups);
|
||||
assertTrue("Instance of firest element should be Long", response.get(0)[1] instanceof Long);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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()));
|
||||
}
|
||||
}
|
139
buisnesslogic/src/test/java/com/plannaplan/services/AssignmentServiceTest.java
Executable file
139
buisnesslogic/src/test/java/com/plannaplan/services/AssignmentServiceTest.java
Executable file
@ -0,0 +1,139 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class AssignmentServiceTest {
|
||||
|
||||
@Autowired
|
||||
private AssignmentService service;
|
||||
@Autowired
|
||||
private CommisionService comServie;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
@Test
|
||||
public void shouldSaveAssignment() {
|
||||
final User user = new User("Gibi", "Kovalsky", "shouldSaveAssignment@assignmentservice.test",
|
||||
UserRoles.STUDENT);
|
||||
this.userService.save(user);
|
||||
|
||||
long beginState = this.service.getAssignmentsAmmount();
|
||||
Commision com = new Commision(user);
|
||||
this.comServie.save(com);
|
||||
this.addAssignmentToCommision(com);
|
||||
assertTrue("Assign ammount should increase", this.service.getAssignmentsAmmount() > beginState);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetCommisionAssignments() {
|
||||
final User user = new User("Gibi", "Kovalsky", "shouldGetCommisionAssignments@assignmentservice.test",
|
||||
UserRoles.STUDENT);
|
||||
this.userService.save(user);
|
||||
Commision com = new Commision(user);
|
||||
this.comServie.save(com);
|
||||
this.addAssignmentToCommision(com);
|
||||
|
||||
final List<Assignment> response = this.service.getCommisionAssignments(com);
|
||||
assertTrue("Returned list size should be 1", response.size() == 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldPerformAcceptAlgorythm() {
|
||||
final Random generator = new Random();
|
||||
|
||||
final List<Groups> groups = new ArrayList<>();
|
||||
|
||||
IntStream.range(0, 418).forEach(i -> {
|
||||
groups.add(this.groupService.save(new Groups(generator.nextInt(80) + 20, null, null,
|
||||
generator.nextInt(9) * 30 + 9 * 30, WeekDay.getDay(generator.nextInt(5)), null)));
|
||||
});
|
||||
|
||||
IntStream.range(0, 1700).forEach(i -> {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldPerformAcceptAlgorythm-" + UUID.randomUUID().toString() + "@AssignmentService.test", null,
|
||||
UserRoles.STUDENT, generator.nextInt(400) + 100));
|
||||
final Commision com = this.comServie.save(new Commision(user));
|
||||
IntStream.range(0, 5).forEach(j -> {
|
||||
this.service.save(new Assignment(groups.get(generator.nextInt(groups.size())), com));
|
||||
});
|
||||
});
|
||||
this.service.callAcceptAlgorythm();
|
||||
}
|
||||
|
||||
/**
|
||||
* This test will also sand a mail to users as a side effect. U can check them
|
||||
* in mailcater
|
||||
*/
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldNotAcceptForOnePerson() {
|
||||
final Random generator = new Random();
|
||||
final Groups group = this.groupService.save(new Groups(5, null, null, 840, WeekDay.MONDAY, null));
|
||||
|
||||
IntStream.range(0, 6).forEach(i -> {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldNotAcceptForOnePerson-" + UUID.randomUUID().toString() + "@AssignmentService.test", null,
|
||||
UserRoles.STUDENT, generator.nextInt(400) + 100));
|
||||
|
||||
final Commision com = this.comServie.save(new Commision(user));
|
||||
|
||||
this.service.save(new Assignment(group, com));
|
||||
});
|
||||
|
||||
this.service.callAcceptAlgorythm();
|
||||
|
||||
final List<User> users = this.userService.getStudentsSortedByRanking();
|
||||
final User loser = users.get(users.size() - 1);
|
||||
|
||||
assertTrue(loser.getStudentRegisteredGrups().size() == 0);
|
||||
|
||||
users.forEach(u -> {
|
||||
final Commision com = this.comServie.getNewestCommision(u).get();
|
||||
final List<Assignment> assignments = com.getAssignments();
|
||||
if (u.getId() == loser.getId()) {
|
||||
assertTrue(!assignments.get(0).isAccepted());
|
||||
} else {
|
||||
assertTrue(assignments.get(0).isAccepted());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void addAssignmentToCommision(Commision com) {
|
||||
Assignment a = new Assignment(null, com);
|
||||
this.service.save(a);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class CommisionServiceTest {
|
||||
|
||||
@Autowired
|
||||
private CommisionService service;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
@Test
|
||||
public void shouldSaveCommision() {
|
||||
User usr = new User();
|
||||
this.userService.save(usr);
|
||||
long beginState = this.service.getCommisionsAmmount();
|
||||
this.service.save(new Commision(usr));
|
||||
assertTrue("Commision ammount should have changed", this.service.getCommisionsAmmount() > beginState);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetUserCommisions() {
|
||||
User usr = new User();
|
||||
this.userService.save(usr);
|
||||
this.service.save(new Commision(usr));
|
||||
|
||||
assertTrue("User should have one commision", this.service.getUsersCommisions(usr).size() == 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetNewestCommision() throws NullPointerException, InterruptedException {
|
||||
User usr = new User();
|
||||
this.userService.save(usr);
|
||||
this.service.save(new Commision(usr));
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
final Commision newestCommision = new Commision(usr);
|
||||
this.service.save(newestCommision);
|
||||
|
||||
final Commision result = this.service.getNewestCommision(usr)
|
||||
.orElseThrow(() -> new NullPointerException("There was no commision"));
|
||||
|
||||
assertTrue("Wrong commision was returned", result.getId().equals(newestCommision.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMarkAssignmentsOfPreviousCommisionPast() {
|
||||
final User usr = new User("Trevor", "Hammolt",
|
||||
"shouldMarkAssignmentsOfPreviousCommisionPast@commisionservice.test", UserRoles.STUDENT);
|
||||
this.userService.save(usr);
|
||||
|
||||
final Commision firstCommision = new Commision(usr);
|
||||
this.service.save(firstCommision);
|
||||
|
||||
Assignment firstCommisionAssignment = this.assignmentService.save(new Assignment(null, firstCommision));
|
||||
|
||||
assertTrue("FirstCommisionAssignment should be flaged as present assignment",
|
||||
!firstCommisionAssignment.isPastAssignment());
|
||||
|
||||
final Commision secondCommision = new Commision(usr);
|
||||
this.service.save(secondCommision);
|
||||
|
||||
Assignment secondCommisionAssignment = new Assignment(null, secondCommision);
|
||||
this.assignmentService.save(secondCommisionAssignment);
|
||||
|
||||
assertTrue("SecondCommisionAssignment should be flaged as present assignment",
|
||||
!secondCommisionAssignment.isPastAssignment());
|
||||
assertTrue("FirstCommisionAssignment should be flaged as past assignment",
|
||||
this.assignmentService.getById(firstCommisionAssignment.getId()).get().isPastAssignment());
|
||||
|
||||
}
|
||||
|
||||
}
|
134
buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java
Executable file
134
buisnesslogic/src/test/java/com/plannaplan/services/ConfiguratorServiceTest.java
Executable file
@ -0,0 +1,134 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.Date;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import com.plannaplan.TestApplication;
|
||||
import com.plannaplan.entities.AppConfig;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.models.ConfigData;
|
||||
import com.plannaplan.models.TourData;
|
||||
import com.plannaplan.repositories.AppConfigRepository;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class ConfiguratorServiceTest {
|
||||
|
||||
private final static String BEFORE_UPDATE_FILE = "ZajeciaBeforeUpdate.xlsx";
|
||||
private final static String AFTER_UPDATE_FILE = "ZajeciaAfterUpdate.xlsx";
|
||||
|
||||
@Autowired
|
||||
private ConfiguratorService configuratorService;
|
||||
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
@Autowired
|
||||
private LecturerService lecturerService;
|
||||
|
||||
@Autowired
|
||||
private AppConfigRepository appConfigRepo;
|
||||
|
||||
@Autowired
|
||||
private EventService eventService;
|
||||
|
||||
@Test
|
||||
public void shouldImportDataToDataBase() {
|
||||
final InputStream inputStream = getClass().getClassLoader()
|
||||
.getResourceAsStream(TestApplication.TEST_CONFIG_FILE);
|
||||
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);
|
||||
|
||||
int courses_ammount = this.courseService.getCoursesAmmount();
|
||||
int groups_ammount = this.groupService.getGroupsAmmount();
|
||||
int lecturers_ammount = this.lecturerService.getLecturersAmmount();
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shlouldScheduleTaskWhenSetTourDate()
|
||||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
|
||||
final InputStream inputStream = getClass().getClassLoader()
|
||||
.getResourceAsStream(TestApplication.TEST_CONFIG_FILE);
|
||||
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);
|
||||
|
||||
final Field reader = EventService.class.getDeclaredField("jobsMap");
|
||||
reader.setAccessible(true);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
final Map<Integer, ScheduledFuture<?>> map = (Map<Integer, ScheduledFuture<?>>) reader.get(this.eventService);
|
||||
|
||||
assertTrue(map.size() == 2);
|
||||
assertTrue(map.get(EventService.FIRST_TOUR_SCHEDULE).isDone() == false);
|
||||
assertTrue(map.get(EventService.SECOND_TOUR_SCHEDULE).isDone() == false);
|
||||
}
|
||||
|
||||
}
|
7
buisnesslogic/src/test/java/com/plannaplan/services/CourseServiceTest.java
Normal file → Executable file
7
buisnesslogic/src/test/java/com/plannaplan/services/CourseServiceTest.java
Normal file → Executable file
@ -20,17 +20,12 @@ public class CourseServiceTest {
|
||||
|
||||
@Test
|
||||
public void createAndDeleteCourse() {
|
||||
Course course;
|
||||
Course course = new Course("Testowy kurs", "TK");
|
||||
int startAmmount = this.courseService.getCoursesAmmount();
|
||||
|
||||
// Create course
|
||||
course = new Course();
|
||||
course.setName("Testowy kurs");
|
||||
course.setSymbol("TK");
|
||||
courseService.save(course);
|
||||
assertTrue(this.courseService.getCoursesAmmount() > startAmmount);
|
||||
|
||||
// Delete course
|
||||
courseService.delete(course);
|
||||
assertTrue(this.courseService.getCoursesAmmount() == startAmmount);
|
||||
}
|
||||
|
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");
|
||||
}
|
||||
|
||||
}
|
208
buisnesslogic/src/test/java/com/plannaplan/services/ExchangeServiceTest.java
Executable file
208
buisnesslogic/src/test/java/com/plannaplan/services/ExchangeServiceTest.java
Executable file
@ -0,0 +1,208 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Exchange;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.models.MatchData;
|
||||
import com.plannaplan.repositories.CommisionRepository;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
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.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.MethodMode;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class ExchangeServiceTest {
|
||||
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private CommisionRepository commisionRepository;
|
||||
|
||||
@Autowired
|
||||
private ExchangeService exchangeService;
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldReturnUniqMatches() {
|
||||
final User user1 = this.userService.save(
|
||||
new User(null, null, "shouldReturnMatches@ExchangeRepository.test", "123454", UserRoles.STUDENT, 451));
|
||||
final Groups group1 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.MONDAY, null));
|
||||
final Commision commision1 = this.commisionRepository.save(new Commision(user1));
|
||||
final User user2 = this.userService.save(
|
||||
new User(null, null, "shouldReturnMatches@ExchangeRepository.test", "123454", UserRoles.STUDENT, 451));
|
||||
final Groups group2 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.MONDAY, null));
|
||||
final Commision commision2 = this.commisionRepository.save(new Commision(user2));
|
||||
final Assignment assignmentUser1 = this.assignmentService.save(new Assignment(group1, commision1));
|
||||
final Assignment assignmentUser2 = this.assignmentService.save(new Assignment(group2, commision2));
|
||||
|
||||
this.assignmentService.callAcceptAlgorythm();
|
||||
|
||||
this.exchangeService.save(new Exchange(assignmentUser1, group2));
|
||||
this.exchangeService.save(new Exchange(assignmentUser2, group1));
|
||||
|
||||
final List<MatchData> uniqList = this.exchangeService.getMatches();
|
||||
assertTrue(uniqList.size() == 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldPerformExchange() throws Exception{
|
||||
User user1 = this.userService.save(
|
||||
new User(null, null, "1shouldReturnMatches@ExchangeRepository.test", "123454", UserRoles.STUDENT, 451));
|
||||
final Long user1Id = user1.getId();
|
||||
final Groups group1 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.MONDAY, null));
|
||||
final Commision commision1 = this.commisionRepository.save(new Commision(user1));
|
||||
|
||||
User user2 = this.userService.save(
|
||||
new User(null, null, "2shouldReturnMatches@ExchangeRepository.test", "123455", UserRoles.STUDENT, 452));
|
||||
final Long user2Id = user2.getId();
|
||||
final Groups group2 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.THURSDAY, null));
|
||||
final Commision commision2 = this.commisionRepository.save(new Commision(user2));
|
||||
|
||||
User user3 = this.userService.save(
|
||||
new User(null, null, "3shouldReturnMatches@ExchangeRepository.test", "123456", UserRoles.STUDENT, 453));
|
||||
final Long user3Id = user3.getId();
|
||||
final Groups group3 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.WEDNESDAY, null));
|
||||
final Commision commision3 = this.commisionRepository.save(new Commision(user3));
|
||||
|
||||
User user4 = this.userService.save(
|
||||
new User(null, null, "2shouldReturnMatches@ExchangeRepository.test", "123457", UserRoles.STUDENT, 455));
|
||||
final Long user4Id = user4.getId();
|
||||
final Groups group4 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.FRIDAY, null));
|
||||
final Commision commision4 = this.commisionRepository.save(new Commision(user4));
|
||||
|
||||
final Assignment assignmentUser1 = this.assignmentService.save(new Assignment(group1, commision1));
|
||||
final Assignment assignmentUser2 = this.assignmentService.save(new Assignment(group2, commision2));
|
||||
final Assignment assignmentUser3 = this.assignmentService.save(new Assignment(group2, commision3));
|
||||
final Assignment assignmentUser4 = this.assignmentService.save(new Assignment(group4, commision4));
|
||||
|
||||
this.assignmentService.callAcceptAlgorythm();
|
||||
|
||||
this.exchangeService.save(new Exchange(assignmentUser1, group2));
|
||||
Thread.sleep(1000);
|
||||
this.exchangeService.save(new Exchange(assignmentUser2, group1));
|
||||
Thread.sleep(1000);
|
||||
this.exchangeService.save(new Exchange(assignmentUser3, group1));
|
||||
Thread.sleep(1000);
|
||||
this.exchangeService.save(new Exchange(assignmentUser4, group3));
|
||||
|
||||
this.exchangeService.performExchange();
|
||||
|
||||
user1 = this.userService.getById(user1Id).get();
|
||||
Thread.sleep(1000);
|
||||
user2 = this.userService.getById(user2Id).get();
|
||||
Thread.sleep(1000);
|
||||
user3 = this.userService.getById(user3Id).get();
|
||||
Thread.sleep(1000);
|
||||
user4 = this.userService.getById(user4Id).get();
|
||||
Thread.sleep(1000);
|
||||
|
||||
final List<Long> listGroupsOfUser1 = user1.getStudentRegisteredGrups().stream().map(Groups::getId)
|
||||
.collect(Collectors.toList());
|
||||
final List<Long> listGroupsOfUser2 = user2.getStudentRegisteredGrups().stream().map(Groups::getId)
|
||||
.collect(Collectors.toList());
|
||||
final List<Long> listGroupsOfUser3 = user3.getStudentRegisteredGrups().stream().map(Groups::getId)
|
||||
.collect(Collectors.toList());
|
||||
final List<Long> listGroupsOfUser4 = user4.getStudentRegisteredGrups().stream().map(Groups::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertTrue(listGroupsOfUser1.contains(group2.getId()));
|
||||
assertTrue(listGroupsOfUser2.contains(group1.getId()));
|
||||
assertTrue(listGroupsOfUser3.contains(group2.getId()));
|
||||
assertTrue(listGroupsOfUser4.contains(group4.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldRemoveOutDatedExchnages() throws Exception {
|
||||
User user1 = this.userService.save(
|
||||
new User(null, null, "1shouldReturnMatches@ExchangeRepository.test", "123454", UserRoles.STUDENT, 451));
|
||||
final Long user1Id = user1.getId();
|
||||
final Groups group1 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.MONDAY, null));
|
||||
final Commision commision1 = this.commisionRepository.save(new Commision(user1));
|
||||
|
||||
User user2 = this.userService.save(
|
||||
new User(null, null, "2shouldReturnMatches@ExchangeRepository.test", "123455", UserRoles.STUDENT, 452));
|
||||
final Long user2Id = user2.getId();
|
||||
final Groups group2 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.THURSDAY, null));
|
||||
final Commision commision2 = this.commisionRepository.save(new Commision(user2));
|
||||
|
||||
final Groups group3 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.THURSDAY, null));
|
||||
final Groups group4 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.THURSDAY, null));
|
||||
|
||||
final Assignment assignmentUser1 = this.assignmentService.save(new Assignment(group1, commision1));
|
||||
final Assignment assignmentUser2 = this.assignmentService.save(new Assignment(group2, commision2));
|
||||
|
||||
this.assignmentService.callAcceptAlgorythm();
|
||||
|
||||
this.exchangeService.save(new Exchange(assignmentUser1, group2));
|
||||
Thread.sleep(1000);
|
||||
this.exchangeService.save(new Exchange(assignmentUser2, group1));
|
||||
Thread.sleep(1000);
|
||||
this.exchangeService.save(new Exchange(assignmentUser1, group3));
|
||||
Thread.sleep(1000);
|
||||
this.exchangeService.save(new Exchange(assignmentUser1, group4));
|
||||
Thread.sleep(1000);
|
||||
|
||||
this.exchangeService.performExchange();
|
||||
|
||||
user1 = this.userService.getById(user1Id).get();
|
||||
user2 = this.userService.getById(user2Id).get();
|
||||
|
||||
final List<Long> listGroupsOfUser1 = user1.getStudentRegisteredGrups().stream().map(Groups::getId)
|
||||
.collect(Collectors.toList());
|
||||
final List<Long> listGroupsOfUser2 = user2.getStudentRegisteredGrups().stream().map(Groups::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertTrue(listGroupsOfUser1.contains(group2.getId()));
|
||||
assertTrue(listGroupsOfUser2.contains(group1.getId()));
|
||||
assertTrue(this.exchangeService.getAllExchanges().size() == 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldSortExchanges() throws Exception{
|
||||
final List<MatchData> listMatrix = new ArrayList<>();
|
||||
final Exchange exchange1 = new Exchange(null, null);
|
||||
Thread.sleep(1000);
|
||||
final Exchange exchange2 = new Exchange(null, null);
|
||||
Thread.sleep(1000);
|
||||
final Exchange exchange3 = new Exchange(null, null);
|
||||
Thread.sleep(1000);
|
||||
final Exchange exchange4 = new Exchange(null, null);
|
||||
Thread.sleep(1000);
|
||||
|
||||
listMatrix.add(new MatchData(exchange2, exchange4));
|
||||
listMatrix.add(new MatchData(exchange1, exchange3));
|
||||
|
||||
final List<MatchData> matchDataListSorted = listMatrix.stream().sorted((m1, m2) -> -1 * m1.compare(m2)).collect(Collectors.toList());
|
||||
|
||||
assertTrue(listMatrix.get(0).equals(matchDataListSorted.get(1)));
|
||||
assertTrue(listMatrix.get(1).equals(matchDataListSorted.get(0)));
|
||||
assertTrue(matchDataListSorted.size() == 2);
|
||||
}
|
||||
}
|
42
buisnesslogic/src/test/java/com/plannaplan/services/GroupServiceTest.java
Normal file → Executable file
42
buisnesslogic/src/test/java/com/plannaplan/services/GroupServiceTest.java
Normal file → Executable file
@ -2,7 +2,15 @@ package com.plannaplan.services;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.Assignment;
|
||||
import com.plannaplan.entities.Commision;
|
||||
import com.plannaplan.entities.Groups;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
import com.plannaplan.types.WeekDay;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@ -18,20 +26,46 @@ public class GroupServiceTest {
|
||||
|
||||
@Autowired
|
||||
private GroupService groupService;
|
||||
@Autowired
|
||||
private AssignmentService assignmentService;
|
||||
@Autowired
|
||||
private CommisionService commisionService;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Test
|
||||
public void createAndDeleteGroup() {
|
||||
Groups group;
|
||||
int startAmmount = this.groupService.getGroupsAmmount();
|
||||
|
||||
//Create group
|
||||
group = new Groups();
|
||||
Groups group = new Groups();
|
||||
group.setRoom("A1");
|
||||
groupService.save(group);
|
||||
assertTrue(this.groupService.getGroupsAmmount() > startAmmount);
|
||||
|
||||
// Delete course
|
||||
groupService.delete(group);
|
||||
assertTrue(this.groupService.getGroupsAmmount() == startAmmount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetGroupsAssignmentsAmmounts() throws InterruptedException {
|
||||
final Groups testGroup = groupService.save(new Groups(43, "A-41", null, 645, WeekDay.MONDAY, null));
|
||||
final Groups testGroup2 = groupService.save(new Groups(433, "A-41", null, 235, WeekDay.TUESDAY, null));
|
||||
final Groups testGroup3 = groupService.save(new Groups(23, "A-41", null, 340, WeekDay.MONDAY, null));
|
||||
final User user = this.userService.save(
|
||||
new User("Dare", "Oc", "shouldReturnGroupAssignmentTimesList@grouprepository.test", UserRoles.STUDENT));
|
||||
final Commision commision = this.commisionService.save(new Commision(user));
|
||||
|
||||
this.assignmentService.save(new Assignment(testGroup, commision));
|
||||
this.assignmentService.save(new Assignment(testGroup2, commision));
|
||||
this.assignmentService.save(new Assignment(testGroup3, commision));
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
HashMap<Long, Integer> response = this.groupService.getTakenPlaces(List.of(testGroup, testGroup2, testGroup3));
|
||||
|
||||
assertTrue(response.size() == 3);
|
||||
assertTrue(response.get(testGroup.getId()) == 1);
|
||||
assertTrue(response.get(testGroup2.getId()) == 1);
|
||||
assertTrue(response.get(testGroup3.getId()) == 1);
|
||||
}
|
||||
}
|
||||
|
8
buisnesslogic/src/test/java/com/plannaplan/services/LecturerServiceTest.java
Normal file → Executable file
8
buisnesslogic/src/test/java/com/plannaplan/services/LecturerServiceTest.java
Normal file → Executable file
@ -20,18 +20,12 @@ public class LecturerServiceTest {
|
||||
|
||||
@Test
|
||||
public void createAndDeleteLecturer() {
|
||||
Lecturer lecturer;
|
||||
int startAmmount = this.lecturerService.getLecturersAmmount();
|
||||
|
||||
// Create lecturer
|
||||
lecturer = new Lecturer();
|
||||
lecturer.setName("Tomasz");
|
||||
lecturer.setSurname("Kowalski");
|
||||
lecturer.setTitle("prof.");
|
||||
Lecturer lecturer = new Lecturer("prof.", "Tomasz", "Kowalski");
|
||||
lecturerService.save(lecturer);
|
||||
assertTrue(this.lecturerService.getLecturersAmmount() > startAmmount);
|
||||
|
||||
// Delete lecturer
|
||||
lecturerService.delete(lecturer);
|
||||
assertTrue(this.lecturerService.getLecturersAmmount() == startAmmount);
|
||||
}
|
||||
|
107
buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java
Normal file → Executable file
107
buisnesslogic/src/test/java/com/plannaplan/services/UserServiceTest.java
Normal file → Executable file
@ -2,16 +2,19 @@ package com.plannaplan.services;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.exceptions.UserNotFoundException;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
@ -22,29 +25,21 @@ import org.junit.runner.RunWith;
|
||||
@ContextConfiguration
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
public class UserServiceTest {
|
||||
public static String TEST_USER_MAIL = "noteexisitingmail@notexistingdomain.com";
|
||||
public static String TEST_USER_NAME = "Tom";
|
||||
public static String TEST_USER_SUERNAME = "Kovalsky";
|
||||
private static String TEST_USER_MAIL = "noteexisitingmail@notexistingdomain.com";
|
||||
private static String TEST_USER_NAME = "Tom";
|
||||
private static String TEST_USER_SUERNAME = "Kovalsky";
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Before
|
||||
public void initialize() {
|
||||
User testUser = new User();
|
||||
testUser.setEmail(TEST_USER_MAIL);
|
||||
testUser.setName(TEST_USER_NAME);
|
||||
testUser.setSurname(TEST_USER_SUERNAME);
|
||||
testUser.setRole(UserRoles.TEST_USER);
|
||||
this.userService.save(testUser);
|
||||
}
|
||||
private UserService userService;
|
||||
|
||||
@Test
|
||||
public void shouldReturnToken() {
|
||||
User testUser = this.userService
|
||||
.save(new User(TEST_USER_NAME, TEST_USER_SUERNAME, TEST_USER_MAIL, UserRoles.TEST_USER));
|
||||
try {
|
||||
String token = this.userService.login(TEST_USER_MAIL);
|
||||
System.out.println("Returned token: " + token);
|
||||
assertTrue(token != null);
|
||||
testUser = this.userService.login(testUser);
|
||||
System.out.println("Returned token: " + testUser.getToken());
|
||||
assertTrue(testUser.getToken() != null);
|
||||
assertTrue(this.userService.getUserByEmail(TEST_USER_MAIL).getToken() != null);
|
||||
} catch (UserNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
@ -53,12 +48,74 @@ public class UserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldThrowException() {
|
||||
try {
|
||||
this.userService.login("thiseamilisnotindatabase@gmail.com");
|
||||
assertTrue(false);
|
||||
} catch (UserNotFoundException e) {
|
||||
assertTrue(true);
|
||||
}
|
||||
public void shouldFindStudents() {
|
||||
this.userService.save(new User("Nemo", "TheFish", "Nemo@shouldFindStudents.test", UserRoles.STUDENT));
|
||||
final List<User> response = this.userService.searchForStudents("Nemo");
|
||||
assertTrue(response.size() >= 1);
|
||||
assertTrue(containsName(response, "Nemo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnAllStudents() {
|
||||
final User veryWantedUser = new User("Xavier", "123", "Xavier@shouldReturnAllStudents.test", UserRoles.STUDENT);
|
||||
final User littleLessWanted = new User("Ravier", "321", "Ravier@shouldReturnAllStudents.test",
|
||||
UserRoles.STUDENT);
|
||||
final User notWantadUser = new User("Fiona", "Raskolnikov", "Fiona@shouldReturnAllStudents.test",
|
||||
UserRoles.DEANERY);
|
||||
|
||||
this.userService.save(veryWantedUser);
|
||||
this.userService.save(littleLessWanted);
|
||||
this.userService.save(notWantadUser);
|
||||
|
||||
final List<User> response = this.userService.searchForStudents("");
|
||||
assertTrue(response.size() >= 2);
|
||||
assertTrue(!containsName(response, notWantadUser.getName()));
|
||||
assertTrue(containsName(response, littleLessWanted.getName()));
|
||||
assertTrue(containsName(response, veryWantedUser.getName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldntFindStudents() {
|
||||
this.userService.save(new User("Nadia", "Ladia", "Nadia@shouldntFindStudents.test", UserRoles.STUDENT));
|
||||
final List<User> response = this.userService.searchForStudents(
|
||||
"THISisIMPOIBLEQUEryThatShouldntReturnAnyPersonAtAllfnjiasdfjivlsdfnjgklsomerandomcharsjustinCaseXD");
|
||||
assertTrue(response.size() == 0);
|
||||
}
|
||||
|
||||
private boolean containsName(final List<User> list, final String name) {
|
||||
return list.stream().map(User::getName).filter(name::equals).findFirst().isPresent();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateUser() {
|
||||
|
||||
final User user = this.userService.checkForUser("shouldCreateUser@UserService.test", null);
|
||||
|
||||
assertTrue(user.getId() != null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnExistingUser() {
|
||||
final String email = "shouldReturnExistingUser@UserService.test";
|
||||
this.userService.save(new User("Tom", "Smieszne", email, UserRoles.TEST_USER));
|
||||
final User user = this.userService.checkForUser(email, null);
|
||||
|
||||
assertTrue(user.getName() != "Tom");
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
38
buisnesslogic/src/test/java/com/plannaplan/services/UsosApiServiceTest.java
Executable file
38
buisnesslogic/src/test/java/com/plannaplan/services/UsosApiServiceTest.java
Executable file
@ -0,0 +1,38 @@
|
||||
package com.plannaplan.services;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import com.plannaplan.models.UserApiResponse;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class UsosApiServiceTest {
|
||||
|
||||
@Autowired
|
||||
private UsosApiService service;
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void shouldReturnPersonalData() throws IOException, InterruptedException, ExecutionException {
|
||||
|
||||
final UserApiResponse response = this.service.getUserData("499054");
|
||||
|
||||
assertTrue(response.getName().equals("Marcin"));
|
||||
assertTrue(response.getSurname().equals("Woźniak"));
|
||||
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user