Compare commits
455 Commits
Author | SHA1 | Date | |
---|---|---|---|
70c2ab3f8c | |||
9c2fcef028 | |||
0a8a5f2df4 | |||
7713078596 | |||
e6b4ed9f2c | |||
6dc88fdada | |||
234b043d72 | |||
f522ed9b81 | |||
6f6a8b0eac | |||
eb5ad650c9 | |||
9274dfc3d0 | |||
41b5d42330 | |||
c6c0db0232 | |||
6a04b5e037 | |||
a9c617075f | |||
db4620694c | |||
70c950cdd7 | |||
a9e8336986 | |||
23797bae9e | |||
37c1d0db08 | |||
b49adee62a | |||
c8382c4aea | |||
6e40343d6c | |||
55a76daa5a | |||
5371df1f50 | |||
|
4ab3637d9c | ||
|
893f7ae1f2 | ||
|
06f657f5c2 | ||
|
b13f331f2c | ||
|
12973109d3 | ||
|
278e2135bb | ||
|
b662437afe | ||
|
5ae17fbe83 | ||
|
3f16c8a078 | ||
|
e3da8c710f | ||
|
54b992a7f3 | ||
|
e20fb468f9 | ||
|
1a3ffb7bab | ||
|
d29416fb76 | ||
|
37053d853b | ||
|
b961c8e3dc | ||
|
3dd6210f42 | ||
|
5520f19357 | ||
|
2cc3008dc5 | ||
|
708a1a6d32 | ||
|
751195bf96 | ||
|
6adb3fec71 | ||
|
ae0a1f3532 | ||
|
e167a68bc6 | ||
|
6b717f26d3 | ||
|
b20ab96b55 | ||
|
2c55293e0e | ||
|
a14735699c | ||
|
9f21850767 | ||
|
abde7f311c | ||
|
5333258c62 | ||
|
2149dfd32f | ||
|
34c5e79cbb | ||
|
2110c21be7 | ||
|
30e06335e9 | ||
|
c528711431 | ||
|
0bb9768bda | ||
|
52d6210875 | ||
|
65569732d6 | ||
|
1d0c90d932 | ||
|
440def2b71 | ||
|
1460e26127 | ||
|
1f5cde4b66 | ||
|
10a99d42cf | ||
|
90c11c6946 | ||
|
134f75666c | ||
|
b8d492724c | ||
|
bc48a486ee | ||
|
c36876f7e7 | ||
|
a136acb0b4 | ||
|
7d1f5e9059 | ||
|
4c4c1b2015 | ||
|
6b90d7b0c0 | ||
|
fa03edf32d | ||
|
4e1d99392a | ||
|
ac55481bc6 | ||
|
71448364d7 | ||
|
c57914db7c | ||
|
ab20b3843f | ||
|
268a311a87 | ||
|
a67eb23714 | ||
|
5ee1f33de1 | ||
|
107ddb90ac | ||
|
ac6bd13c6c | ||
|
e7061f4545 | ||
|
d741bd019a | ||
|
846d94bb46 | ||
|
5755cf2f92 | ||
|
7587ff7a51 | ||
|
6c220355ee | ||
|
779f286988 | ||
|
7753dd104c | ||
|
48955b9cfd | ||
|
9665653234 | ||
|
04f545db1c | ||
|
746f443931 | ||
|
1be74769bf | ||
|
2cdec4bcda | ||
|
a17dac55e2 | ||
|
9e6993f136 | ||
|
0647438bfb | ||
|
41c4ee7997 | ||
|
9d3ee273f6 | ||
|
3267138524 | ||
|
df1bf873ff | ||
|
24f447aed7 | ||
|
36c4e52e37 | ||
|
529db0442c | ||
|
db97892af2 | ||
|
ff19001f1f | ||
|
2012a58fc2 | ||
|
9ba4476f80 | ||
|
098f70ede6 | ||
|
d84b1fcbdc | ||
|
b44bbaec75 | ||
|
436c15e727 | ||
|
e4f5bede2a | ||
|
888fecf687 | ||
|
51ed732ae8 | ||
|
18bb0b85ac | ||
|
615c70d12a | ||
|
96d166d031 | ||
|
fb23f182de | ||
|
f8c1e52ca4 | ||
|
59e52aaf4a | ||
|
dc467ec72c | ||
|
019ac6e0ad | ||
|
1ccec83390 | ||
|
4104844b1e | ||
|
c0afabc37c | ||
|
624573a47a | ||
|
fddc15af5a | ||
|
bdb8fd8ce4 | ||
|
acd58005de | ||
|
1ff38fc80e | ||
|
c77702704f | ||
|
44824e53b2 | ||
|
bacd3827e3 | ||
|
0cd8003dd7 | ||
|
bdff81d25e | ||
|
482964fe53 | ||
|
dc52968ddf | ||
|
22abf6a27d | ||
|
abea3c7dad | ||
|
23d4e5602f | ||
|
bde4ac5f1c | ||
|
3898dcf1c1 | ||
|
2d230afa35 | ||
|
db3252d822 | ||
|
e6dc2abdd9 | ||
|
ae8dc58a9d | ||
|
38478835fb | ||
|
7edb9d2aa3 | ||
|
961a6a318e | ||
|
267bd5b0f3 | ||
|
a5ac2bcbc2 | ||
|
291f4e1e33 | ||
|
53307c6add | ||
|
a405267092 | ||
|
1224cc7a23 | ||
|
a878f8c22c | ||
|
d2ce6d604e | ||
|
b4b7b9087e | ||
|
a7b48e1534 | ||
|
9388302a47 | ||
|
e680aa30c4 | ||
|
4498b71259 | ||
|
632c6299b7 | ||
|
9013d79228 | ||
|
192adbfa0b | ||
|
eb30d07d10 | ||
|
eceb8ec528 | ||
|
330ffc4df1 | ||
|
77ce908d58 | ||
|
8ffafd6693 | ||
|
e967e2bfee | ||
|
c25392337a | ||
|
3b0a2dd964 | ||
|
8d1e410e83 | ||
|
eb87c6d52f | ||
|
a35bcfce1b | ||
|
6258e7b6bf | ||
|
c4b35ddf6a | ||
|
7388e12e3f | ||
|
4bb4fd6bca | ||
|
4eeb79ab80 | ||
|
336a16ff73 | ||
|
0e7fdac980 | ||
|
482e2b3595 | ||
|
2b911017b1 | ||
|
0cd3055176 | ||
|
280c39dae4 | ||
|
828d320e0f | ||
|
678397e970 | ||
|
916bbae414 | ||
|
477a9fd6ff | ||
|
59d6edb818 | ||
|
f4479c2ab7 | ||
|
193b2b3a32 | ||
|
837a9f465c | ||
|
eba3592410 | ||
|
22195813ae | ||
|
43e7b9fe1f | ||
|
308da4113d | ||
|
c9ecae9842 | ||
|
d4364b9767 | ||
|
505a054cc8 | ||
|
8bb9e3a844 | ||
|
661da17f73 | ||
|
01bcac2680 | ||
|
421ed635e8 | ||
|
24a1276005 | ||
|
512a805e8c | ||
|
ab17b9f152 | ||
|
181086c9db | ||
|
82e454a50b | ||
|
c303d65c8d | ||
|
7c1b124c94 | ||
|
29cfadef02 | ||
|
ef521123dd | ||
|
82ae42f7fc | ||
|
af09938e66 | ||
|
1c8359f900 | ||
|
47131f1fb7 | ||
|
284a3f51e9 | ||
|
bd24525315 | ||
|
3e9bbb3584 | ||
|
16885cc94f | ||
|
b1c090b0ea | ||
|
ecda92326b | ||
|
457f1da985 | ||
|
5f214620bf | ||
|
c21739bfc6 | ||
|
bab621677e | ||
|
8b52518c4a | ||
|
d7c4e6b222 | ||
|
bb9f412480 | ||
|
c0e66e81a2 | ||
|
1823c1ba50 | ||
|
e468646cd6 | ||
|
90799356ab | ||
|
59bc0dbd34 | ||
|
d076f35ff7 | ||
|
56f083e757 | ||
|
532e007b0b | ||
|
3dbf635fb6 | ||
|
3da374326b | ||
|
4213524dbd | ||
|
f960d4de1b | ||
|
740adc5318 | ||
|
b8281c527a | ||
|
7163937a53 | ||
|
097f7827b0 | ||
|
83aba158b6 | ||
|
50314246f5 | ||
|
76d3adb464 | ||
|
64357c2508 | ||
|
6a62e61caf | ||
|
b9748905d1 | ||
|
fbd618a6d0 | ||
|
052e4a1aef | ||
|
4fc8bc3717 | ||
|
728fa42972 | ||
|
dc34c7bfb7 | ||
|
5263393379 | ||
|
80de18d3ee | ||
|
bde9cb51fb | ||
|
c0937d721a | ||
|
ce7b4c9c7a | ||
|
19a6b45cf9 | ||
|
c47d4f8a05 | ||
|
33f62c04e7 | ||
|
d50673f5fa | ||
|
f8f501b8ff | ||
|
cd1caa559e | ||
|
bc9cca62d6 | ||
|
ca3159a66b | ||
|
3226cc3971 | ||
|
48a18a3a57 | ||
|
d88f67ce00 | ||
|
11ef644e5e | ||
|
1e06edfcc0 | ||
|
7952787229 | ||
|
00c5d5f755 | ||
|
3d02f551cc | ||
|
95fc9da47d | ||
|
11cab955b4 | ||
|
c88c77cd7d | ||
|
1c5c05b5e4 | ||
|
e6cb991463 | ||
|
a8d987b01f | ||
|
3a9fde3404 | ||
|
9da5fd8a7a | ||
|
51851baa48 | ||
|
10a9bd7a28 | ||
|
58a8495835 | ||
|
ab59cb524e | ||
|
1f8722e3ff | ||
|
6044d6f8e3 | ||
|
a3afdeb988 | ||
|
aaa21d591d | ||
|
f6830d499b | ||
|
99ec7af319 | ||
|
e1907d3169 | ||
|
451e7e5d04 | ||
|
5cbbb6c319 | ||
|
70062992ae | ||
|
fe53c86136 | ||
|
5b4180e685 | ||
|
a11e10dec4 | ||
|
d846192046 | ||
|
7798508d4f | ||
|
c59bb45c70 | ||
|
0de34c89fe | ||
|
b2e8a43cee | ||
|
3f32a61ed2 | ||
|
6edcf8f594 | ||
|
4686406954 | ||
|
4e4e7ae194 | ||
|
cad8682088 | ||
|
d9a4224317 | ||
|
7b4318a3b5 | ||
|
0cb7b05c25 | ||
|
253f4b4aad | ||
|
1ad66d6fb1 | ||
|
961fdf9397 | ||
|
ff7f535980 | ||
|
77e2ad0651 | ||
|
74a8dcbd8a | ||
|
4262446aef | ||
|
b640dea99a | ||
|
2d9fd05060 | ||
|
b57142e28f | ||
|
e3ad5ba510 | ||
|
09aa3d0084 | ||
|
662847698e | ||
|
2fba252df0 | ||
|
7ffe04f1db | ||
|
d244437858 | ||
|
934d194df1 | ||
|
1e07c5424d | ||
|
dffd839905 | ||
|
279cc0e18a | ||
|
b1e101c940 | ||
|
2dae39a100 | ||
|
241c489b21 | ||
|
52ae197f34 | ||
|
4025aa67ca | ||
|
65dea9bce2 | ||
|
4bab980f62 | ||
|
ee55e08fee | ||
|
82ab40a608 | ||
|
2dff183662 | ||
|
da382b659a | ||
|
114f6769ac | ||
|
beb334f2fa | ||
|
68737b976f | ||
|
6eed8591b4 | ||
|
74d43dcd0d | ||
|
0955388f27 | ||
|
de625923e9 | ||
|
b334b5d70e | ||
|
8b333ab3a6 | ||
|
6350e1c0d6 | ||
|
6820c617f3 | ||
|
60bdd9d233 | ||
|
c8cfde67a9 | ||
|
a6f2177179 | ||
|
1f6d15b74b | ||
|
a69a257f09 | ||
|
6442a67ff1 | ||
|
2ebd61016d | ||
|
7ce8b20841 | ||
|
0e062f1337 | ||
|
9edcf35338 | ||
|
5c677a975c | ||
|
83f3f7d6b9 | ||
|
b4c11a7f90 | ||
|
0e8752e460 | ||
|
e178cd1639 | ||
|
9cf002ad95 | ||
|
39f3c69479 | ||
|
dbcdb96dbf | ||
|
a352f561fa | ||
|
b2d4d52675 | ||
|
a8fbf98d85 | ||
|
51877023d1 | ||
|
1fe2f5469b | ||
|
51e121ae24 | ||
|
8f3e3fd9a7 | ||
|
71ec7bb726 | ||
|
34925b81ff | ||
|
16e9bf1fb5 | ||
|
c489ebbf91 | ||
|
88ec35faa0 | ||
|
fc94ea1f26 | ||
|
7853496048 | ||
|
2bb5189fff | ||
|
4fa0c14ae6 | ||
|
7c5a0826c5 | ||
|
8ced83ad2b | ||
|
bc73265109 | ||
|
b77619777e | ||
|
70d260c34b | ||
|
d4b514a9b0 | ||
|
d921def09d | ||
|
f556b969b4 | ||
|
b16b3ed2e3 | ||
|
5bff419dbd | ||
|
4dd0a6c210 | ||
|
bb2518e5f4 | ||
|
1e6fbdc1fa | ||
|
54c6fe815d | ||
|
d37c9bda57 | ||
|
fe55890518 | ||
|
7eb5dce94e | ||
|
7248a84c30 | ||
|
02d643727e | ||
|
50a0f8aa78 | ||
|
2418e953be | ||
|
e32da7c7c2 | ||
|
3aea19088d | ||
|
8f2f6adc3b | ||
|
c18ecea13b | ||
|
bf515a3fcb | ||
|
2d6de6b535 | ||
|
39f44403c1 | ||
|
2f3c1addbb | ||
|
c78ea05255 | ||
|
26969dba5b | ||
|
6df1a87367 | ||
|
546b0dc323 | ||
|
41bd00d645 | ||
|
6d6ea3136d | ||
|
70920cc612 | ||
|
d3b8be2cf1 | ||
|
3698d31bc8 | ||
|
53cc777734 | ||
|
2767403128 | ||
|
5bfeaff054 | ||
|
6876d09557 | ||
|
8400c5d40d | ||
|
eec739a49f | ||
|
f29d31b840 | ||
|
7bec7b4e44 | ||
|
59887e5141 | ||
|
9da227ab34 | ||
|
6469ddcd42 | ||
|
92a0674b95 | ||
|
8fbce55028 |
19
Jenkinsfile
vendored
Normal file
19
Jenkinsfile
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
stages {
|
||||||
|
stage('Test') {
|
||||||
|
steps {
|
||||||
|
sh "./gradlew clean test --info"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
script {
|
||||||
|
if (currentBuild.currentResult == 'FAILURE') {
|
||||||
|
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "a.romanov@ulstu.ru", sendToIndividuals: true])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,4 @@
|
|||||||
4. Получить проект для обучения бакалавров современым технологиям разработки.
|
4. Получить проект для обучения бакалавров современым технологиям разработки.
|
||||||
5. Создать систему хранения и трансляции опыта между участниками научной группы.
|
5. Создать систему хранения и трансляции опыта между участниками научной группы.
|
||||||
|
|
||||||
[Демо версия доступна здесь](http://193.110.3.124:8080)
|
[Для разворачивания проекта и ведения разработки ознакомьтесь с wiki](https://git.athene.tech/romanov73/ng-tracker/wiki/home)
|
||||||
|
|
||||||
[Для разворачивания проекта и ведения разработки ознакомьтесь с wiki](https://gitlab.com/romanov73/ng-tracker/wikis/home)
|
|
103
build.gradle
103
build.gradle
@ -1,34 +1,19 @@
|
|||||||
buildscript {
|
plugins {
|
||||||
ext {
|
id 'java'
|
||||||
versionSpringBoot = '2.1.3.RELEASE'
|
id 'org.springframework.boot' version '3.2.4'
|
||||||
}
|
id 'io.spring.dependency-management' version '1.1.4'
|
||||||
|
id 'checkstyle'
|
||||||
repositories {
|
|
||||||
mavenLocal()
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: versionSpringBoot
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'ru.ulstu'
|
group 'ru.ulstu'
|
||||||
version '0.1.0-SNAPSHOT'
|
version '0.1.0-SNAPSHOT'
|
||||||
|
|
||||||
apply plugin: 'application'
|
|
||||||
apply plugin: 'java'
|
|
||||||
apply plugin: 'org.springframework.boot'
|
|
||||||
apply plugin: 'io.spring.dependency-management'
|
|
||||||
apply plugin: 'checkstyle'
|
|
||||||
|
|
||||||
mainClassName = 'ru.ulstu.NgTrackerApplication'
|
|
||||||
|
|
||||||
build.dependsOn checkstyleMain
|
build.dependsOn checkstyleMain
|
||||||
bootRun.dependsOn checkstyleMain
|
bootRun.dependsOn checkstyleMain
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
java {
|
||||||
targetCompatibility = 1.8
|
sourceCompatibility = '17'
|
||||||
|
}
|
||||||
|
|
||||||
bootRun {
|
bootRun {
|
||||||
systemProperties = System.properties
|
systemProperties = System.properties
|
||||||
@ -64,7 +49,7 @@ checkstyle {
|
|||||||
checkstyle
|
checkstyle
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies{
|
dependencies {
|
||||||
assert project.hasProperty("checkstyleVersion")
|
assert project.hasProperty("checkstyleVersion")
|
||||||
|
|
||||||
checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}"
|
checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}"
|
||||||
@ -76,9 +61,16 @@ task health(dependsOn: [
|
|||||||
'checkstyleMain'
|
'checkstyleMain'
|
||||||
])
|
])
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
baseName = 'ng-tracker'
|
enabled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
bootJar {
|
||||||
|
archiveFileName = String.format('%s-%s.jar', rootProject.name, version)
|
||||||
}
|
}
|
||||||
|
|
||||||
compileJava {
|
compileJava {
|
||||||
@ -90,44 +82,39 @@ repositories {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations {
|
|
||||||
compile.exclude module: "spring-boot-starter-tomcat"
|
|
||||||
compile.exclude module: "bcmail-jdk14"
|
|
||||||
compile.exclude module: "bcprov-jdk14"
|
|
||||||
compile.exclude module: "bctsp-jdk14"
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
|
implementation('org.springframework.boot:spring-boot-starter-web') {
|
||||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security'
|
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
|
||||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-aop'
|
}
|
||||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail'
|
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
|
||||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jetty'
|
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-aop'
|
||||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
|
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-mail'
|
||||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf'
|
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jetty'
|
||||||
compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect'
|
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
|
||||||
compile group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity5'
|
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf'
|
||||||
compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner'
|
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
|
||||||
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5'
|
implementation group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect'
|
||||||
|
implementation group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity6'
|
||||||
|
implementation group: 'com.fasterxml.jackson.module', name: 'jackson-module-afterburner'
|
||||||
|
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate5'
|
||||||
|
|
||||||
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
|
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
|
||||||
|
|
||||||
compile group: 'org.liquibase', name: 'liquibase-core', version: '3.6.3'
|
implementation group: 'org.liquibase', name: 'liquibase-core', version: '4.27.0'
|
||||||
compile group: 'com.mattbertolini', name: 'liquibase-slf4j', version: '2.0.0'
|
implementation group: 'com.mattbertolini', name: 'liquibase-slf4j', version: '2.0.0'
|
||||||
|
|
||||||
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
|
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
|
||||||
|
|
||||||
compile group: 'org.webjars', name: 'bootstrap', version: '4.1.0'
|
implementation group: 'org.webjars', name: 'bootstrap', version: '5.3.3'
|
||||||
compile group: 'org.webjars', name: 'bootstrap-select', version: '1.13.3'
|
runtimeOnly group: 'org.webjars', name: 'bootstrap-select', version: '1.4.2'
|
||||||
compile group: 'org.webjars', name: 'jquery', version: '3.3.1-1'
|
implementation group: 'org.webjars', name: 'jquery', version: '3.7.1'
|
||||||
compile group: 'org.webjars.npm', name: 'jquery.easing', version: '1.4.1'
|
implementation group: 'org.webjars', name: 'jquery-easing', version: '1.4.1'
|
||||||
compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0'
|
implementation group: 'org.webjars', name: 'font-awesome', version: '4.7.0'
|
||||||
|
|
||||||
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.6.0'
|
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.8.0'
|
||||||
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.6.0'
|
implementation group: 'net.sourceforge.htmlunit', name: 'htmlunit', version: '2.35.0'
|
||||||
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
|
implementation group: 'xalan', name: 'xalan', version: '2.7.2'
|
||||||
|
|
||||||
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
|
|
||||||
testCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1'
|
|
||||||
|
|
||||||
|
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
|
||||||
|
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.10.2'
|
||||||
}
|
}
|
@ -18,6 +18,6 @@ fi
|
|||||||
|
|
||||||
ssh $USERSERVER "cd /tmp && rm -rf $ARTIFACT_NAME*.jar && echo `date` 'killed' >> log_$ARTIFACT_NAME"
|
ssh $USERSERVER "cd /tmp && rm -rf $ARTIFACT_NAME*.jar && echo `date` 'killed' >> log_$ARTIFACT_NAME"
|
||||||
scp build/libs/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar $USERSERVER:/tmp/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar
|
scp build/libs/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar $USERSERVER:/tmp/$ARTIFACT_NAME-0.1.0-SNAPSHOT.jar
|
||||||
ssh $USERSERVER -f "cd /tmp/ && /opt/jdk1.8.0_192/bin/java -jar $ARTIFACT_NAME-0.1.0-SNAPSHOT.jar -Xms 512m -Xmx 1024m --server.port=8443 --server.http.port=8080 --ng-tracker.base-url=http://193.110.3.124:8080 >> /home/user/logfile_$ARTIFACT_NAME" &
|
ssh $USERSERVER -f "cd /tmp/ && /opt/jdk-11/bin/java -jar $ARTIFACT_NAME-0.1.0-SNAPSHOT.jar -Xms 512m -Xmx 1024m --server.port=8080 --server.http.port=8443 --ng-tracker.base-url=http://193.110.3.124:8080 --ng-tracker.dev-mode=false --ng-tracker.driver-path=/home/user >> /home/user/logfile_$ARTIFACT_NAME" &
|
||||||
sleep 10
|
sleep 10
|
||||||
echo "is deployed"
|
echo "is deployed"
|
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@ -2,4 +2,6 @@ distributionBase=GRADLE_USER_HOME
|
|||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
@ -4,20 +4,17 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import ru.ulstu.configuration.Constants;
|
|
||||||
import ru.ulstu.core.model.response.PageableItems;
|
|
||||||
import ru.ulstu.commit.model.CommitListDto;
|
import ru.ulstu.commit.model.CommitListDto;
|
||||||
import ru.ulstu.commit.service.CommitService;
|
import ru.ulstu.commit.service.CommitService;
|
||||||
|
import ru.ulstu.configuration.Constants;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
import ru.ulstu.core.model.response.Response;
|
import ru.ulstu.core.model.response.Response;
|
||||||
import ru.ulstu.odin.controller.OdinController;
|
import ru.ulstu.odin.controller.OdinController;
|
||||||
import ru.ulstu.odin.model.OdinVoid;
|
import ru.ulstu.odin.model.OdinVoid;
|
||||||
|
|
||||||
import static ru.ulstu.commit.controller.CommitController.URL;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(URL)
|
@RequestMapping(Constants.API_1_0 + "commits")
|
||||||
public class CommitController extends OdinController<CommitListDto, OdinVoid> {
|
public class CommitController extends OdinController<CommitListDto, OdinVoid> {
|
||||||
public static final String URL = Constants.API_1_0 + "commits";
|
|
||||||
private final CommitService commitService;
|
private final CommitService commitService;
|
||||||
|
|
||||||
public CommitController(CommitService commitService) {
|
public CommitController(CommitService commitService) {
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package ru.ulstu.conference.controller;
|
package ru.ulstu.conference.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Hidden;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
@ -14,18 +15,13 @@ import ru.ulstu.conference.model.ConferenceDto;
|
|||||||
import ru.ulstu.conference.model.ConferenceFilterDto;
|
import ru.ulstu.conference.model.ConferenceFilterDto;
|
||||||
import ru.ulstu.conference.model.ConferenceUser;
|
import ru.ulstu.conference.model.ConferenceUser;
|
||||||
import ru.ulstu.conference.service.ConferenceService;
|
import ru.ulstu.conference.service.ConferenceService;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static org.springframework.util.StringUtils.isEmpty;
|
|
||||||
import static ru.ulstu.core.controller.Navigation.CONFERENCES_PAGE;
|
import static ru.ulstu.core.controller.Navigation.CONFERENCES_PAGE;
|
||||||
import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE;
|
import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE;
|
||||||
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
||||||
@ -33,7 +29,7 @@ import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
|||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@RequestMapping(value = "/conferences")
|
@RequestMapping(value = "/conferences")
|
||||||
@ApiIgnore
|
@Hidden
|
||||||
public class ConferenceController {
|
public class ConferenceController {
|
||||||
|
|
||||||
private final ConferenceService conferenceService;
|
private final ConferenceService conferenceService;
|
||||||
@ -57,6 +53,8 @@ public class ConferenceController {
|
|||||||
@GetMapping("/dashboard")
|
@GetMapping("/dashboard")
|
||||||
public void getDashboard(ModelMap modelMap) {
|
public void getDashboard(ModelMap modelMap) {
|
||||||
modelMap.put("conferences", conferenceService.findAllActiveDto());
|
modelMap.put("conferences", conferenceService.findAllActiveDto());
|
||||||
|
|
||||||
|
conferenceService.setChartData(modelMap); // example
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/conference")
|
@GetMapping("/conference")
|
||||||
@ -68,30 +66,27 @@ public class ConferenceController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/conference", params = "save")
|
@PostMapping(value = "/conferences", params = "deleteConference")
|
||||||
public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
public String delete(@RequestParam("deleteConference") Integer conferenceId) throws IOException {
|
||||||
filterEmptyDeadlines(conferenceDto);
|
|
||||||
if (errors.hasErrors()) {
|
|
||||||
return CONFERENCE_PAGE;
|
|
||||||
}
|
|
||||||
conferenceService.save(conferenceDto);
|
|
||||||
return String.format(REDIRECT_TO, CONFERENCES_PAGE);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/delete/{conference-id}")
|
|
||||||
public String delete(@PathVariable("conference-id") Integer conferenceId) throws IOException {
|
|
||||||
conferenceService.delete(conferenceId);
|
conferenceService.delete(conferenceId);
|
||||||
return String.format(REDIRECT_TO, CONFERENCES_PAGE);
|
return String.format(REDIRECT_TO, CONFERENCES_PAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/conference", params = "save")
|
||||||
|
public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||||
|
if (!conferenceService.save(conferenceDto, errors)) {
|
||||||
|
return CONFERENCE_PAGE;
|
||||||
|
}
|
||||||
|
return String.format(REDIRECT_TO, CONFERENCES_PAGE);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/conference", params = "addDeadline")
|
@PostMapping(value = "/conference", params = "addDeadline")
|
||||||
public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) {
|
public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||||
filterEmptyDeadlines(conferenceDto);
|
conferenceService.filterEmptyDeadlines(conferenceDto);
|
||||||
if (errors.hasErrors()) {
|
if (errors.hasErrors()) {
|
||||||
return CONFERENCE_PAGE;
|
return CONFERENCE_PAGE;
|
||||||
}
|
}
|
||||||
conferenceDto.getDeadlines().add(new Deadline());
|
conferenceService.addDeadline(conferenceDto);
|
||||||
return CONFERENCE_PAGE;
|
return CONFERENCE_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +100,16 @@ public class ConferenceController {
|
|||||||
return CONFERENCE_PAGE;
|
return CONFERENCE_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/conference", params = "addPaper")
|
||||||
|
public String addPaper(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||||
|
if (errors.hasErrors()) {
|
||||||
|
return CONFERENCE_PAGE;
|
||||||
|
}
|
||||||
|
conferenceService.addPaper(conferenceDto);
|
||||||
|
|
||||||
|
return CONFERENCE_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/conference", params = "removePaper")
|
@PostMapping(value = "/conference", params = "removePaper")
|
||||||
public String removePaper(@Valid ConferenceDto conferenceDto, Errors errors,
|
public String removePaper(@Valid ConferenceDto conferenceDto, Errors errors,
|
||||||
@RequestParam(value = "removePaper") Integer paperIndex) throws IOException {
|
@RequestParam(value = "removePaper") Integer paperIndex) throws IOException {
|
||||||
@ -124,6 +129,15 @@ public class ConferenceController {
|
|||||||
return CONFERENCE_PAGE;
|
return CONFERENCE_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/conference", params = "pingConference")
|
||||||
|
public String ping(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||||
|
if (errors.hasErrors()) {
|
||||||
|
return CONFERENCE_PAGE;
|
||||||
|
}
|
||||||
|
conferenceService.ping(conferenceDto);
|
||||||
|
return CONFERENCE_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
@ModelAttribute("allParticipation")
|
@ModelAttribute("allParticipation")
|
||||||
public List<ConferenceUser.Participation> getAllParticipation() {
|
public List<ConferenceUser.Participation> getAllParticipation() {
|
||||||
return conferenceService.getAllParticipations();
|
return conferenceService.getAllParticipations();
|
||||||
@ -148,9 +162,4 @@ public class ConferenceController {
|
|||||||
return years;
|
return years;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void filterEmptyDeadlines(ConferenceDto conferenceDto) {
|
|
||||||
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
|
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
|
||||||
.collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,40 @@
|
|||||||
package ru.ulstu.conference.model;
|
package ru.ulstu.conference.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.CascadeType;
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.DiscriminatorValue;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.OneToMany;
|
||||||
|
import jakarta.persistence.OrderBy;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.persistence.Temporal;
|
||||||
|
import jakarta.persistence.TemporalType;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import org.hibernate.annotations.Fetch;
|
import org.hibernate.annotations.Fetch;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
import ru.ulstu.core.model.EventSource;
|
||||||
|
import ru.ulstu.core.model.UserActivity;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
import ru.ulstu.timeline.model.Event;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.FetchType;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.JoinTable;
|
|
||||||
import javax.persistence.ManyToMany;
|
|
||||||
import javax.persistence.OneToMany;
|
|
||||||
import javax.persistence.OrderBy;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import javax.persistence.Temporal;
|
|
||||||
import javax.persistence.TemporalType;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "conference")
|
@Table(name = "conference")
|
||||||
public class Conference extends BaseEntity {
|
@DiscriminatorValue("CONFERENCE")
|
||||||
|
public class Conference extends BaseEntity implements UserActivity, EventSource {
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String title;
|
private String title;
|
||||||
@ -35,17 +43,17 @@ public class Conference extends BaseEntity {
|
|||||||
|
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
private int ping;
|
private int ping = 0;
|
||||||
|
|
||||||
@Column(name = "begin_date")
|
@Column(name = "begin_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date beginDate;
|
private Date beginDate = new Date();
|
||||||
|
|
||||||
@Column(name = "end_date")
|
@Column(name = "end_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date endDate;
|
private Date endDate = new Date();
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "conference_id", unique = true)
|
@JoinColumn(name = "conference_id", unique = true)
|
||||||
@ -53,21 +61,38 @@ public class Conference extends BaseEntity {
|
|||||||
@OrderBy("date")
|
@OrderBy("date")
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER)
|
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||||
@JoinTable(name = "paper_conference",
|
@JoinColumn(name = "conference_id")
|
||||||
joinColumns = {@JoinColumn(name = "conference_id")},
|
|
||||||
inverseJoinColumns = {@JoinColumn(name = "paper_id")})
|
|
||||||
private List<Paper> papers = new ArrayList<>();
|
private List<Paper> papers = new ArrayList<>();
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "conference_id", unique = true)
|
@JoinColumn(name = "conference_id", unique = true)
|
||||||
@Fetch(FetchMode.SUBSELECT)
|
|
||||||
private List<ConferenceUser> users = new ArrayList<>();
|
private List<ConferenceUser> users = new ArrayList<>();
|
||||||
|
|
||||||
|
public Conference() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Conference(@NotBlank String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<User> getRecipients() {
|
||||||
|
List<User> list = new ArrayList<>();
|
||||||
|
|
||||||
|
getUsers().forEach(conferenceUser -> list.add(conferenceUser.getUser()));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addObjectToEvent(Event event) {
|
||||||
|
event.setConference(this);
|
||||||
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
@ -135,4 +160,18 @@ public class Conference extends BaseEntity {
|
|||||||
public void setUsers(List<ConferenceUser> users) {
|
public void setUsers(List<ConferenceUser> users) {
|
||||||
this.users = users;
|
this.users = users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<Deadline> getNextDeadline() {
|
||||||
|
return deadlines
|
||||||
|
.stream()
|
||||||
|
.filter(deadline -> deadline.getDate() != null)
|
||||||
|
.sorted(Comparator.comparing(Deadline::getDate))
|
||||||
|
.filter(d -> d.getDate().after(new Date()))
|
||||||
|
.findFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<User> getActivityUsers() {
|
||||||
|
return getUsers().stream().map(ConferenceUser::getUser).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,22 +2,24 @@ package ru.ulstu.conference.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import jakarta.persistence.Temporal;
|
||||||
|
import jakarta.persistence.TemporalType;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.name.NameContainer;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
|
||||||
import javax.persistence.Temporal;
|
|
||||||
import javax.persistence.TemporalType;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import javax.validation.constraints.Size;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class ConferenceDto {
|
public class ConferenceDto extends NameContainer {
|
||||||
|
|
||||||
private final static String BEGIN_DATE = "Начало: ";
|
private final static String BEGIN_DATE = "Начало: ";
|
||||||
private final static String END_DATE = "Конец: ";
|
private final static String END_DATE = "Конец: ";
|
||||||
@ -219,4 +221,33 @@ public class ConferenceDto {
|
|||||||
return BEGIN_DATE + beginDate.toString().split(" ")[0] + " " + END_DATE + endDate.toString().split(" ")[0];
|
return BEGIN_DATE + beginDate.toString().split(" ")[0] + " " + END_DATE + endDate.toString().split(" ")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ConferenceDto that = (ConferenceDto) o;
|
||||||
|
return ping == that.ping &&
|
||||||
|
disabledTakePart == that.disabledTakePart &&
|
||||||
|
Objects.equals(id, that.id) &&
|
||||||
|
Objects.equals(title, that.title) &&
|
||||||
|
Objects.equals(description, that.description) &&
|
||||||
|
Objects.equals(url, that.url) &&
|
||||||
|
Objects.equals(deadlines, that.deadlines) &&
|
||||||
|
Objects.equals(removedDeadlineIds, that.removedDeadlineIds) &&
|
||||||
|
Objects.equals(userIds, that.userIds) &&
|
||||||
|
Objects.equals(paperIds, that.paperIds) &&
|
||||||
|
Objects.equals(papers, that.papers) &&
|
||||||
|
Objects.equals(notSelectedPapers, that.notSelectedPapers) &&
|
||||||
|
Objects.equals(users, that.users);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, title, description, url, ping, beginDate, endDate, deadlines, removedDeadlineIds,
|
||||||
|
userIds, paperIds, papers, notSelectedPapers, users, disabledTakePart);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,14 @@ public class ConferenceFilterDto {
|
|||||||
public ConferenceFilterDto() {
|
public ConferenceFilterDto() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceFilterDto(List<ConferenceDto> conferenceDtos, Integer filterUserId, Integer year) {
|
public ConferenceFilterDto(List<ConferenceDto> conferences, Integer filterUserId, Integer year) {
|
||||||
this.conferences = conferenceDtos;
|
this.conferences = conferences;
|
||||||
this.filterUserId = filterUserId;
|
this.filterUserId = filterUserId;
|
||||||
this.year = year;
|
this.year = year;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceFilterDto(List<ConferenceDto> conferenceDtos) {
|
public ConferenceFilterDto(List<ConferenceDto> conferences) {
|
||||||
this(conferenceDtos, null, null);
|
this(conferences, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ConferenceDto> getConferences() {
|
public List<ConferenceDto> getConferences() {
|
||||||
|
@ -2,18 +2,17 @@ package ru.ulstu.conference.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EnumType;
|
|
||||||
import javax.persistence.Enumerated;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users_conference")
|
@Table(name = "users_conference")
|
||||||
public class ConferenceUser extends BaseEntity {
|
public class ConferenceUser extends BaseEntity {
|
||||||
@ -22,7 +21,7 @@ public class ConferenceUser extends BaseEntity {
|
|||||||
INTRAMURAL("Очная"),
|
INTRAMURAL("Очная"),
|
||||||
EXTRAMURAL("Заочная");
|
EXTRAMURAL("Заочная");
|
||||||
|
|
||||||
private String participationName;
|
private final String participationName;
|
||||||
|
|
||||||
Participation(String name) {
|
Participation(String name) {
|
||||||
this.participationName = name;
|
this.participationName = name;
|
||||||
@ -38,7 +37,7 @@ public class ConferenceUser extends BaseEntity {
|
|||||||
REPORT("Доклад"),
|
REPORT("Доклад"),
|
||||||
PRESENTATION("Презентация");
|
PRESENTATION("Презентация");
|
||||||
|
|
||||||
private String depositName;
|
private final String depositName;
|
||||||
|
|
||||||
Deposit(String name) {
|
Deposit(String name) {
|
||||||
this.depositName = name;
|
this.depositName = name;
|
||||||
@ -69,6 +68,7 @@ public class ConferenceUser extends BaseEntity {
|
|||||||
|
|
||||||
public ConferenceUser(User user) {
|
public ConferenceUser(User user) {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
this.deposit = Deposit.REPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
|
@ -1,19 +1,36 @@
|
|||||||
package ru.ulstu.conference.repository;
|
package ru.ulstu.conference.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Modifying;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import ru.ulstu.conference.model.Conference;
|
import ru.ulstu.conference.model.Conference;
|
||||||
|
import ru.ulstu.name.BaseRepository;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface ConferenceRepository extends JpaRepository<Conference, Integer> {
|
public interface ConferenceRepository extends JpaRepository<Conference, Integer>, BaseRepository {
|
||||||
@Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " +
|
@Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " +
|
||||||
"AND (YEAR(c.beginDate) = :year OR :year IS NULL) ORDER BY begin_date DESC")
|
"AND (YEAR(c.beginDate) = :year OR :year IS NULL) ORDER BY c.beginDate DESC")
|
||||||
List<Conference> findByUserAndYear(@Param("user") User user, @Param("year") Integer year);
|
List<Conference> findByUserAndYear(@Param("user") User user, @Param("year") Integer year);
|
||||||
|
|
||||||
@Query("SELECT c FROM Conference c WHERE c.beginDate > :date")
|
@Query("SELECT c FROM Conference c WHERE c.beginDate > :date")
|
||||||
List<Conference> findAllActive(@Param("date") Date date);
|
List<Conference> findAllActive(@Param("date") Date date);
|
||||||
|
|
||||||
|
@Query("SELECT case when count(c) > 0 then true else false end FROM Conference c JOIN c.papers p WHERE p.id = :paperId")
|
||||||
|
boolean isPaperAttached(@Param("paperId") Integer paperId);
|
||||||
|
|
||||||
|
@Modifying
|
||||||
|
@Query("UPDATE Conference c SET c.ping = (c.ping + 1) WHERE c.id = :id")
|
||||||
|
int updatePingConference(@Param("id") Integer id);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Query("SELECT title FROM Conference c WHERE (c.title = :name) AND (:id IS NULL OR c.id != :id) ")
|
||||||
|
List<String> findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
|
|
||||||
|
@Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " +
|
||||||
|
"AND (u.participation = 'INTRAMURAL') AND (c.beginDate <= CURRENT_DATE) AND (c.endDate >= CURRENT_DATE)")
|
||||||
|
Conference findActiveByUser(@Param("user") User user);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,112 @@
|
|||||||
package ru.ulstu.conference.service;
|
package ru.ulstu.conference.service;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
|
import ru.ulstu.core.util.DateUtils;
|
||||||
|
import ru.ulstu.ping.service.PingService;
|
||||||
|
import ru.ulstu.user.service.MailService;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ConferenceNotificationService {
|
public class ConferenceNotificationService {
|
||||||
|
|
||||||
|
private final static int YESTERDAY = -1;
|
||||||
|
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
||||||
|
private final static String TEMPLATE_PING = "conferencePingNotification";
|
||||||
|
private final static String TEMPLATE_DEADLINE = "conferenceDeadlineNotification";
|
||||||
|
private final static String TEMPLATE_CREATE = "conferenceCreateNotification";
|
||||||
|
private final static String TEMPLATE_UPDATE_DEADLINES = "conferenceUpdateDeadlinesNotification";
|
||||||
|
private final static String TEMPLATE_UPDATE_DATES = "conferenceUpdateDatesNotification";
|
||||||
|
|
||||||
|
private final static String TITLE_PING = "Обратите внимание на конференцию: %s";
|
||||||
|
private final static String TITLE_DEADLINE = "Приближается дедлайн конференции: %s";
|
||||||
|
private final static String TITLE_CREATE = "Создана новая конференция: %s";
|
||||||
|
private final static String TITLE_UPDATE_DEADLINES = "Изменения дедлайнов в конференции: %s";
|
||||||
|
private final static String TITLE_UPDATE_DATES = "Изменение дат проведения конференции: %s";
|
||||||
|
|
||||||
|
private final MailService mailService;
|
||||||
|
private final UserService userService;
|
||||||
|
private final PingService pingService;
|
||||||
|
|
||||||
|
public ConferenceNotificationService(MailService mailService,
|
||||||
|
UserService userService,
|
||||||
|
PingService pingService) {
|
||||||
|
this.mailService = mailService;
|
||||||
|
this.userService = userService;
|
||||||
|
this.pingService = pingService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendDeadlineNotifications(List<Conference> conferences) {
|
||||||
|
Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION);
|
||||||
|
conferences
|
||||||
|
.stream()
|
||||||
|
.filter(conference -> needToSendDeadlineNotification(conference, now))
|
||||||
|
.forEach(this::sendMessageDeadline);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean needToSendDeadlineNotification(Conference conference, Date compareDate) {
|
||||||
|
return (conference.getNextDeadline().isPresent())
|
||||||
|
&& conference.getNextDeadline().get().getDate().after(new Date())
|
||||||
|
&& conference.getNextDeadline().get().getDate().before(compareDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageDeadline(Conference conference) {
|
||||||
|
Map<String, Object> variables = Map.of("conference", conference);
|
||||||
|
sendForAllParticipants(variables, conference, TEMPLATE_DEADLINE, String.format(TITLE_DEADLINE, conference.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCreateNotification(Conference conference) {
|
||||||
|
Map<String, Object> variables = Map.of("conference", conference);
|
||||||
|
sendForAllUsers(variables, String.format(TITLE_CREATE, conference.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateDeadlineNotification(Conference conference) {
|
||||||
|
Map<String, Object> variables = Map.of("conference", conference);
|
||||||
|
sendForAllParticipants(variables, conference, TEMPLATE_UPDATE_DEADLINES, String.format(TITLE_UPDATE_DEADLINES, conference.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateConferencesDatesNotification(Conference conference, Date oldBeginDate, Date oldEndDate) {
|
||||||
|
Map<String, Object> variables = Map.of("conference", conference, "oldBeginDate", oldBeginDate, "oldEndDate", oldEndDate);
|
||||||
|
sendForAllParticipants(variables, conference, TEMPLATE_UPDATE_DATES, String.format(TITLE_UPDATE_DATES, conference.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendForAllUsers(Map<String, Object> variables, String title) {
|
||||||
|
userService.findAll().forEach(user -> mailService.sendEmailFromTemplate(variables, user, ConferenceNotificationService.TEMPLATE_CREATE, title));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendForAllParticipants(Map<String, Object> variables, Conference conference, String template, String title) {
|
||||||
|
conference.getUsers().forEach(conferenceUser -> mailService.sendEmailFromTemplate(variables, conferenceUser.getUser(), template, title));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void sendPingNotifications(List<Conference> conferences) {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(new Date());
|
||||||
|
calendar.add(Calendar.DAY_OF_MONTH, YESTERDAY);
|
||||||
|
conferences
|
||||||
|
.stream()
|
||||||
|
.filter(conference -> {
|
||||||
|
Integer pingCount = pingService.countPingYesterday(conference, calendar);
|
||||||
|
return needToSendPingNotification(conference, pingCount);
|
||||||
|
})
|
||||||
|
.forEach(this::sendMessagePing);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean needToSendPingNotification(Conference conference, Integer pingCount) {
|
||||||
|
if (pingCount > 0) {
|
||||||
|
conference.setPing((Integer) pingCount);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessagePing(Conference conference) {
|
||||||
|
Map<String, Object> variables = Map.of("conference", conference);
|
||||||
|
sendForAllParticipants(variables, conference, TEMPLATE_PING, String.format(TITLE_PING, conference.getTitle()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
package ru.ulstu.conference.service;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ConferenceScheduler {
|
||||||
|
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(ConferenceScheduler.class);
|
||||||
|
|
||||||
|
private final ConferenceNotificationService conferenceNotificationService;
|
||||||
|
private final ConferenceService conferenceService;
|
||||||
|
|
||||||
|
public ConferenceScheduler(ConferenceNotificationService conferenceNotificationService,
|
||||||
|
ConferenceService conferenceService) {
|
||||||
|
this.conferenceNotificationService = conferenceNotificationService;
|
||||||
|
this.conferenceService = conferenceService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
|
||||||
|
public void checkDeadlineBeforeWeek() {
|
||||||
|
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started");
|
||||||
|
conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll());
|
||||||
|
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara")
|
||||||
|
public void checkNewPing() {
|
||||||
|
log.debug("ConferenceScheduler.checkPing started");
|
||||||
|
conferenceNotificationService.sendPingNotifications(conferenceService.findAll());
|
||||||
|
log.debug("ConferenceScheduler.checkPing finished");
|
||||||
|
}
|
||||||
|
}
|
@ -4,28 +4,38 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.ui.ModelMap;
|
||||||
|
import org.springframework.validation.Errors;
|
||||||
import ru.ulstu.conference.model.Conference;
|
import ru.ulstu.conference.model.Conference;
|
||||||
import ru.ulstu.conference.model.ConferenceDto;
|
import ru.ulstu.conference.model.ConferenceDto;
|
||||||
import ru.ulstu.conference.model.ConferenceFilterDto;
|
import ru.ulstu.conference.model.ConferenceFilterDto;
|
||||||
import ru.ulstu.conference.model.ConferenceUser;
|
import ru.ulstu.conference.model.ConferenceUser;
|
||||||
import ru.ulstu.conference.repository.ConferenceRepository;
|
import ru.ulstu.conference.repository.ConferenceRepository;
|
||||||
|
import ru.ulstu.core.util.DateUtils;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.name.BaseService;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
|
import ru.ulstu.ping.service.PingService;
|
||||||
|
import ru.ulstu.timeline.service.EventService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ConferenceService {
|
public class ConferenceService extends BaseService {
|
||||||
private final static int MAX_DISPLAY_SIZE = 40;
|
private final static int MAX_DISPLAY_SIZE = 40;
|
||||||
|
|
||||||
private final ConferenceRepository conferenceRepository;
|
private final ConferenceRepository conferenceRepository;
|
||||||
@ -33,21 +43,31 @@ public class ConferenceService {
|
|||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
private final PaperService paperService;
|
private final PaperService paperService;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
private final PingService pingService;
|
||||||
|
private final ConferenceNotificationService conferenceNotificationService;
|
||||||
|
private final EventService eventService;
|
||||||
|
|
||||||
public ConferenceService(ConferenceRepository conferenceRepository,
|
public ConferenceService(ConferenceRepository conferenceRepository,
|
||||||
ConferenceUserService conferenceUserService,
|
ConferenceUserService conferenceUserService,
|
||||||
DeadlineService deadlineService,
|
DeadlineService deadlineService,
|
||||||
PaperService paperService,
|
PaperService paperService,
|
||||||
UserService userService) {
|
UserService userService,
|
||||||
|
PingService pingService,
|
||||||
|
ConferenceNotificationService conferenceNotificationService,
|
||||||
|
EventService eventService) {
|
||||||
|
this.baseRepository = conferenceRepository;
|
||||||
this.conferenceRepository = conferenceRepository;
|
this.conferenceRepository = conferenceRepository;
|
||||||
this.conferenceUserService = conferenceUserService;
|
this.conferenceUserService = conferenceUserService;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.paperService = paperService;
|
this.paperService = paperService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
|
this.pingService = pingService;
|
||||||
|
this.conferenceNotificationService = conferenceNotificationService;
|
||||||
|
this.eventService = eventService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto getExistConferenceById(Integer id) {
|
public ConferenceDto getExistConferenceById(Integer id) {
|
||||||
ConferenceDto conferenceDto = findOneDto(id);
|
ConferenceDto conferenceDto = new ConferenceDto(conferenceRepository.getOne(id));
|
||||||
conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds()));
|
conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds()));
|
||||||
conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers()));
|
conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers()));
|
||||||
return conferenceDto;
|
return conferenceDto;
|
||||||
@ -55,13 +75,13 @@ public class ConferenceService {
|
|||||||
|
|
||||||
public ConferenceDto getNewConference() {
|
public ConferenceDto getNewConference() {
|
||||||
ConferenceDto conferenceDto = new ConferenceDto();
|
ConferenceDto conferenceDto = new ConferenceDto();
|
||||||
conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList<Integer>()));
|
conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList<>()));
|
||||||
return conferenceDto;
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<Conference> findAll() {
|
public List<Conference> findAll() {
|
||||||
return conferenceRepository.findAll(new Sort(Sort.Direction.DESC, "beginDate"));
|
return conferenceRepository.findAll(Sort.by(Sort.Direction.DESC, "beginDate"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ConferenceDto> findAllDto() {
|
public List<ConferenceDto> findAllDto() {
|
||||||
@ -70,58 +90,122 @@ public class ConferenceService {
|
|||||||
return conferences;
|
return conferences;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto findOneDto(Integer id) {
|
public boolean save(ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||||
return new ConferenceDto(conferenceRepository.getOne(id));
|
conferenceDto.setName(conferenceDto.getTitle());
|
||||||
|
filterEmptyDeadlines(conferenceDto);
|
||||||
|
checkEmptyFieldsOfDeadline(conferenceDto, errors);
|
||||||
|
checkEmptyFieldsOfDates(conferenceDto, errors);
|
||||||
|
checkUniqueName(conferenceDto,
|
||||||
|
errors,
|
||||||
|
conferenceDto.getId(),
|
||||||
|
"Конференция с таким именем уже существует");
|
||||||
|
if (errors.hasErrors()) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(ConferenceDto conferenceDto) throws IOException {
|
|
||||||
if (isEmpty(conferenceDto.getId())) {
|
if (isEmpty(conferenceDto.getId())) {
|
||||||
create(conferenceDto);
|
create(conferenceDto);
|
||||||
} else {
|
} else {
|
||||||
update(conferenceDto);
|
update(conferenceDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Conference save(Conference conference) {
|
||||||
|
if (isEmpty(conference.getId())) {
|
||||||
|
return create(conference);
|
||||||
|
} else {
|
||||||
|
return update(conference);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer create(ConferenceDto conferenceDto) throws IOException {
|
public Conference create(ConferenceDto conferenceDto) throws IOException {
|
||||||
Conference newConference = copyFromDto(new Conference(), conferenceDto);
|
return create(copyFromDto(new Conference(), conferenceDto));
|
||||||
newConference = conferenceRepository.save(newConference);
|
|
||||||
return newConference.getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer update(ConferenceDto conferenceDto) throws IOException {
|
public Conference create(Conference conference) {
|
||||||
Conference conference = conferenceRepository.getOne(conferenceDto.getId());
|
conference = conferenceRepository.save(conference);
|
||||||
conferenceRepository.save(copyFromDto(conference, conferenceDto));
|
conferenceNotificationService.sendCreateNotification(conference);
|
||||||
conferenceDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
return conference;
|
||||||
return conference.getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer conferenceId) {
|
private Conference update(ConferenceDto conferenceDto) throws IOException {
|
||||||
|
return update(copyFromDto(conferenceRepository.getOne(conferenceDto.getId()), conferenceDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
private Conference update(Conference conference) {
|
||||||
|
Conference oldConference = conferenceRepository.getOne(conference.getId());
|
||||||
|
List<Deadline> oldDeadlines = oldConference.getDeadlines().stream()
|
||||||
|
.map(this::copyDeadline)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
Date oldBeginDate = conference.getBeginDate();
|
||||||
|
Date oldEndDate = conference.getEndDate();
|
||||||
|
conferenceRepository.save(conference);
|
||||||
|
sendNotificationAfterUpdateDeadlines(conference, oldDeadlines);
|
||||||
|
if (!conference.getBeginDate().equals(oldBeginDate) || !conference.getEndDate().equals(oldEndDate)) {
|
||||||
|
conferenceNotificationService.updateConferencesDatesNotification(conference, oldBeginDate, oldEndDate);
|
||||||
|
}
|
||||||
|
return conference;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public boolean delete(Integer conferenceId) {
|
||||||
if (conferenceRepository.existsById(conferenceId)) {
|
if (conferenceRepository.existsById(conferenceId)) {
|
||||||
|
eventService.removeConferencesEvent(conferenceRepository.getOne(conferenceId));
|
||||||
conferenceRepository.deleteById(conferenceId);
|
conferenceRepository.deleteById(conferenceId);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException {
|
@Transactional
|
||||||
|
public boolean delete(List<Conference> conferences) {
|
||||||
|
conferences.forEach(conference -> delete(conference.getId()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConferenceDto addDeadline(ConferenceDto conferenceDto) {
|
||||||
|
conferenceDto.getDeadlines().add(new Deadline());
|
||||||
|
return conferenceDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ConferenceDto removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException {
|
||||||
if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) {
|
if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) {
|
||||||
conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId());
|
conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId());
|
||||||
}
|
}
|
||||||
conferenceDto.getDeadlines().remove((int) deadlineIndex);
|
conferenceDto.getDeadlines().remove((int) deadlineIndex);
|
||||||
|
return conferenceDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException {
|
public ConferenceDto addPaper(ConferenceDto conferenceDto) {
|
||||||
|
Paper paper = new Paper();
|
||||||
|
paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle() + "_" + (new Date()).getTime());
|
||||||
|
paper.setStatus(Paper.PaperStatus.DRAFT);
|
||||||
|
conferenceDto.getPapers().add(paper);
|
||||||
|
return conferenceDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConferenceDto removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException {
|
||||||
Paper removedPaper = conferenceDto.getPapers().remove((int) paperIndex);
|
Paper removedPaper = conferenceDto.getPapers().remove((int) paperIndex);
|
||||||
|
if (removedPaper.getId() != null) {
|
||||||
conferenceDto.getNotSelectedPapers().add(removedPaper);
|
conferenceDto.getNotSelectedPapers().add(removedPaper);
|
||||||
}
|
}
|
||||||
|
return conferenceDto;
|
||||||
public void takePart(ConferenceDto conferenceDto) throws IOException {
|
|
||||||
conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser()));
|
|
||||||
conferenceDto.setDisabledTakePart(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> getNotSelectPapers(List<Integer> paperIds) {
|
public ConferenceDto takePart(ConferenceDto conferenceDto) throws IOException {
|
||||||
|
conferenceDto.getUsers().add(new ConferenceUser(userService.getCurrentUser()));
|
||||||
|
conferenceDto.setDisabledTakePart(true);
|
||||||
|
return conferenceDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Paper> getNotSelectPapers(List<Integer> paperIds) {
|
||||||
return paperService.findAllNotSelect(paperIds);
|
return paperService.findAllNotSelect(paperIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,21 +225,21 @@ public class ConferenceService {
|
|||||||
conference.setTitle(conferenceDto.getTitle());
|
conference.setTitle(conferenceDto.getTitle());
|
||||||
conference.setDescription(conferenceDto.getDescription());
|
conference.setDescription(conferenceDto.getDescription());
|
||||||
conference.setUrl(conferenceDto.getUrl());
|
conference.setUrl(conferenceDto.getUrl());
|
||||||
conference.setPing(0);
|
|
||||||
conference.setBeginDate(conferenceDto.getBeginDate());
|
conference.setBeginDate(conferenceDto.getBeginDate());
|
||||||
conference.setEndDate(conferenceDto.getEndDate());
|
conference.setEndDate(conferenceDto.getEndDate());
|
||||||
conference.setPapers(conferenceDto.getPapers());
|
conference.getPapers().clear();
|
||||||
|
conferenceDto.getPapers().forEach(paper -> conference.getPapers().add(paper.getId() != null ? paperService.findPaperById(paper.getId()) : paperService.create(paper)));
|
||||||
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines()));
|
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines()));
|
||||||
conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers()));
|
conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers()));
|
||||||
if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) {
|
if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) {
|
||||||
conferenceDto.getPaperIds().forEach(paperId ->
|
conferenceDto.getPaperIds().forEach(paperId ->
|
||||||
conference.getPapers().add(paperService.findEntityById(paperId)));
|
conference.getPapers().add(paperService.findPaperById(paperId)));
|
||||||
}
|
}
|
||||||
return conference;
|
return conference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isCurrentUserParticipant(List<ConferenceUser> conferenceUsers) {
|
private boolean isCurrentUserParticipant(List<ConferenceUser> conferenceUsers) {
|
||||||
return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser()));
|
return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,4 +257,102 @@ public class ConferenceService {
|
|||||||
public List<Conference> findAllActive() {
|
public List<Conference> findAllActive() {
|
||||||
return conferenceRepository.findAllActive(new Date());
|
return conferenceRepository.findAllActive(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAttachedToConference(Integer paperId) {
|
||||||
|
return conferenceRepository.isPaperAttached(paperId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void ping(ConferenceDto conferenceDto) throws IOException {
|
||||||
|
pingService.addPing(findOne(conferenceDto.getId()));
|
||||||
|
conferenceRepository.updatePingConference(conferenceDto.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Conference findOne(Integer conferenceId) {
|
||||||
|
return conferenceRepository.getOne(conferenceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChartData(ModelMap modelMap) {
|
||||||
|
//first, add the regional sales
|
||||||
|
Integer northeastSales = 17089;
|
||||||
|
Integer westSales = 10603;
|
||||||
|
Integer midwestSales = 5223;
|
||||||
|
Integer southSales = 10111;
|
||||||
|
|
||||||
|
modelMap.addAttribute("northeastSales", northeastSales);
|
||||||
|
modelMap.addAttribute("southSales", southSales);
|
||||||
|
modelMap.addAttribute("midwestSales", midwestSales);
|
||||||
|
modelMap.addAttribute("westSales", westSales);
|
||||||
|
|
||||||
|
//now add sales by lure type
|
||||||
|
List<Integer> inshoreSales = Arrays.asList(4074, 3455, 4112);
|
||||||
|
List<Integer> nearshoreSales = Arrays.asList(3222, 3011, 3788);
|
||||||
|
List<Integer> offshoreSales = Arrays.asList(7811, 7098, 6455);
|
||||||
|
|
||||||
|
modelMap.addAttribute("inshoreSales", inshoreSales);
|
||||||
|
modelMap.addAttribute("nearshoreSales", nearshoreSales);
|
||||||
|
modelMap.addAttribute("offshoreSales", offshoreSales);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendNotificationAfterUpdateDeadlines(Conference conference, List<Deadline> oldDeadlines) {
|
||||||
|
if (oldDeadlines.size() != conference.getDeadlines().size()) {
|
||||||
|
conferenceNotificationService.updateDeadlineNotification(conference);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conference.getDeadlines()
|
||||||
|
.stream()
|
||||||
|
.filter(deadline -> !oldDeadlines.contains(deadline))
|
||||||
|
.count() > 0) {
|
||||||
|
conferenceNotificationService.updateDeadlineNotification(conference);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Deadline copyDeadline(Deadline oldDeadline) {
|
||||||
|
Deadline newDeadline = new Deadline(oldDeadline.getDate(), oldDeadline.getDescription());
|
||||||
|
newDeadline.setId(oldDeadline.getId());
|
||||||
|
return newDeadline;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEmptyFieldsOfDeadline(ConferenceDto conferenceDto, Errors errors) {
|
||||||
|
for (Deadline deadline : conferenceDto.getDeadlines()) {
|
||||||
|
if (deadline.getDate() == null || deadline.getDescription().isEmpty()) {
|
||||||
|
errors.rejectValue("deadlines", "errorCode", "Все поля дедлайна должны быть заполнены");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEmptyFieldsOfDates(ConferenceDto conferenceDto, Errors errors) {
|
||||||
|
if (conferenceDto.getBeginDate() == null || conferenceDto.getEndDate() == null) {
|
||||||
|
errors.rejectValue("beginDate", "errorCode", "Даты должны быть заполнены");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void filterEmptyDeadlines(ConferenceDto conferenceDto) {
|
||||||
|
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
|
||||||
|
.filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription()))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Conference getActiveConferenceByUser(User user) {
|
||||||
|
return conferenceRepository.findActiveByUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Conference createByTitle(String newConferenceTitle) {
|
||||||
|
Conference conference = new Conference(newConferenceTitle);
|
||||||
|
conference.setBeginDate(DateUtils.localDateToDate(DateUtils.convertToLocalDate(new Date()).plus(1, ChronoUnit.WEEKS)));
|
||||||
|
conference.setEndDate(DateUtils.localDateToDate(DateUtils.convertToLocalDate(new Date()).plus(2, ChronoUnit.WEEKS)));
|
||||||
|
conference.getUsers().add(new ConferenceUser(userService.getCurrentUser()));
|
||||||
|
conference.getDeadlines().add(deadlineService.createWithOffset(new Date(), 1, ChronoUnit.WEEKS));
|
||||||
|
return save(conference);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Conference> findAllActiveByCurrentUser() {
|
||||||
|
return findAllActive()
|
||||||
|
.stream()
|
||||||
|
.filter(conference -> conference.getUsers()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(user -> user.getUser().equals(userService.getCurrentUser())))
|
||||||
|
.collect(toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ public class ConferenceUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public ConferenceUser update(ConferenceUser user) {
|
private ConferenceUser update(ConferenceUser user) {
|
||||||
ConferenceUser updateUser = conferenceUserRepository.getOne(user.getId());
|
ConferenceUser updateUser = conferenceUserRepository.getOne(user.getId());
|
||||||
updateUser.setDeposit(user.getDeposit());
|
updateUser.setDeposit(user.getDeposit());
|
||||||
updateUser.setParticipation(user.getParticipation());
|
updateUser.setParticipation(user.getParticipation());
|
||||||
@ -35,7 +35,7 @@ public class ConferenceUserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public ConferenceUser create(ConferenceUser user) {
|
private ConferenceUser create(ConferenceUser user) {
|
||||||
ConferenceUser newUser = new ConferenceUser();
|
ConferenceUser newUser = new ConferenceUser();
|
||||||
newUser.setDeposit(user.getDeposit());
|
newUser.setDeposit(user.getDeposit());
|
||||||
newUser.setParticipation(user.getParticipation());
|
newUser.setParticipation(user.getParticipation());
|
||||||
@ -43,6 +43,4 @@ public class ConferenceUserService {
|
|||||||
newUser = conferenceUserRepository.save(newUser);
|
newUser = conferenceUserRepository.save(newUser);
|
||||||
return newUser;
|
return newUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package ru.ulstu.configuration;
|
package ru.ulstu.configuration;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ConfigurationProperties(prefix = "ng-tracker")
|
@ConfigurationProperties(prefix = "ng-tracker")
|
||||||
@Validated
|
@Validated
|
||||||
@ -22,6 +21,10 @@ public class ApplicationProperties {
|
|||||||
|
|
||||||
private boolean checkRun;
|
private boolean checkRun;
|
||||||
|
|
||||||
|
private String debugEmail;
|
||||||
|
|
||||||
|
private String driverPath;
|
||||||
|
|
||||||
public boolean isUseHttps() {
|
public boolean isUseHttps() {
|
||||||
return useHttps;
|
return useHttps;
|
||||||
}
|
}
|
||||||
@ -61,4 +64,20 @@ public class ApplicationProperties {
|
|||||||
public void setCheckRun(boolean checkRun) {
|
public void setCheckRun(boolean checkRun) {
|
||||||
this.checkRun = checkRun;
|
this.checkRun = checkRun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDebugEmail() {
|
||||||
|
return debugEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDebugEmail(String debugEmail) {
|
||||||
|
this.debugEmail = debugEmail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDriverPath() {
|
||||||
|
return driverPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDriverPath(String driverPath) {
|
||||||
|
this.driverPath = driverPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,11 @@ public class Constants {
|
|||||||
|
|
||||||
public static final String MAIL_ACTIVATE = "Account activation";
|
public static final String MAIL_ACTIVATE = "Account activation";
|
||||||
public static final String MAIL_RESET = "Password reset";
|
public static final String MAIL_RESET = "Password reset";
|
||||||
|
public static final String MAIL_INVITE = "Account registration";
|
||||||
|
public static final String MAIL_CHANGE_PASSWORD = "Password has been changed";
|
||||||
|
|
||||||
public static final int MIN_PASSWORD_LENGTH = 6;
|
public static final int MIN_PASSWORD_LENGTH = 6;
|
||||||
|
public static final int MAX_PASSWORD_LENGTH = 32;
|
||||||
|
|
||||||
public static final String LOGIN_REGEX = "^[_'.@A-Za-z0-9-]*$";
|
public static final String LOGIN_REGEX = "^[_'.@A-Za-z0-9-]*$";
|
||||||
|
|
||||||
@ -17,4 +21,5 @@ public class Constants {
|
|||||||
public static final String PASSWORD_RESET_REQUEST_PAGE = "/resetRequest";
|
public static final String PASSWORD_RESET_REQUEST_PAGE = "/resetRequest";
|
||||||
public static final String PASSWORD_RESET_PAGE = "/reset";
|
public static final String PASSWORD_RESET_PAGE = "/reset";
|
||||||
|
|
||||||
|
public static final int RESET_KEY_LENGTH = 6;
|
||||||
}
|
}
|
@ -1,30 +0,0 @@
|
|||||||
package ru.ulstu.configuration;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.server.ServerConnector;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
|
|
||||||
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
|
|
||||||
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
|
|
||||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class HttpListenerConfiguration implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
|
|
||||||
@Value("${server.http.port}")
|
|
||||||
private int httpPort;
|
|
||||||
|
|
||||||
private void configureJetty(JettyServletWebServerFactory jettyFactory) {
|
|
||||||
jettyFactory.addServerCustomizers((JettyServerCustomizer) server -> {
|
|
||||||
ServerConnector serverConnector = new ServerConnector(server);
|
|
||||||
serverConnector.setPort(httpPort);
|
|
||||||
server.addConnector(serverConnector);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void customize(ConfigurableWebServerFactory factory) {
|
|
||||||
if (factory instanceof JettyServletWebServerFactory) {
|
|
||||||
configureJetty((JettyServletWebServerFactory) factory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,10 @@
|
|||||||
package ru.ulstu.configuration;
|
package ru.ulstu.configuration;
|
||||||
|
|
||||||
import nz.net.ultraq.thymeleaf.LayoutDialect;
|
import nz.net.ultraq.thymeleaf.layoutdialect.LayoutDialect;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.thymeleaf.extras.springsecurity5.dialect.SpringSecurityDialect;
|
import org.thymeleaf.extras.springsecurity6.dialect.SpringSecurityDialect;
|
||||||
import org.thymeleaf.spring5.SpringTemplateEngine;
|
import org.thymeleaf.spring6.SpringTemplateEngine;
|
||||||
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
|
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
|
||||||
import org.thymeleaf.templateresolver.ITemplateResolver;
|
import org.thymeleaf.templateresolver.ITemplateResolver;
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ public class MailTemplateConfiguration {
|
|||||||
return templateEngine;
|
return templateEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassLoaderTemplateResolver emailTemplateResolver() {
|
private ClassLoaderTemplateResolver emailTemplateResolver() {
|
||||||
ClassLoaderTemplateResolver emailTemplateResolver = new ClassLoaderTemplateResolver();
|
ClassLoaderTemplateResolver emailTemplateResolver = new ClassLoaderTemplateResolver();
|
||||||
emailTemplateResolver.setPrefix("/mail_templates/");
|
emailTemplateResolver.setPrefix("/mail_templates/");
|
||||||
emailTemplateResolver.setTemplateMode("HTML");
|
emailTemplateResolver.setTemplateMode("HTML");
|
||||||
|
@ -5,26 +5,32 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.beans.factory.BeanInitializationException;
|
import org.springframework.beans.factory.BeanInitializationException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
||||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
|
||||||
|
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||||
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
|
||||||
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
|
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
|
||||||
|
import ru.ulstu.core.model.AuthFailureHandler;
|
||||||
import ru.ulstu.user.controller.UserController;
|
import ru.ulstu.user.controller.UserController;
|
||||||
import ru.ulstu.user.model.UserRoleConstants;
|
import ru.ulstu.user.model.UserRoleConstants;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
|
public class SecurityConfiguration {
|
||||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|
||||||
private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class);
|
private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Environment env;
|
||||||
|
|
||||||
@Value("${server.http.port}")
|
@Value("${server.http.port}")
|
||||||
private int httpPort;
|
private int httpPort;
|
||||||
@Value("${server.port}")
|
@Value("${server.port}")
|
||||||
@ -35,76 +41,77 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
|||||||
private final AuthenticationSuccessHandler authenticationSuccessHandler;
|
private final AuthenticationSuccessHandler authenticationSuccessHandler;
|
||||||
private final LogoutSuccessHandler logoutSuccessHandler;
|
private final LogoutSuccessHandler logoutSuccessHandler;
|
||||||
private final ApplicationProperties applicationProperties;
|
private final ApplicationProperties applicationProperties;
|
||||||
|
private final AuthenticationFailureHandler authenticationFailureHandler;
|
||||||
|
|
||||||
public SecurityConfiguration(UserService userService,
|
public SecurityConfiguration(UserService userService,
|
||||||
BCryptPasswordEncoder bCryptPasswordEncoder,
|
BCryptPasswordEncoder bCryptPasswordEncoder,
|
||||||
AuthenticationSuccessHandler authenticationSuccessHandler,
|
AuthenticationSuccessHandler authenticationSuccessHandler,
|
||||||
LogoutSuccessHandler logoutSuccessHandler,
|
LogoutSuccessHandler logoutSuccessHandler,
|
||||||
ApplicationProperties applicationProperties) {
|
ApplicationProperties applicationProperties,
|
||||||
|
AuthFailureHandler authenticationFailureHandler) {
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
|
this.bCryptPasswordEncoder = bCryptPasswordEncoder;
|
||||||
this.authenticationSuccessHandler = authenticationSuccessHandler;
|
this.authenticationSuccessHandler = authenticationSuccessHandler;
|
||||||
this.logoutSuccessHandler = logoutSuccessHandler;
|
this.logoutSuccessHandler = logoutSuccessHandler;
|
||||||
this.applicationProperties = applicationProperties;
|
this.applicationProperties = applicationProperties;
|
||||||
|
this.authenticationFailureHandler = authenticationFailureHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
http.csrf()
|
http.csrf(AbstractHttpConfigurer::disable);
|
||||||
.disable();
|
|
||||||
if (applicationProperties.isDevMode()) {
|
if (applicationProperties.isDevMode()) {
|
||||||
log.debug("Security disabled");
|
log.debug("Security disabled");
|
||||||
http.authorizeRequests()
|
http.authorizeHttpRequests((authz) -> authz
|
||||||
.anyRequest()
|
.anyRequest()
|
||||||
.permitAll();
|
.permitAll()
|
||||||
http.anonymous()
|
);
|
||||||
|
http.anonymous((anonymousCustomizer) -> anonymousCustomizer
|
||||||
.principal("admin")
|
.principal("admin")
|
||||||
.authorities(UserRoleConstants.ADMIN);
|
.authorities(UserRoleConstants.ADMIN)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
log.debug("Security enabled");
|
log.debug("Security enabled");
|
||||||
http.authorizeRequests()
|
http.authorizeHttpRequests((authz) -> authz
|
||||||
.antMatchers(UserController.ACTIVATE_URL).permitAll()
|
.requestMatchers(UserController.ACTIVATE_URL).permitAll()
|
||||||
.antMatchers(Constants.PASSWORD_RESET_REQUEST_PAGE).permitAll()
|
.requestMatchers(Constants.PASSWORD_RESET_REQUEST_PAGE).permitAll()
|
||||||
.antMatchers(Constants.PASSWORD_RESET_PAGE).permitAll()
|
.requestMatchers(Constants.PASSWORD_RESET_PAGE).permitAll()
|
||||||
.antMatchers(UserController.URL + UserController.REGISTER_URL).permitAll()
|
.requestMatchers("/users/block").permitAll()
|
||||||
.antMatchers(UserController.URL + UserController.ACTIVATE_URL).permitAll()
|
.requestMatchers(UserController.URL + UserController.REGISTER_URL).permitAll()
|
||||||
.antMatchers(UserController.URL + UserController.PASSWORD_RESET_REQUEST_URL).permitAll()
|
.requestMatchers(UserController.URL + UserController.ACTIVATE_URL).permitAll()
|
||||||
.antMatchers(UserController.URL + UserController.PASSWORD_RESET_URL).permitAll()
|
.requestMatchers(UserController.URL + UserController.PASSWORD_RESET_REQUEST_URL).permitAll()
|
||||||
.antMatchers("/swagger-ui.html").hasAuthority(UserRoleConstants.ADMIN)
|
.requestMatchers(UserController.URL + UserController.PASSWORD_RESET_URL).permitAll()
|
||||||
.anyRequest().authenticated()
|
.requestMatchers("/swagger-ui.html").hasAuthority(UserRoleConstants.ADMIN)
|
||||||
.and()
|
.anyRequest().authenticated())
|
||||||
.formLogin()
|
.formLogin((formLoginCustomizer) -> formLoginCustomizer
|
||||||
.loginPage("/login")
|
.loginPage("/login")
|
||||||
.successHandler(authenticationSuccessHandler)
|
.successHandler(authenticationSuccessHandler)
|
||||||
|
.failureHandler(authenticationFailureHandler)
|
||||||
.permitAll()
|
.permitAll()
|
||||||
.and()
|
)
|
||||||
.logout()
|
.rememberMe(rememberMe -> rememberMe.key("uniqueAndSecret"))
|
||||||
|
.logout((logoutCustomizer) -> logoutCustomizer
|
||||||
.logoutSuccessHandler(logoutSuccessHandler)
|
.logoutSuccessHandler(logoutSuccessHandler)
|
||||||
.logoutSuccessUrl(Constants.LOGOUT_URL)
|
.logoutSuccessUrl(Constants.LOGOUT_URL)
|
||||||
.invalidateHttpSession(false)
|
.invalidateHttpSession(false)
|
||||||
.clearAuthentication(true)
|
.clearAuthentication(true)
|
||||||
.deleteCookies(Constants.COOKIES_NAME)
|
.deleteCookies(Constants.COOKIES_NAME)
|
||||||
.permitAll();
|
.permitAll()
|
||||||
|
);
|
||||||
|
http.csrf(AbstractHttpConfigurer::disable);
|
||||||
}
|
}
|
||||||
if (applicationProperties.isUseHttps()) {
|
return http.build();
|
||||||
http.portMapper()
|
|
||||||
.http(httpPort)
|
|
||||||
.mapsTo(httpsPort)
|
|
||||||
.and()
|
|
||||||
.requiresChannel()
|
|
||||||
.anyRequest()
|
|
||||||
.requiresSecure();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
@Bean
|
||||||
|
public WebSecurityCustomizer webSecurityCustomizer() {
|
||||||
@Override
|
return (web) -> web.ignoring()
|
||||||
public void configure(WebSecurity web) {
|
.requestMatchers("/css/**",
|
||||||
web.ignoring()
|
"/javax.faces.resource/**",
|
||||||
.antMatchers("/css/**")
|
"/js/**",
|
||||||
.antMatchers("/js/**")
|
"/templates/**",
|
||||||
.antMatchers("/templates/**")
|
"/webjars/**",
|
||||||
.antMatchers("/webjars/**");
|
"/img/**");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
package ru.ulstu.configuration;
|
|
||||||
|
|
||||||
import com.google.common.base.Predicates;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import springfox.documentation.builders.PathSelectors;
|
|
||||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
||||||
import springfox.documentation.spi.DocumentationType;
|
|
||||||
import springfox.documentation.spring.web.plugins.Docket;
|
|
||||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableSwagger2
|
|
||||||
public class SwaggerConfiguration {
|
|
||||||
@Bean
|
|
||||||
public Docket swaggerApi() {
|
|
||||||
return new Docket(DocumentationType.SWAGGER_2)
|
|
||||||
.select()
|
|
||||||
.apis(RequestHandlerSelectors.any())
|
|
||||||
.paths(Predicates.not(PathSelectors.regex("/error")))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,6 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.validation.FieldError;
|
import org.springframework.validation.FieldError;
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import ru.ulstu.core.error.EntityIdIsNullException;
|
import ru.ulstu.core.error.EntityIdIsNullException;
|
||||||
@ -20,12 +19,13 @@ import ru.ulstu.user.error.UserNotActivatedException;
|
|||||||
import ru.ulstu.user.error.UserNotFoundException;
|
import ru.ulstu.user.error.UserNotFoundException;
|
||||||
import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
|
import ru.ulstu.user.error.UserPasswordsNotValidOrNotMatchException;
|
||||||
import ru.ulstu.user.error.UserResetKeyError;
|
import ru.ulstu.user.error.UserResetKeyError;
|
||||||
|
import ru.ulstu.user.error.UserSendingMailException;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ControllerAdvice
|
//@ControllerAdvice
|
||||||
public class AdviceController {
|
public class AdviceController {
|
||||||
private final Logger log = LoggerFactory.getLogger(AdviceController.class);
|
private final Logger log = LoggerFactory.getLogger(AdviceController.class);
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
@ -34,9 +34,9 @@ public class AdviceController {
|
|||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ModelAttribute("currentUser")
|
@ModelAttribute("flashMessage")
|
||||||
public String getCurrentUser() {
|
public String getFlashMessage() {
|
||||||
return userService.getCurrentUser().getUserAbbreviate();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response<Void> handleException(ErrorConstants error) {
|
private Response<Void> handleException(ErrorConstants error) {
|
||||||
@ -107,4 +107,9 @@ public class AdviceController {
|
|||||||
public ResponseExtended<String> handleUserIsUndeadException(Throwable e) {
|
public ResponseExtended<String> handleUserIsUndeadException(Throwable e) {
|
||||||
return handleException(ErrorConstants.USER_UNDEAD_ERROR, e.getMessage());
|
return handleException(ErrorConstants.USER_UNDEAD_ERROR, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ExceptionHandler(UserSendingMailException.class)
|
||||||
|
public ResponseExtended<String> handleUserSendingMailException(Throwable e) {
|
||||||
|
return handleException(ErrorConstants.USER_SENDING_MAIL_EXCEPTION, e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
@ -15,7 +15,7 @@ public class OffsetablePageRequest implements Pageable, Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public OffsetablePageRequest(long offset, int count, Sort.Direction direction, String... properties) {
|
public OffsetablePageRequest(long offset, int count, Sort.Direction direction, String... properties) {
|
||||||
this(offset, count, new Sort(direction, properties));
|
this(offset, count, Sort.by(direction, properties));
|
||||||
}
|
}
|
||||||
|
|
||||||
public OffsetablePageRequest(long offset, int count, Sort sort) {
|
public OffsetablePageRequest(long offset, int count, Sort sort) {
|
||||||
@ -30,6 +30,12 @@ public class OffsetablePageRequest implements Pageable, Serializable {
|
|||||||
this.sort = sort;
|
this.sort = sort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pageable withPage(int pageNumber) {
|
||||||
|
//TODO
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Sort getSort() {
|
public Sort getSort() {
|
||||||
return sort;
|
return sort;
|
||||||
@ -65,7 +71,7 @@ public class OffsetablePageRequest implements Pageable, Serializable {
|
|||||||
return hasPrevious() ? previous() : first();
|
return hasPrevious() ? previous() : first();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pageable previous() {
|
private Pageable previous() {
|
||||||
return getOffset() == 0 ? this : new OffsetablePageRequest(getOffset() - getPageSize(), getPageSize(), getSort());
|
return getOffset() == 0 ? this : new OffsetablePageRequest(getOffset() - getPageSize(), getPageSize(), getSort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
src/main/java/ru/ulstu/core/model/AuthFailureHandler.java
Normal file
21
src/main/java/ru/ulstu/core/model/AuthFailureHandler.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package ru.ulstu.core.model;
|
||||||
|
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.security.core.AuthenticationException;
|
||||||
|
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import ru.ulstu.user.error.UserBlockedException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class AuthFailureHandler implements AuthenticationFailureHandler {
|
||||||
|
@Override
|
||||||
|
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
|
||||||
|
AuthenticationException ex) throws IOException {
|
||||||
|
if (ex.getClass() == UserBlockedException.class) {
|
||||||
|
response.sendRedirect("/users/block");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,16 @@
|
|||||||
package ru.ulstu.core.model;
|
package ru.ulstu.core.model;
|
||||||
|
|
||||||
import javax.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import javax.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import javax.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import javax.persistence.MappedSuperclass;
|
import jakarta.persistence.MappedSuperclass;
|
||||||
import javax.persistence.Version;
|
import jakarta.persistence.Version;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
public abstract class BaseEntity implements Serializable, Comparable {
|
public abstract class BaseEntity implements Serializable, Comparable<BaseEntity> {
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.TABLE)
|
@GeneratedValue(strategy = GenerationType.TABLE)
|
||||||
private Integer id;
|
private Integer id;
|
||||||
@ -16,14 +18,6 @@ public abstract class BaseEntity implements Serializable, Comparable {
|
|||||||
@Version
|
@Version
|
||||||
private Integer version;
|
private Integer version;
|
||||||
|
|
||||||
public BaseEntity() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public BaseEntity(Integer id, Integer version) {
|
|
||||||
this.id = id;
|
|
||||||
this.version = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -75,8 +69,8 @@ public abstract class BaseEntity implements Serializable, Comparable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Object o) {
|
public int compareTo(@NotNull BaseEntity o) {
|
||||||
return id != null ? id.compareTo(((BaseEntity) o).getId()) : -1;
|
return id != null ? id.compareTo(o.getId()) : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
|
@ -6,17 +6,18 @@ public enum ErrorConstants {
|
|||||||
VALIDATION_ERROR(2, "Validation error"),
|
VALIDATION_ERROR(2, "Validation error"),
|
||||||
USER_ID_EXISTS(100, "New user can't have id"),
|
USER_ID_EXISTS(100, "New user can't have id"),
|
||||||
USER_ACTIVATION_ERROR(101, "Invalid activation key"),
|
USER_ACTIVATION_ERROR(101, "Invalid activation key"),
|
||||||
USER_EMAIL_EXISTS(102, "User with same email already exists"),
|
USER_EMAIL_EXISTS(102, "Пользователь с таким почтовым ящиком уже существует"),
|
||||||
USER_LOGIN_EXISTS(103, "User with same login already exists"),
|
USER_LOGIN_EXISTS(103, "Пользователь с таким логином уже существует"),
|
||||||
USER_PASSWORDS_NOT_VALID_OR_NOT_MATCH(104, "User passwords is not valid or not match"),
|
USER_PASSWORDS_NOT_VALID_OR_NOT_MATCH(104, "Пароли введены неверно"),
|
||||||
USER_NOT_FOUND(105, "User is not found"),
|
USER_NOT_FOUND(105, "Аккаунт не найден"),
|
||||||
USER_NOT_ACTIVATED(106, "User is not activated"),
|
USER_NOT_ACTIVATED(106, "User is not activated"),
|
||||||
USER_RESET_ERROR(107, "Invalid reset key"),
|
USER_RESET_ERROR(107, "Некорректный ключ подтверждения"),
|
||||||
USER_UNDEAD_ERROR(108, "Can't edit/delete that user"),
|
USER_UNDEAD_ERROR(108, "Can't edit/delete that user"),
|
||||||
FILE_UPLOAD_ERROR(110, "File upload error");
|
FILE_UPLOAD_ERROR(110, "File upload error"),
|
||||||
|
USER_SENDING_MAIL_EXCEPTION(111, "Во время отправки приглашения пользователю произошла ошибка");
|
||||||
|
|
||||||
private int code;
|
private final int code;
|
||||||
private String message;
|
private final String message;
|
||||||
|
|
||||||
ErrorConstants(int code, String message) {
|
ErrorConstants(int code, String message) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
|
17
src/main/java/ru/ulstu/core/model/EventSource.java
Normal file
17
src/main/java/ru/ulstu/core/model/EventSource.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package ru.ulstu.core.model;
|
||||||
|
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.timeline.model.Event;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface EventSource {
|
||||||
|
List<Deadline> getDeadlines();
|
||||||
|
|
||||||
|
String getTitle();
|
||||||
|
|
||||||
|
List<User> getRecipients();
|
||||||
|
|
||||||
|
void addObjectToEvent(Event event);
|
||||||
|
}
|
@ -1,34 +0,0 @@
|
|||||||
package ru.ulstu.core.model;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TreeDto {
|
|
||||||
private Integer id;
|
|
||||||
private String text;
|
|
||||||
private List<TreeDto> children = new ArrayList<>();
|
|
||||||
|
|
||||||
public TreeDto() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends TreeEntity> TreeDto(TreeEntity item) {
|
|
||||||
this.text = item.toString();
|
|
||||||
this.id = item.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TreeDto(String rootName) {
|
|
||||||
this.text = rootName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getText() {
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TreeDto> getChildren() {
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package ru.ulstu.core.model;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface TreeEntity<T> {
|
|
||||||
|
|
||||||
Integer getId();
|
|
||||||
|
|
||||||
List<T> getChildren();
|
|
||||||
|
|
||||||
void setChildren(List<T> children);
|
|
||||||
|
|
||||||
T getParent();
|
|
||||||
|
|
||||||
void setParent(T parent);
|
|
||||||
}
|
|
11
src/main/java/ru/ulstu/core/model/UserActivity.java
Normal file
11
src/main/java/ru/ulstu/core/model/UserActivity.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package ru.ulstu.core.model;
|
||||||
|
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public interface UserActivity {
|
||||||
|
String getTitle();
|
||||||
|
|
||||||
|
Set<User> getActivityUsers();
|
||||||
|
}
|
@ -1,9 +0,0 @@
|
|||||||
package ru.ulstu.core.model;
|
|
||||||
|
|
||||||
import ru.ulstu.user.model.User;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public interface UserContainer {
|
|
||||||
Set<User> getUsers();
|
|
||||||
}
|
|
@ -1,8 +1,8 @@
|
|||||||
package ru.ulstu.core.model.response;
|
package ru.ulstu.core.model.response;
|
||||||
|
|
||||||
class ControllerResponse<D, E> {
|
class ControllerResponse<D, E> {
|
||||||
private D data;
|
private final D data;
|
||||||
private ControllerResponseError<E> error;
|
private final ControllerResponseError<E> error;
|
||||||
|
|
||||||
ControllerResponse(D data) {
|
ControllerResponse(D data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
|
@ -3,8 +3,8 @@ package ru.ulstu.core.model.response;
|
|||||||
import ru.ulstu.core.model.ErrorConstants;
|
import ru.ulstu.core.model.ErrorConstants;
|
||||||
|
|
||||||
class ControllerResponseError<D> {
|
class ControllerResponseError<D> {
|
||||||
private ErrorConstants description;
|
private final ErrorConstants description;
|
||||||
private D data;
|
private final D data;
|
||||||
|
|
||||||
ControllerResponseError(ErrorConstants description, D data) {
|
ControllerResponseError(ErrorConstants description, D data) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
@ -11,6 +11,6 @@ public class Response<D> extends ResponseEntity<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Response(ErrorConstants error) {
|
public Response(ErrorConstants error) {
|
||||||
super(new ControllerResponse<Void, Void>(new ControllerResponseError<>(error, null)), HttpStatus.OK);
|
super(new ControllerResponse<Void, Void>(new ControllerResponseError<>(error, null)), HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@ import ru.ulstu.core.model.ErrorConstants;
|
|||||||
public class ResponseExtended<E> extends ResponseEntity<Object> {
|
public class ResponseExtended<E> extends ResponseEntity<Object> {
|
||||||
|
|
||||||
public ResponseExtended(ErrorConstants error, E errorData) {
|
public ResponseExtended(ErrorConstants error, E errorData) {
|
||||||
super(new ControllerResponse<Void, E>(new ControllerResponseError<E>(error, errorData)), HttpStatus.OK);
|
super(new ControllerResponse<Void, E>(new ControllerResponseError<E>(error, errorData)), HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
69
src/main/java/ru/ulstu/core/navigation/Page.java
Normal file
69
src/main/java/ru/ulstu/core/navigation/Page.java
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
package ru.ulstu.core.navigation;
|
||||||
|
|
||||||
|
public class Page {
|
||||||
|
public static final String INDEX = "/index.html";
|
||||||
|
public static final String PAPER = "/paper/paper.html";
|
||||||
|
public static final String PAPER_LIST = "/paper/papers.html";
|
||||||
|
public static final String PAPER_DASHBOARD = "/paper/dashboard.html";
|
||||||
|
public static final String GRANT = "/grant/grant.html";
|
||||||
|
public static final String GRANT_LIST = "/grant/grants.html";
|
||||||
|
public static final String GRANT_DASHBOARD = "/grant/dashboard.html";
|
||||||
|
public static final String USER_LIST = "/admin/users.html";
|
||||||
|
public static final String LOGOUT = "/logout";
|
||||||
|
public static final String CONFERENCE = "/conference/conference.html";
|
||||||
|
public static final String CONFERENCE_DASHBOARD = "/conference/dashboard.html";
|
||||||
|
public static final String CONFERENCE_LIST = "/conference/conferences.html";
|
||||||
|
public static final String PROJECT_DASHBOARD = "/conference/dashboard.html";
|
||||||
|
|
||||||
|
public String getIndex() {
|
||||||
|
return INDEX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPaperList() {
|
||||||
|
return PAPER_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPaperDashboard() {
|
||||||
|
return PAPER_DASHBOARD;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserList() {
|
||||||
|
return USER_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLogout() {
|
||||||
|
return LOGOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGrantList() {
|
||||||
|
return GRANT_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGrantDashboard() {
|
||||||
|
return GRANT_DASHBOARD;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPaper() {
|
||||||
|
return PAPER;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGrant() {
|
||||||
|
return GRANT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConferenceDashboard() {
|
||||||
|
return CONFERENCE_DASHBOARD;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectDashboard() {
|
||||||
|
return PROJECT_DASHBOARD;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConference() {
|
||||||
|
return CONFERENCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConferenceList() {
|
||||||
|
return CONFERENCE_LIST;
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,14 @@
|
|||||||
package ru.ulstu.core.repository;
|
package ru.ulstu.core.repository;
|
||||||
|
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
import org.springframework.data.jpa.repository.support.JpaEntityInformation;
|
import org.springframework.data.jpa.repository.support.JpaEntityInformation;
|
||||||
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
|
import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
public class JpaDetachableRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID>
|
public class JpaDetachableRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID>
|
||||||
implements JpaDetachableRepository<T, ID> {
|
implements JpaDetachableRepository<T, ID> {
|
||||||
private EntityManager entityManager;
|
private final EntityManager entityManager;
|
||||||
|
|
||||||
public JpaDetachableRepositoryImpl(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
|
public JpaDetachableRepositoryImpl(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
|
||||||
super(entityInformation, entityManager);
|
super(entityInformation, entityManager);
|
||||||
|
@ -14,9 +14,12 @@ import java.util.List;
|
|||||||
public class DateUtils {
|
public class DateUtils {
|
||||||
|
|
||||||
public static Date clearTime(Date date) {
|
public static Date clearTime(Date date) {
|
||||||
|
if (date == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTime(date);
|
calendar.setTime(date);
|
||||||
calendar.set(Calendar.HOUR, 0);
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
calendar.set(Calendar.MINUTE, 0);
|
calendar.set(Calendar.MINUTE, 0);
|
||||||
calendar.set(Calendar.SECOND, 0);
|
calendar.set(Calendar.SECOND, 0);
|
||||||
calendar.set(Calendar.MILLISECOND, 0);
|
calendar.set(Calendar.MILLISECOND, 0);
|
||||||
@ -54,4 +57,16 @@ public class DateUtils {
|
|||||||
cal.add(Calendar.DAY_OF_MONTH, count);
|
cal.add(Calendar.DAY_OF_MONTH, count);
|
||||||
return cal.getTime();
|
return cal.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Date addYears(Date date, int count) {
|
||||||
|
Calendar cal = getCalendar(date);
|
||||||
|
cal.add(Calendar.YEAR, count);
|
||||||
|
return cal.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LocalDate convertToLocalDate(Date dateToConvert) {
|
||||||
|
return dateToConvert.toInstant()
|
||||||
|
.atZone(ZoneId.systemDefault())
|
||||||
|
.toLocalDate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
package ru.ulstu.core.util;
|
|
||||||
|
|
||||||
public class NumberUtils {
|
|
||||||
public static Double ceil(Double number) {
|
|
||||||
if (number == null) {
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
return Double.valueOf(Math.ceil(number));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Double round(Double number) {
|
|
||||||
if (number == null) {
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
return Double.valueOf(Math.ceil(number * 100)) / 100;
|
|
||||||
}
|
|
||||||
}
|
|
@ -11,12 +11,12 @@ public class StreamApiUtils {
|
|||||||
public static <T, R> List<T> convert(List<R> entities, Function<R, T> converter) {
|
public static <T, R> List<T> convert(List<R> entities, Function<R, T> converter) {
|
||||||
return entities == null
|
return entities == null
|
||||||
? Collections.emptyList()
|
? Collections.emptyList()
|
||||||
: entities.stream().map(e -> converter.apply(e)).collect(Collectors.toList());
|
: entities.stream().map(converter).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T, R> Set<T> convert(Set<R> entities, Function<R, T> converter) {
|
public static <T, R> Set<T> convert(Set<R> entities, Function<R, T> converter) {
|
||||||
return entities == null
|
return entities == null
|
||||||
? Collections.emptySet()
|
? Collections.emptySet()
|
||||||
: entities.stream().map(e -> converter.apply(e)).collect(Collectors.toSet());
|
: entities.stream().map(converter).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,23 +2,33 @@ package ru.ulstu.deadline.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.OneToMany;
|
||||||
|
import jakarta.persistence.Temporal;
|
||||||
|
import jakarta.persistence.TemporalType;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Temporal;
|
|
||||||
import javax.persistence.TemporalType;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Deadline extends BaseEntity {
|
public class Deadline extends BaseEntity {
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
@Temporal(value = TemporalType.TIMESTAMP)
|
@Temporal(value = TemporalType.DATE)
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date date;
|
private Date date;
|
||||||
|
|
||||||
|
@OneToMany(targetEntity = User.class, fetch = FetchType.EAGER)
|
||||||
|
private List<User> executors;
|
||||||
|
|
||||||
|
private Boolean done;
|
||||||
|
|
||||||
public Deadline() {
|
public Deadline() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,13 +37,24 @@ public class Deadline extends BaseEntity {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Deadline(Date deadlineDate, String description, List<User> executors, Boolean done) {
|
||||||
|
this.date = deadlineDate;
|
||||||
|
this.description = description;
|
||||||
|
this.executors = executors;
|
||||||
|
this.done = done;
|
||||||
|
}
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public Deadline(@JsonProperty("id") Integer id,
|
public Deadline(@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("description") String description,
|
@JsonProperty("description") String description,
|
||||||
@JsonProperty("date") Date date) {
|
@JsonProperty("date") Date date,
|
||||||
|
@JsonProperty("executors") List<User> executors,
|
||||||
|
@JsonProperty("done") Boolean done) {
|
||||||
this.setId(id);
|
this.setId(id);
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
|
this.executors = executors;
|
||||||
|
this.done = done;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
@ -51,4 +72,47 @@ public class Deadline extends BaseEntity {
|
|||||||
public void setDate(Date date) {
|
public void setDate(Date date) {
|
||||||
this.date = date;
|
this.date = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<User> getExecutors() {
|
||||||
|
return executors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExecutors(List<User> executors) {
|
||||||
|
this.executors = executors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getDone() {
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDone(Boolean done) {
|
||||||
|
this.done = done;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!super.equals(o)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Deadline deadline = (Deadline) o;
|
||||||
|
if (getId() == null && deadline.getId() == null &&
|
||||||
|
description == null && deadline.description == null &&
|
||||||
|
date == null && deadline.date == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return getId().equals(deadline.getId()) &&
|
||||||
|
description.equals(deadline.description) &&
|
||||||
|
date.equals(deadline.date);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(super.hashCode(), description, date, executors, done);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,14 @@ package ru.ulstu.deadline.repository;
|
|||||||
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public interface DeadlineRepository extends JpaRepository<Deadline, Integer> {
|
public interface DeadlineRepository extends JpaRepository<Deadline, Integer> {
|
||||||
|
|
||||||
|
@Query("SELECT d.date FROM Grant g JOIN g.deadlines d WHERE (g.id = :id) AND (d.date = :date)")
|
||||||
|
Date findByGrantIdAndDate(@Param("id") Integer grantId, @Param("date") Date date);
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,12 @@ package ru.ulstu.deadline.service;
|
|||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.core.util.DateUtils;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.repository.DeadlineRepository;
|
import ru.ulstu.deadline.repository.DeadlineRepository;
|
||||||
|
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -25,10 +28,12 @@ public class DeadlineService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Deadline update(Deadline deadline) {
|
private Deadline update(Deadline deadline) {
|
||||||
Deadline updateDeadline = deadlineRepository.getOne(deadline.getId());
|
Deadline updateDeadline = deadlineRepository.getOne(deadline.getId());
|
||||||
updateDeadline.setDate(deadline.getDate());
|
updateDeadline.setDate(deadline.getDate());
|
||||||
updateDeadline.setDescription(deadline.getDescription());
|
updateDeadline.setDescription(deadline.getDescription());
|
||||||
|
updateDeadline.setExecutors(deadline.getExecutors());
|
||||||
|
updateDeadline.setDone(deadline.getDone());
|
||||||
deadlineRepository.save(updateDeadline);
|
deadlineRepository.save(updateDeadline);
|
||||||
return updateDeadline;
|
return updateDeadline;
|
||||||
}
|
}
|
||||||
@ -38,12 +43,39 @@ public class DeadlineService {
|
|||||||
Deadline newDeadline = new Deadline();
|
Deadline newDeadline = new Deadline();
|
||||||
newDeadline.setDate(deadline.getDate());
|
newDeadline.setDate(deadline.getDate());
|
||||||
newDeadline.setDescription(deadline.getDescription());
|
newDeadline.setDescription(deadline.getDescription());
|
||||||
|
newDeadline.setExecutors(deadline.getExecutors());
|
||||||
|
newDeadline.setDone(deadline.getDone());
|
||||||
newDeadline = deadlineRepository.save(newDeadline);
|
newDeadline = deadlineRepository.save(newDeadline);
|
||||||
return newDeadline;
|
return newDeadline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Deadline create(Date date) {
|
||||||
|
Deadline deadline = new Deadline();
|
||||||
|
deadline.setDate(date);
|
||||||
|
return create(deadline);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Deadline create(String description, Date date) {
|
||||||
|
Deadline deadline = new Deadline();
|
||||||
|
deadline.setDate(date);
|
||||||
|
deadline.setDescription(description);
|
||||||
|
return create(deadline);
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void remove(Integer deadlineId) {
|
public void remove(Integer deadlineId) {
|
||||||
deadlineRepository.deleteById(deadlineId);
|
deadlineRepository.deleteById(deadlineId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Date findByGrantIdAndDate(Integer id, Date date) {
|
||||||
|
return deadlineRepository.findByGrantIdAndDate(id, date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Deadline createWithOffset(Date date, long value, ChronoUnit chronoUnit) {
|
||||||
|
return create(DateUtils.localDateToDate(DateUtils.convertToLocalDate(date).plus(value, chronoUnit)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(List<Deadline> deadlines) {
|
||||||
|
deadlineRepository.deleteInBatch(deadlines);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,10 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
import static ru.ulstu.file.FileController.URL;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(URL)
|
@RequestMapping(Constants.API_1_0 + "files")
|
||||||
public class FileController {
|
public class FileController {
|
||||||
public static final String URL = Constants.API_1_0 + "files";
|
|
||||||
|
|
||||||
private final FileService fileService;
|
private final FileService fileService;
|
||||||
|
|
||||||
public FileController(FileService fileService) {
|
public FileController(FileService fileService) {
|
||||||
@ -53,6 +50,6 @@ public class FileController {
|
|||||||
|
|
||||||
@PostMapping("/uploadTmpFile")
|
@PostMapping("/uploadTmpFile")
|
||||||
public Response<FileDataDto> upload(@RequestParam("file") MultipartFile multipartFile) throws IOException {
|
public Response<FileDataDto> upload(@RequestParam("file") MultipartFile multipartFile) throws IOException {
|
||||||
return new Response(fileService.createFromMultipartFile(multipartFile));
|
return new Response<>(fileService.createFromMultipartFile(multipartFile));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package ru.ulstu.file.model;
|
package ru.ulstu.file.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@ -27,15 +27,15 @@ public class FileService {
|
|||||||
private final static int META_FILE_NAME_INDEX = 0;
|
private final static int META_FILE_NAME_INDEX = 0;
|
||||||
private final static int META_FILE_SIZE_INDEX = 1;
|
private final static int META_FILE_SIZE_INDEX = 1;
|
||||||
|
|
||||||
private String tmpDir;
|
private final String tmpDir;
|
||||||
private FileRepository fileRepository;
|
private final FileRepository fileRepository;
|
||||||
|
|
||||||
public FileService(FileRepository fileRepository) {
|
public FileService(FileRepository fileRepository) {
|
||||||
tmpDir = System.getProperty("java.io.tmpdir");
|
tmpDir = System.getProperty("java.io.tmpdir");
|
||||||
this.fileRepository = fileRepository;
|
this.fileRepository = fileRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileData createFileFromTmp(String tmpFileName) throws IOException {
|
private FileData createFileFromTmp(String tmpFileName) throws IOException {
|
||||||
FileData fileData = new FileData();
|
FileData fileData = new FileData();
|
||||||
fileData.setData(getTmpFile(tmpFileName));
|
fileData.setData(getTmpFile(tmpFileName));
|
||||||
fileData.setSize(getTmpFileSize(tmpFileName));
|
fileData.setSize(getTmpFileSize(tmpFileName));
|
||||||
@ -43,7 +43,7 @@ public class FileService {
|
|||||||
return fileRepository.save(fileData);
|
return fileRepository.save(fileData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String uploadToTmpDir(MultipartFile multipartFile) throws IOException {
|
private String uploadToTmpDir(MultipartFile multipartFile) throws IOException {
|
||||||
String tmpFileName = String.valueOf(System.currentTimeMillis()) + UUID.randomUUID();
|
String tmpFileName = String.valueOf(System.currentTimeMillis()) + UUID.randomUUID();
|
||||||
Files.write(getTmpFilePath(tmpFileName), multipartFile.getBytes());
|
Files.write(getTmpFilePath(tmpFileName), multipartFile.getBytes());
|
||||||
String meta = multipartFile.getOriginalFilename() + "\n" + multipartFile.getSize();
|
String meta = multipartFile.getOriginalFilename() + "\n" + multipartFile.getSize();
|
||||||
@ -56,7 +56,7 @@ public class FileService {
|
|||||||
.split("\n");
|
.split("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getTmpFileSize(String tmpFileName) throws IOException {
|
private long getTmpFileSize(String tmpFileName) throws IOException {
|
||||||
return Long.valueOf(getMeta(tmpFileName)[META_FILE_SIZE_INDEX]).longValue();
|
return Long.valueOf(getMeta(tmpFileName)[META_FILE_SIZE_INDEX]).longValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,13 +97,13 @@ public class FileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public FileData update(FileDataDto fileDataDto) {
|
private FileData update(FileDataDto fileDataDto) {
|
||||||
FileData file = fileRepository.getOne(fileDataDto.getId());
|
FileData file = fileRepository.getOne(fileDataDto.getId());
|
||||||
return fileRepository.save(copyFromDto(file, fileDataDto));
|
return fileRepository.save(copyFromDto(file, fileDataDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public FileData create(FileDataDto fileDataDto) throws IOException {
|
private FileData create(FileDataDto fileDataDto) throws IOException {
|
||||||
FileData newFile = createFileFromTmp(fileDataDto.getTmpFileName());
|
FileData newFile = createFileFromTmp(fileDataDto.getTmpFileName());
|
||||||
copyFromDto(newFile, fileDataDto);
|
copyFromDto(newFile, fileDataDto);
|
||||||
return fileRepository.save(newFile);
|
return fileRepository.save(newFile);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package ru.ulstu.grant.controller;
|
package ru.ulstu.grant.controller;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Hidden;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
@ -9,19 +11,17 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.grant.model.Grant;
|
||||||
import ru.ulstu.grant.model.GrantDto;
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
import ru.ulstu.grant.service.GrantService;
|
import ru.ulstu.grant.service.GrantService;
|
||||||
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static org.springframework.util.StringUtils.isEmpty;
|
|
||||||
import static ru.ulstu.core.controller.Navigation.GRANTS_PAGE;
|
import static ru.ulstu.core.controller.Navigation.GRANTS_PAGE;
|
||||||
import static ru.ulstu.core.controller.Navigation.GRANT_PAGE;
|
import static ru.ulstu.core.controller.Navigation.GRANT_PAGE;
|
||||||
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
||||||
@ -29,7 +29,7 @@ import static ru.ulstu.core.controller.Navigation.REDIRECT_TO;
|
|||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@RequestMapping(value = "/grants")
|
@RequestMapping(value = "/grants")
|
||||||
@ApiIgnore
|
@Hidden
|
||||||
public class GrantController {
|
public class GrantController {
|
||||||
private final GrantService grantService;
|
private final GrantService grantService;
|
||||||
|
|
||||||
@ -44,13 +44,15 @@ public class GrantController {
|
|||||||
|
|
||||||
@GetMapping("/dashboard")
|
@GetMapping("/dashboard")
|
||||||
public void getDashboard(ModelMap modelMap) {
|
public void getDashboard(ModelMap modelMap) {
|
||||||
modelMap.put("grants", grantService.findAllDto());
|
modelMap.put("grants", grantService.findAllActiveDto());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/grant")
|
@GetMapping("/grant")
|
||||||
public void getGrant(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
public void getGrant(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
||||||
if (id != null && id > 0) {
|
if (id != null && id > 0) {
|
||||||
modelMap.put("grantDto", grantService.findOneDto(id));
|
GrantDto grantDto = grantService.getExistGrantById(id);
|
||||||
|
attachPaper(grantDto);
|
||||||
|
modelMap.put("grantDto", grantDto);
|
||||||
} else {
|
} else {
|
||||||
modelMap.put("grantDto", new GrantDto());
|
modelMap.put("grantDto", new GrantDto());
|
||||||
}
|
}
|
||||||
@ -59,17 +61,9 @@ public class GrantController {
|
|||||||
@PostMapping(value = "/grant", params = "save")
|
@PostMapping(value = "/grant", params = "save")
|
||||||
public String save(@Valid GrantDto grantDto, Errors errors)
|
public String save(@Valid GrantDto grantDto, Errors errors)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
filterEmptyDeadlines(grantDto);
|
if (!grantService.save(grantDto, errors)) {
|
||||||
if (grantDto.getDeadlines().isEmpty()) {
|
|
||||||
errors.rejectValue("deadlines", "errorCode", "Не может быть пусто");
|
|
||||||
}
|
|
||||||
if (grantDto.getLeaderId().equals(-1)) {
|
|
||||||
errors.rejectValue("leaderId", "errorCode", "Укажите руководителя");
|
|
||||||
}
|
|
||||||
if (errors.hasErrors()) {
|
|
||||||
return GRANT_PAGE;
|
return GRANT_PAGE;
|
||||||
}
|
}
|
||||||
grantService.save(grantDto);
|
|
||||||
return String.format(REDIRECT_TO, GRANTS_PAGE);
|
return String.format(REDIRECT_TO, GRANTS_PAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,9 +72,15 @@ public class GrantController {
|
|||||||
return GRANT_PAGE;
|
return GRANT_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/grant", params = "attachPaper")
|
||||||
|
public String attachPaper(GrantDto grantDto) {
|
||||||
|
grantService.attachPaper(grantDto);
|
||||||
|
return GRANT_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/grant", params = "addDeadline")
|
@PostMapping(value = "/grant", params = "addDeadline")
|
||||||
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
|
public String addDeadline(@Valid GrantDto grantDto, Errors errors) {
|
||||||
filterEmptyDeadlines(grantDto);
|
grantService.filterEmptyDeadlines(grantDto);
|
||||||
if (errors.hasErrors()) {
|
if (errors.hasErrors()) {
|
||||||
return GRANT_PAGE;
|
return GRANT_PAGE;
|
||||||
}
|
}
|
||||||
@ -88,6 +88,13 @@ public class GrantController {
|
|||||||
return GRANT_PAGE;
|
return GRANT_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/grant", params = "removeDeadline")
|
||||||
|
public String removeDeadline(GrantDto grantDto,
|
||||||
|
@RequestParam(value = "removeDeadline") Integer deadlineId) {
|
||||||
|
grantService.removeDeadline(grantDto, deadlineId);
|
||||||
|
return GRANT_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/grant", params = "createProject")
|
@PostMapping(value = "/grant", params = "createProject")
|
||||||
public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException {
|
public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException {
|
||||||
if (errors.hasErrors()) {
|
if (errors.hasErrors()) {
|
||||||
@ -113,9 +120,14 @@ public class GrantController {
|
|||||||
return grantService.getGrantAuthors(grantDto);
|
return grantService.getGrantAuthors(grantDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void filterEmptyDeadlines(GrantDto grantDto) {
|
@ModelAttribute("allPapers")
|
||||||
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
public List<PaperDto> getAllPapers() {
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
return grantService.getAllUncompletedPapers();
|
||||||
.collect(Collectors.toList()));
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@PostMapping(value = "/ping")
|
||||||
|
public void ping(@RequestParam("grantId") int grantId) throws IOException {
|
||||||
|
grantService.ping(grantId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,29 @@
|
|||||||
|
package ru.ulstu.grant.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ru.ulstu.configuration.Constants;
|
||||||
|
import ru.ulstu.grant.service.GrantService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
|
||||||
|
import static ru.ulstu.paper.controller.PaperRestController.URL;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(URL)
|
||||||
|
public class GrantRestController {
|
||||||
|
public static final String URL = Constants.API_1_0 + "grants";
|
||||||
|
|
||||||
|
private final GrantService grantService;
|
||||||
|
|
||||||
|
public GrantRestController(GrantService grantService) {
|
||||||
|
this.grantService = grantService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/grab")
|
||||||
|
public void grab() throws IOException, ParseException {
|
||||||
|
grantService.createFromKias();
|
||||||
|
}
|
||||||
|
}
|
@ -1,26 +1,34 @@
|
|||||||
package ru.ulstu.grant.model;
|
package ru.ulstu.grant.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.CascadeType;
|
||||||
|
import jakarta.persistence.DiscriminatorValue;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.JoinTable;
|
||||||
|
import jakarta.persistence.ManyToMany;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.OneToMany;
|
||||||
|
import jakarta.persistence.OrderBy;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import org.hibernate.annotations.Fetch;
|
||||||
|
import org.hibernate.annotations.FetchMode;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.core.model.UserContainer;
|
import ru.ulstu.core.model.EventSource;
|
||||||
|
import ru.ulstu.core.model.UserActivity;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.file.model.FileData;
|
import ru.ulstu.file.model.FileData;
|
||||||
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.project.model.Project;
|
||||||
|
import ru.ulstu.timeline.model.Event;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EnumType;
|
|
||||||
import javax.persistence.Enumerated;
|
|
||||||
import javax.persistence.FetchType;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.ManyToMany;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.persistence.OneToMany;
|
|
||||||
import javax.persistence.OrderBy;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -30,25 +38,33 @@ import java.util.Set;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "grants")
|
@Table(name = "grants")
|
||||||
public class Grant extends BaseEntity implements UserContainer {
|
@DiscriminatorValue("GRANT")
|
||||||
|
public class Grant extends BaseEntity implements UserActivity, EventSource {
|
||||||
public enum GrantStatus {
|
public enum GrantStatus {
|
||||||
APPLICATION("Заявка"),
|
APPLICATION("Заявка", "text-draft"),
|
||||||
ON_COMPETITION("Отправлен на конкурс"),
|
ON_COMPETITION("Отправлен на конкурс", "text-review"),
|
||||||
SUCCESSFUL_PASSAGE("Успешное прохождение"),
|
SUCCESSFUL_PASSAGE("Успешное прохождение", "text-accepted"),
|
||||||
IN_WORK("В работе"),
|
IN_WORK("В работе", "text-primary"),
|
||||||
COMPLETED("Завершен"),
|
COMPLETED("Завершен", "text-success"),
|
||||||
FAILED("Провалены сроки"),
|
FAILED("Провалены сроки", "text-failed"),
|
||||||
LOADED_FROM_KIAS("Загружен автоматически");
|
LOADED_FROM_KIAS("Загружен автоматически", "text-warning"),
|
||||||
|
SKIPPED("Не интересует", "text-not-accepted");
|
||||||
|
|
||||||
private String statusName;
|
private final String statusName;
|
||||||
|
private final String elementClass;
|
||||||
|
|
||||||
GrantStatus(String statusName) {
|
GrantStatus(String statusName, String elementClass) {
|
||||||
this.statusName = statusName;
|
this.statusName = statusName;
|
||||||
|
this.elementClass = elementClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatusName() {
|
public String getStatusName() {
|
||||||
return statusName;
|
return statusName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getElementClass() {
|
||||||
|
return elementClass;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@ -57,19 +73,17 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
private GrantStatus status = GrantStatus.APPLICATION;
|
private GrantStatus status = GrantStatus.APPLICATION;
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "grant_id")
|
@JoinColumn(name = "grant_id")
|
||||||
@OrderBy("date")
|
@OrderBy("date")
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
|
|
||||||
//Описание гранта
|
|
||||||
@NotNull
|
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
//Заявка на грант
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
@ManyToOne
|
@JoinColumn(name = "grant_id", unique = true)
|
||||||
@JoinColumn(name = "file_id")
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
private FileData application;
|
private List<FileData> files = new ArrayList<>();
|
||||||
|
|
||||||
@ManyToOne(cascade = CascadeType.ALL)
|
@ManyToOne(cascade = CascadeType.ALL)
|
||||||
@JoinColumn(name = "project_id")
|
@JoinColumn(name = "project_id")
|
||||||
@ -83,6 +97,17 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
@JoinColumn(name = "leader_id")
|
@JoinColumn(name = "leader_id")
|
||||||
private User leader;
|
private User leader;
|
||||||
|
|
||||||
|
@ManyToMany(fetch = FetchType.EAGER)
|
||||||
|
@JoinTable(name = "grants_papers",
|
||||||
|
joinColumns = {@JoinColumn(name = "grant_id")},
|
||||||
|
inverseJoinColumns = {@JoinColumn(name = "paper_id")})
|
||||||
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
|
private List<Paper> papers = new ArrayList<>();
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "grant_id")
|
||||||
|
private List<Event> events = new ArrayList<>();
|
||||||
|
|
||||||
public GrantStatus getStatus() {
|
public GrantStatus getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -107,18 +132,28 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileData getApplication() {
|
public List<FileData> getFiles() {
|
||||||
return application;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setApplication(FileData application) {
|
public void setFiles(List<FileData> files) {
|
||||||
this.application = application;
|
this.files = files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<User> getRecipients() {
|
||||||
|
return authors != null ? new ArrayList<>(authors) : Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addObjectToEvent(Event event) {
|
||||||
|
event.setGrant(this);
|
||||||
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
@ -140,7 +175,7 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<User> getUsers() {
|
public Set<User> getActivityUsers() {
|
||||||
return getAuthors();
|
return getAuthors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,6 +187,22 @@ public class Grant extends BaseEntity implements UserContainer {
|
|||||||
this.leader = leader;
|
this.leader = leader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Paper> getPapers() {
|
||||||
|
return papers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPapers(List<Paper> papers) {
|
||||||
|
this.papers = papers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Event> getEvents() {
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEvents(List<Event> events) {
|
||||||
|
this.events = events;
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<Deadline> getNextDeadline() {
|
public Optional<Deadline> getNextDeadline() {
|
||||||
return deadlines
|
return deadlines
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -2,20 +2,24 @@ package ru.ulstu.grant.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
|
import ru.ulstu.name.NameContainer;
|
||||||
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.project.model.ProjectDto;
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class GrantDto {
|
public class GrantDto extends NameContainer {
|
||||||
private final static int MAX_AUTHORS_LENGTH = 60;
|
private final static int MAX_AUTHORS_LENGTH = 60;
|
||||||
|
|
||||||
private Integer id;
|
private Integer id;
|
||||||
@ -24,7 +28,7 @@ public class GrantDto {
|
|||||||
private Grant.GrantStatus status;
|
private Grant.GrantStatus status;
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
private String comment;
|
private String comment;
|
||||||
private String applicationFileName;
|
private List<FileDataDto> files = new ArrayList<>();
|
||||||
private ProjectDto project;
|
private ProjectDto project;
|
||||||
private Set<Integer> authorIds;
|
private Set<Integer> authorIds;
|
||||||
private Set<UserDto> authors;
|
private Set<UserDto> authors;
|
||||||
@ -32,6 +36,11 @@ public class GrantDto {
|
|||||||
private boolean wasLeader;
|
private boolean wasLeader;
|
||||||
private boolean hasAge;
|
private boolean hasAge;
|
||||||
private boolean hasDegree;
|
private boolean hasDegree;
|
||||||
|
private boolean hasBAKPapers;
|
||||||
|
private boolean hasScopusPapers;
|
||||||
|
private List<Integer> paperIds = new ArrayList<>();
|
||||||
|
private List<PaperDto> papers = new ArrayList<>();
|
||||||
|
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
||||||
|
|
||||||
public GrantDto() {
|
public GrantDto() {
|
||||||
deadlines.add(new Deadline());
|
deadlines.add(new Deadline());
|
||||||
@ -43,25 +52,31 @@ public class GrantDto {
|
|||||||
@JsonProperty("status") Grant.GrantStatus status,
|
@JsonProperty("status") Grant.GrantStatus status,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
@JsonProperty("deadlines") List<Deadline> deadlines,
|
||||||
@JsonProperty("comment") String comment,
|
@JsonProperty("comment") String comment,
|
||||||
|
@JsonProperty("files") List<FileDataDto> files,
|
||||||
@JsonProperty("project") ProjectDto project,
|
@JsonProperty("project") ProjectDto project,
|
||||||
@JsonProperty("authorIds") Set<Integer> authorIds,
|
@JsonProperty("authorIds") Set<Integer> authorIds,
|
||||||
@JsonProperty("authors") Set<UserDto> authors,
|
@JsonProperty("authors") Set<UserDto> authors,
|
||||||
@JsonProperty("leader") Integer leaderId,
|
@JsonProperty("leaderId") Integer leaderId,
|
||||||
@JsonProperty("wasLeader") boolean wasLeader,
|
@JsonProperty("wasLeader") boolean wasLeader,
|
||||||
@JsonProperty("hasAge") boolean hasAge,
|
@JsonProperty("hasAge") boolean hasAge,
|
||||||
@JsonProperty("hasDegree") boolean hasDegree) {
|
@JsonProperty("hasDegree") boolean hasDegree,
|
||||||
|
@JsonProperty("paperIds") List<Integer> paperIds,
|
||||||
|
@JsonProperty("papers") List<PaperDto> papers) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.applicationFileName = null;
|
this.files = files;
|
||||||
this.project = project;
|
this.project = project;
|
||||||
|
this.authorIds = authorIds;
|
||||||
this.authors = authors;
|
this.authors = authors;
|
||||||
this.leaderId = leaderId;
|
this.leaderId = leaderId;
|
||||||
this.wasLeader = wasLeader;
|
this.wasLeader = wasLeader;
|
||||||
this.hasAge = hasAge;
|
this.hasAge = hasAge;
|
||||||
this.hasDegree = hasDegree;
|
this.hasDegree = hasDegree;
|
||||||
|
this.paperIds = paperIds;
|
||||||
|
this.papers = papers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GrantDto(Grant grant) {
|
public GrantDto(Grant grant) {
|
||||||
@ -70,14 +85,22 @@ public class GrantDto {
|
|||||||
this.status = grant.getStatus();
|
this.status = grant.getStatus();
|
||||||
this.deadlines = grant.getDeadlines();
|
this.deadlines = grant.getDeadlines();
|
||||||
this.comment = grant.getComment();
|
this.comment = grant.getComment();
|
||||||
|
this.files = convert(grant.getFiles(), FileDataDto::new);
|
||||||
this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject());
|
this.project = grant.getProject() == null ? null : new ProjectDto(grant.getProject());
|
||||||
this.applicationFileName = grant.getApplication() == null ? null : grant.getApplication().getName();
|
|
||||||
this.authorIds = convert(grant.getAuthors(), user -> user.getId());
|
this.authorIds = convert(grant.getAuthors(), user -> user.getId());
|
||||||
this.authors = convert(grant.getAuthors(), UserDto::new);
|
this.authors = convert(grant.getAuthors(), UserDto::new);
|
||||||
this.leaderId = grant.getLeader().getId();
|
this.leaderId = grant.getLeader().getId();
|
||||||
this.wasLeader = false;
|
this.wasLeader = false;
|
||||||
this.hasAge = false;
|
this.hasAge = false;
|
||||||
this.hasDegree = false;
|
this.hasDegree = false;
|
||||||
|
this.paperIds = convert(grant.getPapers(), paper -> paper.getId());
|
||||||
|
this.papers = convert(grant.getPapers(), PaperDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GrantDto(String grantTitle, Date deadLineDate) {
|
||||||
|
this.title = grantTitle;
|
||||||
|
deadlines.add(new Deadline(deadLineDate, "Окончание приёма заявок"));
|
||||||
|
status = Grant.GrantStatus.LOADED_FROM_KIAS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -120,6 +143,14 @@ public class GrantDto {
|
|||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<FileDataDto> getFiles() {
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFiles(List<FileDataDto> files) {
|
||||||
|
this.files = files;
|
||||||
|
}
|
||||||
|
|
||||||
public ProjectDto getProject() {
|
public ProjectDto getProject() {
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
@ -128,14 +159,6 @@ public class GrantDto {
|
|||||||
this.project = project;
|
this.project = project;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getApplicationFileName() {
|
|
||||||
return applicationFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApplicationFileName(String applicationFileName) {
|
|
||||||
this.applicationFileName = applicationFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Integer> getAuthorIds() {
|
public Set<Integer> getAuthorIds() {
|
||||||
return authorIds;
|
return authorIds;
|
||||||
}
|
}
|
||||||
@ -190,4 +213,44 @@ public class GrantDto {
|
|||||||
public void setHasDegree(boolean hasDegree) {
|
public void setHasDegree(boolean hasDegree) {
|
||||||
this.hasDegree = hasDegree;
|
this.hasDegree = hasDegree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Integer> getPaperIds() {
|
||||||
|
return paperIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaperIds(List<Integer> paperIds) {
|
||||||
|
this.paperIds = paperIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PaperDto> getPapers() {
|
||||||
|
return papers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPapers(List<PaperDto> papers) {
|
||||||
|
this.papers = papers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getRemovedDeadlineIds() {
|
||||||
|
return removedDeadlineIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
|
||||||
|
this.removedDeadlineIds = removedDeadlineIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHasBAKPapers() {
|
||||||
|
return hasBAKPapers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHasBAKPapers(boolean hasBAKPapers) {
|
||||||
|
this.hasBAKPapers = hasBAKPapers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHasScopusPapers() {
|
||||||
|
return hasScopusPapers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHasScopusPapers(boolean hasScopusPapers) {
|
||||||
|
this.hasScopusPapers = hasScopusPapers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
55
src/main/java/ru/ulstu/grant/page/KiasPage.java
Normal file
55
src/main/java/ru/ulstu/grant/page/KiasPage.java
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package ru.ulstu.grant.page;
|
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.html.DomNode;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlElement;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class KiasPage {
|
||||||
|
private final static String KIAS_GRANT_DATE_FORMAT = "dd.MM.yyyy HH:mm";
|
||||||
|
private final HtmlPage page;
|
||||||
|
|
||||||
|
public KiasPage(HtmlPage page) {
|
||||||
|
this.page = page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean goToNextPage() {
|
||||||
|
try {
|
||||||
|
HtmlElement nextPageLink = page.getHtmlElementById("js-ctrlNext");
|
||||||
|
if (nextPageLink.isDisplayed()) {
|
||||||
|
nextPageLink.click();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DomNode> getPageOfGrants() {
|
||||||
|
return page.getByXPath("/html/body/div[2]/div/div[2]/main/div[1]/table/tbody/tr");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGrantTitle(DomNode grant) {
|
||||||
|
return ((DomNode) grant.getFirstByXPath("td[2]")).getTextContent() + " "
|
||||||
|
+ ((DomNode) grant.getFirstByXPath("td[@class='tertiary']/a")).getTextContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date parseDeadLineDate(DomNode grantElement) throws ParseException {
|
||||||
|
String deadlineDate = getFirstDeadline(grantElement); //10.06.2019 23:59
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat(KIAS_GRANT_DATE_FORMAT);
|
||||||
|
return formatter.parse(deadlineDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFirstDeadline(DomNode grantElement) {
|
||||||
|
return ((DomNode) grantElement.getFirstByXPath("td[5]")).getTextContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTableRowGrantLine(DomNode grantElement) {
|
||||||
|
return !((HtmlTableRow) grantElement).getAttribute("class").contains("pagerSavedHeightSpacer");
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,25 @@
|
|||||||
package ru.ulstu.grant.repository;
|
package ru.ulstu.grant.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.grant.model.Grant;
|
||||||
|
import ru.ulstu.name.BaseRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface GrantRepository extends JpaRepository<Grant, Integer> {
|
public interface GrantRepository extends JpaRepository<Grant, Integer>, BaseRepository {
|
||||||
|
|
||||||
List<Grant> findByStatus(Grant.GrantStatus status);
|
List<Grant> findByStatus(Grant.GrantStatus status);
|
||||||
|
|
||||||
|
Grant findFirstByTitle(String title);
|
||||||
|
|
||||||
|
Grant findGrantById(Integer grantId);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Query("SELECT title FROM Grant g WHERE (g.title = :name) AND (:id IS NULL OR g.id != :id) ")
|
||||||
|
List<String> findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
|
|
||||||
|
@Query("SELECT g FROM Grant g WHERE (g.status <> 'SKIPPED') AND (g.status <> 'COMPLETED')")
|
||||||
|
List<Grant> findAllActive();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
package ru.ulstu.grant.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.core.util.DateUtils;
|
||||||
|
import ru.ulstu.grant.model.Grant;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GrantNotificationService {
|
||||||
|
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
||||||
|
private final static String TEMPLATE_DEADLINE = "grantDeadlineNotification";
|
||||||
|
private final static String TEMPLATE_CREATE = "grantCreateNotification";
|
||||||
|
private final static String TEMPLATE_AUTHORS_CHANGED = "grantAuthorsChangeNotification";
|
||||||
|
private final static String TEMPLATE_LEADER_CHANGED = "grantLeaderChangeNotification";
|
||||||
|
|
||||||
|
private final static String TITLE_DEADLINE = "Приближается дедлайн гранта: %s";
|
||||||
|
private final static String TITLE_CREATE = "Создан грант: %s";
|
||||||
|
private final static String TITLE_AUTHORS_CHANGED = "Изменился состав рабочей группы гранта: %s";
|
||||||
|
private final static String TITLE_LEADER_CHANGED = "Изменился руководитель гранта: %s";
|
||||||
|
|
||||||
|
private final MailService mailService;
|
||||||
|
|
||||||
|
public GrantNotificationService(MailService mailService) {
|
||||||
|
this.mailService = mailService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendDeadlineNotifications(List<Grant> grants, boolean isDeadlineBeforeWeek) {
|
||||||
|
Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION);
|
||||||
|
grants.stream()
|
||||||
|
.filter(grant -> needToSendDeadlineNotification(grant, now, isDeadlineBeforeWeek))
|
||||||
|
.forEach(grant -> sendMessageDeadline(grant));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean needToSendDeadlineNotification(Grant grant, Date compareDate, boolean isDeadlineBeforeWeek) {
|
||||||
|
return (grant.getNextDeadline().isPresent())
|
||||||
|
&& (compareDate.before(grant.getNextDeadline().get().getDate()) && isDeadlineBeforeWeek
|
||||||
|
|| compareDate.after(grant.getNextDeadline().get().getDate()) && !isDeadlineBeforeWeek)
|
||||||
|
&& grant.getNextDeadline().get().getDate().after(new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageDeadline(Grant grant) {
|
||||||
|
Map<String, Object> variables = Map.of("grant", grant);
|
||||||
|
sendForAllAuthors(variables, grant, TEMPLATE_DEADLINE, String.format(TITLE_DEADLINE, grant.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCreateNotification(Grant grant) {
|
||||||
|
Map<String, Object> variables = Map.of("grant", grant);
|
||||||
|
sendForAllAuthors(variables, grant, TEMPLATE_CREATE, String.format(TITLE_CREATE, grant.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendAuthorsChangeNotification(Grant grant, Set<User> oldAuthors) {
|
||||||
|
Map<String, Object> variables = Map.of("grant", grant, "oldAuthors", oldAuthors);
|
||||||
|
sendForAllAuthors(variables, grant, TEMPLATE_AUTHORS_CHANGED, String.format(TITLE_AUTHORS_CHANGED, grant.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendLeaderChangeNotification(Grant grant, User oldLeader) {
|
||||||
|
Map<String, Object> variables = Map.of("grant", grant, "oldLeader", oldLeader);
|
||||||
|
sendForAllAuthors(variables, grant, TEMPLATE_LEADER_CHANGED, String.format(TITLE_LEADER_CHANGED, grant.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendForAllAuthors(Map<String, Object> variables, Grant grant, String template, String title) {
|
||||||
|
Set<User> allAuthors = grant.getAuthors();
|
||||||
|
allAuthors.forEach(author -> mailService.sendEmailFromTemplate(variables, author, template, title));
|
||||||
|
mailService.sendEmailFromTemplate(variables, grant.getLeader(), template, title);
|
||||||
|
}
|
||||||
|
}
|
41
src/main/java/ru/ulstu/grant/service/GrantScheduler.java
Normal file
41
src/main/java/ru/ulstu/grant/service/GrantScheduler.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package ru.ulstu.grant.service;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GrantScheduler {
|
||||||
|
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(GrantScheduler.class);
|
||||||
|
|
||||||
|
private final GrantNotificationService grantNotificationService;
|
||||||
|
private final GrantService grantService;
|
||||||
|
|
||||||
|
public GrantScheduler(GrantNotificationService grantNotificationService,
|
||||||
|
GrantService grantService) {
|
||||||
|
this.grantNotificationService = grantNotificationService;
|
||||||
|
this.grantService = grantService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
|
||||||
|
public void checkDeadlineBeforeWeek() {
|
||||||
|
log.debug("GrantScheduler.checkDeadlineBeforeWeek started");
|
||||||
|
grantNotificationService.sendDeadlineNotifications(grantService.findAllActive(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||||
|
log.debug("GrantScheduler.checkDeadlineBeforeWeek finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara")
|
||||||
|
public void loadGrantsFromKias() {
|
||||||
|
log.debug("GrantScheduler.loadGrantsFromKias started");
|
||||||
|
// try {
|
||||||
|
// grantService.createFromKias();
|
||||||
|
// } catch (ParseException | IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
log.debug("GrantScheduler.loadGrantsFromKias finished");
|
||||||
|
}
|
||||||
|
}
|
@ -1,50 +1,86 @@
|
|||||||
package ru.ulstu.grant.service;
|
package ru.ulstu.grant.service;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.validation.Errors;
|
||||||
|
import ru.ulstu.core.util.DateUtils;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.file.service.FileService;
|
import ru.ulstu.file.service.FileService;
|
||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.grant.model.Grant;
|
||||||
import ru.ulstu.grant.model.GrantDto;
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
import ru.ulstu.grant.repository.GrantRepository;
|
import ru.ulstu.grant.repository.GrantRepository;
|
||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.name.BaseService;
|
||||||
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
|
import ru.ulstu.paper.service.PaperService;
|
||||||
|
import ru.ulstu.ping.service.PingService;
|
||||||
import ru.ulstu.project.model.ProjectDto;
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
import ru.ulstu.project.service.ProjectService;
|
import ru.ulstu.project.service.ProjectService;
|
||||||
|
import ru.ulstu.timeline.service.EventService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION;
|
import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GrantService {
|
public class GrantService extends BaseService {
|
||||||
private final static int MAX_DISPLAY_SIZE = 40;
|
private final Logger log = LoggerFactory.getLogger(GrantService.class);
|
||||||
|
|
||||||
private final GrantRepository grantRepository;
|
private final GrantRepository grantRepository;
|
||||||
private final ProjectService projectService;
|
private final ProjectService projectService;
|
||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
private final FileService fileService;
|
private final FileService fileService;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
private final PaperService paperService;
|
||||||
|
private final EventService eventService;
|
||||||
|
private final GrantNotificationService grantNotificationService;
|
||||||
|
private final KiasService kiasService;
|
||||||
|
private final PingService pingService;
|
||||||
|
|
||||||
public GrantService(GrantRepository grantRepository,
|
public GrantService(GrantRepository grantRepository,
|
||||||
FileService fileService,
|
FileService fileService,
|
||||||
DeadlineService deadlineService,
|
DeadlineService deadlineService,
|
||||||
ProjectService projectService,
|
ProjectService projectService,
|
||||||
UserService userService) {
|
UserService userService,
|
||||||
|
PaperService paperService,
|
||||||
|
EventService eventService,
|
||||||
|
GrantNotificationService grantNotificationService,
|
||||||
|
KiasService kiasService,
|
||||||
|
PingService pingService) {
|
||||||
this.grantRepository = grantRepository;
|
this.grantRepository = grantRepository;
|
||||||
|
this.kiasService = kiasService;
|
||||||
|
this.baseRepository = grantRepository;
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.projectService = projectService;
|
this.projectService = projectService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
|
this.paperService = paperService;
|
||||||
|
this.eventService = eventService;
|
||||||
|
this.grantNotificationService = grantNotificationService;
|
||||||
|
this.pingService = pingService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GrantDto getExistGrantById(Integer id) {
|
||||||
|
return new GrantDto(findById(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Grant> findAll() {
|
public List<Grant> findAll() {
|
||||||
@ -52,20 +88,16 @@ public class GrantService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<GrantDto> findAllDto() {
|
public List<GrantDto> findAllDto() {
|
||||||
List<GrantDto> grants = convert(findAll(), GrantDto::new);
|
return convert(findAll(), GrantDto::new);
|
||||||
grants.forEach(grantDto -> grantDto.setTitle(StringUtils.abbreviate(grantDto.getTitle(), MAX_DISPLAY_SIZE)));
|
|
||||||
return grants;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GrantDto findOneDto(Integer id) {
|
|
||||||
return new GrantDto(grantRepository.getOne(id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer create(GrantDto grantDto) throws IOException {
|
public Grant create(GrantDto grantDto) throws IOException {
|
||||||
Grant newGrant = copyFromDto(new Grant(), grantDto);
|
Grant newGrant = copyFromDto(new Grant(), grantDto);
|
||||||
newGrant = grantRepository.save(newGrant);
|
newGrant = grantRepository.save(newGrant);
|
||||||
return newGrant.getId();
|
eventService.createFromObject(newGrant, Collections.emptyList(), false, "гранта");
|
||||||
|
grantNotificationService.sendCreateNotification(newGrant);
|
||||||
|
return newGrant;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Grant copyFromDto(Grant grant, GrantDto grantDto) throws IOException {
|
private Grant copyFromDto(Grant grant, GrantDto grantDto) throws IOException {
|
||||||
@ -76,8 +108,10 @@ public class GrantService {
|
|||||||
grant.setProject(projectService.findById(grantDto.getProject().getId()));
|
grant.setProject(projectService.findById(grantDto.getProject().getId()));
|
||||||
}
|
}
|
||||||
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
||||||
if (grantDto.getApplicationFileName() != null) {
|
if (!grant.getFiles().isEmpty()) {
|
||||||
grant.setApplication(fileService.createFileFromTmp(grantDto.getApplicationFileName()));
|
grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream()
|
||||||
|
.filter(f -> !f.isDeleted())
|
||||||
|
.collect(toList())));
|
||||||
}
|
}
|
||||||
grant.getAuthors().clear();
|
grant.getAuthors().clear();
|
||||||
if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) {
|
if (grantDto.getAuthorIds() != null && !grantDto.getAuthorIds().isEmpty()) {
|
||||||
@ -86,75 +120,284 @@ public class GrantService {
|
|||||||
if (grantDto.getLeaderId() != null) {
|
if (grantDto.getLeaderId() != null) {
|
||||||
grant.setLeader(userService.findById(grantDto.getLeaderId()));
|
grant.setLeader(userService.findById(grantDto.getLeaderId()));
|
||||||
}
|
}
|
||||||
|
grant.getPapers().clear();
|
||||||
|
if (grantDto.getPaperIds() != null && !grantDto.getPaperIds().isEmpty()) {
|
||||||
|
grantDto.getPaperIds().forEach(paperIds -> grant.getPapers().add(paperService.findPaperById(paperIds)));
|
||||||
|
}
|
||||||
return grant;
|
return grant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void createProject(GrantDto grantDto) throws IOException {
|
public void createProject(GrantDto grantDto) throws IOException {
|
||||||
grantDto.setProject(
|
grantDto.setProject(
|
||||||
new ProjectDto(projectService.save(new ProjectDto(grantDto.getTitle()))));
|
new ProjectDto(projectService.save(new ProjectDto(grantDto.getTitle()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer update(GrantDto grantDto) throws IOException {
|
private Integer update(GrantDto grantDto) throws IOException {
|
||||||
Grant grant = grantRepository.getOne(grantDto.getId());
|
Grant grant = findById(grantDto.getId());
|
||||||
Grant.GrantStatus oldStatus = grant.getStatus();
|
Set<User> oldAuthors = new HashSet<>(grant.getAuthors());
|
||||||
if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) {
|
User oldLeader = grant.getLeader();
|
||||||
fileService.deleteFile(grant.getApplication());
|
for (FileDataDto file : grantDto.getFiles().stream()
|
||||||
|
.filter(f -> f.isDeleted() && f.getId() != null)
|
||||||
|
.collect(toList())) {
|
||||||
|
fileService.delete(file.getId());
|
||||||
}
|
}
|
||||||
|
grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
||||||
grantRepository.save(copyFromDto(grant, grantDto));
|
grantRepository.save(copyFromDto(grant, grantDto));
|
||||||
|
|
||||||
|
grant.getAuthors().forEach(author -> {
|
||||||
|
if (!oldAuthors.contains(author)) {
|
||||||
|
grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
oldAuthors.forEach(oldAuthor -> {
|
||||||
|
if (!grant.getAuthors().contains(oldAuthor)) {
|
||||||
|
grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (grant.getLeader() != oldLeader) {
|
||||||
|
grantNotificationService.sendLeaderChangeNotification(grant, oldLeader);
|
||||||
|
}
|
||||||
|
eventService.updateGrantDeadlines(grant);
|
||||||
return grant.getId();
|
return grant.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer grantId) throws IOException {
|
public boolean delete(Integer grantId) throws IOException {
|
||||||
Grant grant = grantRepository.getOne(grantId);
|
Grant grant = findById(grantId);
|
||||||
if (grant.getApplication() != null) {
|
if (grant != null) {
|
||||||
fileService.deleteFile(grant.getApplication());
|
|
||||||
}
|
|
||||||
grantRepository.delete(grant);
|
grantRepository.delete(grant);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Grant.GrantStatus> getGrantStatuses() {
|
public List<Grant.GrantStatus> getGrantStatuses() {
|
||||||
return Arrays.asList(Grant.GrantStatus.values());
|
return Arrays.asList(Grant.GrantStatus.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
public boolean save(GrantDto grantDto, Errors errors) throws IOException {
|
||||||
public Grant create(String title, Project projectId, Date deadlineDate, User user) {
|
grantDto.setName(grantDto.getTitle());
|
||||||
Grant grant = new Grant();
|
filterEmptyDeadlines(grantDto);
|
||||||
grant.setTitle(title);
|
checkEmptyDeadlines(grantDto, errors);
|
||||||
grant.setComment("Комментарий к гранту 1");
|
checkEmptyLeader(grantDto, errors);
|
||||||
grant.setProject(projectId);
|
checkUniqueName(grantDto, errors, grantDto.getId(), "Грант с таким именем уже существует");
|
||||||
grant.setStatus(APPLICATION);
|
if (errors.hasErrors()) {
|
||||||
grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн"));
|
return false;
|
||||||
grant.getAuthors().add(user);
|
|
||||||
grant.setLeader(user);
|
|
||||||
grant = grantRepository.save(grant);
|
|
||||||
return grant;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(GrantDto grantDto) throws IOException {
|
|
||||||
if (isEmpty(grantDto.getId())) {
|
if (isEmpty(grantDto.getId())) {
|
||||||
create(grantDto);
|
create(grantDto);
|
||||||
} else {
|
} else {
|
||||||
update(grantDto);
|
update(grantDto);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean saveFromKias(GrantDto grantDto) throws IOException {
|
||||||
|
grantDto.setName(grantDto.getTitle());
|
||||||
|
String title = checkUniqueName(grantDto, grantDto.getId()); //проверка уникальности имени
|
||||||
|
if (title != null) {
|
||||||
|
Grant grantFromDB = grantRepository.findFirstByTitle(title); //грант с таким же названием из бд
|
||||||
|
if (checkSameDeadline(grantDto, grantFromDB.getId())) { //если дедайны тоже совпадают
|
||||||
|
return false;
|
||||||
|
} else { //иначе грант уже был в системе, но в другом году, поэтому надо создать
|
||||||
|
create(grantDto);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else { //иначе такого гранта ещё нет, поэтому надо создать
|
||||||
|
create(grantDto);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEmptyLeader(GrantDto grantDto, Errors errors) {
|
||||||
|
if (grantDto.getLeaderId().equals(-1)) {
|
||||||
|
errors.rejectValue("leaderId", "errorCode", "Укажите руководителя");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkEmptyDeadlines(GrantDto grantDto, Errors errors) {
|
||||||
|
if (grantDto.getDeadlines().isEmpty()) {
|
||||||
|
errors.rejectValue("deadlines", "errorCode", "Не может быть пусто");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkSameDeadline(GrantDto grantDto, Integer id) {
|
||||||
|
Date date = DateUtils.clearTime(grantDto.getDeadlines().get(0).getDate()); //дата с сайта киас
|
||||||
|
Date foundGrantDate = DateUtils.clearTime(deadlineService.findByGrantIdAndDate(id, date));
|
||||||
|
return foundGrantDate != null && foundGrantDate.compareTo(date) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<User> getGrantAuthors(GrantDto grantDto) {
|
public List<User> getGrantAuthors(GrantDto grantDto) {
|
||||||
List<User> filteredUsers = userService.filterByAgeAndDegree(grantDto.isHasAge(), grantDto.isHasDegree());
|
List<User> filteredUsers = userService.filterByAgeAndDegree(grantDto.isHasAge(), grantDto.isHasDegree());
|
||||||
if (grantDto.isWasLeader()) {
|
if (grantDto.isWasLeader()) {
|
||||||
filteredUsers = filteredUsers
|
filteredUsers = checkContains(filteredUsers, getCompletedGrantLeaders());
|
||||||
.stream()
|
}
|
||||||
.filter(getCompletedGrantLeaders()::contains)
|
if (grantDto.isHasBAKPapers()) {
|
||||||
.collect(Collectors.toList());
|
filteredUsers = checkContains(filteredUsers, getBAKAuthors());
|
||||||
|
}
|
||||||
|
if (grantDto.isHasScopusPapers()) {
|
||||||
|
filteredUsers = checkContains(filteredUsers, getScopusAuthors());
|
||||||
}
|
}
|
||||||
return filteredUsers;
|
return filteredUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<User> checkContains(List<User> filteredUsers, List<User> checkUsers) {
|
||||||
|
return filteredUsers.stream()
|
||||||
|
.filter(checkUsers::contains)
|
||||||
|
.collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
private List<User> getCompletedGrantLeaders() {
|
private List<User> getCompletedGrantLeaders() {
|
||||||
return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED)
|
return grantRepository.findByStatus(Grant.GrantStatus.COMPLETED)
|
||||||
.stream()
|
.stream()
|
||||||
.map(Grant::getLeader)
|
.map(Grant::getLeader)
|
||||||
.collect(Collectors.toList());
|
.collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PaperDto> getGrantPapers(List<Integer> paperIds) {
|
||||||
|
return paperService.findAllSelect(paperIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PaperDto> getAllUncompletedPapers() {
|
||||||
|
return paperService.findAllNotCompleted();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PaperDto> attachPaper(GrantDto grantDto) {
|
||||||
|
if (!grantDto.getPaperIds().isEmpty()) {
|
||||||
|
grantDto.getPapers().clear();
|
||||||
|
grantDto.setPapers(getGrantPapers(grantDto.getPaperIds()));
|
||||||
|
} else {
|
||||||
|
grantDto.getPapers().clear();
|
||||||
|
}
|
||||||
|
return grantDto.getPapers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public GrantDto removeDeadline(GrantDto grantDto, Integer deadlineId) {
|
||||||
|
if (grantDto.getDeadlines().get(deadlineId).getId() != null) {
|
||||||
|
grantDto.getRemovedDeadlineIds().add(grantDto.getDeadlines().get(deadlineId).getId());
|
||||||
|
}
|
||||||
|
grantDto.getDeadlines().remove((int) deadlineId);
|
||||||
|
return grantDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<User> getCompletedPapersAuthors(Paper.PaperType type) {
|
||||||
|
List<Paper> papers = paperService.findAllCompletedByType(type);
|
||||||
|
return papers.stream()
|
||||||
|
.filter(paper -> paper.getAuthors() != null)
|
||||||
|
.flatMap(paper -> paper.getAuthors().stream())
|
||||||
|
.collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<User> getBAKAuthors() {
|
||||||
|
return getCompletedPapersAuthors(Paper.PaperType.VAK)
|
||||||
|
.stream()
|
||||||
|
.distinct()
|
||||||
|
.collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<User> getScopusAuthors() {
|
||||||
|
List<User> authors = getCompletedPapersAuthors(Paper.PaperType.SCOPUS);
|
||||||
|
return authors
|
||||||
|
.stream()
|
||||||
|
.filter(author -> Collections.frequency(authors, author) > 3)
|
||||||
|
.collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Deadline> filterEmptyDeadlines(GrantDto grantDto) {
|
||||||
|
grantDto.setDeadlines(grantDto.getDeadlines().stream()
|
||||||
|
.filter(dto -> dto.getDate() != null || !StringUtils.isEmpty(dto.getDescription()))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
return grantDto.getDeadlines();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void createFromKias() throws IOException, ParseException {
|
||||||
|
for (GrantDto grantDto : kiasService.getNewGrantsDto()) {
|
||||||
|
if (saveFromKias(grantDto)) {
|
||||||
|
log.debug("GrantScheduler.loadGrantsFromKias new grant was loaded");
|
||||||
|
} else {
|
||||||
|
log.debug("GrantScheduler.loadGrantsFromKias grant wasn't loaded, cause it's already exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GrantDto> findAllActiveDto() {
|
||||||
|
return convert(findAllActive(), GrantDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Grant> findAllActive() {
|
||||||
|
return grantRepository.findAllActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Grant findById(Integer id) {
|
||||||
|
return grantRepository.getOne(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void ping(int grantId) throws IOException {
|
||||||
|
pingService.addPing(findById(grantId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(Grant grant) {
|
||||||
|
if (isEmpty(grant.getId())) {
|
||||||
|
create(grant);
|
||||||
|
} else {
|
||||||
|
update(grant);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Grant create(Grant grant) {
|
||||||
|
Grant newGrant = grantRepository.save(grant);
|
||||||
|
grantNotificationService.sendCreateNotification(newGrant);
|
||||||
|
return newGrant;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Integer update(Grant newGrant) {
|
||||||
|
Grant oldGrant = grantRepository.getOne(newGrant.getId());
|
||||||
|
//Grant.GrantStatus oldStatus = oldGrant.getStatus();
|
||||||
|
Set<User> oldAuthors = new HashSet<>(oldGrant.getAuthors());
|
||||||
|
newGrant = grantRepository.save(newGrant);
|
||||||
|
for (User author : newGrant.getAuthors()) {
|
||||||
|
if (!oldAuthors.contains(author)) {
|
||||||
|
grantNotificationService.sendCreateNotification(newGrant);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (newGrant.getStatus() != oldStatus) {
|
||||||
|
// grantNotificationService.statusChangeNotification(newPaper, oldStatus);
|
||||||
|
// }
|
||||||
|
|
||||||
|
return newGrant.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createByTitle(String newGrantTitle) {
|
||||||
|
Grant grant = new Grant();
|
||||||
|
grant.setTitle(newGrantTitle);
|
||||||
|
grant.setStatus(APPLICATION);
|
||||||
|
grant.getAuthors().add(userService.getCurrentUser());
|
||||||
|
grant.setLeader(userService.getCurrentUser());
|
||||||
|
grant.getDeadlines().add(deadlineService.createWithOffset(new Date(), 1, ChronoUnit.WEEKS));
|
||||||
|
create(grant);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Grant> findAllActiveByCurrentUser() {
|
||||||
|
return findAllActive()
|
||||||
|
.stream()
|
||||||
|
.filter(grant -> grant.getAuthors().contains(userService.getCurrentUser()) ||
|
||||||
|
grant.getLeader().equals(userService.getCurrentUser()))
|
||||||
|
.collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(List<Grant> grants) {
|
||||||
|
grants.forEach(grant -> delete(grant));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(Grant grant) {
|
||||||
|
deadlineService.delete(grant.getDeadlines());
|
||||||
|
grantRepository.delete(grant);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
73
src/main/java/ru/ulstu/grant/service/KiasService.java
Normal file
73
src/main/java/ru/ulstu/grant/service/KiasService.java
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
package ru.ulstu.grant.service;
|
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.WebClient;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.DomNode;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.configuration.ApplicationProperties;
|
||||||
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
|
import ru.ulstu.grant.page.KiasPage;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class KiasService {
|
||||||
|
private final static String BASE_URL = "https://www.rfbr.ru/rffi/ru/contest_search?CONTEST_STATUS_ID=%s&CONTEST_TYPE=%s&CONTEST_YEAR=%s";
|
||||||
|
private final static String CONTEST_STATUS_ID = "1";
|
||||||
|
private final static String CONTEST_TYPE = "-1";
|
||||||
|
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
public KiasService(UserService userService,
|
||||||
|
ApplicationProperties applicationProperties) {
|
||||||
|
this.userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GrantDto> getNewGrantsDto() throws ParseException, IOException {
|
||||||
|
Integer leaderId = userService.findOneByLoginIgnoreCase("admin").getId();
|
||||||
|
List<GrantDto> grants = new ArrayList<>();
|
||||||
|
try (WebClient webClient = new WebClient()) {
|
||||||
|
webClient.setJavaScriptTimeout(60 * 1000);
|
||||||
|
webClient.getOptions().setThrowExceptionOnScriptError(false);
|
||||||
|
for (Integer year : generateGrantYears()) {
|
||||||
|
final HtmlPage page = webClient.getPage(String.format(BASE_URL, CONTEST_STATUS_ID, CONTEST_TYPE, year));
|
||||||
|
grants.addAll(getKiasGrants(page));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
grants.forEach(grantDto -> grantDto.setLeaderId(leaderId));
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<GrantDto> getKiasGrants(HtmlPage page) throws ParseException {
|
||||||
|
List<GrantDto> newGrants = new ArrayList<>();
|
||||||
|
KiasPage kiasPage = new KiasPage(page);
|
||||||
|
do {
|
||||||
|
newGrants.addAll(getGrantsFromPage(kiasPage));
|
||||||
|
} while (kiasPage.goToNextPage()); //проверка существования следующей страницы с грантами
|
||||||
|
return newGrants;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<GrantDto> getGrantsFromPage(KiasPage kiasPage) throws ParseException {
|
||||||
|
List<GrantDto> grants = new ArrayList<>();
|
||||||
|
for (DomNode grantElement : kiasPage.getPageOfGrants()) {
|
||||||
|
if (kiasPage.isTableRowGrantLine(grantElement)) {
|
||||||
|
GrantDto grantDto = new GrantDto(
|
||||||
|
kiasPage.getGrantTitle(grantElement),
|
||||||
|
kiasPage.parseDeadLineDate(grantElement));
|
||||||
|
grants.add(grantDto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Integer> generateGrantYears() {
|
||||||
|
return Arrays.asList(Calendar.getInstance().get(Calendar.YEAR),
|
||||||
|
Calendar.getInstance().get(Calendar.YEAR) + 1);
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,16 @@
|
|||||||
package ru.ulstu.index.controller;
|
package ru.ulstu.index.controller;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Hidden;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import ru.ulstu.core.controller.AdviceController;
|
import ru.ulstu.core.controller.AdviceController;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@RequestMapping(value = "/index")
|
@RequestMapping(value = "/index")
|
||||||
@ApiIgnore
|
@Hidden
|
||||||
public class IndexController extends AdviceController {
|
public class IndexController extends AdviceController {
|
||||||
public IndexController(UserService userService) {
|
public IndexController(UserService userService) {
|
||||||
super(userService);
|
super(userService);
|
||||||
|
25
src/main/java/ru/ulstu/index/model/Section.java
Normal file
25
src/main/java/ru/ulstu/index/model/Section.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package ru.ulstu.index.model;
|
||||||
|
|
||||||
|
public class Section {
|
||||||
|
private final String title;
|
||||||
|
private final String image;
|
||||||
|
private final String href;
|
||||||
|
|
||||||
|
public Section(String title, String href, String image) {
|
||||||
|
this.title = title;
|
||||||
|
this.image = image;
|
||||||
|
this.href = href;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImage() {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHref() {
|
||||||
|
return href;
|
||||||
|
}
|
||||||
|
}
|
9
src/main/java/ru/ulstu/name/BaseRepository.java
Normal file
9
src/main/java/ru/ulstu/name/BaseRepository.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package ru.ulstu.name;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface BaseRepository {
|
||||||
|
List<String> findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
|
}
|
36
src/main/java/ru/ulstu/name/BaseService.java
Normal file
36
src/main/java/ru/ulstu/name/BaseService.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package ru.ulstu.name;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.Errors;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public abstract class BaseService {
|
||||||
|
|
||||||
|
public BaseRepository baseRepository;
|
||||||
|
|
||||||
|
protected void checkUniqueName(NameContainer nameContainer, Errors errors, Integer id, String errorMessage) {
|
||||||
|
if (nameContainer.getName().equals(getUnique(baseRepository.findByNameAndNotId(nameContainer.getName(), id)))) {
|
||||||
|
errors.rejectValue("title", "errorCode", errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String checkUniqueName(NameContainer nameContainer, Integer id) {
|
||||||
|
String foundName = getUnique(baseRepository.findByNameAndNotId(nameContainer.getName(), id));
|
||||||
|
if (nameContainer.getName().equals(foundName)) {
|
||||||
|
return foundName;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getUnique(List<String> names) {
|
||||||
|
return Optional.ofNullable(names)
|
||||||
|
.orElse(new ArrayList<>())
|
||||||
|
.stream()
|
||||||
|
.findAny()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
}
|
14
src/main/java/ru/ulstu/name/NameContainer.java
Normal file
14
src/main/java/ru/ulstu/name/NameContainer.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package ru.ulstu.name;
|
||||||
|
|
||||||
|
public abstract class NameContainer {
|
||||||
|
|
||||||
|
private String name = "";
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
@ -9,10 +9,10 @@ import ru.ulstu.odin.service.OdinService;
|
|||||||
|
|
||||||
public abstract class OdinController<L, E extends OdinDto> {
|
public abstract class OdinController<L, E extends OdinDto> {
|
||||||
public static final String META_LIST_URL = "/meta/list";
|
public static final String META_LIST_URL = "/meta/list";
|
||||||
public static final String META_ELEMENT_URL = "/meta/element";
|
private static final String META_ELEMENT_URL = "/meta/element";
|
||||||
|
|
||||||
private Class<L> listDtoClass;
|
private final Class<L> listDtoClass;
|
||||||
private Class<E> elementDtoClass;
|
private final Class<E> elementDtoClass;
|
||||||
@Autowired
|
@Autowired
|
||||||
private OdinService<L, E> odinService;
|
private OdinService<L, E> odinService;
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package ru.ulstu.odin.model;
|
|||||||
import ru.ulstu.core.error.OdinException;
|
import ru.ulstu.core.error.OdinException;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
@ -14,9 +15,9 @@ public class OdinCollectionField extends OdinField {
|
|||||||
ParameterizedType genericType = (ParameterizedType) field.getGenericType();
|
ParameterizedType genericType = (ParameterizedType) field.getGenericType();
|
||||||
Type fieldElementClass = genericType.getActualTypeArguments()[0];
|
Type fieldElementClass = genericType.getActualTypeArguments()[0];
|
||||||
try {
|
try {
|
||||||
OdinDto someInstance = (OdinDto) ((Class) (fieldElementClass)).newInstance();
|
OdinDto someInstance = (OdinDto) ((Class) (fieldElementClass)).getDeclaredConstructor().newInstance();
|
||||||
this.path = someInstance.getControllerPath();
|
this.path = someInstance.getControllerPath();
|
||||||
} catch (IllegalAccessException | InstantiationException e) {
|
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
|
||||||
throw new OdinException(String.format("Can't create new instance, check default constructor of %s",
|
throw new OdinException(String.format("Can't create new instance, check default constructor of %s",
|
||||||
fieldElementClass.getTypeName()));
|
fieldElementClass.getTypeName()));
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package ru.ulstu.odin.model;
|
package ru.ulstu.odin.model;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
import ru.ulstu.core.error.OdinException;
|
import ru.ulstu.core.error.OdinException;
|
||||||
import ru.ulstu.odin.model.annotation.OdinCaption;
|
import ru.ulstu.odin.model.annotation.OdinCaption;
|
||||||
import ru.ulstu.odin.model.annotation.OdinReadOnly;
|
import ru.ulstu.odin.model.annotation.OdinReadOnly;
|
||||||
import ru.ulstu.odin.model.annotation.OdinVisible;
|
import ru.ulstu.odin.model.annotation.OdinVisible;
|
||||||
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@ -31,15 +31,16 @@ public abstract class OdinField implements Comparable {
|
|||||||
return this.name().toLowerCase();
|
return this.name().toLowerCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected final OdinFieldType fieldType;
|
|
||||||
protected final String fieldName;
|
|
||||||
protected final String caption;
|
|
||||||
protected final OdinVisible.OdinVisibleType visible;
|
|
||||||
protected final boolean readOnly;
|
|
||||||
protected final boolean notEmpty;
|
|
||||||
private Field field;
|
|
||||||
|
|
||||||
public OdinField(Field field, OdinFieldType fieldType) {
|
private final OdinFieldType fieldType;
|
||||||
|
private final String fieldName;
|
||||||
|
private final String caption;
|
||||||
|
private final OdinVisible.OdinVisibleType visible;
|
||||||
|
private final boolean readOnly;
|
||||||
|
private final boolean notEmpty;
|
||||||
|
private final Field field;
|
||||||
|
|
||||||
|
OdinField(Field field, OdinFieldType fieldType) {
|
||||||
this.field = field;
|
this.field = field;
|
||||||
this.fieldName = getFieldName(field);
|
this.fieldName = getFieldName(field);
|
||||||
this.caption = Optional.ofNullable(getValueFromAnnotation(OdinCaption.class, "value"))
|
this.caption = Optional.ofNullable(getValueFromAnnotation(OdinCaption.class, "value"))
|
||||||
@ -92,7 +93,7 @@ public abstract class OdinField implements Comparable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> T getValue(Class<? extends Annotation> annotationClass, String valueName, Class<T> clazz) {
|
<T> T getValue(Class<? extends Annotation> annotationClass, String valueName, Class<T> clazz) {
|
||||||
if (field.isAnnotationPresent(annotationClass)) {
|
if (field.isAnnotationPresent(annotationClass)) {
|
||||||
return cast(getValueFromAnnotation(annotationClass, valueName), clazz);
|
return cast(getValueFromAnnotation(annotationClass, valueName), clazz);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package ru.ulstu.odin.model;
|
|||||||
import ru.ulstu.core.error.OdinException;
|
import ru.ulstu.core.error.OdinException;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
public class OdinObjectField extends OdinField {
|
public class OdinObjectField extends OdinField {
|
||||||
@ -12,9 +13,9 @@ public class OdinObjectField extends OdinField {
|
|||||||
super(field, OdinFieldType.OBJECT);
|
super(field, OdinFieldType.OBJECT);
|
||||||
Type fieldElementClass = field.getType();
|
Type fieldElementClass = field.getType();
|
||||||
try {
|
try {
|
||||||
OdinDto someInstance = (OdinDto) ((Class) (fieldElementClass)).newInstance();
|
OdinDto someInstance = (OdinDto) ((Class) (fieldElementClass)).getDeclaredConstructor().newInstance();
|
||||||
this.path = someInstance.getControllerPath();
|
this.path = someInstance.getControllerPath();
|
||||||
} catch (IllegalAccessException | InstantiationException e) {
|
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
|
||||||
throw new OdinException(String.format("Can't create new instance, check default constructor of %s",
|
throw new OdinException(String.format("Can't create new instance, check default constructor of %s",
|
||||||
fieldElementClass.getTypeName()));
|
fieldElementClass.getTypeName()));
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package ru.ulstu.odin.model;
|
package ru.ulstu.odin.model;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.Email;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
import ru.ulstu.odin.model.annotation.OdinString;
|
import ru.ulstu.odin.model.annotation.OdinString;
|
||||||
import ru.ulstu.odin.model.annotation.OdinString.OdinStringType;
|
import ru.ulstu.odin.model.annotation.OdinString.OdinStringType;
|
||||||
|
|
||||||
import javax.validation.constraints.Email;
|
|
||||||
import javax.validation.constraints.Size;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import static ru.ulstu.odin.model.annotation.OdinString.OdinStringType.EMAIL;
|
import static ru.ulstu.odin.model.annotation.OdinString.OdinStringType.EMAIL;
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
package ru.ulstu.odinexample.controller;
|
|
||||||
|
|
||||||
public class OdinExampleController {
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
package ru.ulstu.odinexample.model;
|
|
||||||
|
|
||||||
public class OdinExampleDto {
|
|
||||||
}
|
|
@ -1,103 +0,0 @@
|
|||||||
package ru.ulstu.odinexample.model;
|
|
||||||
|
|
||||||
import ru.ulstu.core.util.DateUtils;
|
|
||||||
import ru.ulstu.odin.model.annotation.OdinCaption;
|
|
||||||
import ru.ulstu.odin.model.annotation.OdinDate;
|
|
||||||
import ru.ulstu.odin.model.annotation.OdinNumeric;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.LocalTime;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class OdinExampleListDto {
|
|
||||||
@OdinCaption("instant")
|
|
||||||
@OdinDate(type = OdinDate.OdinDateType.DATETIME)
|
|
||||||
private Instant instant;
|
|
||||||
@OdinCaption("date")
|
|
||||||
private Date date;
|
|
||||||
@OdinCaption("localdate")
|
|
||||||
private LocalDate localDate;
|
|
||||||
@OdinCaption("localtime")
|
|
||||||
@OdinDate(type = OdinDate.OdinDateType.TIME)
|
|
||||||
private LocalTime localTime;
|
|
||||||
@OdinCaption("localdatetime")
|
|
||||||
@OdinDate(type = OdinDate.OdinDateType.DATETIME)
|
|
||||||
private LocalDateTime localDateTime;
|
|
||||||
@OdinCaption("int")
|
|
||||||
private int intval;
|
|
||||||
@OdinCaption("int+settings")
|
|
||||||
@OdinNumeric(precision = 5, scale = 2)
|
|
||||||
private int intvalset;
|
|
||||||
@OdinCaption("float")
|
|
||||||
private float floatval;
|
|
||||||
@OdinCaption("double")
|
|
||||||
private double aDouble;
|
|
||||||
@OdinCaption("double+set")
|
|
||||||
@OdinNumeric(precision = 5, scale = 3)
|
|
||||||
private double aDoubles;
|
|
||||||
@OdinCaption("int+positive")
|
|
||||||
@OdinNumeric(positiveOnly = true, scale = 2)
|
|
||||||
private int invalpos;
|
|
||||||
|
|
||||||
public OdinExampleListDto() {
|
|
||||||
this.instant = Instant.now();
|
|
||||||
this.date = new Date();
|
|
||||||
this.localDate = LocalDate.now();
|
|
||||||
this.localTime = LocalTime.now();
|
|
||||||
this.localDateTime = LocalDateTime.now();
|
|
||||||
intval = -134;
|
|
||||||
intvalset = 1343423232;
|
|
||||||
floatval = 2323.44F;
|
|
||||||
aDouble = -232323.43434;
|
|
||||||
aDoubles = 0.456456456;
|
|
||||||
invalpos = -23232323;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Date getInstant() {
|
|
||||||
return DateUtils.instantToDate(instant);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getDate() {
|
|
||||||
return date;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getLocalDate() {
|
|
||||||
return DateUtils.localDateToDate(localDate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getLocalTime() {
|
|
||||||
return DateUtils.localTimeToDate(localTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getLocalDateTime() {
|
|
||||||
return DateUtils.localDateTimeToDate(localDateTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIntval() {
|
|
||||||
return intval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getIntvalset() {
|
|
||||||
return intvalset;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getFloatval() {
|
|
||||||
return floatval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getaDouble() {
|
|
||||||
return aDouble;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getaDoubles() {
|
|
||||||
return aDoubles;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getInvalpos() {
|
|
||||||
return invalpos;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
package ru.ulstu.odinexample.service;
|
|
||||||
|
|
||||||
public class OdinExampleService {
|
|
||||||
}
|
|
@ -1,60 +1,65 @@
|
|||||||
package ru.ulstu.paper.controller;
|
package ru.ulstu.paper.controller;
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import io.swagger.v3.oas.annotations.Hidden;
|
||||||
import org.springframework.http.HttpStatus;
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import ru.ulstu.conference.service.ConferenceService;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.paper.model.AutoCompleteData;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.paper.model.PaperFilterDto;
|
import ru.ulstu.paper.model.PaperListDto;
|
||||||
import ru.ulstu.paper.service.LatexService;
|
import ru.ulstu.paper.service.LatexService;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
||||||
import static org.springframework.util.StringUtils.isEmpty;
|
|
||||||
|
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@RequestMapping(value = "/papers")
|
@RequestMapping(value = "/papers")
|
||||||
@ApiIgnore
|
@Hidden
|
||||||
public class PaperController {
|
public class PaperController {
|
||||||
private final PaperService paperService;
|
private final PaperService paperService;
|
||||||
|
private final ConferenceService conferenceService;
|
||||||
private final LatexService latexService;
|
private final LatexService latexService;
|
||||||
|
|
||||||
public PaperController(PaperService paperService, LatexService latexService) {
|
public PaperController(PaperService paperService,
|
||||||
|
ConferenceService conferenceService,
|
||||||
|
LatexService latexService) {
|
||||||
this.paperService = paperService;
|
this.paperService = paperService;
|
||||||
|
this.conferenceService = conferenceService;
|
||||||
this.latexService = latexService;
|
this.latexService = latexService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/papers")
|
@GetMapping("/papers")
|
||||||
public void getPapers(ModelMap modelMap) {
|
public void getPapers(ModelMap modelMap) {
|
||||||
modelMap.put("filteredPapers", new PaperFilterDto(paperService.findAllDto(), null, null));
|
modelMap.put("filteredPapers", new PaperListDto(paperService.findAllDto(), null, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/papers")
|
@PostMapping("/papers")
|
||||||
public void filterPapers(@Valid PaperFilterDto paperFilterDto, ModelMap modelMap) {
|
public void listPapers(@Valid PaperListDto paperListDto, ModelMap modelMap) {
|
||||||
modelMap.put("filteredPapers", new PaperFilterDto(paperService.filter(paperFilterDto),
|
if (paperListDto.getPaperDeleteId() != null) {
|
||||||
paperFilterDto.getFilterAuthorId(),
|
if (conferenceService.isAttachedToConference(paperListDto.getPaperDeleteId())) {
|
||||||
paperFilterDto.getYear()));
|
modelMap.put("flashMessage", "Статью нельзя удалить, она прикреплена к конференции");
|
||||||
|
} else {
|
||||||
|
paperService.delete(paperListDto.getPaperDeleteId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modelMap.put("filteredPapers", new PaperListDto(paperService.filter(paperListDto),
|
||||||
|
paperListDto.getFilterAuthorId(),
|
||||||
|
paperListDto.getYear()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/dashboard")
|
@GetMapping("/dashboard")
|
||||||
@ -63,7 +68,7 @@ public class PaperController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/paper")
|
@GetMapping("/paper")
|
||||||
public void getPapers(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
public void getPaper(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
||||||
if (id != null && id > 0) {
|
if (id != null && id > 0) {
|
||||||
modelMap.put("paperDto", paperService.findOneDto(id));
|
modelMap.put("paperDto", paperService.findOneDto(id));
|
||||||
} else {
|
} else {
|
||||||
@ -94,12 +99,6 @@ public class PaperController {
|
|||||||
return "/papers/paper";
|
return "/papers/paper";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/delete/{paper-id}")
|
|
||||||
public String delete(@PathVariable("paper-id") Integer paperId) throws IOException {
|
|
||||||
paperService.delete(paperId);
|
|
||||||
return "redirect:/papers/papers";
|
|
||||||
}
|
|
||||||
|
|
||||||
@ModelAttribute("allStatuses")
|
@ModelAttribute("allStatuses")
|
||||||
public List<Paper.PaperStatus> getPaperStatuses() {
|
public List<Paper.PaperStatus> getPaperStatuses() {
|
||||||
return paperService.getPaperStatuses();
|
return paperService.getPaperStatuses();
|
||||||
@ -124,17 +123,14 @@ public class PaperController {
|
|||||||
return years;
|
return years;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/generatePdf")
|
@ModelAttribute("autocompleteData")
|
||||||
public ResponseEntity<byte[]> getPdfFile(PaperDto paper) throws IOException, InterruptedException {
|
public AutoCompleteData getAutocompleteData() {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
return paperService.getAutoCompleteData();
|
||||||
headers.add("Content-Disposition", "attachment; filename='" +
|
|
||||||
URLEncoder.encode(paper.getTitle() + ".pdf", UTF_8.toString()) + "'");
|
|
||||||
return new ResponseEntity<>(latexService.generatePdfFromLatexFile(paper), headers, HttpStatus.OK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void filterEmptyDeadlines(PaperDto paperDto) {
|
private void filterEmptyDeadlines(PaperDto paperDto) {
|
||||||
paperDto.setDeadlines(paperDto.getDeadlines().stream()
|
paperDto.setDeadlines(paperDto.getDeadlines().stream()
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
.filter(dto -> dto.getDate() != null || !dto.getDescription().isEmpty())
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package ru.ulstu.paper.controller;
|
package ru.ulstu.paper.controller;
|
||||||
|
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
@ -7,14 +8,15 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.PutMapping;
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import ru.ulstu.configuration.Constants;
|
import ru.ulstu.configuration.Constants;
|
||||||
import ru.ulstu.core.model.response.Response;
|
import ru.ulstu.core.model.response.Response;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.paper.model.PaperFilterDto;
|
import ru.ulstu.paper.model.PaperListDto;
|
||||||
|
import ru.ulstu.paper.model.ReferenceDto;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -38,7 +40,7 @@ public class PaperRestController {
|
|||||||
|
|
||||||
@GetMapping("/{paper-id}")
|
@GetMapping("/{paper-id}")
|
||||||
public Response<PaperDto> getPaper(@PathVariable("paper-id") Integer paperId) {
|
public Response<PaperDto> getPaper(@PathVariable("paper-id") Integer paperId) {
|
||||||
return new Response(paperService.findById(paperId));
|
return new Response<>(paperService.findById(paperId));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ -54,16 +56,26 @@ public class PaperRestController {
|
|||||||
@DeleteMapping("/{paper-id}")
|
@DeleteMapping("/{paper-id}")
|
||||||
public Response<Boolean> delete(@PathVariable("paper-id") Integer paperId) throws IOException {
|
public Response<Boolean> delete(@PathVariable("paper-id") Integer paperId) throws IOException {
|
||||||
paperService.delete(paperId);
|
paperService.delete(paperId);
|
||||||
return new Response<>(true);
|
return new Response<>(Boolean.TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/filter")
|
@PostMapping("/filter")
|
||||||
public Response<List<PaperDto>> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException {
|
public Response<List<PaperDto>> filter(@RequestBody @Valid PaperListDto paperListDto) throws IOException {
|
||||||
return new Response<>(paperService.filter(paperFilterDto));
|
return new Response<>(paperService.filter(paperListDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("formatted-list")
|
@GetMapping("formatted-list")
|
||||||
public Response<List<String>> getFormattedPaperList() {
|
public Response<List<String>> getFormattedPaperList() {
|
||||||
return new Response<>(paperService.getFormattedPaperList());
|
return new Response<>(paperService.getFormattedPaperList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getFormattedReference")
|
||||||
|
public Response<String> getFormattedReference(@RequestBody @Valid ReferenceDto referenceDto) {
|
||||||
|
return new Response<>(paperService.getFormattedReference(referenceDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/ping")
|
||||||
|
public void ping(@RequestParam("paperId") int paperId) throws IOException {
|
||||||
|
paperService.ping(paperId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
43
src/main/java/ru/ulstu/paper/model/AutoCompleteData.java
Normal file
43
src/main/java/ru/ulstu/paper/model/AutoCompleteData.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package ru.ulstu.paper.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AutoCompleteData {
|
||||||
|
private List<String> authors = new ArrayList<>();
|
||||||
|
private List<String> publicationTitles = new ArrayList<>();
|
||||||
|
private List<String> publishers = new ArrayList<>();
|
||||||
|
private List<String> journalOrCollectionTitles = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<String> getAuthors() {
|
||||||
|
return authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthors(List<String> authors) {
|
||||||
|
this.authors = authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getPublicationTitles() {
|
||||||
|
return publicationTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicationTitles(List<String> publicationTitles) {
|
||||||
|
this.publicationTitles = publicationTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getPublishers() {
|
||||||
|
return publishers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublishers(List<String> publishers) {
|
||||||
|
this.publishers = publishers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getJournalOrCollectionTitles() {
|
||||||
|
return journalOrCollectionTitles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJournalOrCollectionTitles(List<String> journalOrCollectionTitles) {
|
||||||
|
this.journalOrCollectionTitles = journalOrCollectionTitles;
|
||||||
|
}
|
||||||
|
}
|
@ -1,56 +1,70 @@
|
|||||||
package ru.ulstu.paper.model;
|
package ru.ulstu.paper.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.CascadeType;
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.DiscriminatorValue;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToMany;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.OneToMany;
|
||||||
|
import jakarta.persistence.OrderBy;
|
||||||
|
import jakarta.persistence.Temporal;
|
||||||
|
import jakarta.persistence.TemporalType;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import org.hibernate.annotations.Fetch;
|
import org.hibernate.annotations.Fetch;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.core.model.UserContainer;
|
import ru.ulstu.core.model.EventSource;
|
||||||
|
import ru.ulstu.core.model.UserActivity;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.file.model.FileData;
|
import ru.ulstu.file.model.FileData;
|
||||||
|
import ru.ulstu.grant.model.Grant;
|
||||||
import ru.ulstu.timeline.model.Event;
|
import ru.ulstu.timeline.model.Event;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EnumType;
|
|
||||||
import javax.persistence.Enumerated;
|
|
||||||
import javax.persistence.FetchType;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.ManyToMany;
|
|
||||||
import javax.persistence.OneToMany;
|
|
||||||
import javax.persistence.OrderBy;
|
|
||||||
import javax.persistence.Temporal;
|
|
||||||
import javax.persistence.TemporalType;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Paper extends BaseEntity implements UserContainer {
|
@DiscriminatorValue("PAPER")
|
||||||
|
public class Paper extends BaseEntity implements UserActivity, EventSource {
|
||||||
public enum PaperStatus {
|
public enum PaperStatus {
|
||||||
ATTENTION("Обратить внимание"),
|
ATTENTION("Обратить внимание", "text-warning"),
|
||||||
ON_PREPARATION("На подготовке"),
|
ON_PREPARATION("На подготовке", "text-primary"),
|
||||||
ON_REVIEW("Отправлена на проверку"),
|
ON_REVIEW("Отправлена на проверку", "text-review"),
|
||||||
ACCEPTED("Принята"),
|
ACCEPTED("Принята", "text-accepted"),
|
||||||
NOT_ACCEPTED("Не принята"),
|
NOT_ACCEPTED("Не принята", "text-not-accepted"),
|
||||||
COMPLETED("Завершена (опубликована)"),
|
COMPLETED("Завершена (опубликована)", "text-success"),
|
||||||
DRAFT("Черновик"),
|
DRAFT("Черновик", "text-draft"),
|
||||||
FAILED("Провалены сроки");
|
FAILED("Провалены сроки", "text-failed");
|
||||||
|
|
||||||
private String statusName;
|
private final String statusName;
|
||||||
|
private final String elementClass;
|
||||||
|
|
||||||
PaperStatus(String name) {
|
PaperStatus(String name, String elementClass) {
|
||||||
this.statusName = name;
|
this.statusName = name;
|
||||||
|
this.elementClass = elementClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatusName() {
|
public String getStatusName() {
|
||||||
return statusName;
|
return statusName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getElementClass() {
|
||||||
|
return elementClass;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum PaperType {
|
public enum PaperType {
|
||||||
@ -59,7 +73,7 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
SCOPUS("Scopus"),
|
SCOPUS("Scopus"),
|
||||||
WEB_OF_SCIENCE("Web Of Science");
|
WEB_OF_SCIENCE("Web Of Science");
|
||||||
|
|
||||||
private String typeName;
|
private final String typeName;
|
||||||
|
|
||||||
PaperType(String name) {
|
PaperType(String name) {
|
||||||
this.typeName = name;
|
this.typeName = name;
|
||||||
@ -81,13 +95,15 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
|
|
||||||
@Column(name = "create_date")
|
@Column(name = "create_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSXXX")
|
||||||
private Date createDate = new Date();
|
private Date createDate = new Date();
|
||||||
|
|
||||||
@Column(name = "update_date")
|
@Column(name = "update_date")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSXXX")
|
||||||
private Date updateDate = new Date();
|
private Date updateDate = new Date();
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
@JoinColumn(name = "paper_id", unique = true)
|
@JoinColumn(name = "paper_id", unique = true)
|
||||||
@Fetch(FetchMode.SUBSELECT)
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
@OrderBy("date")
|
@OrderBy("date")
|
||||||
@ -110,9 +126,17 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER)
|
@ManyToMany(fetch = FetchType.EAGER)
|
||||||
private Set<User> authors = new HashSet<>();
|
private Set<User> authors = new HashSet<>();
|
||||||
|
@ManyToOne()
|
||||||
|
@JoinColumn(name = "conference_id")
|
||||||
|
private Conference conference;
|
||||||
|
|
||||||
@Column(name = "latex_text")
|
@ManyToMany(mappedBy = "papers")
|
||||||
private String latexText;
|
private List<Grant> grants;
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(name = "paper_id", unique = true)
|
||||||
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
|
private List<Reference> references = new ArrayList<>();
|
||||||
|
|
||||||
public PaperStatus getStatus() {
|
public PaperStatus getStatus() {
|
||||||
return status;
|
return status;
|
||||||
@ -182,6 +206,16 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<User> getRecipients() {
|
||||||
|
return new ArrayList<>(authors);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addObjectToEvent(Event event) {
|
||||||
|
event.setPaper(this);
|
||||||
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
@ -210,19 +244,35 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLatexText() {
|
public Conference getConference() {
|
||||||
return latexText;
|
return conference;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLatexText(String latexText) {
|
public void setConference(Conference conference) {
|
||||||
this.latexText = latexText;
|
this.conference = conference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Grant> getGrants() {
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGrants(List<Grant> grants) {
|
||||||
|
this.grants = grants;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<User> getUsers() {
|
public Set<User> getActivityUsers() {
|
||||||
return getAuthors();
|
return getAuthors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Reference> getReferences() {
|
||||||
|
return references;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferences(List<Reference> references) {
|
||||||
|
this.references = references;
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<Deadline> getNextDeadline() {
|
public Optional<Deadline> getNextDeadline() {
|
||||||
return deadlines
|
return deadlines
|
||||||
.stream()
|
.stream()
|
||||||
@ -240,4 +290,35 @@ public class Paper extends BaseEntity implements UserContainer {
|
|||||||
.findAny()
|
.findAny()
|
||||||
.isPresent();
|
.isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!super.equals(o)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Paper paper = (Paper) o;
|
||||||
|
return Objects.equals(title, paper.title) &&
|
||||||
|
status == paper.status &&
|
||||||
|
type == paper.type &&
|
||||||
|
Objects.equals(deadlines, paper.deadlines) &&
|
||||||
|
Objects.equals(comment, paper.comment) &&
|
||||||
|
Objects.equals(url, paper.url) &&
|
||||||
|
Objects.equals(locked, paper.locked) &&
|
||||||
|
Objects.equals(events, paper.events) &&
|
||||||
|
Objects.equals(files, paper.files) &&
|
||||||
|
Objects.equals(authors, paper.authors) &&
|
||||||
|
Objects.equals(conference, paper.conference) &&
|
||||||
|
Objects.equals(grants, paper.grants);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(super.hashCode(), title, status, type, createDate, updateDate, deadlines, comment, url, locked, events, files, authors, conference, grants);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,15 @@ package ru.ulstu.paper.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.user.model.UserDto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import javax.validation.constraints.Size;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -26,7 +28,9 @@ public class PaperDto {
|
|||||||
private String title;
|
private String title;
|
||||||
private Paper.PaperStatus status;
|
private Paper.PaperStatus status;
|
||||||
private Paper.PaperType type;
|
private Paper.PaperType type;
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSXXX")
|
||||||
private Date createDate;
|
private Date createDate;
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSXXX")
|
||||||
private Date updateDate;
|
private Date updateDate;
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
@ -38,6 +42,8 @@ public class PaperDto {
|
|||||||
private Set<UserDto> authors;
|
private Set<UserDto> authors;
|
||||||
private Integer filterAuthorId;
|
private Integer filterAuthorId;
|
||||||
private String latexText;
|
private String latexText;
|
||||||
|
private List<ReferenceDto> references = new ArrayList<>();
|
||||||
|
private ReferenceDto.FormatStandard formatStandard = ReferenceDto.FormatStandard.GOST;
|
||||||
|
|
||||||
public PaperDto() {
|
public PaperDto() {
|
||||||
deadlines.add(new Deadline());
|
deadlines.add(new Deadline());
|
||||||
@ -57,7 +63,9 @@ public class PaperDto {
|
|||||||
@JsonProperty("locked") Boolean locked,
|
@JsonProperty("locked") Boolean locked,
|
||||||
@JsonProperty("files") List<FileDataDto> files,
|
@JsonProperty("files") List<FileDataDto> files,
|
||||||
@JsonProperty("authorIds") Set<Integer> authorIds,
|
@JsonProperty("authorIds") Set<Integer> authorIds,
|
||||||
@JsonProperty("authors") Set<UserDto> authors) {
|
@JsonProperty("authors") Set<UserDto> authors,
|
||||||
|
@JsonProperty("references") List<ReferenceDto> references,
|
||||||
|
@JsonProperty("formatStandard") ReferenceDto.FormatStandard formatStandard) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
@ -71,6 +79,8 @@ public class PaperDto {
|
|||||||
this.locked = locked;
|
this.locked = locked;
|
||||||
this.files = files;
|
this.files = files;
|
||||||
this.authors = authors;
|
this.authors = authors;
|
||||||
|
this.references = references;
|
||||||
|
this.formatStandard = formatStandard;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaperDto(Paper paper) {
|
public PaperDto(Paper paper) {
|
||||||
@ -83,11 +93,11 @@ public class PaperDto {
|
|||||||
this.deadlines = paper.getDeadlines();
|
this.deadlines = paper.getDeadlines();
|
||||||
this.comment = paper.getComment();
|
this.comment = paper.getComment();
|
||||||
this.url = paper.getUrl();
|
this.url = paper.getUrl();
|
||||||
this.latexText = paper.getLatexText();
|
|
||||||
this.locked = paper.getLocked();
|
this.locked = paper.getLocked();
|
||||||
this.files = convert(paper.getFiles(), FileDataDto::new);
|
this.files = convert(paper.getFiles(), FileDataDto::new);
|
||||||
this.authorIds = convert(paper.getAuthors(), user -> user.getId());
|
this.authorIds = convert(paper.getAuthors(), BaseEntity::getId);
|
||||||
this.authors = convert(paper.getAuthors(), UserDto::new);
|
this.authors = convert(paper.getAuthors(), UserDto::new);
|
||||||
|
this.references = convert(paper.getReferences(), ReferenceDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -205,7 +215,7 @@ public class PaperDto {
|
|||||||
public String getAuthorsString() {
|
public String getAuthorsString() {
|
||||||
return StringUtils.abbreviate(authors
|
return StringUtils.abbreviate(authors
|
||||||
.stream()
|
.stream()
|
||||||
.map(author -> author.getLastName())
|
.map(UserDto::getLastName)
|
||||||
.collect(Collectors.joining(", ")), MAX_AUTHORS_LENGTH);
|
.collect(Collectors.joining(", ")), MAX_AUTHORS_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,4 +226,20 @@ public class PaperDto {
|
|||||||
public void setFilterAuthorId(Integer filterAuthorId) {
|
public void setFilterAuthorId(Integer filterAuthorId) {
|
||||||
this.filterAuthorId = filterAuthorId;
|
this.filterAuthorId = filterAuthorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ReferenceDto> getReferences() {
|
||||||
|
return references;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferences(List<ReferenceDto> references) {
|
||||||
|
this.references = references;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceDto.FormatStandard getFormatStandard() {
|
||||||
|
return formatStandard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFormatStandard(ReferenceDto.FormatStandard formatStandard) {
|
||||||
|
this.formatStandard = formatStandard;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,15 +2,16 @@ package ru.ulstu.paper.model;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PaperFilterDto {
|
public class PaperListDto {
|
||||||
private List<PaperDto> papers;
|
private List<PaperDto> papers;
|
||||||
private Integer filterAuthorId;
|
private Integer filterAuthorId;
|
||||||
|
private Integer paperDeleteId;
|
||||||
private Integer year;
|
private Integer year;
|
||||||
|
|
||||||
public PaperFilterDto() {
|
public PaperListDto() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaperFilterDto(List<PaperDto> paperDtos, Integer filterAuthorId, Integer year) {
|
public PaperListDto(List<PaperDto> paperDtos, Integer filterAuthorId, Integer year) {
|
||||||
this.papers = paperDtos;
|
this.papers = paperDtos;
|
||||||
this.filterAuthorId = filterAuthorId;
|
this.filterAuthorId = filterAuthorId;
|
||||||
this.year = year;
|
this.year = year;
|
||||||
@ -39,4 +40,12 @@ public class PaperFilterDto {
|
|||||||
public void setYear(Integer year) {
|
public void setYear(Integer year) {
|
||||||
this.year = year;
|
this.year = year;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getPaperDeleteId() {
|
||||||
|
return paperDeleteId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaperDeleteId(Integer paperDeleteId) {
|
||||||
|
this.paperDeleteId = paperDeleteId;
|
||||||
|
}
|
||||||
}
|
}
|
87
src/main/java/ru/ulstu/paper/model/Reference.java
Normal file
87
src/main/java/ru/ulstu/paper/model/Reference.java
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
package ru.ulstu.paper.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class Reference extends BaseEntity {
|
||||||
|
|
||||||
|
private String authors;
|
||||||
|
|
||||||
|
@Column(name = "publication_title")
|
||||||
|
private String publicationTitle;
|
||||||
|
|
||||||
|
@Column(name = "publication_year")
|
||||||
|
private Integer publicationYear;
|
||||||
|
|
||||||
|
private String publisher;
|
||||||
|
|
||||||
|
private String pages;
|
||||||
|
|
||||||
|
@Column(name = "journal_or_collection_title")
|
||||||
|
private String journalOrCollectionTitle;
|
||||||
|
|
||||||
|
@Enumerated(value = EnumType.STRING)
|
||||||
|
@Column(name = "reference_type")
|
||||||
|
private ReferenceDto.ReferenceType referenceType = ReferenceDto.ReferenceType.ARTICLE;
|
||||||
|
|
||||||
|
public String getAuthors() {
|
||||||
|
return authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthors(String authors) {
|
||||||
|
this.authors = authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublicationTitle() {
|
||||||
|
return publicationTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicationTitle(String publicationTitle) {
|
||||||
|
this.publicationTitle = publicationTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPublicationYear() {
|
||||||
|
return publicationYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicationYear(Integer publicationYear) {
|
||||||
|
this.publicationYear = publicationYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublisher() {
|
||||||
|
return publisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublisher(String publisher) {
|
||||||
|
this.publisher = publisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPages() {
|
||||||
|
return pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPages(String pages) {
|
||||||
|
this.pages = pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJournalOrCollectionTitle() {
|
||||||
|
return journalOrCollectionTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJournalOrCollectionTitle(String journalOrCollectionTitle) {
|
||||||
|
this.journalOrCollectionTitle = journalOrCollectionTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceDto.ReferenceType getReferenceType() {
|
||||||
|
return referenceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferenceType(ReferenceDto.ReferenceType referenceType) {
|
||||||
|
this.referenceType = referenceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
166
src/main/java/ru/ulstu/paper/model/ReferenceDto.java
Normal file
166
src/main/java/ru/ulstu/paper/model/ReferenceDto.java
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
package ru.ulstu.paper.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
public class ReferenceDto {
|
||||||
|
public enum ReferenceType {
|
||||||
|
ARTICLE("Статья"),
|
||||||
|
BOOK("Книга");
|
||||||
|
|
||||||
|
private final String typeName;
|
||||||
|
|
||||||
|
ReferenceType(String name) {
|
||||||
|
this.typeName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTypeName() {
|
||||||
|
return typeName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum FormatStandard {
|
||||||
|
GOST("ГОСТ"),
|
||||||
|
SPRINGER("Springer");
|
||||||
|
|
||||||
|
private final String standardName;
|
||||||
|
|
||||||
|
FormatStandard(String name) {
|
||||||
|
this.standardName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStandardName() {
|
||||||
|
return standardName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
private String authors;
|
||||||
|
private String publicationTitle;
|
||||||
|
private Integer publicationYear;
|
||||||
|
private String publisher;
|
||||||
|
private String pages;
|
||||||
|
private String journalOrCollectionTitle;
|
||||||
|
private ReferenceType referenceType;
|
||||||
|
private FormatStandard formatStandard;
|
||||||
|
private boolean deleted;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public ReferenceDto(
|
||||||
|
@JsonProperty("id") Integer id,
|
||||||
|
@JsonProperty("authors") String authors,
|
||||||
|
@JsonProperty("publicationTitle") String publicationTitle,
|
||||||
|
@JsonProperty("publicationYear") Integer publicationYear,
|
||||||
|
@JsonProperty("publisher") String publisher,
|
||||||
|
@JsonProperty("pages") String pages,
|
||||||
|
@JsonProperty("journalOrCollectionTitle") String journalOrCollectionTitle,
|
||||||
|
@JsonProperty("referenceType") ReferenceType referenceType,
|
||||||
|
@JsonProperty("formatStandard") FormatStandard formatStandard,
|
||||||
|
@JsonProperty("isDeleted") boolean deleted) {
|
||||||
|
this.id = id;
|
||||||
|
this.authors = authors;
|
||||||
|
this.publicationTitle = publicationTitle;
|
||||||
|
this.publicationYear = publicationYear;
|
||||||
|
this.publisher = publisher;
|
||||||
|
this.pages = pages;
|
||||||
|
this.journalOrCollectionTitle = journalOrCollectionTitle;
|
||||||
|
this.referenceType = referenceType;
|
||||||
|
this.formatStandard = formatStandard;
|
||||||
|
this.deleted = deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceDto(Reference reference) {
|
||||||
|
this.id = reference.getId();
|
||||||
|
this.authors = reference.getAuthors();
|
||||||
|
this.publicationTitle = reference.getPublicationTitle();
|
||||||
|
this.publicationYear = reference.getPublicationYear();
|
||||||
|
this.publisher = reference.getPublisher();
|
||||||
|
this.pages = reference.getPages();
|
||||||
|
this.journalOrCollectionTitle = reference.getJournalOrCollectionTitle();
|
||||||
|
this.referenceType = reference.getReferenceType();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceDto() {
|
||||||
|
referenceType = ReferenceType.ARTICLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuthors() {
|
||||||
|
return authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthors(String authors) {
|
||||||
|
this.authors = authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublicationTitle() {
|
||||||
|
return publicationTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicationTitle(String publicationTitle) {
|
||||||
|
this.publicationTitle = publicationTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPublicationYear() {
|
||||||
|
return publicationYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublicationYear(Integer publicationYear) {
|
||||||
|
this.publicationYear = publicationYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublisher() {
|
||||||
|
return publisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPublisher(String publisher) {
|
||||||
|
this.publisher = publisher;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPages() {
|
||||||
|
return pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPages(String pages) {
|
||||||
|
this.pages = pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJournalOrCollectionTitle() {
|
||||||
|
return journalOrCollectionTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJournalOrCollectionTitle(String journalOrCollectionTitle) {
|
||||||
|
this.journalOrCollectionTitle = journalOrCollectionTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReferenceType getReferenceType() {
|
||||||
|
return referenceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferenceType(ReferenceType referenceType) {
|
||||||
|
this.referenceType = referenceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FormatStandard getFormatStandard() {
|
||||||
|
return formatStandard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFormatStandard(FormatStandard formatStandard) {
|
||||||
|
this.formatStandard = formatStandard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getDeleted() {
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeleted(boolean deleted) {
|
||||||
|
this.deleted = deleted;
|
||||||
|
}
|
||||||
|
}
|
@ -14,4 +14,14 @@ public interface PaperRepository extends JpaRepository<Paper, Integer> {
|
|||||||
List<Paper> filter(@Param("author") User author, @Param("year") Integer year);
|
List<Paper> filter(@Param("author") User author, @Param("year") Integer year);
|
||||||
|
|
||||||
List<Paper> findByIdNotIn(List<Integer> paperIds);
|
List<Paper> findByIdNotIn(List<Integer> paperIds);
|
||||||
|
|
||||||
|
List<Paper> findAllByIdIn(List<Integer> paperIds);
|
||||||
|
|
||||||
|
List<Paper> findByTypeAndStatus(Paper.PaperType type, Paper.PaperStatus status);
|
||||||
|
|
||||||
|
List<Paper> findByStatusNot(Paper.PaperStatus status);
|
||||||
|
|
||||||
|
List<Paper> findByConferenceIsNullAndStatusNot(Paper.PaperStatus status);
|
||||||
|
|
||||||
|
List<Paper> findByIdNotInAndConferenceIsNullAndStatusNot(List<Integer> paperIds, Paper.PaperStatus status);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package ru.ulstu.paper.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import ru.ulstu.paper.model.Reference;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ReferenceRepository extends JpaRepository<Reference, Integer> {
|
||||||
|
void deleteById(Integer id);
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT r.authors FROM Reference r")
|
||||||
|
List<String> findDistinctAuthors();
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT r.publicationTitle FROM Reference r")
|
||||||
|
List<String> findDistinctPublicationTitles();
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT r.publisher FROM Reference r")
|
||||||
|
List<String> findDistinctPublishers();
|
||||||
|
|
||||||
|
@Query("SELECT DISTINCT r.journalOrCollectionTitle FROM Reference r where r.journalOrCollectionTitle <> ''")
|
||||||
|
List<String> findDistinctJournalOrCollectionTitles();
|
||||||
|
}
|
@ -12,11 +12,11 @@ import java.nio.file.Files;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class LatexService {
|
public class LatexService {
|
||||||
private final String pdfLatexError = "Errors occurred while executing pdfLaTeX.";
|
private static final String PDF_LATEX_ERROR = "Errors occurred while executing pdfLaTeX.";
|
||||||
private final String bibtexError = "Errors occurred while executing bibtex.";
|
private static final String BIBTEX_ERROR = "Errors occurred while executing bibtex.";
|
||||||
private String errorMessage;
|
private String errorMessage;
|
||||||
private File pdfFile;
|
private File pdfFile;
|
||||||
private FileService fileService;
|
private final FileService fileService;
|
||||||
|
|
||||||
public LatexService(FileService fileService) {
|
public LatexService(FileService fileService) {
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
@ -42,8 +42,9 @@ public class LatexService {
|
|||||||
InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream());
|
InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream());
|
||||||
|
|
||||||
try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
|
try (BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
|
||||||
while ((bufferedReader.readLine()) != null) {
|
String line = bufferedReader.readLine();
|
||||||
//
|
while (line != null) {
|
||||||
|
line = bufferedReader.readLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,9 +56,9 @@ public class LatexService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean generate(String filename, File dir) throws IOException, InterruptedException {
|
private boolean generate(String filename, File dir) throws IOException, InterruptedException {
|
||||||
startProcess(new String[]{"pdflatex", filename, "--interaction=nonstopmode"}, dir, pdfLatexError);
|
startProcess(new String[]{"pdflatex", filename, "--interaction=nonstopmode"}, dir, PDF_LATEX_ERROR);
|
||||||
startProcess(new String[]{"bibtex", filename}, dir, bibtexError);
|
startProcess(new String[]{"bibtex", filename}, dir, BIBTEX_ERROR);
|
||||||
if (startProcess(new String[]{"pdflatex", filename, "--interaction=nonstopmode"}, dir, pdfLatexError) != 0) {
|
if (startProcess(new String[]{"pdflatex", filename, "--interaction=nonstopmode"}, dir, PDF_LATEX_ERROR) != 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return checkPdf(filename, dir);
|
return checkPdf(filename, dir);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package ru.ulstu.paper.service;
|
package ru.ulstu.paper.service;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.ulstu.core.util.DateUtils;
|
import ru.ulstu.core.util.DateUtils;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
@ -46,22 +45,22 @@ public class PaperNotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessageDeadline(Paper paper) {
|
private void sendMessageDeadline(Paper paper) {
|
||||||
Map<String, Object> variables = ImmutableMap.of("paper", paper);
|
Map<String, Object> variables = Map.of("paper", paper);
|
||||||
sendForAllAuhtors(variables, paper, TEMPLATE_DEADLINE, TITLE_DEADLINE);
|
sendForAllAuhtors(variables, paper, TEMPLATE_DEADLINE, TITLE_DEADLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendCreateNotification(Paper paper) {
|
public void sendCreateNotification(Paper paper) {
|
||||||
Map<String, Object> variables = ImmutableMap.of("paper", paper);
|
Map<String, Object> variables = Map.of("paper", paper);
|
||||||
sendForAllAuhtors(variables, paper, TEMPLATE_CREATE, TITLE_CREATE);
|
sendForAllAuhtors(variables, paper, TEMPLATE_CREATE, TITLE_CREATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
||||||
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
|
Map<String, Object> variables = Map.of("paper", paper, "oldStatus", oldStatus);
|
||||||
sendForAllAuhtors(variables, paper, TEMPLATE_STATUS_CHANGED, TITLE_STATUS_CHANGED);
|
sendForAllAuhtors(variables, paper, TEMPLATE_STATUS_CHANGED, TITLE_STATUS_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendFailedNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
public void sendFailedNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
||||||
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
|
Map<String, Object> variables = Map.of("paper", paper, "oldStatus", oldStatus);
|
||||||
sendForAllAuhtors(variables, paper, TEMPLATE_FAILED, TITLE_FAILED);
|
sendForAllAuhtors(variables, paper, TEMPLATE_FAILED, TITLE_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,15 +7,22 @@ import ru.ulstu.deadline.model.Deadline;
|
|||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.file.service.FileService;
|
import ru.ulstu.file.service.FileService;
|
||||||
|
import ru.ulstu.paper.model.AutoCompleteData;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
import ru.ulstu.paper.model.PaperDto;
|
||||||
import ru.ulstu.paper.model.PaperFilterDto;
|
import ru.ulstu.paper.model.PaperListDto;
|
||||||
|
import ru.ulstu.paper.model.Reference;
|
||||||
|
import ru.ulstu.paper.model.ReferenceDto;
|
||||||
import ru.ulstu.paper.repository.PaperRepository;
|
import ru.ulstu.paper.repository.PaperRepository;
|
||||||
|
import ru.ulstu.paper.repository.ReferenceRepository;
|
||||||
|
import ru.ulstu.ping.service.PingService;
|
||||||
import ru.ulstu.timeline.service.EventService;
|
import ru.ulstu.timeline.service.EventService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -32,8 +39,12 @@ import static ru.ulstu.paper.model.Paper.PaperStatus.DRAFT;
|
|||||||
import static ru.ulstu.paper.model.Paper.PaperStatus.FAILED;
|
import static ru.ulstu.paper.model.Paper.PaperStatus.FAILED;
|
||||||
import static ru.ulstu.paper.model.Paper.PaperStatus.ON_PREPARATION;
|
import static ru.ulstu.paper.model.Paper.PaperStatus.ON_PREPARATION;
|
||||||
import static ru.ulstu.paper.model.Paper.PaperType.OTHER;
|
import static ru.ulstu.paper.model.Paper.PaperType.OTHER;
|
||||||
|
import static ru.ulstu.paper.model.ReferenceDto.FormatStandard.GOST;
|
||||||
|
import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.ARTICLE;
|
||||||
|
import static ru.ulstu.paper.model.ReferenceDto.ReferenceType.BOOK;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional
|
||||||
public class PaperService {
|
public class PaperService {
|
||||||
private final static int MAX_DISPLAY_SIZE = 40;
|
private final static int MAX_DISPLAY_SIZE = 40;
|
||||||
private final static String PAPER_FORMATTED_TEMPLATE = "%s %s";
|
private final static String PAPER_FORMATTED_TEMPLATE = "%s %s";
|
||||||
@ -44,19 +55,25 @@ public class PaperService {
|
|||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
private final FileService fileService;
|
private final FileService fileService;
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
|
private final ReferenceRepository referenceRepository;
|
||||||
|
private final PingService pingService;
|
||||||
|
|
||||||
public PaperService(PaperRepository paperRepository,
|
public PaperService(PaperRepository paperRepository,
|
||||||
|
ReferenceRepository referenceRepository,
|
||||||
FileService fileService,
|
FileService fileService,
|
||||||
PaperNotificationService paperNotificationService,
|
PaperNotificationService paperNotificationService,
|
||||||
UserService userService,
|
UserService userService,
|
||||||
DeadlineService deadlineService,
|
DeadlineService deadlineService,
|
||||||
EventService eventService) {
|
EventService eventService,
|
||||||
|
PingService pingService) {
|
||||||
this.paperRepository = paperRepository;
|
this.paperRepository = paperRepository;
|
||||||
|
this.referenceRepository = referenceRepository;
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
this.paperNotificationService = paperNotificationService;
|
this.paperNotificationService = paperNotificationService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
|
this.pingService = pingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> findAll() {
|
public List<Paper> findAll() {
|
||||||
@ -64,9 +81,7 @@ public class PaperService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<PaperDto> findAllDto() {
|
public List<PaperDto> findAllDto() {
|
||||||
List<PaperDto> papers = convert(findAll(), PaperDto::new);
|
return convert(findAll(), PaperDto::new);
|
||||||
papers.forEach(paperDto -> paperDto.setTitle(StringUtils.abbreviate(paperDto.getTitle(), MAX_DISPLAY_SIZE)));
|
|
||||||
return papers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> findAllActive() {
|
public List<Paper> findAllActive() {
|
||||||
@ -76,27 +91,38 @@ public class PaperService {
|
|||||||
.collect(toList());
|
.collect(toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Paper> findAllActiveByCurrentUser() {
|
||||||
|
return findAllActive()
|
||||||
|
.stream()
|
||||||
|
.filter(paper -> paper.getAuthors().contains(userService.getCurrentUser()))
|
||||||
|
.collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
public List<PaperDto> findAllActiveDto() {
|
public List<PaperDto> findAllActiveDto() {
|
||||||
return convert(findAllActive(), PaperDto::new);
|
return convert(findAllActive(), PaperDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaperDto findOneDto(Integer id) {
|
public PaperDto findOneDto(Integer id) {
|
||||||
return new PaperDto(paperRepository.getOne(id));
|
return new PaperDto(paperRepository.findById(id).orElseThrow());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer create(PaperDto paperDto) throws IOException {
|
public Integer create(PaperDto paperDto) throws IOException {
|
||||||
Paper newPaper = copyFromDto(new Paper(), paperDto);
|
Paper newPaper = copyFromDto(new Paper(), paperDto);
|
||||||
newPaper = paperRepository.save(newPaper);
|
return create(newPaper).getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Paper create(Paper paper) {
|
||||||
|
Paper newPaper = paperRepository.save(paper);
|
||||||
|
newPaper.setCreateDate(new Date());
|
||||||
paperNotificationService.sendCreateNotification(newPaper);
|
paperNotificationService.sendCreateNotification(newPaper);
|
||||||
eventService.createFromPaper(newPaper);
|
return newPaper;
|
||||||
return newPaper.getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Paper copyFromDto(Paper paper, PaperDto paperDto) throws IOException {
|
private Paper copyFromDto(Paper paper, PaperDto paperDto) throws IOException {
|
||||||
paper.setComment(paperDto.getComment());
|
paper.setComment(paperDto.getComment());
|
||||||
paper.setUrl(paperDto.getUrl());
|
paper.setUrl(paperDto.getUrl());
|
||||||
paper.setLatexText(paperDto.getLatexText());
|
|
||||||
paper.setCreateDate(paper.getCreateDate() == null ? new Date() : paper.getCreateDate());
|
paper.setCreateDate(paper.getCreateDate() == null ? new Date() : paper.getCreateDate());
|
||||||
paper.setLocked(paperDto.getLocked());
|
paper.setLocked(paperDto.getLocked());
|
||||||
paper.setStatus(paperDto.getStatus() == null ? DRAFT : paperDto.getStatus());
|
paper.setStatus(paperDto.getStatus() == null ? DRAFT : paperDto.getStatus());
|
||||||
@ -104,6 +130,7 @@ public class PaperService {
|
|||||||
paper.setTitle(paperDto.getTitle());
|
paper.setTitle(paperDto.getTitle());
|
||||||
paper.setUpdateDate(new Date());
|
paper.setUpdateDate(new Date());
|
||||||
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
||||||
|
paper.setReferences(saveOrCreateReferences(paperDto.getReferences()));
|
||||||
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream()
|
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream()
|
||||||
.filter(f -> !f.isDeleted())
|
.filter(f -> !f.isDeleted())
|
||||||
.collect(toList())));
|
.collect(toList())));
|
||||||
@ -114,6 +141,41 @@ public class PaperService {
|
|||||||
return paper;
|
return paper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Reference> saveOrCreateReferences(List<ReferenceDto> references) {
|
||||||
|
return references
|
||||||
|
.stream()
|
||||||
|
.filter(reference -> !reference.getDeleted())
|
||||||
|
.map(reference -> reference.getId() != null ? updateReference(reference) : createReference(reference))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
private Reference updateReference(ReferenceDto referenceDto) {
|
||||||
|
Reference updateReference = referenceRepository.getOne(referenceDto.getId());
|
||||||
|
copyFromDto(updateReference, referenceDto);
|
||||||
|
referenceRepository.save(updateReference);
|
||||||
|
return updateReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
private Reference createReference(ReferenceDto referenceDto) {
|
||||||
|
Reference newReference = new Reference();
|
||||||
|
copyFromDto(newReference, referenceDto);
|
||||||
|
newReference = referenceRepository.save(newReference);
|
||||||
|
return newReference;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Reference copyFromDto(Reference reference, ReferenceDto referenceDto) {
|
||||||
|
reference.setAuthors(referenceDto.getAuthors());
|
||||||
|
reference.setJournalOrCollectionTitle(referenceDto.getJournalOrCollectionTitle());
|
||||||
|
reference.setPages(referenceDto.getPages());
|
||||||
|
reference.setPublicationTitle(referenceDto.getPublicationTitle());
|
||||||
|
reference.setPublicationYear(referenceDto.getPublicationYear());
|
||||||
|
reference.setPublisher(referenceDto.getPublisher());
|
||||||
|
reference.setReferenceType(referenceDto.getReferenceType());
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Integer update(PaperDto paperDto) throws IOException {
|
public Integer update(PaperDto paperDto) throws IOException {
|
||||||
Paper paper = paperRepository.getOne(paperDto.getId());
|
Paper paper = paperRepository.getOne(paperDto.getId());
|
||||||
@ -126,6 +188,11 @@ public class PaperService {
|
|||||||
fileService.delete(file.getId());
|
fileService.delete(file.getId());
|
||||||
}
|
}
|
||||||
paperRepository.save(copyFromDto(paper, paperDto));
|
paperRepository.save(copyFromDto(paper, paperDto));
|
||||||
|
for (ReferenceDto referenceDto : paperDto.getReferences().stream()
|
||||||
|
.filter(f -> f.getDeleted() && f.getId() != null)
|
||||||
|
.collect(toList())) {
|
||||||
|
referenceRepository.deleteById(referenceDto.getId());
|
||||||
|
}
|
||||||
eventService.updatePaperDeadlines(paper);
|
eventService.updatePaperDeadlines(paper);
|
||||||
|
|
||||||
paper.getAuthors().forEach(author -> {
|
paper.getAuthors().forEach(author -> {
|
||||||
@ -142,9 +209,28 @@ public class PaperService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer paperId) throws IOException {
|
public Integer update(Paper newPaper) {
|
||||||
Paper paper = paperRepository.getOne(paperId);
|
Paper oldPaper = paperRepository.getOne(newPaper.getId());
|
||||||
paperRepository.delete(paper);
|
Paper.PaperStatus oldStatus = oldPaper.getStatus();
|
||||||
|
Set<User> oldAuthors = new HashSet<>(oldPaper.getAuthors());
|
||||||
|
newPaper.setUpdateDate(new Date());
|
||||||
|
newPaper = paperRepository.save(newPaper);
|
||||||
|
for (User author : newPaper.getAuthors()) {
|
||||||
|
if (!oldAuthors.contains(author)) {
|
||||||
|
paperNotificationService.sendCreateNotification(newPaper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPaper.getStatus() != oldStatus) {
|
||||||
|
paperNotificationService.statusChangeNotification(newPaper, oldStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newPaper.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void delete(Integer paperId) {
|
||||||
|
delete(paperRepository.getOne(paperId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper.PaperStatus> getPaperStatuses() {
|
public List<Paper.PaperStatus> getPaperStatuses() {
|
||||||
@ -155,6 +241,14 @@ public class PaperService {
|
|||||||
return Arrays.asList(Paper.PaperType.values());
|
return Arrays.asList(Paper.PaperType.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<ReferenceDto.FormatStandard> getFormatStandards() {
|
||||||
|
return Arrays.asList(ReferenceDto.FormatStandard.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ReferenceDto.ReferenceType> getReferenceTypes() {
|
||||||
|
return Arrays.asList(ReferenceDto.ReferenceType.values());
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Paper create(String title, User user, Date deadlineDate) {
|
public Paper create(String title, User user, Date deadlineDate) {
|
||||||
Paper paper = new Paper();
|
Paper paper = new Paper();
|
||||||
@ -173,7 +267,7 @@ public class PaperService {
|
|||||||
return paper;
|
return paper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaperDto> filter(PaperFilterDto filterDto) {
|
public List<PaperDto> filter(PaperListDto filterDto) {
|
||||||
return convert(sortPapers(paperRepository.filter(
|
return convert(sortPapers(paperRepository.filter(
|
||||||
filterDto.getFilterAuthorId() == null ? null : userService.findById(filterDto.getFilterAuthorId()),
|
filterDto.getFilterAuthorId() == null ? null : userService.findById(filterDto.getFilterAuthorId()),
|
||||||
filterDto.getYear())), PaperDto::new);
|
filterDto.getYear())), PaperDto::new);
|
||||||
@ -219,21 +313,36 @@ public class PaperService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void save(Paper paper) {
|
||||||
|
if (isEmpty(paper.getId())) {
|
||||||
|
create(paper);
|
||||||
|
} else {
|
||||||
|
update(paper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public PaperDto findById(Integer paperId) {
|
public PaperDto findById(Integer paperId) {
|
||||||
return new PaperDto(paperRepository.getOne(paperId));
|
return new PaperDto(paperRepository.getOne(paperId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Paper findEntityById(Integer paperId) {
|
public Paper findPaperById(Integer paperId) {
|
||||||
return paperRepository.getOne(paperId);
|
return paperRepository.getOne(paperId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> findAllNotSelect(List<Integer> paperIds) {
|
public List<Paper> findAllNotSelect(List<Integer> paperIds) {
|
||||||
if (!paperIds.isEmpty()) {
|
if (!paperIds.isEmpty()) {
|
||||||
return sortPapers(paperRepository.findByIdNotIn(paperIds));
|
return sortPapers(paperRepository.findByIdNotInAndConferenceIsNullAndStatusNot(paperIds, COMPLETED));
|
||||||
} else {
|
} else {
|
||||||
return sortPapers(paperRepository.findAll());
|
return sortPapers(paperRepository.findByConferenceIsNullAndStatusNot(COMPLETED));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<PaperDto> findAllNotCompleted() {
|
||||||
|
return convert(paperRepository.findByStatusNot(COMPLETED), PaperDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PaperDto> findAllSelect(List<Integer> paperIds) {
|
||||||
|
return convert(paperRepository.findAllByIdIn(paperIds), PaperDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<User> getPaperAuthors() {
|
public List<User> getPaperAuthors() {
|
||||||
@ -260,4 +369,77 @@ public class PaperService {
|
|||||||
.map(User::getUserAbbreviate)
|
.map(User::getUserAbbreviate)
|
||||||
.collect(Collectors.joining(", "));
|
.collect(Collectors.joining(", "));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getFormattedReference(ReferenceDto referenceDto) {
|
||||||
|
return referenceDto.getFormatStandard() == GOST
|
||||||
|
? getGostReference(referenceDto)
|
||||||
|
: getSpringerReference(referenceDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFormattedReferences(PaperDto paperDto) {
|
||||||
|
return String.join("\r\n", paperDto.getReferences()
|
||||||
|
.stream()
|
||||||
|
.filter(r -> !r.getDeleted())
|
||||||
|
.map(r -> {
|
||||||
|
r.setFormatStandard(paperDto.getFormatStandard());
|
||||||
|
return getFormattedReference(r);
|
||||||
|
})
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getGostReference(ReferenceDto referenceDto) {
|
||||||
|
return MessageFormat.format(referenceDto.getReferenceType() == BOOK ? "{0} {1} - {2}{3}. - {4}с." : "{0} {1}{5} {2}{3}. С. {4}.",
|
||||||
|
referenceDto.getAuthors(),
|
||||||
|
referenceDto.getPublicationTitle(),
|
||||||
|
StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ",
|
||||||
|
referenceDto.getPublicationYear() != null ? referenceDto.getPublicationYear().toString() : "",
|
||||||
|
referenceDto.getPages(),
|
||||||
|
StringUtils.isEmpty(referenceDto.getJournalOrCollectionTitle()) ? "." : " // " + referenceDto.getJournalOrCollectionTitle() + ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSpringerReference(ReferenceDto referenceDto) {
|
||||||
|
return MessageFormat.format("{0} ({1}) {2}.{3} {4}pp {5}",
|
||||||
|
referenceDto.getAuthors(),
|
||||||
|
referenceDto.getPublicationYear() != null ? referenceDto.getPublicationYear().toString() : "",
|
||||||
|
referenceDto.getPublicationTitle(),
|
||||||
|
referenceDto.getReferenceType() == ARTICLE ? " " + referenceDto.getJournalOrCollectionTitle() + "," : "",
|
||||||
|
StringUtils.isEmpty(referenceDto.getPublisher()) ? "" : referenceDto.getPublisher() + ", ",
|
||||||
|
referenceDto.getPages());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Paper> findAllCompletedByType(Paper.PaperType type) {
|
||||||
|
return paperRepository.findByTypeAndStatus(type, Paper.PaperStatus.COMPLETED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutoCompleteData getAutoCompleteData() {
|
||||||
|
AutoCompleteData autoCompleteData = new AutoCompleteData();
|
||||||
|
autoCompleteData.setAuthors(referenceRepository.findDistinctAuthors());
|
||||||
|
autoCompleteData.setJournalOrCollectionTitles(referenceRepository.findDistinctJournalOrCollectionTitles());
|
||||||
|
autoCompleteData.setPublicationTitles(referenceRepository.findDistinctPublicationTitles());
|
||||||
|
autoCompleteData.setPublishers(referenceRepository.findDistinctPublishers());
|
||||||
|
return autoCompleteData;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void ping(int paperId) throws IOException {
|
||||||
|
pingService.addPing(findPaperById(paperId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createByTitle(String newPaperTitle) {
|
||||||
|
Paper paper = new Paper();
|
||||||
|
paper.setTitle(newPaperTitle);
|
||||||
|
paper.setStatus(DRAFT);
|
||||||
|
paper.getAuthors().add(userService.getCurrentUser());
|
||||||
|
paper.getDeadlines().add(deadlineService.createWithOffset(new Date(), 1, ChronoUnit.WEEKS));
|
||||||
|
create(paper);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(List<Paper> papers) {
|
||||||
|
papers.forEach(paper -> delete(paper));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(Paper paper) {
|
||||||
|
deadlineService.delete(paper.getDeadlines());
|
||||||
|
paperRepository.delete(paper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
82
src/main/java/ru/ulstu/ping/model/Ping.java
Normal file
82
src/main/java/ru/ulstu/ping/model/Ping.java
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
package ru.ulstu.ping.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.DiscriminatorType;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.persistence.Temporal;
|
||||||
|
import jakarta.persistence.TemporalType;
|
||||||
|
import org.hibernate.annotations.Any;
|
||||||
|
import org.hibernate.annotations.AnyDiscriminator;
|
||||||
|
import org.hibernate.annotations.AnyDiscriminatorValue;
|
||||||
|
import org.hibernate.annotations.AnyKeyJavaClass;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
import ru.ulstu.core.model.UserActivity;
|
||||||
|
import ru.ulstu.grant.model.Grant;
|
||||||
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
import ru.ulstu.project.model.Project;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "ping")
|
||||||
|
public class Ping extends BaseEntity {
|
||||||
|
@Temporal(value = TemporalType.TIMESTAMP)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
|
private Date date;
|
||||||
|
|
||||||
|
@ManyToOne(optional = false)
|
||||||
|
@JoinColumn(name = "users_id")
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
@Column(name = "activity_type", insertable = false, updatable = false)
|
||||||
|
private String activityType;
|
||||||
|
|
||||||
|
@Any
|
||||||
|
@AnyDiscriminator(DiscriminatorType.STRING)
|
||||||
|
@AnyKeyJavaClass(Integer.class)
|
||||||
|
@JoinColumn(name = "activity_id")
|
||||||
|
@Column(name = "activity_type")
|
||||||
|
@AnyDiscriminatorValue(entity = Conference.class, discriminator = "CONFERENCE")
|
||||||
|
@AnyDiscriminatorValue(entity = Paper.class, discriminator = "PAPER")
|
||||||
|
@AnyDiscriminatorValue(entity = Project.class, discriminator = "PROJECT")
|
||||||
|
@AnyDiscriminatorValue(entity = Grant.class, discriminator = "GRANT")
|
||||||
|
private UserActivity activity;
|
||||||
|
|
||||||
|
public Ping() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ping(Date date, User user) {
|
||||||
|
this.date = date;
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserActivity getActivity() {
|
||||||
|
return this.activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivity(UserActivity activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
}
|
35
src/main/java/ru/ulstu/ping/model/PingInfo.java
Normal file
35
src/main/java/ru/ulstu/ping/model/PingInfo.java
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
package ru.ulstu.ping.model;
|
||||||
|
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PingInfo {
|
||||||
|
private User user;
|
||||||
|
private List<Ping> pings = new ArrayList<>();
|
||||||
|
|
||||||
|
public PingInfo(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Ping> getPings() {
|
||||||
|
return pings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPings(List<Ping> pings) {
|
||||||
|
this.pings = pings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPing(Ping ping) {
|
||||||
|
this.pings.add(ping);
|
||||||
|
}
|
||||||
|
}
|
22
src/main/java/ru/ulstu/ping/repository/PingRepository.java
Normal file
22
src/main/java/ru/ulstu/ping/repository/PingRepository.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package ru.ulstu.ping.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
|
import ru.ulstu.ping.model.Ping;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface PingRepository extends JpaRepository<Ping, Integer> {
|
||||||
|
|
||||||
|
@Query("SELECT count(*) FROM Ping p WHERE (DAY(p.date) = :day) AND (MONTH(p.date) = :month) AND (YEAR(p.date) = :year) AND (p.activityType = 'conference') AND (p.activity = :conference)")
|
||||||
|
long countByConferenceAndDate(@Param("conference") Conference conference, @Param("day") Integer day, @Param("month") Integer month, @Param("year") Integer year);
|
||||||
|
|
||||||
|
@Query("SELECT p FROM Ping p WHERE (:activity = '' OR p.activityType = :activity)")
|
||||||
|
List<Ping> getPings(@Param("activity") String activity);
|
||||||
|
|
||||||
|
@Query("SELECT p FROM Ping p WHERE (:dateFrom < date)")
|
||||||
|
List<Ping> findByDate(@Param("dateFrom") Date dateFrom);
|
||||||
|
}
|
58
src/main/java/ru/ulstu/ping/service/PingScheduler.java
Normal file
58
src/main/java/ru/ulstu/ping/service/PingScheduler.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package ru.ulstu.ping.service;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.core.model.UserActivity;
|
||||||
|
import ru.ulstu.ping.model.Ping;
|
||||||
|
import ru.ulstu.ping.model.PingInfo;
|
||||||
|
import ru.ulstu.ping.repository.PingRepository;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PingScheduler {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(PingScheduler.class);
|
||||||
|
private final PingRepository pingRepository;
|
||||||
|
private final MailService mailService;
|
||||||
|
private final static String PING_MAIL_SUBJECT = "Ping статистика";
|
||||||
|
|
||||||
|
public PingScheduler(PingRepository pingRepository, MailService mailService) {
|
||||||
|
this.pingRepository = pingRepository;
|
||||||
|
this.mailService = mailService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 * * 1 ?")
|
||||||
|
public void sendPingsInfo() {
|
||||||
|
log.debug("Scheduler.sendPingsInfo started");
|
||||||
|
|
||||||
|
List<PingInfo> pingInfos = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Ping ping : pingRepository.findByDate(java.sql.Date.valueOf(LocalDate.now().minusWeeks(1)))) {
|
||||||
|
UserActivity pingActivity = ping.getActivity();
|
||||||
|
Set<User> users = pingActivity.getActivityUsers();
|
||||||
|
|
||||||
|
for (User user : users) {
|
||||||
|
PingInfo userPing = pingInfos.stream().filter(u -> u.getUser() == user).findFirst().orElse(null);
|
||||||
|
if (userPing == null) {
|
||||||
|
userPing = new PingInfo(user);
|
||||||
|
pingInfos.add(userPing);
|
||||||
|
}
|
||||||
|
userPing.addPing(ping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PingInfo pingInfo : pingInfos) {
|
||||||
|
mailService.sendEmailFromTemplate(Map.of("pings", pingInfo.getPings()),
|
||||||
|
pingInfo.getUser(), "pingsInfoWeekEmail", PING_MAIL_SUBJECT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
src/main/java/ru/ulstu/ping/service/PingService.java
Normal file
43
src/main/java/ru/ulstu/ping/service/PingService.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package ru.ulstu.ping.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.conference.model.Conference;
|
||||||
|
import ru.ulstu.core.model.UserActivity;
|
||||||
|
import ru.ulstu.ping.model.Ping;
|
||||||
|
import ru.ulstu.ping.repository.PingRepository;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PingService {
|
||||||
|
private final PingRepository pingRepository;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
public PingService(PingRepository pingRepository,
|
||||||
|
UserService userService,
|
||||||
|
PingScheduler pingScheduler) {
|
||||||
|
this.pingRepository = pingRepository;
|
||||||
|
this.userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Ping addPing(UserActivity activity) throws IOException {
|
||||||
|
Ping newPing = new Ping(new Date(), userService.getCurrentUser());
|
||||||
|
//newPing.setActivity(activity);
|
||||||
|
return pingRepository.save(newPing);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer countPingYesterday(Conference conference, Calendar calendar) {
|
||||||
|
return Math.toIntExact(pingRepository.countByConferenceAndDate(conference, calendar.get(Calendar.DAY_OF_MONTH),
|
||||||
|
calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.YEAR)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Ping> getPings(String activity) {
|
||||||
|
return pingRepository.getPings(activity);
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +1,24 @@
|
|||||||
package ru.ulstu.project.controller;
|
package ru.ulstu.project.controller;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Hidden;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.project.model.Project;
|
||||||
import ru.ulstu.project.model.ProjectDto;
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
import ru.ulstu.project.service.ProjectService;
|
import ru.ulstu.project.service.ProjectService;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -23,7 +27,7 @@ import static org.springframework.util.StringUtils.isEmpty;
|
|||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@RequestMapping(value = "/projects")
|
@RequestMapping(value = "/projects")
|
||||||
@ApiIgnore
|
@Hidden
|
||||||
public class ProjectController {
|
public class ProjectController {
|
||||||
private final ProjectService projectService;
|
private final ProjectService projectService;
|
||||||
|
|
||||||
@ -44,6 +48,8 @@ public class ProjectController {
|
|||||||
@GetMapping("/project")
|
@GetMapping("/project")
|
||||||
public void getProject(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
public void getProject(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
||||||
if (id != null && id > 0) {
|
if (id != null && id > 0) {
|
||||||
|
ProjectDto projectDto = projectService.findOneDto(id);
|
||||||
|
attachGrant(projectDto);
|
||||||
modelMap.put("projectDto", projectService.findOneDto(id));
|
modelMap.put("projectDto", projectService.findOneDto(id));
|
||||||
} else {
|
} else {
|
||||||
modelMap.put("projectDto", new ProjectDto());
|
modelMap.put("projectDto", new ProjectDto());
|
||||||
@ -68,6 +74,12 @@ public class ProjectController {
|
|||||||
return String.format("redirect:%s", "/projects/projects");
|
return String.format("redirect:%s", "/projects/projects");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/project", params = "attachGrant")
|
||||||
|
public String attachGrant(ProjectDto projectDto) {
|
||||||
|
projectService.attachGrant(projectDto);
|
||||||
|
return "/projects/project";
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/project", params = "addDeadline")
|
@PostMapping(value = "/project", params = "addDeadline")
|
||||||
public String addDeadline(@Valid ProjectDto projectDto, Errors errors) {
|
public String addDeadline(@Valid ProjectDto projectDto, Errors errors) {
|
||||||
filterEmptyDeadlines(projectDto);
|
filterEmptyDeadlines(projectDto);
|
||||||
@ -78,9 +90,38 @@ public class ProjectController {
|
|||||||
return "/projects/project";
|
return "/projects/project";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/project", params = "removeDeadline")
|
||||||
|
public String removeDeadline(ProjectDto projectDto,
|
||||||
|
@RequestParam(value = "removeDeadline") Integer deadlineId) {
|
||||||
|
projectService.removeDeadline(projectDto, deadlineId);
|
||||||
|
return "/projects/project";
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/delete/{project-id}")
|
||||||
|
public String delete(@PathVariable("project-id") Integer projectId) throws IOException {
|
||||||
|
projectService.delete(projectId);
|
||||||
|
return String.format("redirect:%s", "/projects/projects");
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("allExecutors")
|
||||||
|
public List<User> getAllExecutors(ProjectDto projectDto) {
|
||||||
|
return projectService.getProjectExecutors(projectDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("allGrants")
|
||||||
|
public List<GrantDto> getAllGrants() {
|
||||||
|
return projectService.getAllGrants();
|
||||||
|
}
|
||||||
|
|
||||||
private void filterEmptyDeadlines(ProjectDto projectDto) {
|
private void filterEmptyDeadlines(ProjectDto projectDto) {
|
||||||
projectDto.setDeadlines(projectDto.getDeadlines().stream()
|
projectDto.setDeadlines(projectDto.getDeadlines().stream()
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@PostMapping(value = "/ping")
|
||||||
|
public void ping(@RequestParam("projectId") int projectId) throws IOException {
|
||||||
|
projectService.ping(projectId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,48 @@
|
|||||||
package ru.ulstu.project.model;
|
package ru.ulstu.project.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.CascadeType;
|
||||||
|
import jakarta.persistence.DiscriminatorValue;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.JoinTable;
|
||||||
|
import jakarta.persistence.ManyToMany;
|
||||||
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.OneToMany;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import org.hibernate.annotations.Fetch;
|
||||||
|
import org.hibernate.annotations.FetchMode;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
import ru.ulstu.core.model.EventSource;
|
||||||
|
import ru.ulstu.core.model.UserActivity;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.file.model.FileData;
|
import ru.ulstu.file.model.FileData;
|
||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.grant.model.Grant;
|
||||||
|
import ru.ulstu.timeline.model.Event;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EnumType;
|
|
||||||
import javax.persistence.Enumerated;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.persistence.OneToMany;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Project extends BaseEntity {
|
@DiscriminatorValue("PROJECT")
|
||||||
|
public class Project extends BaseEntity implements UserActivity, EventSource {
|
||||||
|
|
||||||
public enum ProjectStatus {
|
public enum ProjectStatus {
|
||||||
APPLICATION("Заявка"),
|
TECHNICAL_TASK("Техническое задание"),
|
||||||
ON_COMPETITION("Отправлен на конкурс"),
|
OPEN("Открыт"),
|
||||||
SUCCESSFUL_PASSAGE("Успешное прохождение"),
|
|
||||||
IN_WORK("В работе"),
|
IN_WORK("В работе"),
|
||||||
COMPLETED("Завершен"),
|
CERTIFICATE_ISSUED("Оформление свидетельства"),
|
||||||
|
CLOSED("Закрыт"),
|
||||||
FAILED("Провалены сроки");
|
FAILED("Провалены сроки");
|
||||||
|
|
||||||
private String statusName;
|
private final String statusName;
|
||||||
|
|
||||||
ProjectStatus(String statusName) {
|
ProjectStatus(String statusName) {
|
||||||
this.statusName = statusName;
|
this.statusName = statusName;
|
||||||
@ -42,7 +57,7 @@ public class Project extends BaseEntity {
|
|||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
private ProjectStatus status = ProjectStatus.APPLICATION;
|
private ProjectStatus status = ProjectStatus.TECHNICAL_TASK;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String description;
|
private String description;
|
||||||
@ -58,14 +73,39 @@ public class Project extends BaseEntity {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private String repository;
|
private String repository;
|
||||||
|
|
||||||
@ManyToOne
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "file_id")
|
@JoinColumn(name = "project_id", unique = true)
|
||||||
private FileData application;
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
|
private List<FileData> files = new ArrayList<>();
|
||||||
|
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
|
@JoinColumn(name = "project_id")
|
||||||
|
private List<Event> events = new ArrayList<>();
|
||||||
|
|
||||||
|
@ManyToMany(fetch = FetchType.LAZY)
|
||||||
|
private List<User> executors = new ArrayList<>();
|
||||||
|
|
||||||
|
@ManyToMany(fetch = FetchType.LAZY)
|
||||||
|
@JoinTable(name = "project_grants",
|
||||||
|
joinColumns = {@JoinColumn(name = "project_id")},
|
||||||
|
inverseJoinColumns = {@JoinColumn(name = "grants_id")})
|
||||||
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
|
private List<Grant> grants = new ArrayList<>();
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<User> getRecipients() {
|
||||||
|
return executors != null ? new ArrayList<>(executors) : Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addObjectToEvent(Event event) {
|
||||||
|
event.setProject(this);
|
||||||
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
@ -110,11 +150,44 @@ public class Project extends BaseEntity {
|
|||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileData getApplication() {
|
public List<FileData> getFiles() {
|
||||||
return application;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setApplication(FileData application) {
|
public void setFiles(List<FileData> files) {
|
||||||
this.application = application;
|
this.files = files;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Event> getEvents() {
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEvents(List<Event> events) {
|
||||||
|
this.events = events;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<User> getExecutors() {
|
||||||
|
return executors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExecutors(List<User> executors) {
|
||||||
|
this.executors = executors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<User> getUsers() {
|
||||||
|
return new HashSet<>(getExecutors());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<User> getActivityUsers() {
|
||||||
|
return new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Grant> getGrants() {
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGrants(List<Grant> grants) {
|
||||||
|
this.grants = grants;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,21 @@ package ru.ulstu.project.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import org.thymeleaf.util.StringUtils;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.grant.model.GrantDto;
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.model.UserDto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class ProjectDto {
|
public class ProjectDto {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
@ -19,7 +28,14 @@ public class ProjectDto {
|
|||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<Deadline> deadlines = new ArrayList<>();
|
||||||
private GrantDto grant;
|
private GrantDto grant;
|
||||||
private String repository;
|
private String repository;
|
||||||
private String applicationFileName;
|
private List<FileDataDto> files = new ArrayList<>();
|
||||||
|
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
||||||
|
private Set<Integer> executorIds;
|
||||||
|
private List<UserDto> executors;
|
||||||
|
private List<Integer> grantIds;
|
||||||
|
private List<GrantDto> grants;
|
||||||
|
|
||||||
|
private final static int MAX_EXECUTORS_LENGTH = 40;
|
||||||
|
|
||||||
public ProjectDto() {
|
public ProjectDto() {
|
||||||
}
|
}
|
||||||
@ -35,7 +51,12 @@ public class ProjectDto {
|
|||||||
@JsonProperty("description") String description,
|
@JsonProperty("description") String description,
|
||||||
@JsonProperty("grant") GrantDto grant,
|
@JsonProperty("grant") GrantDto grant,
|
||||||
@JsonProperty("repository") String repository,
|
@JsonProperty("repository") String repository,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines) {
|
@JsonProperty("files") List<FileDataDto> files,
|
||||||
|
@JsonProperty("deadlines") List<Deadline> deadlines,
|
||||||
|
@JsonProperty("executorIds") Set<Integer> executorIds,
|
||||||
|
@JsonProperty("executors") List<UserDto> executors,
|
||||||
|
@JsonProperty("grantIds") List<Integer> grantIds,
|
||||||
|
@JsonProperty("grants") List<GrantDto> grants) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
@ -43,19 +64,28 @@ public class ProjectDto {
|
|||||||
this.grant = grant;
|
this.grant = grant;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
this.applicationFileName = null;
|
this.files = files;
|
||||||
|
this.executorIds = executorIds;
|
||||||
|
this.executors = executors;
|
||||||
|
this.grantIds = grantIds;
|
||||||
|
this.grants = grants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ProjectDto(Project project) {
|
public ProjectDto(Project project) {
|
||||||
|
Set<User> users = new HashSet<User>(project.getExecutors());
|
||||||
this.id = project.getId();
|
this.id = project.getId();
|
||||||
this.title = project.getTitle();
|
this.title = project.getTitle();
|
||||||
this.status = project.getStatus();
|
this.status = project.getStatus();
|
||||||
this.description = project.getDescription();
|
this.description = project.getDescription();
|
||||||
this.applicationFileName = project.getApplication() == null ? null : project.getApplication().getName();
|
this.files = convert(project.getFiles(), FileDataDto::new);
|
||||||
this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant());
|
this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant());
|
||||||
this.repository = project.getRepository();
|
this.repository = project.getRepository();
|
||||||
this.deadlines = project.getDeadlines();
|
this.deadlines = project.getDeadlines();
|
||||||
|
this.executorIds = convert(users, user -> user.getId());
|
||||||
|
this.executors = convert(project.getExecutors(), UserDto::new);
|
||||||
|
this.grantIds = convert(project.getGrants(), grant -> grant.getId());
|
||||||
|
this.grants = convert(project.getGrants(), GrantDto::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -114,11 +144,58 @@ public class ProjectDto {
|
|||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getApplicationFileName() {
|
public List<FileDataDto> getFiles() {
|
||||||
return applicationFileName;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setApplicationFileName(String applicationFileName) {
|
public void setFiles(List<FileDataDto> files) {
|
||||||
this.applicationFileName = applicationFileName;
|
this.files = files;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getRemovedDeadlineIds() {
|
||||||
|
return removedDeadlineIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
|
||||||
|
this.removedDeadlineIds = removedDeadlineIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Integer> getExecutorIds() {
|
||||||
|
return executorIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExecutorIds(Set<Integer> executorIds) {
|
||||||
|
this.executorIds = executorIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UserDto> getExecutors() {
|
||||||
|
return executors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExecutors(List<UserDto> executors) {
|
||||||
|
this.executors = executors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExecutorsString() {
|
||||||
|
return StringUtils.abbreviate(executors
|
||||||
|
.stream()
|
||||||
|
.map(executor -> executor.getLastName())
|
||||||
|
.collect(Collectors.joining(", ")), MAX_EXECUTORS_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getGrantIds() {
|
||||||
|
return grantIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGrantIds(List<Integer> grantIds) {
|
||||||
|
this.grantIds = grantIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GrantDto> getGrants() {
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGrants(List<GrantDto> grants) {
|
||||||
|
this.grants = grants;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,19 +4,27 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.thymeleaf.util.StringUtils;
|
import org.thymeleaf.util.StringUtils;
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.file.service.FileService;
|
import ru.ulstu.file.service.FileService;
|
||||||
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
import ru.ulstu.grant.repository.GrantRepository;
|
import ru.ulstu.grant.repository.GrantRepository;
|
||||||
|
import ru.ulstu.ping.service.PingService;
|
||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.project.model.Project;
|
||||||
import ru.ulstu.project.model.ProjectDto;
|
import ru.ulstu.project.model.ProjectDto;
|
||||||
import ru.ulstu.project.repository.ProjectRepository;
|
import ru.ulstu.project.repository.ProjectRepository;
|
||||||
|
import ru.ulstu.timeline.service.EventService;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
import static ru.ulstu.project.model.Project.ProjectStatus.APPLICATION;
|
import static ru.ulstu.project.model.Project.ProjectStatus.TECHNICAL_TASK;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ProjectService {
|
public class ProjectService {
|
||||||
@ -26,15 +34,24 @@ public class ProjectService {
|
|||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
private final GrantRepository grantRepository;
|
private final GrantRepository grantRepository;
|
||||||
private final FileService fileService;
|
private final FileService fileService;
|
||||||
|
private final EventService eventService;
|
||||||
|
private final UserService userService;
|
||||||
|
private final PingService pingService;
|
||||||
|
|
||||||
public ProjectService(ProjectRepository projectRepository,
|
public ProjectService(ProjectRepository projectRepository,
|
||||||
DeadlineService deadlineService,
|
DeadlineService deadlineService,
|
||||||
GrantRepository grantRepository,
|
GrantRepository grantRepository,
|
||||||
FileService fileService) {
|
FileService fileService,
|
||||||
|
EventService eventService,
|
||||||
|
UserService userService,
|
||||||
|
PingService pingService) {
|
||||||
this.projectRepository = projectRepository;
|
this.projectRepository = projectRepository;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.grantRepository = grantRepository;
|
this.grantRepository = grantRepository;
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
|
this.eventService = eventService;
|
||||||
|
this.userService = userService;
|
||||||
|
this.pingService = pingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Project> findAll() {
|
public List<Project> findAll() {
|
||||||
@ -59,20 +76,48 @@ public class ProjectService {
|
|||||||
public Project create(ProjectDto projectDto) throws IOException {
|
public Project create(ProjectDto projectDto) throws IOException {
|
||||||
Project newProject = copyFromDto(new Project(), projectDto);
|
Project newProject = copyFromDto(new Project(), projectDto);
|
||||||
newProject = projectRepository.save(newProject);
|
newProject = projectRepository.save(newProject);
|
||||||
|
eventService.createFromObject(newProject, Collections.emptyList(), false, "проекта");
|
||||||
return newProject;
|
return newProject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
private Project update(ProjectDto projectDto) throws IOException {
|
||||||
|
Project project = projectRepository.getOne(projectDto.getId());
|
||||||
|
projectRepository.save(copyFromDto(project, projectDto));
|
||||||
|
eventService.updateProjectDeadlines(project);
|
||||||
|
for (FileDataDto file : projectDto.getFiles().stream()
|
||||||
|
.filter(f -> f.isDeleted() && f.getId() != null)
|
||||||
|
.collect(toList())) {
|
||||||
|
fileService.delete(file.getId());
|
||||||
|
}
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public boolean delete(Integer projectId) throws IOException {
|
||||||
|
if (projectRepository.existsById(projectId)) {
|
||||||
|
Project project = projectRepository.getOne(projectId);
|
||||||
|
projectRepository.delete(project);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException {
|
private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException {
|
||||||
project.setDescription(projectDto.getDescription());
|
project.setDescription(projectDto.getDescription());
|
||||||
project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus());
|
project.setStatus(projectDto.getStatus() == null ? TECHNICAL_TASK : projectDto.getStatus());
|
||||||
project.setTitle(projectDto.getTitle());
|
project.setTitle(projectDto.getTitle());
|
||||||
if (projectDto.getGrant() != null && projectDto.getGrant().getId() != null) {
|
if (projectDto.getGrant() != null && projectDto.getGrant().getId() != null) {
|
||||||
project.setGrant(grantRepository.getOne(projectDto.getGrant().getId()));
|
project.setGrant(grantRepository.getOne(projectDto.getGrant().getId()));
|
||||||
}
|
}
|
||||||
project.setRepository(projectDto.getRepository());
|
project.setRepository(projectDto.getRepository());
|
||||||
project.setDeadlines(deadlineService.saveOrCreate(projectDto.getDeadlines()));
|
project.setDeadlines(deadlineService.saveOrCreate(projectDto.getDeadlines()));
|
||||||
if (projectDto.getApplicationFileName() != null) {
|
project.setFiles(fileService.saveOrCreate(projectDto.getFiles().stream()
|
||||||
project.setApplication(fileService.createFileFromTmp(projectDto.getApplicationFileName()));
|
.filter(f -> !f.isDeleted())
|
||||||
|
.collect(toList())));
|
||||||
|
project.getGrants().clear();
|
||||||
|
if (projectDto.getGrantIds() != null && !projectDto.getGrantIds().isEmpty()) {
|
||||||
|
projectDto.getGrantIds().forEach(grantIds -> project.getGrants().add(grantRepository.findGrantById(grantIds)));
|
||||||
}
|
}
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
@ -85,12 +130,42 @@ public class ProjectService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Project update(ProjectDto projectDto) {
|
public ProjectDto removeDeadline(ProjectDto projectDto, Integer deadlineId) {
|
||||||
throw new RuntimeException("not implemented yet");
|
if (deadlineId != null) {
|
||||||
|
projectDto.getRemovedDeadlineIds().add(deadlineId);
|
||||||
|
}
|
||||||
|
projectDto.getDeadlines().remove((int) deadlineId);
|
||||||
|
return projectDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Project findById(Integer id) {
|
public Project findById(Integer id) {
|
||||||
return projectRepository.getOne(id);
|
return projectRepository.getOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<User> getProjectExecutors(ProjectDto projectDto) {
|
||||||
|
return userService.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void ping(int projectId) throws IOException {
|
||||||
|
pingService.addPing(findById(projectId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GrantDto> getAllGrants() {
|
||||||
|
return convert(grantRepository.findAll(), GrantDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<GrantDto> getProjectGrants(List<Integer> grantIds) {
|
||||||
|
return convert(grantRepository.findAllById(grantIds), GrantDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void attachGrant(ProjectDto projectDto) {
|
||||||
|
if (!projectDto.getGrantIds().isEmpty()) {
|
||||||
|
projectDto.getGrants().clear();
|
||||||
|
projectDto.setGrants(getProjectGrants(projectDto.getGrantIds()));
|
||||||
|
} else {
|
||||||
|
projectDto.getGrants().clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
package ru.ulstu.strategy.api;
|
package ru.ulstu.strategy.api;
|
||||||
|
|
||||||
import ru.ulstu.core.model.UserContainer;
|
import ru.ulstu.core.model.UserActivity;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public abstract class EntityCreateStrategy<T extends UserContainer> {
|
public abstract class EntityCreateStrategy<T extends UserActivity> {
|
||||||
protected abstract List<T> getActiveEntities();
|
protected abstract List<T> getActiveEntities();
|
||||||
|
|
||||||
protected abstract void createEntity(User user);
|
protected abstract void createEntity(User user);
|
||||||
|
|
||||||
protected void createDefaultEntityIfNeed(List<User> allUsers, List<? extends UserContainer> entities) {
|
private void createDefaultEntityIfNeed(List<User> allUsers, List<? extends UserActivity> entities) {
|
||||||
allUsers.forEach(user -> {
|
allUsers.forEach(user -> {
|
||||||
if (entities
|
if (entities
|
||||||
.stream()
|
.stream()
|
||||||
.filter(entity -> entity.getUsers().contains(user))
|
.filter(entity -> entity.getActivityUsers().contains(user))
|
||||||
.collect(Collectors.toSet()).isEmpty()) {
|
.collect(Collectors.toSet()).isEmpty()) {
|
||||||
createEntity(user);
|
createEntity(user);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package ru.ulstu.students.controller;
|
|||||||
|
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
|
|
||||||
public class Navigation {
|
class Navigation {
|
||||||
public static final String REDIRECT_TO = "redirect:%s";
|
public static final String REDIRECT_TO = "redirect:%s";
|
||||||
public static final String TASKS_PAGE = "/students/tasks";
|
public static final String TASKS_PAGE = "/students/tasks";
|
||||||
public static final String TASK_PAGE = "/students/task";
|
public static final String TASK_PAGE = "/students/task";
|
||||||
|
@ -1,20 +1,23 @@
|
|||||||
package ru.ulstu.students.controller;
|
package ru.ulstu.students.controller;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.Hidden;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.ModelMap;
|
import org.springframework.ui.ModelMap;
|
||||||
import org.springframework.validation.Errors;
|
import org.springframework.validation.Errors;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.students.model.Task;
|
import ru.ulstu.students.model.Task;
|
||||||
import ru.ulstu.students.model.TaskDto;
|
import ru.ulstu.students.model.TaskDto;
|
||||||
|
import ru.ulstu.students.model.TaskFilterDto;
|
||||||
import ru.ulstu.students.service.TaskService;
|
import ru.ulstu.students.service.TaskService;
|
||||||
import springfox.documentation.annotations.ApiIgnore;
|
import ru.ulstu.tags.model.Tag;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -26,7 +29,7 @@ import static ru.ulstu.students.controller.Navigation.TASK_PAGE;
|
|||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@RequestMapping(value = "/students")
|
@RequestMapping(value = "/students")
|
||||||
@ApiIgnore
|
@Hidden
|
||||||
public class TaskController {
|
public class TaskController {
|
||||||
|
|
||||||
private final TaskService taskService;
|
private final TaskService taskService;
|
||||||
@ -35,16 +38,16 @@ public class TaskController {
|
|||||||
this.taskService = taskService;
|
this.taskService = taskService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/tasks")
|
|
||||||
public void getTasks(ModelMap modelMap) {
|
|
||||||
modelMap.put("tasks", taskService.findAllDto());
|
|
||||||
}
|
|
||||||
|
|
||||||
@GetMapping("/dashboard")
|
@GetMapping("/dashboard")
|
||||||
public void getDashboard(ModelMap modelMap) {
|
public void getDashboard(ModelMap modelMap) {
|
||||||
modelMap.put("tasks", taskService.findAllDto());
|
modelMap.put("tasks", taskService.findAllDto());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/tasks")
|
||||||
|
public void getTask(ModelMap modelMap) {
|
||||||
|
modelMap.put("filteredTasks", new TaskFilterDto(taskService.findAllDto(), null, null, null));
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/task")
|
@GetMapping("/task")
|
||||||
public void getTask(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
public void getTask(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
||||||
if (id != null && id > 0) {
|
if (id != null && id > 0) {
|
||||||
@ -54,6 +57,14 @@ public class TaskController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/tasks")
|
||||||
|
public void filterTasks(@Valid TaskFilterDto taskFilterDto, ModelMap modelMap) {
|
||||||
|
modelMap.put("filteredTasks", new TaskFilterDto(taskService.filter(taskFilterDto),
|
||||||
|
taskFilterDto.getStatus(),
|
||||||
|
taskFilterDto.getTag(),
|
||||||
|
taskFilterDto.getOrder()));
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/task", params = "save")
|
@PostMapping(value = "/task", params = "save")
|
||||||
public String save(@Valid TaskDto taskDto, Errors errors) throws IOException {
|
public String save(@Valid TaskDto taskDto, Errors errors) throws IOException {
|
||||||
filterEmptyDeadlines(taskDto);
|
filterEmptyDeadlines(taskDto);
|
||||||
@ -77,11 +88,23 @@ public class TaskController {
|
|||||||
return TASK_PAGE;
|
return TASK_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/delete/{task-id}")
|
||||||
|
public String delete(@PathVariable("task-id") Integer taskId) throws IOException {
|
||||||
|
taskService.delete(taskId);
|
||||||
|
return String.format(REDIRECT_TO, TASKS_PAGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ModelAttribute("allStatuses")
|
@ModelAttribute("allStatuses")
|
||||||
public List<Task.TaskStatus> getTaskStatuses() {
|
public List<Task.TaskStatus> getTaskStatuses() {
|
||||||
return taskService.getTaskStatuses();
|
return taskService.getTaskStatuses();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ModelAttribute("allTags")
|
||||||
|
public List<Tag> getTags() {
|
||||||
|
return taskService.getTags();
|
||||||
|
}
|
||||||
|
|
||||||
private void filterEmptyDeadlines(TaskDto taskDto) {
|
private void filterEmptyDeadlines(TaskDto taskDto) {
|
||||||
taskDto.setDeadlines(taskDto.getDeadlines().stream()
|
taskDto.setDeadlines(taskDto.getDeadlines().stream()
|
||||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
||||||
|
49
src/main/java/ru/ulstu/students/model/Scheduler.java
Normal file
49
src/main/java/ru/ulstu/students/model/Scheduler.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package ru.ulstu.students.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.OneToOne;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import jakarta.persistence.Temporal;
|
||||||
|
import jakarta.persistence.TemporalType;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "scheduler")
|
||||||
|
public class Scheduler extends BaseEntity {
|
||||||
|
|
||||||
|
@OneToOne(optional = false)
|
||||||
|
@JoinColumn(name = "task_id")
|
||||||
|
private Task task;
|
||||||
|
|
||||||
|
@Temporal(value = TemporalType.TIMESTAMP)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
|
private Date date;
|
||||||
|
|
||||||
|
public Scheduler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Scheduler(Task task, Date date) {
|
||||||
|
this.task = task;
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task getTask() {
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTask(Task task) {
|
||||||
|
this.task = task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
}
|
@ -1,31 +1,35 @@
|
|||||||
package ru.ulstu.students.model;
|
package ru.ulstu.students.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.CascadeType;
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.EnumType;
|
||||||
|
import jakarta.persistence.Enumerated;
|
||||||
|
import jakarta.persistence.FetchType;
|
||||||
|
import jakarta.persistence.JoinColumn;
|
||||||
|
import jakarta.persistence.JoinTable;
|
||||||
|
import jakarta.persistence.ManyToMany;
|
||||||
|
import jakarta.persistence.OneToMany;
|
||||||
|
import jakarta.persistence.OrderBy;
|
||||||
|
import jakarta.persistence.Temporal;
|
||||||
|
import jakarta.persistence.TemporalType;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import org.hibernate.annotations.Fetch;
|
import org.hibernate.annotations.Fetch;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
import ru.ulstu.core.model.EventSource;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.tags.model.Tag;
|
import ru.ulstu.tags.model.Tag;
|
||||||
|
import ru.ulstu.timeline.model.Event;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
|
||||||
import javax.persistence.Column;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.EnumType;
|
|
||||||
import javax.persistence.Enumerated;
|
|
||||||
import javax.persistence.FetchType;
|
|
||||||
import javax.persistence.JoinColumn;
|
|
||||||
import javax.persistence.JoinTable;
|
|
||||||
import javax.persistence.ManyToMany;
|
|
||||||
import javax.persistence.OneToMany;
|
|
||||||
import javax.persistence.OrderBy;
|
|
||||||
import javax.persistence.Temporal;
|
|
||||||
import javax.persistence.TemporalType;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Task extends BaseEntity {
|
public class Task extends BaseEntity implements EventSource {
|
||||||
|
|
||||||
public enum TaskStatus {
|
public enum TaskStatus {
|
||||||
IN_WORK("В работе"),
|
IN_WORK("В работе"),
|
||||||
@ -33,7 +37,7 @@ public class Task extends BaseEntity {
|
|||||||
FAILED("Провалены сроки"),
|
FAILED("Провалены сроки"),
|
||||||
LOADED_FROM_KIAS("Загружен автоматически");
|
LOADED_FROM_KIAS("Загружен автоматически");
|
||||||
|
|
||||||
private String statusName;
|
private final String statusName;
|
||||||
|
|
||||||
TaskStatus(String name) {
|
TaskStatus(String name) {
|
||||||
this.statusName = name;
|
this.statusName = name;
|
||||||
@ -49,8 +53,12 @@ public class Task extends BaseEntity {
|
|||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
public Task() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Enumerated(value = EnumType.STRING)
|
@Enumerated(value = EnumType.STRING)
|
||||||
private ru.ulstu.students.model.Task.TaskStatus status = TaskStatus.IN_WORK;
|
private TaskStatus status = TaskStatus.IN_WORK;
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||||
@JoinColumn(name = "task_id", unique = true)
|
@JoinColumn(name = "task_id", unique = true)
|
||||||
@ -67,6 +75,7 @@ public class Task extends BaseEntity {
|
|||||||
private Date updateDate = new Date();
|
private Date updateDate = new Date();
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER)
|
@ManyToMany(fetch = FetchType.EAGER)
|
||||||
|
@Fetch(FetchMode.SUBSELECT)
|
||||||
@JoinTable(name = "task_tags",
|
@JoinTable(name = "task_tags",
|
||||||
joinColumns = {@JoinColumn(name = "task_id")},
|
joinColumns = {@JoinColumn(name = "task_id")},
|
||||||
inverseJoinColumns = {@JoinColumn(name = "tag_id")})
|
inverseJoinColumns = {@JoinColumn(name = "tag_id")})
|
||||||
@ -76,6 +85,16 @@ public class Task extends BaseEntity {
|
|||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<User> getRecipients() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addObjectToEvent(Event event) {
|
||||||
|
event.setTask(this);
|
||||||
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
public void setTitle(String title) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
@ -127,4 +146,5 @@ public class Task extends BaseEntity {
|
|||||||
public void setTags(List<Tag> tags) {
|
public void setTags(List<Tag> tags) {
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,15 @@ package ru.ulstu.students.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.tags.model.Tag;
|
import ru.ulstu.tags.model.Tag;
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ public class TaskDto {
|
|||||||
private Date createDate;
|
private Date createDate;
|
||||||
private Date updateDate;
|
private Date updateDate;
|
||||||
private Set<Integer> tagIds;
|
private Set<Integer> tagIds;
|
||||||
private List<Tag> tags;
|
private List<Tag> tags = new ArrayList<>();
|
||||||
|
|
||||||
public TaskDto() {
|
public TaskDto() {
|
||||||
deadlines.add(new Deadline());
|
deadlines.add(new Deadline());
|
||||||
@ -135,6 +136,29 @@ public class TaskDto {
|
|||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
TaskDto taskDto = (TaskDto) o;
|
||||||
|
return Objects.equals(id, taskDto.id) &&
|
||||||
|
Objects.equals(title, taskDto.title) &&
|
||||||
|
Objects.equals(description, taskDto.description) &&
|
||||||
|
status == taskDto.status &&
|
||||||
|
Objects.equals(deadlines, taskDto.deadlines) &&
|
||||||
|
Objects.equals(tagIds, taskDto.tagIds) &&
|
||||||
|
Objects.equals(tags, taskDto.tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, title, description, status, deadlines, createDate, updateDate, tagIds, tags);
|
||||||
|
}
|
||||||
|
|
||||||
public String getTagsString() {
|
public String getTagsString() {
|
||||||
return StringUtils.abbreviate(tags
|
return StringUtils.abbreviate(tags
|
||||||
.stream()
|
.stream()
|
||||||
|
54
src/main/java/ru/ulstu/students/model/TaskFilterDto.java
Normal file
54
src/main/java/ru/ulstu/students/model/TaskFilterDto.java
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package ru.ulstu.students.model;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TaskFilterDto {
|
||||||
|
|
||||||
|
private List<TaskDto> tasks;
|
||||||
|
private Task.TaskStatus status;
|
||||||
|
private Integer tagId;
|
||||||
|
private String order;
|
||||||
|
|
||||||
|
public TaskFilterDto(List<TaskDto> tasks, Task.TaskStatus status, Integer tagId, String order) {
|
||||||
|
this.tasks = tasks;
|
||||||
|
this.status = status;
|
||||||
|
this.tagId = tagId;
|
||||||
|
this.order = order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TaskFilterDto() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TaskDto> getTasks() {
|
||||||
|
return tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTasks(List<TaskDto> tasks) {
|
||||||
|
this.tasks = tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task.TaskStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Task.TaskStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getTag() {
|
||||||
|
return tagId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTag(Integer tagId) {
|
||||||
|
this.tagId = tagId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrder() {
|
||||||
|
return order;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrder(String order) {
|
||||||
|
this.order = order;
|
||||||
|
}
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user