WIP: Try vue #244
165
.jshintrc
Normal file
165
.jshintrc
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
{
|
||||||
|
// JSHint Default Configuration File (as on JSHint website)
|
||||||
|
// See http://jshint.com/docs/ for more details
|
||||||
|
|
||||||
|
"maxerr": 50,
|
||||||
|
// {int} Maximum error before stopping
|
||||||
|
|
||||||
|
// Enforcing
|
||||||
|
"bitwise": true,
|
||||||
|
// true: Prohibit bitwise operators (&, |, ^, etc.)
|
||||||
|
"camelcase": false,
|
||||||
|
// true: Identifiers must be in camelCase
|
||||||
|
"curly": true,
|
||||||
|
// true: Require {} for every new block or scope
|
||||||
|
"eqeqeq": true,
|
||||||
|
// true: Require triple equals (===) for comparison
|
||||||
|
"forin": true,
|
||||||
|
// true: Require filtering for..in loops with obj.hasOwnProperty()
|
||||||
|
"freeze": true,
|
||||||
|
// true: prohibits overwriting prototypes of native objects such as Array, Date etc.
|
||||||
|
"immed": false,
|
||||||
|
// true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
|
||||||
|
"latedef": false,
|
||||||
|
// true: Require variables/functions to be defined before being used
|
||||||
|
"newcap": false,
|
||||||
|
// true: Require capitalization of all constructor functions e.g. `new F()`
|
||||||
|
"noarg": true,
|
||||||
|
// true: Prohibit use of `arguments.caller` and `arguments.callee`
|
||||||
|
"noempty": true,
|
||||||
|
// true: Prohibit use of empty blocks
|
||||||
|
"nonbsp": true,
|
||||||
|
// true: Prohibit "non-breaking whitespace" characters.
|
||||||
|
"nonew": false,
|
||||||
|
// true: Prohibit use of constructors for side-effects (without assignment)
|
||||||
|
"plusplus": false,
|
||||||
|
// true: Prohibit use of `++` and `--`
|
||||||
|
"quotmark": false,
|
||||||
|
// Quotation mark consistency:
|
||||||
|
// false : do nothing (default)
|
||||||
|
// true : ensure whatever is used is consistent
|
||||||
|
// "single" : require single quotes
|
||||||
|
// "double" : require double quotes
|
||||||
|
"undef": true,
|
||||||
|
// true: Require all non-global variables to be declared (prevents global leaks)
|
||||||
|
"unused": true,
|
||||||
|
// Unused variables:
|
||||||
|
// true : all variables, last function parameter
|
||||||
|
// "vars" : all variables only
|
||||||
|
// "strict" : all variables, all function parameters
|
||||||
|
"strict": false,
|
||||||
|
// true: Requires all functions run in ES5 Strict Mode
|
||||||
|
"maxparams": false,
|
||||||
|
// {int} Max number of formal params allowed per function
|
||||||
|
"maxdepth": false,
|
||||||
|
// {int} Max depth of nested blocks (within functions)
|
||||||
|
"maxstatements": false,
|
||||||
|
// {int} Max number statements per function
|
||||||
|
"maxcomplexity": false,
|
||||||
|
// {int} Max cyclomatic complexity per function
|
||||||
|
"maxlen": false,
|
||||||
|
// {int} Max number of characters per line
|
||||||
|
"varstmt": false,
|
||||||
|
// true: Disallow any var statements. Only `let` and `const` are allowed.
|
||||||
|
|
||||||
|
// Relaxing
|
||||||
|
"asi": false,
|
||||||
|
// true: Tolerate Automatic Semicolon Insertion (no semicolons)
|
||||||
|
"boss": false,
|
||||||
|
// true: Tolerate assignments where comparisons would be expected
|
||||||
|
"debug": false,
|
||||||
|
// true: Allow debugger statements e.g. browser breakpoints.
|
||||||
|
"eqnull": true,
|
||||||
|
// true: Tolerate use of `== null`
|
||||||
|
"esversion": 5,
|
||||||
|
// {int} Specify the ECMAScript version to which the code must adhere.
|
||||||
|
"moz": false,
|
||||||
|
// true: Allow Mozilla specific syntax (extends and overrides esnext features)
|
||||||
|
// (ex: `for each`, multiple try/catch, function expression…)
|
||||||
|
"evil": false,
|
||||||
|
// true: Tolerate use of `eval` and `new Function()`
|
||||||
|
"expr": false,
|
||||||
|
// true: Tolerate `ExpressionStatement` as Programs
|
||||||
|
"funcscope": false,
|
||||||
|
// true: Tolerate defining variables inside control statements
|
||||||
|
"globalstrict": false,
|
||||||
|
// true: Allow global "use strict" (also enables 'strict')
|
||||||
|
"iterator": false,
|
||||||
|
// true: Tolerate using the `__iterator__` property
|
||||||
|
"lastsemic": false,
|
||||||
|
// true: Tolerate omitting a semicolon for the last statement of a 1-line block
|
||||||
|
"laxbreak": false,
|
||||||
|
// true: Tolerate possibly unsafe line breakings
|
||||||
|
"laxcomma": false,
|
||||||
|
// true: Tolerate comma-first style coding
|
||||||
|
"loopfunc": false,
|
||||||
|
// true: Tolerate functions being defined in loops
|
||||||
|
"multistr": false,
|
||||||
|
// true: Tolerate multi-line strings
|
||||||
|
"noyield": false,
|
||||||
|
// true: Tolerate generator functions with no yield statement in them.
|
||||||
|
"notypeof": false,
|
||||||
|
// true: Tolerate invalid typeof operator values
|
||||||
|
"proto": false,
|
||||||
|
// true: Tolerate using the `__proto__` property
|
||||||
|
"scripturl": false,
|
||||||
|
// true: Tolerate script-targeted URLs
|
||||||
|
"shadow": false,
|
||||||
|
// true: Allows re-define variables later in code e.g. `var x=1; x=2;`
|
||||||
|
"sub": false,
|
||||||
|
// true: Tolerate using `[]` notation when it can still be expressed in dot notation
|
||||||
|
"supernew": false,
|
||||||
|
// true: Tolerate `new function () { ... };` and `new Object;`
|
||||||
|
"validthis": false,
|
||||||
|
// true: Tolerate using this in a non-constructor function
|
||||||
|
|
||||||
|
// Environments
|
||||||
|
"browser": true,
|
||||||
|
// Web Browser (window, document, etc)
|
||||||
|
"browserify": false,
|
||||||
|
// Browserify (node.js code in the browser)
|
||||||
|
"couch": false,
|
||||||
|
// CouchDB
|
||||||
|
"devel": true,
|
||||||
|
// Development/debugging (alert, confirm, etc)
|
||||||
|
"dojo": false,
|
||||||
|
// Dojo Toolkit
|
||||||
|
"jasmine": false,
|
||||||
|
// Jasmine
|
||||||
|
"jquery": true,
|
||||||
|
// jQuery
|
||||||
|
"mocha": false,
|
||||||
|
// Mocha
|
||||||
|
"mootools": false,
|
||||||
|
// MooTools
|
||||||
|
"node": false,
|
||||||
|
// Node.js
|
||||||
|
"nonstandard": false,
|
||||||
|
// Widely adopted globals (escape, unescape, etc)
|
||||||
|
"phantom": false,
|
||||||
|
// PhantomJS
|
||||||
|
"prototypejs": false,
|
||||||
|
// Prototype and Scriptaculous
|
||||||
|
"qunit": false,
|
||||||
|
// QUnit
|
||||||
|
"rhino": false,
|
||||||
|
// Rhino
|
||||||
|
"shelljs": false,
|
||||||
|
// ShellJS
|
||||||
|
"typed": false,
|
||||||
|
// Globals for typed array constructions
|
||||||
|
"worker": false,
|
||||||
|
// Web Workers
|
||||||
|
"wsh": false,
|
||||||
|
// Windows Scripting Host
|
||||||
|
"yui": false,
|
||||||
|
// Yahoo User Interface
|
||||||
|
|
||||||
|
// Custom Globals
|
||||||
|
"globals": {
|
||||||
|
"spc": false,
|
||||||
|
"spsn": false,
|
||||||
|
"spconf": false
|
||||||
|
}
|
||||||
|
// additional predefined global variables
|
||||||
|
}
|
13
build.gradle
13
build.gradle
@ -117,11 +117,16 @@ dependencies {
|
|||||||
|
|
||||||
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
|
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
|
||||||
|
|
||||||
compile group: 'org.webjars', name: 'bootstrap', version: '4.1.0'
|
|
||||||
compile group: 'org.webjars', name: 'bootstrap-select', version: '1.13.3'
|
|
||||||
compile group: 'org.webjars', name: 'jquery', version: '3.3.1-1'
|
|
||||||
compile group: 'org.webjars.npm', name: 'jquery.easing', version: '1.4.1'
|
|
||||||
compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0'
|
compile group: 'org.webjars', name: 'font-awesome', version: '4.7.0'
|
||||||
|
compile group: 'org.webjars', name: 'bootstrap', version: '4.1.3'
|
||||||
|
compile group: 'org.webjars.npm', name: 'vue', version: '2.6.9'
|
||||||
|
compile group: 'org.webjars.npm', name: 'vuex', version: '3.1.0'
|
||||||
|
compile group: 'org.webjars.npm', name: 'vue-router', version: '3.0.2'
|
||||||
|
compile group: 'org.webjars.npm', name: 'vue-multiselect', version: '2.0.2'
|
||||||
|
compile group: 'org.webjars.npm', name: 'vue-moment', version: '4.0.0'
|
||||||
|
compile group: 'org.webjars.npm', name: 'http-vue-loader', version: '1.3.5'
|
||||||
|
compile group: 'org.webjars.npm', name: 'axios', version: '0.18.0'
|
||||||
|
compile group: 'org.webjars.npm', name: 'vee-validate', version: '2.1.7'
|
||||||
|
|
||||||
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.6.0'
|
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.6.0'
|
||||||
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.6.0'
|
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.6.0'
|
||||||
|
24
deploy/run_psql.sh
Normal file
24
deploy/run_psql.sh
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# to run this execute
|
||||||
|
# export PSQL_HOME_DIR=/home/user/pgsql-10.5.1; bash ./deploy/run_psql.sh
|
||||||
|
PSQL_DATA_DIR=./ng-tracker
|
||||||
|
PSQL_USER_NAME=postgres
|
||||||
|
PSQL_DB_NAME=ng-tracker
|
||||||
|
if [ ! -d "$PSQL_HOME_DIR" ]; then
|
||||||
|
echo "Directory $PSQL_HOME_DIR is not exists"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
cd "$PSQL_HOME_DIR"
|
||||||
|
if [ ! -d "$PSQL_DATA_DIR" ]; then
|
||||||
|
./bin/initdb "$PSQL_DATA_DIR"
|
||||||
|
./bin/pg_ctl -D "$PSQL_DATA_DIR" start
|
||||||
|
./bin/createuser -s "$PSQL_USER_NAME"
|
||||||
|
./bin/createdb -O "$PSQL_USER_NAME" "$PSQL_DB_NAME"
|
||||||
|
else
|
||||||
|
PSQL_STATUS=$(./bin/pg_ctl -D "$PSQL_DATA_DIR" status | wc -l)
|
||||||
|
if [ $PSQL_STATUS -eq 1 ]; then
|
||||||
|
./bin/pg_ctl -D "$PSQL_DATA_DIR" start
|
||||||
|
else
|
||||||
|
./bin/pg_ctl -D "$PSQL_DATA_DIR" stop
|
||||||
|
fi
|
||||||
|
fi
|
31
src/main/java/ru/ulstu/activity/api/ActivityController.java
Normal file
31
src/main/java/ru/ulstu/activity/api/ActivityController.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package ru.ulstu.activity.api;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.api.model.ActivityDashboardDto;
|
||||||
|
import ru.ulstu.activity.api.model.ActivityDto;
|
||||||
|
import ru.ulstu.activity.api.model.ActivityListDto;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
import ru.ulstu.core.model.response.Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Базовый API для контролеров активностей
|
||||||
|
*
|
||||||
|
* @param <LIST>
|
||||||
|
* @param <DASHBOARD>
|
||||||
|
* @param <ENTITYDTO>
|
||||||
|
*/
|
||||||
|
public interface ActivityController<LIST extends ActivityListDto, DASHBOARD extends ActivityDashboardDto, ENTITYDTO extends ActivityDto> {
|
||||||
|
|
||||||
|
Response<PageableItems<LIST>> getList(int offset, int count);
|
||||||
|
|
||||||
|
Response<PageableItems<DASHBOARD>> getDashboard(int offset, int count);
|
||||||
|
|
||||||
|
Response<ENTITYDTO> get(Integer entityId);
|
||||||
|
|
||||||
|
Response<ENTITYDTO> create(ENTITYDTO entity);
|
||||||
|
|
||||||
|
Response<ENTITYDTO> update(ENTITYDTO entity);
|
||||||
|
|
||||||
|
Response<Boolean> delete(Integer entityId);
|
||||||
|
|
||||||
|
void ping(int entityId);
|
||||||
|
}
|
23
src/main/java/ru/ulstu/activity/api/ActivityRepository.java
Normal file
23
src/main/java/ru/ulstu/activity/api/ActivityRepository.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package ru.ulstu.activity.api;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface ActivityRepository<T> {
|
||||||
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
|
|
||||||
|
T save(T t);
|
||||||
|
|
||||||
|
T getById(Integer id);
|
||||||
|
|
||||||
|
Page<T> findAll(Pageable pageable);
|
||||||
|
|
||||||
|
void deleteById(Integer id);
|
||||||
|
|
||||||
|
Optional<T> findById(Integer id);
|
||||||
|
|
||||||
|
void detach(T t);
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package ru.ulstu.activity.api.model;
|
||||||
|
|
||||||
|
public abstract class ActivityDashboardDto {
|
||||||
|
private final Integer id;
|
||||||
|
private final String title;
|
||||||
|
|
||||||
|
protected ActivityDashboardDto(Integer id, String title) {
|
||||||
|
this.id = id;
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
}
|
13
src/main/java/ru/ulstu/activity/api/model/ActivityDto.java
Normal file
13
src/main/java/ru/ulstu/activity/api/model/ActivityDto.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package ru.ulstu.activity.api.model;
|
||||||
|
|
||||||
|
public abstract class ActivityDto {
|
||||||
|
private final Integer id;
|
||||||
|
|
||||||
|
public ActivityDto(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package ru.ulstu.activity.api.model;
|
||||||
|
|
||||||
|
public abstract class ActivityListDto {
|
||||||
|
private final Integer id;
|
||||||
|
private final String title;
|
||||||
|
|
||||||
|
protected ActivityListDto(Integer id, String title) {
|
||||||
|
this.id = id;
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package ru.ulstu.utils.timetable;
|
package ru.ulstu.activity.boundary.timetable;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.springframework.web.client.RestClientException;
|
import org.springframework.web.client.RestClientException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import ru.ulstu.activity.boundary.timetable.errors.TimetableClientException;
|
||||||
|
import ru.ulstu.activity.boundary.timetable.model.Lesson;
|
||||||
|
import ru.ulstu.activity.boundary.timetable.model.TimetableResponse;
|
||||||
import ru.ulstu.core.util.DateUtils;
|
import ru.ulstu.core.util.DateUtils;
|
||||||
import ru.ulstu.utils.timetable.errors.TimetableClientException;
|
|
||||||
import ru.ulstu.utils.timetable.model.Lesson;
|
|
||||||
import ru.ulstu.utils.timetable.model.TimetableResponse;
|
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.utils.timetable.errors;
|
package ru.ulstu.activity.boundary.timetable.errors;
|
||||||
|
|
||||||
public class TimetableClientException extends RuntimeException {
|
public class TimetableClientException extends RuntimeException {
|
||||||
public TimetableClientException(String message) {
|
public TimetableClientException(String message) {
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.utils.timetable.model;
|
package ru.ulstu.activity.boundary.timetable.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.utils.timetable.model;
|
package ru.ulstu.activity.boundary.timetable.model;
|
||||||
|
|
||||||
public class Lesson {
|
public class Lesson {
|
||||||
private String group;
|
private String group;
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.utils.timetable.model;
|
package ru.ulstu.activity.boundary.timetable.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.utils.timetable.model;
|
package ru.ulstu.activity.boundary.timetable.model;
|
||||||
|
|
||||||
public class TimetableResponse {
|
public class TimetableResponse {
|
||||||
private Response response;
|
private Response response;
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.utils.timetable.model;
|
package ru.ulstu.activity.boundary.timetable.model;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
@ -0,0 +1,24 @@
|
|||||||
|
package ru.ulstu.activity.common.model;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.timeline.model.Event;
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public abstract class AbstractActivity extends BaseEntity {
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Set<User> getActivityMembers();
|
||||||
|
|
||||||
|
public abstract List<Event> getEvents();
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
package ru.ulstu.core.model;
|
package ru.ulstu.activity.common.model;
|
||||||
|
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
import ru.ulstu.timeline.model.Event;
|
import ru.ulstu.activity.timeline.model.Event;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -14,4 +14,6 @@ public interface EventSource {
|
|||||||
List<User> getRecipients();
|
List<User> getRecipients();
|
||||||
|
|
||||||
void addObjectToEvent(Event event);
|
void addObjectToEvent(Event event);
|
||||||
|
|
||||||
|
String getSuffix();
|
||||||
}
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
package ru.ulstu.activity.common.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import ru.ulstu.activity.conference.model.ConferenceUser;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Size;
|
||||||
|
|
||||||
|
public class ScienceGroupMemberDto {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Size(min = 2, max = 50)
|
||||||
|
private String firstName;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Size(min = 2, max = 50)
|
||||||
|
private String lastName;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public ScienceGroupMemberDto(@JsonProperty("id") Integer id,
|
||||||
|
@JsonProperty("firstName") String firstName,
|
||||||
|
@JsonProperty("lastName") String lastName) {
|
||||||
|
this.id = id;
|
||||||
|
this.firstName = firstName;
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScienceGroupMemberDto(User user) {
|
||||||
|
this.id = user.getId();
|
||||||
|
this.firstName = user.getFirstName();
|
||||||
|
this.lastName = user.getLastName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScienceGroupMemberDto(ConferenceUser conferenceUser) {
|
||||||
|
User user = conferenceUser.getUser();
|
||||||
|
this.id = user.getId();
|
||||||
|
this.firstName = user.getFirstName();
|
||||||
|
this.lastName = user.getLastName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstName(String firstName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastName(String lastName) {
|
||||||
|
this.lastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ScienceGroupMember{" +
|
||||||
|
"id=" + id +
|
||||||
|
", firstName='" + firstName + '\'' +
|
||||||
|
", lastName='" + lastName + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package ru.ulstu.activity.common.service;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.common.model.AbstractActivity;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public abstract class ActivityNotificationService<T extends AbstractActivity> {
|
||||||
|
private final MailService mailService;
|
||||||
|
|
||||||
|
protected ActivityNotificationService(MailService mailService) {
|
||||||
|
this.mailService = mailService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void sendCreateNotification(T entity);
|
||||||
|
|
||||||
|
protected void sendForAuthor(Map<String, Object> variables, User author, String template, String title) {
|
||||||
|
mailService.sendEmailFromTemplate(variables, author, template, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendForAllAuthors(Map<String, Object> variables, T entity, String template, String title) {
|
||||||
|
entity.getActivityMembers().forEach(author -> sendForAuthor(variables, author, template, title));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,129 @@
|
|||||||
|
package ru.ulstu.activity.common.service;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.activity.api.ActivityRepository;
|
||||||
|
import ru.ulstu.activity.api.model.ActivityDto;
|
||||||
|
import ru.ulstu.activity.api.model.ActivityListDto;
|
||||||
|
import ru.ulstu.activity.common.model.AbstractActivity;
|
||||||
|
import ru.ulstu.activity.common.model.EventSource;
|
||||||
|
import ru.ulstu.activity.ping.service.PingService;
|
||||||
|
import ru.ulstu.activity.timeline.model.Event;
|
||||||
|
import ru.ulstu.activity.timeline.service.EventService;
|
||||||
|
import ru.ulstu.core.jpa.OffsetablePageRequest;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
|
||||||
|
import javax.persistence.EntityNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
|
|
||||||
|
public abstract class ActivityService<L extends ActivityListDto, T extends AbstractActivity, D extends ActivityDto> {
|
||||||
|
|
||||||
|
protected final ActivityRepository<T> activityRepository;
|
||||||
|
protected final ActivityNotificationService<T> activityNotificationService;
|
||||||
|
protected final PingService pingService;
|
||||||
|
protected final EventService eventService;
|
||||||
|
|
||||||
|
protected ActivityService(ActivityRepository activityRepository,
|
||||||
|
ActivityNotificationService<T> activityNotificationService,
|
||||||
|
PingService pingService,
|
||||||
|
EventService eventService) {
|
||||||
|
this.activityRepository = activityRepository;
|
||||||
|
this.activityNotificationService = activityNotificationService;
|
||||||
|
this.pingService = pingService;
|
||||||
|
this.eventService = eventService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public D create(D entityDto) {
|
||||||
|
T newEntity;
|
||||||
|
try {
|
||||||
|
newEntity = copyFromDto(getNewActivity(), entityDto);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return getNewActivityDto(create(newEntity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public T update(T oldEntity, T entity) {
|
||||||
|
entity.getEvents().clear();
|
||||||
|
eventService.deleteAll(getEvents(entity));
|
||||||
|
eventService.createFromObject((EventSource) entity);
|
||||||
|
doActionsOnDiffObjects(oldEntity, entity);
|
||||||
|
return activityRepository.save(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void doActionsOnDiffObjects(T oldEntity, T entity);
|
||||||
|
|
||||||
|
protected abstract List<Event> getEvents(T entity);
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public D update(D entityDto) {
|
||||||
|
T oldEntity = activityRepository.getById(entityDto.getId());
|
||||||
|
//to init lazy collection
|
||||||
|
oldEntity.getActivityMembers().size();
|
||||||
|
activityRepository.detach(oldEntity);
|
||||||
|
T newEntity;
|
||||||
|
try {
|
||||||
|
newEntity = copyFromDto(activityRepository.getById(entityDto.getId()), entityDto);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return getNewActivityDto(update(oldEntity, newEntity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public T create(T entity) {
|
||||||
|
eventService.createFromObject((EventSource) entity);
|
||||||
|
T newEntity = activityRepository.save(entity);
|
||||||
|
activityNotificationService.sendCreateNotification(newEntity);
|
||||||
|
return newEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean delete(Integer id) {
|
||||||
|
activityRepository.deleteById(id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public D findDtoById(Integer id) {
|
||||||
|
return getNewActivityDto(findById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public T findById(Integer id) {
|
||||||
|
return activityRepository.findById(id)
|
||||||
|
.orElseThrow(() -> new EntityNotFoundException("Entity with id=" + id + " not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public PageableItems<T> findAll(int offset, int count) {
|
||||||
|
final Page<T> page = activityRepository.findAll(new OffsetablePageRequest(offset, count));
|
||||||
|
return new PageableItems<>(page.getTotalElements(), page.getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
public PageableItems<L> findAllDto(int offset, int count) {
|
||||||
|
return convertPageable(findAll(offset, count), entity -> getActivityListDto(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract PageableItems findAllActiveDto(int offset, int count);
|
||||||
|
|
||||||
|
public abstract PageableItems<T> findAllActive(int offset, int count);
|
||||||
|
|
||||||
|
protected abstract T copyFromDto(T t, D d) throws IOException;
|
||||||
|
|
||||||
|
protected abstract L getActivityListDto(T entity);
|
||||||
|
|
||||||
|
protected abstract T getNewActivity();
|
||||||
|
|
||||||
|
protected abstract D getNewActivityDto(T entity);
|
||||||
|
|
||||||
|
protected boolean checkUniqueName(String title, Integer id) {
|
||||||
|
return title.equals(activityRepository.findByNameAndNotId(title, id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void ping(int entityId) {
|
||||||
|
pingService.addPing(findById(entityId));
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +1,21 @@
|
|||||||
package ru.ulstu.strategy.api;
|
package ru.ulstu.activity.common.strategy.api;
|
||||||
|
|
||||||
import ru.ulstu.core.model.UserActivity;
|
import ru.ulstu.activity.common.model.AbstractActivity;
|
||||||
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 UserActivity> {
|
public abstract class EntityCreateStrategy<T extends AbstractActivity> {
|
||||||
protected abstract List<T> getActiveEntities();
|
protected abstract List<T> getActiveEntities();
|
||||||
|
|
||||||
protected abstract void createEntity(User user);
|
protected abstract void createEntity(User user);
|
||||||
|
|
||||||
private void createDefaultEntityIfNeed(List<User> allUsers, List<? extends UserActivity> entities) {
|
private void createDefaultEntityIfNeed(List<User> allUsers, List<? extends AbstractActivity> entities) {
|
||||||
allUsers.forEach(user -> {
|
allUsers.forEach(user -> {
|
||||||
if (entities
|
if (entities
|
||||||
.stream()
|
.stream()
|
||||||
.filter(entity -> entity.getActivityUsers().contains(user))
|
.filter(entity -> entity.getActivityMembers().contains(user))
|
||||||
.collect(Collectors.toSet()).isEmpty()) {
|
.collect(Collectors.toSet()).isEmpty()) {
|
||||||
createEntity(user);
|
createEntity(user);
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.strategy.api;
|
package ru.ulstu.activity.common.strategy.api;
|
||||||
|
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
@ -0,0 +1,70 @@
|
|||||||
|
package ru.ulstu.activity.conference.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import ru.ulstu.activity.api.ActivityController;
|
||||||
|
import ru.ulstu.activity.conference.model.ConferenceDashboardDto;
|
||||||
|
import ru.ulstu.activity.conference.model.ConferenceDto;
|
||||||
|
import ru.ulstu.activity.conference.model.ConferenceListDto;
|
||||||
|
import ru.ulstu.activity.conference.service.ConferenceService;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
import ru.ulstu.core.model.response.Response;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
public class ConferenceController implements ActivityController<ConferenceListDto, ConferenceDashboardDto, ConferenceDto> {
|
||||||
|
|
||||||
|
private final ConferenceService conferenceService;
|
||||||
|
|
||||||
|
public ConferenceController(ConferenceService conferenceService) {
|
||||||
|
this.conferenceService = conferenceService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@GetMapping("list")
|
||||||
|
public Response<PageableItems<ConferenceListDto>> getList(@RequestParam(value = "offset", defaultValue = "0") int offset,
|
||||||
|
@RequestParam(value = "count", defaultValue = "0") int count) {
|
||||||
|
return new Response<>(conferenceService.findAllDto(offset, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@GetMapping("dashboard")
|
||||||
|
public Response<PageableItems<ConferenceDashboardDto>> getDashboard(@RequestParam(value = "offset", defaultValue = "0") int offset,
|
||||||
|
@RequestParam(value = "count", defaultValue = "0") int count) {
|
||||||
|
return new Response<>(conferenceService.findAllActiveDto(offset, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@GetMapping("{conference-id}")
|
||||||
|
public Response<ConferenceDto> get(@PathVariable("conference-id") Integer entityId) {
|
||||||
|
return new Response<>(conferenceService.findConferenceById(entityId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@PostMapping
|
||||||
|
public Response<ConferenceDto> create(@RequestBody @Valid ConferenceDto entity) {
|
||||||
|
return new Response<>(conferenceService.create(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@PutMapping
|
||||||
|
public Response<ConferenceDto> update(@RequestBody @Valid ConferenceDto entity) {
|
||||||
|
return new Response<>(conferenceService.update(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@DeleteMapping("{conference-id}")
|
||||||
|
public Response<Boolean> delete(@PathVariable("conference-id") Integer entityId) {
|
||||||
|
return new Response<>(conferenceService.delete(entityId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("ping/{conference-id}")
|
||||||
|
public void ping(@PathVariable("conference-id") int conferenceId) {
|
||||||
|
conferenceService.ping(conferenceId);
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,13 @@
|
|||||||
package ru.ulstu.conference.model;
|
package ru.ulstu.activity.conference.model;
|
||||||
|
|
||||||
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.activity.common.model.AbstractActivity;
|
||||||
import ru.ulstu.core.model.EventSource;
|
import ru.ulstu.activity.common.model.EventSource;
|
||||||
import ru.ulstu.core.model.UserActivity;
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.activity.paper.model.Paper;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.activity.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.CascadeType;
|
||||||
@ -26,6 +25,7 @@ import javax.persistence.Temporal;
|
|||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
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.List;
|
import java.util.List;
|
||||||
@ -36,7 +36,7 @@ import java.util.stream.Collectors;
|
|||||||
@Entity
|
@Entity
|
||||||
@Table(name = "conference")
|
@Table(name = "conference")
|
||||||
@DiscriminatorValue("CONFERENCE")
|
@DiscriminatorValue("CONFERENCE")
|
||||||
public class Conference extends BaseEntity implements UserActivity, EventSource {
|
public class Conference extends AbstractActivity implements EventSource {
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String title;
|
private String title;
|
||||||
@ -79,6 +79,10 @@ public class Conference extends BaseEntity implements UserActivity, EventSource
|
|||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<User> getRecipients() {
|
public List<User> getRecipients() {
|
||||||
List<User> list = new ArrayList<>();
|
List<User> list = new ArrayList<>();
|
||||||
@ -88,12 +92,13 @@ public class Conference extends BaseEntity implements UserActivity, EventSource
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addObjectToEvent(Event event) {
|
public String getSuffix() {
|
||||||
event.setConference(this);
|
return "конференции";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
@Override
|
||||||
this.title = title;
|
public void addObjectToEvent(Event event) {
|
||||||
|
event.setConference(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
@ -170,7 +175,12 @@ public class Conference extends BaseEntity implements UserActivity, EventSource
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<User> getActivityUsers() {
|
public Set<User> getActivityMembers() {
|
||||||
return getUsers().stream().map(ConferenceUser::getUser).collect(Collectors.toSet());
|
return users.stream().map(conferenceUser -> conferenceUser.getUser()).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Event> getEvents() {
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package ru.ulstu.activity.conference.model;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.api.model.ActivityDashboardDto;
|
||||||
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
|
public class ConferenceDashboardDto extends ActivityDashboardDto {
|
||||||
|
private final Set<ScienceGroupMemberDto> members;
|
||||||
|
|
||||||
|
public ConferenceDashboardDto(Conference conference) {
|
||||||
|
super(conference.getId(), conference.getTitle());
|
||||||
|
this.members = convert(conference.getActivityMembers(), ScienceGroupMemberDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ScienceGroupMemberDto> getAuthors() {
|
||||||
|
return members;
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package ru.ulstu.conference.model;
|
package ru.ulstu.activity.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 org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import ru.ulstu.activity.api.model.ActivityDto;
|
||||||
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
|
import ru.ulstu.activity.deadline.model.DeadlineDto;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
|
||||||
import ru.ulstu.name.NameContainer;
|
|
||||||
import ru.ulstu.paper.model.Paper;
|
|
||||||
|
|
||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
@ -15,11 +15,10 @@ 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 extends NameContainer {
|
public class ConferenceDto extends ActivityDto {
|
||||||
|
|
||||||
private final static String BEGIN_DATE = "Начало: ";
|
private final static String BEGIN_DATE = "Начало: ";
|
||||||
private final static String END_DATE = "Конец: ";
|
private final static String END_DATE = "Конец: ";
|
||||||
@ -39,18 +38,12 @@ public class ConferenceDto extends NameContainer {
|
|||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date endDate = new Date();
|
private Date endDate = new Date();
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||||
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
private List<ScienceGroupMemberDto> userIds = new ArrayList<>();
|
||||||
private List<Integer> userIds = new ArrayList<>();
|
|
||||||
private List<Integer> paperIds = new ArrayList<>();
|
private List<Integer> paperIds = new ArrayList<>();
|
||||||
private List<Paper> papers = new ArrayList<>();
|
|
||||||
private List<Paper> notSelectedPapers = new ArrayList<>();
|
|
||||||
private List<ConferenceUser> users = new ArrayList<>();
|
private List<ConferenceUser> users = new ArrayList<>();
|
||||||
private boolean disabledTakePart = false;
|
private boolean disabledTakePart = false;
|
||||||
|
|
||||||
public ConferenceDto() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public ConferenceDto(@JsonProperty("id") Integer id,
|
public ConferenceDto(@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("title") String title,
|
@JsonProperty("title") String title,
|
||||||
@ -59,15 +52,11 @@ public class ConferenceDto extends NameContainer {
|
|||||||
@JsonProperty("ping") Integer ping,
|
@JsonProperty("ping") Integer ping,
|
||||||
@JsonProperty("beginDate") Date beginDate,
|
@JsonProperty("beginDate") Date beginDate,
|
||||||
@JsonProperty("endDate") Date endDate,
|
@JsonProperty("endDate") Date endDate,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||||
@JsonProperty("userIds") List<Integer> userIds,
|
@JsonProperty("userIds") List<ScienceGroupMemberDto> userIds,
|
||||||
@JsonProperty("paperIds") List<Integer> paperIds,
|
@JsonProperty("paperIds") List<Integer> paperIds,
|
||||||
@JsonProperty("users") List<ConferenceUser> users,
|
@JsonProperty("users") List<ConferenceUser> users) {
|
||||||
@JsonProperty("papers") List<Paper> papers,
|
super(id);
|
||||||
@JsonProperty("notSelectedPapers") List<Paper> notSelectedPapers,
|
|
||||||
@JsonProperty("notSelectedPapers") Boolean disabledTakePart) {
|
|
||||||
this.id = id;
|
|
||||||
this.title = title;
|
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.ping = ping;
|
this.ping = ping;
|
||||||
@ -77,24 +66,25 @@ public class ConferenceDto extends NameContainer {
|
|||||||
this.userIds = userIds;
|
this.userIds = userIds;
|
||||||
this.paperIds = paperIds;
|
this.paperIds = paperIds;
|
||||||
this.users = users;
|
this.users = users;
|
||||||
this.papers = papers;
|
this.title = title;
|
||||||
this.notSelectedPapers = notSelectedPapers;
|
|
||||||
this.disabledTakePart = disabledTakePart;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConferenceDto(Conference conference) {
|
public ConferenceDto(Conference conference) {
|
||||||
this.id = conference.getId();
|
super(conference.getId());
|
||||||
this.title = conference.getTitle();
|
this.title = conference.getTitle();
|
||||||
this.description = conference.getDescription();
|
this.description = conference.getDescription();
|
||||||
this.url = conference.getUrl();
|
this.url = conference.getUrl();
|
||||||
this.ping = conference.getPing();
|
this.ping = conference.getPing();
|
||||||
this.beginDate = conference.getBeginDate();
|
this.beginDate = conference.getBeginDate();
|
||||||
this.endDate = conference.getEndDate();
|
this.endDate = conference.getEndDate();
|
||||||
this.deadlines = conference.getDeadlines();
|
this.deadlines = convert(conference.getDeadlines(), DeadlineDto::new);
|
||||||
this.userIds = convert(conference.getUsers(), BaseEntity::getId);
|
this.userIds = convert(conference.getUsers(), ScienceGroupMemberDto::new);
|
||||||
this.paperIds = convert(conference.getPapers(), BaseEntity::getId);
|
this.paperIds = convert(conference.getPapers(), BaseEntity::getId);
|
||||||
this.users = conference.getUsers();
|
this.users = conference.getUsers();
|
||||||
this.papers = conference.getPapers();
|
}
|
||||||
|
|
||||||
|
public ConferenceDto() {
|
||||||
|
super(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -153,19 +143,19 @@ public class ConferenceDto extends NameContainer {
|
|||||||
this.endDate = endDate;
|
this.endDate = endDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Deadline> getDeadlines() {
|
public List<DeadlineDto> getDeadlines() {
|
||||||
return deadlines;
|
return deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeadlines(List<Deadline> deadlines) {
|
public void setDeadlines(List<DeadlineDto> deadlines) {
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getUserIds() {
|
public List<ScienceGroupMemberDto> getUserIds() {
|
||||||
return userIds;
|
return userIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserIds(List<Integer> userIds) {
|
public void setUserIds(List<ScienceGroupMemberDto> userIds) {
|
||||||
this.userIds = userIds;
|
this.userIds = userIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,14 +167,6 @@ public class ConferenceDto extends NameContainer {
|
|||||||
this.paperIds = paperIds;
|
this.paperIds = paperIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Paper> getPapers() {
|
|
||||||
return papers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPapers(List<Paper> papers) {
|
|
||||||
this.papers = papers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ConferenceUser> getUsers() {
|
public List<ConferenceUser> getUsers() {
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
@ -200,54 +182,4 @@ public class ConferenceDto extends NameContainer {
|
|||||||
public void setDisabledTakePart(boolean disabledTakePart) {
|
public void setDisabledTakePart(boolean disabledTakePart) {
|
||||||
this.disabledTakePart = disabledTakePart;
|
this.disabledTakePart = disabledTakePart;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getRemovedDeadlineIds() {
|
|
||||||
return removedDeadlineIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
|
|
||||||
this.removedDeadlineIds = removedDeadlineIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Paper> getNotSelectedPapers() {
|
|
||||||
return notSelectedPapers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNotSelectedPapers(List<Paper> notSelectedPapers) {
|
|
||||||
this.notSelectedPapers = notSelectedPapers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDatesString() {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.conference.model;
|
package ru.ulstu.activity.conference.model;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -0,0 +1,21 @@
|
|||||||
|
package ru.ulstu.activity.conference.model;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.api.model.ActivityListDto;
|
||||||
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
|
public class ConferenceListDto extends ActivityListDto {
|
||||||
|
private final Set<ScienceGroupMemberDto> members;
|
||||||
|
|
||||||
|
public ConferenceListDto(Conference conference) {
|
||||||
|
super(conference.getId(), conference.getTitle());
|
||||||
|
this.members = convert(conference.getActivityMembers(), ScienceGroupMemberDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ScienceGroupMemberDto> getAuthors() {
|
||||||
|
return members;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.conference.model;
|
package ru.ulstu.activity.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;
|
@ -1,7 +1,7 @@
|
|||||||
package ru.ulstu.conference.repository;
|
package ru.ulstu.activity.conference.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import ru.ulstu.conference.model.ConferenceUser;
|
import ru.ulstu.activity.conference.model.ConferenceUser;
|
||||||
|
|
||||||
public interface ConferenceUserRepository extends JpaRepository<ConferenceUser, Integer> {
|
public interface ConferenceUserRepository extends JpaRepository<ConferenceUser, Integer> {
|
||||||
}
|
}
|
@ -1,10 +1,11 @@
|
|||||||
package ru.ulstu.conference.service;
|
package ru.ulstu.activity.conference.service;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.ulstu.conference.model.Conference;
|
import ru.ulstu.activity.common.service.ActivityNotificationService;
|
||||||
|
import ru.ulstu.activity.conference.model.Conference;
|
||||||
|
import ru.ulstu.activity.ping.service.PingService;
|
||||||
import ru.ulstu.core.util.DateUtils;
|
import ru.ulstu.core.util.DateUtils;
|
||||||
import ru.ulstu.ping.service.PingService;
|
|
||||||
import ru.ulstu.user.service.MailService;
|
import ru.ulstu.user.service.MailService;
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
@ -14,7 +15,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ConferenceNotificationService {
|
public class ConferenceNotificationService extends ActivityNotificationService<Conference> {
|
||||||
|
|
||||||
private final static int YESTERDAY = -1;
|
private final static int YESTERDAY = -1;
|
||||||
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
||||||
@ -37,6 +38,7 @@ public class ConferenceNotificationService {
|
|||||||
public ConferenceNotificationService(MailService mailService,
|
public ConferenceNotificationService(MailService mailService,
|
||||||
UserService userService,
|
UserService userService,
|
||||||
PingService pingService) {
|
PingService pingService) {
|
||||||
|
super(mailService);
|
||||||
this.mailService = mailService;
|
this.mailService = mailService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.pingService = pingService;
|
this.pingService = pingService;
|
@ -1,23 +1,25 @@
|
|||||||
package ru.ulstu.conference.repository;
|
package ru.ulstu.activity.conference.service;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
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.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.activity.api.ActivityRepository;
|
||||||
import ru.ulstu.name.BaseRepository;
|
import ru.ulstu.activity.conference.model.Conference;
|
||||||
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>, BaseRepository {
|
interface ConferenceRepository extends JpaRepository<Conference, Integer>, ActivityRepository<Conference> {
|
||||||
@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 begin_date 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);
|
Page<Conference> findAllActive(Pageable pageable, @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")
|
@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);
|
boolean isPaperAttached(@Param("paperId") Integer paperId);
|
@ -1,10 +1,12 @@
|
|||||||
package ru.ulstu.conference.service;
|
package ru.ulstu.activity.conference.service;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class ConferenceScheduler {
|
public class ConferenceScheduler {
|
||||||
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
||||||
@ -24,14 +26,16 @@ public class ConferenceScheduler {
|
|||||||
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
|
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
|
||||||
public void checkDeadlineBeforeWeek() {
|
public void checkDeadlineBeforeWeek() {
|
||||||
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started");
|
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek started");
|
||||||
conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll());
|
conferenceNotificationService.sendDeadlineNotifications(conferenceService.findAll(0, 100)
|
||||||
|
.getItems().stream().collect(Collectors.toList()));
|
||||||
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished");
|
log.debug("ConferenceScheduler.checkDeadlineBeforeWeek finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara")
|
@Scheduled(cron = "0 0 8 * * *", zone = "Europe/Samara")
|
||||||
public void checkNewPing() {
|
public void checkNewPing() {
|
||||||
log.debug("ConferenceScheduler.checkPing started");
|
log.debug("ConferenceScheduler.checkPing started");
|
||||||
conferenceNotificationService.sendPingNotifications(conferenceService.findAll());
|
conferenceNotificationService.sendPingNotifications(conferenceService.findAll(0, 100)
|
||||||
|
.getItems().stream().collect(Collectors.toList()));
|
||||||
log.debug("ConferenceScheduler.checkPing finished");
|
log.debug("ConferenceScheduler.checkPing finished");
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,154 @@
|
|||||||
|
package ru.ulstu.activity.conference.service;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.activity.common.service.ActivityService;
|
||||||
|
import ru.ulstu.activity.conference.model.Conference;
|
||||||
|
import ru.ulstu.activity.conference.model.ConferenceDashboardDto;
|
||||||
|
import ru.ulstu.activity.conference.model.ConferenceDto;
|
||||||
|
import ru.ulstu.activity.conference.model.ConferenceFilterDto;
|
||||||
|
import ru.ulstu.activity.conference.model.ConferenceListDto;
|
||||||
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.activity.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.activity.paper.service.PaperService;
|
||||||
|
import ru.ulstu.activity.ping.service.PingService;
|
||||||
|
import ru.ulstu.activity.timeline.model.Event;
|
||||||
|
import ru.ulstu.activity.timeline.service.EventService;
|
||||||
|
import ru.ulstu.core.jpa.OffsetablePageRequest;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ConferenceService extends ActivityService<ConferenceListDto, Conference, ConferenceDto> {
|
||||||
|
|
||||||
|
private final ConferenceRepository conferenceRepository;
|
||||||
|
private final ConferenceUserService conferenceUserService;
|
||||||
|
private final DeadlineService deadlineService;
|
||||||
|
private final PaperService paperService;
|
||||||
|
private final UserService userService;
|
||||||
|
private final PingService pingService;
|
||||||
|
private final ConferenceNotificationService conferenceNotificationService;
|
||||||
|
private final EventService eventService;
|
||||||
|
|
||||||
|
public ConferenceService(ConferenceRepository conferenceRepository,
|
||||||
|
ConferenceUserService conferenceUserService,
|
||||||
|
DeadlineService deadlineService,
|
||||||
|
PaperService paperService,
|
||||||
|
UserService userService,
|
||||||
|
PingService pingService,
|
||||||
|
ConferenceNotificationService conferenceNotificationService,
|
||||||
|
EventService eventService) {
|
||||||
|
super(conferenceRepository, conferenceNotificationService, pingService, eventService);
|
||||||
|
this.conferenceRepository = conferenceRepository;
|
||||||
|
this.conferenceUserService = conferenceUserService;
|
||||||
|
this.deadlineService = deadlineService;
|
||||||
|
this.paperService = paperService;
|
||||||
|
this.userService = userService;
|
||||||
|
this.pingService = pingService;
|
||||||
|
this.conferenceNotificationService = conferenceNotificationService;
|
||||||
|
this.eventService = eventService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ConferenceListDto getActivityListDto(Conference entity) {
|
||||||
|
return new ConferenceListDto(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Conference getNewActivity() {
|
||||||
|
return new Conference();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ConferenceDto getNewActivityDto(Conference entity) {
|
||||||
|
return new ConferenceDto(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException {
|
||||||
|
conference.setTitle(conferenceDto.getTitle());
|
||||||
|
conference.setDescription(conferenceDto.getDescription());
|
||||||
|
conference.setUrl(conferenceDto.getUrl());
|
||||||
|
conference.setBeginDate(conferenceDto.getBeginDate());
|
||||||
|
conference.setEndDate(conferenceDto.getEndDate());
|
||||||
|
conference.getPapers().clear();
|
||||||
|
conferenceDto.getPaperIds().forEach(paperId -> conference.getPapers().add(paperService.findById(paperId)));
|
||||||
|
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines()));
|
||||||
|
conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers()));
|
||||||
|
if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) {
|
||||||
|
conferenceDto.getPaperIds().forEach(paperId ->
|
||||||
|
conference.getPapers().add(paperService.findById(paperId)));
|
||||||
|
}
|
||||||
|
return conference;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ConferenceDto> filter(ConferenceFilterDto conferenceFilterDto) {
|
||||||
|
return convert(conferenceRepository.findByUserAndYear(
|
||||||
|
conferenceFilterDto.getFilterUserId() == null ? null : userService.findById(conferenceFilterDto.getFilterUserId()),
|
||||||
|
conferenceFilterDto.getYear()), ConferenceDto::new);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public PageableItems<ConferenceDashboardDto> findAllActiveDto(int offset, int count) {
|
||||||
|
return convertPageable(findAllActive(offset, count), ConferenceDashboardDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageableItems<Conference> findAllActive(int offset, int count) {
|
||||||
|
Page<Conference> activeConferencePage = conferenceRepository
|
||||||
|
.findAllActive(new OffsetablePageRequest(offset, count), new Date());
|
||||||
|
return new PageableItems<>(activeConferencePage.getTotalElements(), activeConferencePage.getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConferenceDto findConferenceById(Integer id) {
|
||||||
|
return new ConferenceDto(findById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Conference findById(Integer id) {
|
||||||
|
return conferenceRepository.getOne(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Conference getActiveConferenceByUser(User user) {
|
||||||
|
return conferenceRepository.findActiveByUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doActionsOnDiffObjects(Conference oldEntity, Conference entity) {
|
||||||
|
if (!entity.getBeginDate().equals(oldEntity.getBeginDate())
|
||||||
|
|| !entity.getEndDate().equals(oldEntity.getEndDate())) {
|
||||||
|
conferenceNotificationService.updateConferencesDatesNotification(entity, oldEntity.getBeginDate(), oldEntity.getEndDate());
|
||||||
|
}
|
||||||
|
entity.getActivityMembers().forEach(author -> {
|
||||||
|
if (!oldEntity.getActivityMembers().contains(author)) {
|
||||||
|
conferenceNotificationService.sendCreateNotification(entity);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
sendNotificationAfterUpdateDeadlines(entity, oldEntity.getDeadlines());
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<Event> getEvents(Conference entity) {
|
||||||
|
return eventService.findByConference(entity);
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
package ru.ulstu.conference.service;
|
package ru.ulstu.activity.conference.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.conference.model.ConferenceUser;
|
import ru.ulstu.activity.conference.model.ConferenceUser;
|
||||||
import ru.ulstu.conference.repository.ConferenceUserRepository;
|
import ru.ulstu.activity.conference.repository.ConferenceUserRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.deadline.model;
|
package ru.ulstu.activity.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;
|
||||||
@ -11,6 +11,7 @@ import javax.persistence.FetchType;
|
|||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Temporal;
|
import javax.persistence.Temporal;
|
||||||
import javax.persistence.TemporalType;
|
import javax.persistence.TemporalType;
|
||||||
|
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.Objects;
|
||||||
@ -24,8 +25,8 @@ public class Deadline extends BaseEntity {
|
|||||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
private Date date;
|
private Date date;
|
||||||
|
|
||||||
@OneToMany(targetEntity = User.class, fetch = FetchType.EAGER)
|
@OneToMany(targetEntity = User.class, fetch = FetchType.LAZY)
|
||||||
private List<User> executors;
|
private List<User> executors = new ArrayList<>();
|
||||||
|
|
||||||
private Boolean done;
|
private Boolean done;
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ public class Deadline extends BaseEntity {
|
|||||||
this.executors = executors;
|
this.executors = executors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getDone() {
|
public Boolean isDone() {
|
||||||
return done;
|
return done;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,61 @@
|
|||||||
|
package ru.ulstu.activity.deadline.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class DeadlineDto {
|
||||||
|
private final Integer id;
|
||||||
|
private final Date date;
|
||||||
|
private final String description;
|
||||||
|
private final List<Integer> executorsIds;
|
||||||
|
private final Boolean done;
|
||||||
|
|
||||||
|
public DeadlineDto() {
|
||||||
|
this.id = null;
|
||||||
|
this.date = null;
|
||||||
|
this.description = null;
|
||||||
|
this.executorsIds = new ArrayList<>();
|
||||||
|
this.done = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeadlineDto(Deadline deadline) {
|
||||||
|
this.id = deadline.getId();
|
||||||
|
this.date = deadline.getDate();
|
||||||
|
this.description = deadline.getDescription();
|
||||||
|
this.executorsIds = deadline.getExecutors()
|
||||||
|
.stream()
|
||||||
|
.map(executor -> executor.getId())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
this.done = deadline.isDone();
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeadlineDto(Date date, String description) {
|
||||||
|
this.id = null;
|
||||||
|
this.date = date;
|
||||||
|
this.description = description;
|
||||||
|
this.executorsIds = new ArrayList<>();
|
||||||
|
this.done = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getExecutorsIds() {
|
||||||
|
return executorsIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean isDone() {
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,14 @@
|
|||||||
package ru.ulstu.deadline.repository;
|
package ru.ulstu.activity.deadline.service;
|
||||||
|
|
||||||
|
|
||||||
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.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public interface DeadlineRepository extends JpaRepository<Deadline, Integer> {
|
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)")
|
@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);
|
Date findByGrantIdAndDate(@Param("id") Integer grantId, @Param("date") Date date);
|
@ -0,0 +1,65 @@
|
|||||||
|
package ru.ulstu.activity.deadline.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.activity.deadline.model.DeadlineDto;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DeadlineService {
|
||||||
|
private final DeadlineRepository deadlineRepository;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
|
public DeadlineService(DeadlineRepository deadlineRepository,
|
||||||
|
UserService userService) {
|
||||||
|
this.deadlineRepository = deadlineRepository;
|
||||||
|
this.userService = userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Deadline> saveOrCreate(List<DeadlineDto> deadlines) {
|
||||||
|
return deadlines
|
||||||
|
.stream()
|
||||||
|
.map(deadline -> {
|
||||||
|
return deadline.getId() != null ? update(deadline) : create(deadline);
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Deadline update(DeadlineDto deadlineDto) {
|
||||||
|
Deadline updateDeadline = deadlineRepository.getOne(deadlineDto.getId());
|
||||||
|
deadlineRepository.save(copyFromDto(updateDeadline, deadlineDto));
|
||||||
|
return updateDeadline;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Deadline create(DeadlineDto deadlineDto) {
|
||||||
|
return deadlineRepository.save(copyFromDto(new Deadline(), deadlineDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Deadline create(Deadline deadline) {
|
||||||
|
return deadlineRepository.save(deadline);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void remove(Integer deadlineId) {
|
||||||
|
deadlineRepository.deleteById(deadlineId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Deadline copyFromDto(Deadline deadline, DeadlineDto deadlineDto) {
|
||||||
|
deadline.setDate(deadlineDto.getDate());
|
||||||
|
deadline.setDescription(deadlineDto.getDescription());
|
||||||
|
deadline.setExecutors(userService.findByIds(deadlineDto.getExecutorsIds()));
|
||||||
|
deadline.setDone(deadlineDto.isDone());
|
||||||
|
return deadline;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date findByGrantIdAndDate(Integer id, Date date) {
|
||||||
|
return deadlineRepository.findByGrantIdAndDate(id, date);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.file;
|
package ru.ulstu.activity.file;
|
||||||
|
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -10,11 +10,11 @@ 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 org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import ru.ulstu.activity.file.model.FileData;
|
||||||
|
import ru.ulstu.activity.file.model.FileDataDto;
|
||||||
|
import ru.ulstu.activity.file.service.FileService;
|
||||||
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.file.model.FileData;
|
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
|
||||||
import ru.ulstu.file.service.FileService;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.file.model;
|
package ru.ulstu.activity.file.model;
|
||||||
|
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.file.model;
|
package ru.ulstu.activity.file.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;
|
@ -0,0 +1,7 @@
|
|||||||
|
package ru.ulstu.activity.file.service;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.ulstu.activity.file.model.FileData;
|
||||||
|
|
||||||
|
interface FileRepository extends JpaRepository<FileData, Integer> {
|
||||||
|
}
|
@ -1,12 +1,11 @@
|
|||||||
package ru.ulstu.file.service;
|
package ru.ulstu.activity.file.service;
|
||||||
|
|
||||||
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.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import ru.ulstu.file.model.FileData;
|
import ru.ulstu.activity.file.model.FileData;
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
import ru.ulstu.activity.file.model.FileDataDto;
|
||||||
import ru.ulstu.file.repostory.FileRepository;
|
import ru.ulstu.activity.paper.model.PaperDto;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -97,13 +96,13 @@ public class FileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private FileData update(FileDataDto fileDataDto) {
|
public 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
|
||||||
private FileData create(FileDataDto fileDataDto) throws IOException {
|
public 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);
|
@ -0,0 +1,82 @@
|
|||||||
|
package ru.ulstu.activity.grant.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ru.ulstu.activity.api.ActivityController;
|
||||||
|
import ru.ulstu.activity.grant.model.GrantDashboardDto;
|
||||||
|
import ru.ulstu.activity.grant.model.GrantDto;
|
||||||
|
import ru.ulstu.activity.grant.model.GrantListDto;
|
||||||
|
import ru.ulstu.activity.grant.service.GrantService;
|
||||||
|
import ru.ulstu.configuration.Constants;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
import ru.ulstu.core.model.response.Response;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(Constants.API_1_0 + "grants")
|
||||||
|
public class GrantController implements ActivityController<GrantListDto, GrantDashboardDto, GrantDto> {
|
||||||
|
private final GrantService grantService;
|
||||||
|
|
||||||
|
public GrantController(GrantService grantService) {
|
||||||
|
this.grantService = grantService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("grab")
|
||||||
|
public void grab() throws IOException, ParseException {
|
||||||
|
grantService.createFromKias();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@GetMapping("list")
|
||||||
|
public Response<PageableItems<GrantListDto>> getList(@RequestParam(value = "offset", defaultValue = "0") int offset,
|
||||||
|
@RequestParam(value = "count", defaultValue = "0") int count) {
|
||||||
|
return new Response<>(grantService.findAllDto(offset, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@GetMapping("dashboard")
|
||||||
|
public Response<PageableItems<GrantDashboardDto>> getDashboard(@RequestParam(value = "offset", defaultValue = "0") int offset,
|
||||||
|
@RequestParam(value = "count", defaultValue = "0") int count) {
|
||||||
|
return new Response<>(grantService.findAllActiveDto(offset, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@GetMapping("{grant-id}")
|
||||||
|
public Response<GrantDto> get(@PathVariable("grant-id") Integer entityId) {
|
||||||
|
return new Response<>(grantService.findDtoById(entityId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@PostMapping
|
||||||
|
public Response<GrantDto> create(@RequestBody @Valid GrantDto entity) {
|
||||||
|
return new Response<>(grantService.create(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@PutMapping
|
||||||
|
public Response<GrantDto> update(@RequestBody @Valid GrantDto entity) {
|
||||||
|
return new Response<>(grantService.update(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@DeleteMapping("{grant-id}")
|
||||||
|
public Response<Boolean> delete(@PathVariable("grant-id") Integer entityId) {
|
||||||
|
return new Response<>(grantService.delete(entityId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@PostMapping("ping/{grant-id}")
|
||||||
|
public void ping(@PathVariable("grant-id") int entityId) {
|
||||||
|
grantService.ping(entityId);
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,14 @@
|
|||||||
package ru.ulstu.grant.model;
|
package ru.ulstu.activity.grant.model;
|
||||||
|
|
||||||
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.activity.common.model.AbstractActivity;
|
||||||
import ru.ulstu.core.model.EventSource;
|
import ru.ulstu.activity.common.model.EventSource;
|
||||||
import ru.ulstu.core.model.UserActivity;
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.activity.file.model.FileData;
|
||||||
import ru.ulstu.file.model.FileData;
|
import ru.ulstu.activity.paper.model.Paper;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.activity.project.model.Project;
|
||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.activity.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.CascadeType;
|
||||||
@ -39,7 +38,7 @@ import java.util.Set;
|
|||||||
@Entity
|
@Entity
|
||||||
@Table(name = "grants")
|
@Table(name = "grants")
|
||||||
@DiscriminatorValue("GRANT")
|
@DiscriminatorValue("GRANT")
|
||||||
public class Grant extends BaseEntity implements UserActivity, EventSource {
|
public class Grant extends AbstractActivity implements EventSource {
|
||||||
public enum GrantStatus {
|
public enum GrantStatus {
|
||||||
APPLICATION("Заявка"),
|
APPLICATION("Заявка"),
|
||||||
ON_COMPETITION("Отправлен на конкурс"),
|
ON_COMPETITION("Отправлен на конкурс"),
|
||||||
@ -138,18 +137,23 @@ public class Grant extends BaseEntity implements UserActivity, EventSource {
|
|||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<User> getRecipients() {
|
public List<User> getRecipients() {
|
||||||
return authors != null ? new ArrayList<>(authors) : Collections.emptyList();
|
return authors != null ? new ArrayList<>(authors) : Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addObjectToEvent(Event event) {
|
public String getSuffix() {
|
||||||
event.setGrant(this);
|
return "гранта";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
@Override
|
||||||
this.title = title;
|
public void addObjectToEvent(Event event) {
|
||||||
|
event.setGrant(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Project getProject() {
|
public Project getProject() {
|
||||||
@ -169,8 +173,8 @@ public class Grant extends BaseEntity implements UserActivity, EventSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<User> getActivityUsers() {
|
public Set<User> getActivityMembers() {
|
||||||
return getAuthors();
|
return authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getLeader() {
|
public User getLeader() {
|
@ -0,0 +1,27 @@
|
|||||||
|
package ru.ulstu.activity.grant.model;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.api.model.ActivityDashboardDto;
|
||||||
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
|
public class GrantDashboardDto extends ActivityDashboardDto {
|
||||||
|
private final Grant.GrantStatus status;
|
||||||
|
private final Set<ScienceGroupMemberDto> members;
|
||||||
|
|
||||||
|
public GrantDashboardDto(Grant grant) {
|
||||||
|
super(grant.getId(), grant.getTitle());
|
||||||
|
this.status = grant.getStatus();
|
||||||
|
this.members = convert(grant.getActivityMembers(), ScienceGroupMemberDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Grant.GrantStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ScienceGroupMemberDto> getAuthors() {
|
||||||
|
return members;
|
||||||
|
}
|
||||||
|
}
|
145
src/main/java/ru/ulstu/activity/grant/model/GrantDto.java
Normal file
145
src/main/java/ru/ulstu/activity/grant/model/GrantDto.java
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
package ru.ulstu.activity.grant.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import ru.ulstu.activity.api.model.ActivityDto;
|
||||||
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
|
import ru.ulstu.activity.deadline.model.DeadlineDto;
|
||||||
|
import ru.ulstu.activity.file.model.FileDataDto;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
|
public class GrantDto extends ActivityDto {
|
||||||
|
@NotEmpty
|
||||||
|
private String title;
|
||||||
|
private Grant.GrantStatus status;
|
||||||
|
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||||
|
private String comment;
|
||||||
|
private List<FileDataDto> files = new ArrayList<>();
|
||||||
|
private List<Integer> projectIds;
|
||||||
|
private Set<ScienceGroupMemberDto> members;
|
||||||
|
private Integer leaderId;
|
||||||
|
private List<Integer> paperIds = new ArrayList<>();
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public GrantDto(@JsonProperty("id") Integer id,
|
||||||
|
@JsonProperty("title") String title,
|
||||||
|
@JsonProperty("status") Grant.GrantStatus status,
|
||||||
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||||
|
@JsonProperty("comment") String comment,
|
||||||
|
@JsonProperty("files") List<FileDataDto> files,
|
||||||
|
@JsonProperty("members") Set<ScienceGroupMemberDto> members,
|
||||||
|
@JsonProperty("leaderId") Integer leaderId,
|
||||||
|
@JsonProperty("paperIds") List<Integer> paperIds) {
|
||||||
|
super(id);
|
||||||
|
this.title = title;
|
||||||
|
this.status = status;
|
||||||
|
this.deadlines = deadlines;
|
||||||
|
this.comment = comment;
|
||||||
|
this.files = files;
|
||||||
|
this.members = members;
|
||||||
|
this.leaderId = leaderId;
|
||||||
|
this.paperIds = paperIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GrantDto(Integer id) {
|
||||||
|
super(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GrantDto(Grant grant) {
|
||||||
|
super(grant.getId());
|
||||||
|
this.title = grant.getTitle();
|
||||||
|
this.status = grant.getStatus();
|
||||||
|
this.deadlines = convert(grant.getDeadlines(), DeadlineDto::new);
|
||||||
|
this.comment = grant.getComment();
|
||||||
|
this.files = convert(grant.getFiles(), FileDataDto::new);
|
||||||
|
this.members = convert(grant.getAuthors(), ScienceGroupMemberDto::new);
|
||||||
|
this.leaderId = grant.getLeader().getId();
|
||||||
|
this.paperIds = convert(grant.getPapers(), paper -> paper.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public GrantDto(String grantTitle, Date deadlineDate) {
|
||||||
|
super(null);
|
||||||
|
this.title = grantTitle;
|
||||||
|
this.deadlines.add(new DeadlineDto(deadlineDate, "Окончание приёма заявок"));
|
||||||
|
this.status = Grant.GrantStatus.LOADED_FROM_KIAS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GrantDto() {
|
||||||
|
super(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Grant.GrantStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Grant.GrantStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DeadlineDto> getDeadlines() {
|
||||||
|
return deadlines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeadlines(List<DeadlineDto> deadlines) {
|
||||||
|
this.deadlines = deadlines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getComment() {
|
||||||
|
return comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setComment(String comment) {
|
||||||
|
this.comment = comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FileDataDto> getFiles() {
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFiles(List<FileDataDto> files) {
|
||||||
|
this.files = files;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ScienceGroupMemberDto> getMembers() {
|
||||||
|
return members;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMembers(Set<ScienceGroupMemberDto> members) {
|
||||||
|
this.members = members;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getLeaderId() {
|
||||||
|
return leaderId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLeaderId(Integer leaderId) {
|
||||||
|
this.leaderId = leaderId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getPaperIds() {
|
||||||
|
return paperIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaperIds(List<Integer> paperIds) {
|
||||||
|
this.paperIds = paperIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getProjectIds() {
|
||||||
|
return projectIds;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package ru.ulstu.activity.grant.model;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.api.model.ActivityListDto;
|
||||||
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
|
public class GrantListDto extends ActivityListDto {
|
||||||
|
|
||||||
|
private final Grant.GrantStatus status;
|
||||||
|
private final Set<ScienceGroupMemberDto> members;
|
||||||
|
|
||||||
|
public GrantListDto(Grant grant) {
|
||||||
|
super(grant.getId(), grant.getTitle());
|
||||||
|
this.status = grant.getStatus();
|
||||||
|
this.members = convert(grant.getActivityMembers(), ScienceGroupMemberDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Grant.GrantStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ScienceGroupMemberDto> getAuthors() {
|
||||||
|
return members;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.grant.page;
|
package ru.ulstu.activity.grant.page;
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.html.DomNode;
|
import com.gargoylesoftware.htmlunit.html.DomNode;
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlElement;
|
import com.gargoylesoftware.htmlunit.html.HtmlElement;
|
@ -1,9 +1,10 @@
|
|||||||
package ru.ulstu.grant.service;
|
package ru.ulstu.activity.grant.service;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.activity.common.service.ActivityNotificationService;
|
||||||
|
import ru.ulstu.activity.grant.model.Grant;
|
||||||
import ru.ulstu.core.util.DateUtils;
|
import ru.ulstu.core.util.DateUtils;
|
||||||
import ru.ulstu.grant.model.Grant;
|
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.service.MailService;
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GrantNotificationService {
|
public class GrantNotificationService extends ActivityNotificationService<Grant> {
|
||||||
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
||||||
private final static String TEMPLATE_DEADLINE = "grantDeadlineNotification";
|
private final static String TEMPLATE_DEADLINE = "grantDeadlineNotification";
|
||||||
private final static String TEMPLATE_CREATE = "grantCreateNotification";
|
private final static String TEMPLATE_CREATE = "grantCreateNotification";
|
||||||
@ -25,10 +26,8 @@ public class GrantNotificationService {
|
|||||||
private final static String TITLE_AUTHORS_CHANGED = "Изменился состав рабочей группы гранта: %s";
|
private final static String TITLE_AUTHORS_CHANGED = "Изменился состав рабочей группы гранта: %s";
|
||||||
private final static String TITLE_LEADER_CHANGED = "Изменился руководитель гранта: %s";
|
private final static String TITLE_LEADER_CHANGED = "Изменился руководитель гранта: %s";
|
||||||
|
|
||||||
private final MailService mailService;
|
|
||||||
|
|
||||||
public GrantNotificationService(MailService mailService) {
|
public GrantNotificationService(MailService mailService) {
|
||||||
this.mailService = mailService;
|
super(mailService);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendDeadlineNotifications(List<Grant> grants, boolean isDeadlineBeforeWeek) {
|
public void sendDeadlineNotifications(List<Grant> grants, boolean isDeadlineBeforeWeek) {
|
||||||
@ -64,10 +63,4 @@ public class GrantNotificationService {
|
|||||||
Map<String, Object> variables = ImmutableMap.of("grant", grant, "oldLeader", oldLeader);
|
Map<String, Object> variables = ImmutableMap.of("grant", grant, "oldLeader", oldLeader);
|
||||||
sendForAllAuthors(variables, grant, TEMPLATE_LEADER_CHANGED, String.format(TITLE_LEADER_CHANGED, grant.getTitle()));
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,14 +1,16 @@
|
|||||||
package ru.ulstu.grant.repository;
|
package ru.ulstu.activity.grant.service;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
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.grant.model.Grant;
|
import ru.ulstu.activity.api.ActivityRepository;
|
||||||
import ru.ulstu.name.BaseRepository;
|
import ru.ulstu.activity.grant.model.Grant;
|
||||||
|
import ru.ulstu.core.repository.JpaDetachableRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface GrantRepository extends JpaRepository<Grant, Integer>, BaseRepository {
|
interface GrantRepository extends JpaDetachableRepository<Grant, Integer>, ActivityRepository<Grant> {
|
||||||
|
|
||||||
List<Grant> findByStatus(Grant.GrantStatus status);
|
List<Grant> findByStatus(Grant.GrantStatus status);
|
||||||
|
|
||||||
@ -21,5 +23,5 @@ public interface GrantRepository extends JpaRepository<Grant, Integer>, BaseRepo
|
|||||||
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
|
|
||||||
@Query("SELECT g FROM Grant g WHERE (g.status <> 'SKIPPED') AND (g.status <> 'COMPLETED')")
|
@Query("SELECT g FROM Grant g WHERE (g.status <> 'SKIPPED') AND (g.status <> 'COMPLETED')")
|
||||||
List<Grant> findAllActive();
|
Page<Grant> findAllActive(Pageable pageable);
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.grant.service;
|
package ru.ulstu.activity.grant.service;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GrantScheduler {
|
public class GrantScheduler {
|
||||||
@ -27,7 +28,8 @@ public class GrantScheduler {
|
|||||||
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
|
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
|
||||||
public void checkDeadlineBeforeWeek() {
|
public void checkDeadlineBeforeWeek() {
|
||||||
log.debug("GrantScheduler.checkDeadlineBeforeWeek started");
|
log.debug("GrantScheduler.checkDeadlineBeforeWeek started");
|
||||||
grantNotificationService.sendDeadlineNotifications(grantService.findAllActive(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
grantNotificationService.sendDeadlineNotifications(grantService.findAllActive(0, 100)
|
||||||
|
.getItems().stream().collect(Collectors.toList()), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||||
log.debug("GrantScheduler.checkDeadlineBeforeWeek finished");
|
log.debug("GrantScheduler.checkDeadlineBeforeWeek finished");
|
||||||
}
|
}
|
||||||
|
|
188
src/main/java/ru/ulstu/activity/grant/service/GrantService.java
Normal file
188
src/main/java/ru/ulstu/activity/grant/service/GrantService.java
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
package ru.ulstu.activity.grant.service;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.activity.common.service.ActivityService;
|
||||||
|
import ru.ulstu.activity.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.activity.file.service.FileService;
|
||||||
|
import ru.ulstu.activity.grant.model.Grant;
|
||||||
|
import ru.ulstu.activity.grant.model.GrantDashboardDto;
|
||||||
|
import ru.ulstu.activity.grant.model.GrantDto;
|
||||||
|
import ru.ulstu.activity.grant.model.GrantListDto;
|
||||||
|
import ru.ulstu.activity.paper.service.PaperService;
|
||||||
|
import ru.ulstu.activity.ping.service.PingService;
|
||||||
|
import ru.ulstu.activity.project.service.ProjectService;
|
||||||
|
import ru.ulstu.activity.timeline.model.Event;
|
||||||
|
import ru.ulstu.activity.timeline.service.EventService;
|
||||||
|
import ru.ulstu.core.jpa.OffsetablePageRequest;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
import ru.ulstu.core.util.DateUtils;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
import static ru.ulstu.activity.grant.model.Grant.GrantStatus.APPLICATION;
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GrantService extends ActivityService<GrantListDto, Grant, GrantDto> {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(GrantService.class);
|
||||||
|
|
||||||
|
private final GrantRepository grantRepository;
|
||||||
|
private final ProjectService projectService;
|
||||||
|
private final DeadlineService deadlineService;
|
||||||
|
private final FileService fileService;
|
||||||
|
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,
|
||||||
|
FileService fileService,
|
||||||
|
DeadlineService deadlineService,
|
||||||
|
ProjectService projectService,
|
||||||
|
UserService userService,
|
||||||
|
PaperService paperService,
|
||||||
|
EventService eventService,
|
||||||
|
GrantNotificationService grantNotificationService,
|
||||||
|
KiasService kiasService,
|
||||||
|
PingService pingService) {
|
||||||
|
super(grantRepository, grantNotificationService, pingService, eventService);
|
||||||
|
this.grantRepository = grantRepository;
|
||||||
|
this.kiasService = kiasService;
|
||||||
|
this.fileService = fileService;
|
||||||
|
this.deadlineService = deadlineService;
|
||||||
|
this.projectService = projectService;
|
||||||
|
this.userService = userService;
|
||||||
|
this.paperService = paperService;
|
||||||
|
this.eventService = eventService;
|
||||||
|
this.grantNotificationService = grantNotificationService;
|
||||||
|
this.pingService = pingService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageableItems<Grant> findAll(int offset, int count) {
|
||||||
|
final Page<Grant> page = grantRepository.findAll(new OffsetablePageRequest(offset, count));
|
||||||
|
return new PageableItems<>(page.getTotalElements(), page.getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GrantListDto getActivityListDto(Grant entity) {
|
||||||
|
return new GrantListDto(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Grant getNewActivity() {
|
||||||
|
return new Grant();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GrantDto getNewActivityDto(Grant entity) {
|
||||||
|
return new GrantDto(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Grant copyFromDto(Grant grant, GrantDto grantDto) throws IOException {
|
||||||
|
grant.setId(grantDto.getId());
|
||||||
|
grant.setComment(grantDto.getComment());
|
||||||
|
grant.setStatus(grantDto.getStatus() == null ? APPLICATION : grantDto.getStatus());
|
||||||
|
grant.setTitle(grantDto.getTitle());
|
||||||
|
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
||||||
|
if (!grant.getFiles().isEmpty()) {
|
||||||
|
grant.setFiles(fileService.saveOrCreate(grantDto.getFiles().stream()
|
||||||
|
.filter(f -> !f.isDeleted())
|
||||||
|
.collect(toList())));
|
||||||
|
}
|
||||||
|
grant.getAuthors().clear();
|
||||||
|
if (grantDto.getMembers() != null && !grantDto.getMembers().isEmpty()) {
|
||||||
|
grantDto.getMembers().forEach(memberDto -> grant.getAuthors().add(userService.findById(memberDto.getId())));
|
||||||
|
}
|
||||||
|
if (grantDto.getLeaderId() != null) {
|
||||||
|
grant.setLeader(userService.findById(grantDto.getLeaderId()));
|
||||||
|
}
|
||||||
|
grant.getPapers().clear();
|
||||||
|
if (grantDto.getPaperIds() != null && !grantDto.getPaperIds().isEmpty()) {
|
||||||
|
grantDto.getPaperIds().forEach(paperIds -> grant.getPapers().add(paperService.findById(paperIds)));
|
||||||
|
}
|
||||||
|
return grant;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doActionsOnDiffObjects(Grant oldEntity, Grant entity) {
|
||||||
|
entity.getAuthors().forEach(author -> {
|
||||||
|
if (!oldEntity.getAuthors().contains(author)) {
|
||||||
|
grantNotificationService.sendAuthorsChangeNotification(entity, oldEntity.getAuthors());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!entity.getLeader().equals(oldEntity.getLeader())) {
|
||||||
|
grantNotificationService.sendLeaderChangeNotification(entity, oldEntity.getLeader());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<Event> getEvents(Grant entity) {
|
||||||
|
return eventService.findByGrant(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Grant.GrantStatus> getGrantStatuses() {
|
||||||
|
return Arrays.asList(Grant.GrantStatus.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean saveFromKias(GrantDto grantDto) throws IOException {
|
||||||
|
grantDto.setTitle(grantDto.getTitle());
|
||||||
|
if (checkUniqueName(grantDto.getTitle(), grantDto.getId())) {
|
||||||
|
Grant grantFromDB = grantRepository.findByTitle(grantDto.getTitle()); //грант с таким же названием из бд
|
||||||
|
if (checkSameDeadline(grantDto, grantFromDB.getId())) { //если дедайны тоже совпадают
|
||||||
|
return false;
|
||||||
|
} else { //иначе грант уже был в системе, но в другом году, поэтому надо создать
|
||||||
|
create(grantDto);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else { //иначе такого гранта ещё нет, поэтому надо создать
|
||||||
|
create(grantDto);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageableItems<GrantDashboardDto> findAllActiveDto(int offset, int count) {
|
||||||
|
return convertPageable(findAllActive(offset, count), GrantDashboardDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageableItems<Grant> findAllActive(int offset, int count) {
|
||||||
|
Page<Grant> activeGrantsPage = grantRepository.findAllActive(new OffsetablePageRequest(offset, count));
|
||||||
|
return new PageableItems<>(activeGrantsPage.getTotalElements(), activeGrantsPage.getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void ping(int grantId) {
|
||||||
|
pingService.addPing(findById(grantId));
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package ru.ulstu.grant.service;
|
package ru.ulstu.activity.grant.service;
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.WebClient;
|
import com.gargoylesoftware.htmlunit.WebClient;
|
||||||
import com.gargoylesoftware.htmlunit.html.DomNode;
|
import com.gargoylesoftware.htmlunit.html.DomNode;
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.activity.grant.model.GrantDto;
|
||||||
|
import ru.ulstu.activity.grant.page.KiasPage;
|
||||||
import ru.ulstu.configuration.ApplicationProperties;
|
import ru.ulstu.configuration.ApplicationProperties;
|
||||||
import ru.ulstu.grant.model.GrantDto;
|
|
||||||
import ru.ulstu.grant.page.KiasPage;
|
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -32,7 +32,7 @@ public class KiasService {
|
|||||||
public List<GrantDto> getNewGrantsDto() throws ParseException, IOException {
|
public List<GrantDto> getNewGrantsDto() throws ParseException, IOException {
|
||||||
Integer leaderId = userService.findOneByLoginIgnoreCase("admin").getId();
|
Integer leaderId = userService.findOneByLoginIgnoreCase("admin").getId();
|
||||||
List<GrantDto> grants = new ArrayList<>();
|
List<GrantDto> grants = new ArrayList<>();
|
||||||
try (final WebClient webClient = new WebClient()) {
|
try (WebClient webClient = new WebClient()) {
|
||||||
for (Integer year : generateGrantYears()) {
|
for (Integer year : generateGrantYears()) {
|
||||||
final HtmlPage page = webClient.getPage(String.format(BASE_URL, CONTEST_STATUS_ID, CONTEST_TYPE, year));
|
final HtmlPage page = webClient.getPage(String.format(BASE_URL, CONTEST_STATUS_ID, CONTEST_TYPE, year));
|
||||||
grants.addAll(getKiasGrants(page));
|
grants.addAll(getKiasGrants(page));
|
@ -0,0 +1,87 @@
|
|||||||
|
package ru.ulstu.activity.paper.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ru.ulstu.activity.api.ActivityController;
|
||||||
|
import ru.ulstu.activity.paper.model.PaperDashboardDto;
|
||||||
|
import ru.ulstu.activity.paper.model.PaperDto;
|
||||||
|
import ru.ulstu.activity.paper.model.PaperListDto;
|
||||||
|
import ru.ulstu.activity.paper.model.PaperStatusDto;
|
||||||
|
import ru.ulstu.activity.paper.model.PaperTypeDto;
|
||||||
|
import ru.ulstu.activity.paper.service.PaperService;
|
||||||
|
import ru.ulstu.configuration.Constants;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
import ru.ulstu.core.model.response.Response;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(Constants.API_1_0 + "papers")
|
||||||
|
public class PaperController implements ActivityController<PaperListDto, PaperDashboardDto, PaperDto> {
|
||||||
|
private final PaperService paperService;
|
||||||
|
|
||||||
|
public PaperController(PaperService paperService) {
|
||||||
|
this.paperService = paperService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("list")
|
||||||
|
public Response<PageableItems<PaperListDto>> getList(@RequestParam(value = "offset", defaultValue = "0") int offset,
|
||||||
|
@RequestParam(value = "count", defaultValue = "10") int count) {
|
||||||
|
return new Response<>(paperService.findAllDto(offset, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("dashboard")
|
||||||
|
public Response<PageableItems<PaperDashboardDto>> getDashboard(@RequestParam(value = "offset", defaultValue = "0") int offset,
|
||||||
|
@RequestParam(value = "count", defaultValue = "10") int count) {
|
||||||
|
return new Response<>(paperService.findAllActiveDto(offset, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("{paper-id}")
|
||||||
|
public Response<PaperDto> get(@PathVariable("paper-id") Integer paperId) {
|
||||||
|
return new Response<>(paperService.findDtoById(paperId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public Response<PaperDto> create(@RequestBody @Valid PaperDto paperDto) {
|
||||||
|
return new Response<>(paperService.create(paperDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping
|
||||||
|
public Response<PaperDto> update(@RequestBody @Valid PaperDto paperDto) {
|
||||||
|
return new Response<>(paperService.update(paperDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{paper-id}")
|
||||||
|
public Response<Boolean> delete(@PathVariable("paper-id") Integer paperId) {
|
||||||
|
return new Response<>(paperService.delete(paperId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("ping/{paper-id}")
|
||||||
|
public void ping(@PathVariable("paper-id") int paperId) {
|
||||||
|
paperService.ping(paperId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("allAuthors")
|
||||||
|
public Response<List<User>> getAllAuthors() {
|
||||||
|
return new Response<>(paperService.getPaperAuthors());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("allTypes")
|
||||||
|
public Response<List<PaperTypeDto>> getPaperTypes() {
|
||||||
|
return new Response<>(paperService.getPaperTypes());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("allStatuses")
|
||||||
|
public Response<List<PaperStatusDto>> getPaperStatuses() {
|
||||||
|
return new Response<>(paperService.getPaperStatuses());
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.paper.model;
|
package ru.ulstu.activity.paper.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,15 +1,14 @@
|
|||||||
package ru.ulstu.paper.model;
|
package ru.ulstu.activity.paper.model;
|
||||||
|
|
||||||
import org.hibernate.annotations.Fetch;
|
import org.hibernate.annotations.Fetch;
|
||||||
import org.hibernate.annotations.FetchMode;
|
import org.hibernate.annotations.FetchMode;
|
||||||
import ru.ulstu.conference.model.Conference;
|
import ru.ulstu.activity.common.model.AbstractActivity;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.activity.common.model.EventSource;
|
||||||
import ru.ulstu.core.model.EventSource;
|
import ru.ulstu.activity.conference.model.Conference;
|
||||||
import ru.ulstu.core.model.UserActivity;
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.activity.file.model.FileData;
|
||||||
import ru.ulstu.file.model.FileData;
|
import ru.ulstu.activity.grant.model.Grant;
|
||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.activity.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.CascadeType;
|
||||||
@ -37,7 +36,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@DiscriminatorValue("PAPER")
|
@DiscriminatorValue("PAPER")
|
||||||
public class Paper extends BaseEntity implements UserActivity, EventSource {
|
public class Paper extends AbstractActivity implements EventSource {
|
||||||
public enum PaperStatus {
|
public enum PaperStatus {
|
||||||
ATTENTION("Обратить внимание"),
|
ATTENTION("Обратить внимание"),
|
||||||
ON_PREPARATION("На подготовке"),
|
ON_PREPARATION("На подготовке"),
|
||||||
@ -93,7 +92,7 @@ public class Paper extends BaseEntity implements UserActivity, EventSource {
|
|||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
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")
|
||||||
@ -109,12 +108,12 @@ public class Paper extends BaseEntity implements UserActivity, EventSource {
|
|||||||
@JoinColumn(name = "paper_id")
|
@JoinColumn(name = "paper_id")
|
||||||
private List<Event> events = new ArrayList<>();
|
private List<Event> events = new ArrayList<>();
|
||||||
|
|
||||||
@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)
|
||||||
private List<FileData> files = new ArrayList<>();
|
private List<FileData> files = new ArrayList<>();
|
||||||
|
|
||||||
@ManyToMany(fetch = FetchType.EAGER)
|
@ManyToMany(fetch = FetchType.LAZY)
|
||||||
private Set<User> authors = new HashSet<>();
|
private Set<User> authors = new HashSet<>();
|
||||||
|
|
||||||
@Column(name = "latex_text")
|
@Column(name = "latex_text")
|
||||||
@ -126,7 +125,7 @@ public class Paper extends BaseEntity implements UserActivity, EventSource {
|
|||||||
@ManyToMany(mappedBy = "papers")
|
@ManyToMany(mappedBy = "papers")
|
||||||
private List<Grant> grants;
|
private List<Grant> grants;
|
||||||
|
|
||||||
@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)
|
||||||
private List<Reference> references = new ArrayList<>();
|
private List<Reference> references = new ArrayList<>();
|
||||||
@ -199,6 +198,10 @@ public class Paper extends BaseEntity implements UserActivity, EventSource {
|
|||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<User> getRecipients() {
|
public List<User> getRecipients() {
|
||||||
return new ArrayList<>(authors);
|
return new ArrayList<>(authors);
|
||||||
@ -209,10 +212,6 @@ public class Paper extends BaseEntity implements UserActivity, EventSource {
|
|||||||
event.setPaper(this);
|
event.setPaper(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<User> getAuthors() {
|
public Set<User> getAuthors() {
|
||||||
return authors;
|
return authors;
|
||||||
}
|
}
|
||||||
@ -262,8 +261,8 @@ public class Paper extends BaseEntity implements UserActivity, EventSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<User> getActivityUsers() {
|
public Set<User> getActivityMembers() {
|
||||||
return getAuthors();
|
return authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Reference> getReferences() {
|
public List<Reference> getReferences() {
|
||||||
@ -323,4 +322,9 @@ public class Paper extends BaseEntity implements UserActivity, EventSource {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(super.hashCode(), title, status, type, createDate, updateDate, deadlines, comment, url, locked, events, files, authors, latexText, conferences, grants);
|
return Objects.hash(super.hashCode(), title, status, type, createDate, updateDate, deadlines, comment, url, locked, events, files, authors, latexText, conferences, grants);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSuffix() {
|
||||||
|
return "статьи";
|
||||||
|
}
|
||||||
}
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package ru.ulstu.activity.paper.model;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.api.model.ActivityDashboardDto;
|
||||||
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
|
public class PaperDashboardDto extends ActivityDashboardDto {
|
||||||
|
private Paper.PaperStatus status;
|
||||||
|
private Set<ScienceGroupMemberDto> authors;
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
public PaperDashboardDto(Paper paper) {
|
||||||
|
super(paper.getId(), paper.getTitle());
|
||||||
|
this.status = paper.getStatus();
|
||||||
|
this.authors = convert(paper.getAuthors(), ScienceGroupMemberDto::new);
|
||||||
|
this.url = paper.getUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Paper.PaperStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Paper.PaperStatus status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ScienceGroupMemberDto> getAuthors() {
|
||||||
|
return authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthors(Set<ScienceGroupMemberDto> authors) {
|
||||||
|
this.authors = authors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,11 @@
|
|||||||
package ru.ulstu.paper.model;
|
package ru.ulstu.activity.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 org.apache.commons.lang3.StringUtils;
|
import ru.ulstu.activity.api.model.ActivityDto;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
import ru.ulstu.activity.deadline.model.DeadlineDto;
|
||||||
import ru.ulstu.user.model.UserDto;
|
import ru.ulstu.activity.file.model.FileDataDto;
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
@ -13,14 +13,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.Date;
|
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 static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class PaperDto {
|
public class PaperDto extends ActivityDto {
|
||||||
private final static int MAX_AUTHORS_LENGTH = 60;
|
|
||||||
|
|
||||||
private Integer id;
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
@Size(min = 3, max = 254)
|
@Size(min = 3, max = 254)
|
||||||
private String title;
|
private String title;
|
||||||
@ -29,22 +25,19 @@ public class PaperDto {
|
|||||||
private Date createDate;
|
private Date createDate;
|
||||||
private Date updateDate;
|
private Date updateDate;
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||||
private String comment;
|
private String comment;
|
||||||
private String url;
|
private String url;
|
||||||
private Boolean locked;
|
private Boolean locked;
|
||||||
private List<FileDataDto> files = new ArrayList<>();
|
private List<FileDataDto> files = new ArrayList<>();
|
||||||
private Set<Integer> authorIds;
|
private Set<ScienceGroupMemberDto> authors;
|
||||||
private Set<UserDto> authors;
|
|
||||||
private Integer filterAuthorId;
|
|
||||||
private String latexText;
|
|
||||||
private List<ReferenceDto> references = new ArrayList<>();
|
|
||||||
private ReferenceDto.FormatStandard formatStandard = ReferenceDto.FormatStandard.GOST;
|
|
||||||
|
|
||||||
public PaperDto() {
|
public String getLatexText() {
|
||||||
deadlines.add(new Deadline());
|
return latexText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String latexText;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public PaperDto(@JsonProperty("id") Integer id,
|
public PaperDto(@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("title") String title,
|
@JsonProperty("title") String title,
|
||||||
@ -52,17 +45,13 @@ public class PaperDto {
|
|||||||
@JsonProperty("type") Paper.PaperType type,
|
@JsonProperty("type") Paper.PaperType type,
|
||||||
@JsonProperty("createDate") Date createDate,
|
@JsonProperty("createDate") Date createDate,
|
||||||
@JsonProperty("updateDate") Date updateDate,
|
@JsonProperty("updateDate") Date updateDate,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||||
@JsonProperty("comment") String comment,
|
@JsonProperty("comment") String comment,
|
||||||
@JsonProperty("latex_text") String latexText,
|
|
||||||
@JsonProperty("url") String url,
|
@JsonProperty("url") String url,
|
||||||
@JsonProperty("locked") Boolean locked,
|
@JsonProperty("locked") Boolean locked,
|
||||||
@JsonProperty("files") List<FileDataDto> files,
|
@JsonProperty("files") List<FileDataDto> files,
|
||||||
@JsonProperty("authorIds") Set<Integer> authorIds,
|
@JsonProperty("authors") Set<ScienceGroupMemberDto> authors) {
|
||||||
@JsonProperty("authors") Set<UserDto> authors,
|
super(id);
|
||||||
@JsonProperty("references") List<ReferenceDto> references,
|
|
||||||
@JsonProperty("formatStandard") ReferenceDto.FormatStandard formatStandard) {
|
|
||||||
this.id = id;
|
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@ -71,38 +60,24 @@ public class PaperDto {
|
|||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.latexText = latexText;
|
|
||||||
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) {
|
||||||
this.id = paper.getId();
|
super(paper.getId());
|
||||||
this.title = paper.getTitle();
|
this.title = paper.getTitle();
|
||||||
this.status = paper.getStatus();
|
this.status = paper.getStatus();
|
||||||
this.type = paper.getType();
|
this.type = paper.getType();
|
||||||
this.createDate = paper.getCreateDate();
|
this.createDate = paper.getCreateDate();
|
||||||
this.updateDate = paper.getUpdateDate();
|
this.updateDate = paper.getUpdateDate();
|
||||||
this.deadlines = paper.getDeadlines();
|
this.deadlines = convert(paper.getDeadlines(), DeadlineDto::new);
|
||||||
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.authors = convert(paper.getAuthors(), ScienceGroupMemberDto::new);
|
||||||
this.authors = convert(paper.getAuthors(), UserDto::new);
|
|
||||||
this.references = convert(paper.getReferences(), ReferenceDto::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Integer id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
@ -145,11 +120,11 @@ public class PaperDto {
|
|||||||
this.updateDate = updateDate;
|
this.updateDate = updateDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Deadline> getDeadlines() {
|
public List<DeadlineDto> getDeadlines() {
|
||||||
return deadlines;
|
return deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeadlines(List<Deadline> deadlines) {
|
public void setDeadlines(List<DeadlineDto> deadlines) {
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,22 +152,14 @@ public class PaperDto {
|
|||||||
this.files = files;
|
this.files = files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<UserDto> getAuthors() {
|
public Set<ScienceGroupMemberDto> getAuthors() {
|
||||||
return authors;
|
return authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthors(Set<UserDto> authors) {
|
public void setAuthors(Set<ScienceGroupMemberDto> authors) {
|
||||||
this.authors = authors;
|
this.authors = authors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Integer> getAuthorIds() {
|
|
||||||
return authorIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthorIds(Set<Integer> authorIds) {
|
|
||||||
this.authorIds = authorIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
public String getUrl() {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
@ -200,43 +167,4 @@ public class PaperDto {
|
|||||||
public void setUrl(String url) {
|
public void setUrl(String url) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLatexText() {
|
|
||||||
return latexText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLatexText(String latexText) {
|
|
||||||
this.latexText = latexText;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAuthorsString() {
|
|
||||||
return StringUtils.abbreviate(authors
|
|
||||||
.stream()
|
|
||||||
.map(author -> author.getLastName())
|
|
||||||
.collect(Collectors.joining(", ")), MAX_AUTHORS_LENGTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getFilterAuthorId() {
|
|
||||||
return filterAuthorId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFilterAuthorId(Integer 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,27 +1,27 @@
|
|||||||
package ru.ulstu.paper.model;
|
package ru.ulstu.activity.paper.model;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PaperListDto {
|
public class PaperFilterListDto {
|
||||||
private List<PaperDto> papers;
|
private List<PaperListDto> papers;
|
||||||
private Integer filterAuthorId;
|
private Integer filterAuthorId;
|
||||||
private Integer paperDeleteId;
|
private Integer paperDeleteId;
|
||||||
private Integer year;
|
private Integer year;
|
||||||
|
|
||||||
public PaperListDto() {
|
public PaperFilterListDto() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public PaperListDto(List<PaperDto> paperDtos, Integer filterAuthorId, Integer year) {
|
public PaperFilterListDto(List<PaperListDto> paperDtos, Integer filterAuthorId, Integer year) {
|
||||||
this.papers = paperDtos;
|
this.papers = paperDtos;
|
||||||
this.filterAuthorId = filterAuthorId;
|
this.filterAuthorId = filterAuthorId;
|
||||||
this.year = year;
|
this.year = year;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PaperDto> getPapers() {
|
public List<PaperListDto> getPapers() {
|
||||||
return papers;
|
return papers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPapers(List<PaperDto> papers) {
|
public void setPapers(List<PaperListDto> papers) {
|
||||||
this.papers = papers;
|
this.papers = papers;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
|||||||
|
package ru.ulstu.activity.paper.model;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.api.model.ActivityListDto;
|
||||||
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
|
public class PaperListDto extends ActivityListDto {
|
||||||
|
private final Paper.PaperStatus status;
|
||||||
|
private final Set<ScienceGroupMemberDto> authors;
|
||||||
|
|
||||||
|
public PaperListDto(Paper paper) {
|
||||||
|
super(paper.getId(), paper.getTitle());
|
||||||
|
this.status = paper.getStatus();
|
||||||
|
this.authors = convert(paper.getAuthors(), ScienceGroupMemberDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Paper.PaperStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<ScienceGroupMemberDto> getAuthors() {
|
||||||
|
return authors;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package ru.ulstu.activity.paper.model;
|
||||||
|
|
||||||
|
public class PaperStatusDto {
|
||||||
|
private final String id;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public PaperStatusDto(Paper.PaperStatus status) {
|
||||||
|
this.id = status.name();
|
||||||
|
this.name = status.getStatusName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package ru.ulstu.activity.paper.model;
|
||||||
|
|
||||||
|
public class PaperTypeDto {
|
||||||
|
private final String id;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public PaperTypeDto(Paper.PaperType type) {
|
||||||
|
this.id = type.name();
|
||||||
|
this.name = type.getTypeName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.paper.model;
|
package ru.ulstu.activity.paper.model;
|
||||||
|
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.paper.model;
|
package ru.ulstu.activity.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;
|
@ -1,8 +1,8 @@
|
|||||||
package ru.ulstu.paper.service;
|
package ru.ulstu.activity.paper.service;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.ulstu.file.service.FileService;
|
import ru.ulstu.activity.file.service.FileService;
|
||||||
import ru.ulstu.paper.model.PaperDto;
|
import ru.ulstu.activity.paper.model.PaperDto;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
@ -1,9 +1,9 @@
|
|||||||
package ru.ulstu.paper.service;
|
package ru.ulstu.activity.paper.service;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.activity.common.strategy.api.EntityCreateStrategy;
|
||||||
|
import ru.ulstu.activity.paper.model.Paper;
|
||||||
import ru.ulstu.core.util.DateUtils;
|
import ru.ulstu.core.util.DateUtils;
|
||||||
import ru.ulstu.paper.model.Paper;
|
|
||||||
import ru.ulstu.strategy.api.EntityCreateStrategy;
|
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -21,7 +21,7 @@ public class PaperCreateStrategy extends EntityCreateStrategy<Paper> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<Paper> getActiveEntities() {
|
protected List<Paper> getActiveEntities() {
|
||||||
return paperService.findAll();
|
return (List<Paper>) paperService.findAll(0, 100).getItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
@ -1,17 +1,20 @@
|
|||||||
package ru.ulstu.paper.service;
|
package ru.ulstu.activity.paper.service;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.activity.common.service.ActivityNotificationService;
|
||||||
|
import ru.ulstu.activity.paper.model.Paper;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
import ru.ulstu.core.util.DateUtils;
|
import ru.ulstu.core.util.DateUtils;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.service.MailService;
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PaperNotificationService {
|
public class PaperNotificationService extends ActivityNotificationService<Paper> {
|
||||||
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
||||||
private final static String TEMPLATE_DEADLINE = "paperDeadlineNotification";
|
private final static String TEMPLATE_DEADLINE = "paperDeadlineNotification";
|
||||||
private final static String TEMPLATE_CREATE = "paperCreateNotification";
|
private final static String TEMPLATE_CREATE = "paperCreateNotification";
|
||||||
@ -23,16 +26,13 @@ public class PaperNotificationService {
|
|||||||
private final static String TITLE_STATUS_CHANGED = "Изменился статус статьи";
|
private final static String TITLE_STATUS_CHANGED = "Изменился статус статьи";
|
||||||
private final static String TITLE_FAILED = "Статья провалена";
|
private final static String TITLE_FAILED = "Статья провалена";
|
||||||
|
|
||||||
|
|
||||||
private final MailService mailService;
|
|
||||||
|
|
||||||
public PaperNotificationService(MailService mailService) {
|
public PaperNotificationService(MailService mailService) {
|
||||||
this.mailService = mailService;
|
super(mailService);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendDeadlineNotifications(List<Paper> papers, boolean isDeadlineBeforeWeek) {
|
public void sendDeadlineNotifications(PageableItems<Paper> papers, boolean isDeadlineBeforeWeek) {
|
||||||
Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION);
|
Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION);
|
||||||
papers
|
papers.getItems()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(paper -> needToSendDeadlineNotification(paper, now, isDeadlineBeforeWeek))
|
.filter(paper -> needToSendDeadlineNotification(paper, now, isDeadlineBeforeWeek))
|
||||||
.forEach(paper -> sendMessageDeadline(paper));
|
.forEach(paper -> sendMessageDeadline(paper));
|
||||||
@ -47,25 +47,35 @@ 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 = ImmutableMap.of("paper", paper);
|
||||||
sendForAllAuhtors(variables, paper, TEMPLATE_DEADLINE, TITLE_DEADLINE);
|
sendForAllAuthors(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 = ImmutableMap.of("paper", paper);
|
||||||
sendForAllAuhtors(variables, paper, TEMPLATE_CREATE, TITLE_CREATE);
|
sendForAllAuthors(variables, paper, TEMPLATE_CREATE, TITLE_CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCreateNotification(Paper paper, User author) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("paper", paper);
|
||||||
|
sendForAuthor(variables, author, TEMPLATE_CREATE, TITLE_CREATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCreateNotification(Paper paper, Set<User> oldAuthors) {
|
||||||
|
paper.getAuthors()
|
||||||
|
.stream()
|
||||||
|
.filter(author -> !oldAuthors.contains(author))
|
||||||
|
.forEach(author -> sendCreateNotification(paper, author));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) {
|
||||||
|
if (paper.getStatus() != oldStatus) {
|
||||||
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
|
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
|
||||||
sendForAllAuhtors(variables, paper, TEMPLATE_STATUS_CHANGED, TITLE_STATUS_CHANGED);
|
sendForAllAuthors(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 = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
|
||||||
sendForAllAuhtors(variables, paper, TEMPLATE_FAILED, TITLE_FAILED);
|
sendForAllAuthors(variables, paper, TEMPLATE_FAILED, TITLE_FAILED);
|
||||||
}
|
|
||||||
|
|
||||||
private void sendForAllAuhtors(Map<String, Object> variables, Paper paper, String template, String title) {
|
|
||||||
paper.getAuthors().forEach(author -> mailService.sendEmailFromTemplate(variables, author, template, title));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,14 +1,17 @@
|
|||||||
package ru.ulstu.paper.repository;
|
package ru.ulstu.activity.paper.service;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
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.paper.model.Paper;
|
import ru.ulstu.activity.api.ActivityRepository;
|
||||||
|
import ru.ulstu.activity.paper.model.Paper;
|
||||||
|
import ru.ulstu.core.repository.JpaDetachableRepository;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface PaperRepository extends JpaRepository<Paper, Integer> {
|
interface PaperRepository extends JpaDetachableRepository<Paper, Integer>, ActivityRepository<Paper> {
|
||||||
|
|
||||||
@Query("SELECT p FROM Paper p WHERE (:author IS NULL OR :author MEMBER OF p.authors) AND (YEAR(p.createDate) = :year OR :year IS NULL)")
|
@Query("SELECT p FROM Paper p WHERE (:author IS NULL OR :author MEMBER OF p.authors) AND (YEAR(p.createDate) = :year OR :year IS NULL)")
|
||||||
List<Paper> filter(@Param("author") User author, @Param("year") Integer year);
|
List<Paper> filter(@Param("author") User author, @Param("year") Integer year);
|
||||||
@ -24,4 +27,13 @@ public interface PaperRepository extends JpaRepository<Paper, Integer> {
|
|||||||
List<Paper> findByConferencesIsNullAndStatusNot(Paper.PaperStatus status);
|
List<Paper> findByConferencesIsNullAndStatusNot(Paper.PaperStatus status);
|
||||||
|
|
||||||
List<Paper> findByIdNotInAndConferencesIsNullAndStatusNot(List<Integer> paperIds, Paper.PaperStatus status);
|
List<Paper> findByIdNotInAndConferencesIsNullAndStatusNot(List<Integer> paperIds, Paper.PaperStatus status);
|
||||||
|
|
||||||
|
@Query("SELECT p FROM Paper p WHERE p.status NOT IN (:statuses)")
|
||||||
|
Page<Paper> findAllWithoutStatuses(Pageable pageable, @Param("statuses") Paper.PaperStatus... statuses);
|
||||||
|
|
||||||
|
@Query("SELECT p FROM Paper p ")
|
||||||
|
Page<Paper> findAll(Pageable pageable);
|
||||||
|
|
||||||
|
@Query("SELECT title FROM Paper p WHERE (p.title = :name) AND (:id IS NULL OR p.id != :id) ")
|
||||||
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.paper.service;
|
package ru.ulstu.activity.paper.service;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -24,14 +24,14 @@ public class PaperScheduler {
|
|||||||
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
|
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
|
||||||
public void checkDeadlineBeforeWeek() {
|
public void checkDeadlineBeforeWeek() {
|
||||||
log.debug("PaperScheduler.checkDeadlineBeforeWeek started");
|
log.debug("PaperScheduler.checkDeadlineBeforeWeek started");
|
||||||
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
paperNotificationService.sendDeadlineNotifications(paperService.findAll(0, 100), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||||
log.debug("PaperScheduler.checkDeadlineBeforeWeek finished");
|
log.debug("PaperScheduler.checkDeadlineBeforeWeek finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara")
|
@Scheduled(cron = "0 0 8 * * ?", zone = "Europe/Samara")
|
||||||
public void checkDeadlineAfterWeek() {
|
public void checkDeadlineAfterWeek() {
|
||||||
log.debug("PaperScheduler.checkDeadlineAfterWeek started");
|
log.debug("PaperScheduler.checkDeadlineAfterWeek started");
|
||||||
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
paperNotificationService.sendDeadlineNotifications(paperService.findAll(0, 100), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||||
log.debug("PaperScheduler.checkDeadlineAfterWeek finished");
|
log.debug("PaperScheduler.checkDeadlineAfterWeek finished");
|
||||||
}
|
}
|
||||||
|
|
201
src/main/java/ru/ulstu/activity/paper/service/PaperService.java
Normal file
201
src/main/java/ru/ulstu/activity/paper/service/PaperService.java
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
package ru.ulstu.activity.paper.service;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.activity.common.service.ActivityService;
|
||||||
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.activity.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.activity.file.service.FileService;
|
||||||
|
import ru.ulstu.activity.paper.model.Paper;
|
||||||
|
import ru.ulstu.activity.paper.model.PaperDashboardDto;
|
||||||
|
import ru.ulstu.activity.paper.model.PaperDto;
|
||||||
|
import ru.ulstu.activity.paper.model.PaperListDto;
|
||||||
|
import ru.ulstu.activity.paper.model.PaperStatusDto;
|
||||||
|
import ru.ulstu.activity.paper.model.PaperTypeDto;
|
||||||
|
import ru.ulstu.activity.ping.service.PingService;
|
||||||
|
import ru.ulstu.activity.timeline.model.Event;
|
||||||
|
import ru.ulstu.activity.timeline.service.EventService;
|
||||||
|
import ru.ulstu.core.jpa.OffsetablePageRequest;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty;
|
||||||
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
|
import static ru.ulstu.activity.paper.model.Paper.PaperStatus.ATTENTION;
|
||||||
|
import static ru.ulstu.activity.paper.model.Paper.PaperStatus.COMPLETED;
|
||||||
|
import static ru.ulstu.activity.paper.model.Paper.PaperStatus.DRAFT;
|
||||||
|
import static ru.ulstu.activity.paper.model.Paper.PaperStatus.FAILED;
|
||||||
|
import static ru.ulstu.activity.paper.model.Paper.PaperStatus.ON_PREPARATION;
|
||||||
|
import static ru.ulstu.activity.paper.model.Paper.PaperType.OTHER;
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PaperService extends ActivityService<PaperListDto, Paper, PaperDto> {
|
||||||
|
private final PaperNotificationService paperNotificationService;
|
||||||
|
private final PaperRepository paperRepository;
|
||||||
|
private final UserService userService;
|
||||||
|
private final DeadlineService deadlineService;
|
||||||
|
private final FileService fileService;
|
||||||
|
private final EventService eventService;
|
||||||
|
private final PingService pingService;
|
||||||
|
|
||||||
|
public PaperService(PaperRepository paperRepository,
|
||||||
|
FileService fileService,
|
||||||
|
PaperNotificationService paperNotificationService,
|
||||||
|
UserService userService,
|
||||||
|
DeadlineService deadlineService,
|
||||||
|
EventService eventService,
|
||||||
|
PingService pingService) {
|
||||||
|
super(paperRepository, paperNotificationService, pingService, eventService);
|
||||||
|
this.paperRepository = paperRepository;
|
||||||
|
this.fileService = fileService;
|
||||||
|
this.paperNotificationService = paperNotificationService;
|
||||||
|
this.userService = userService;
|
||||||
|
this.deadlineService = deadlineService;
|
||||||
|
this.eventService = eventService;
|
||||||
|
this.pingService = pingService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PageableItems<PaperDashboardDto> findAllActiveDto(int offset, int count) {
|
||||||
|
return convertPageable(findAllActive(offset, count), PaperDashboardDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PageableItems<Paper> findAll(int offset, int count) {
|
||||||
|
final Page<Paper> page = paperRepository.findAll(new OffsetablePageRequest(offset, count));
|
||||||
|
return new PageableItems<>(page.getTotalElements(), sortPapers(page.getContent()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PaperListDto getActivityListDto(Paper entity) {
|
||||||
|
return new PaperListDto(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Paper getNewActivity() {
|
||||||
|
return new Paper();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PaperDto getNewActivityDto(Paper entity) {
|
||||||
|
return new PaperDto(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageableItems<Paper> findAllActive(int offset, int count) {
|
||||||
|
Page<Paper> activePapersPage = paperRepository.findAllWithoutStatuses(new OffsetablePageRequest(offset, count), COMPLETED, FAILED);
|
||||||
|
return new PageableItems<>(activePapersPage.getTotalElements(), sortPapers(activePapersPage.getContent()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<Event> getEvents(Paper entity) {
|
||||||
|
return eventService.findByPaper(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doActionsOnDiffObjects(Paper oldEntity, Paper entity) {
|
||||||
|
if (oldEntity.getStatus() != entity.getStatus()) {
|
||||||
|
paperNotificationService.statusChangeNotification(entity, oldEntity.getStatus());
|
||||||
|
}
|
||||||
|
if (!oldEntity.getAuthors().equals(entity.getAuthors())) {
|
||||||
|
paperNotificationService.sendCreateNotification(entity, oldEntity.getAuthors());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Paper copyFromDto(Paper paper, PaperDto paperDto) {
|
||||||
|
paper.setComment(paperDto.getComment());
|
||||||
|
paper.setUrl(paperDto.getUrl());
|
||||||
|
paper.setCreateDate(paper.getCreateDate() == null ? new Date() : paper.getCreateDate());
|
||||||
|
paper.setLocked(paperDto.getLocked());
|
||||||
|
paper.setStatus(paperDto.getStatus() == null ? DRAFT : paperDto.getStatus());
|
||||||
|
paper.setType(paperDto.getType() == null ? OTHER : paperDto.getType());
|
||||||
|
paper.setTitle(paperDto.getTitle());
|
||||||
|
paper.setUpdateDate(new Date());
|
||||||
|
paper.setDeadlines(deadlineService.saveOrCreate(paperDto.getDeadlines()));
|
||||||
|
//TODO: move to service
|
||||||
|
try {
|
||||||
|
if (paperDto.getFiles() != null) {
|
||||||
|
paper.setFiles(fileService.saveOrCreate(paperDto.getFiles().stream()
|
||||||
|
.filter(f -> !f.isDeleted())
|
||||||
|
.collect(toList())));
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
paper.getAuthors().clear();
|
||||||
|
if (isNotEmpty(paperDto.getAuthors())) {
|
||||||
|
paperDto.getAuthors().forEach(authors -> paper.getAuthors().add(userService.findById(authors.getId())));
|
||||||
|
}
|
||||||
|
return paper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PaperStatusDto> getPaperStatuses() {
|
||||||
|
return convert(Arrays.asList(Paper.PaperStatus.values()), PaperStatusDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PaperTypeDto> getPaperTypes() {
|
||||||
|
return convert(Arrays.asList(Paper.PaperType.values()), PaperTypeDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Paper create(String title, User user, Date deadlineDate) {
|
||||||
|
Paper paper = new Paper();
|
||||||
|
paper.setTitle(title);
|
||||||
|
paper.getAuthors().add(user);
|
||||||
|
paper.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн"));
|
||||||
|
paper.setCreateDate(new Date());
|
||||||
|
paper.setUpdateDate(new Date());
|
||||||
|
paper.setStatus(DRAFT);
|
||||||
|
paper.setType(OTHER);
|
||||||
|
|
||||||
|
return create(paper);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Paper> sortPapers(List<Paper> papers) {
|
||||||
|
return papers.stream().sorted((paper1, paper2) -> {
|
||||||
|
int statusCompareResult =
|
||||||
|
Integer.valueOf(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper1.getStatus()))
|
||||||
|
.compareTo(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper2.getStatus()));
|
||||||
|
if (statusCompareResult != 0) {
|
||||||
|
return statusCompareResult;
|
||||||
|
}
|
||||||
|
return paper1.getTitle().compareTo(paper2.getTitle());
|
||||||
|
}).collect(toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeFailedPapers() {
|
||||||
|
List<Paper> papers = paperRepository.findAll()
|
||||||
|
.stream()
|
||||||
|
.filter(paper -> paper.lastDeadlineFailed()
|
||||||
|
&& (paper.getStatus() == ON_PREPARATION
|
||||||
|
|| paper.getStatus() == DRAFT
|
||||||
|
|| paper.getStatus() == ATTENTION))
|
||||||
|
.collect(toList());
|
||||||
|
papers.forEach(paper -> {
|
||||||
|
Paper.PaperStatus oldStatus = paper.getStatus();
|
||||||
|
paper.setStatus(Paper.PaperStatus.FAILED);
|
||||||
|
paperRepository.save(paper);
|
||||||
|
paperNotificationService.sendFailedNotification(paper, oldStatus);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(PaperDto paperDto) {
|
||||||
|
if (isEmpty(paperDto.getId())) {
|
||||||
|
create(paperDto);
|
||||||
|
} else {
|
||||||
|
update(paperDto);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<User> getPaperAuthors() {
|
||||||
|
return userService.findAll();
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
package ru.ulstu.paper.repository;
|
package ru.ulstu.activity.paper.service;
|
||||||
|
|
||||||
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.jpa.repository.Query;
|
||||||
import ru.ulstu.paper.model.Reference;
|
import ru.ulstu.activity.paper.model.Reference;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -1,15 +1,15 @@
|
|||||||
package ru.ulstu.ping.model;
|
package ru.ulstu.activity.ping.model;
|
||||||
|
|
||||||
import org.hibernate.annotations.Any;
|
import org.hibernate.annotations.Any;
|
||||||
import org.hibernate.annotations.AnyMetaDef;
|
import org.hibernate.annotations.AnyMetaDef;
|
||||||
import org.hibernate.annotations.MetaValue;
|
import org.hibernate.annotations.MetaValue;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import ru.ulstu.conference.model.Conference;
|
import ru.ulstu.activity.common.model.AbstractActivity;
|
||||||
|
import ru.ulstu.activity.conference.model.Conference;
|
||||||
|
import ru.ulstu.activity.grant.model.Grant;
|
||||||
|
import ru.ulstu.activity.paper.model.Paper;
|
||||||
|
import ru.ulstu.activity.project.model.Project;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
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 ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
@ -50,7 +50,7 @@ public class Ping extends BaseEntity {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
@JoinColumn(name = "activity_id")
|
@JoinColumn(name = "activity_id")
|
||||||
private UserActivity activity;
|
private AbstractActivity activity;
|
||||||
|
|
||||||
public Ping() {
|
public Ping() {
|
||||||
}
|
}
|
||||||
@ -76,11 +76,11 @@ public class Ping extends BaseEntity {
|
|||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserActivity getActivity() {
|
public AbstractActivity getActivity() {
|
||||||
return this.activity;
|
return this.activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActivity(UserActivity activity) {
|
public void setActivity(AbstractActivity activity) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.ping.model;
|
package ru.ulstu.activity.ping.model;
|
||||||
|
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
@ -1,15 +1,15 @@
|
|||||||
package ru.ulstu.ping.repository;
|
package ru.ulstu.activity.ping.service;
|
||||||
|
|
||||||
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.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.activity.conference.model.Conference;
|
||||||
import ru.ulstu.ping.model.Ping;
|
import ru.ulstu.activity.ping.model.Ping;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface PingRepository extends JpaRepository<Ping, Integer> {
|
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)")
|
@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);
|
long countByConferenceAndDate(@Param("conference") Conference conference, @Param("day") Integer day, @Param("month") Integer month, @Param("year") Integer year);
|
@ -1,14 +1,13 @@
|
|||||||
package ru.ulstu.ping.service;
|
package ru.ulstu.activity.ping.service;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.ulstu.core.model.UserActivity;
|
import ru.ulstu.activity.common.model.AbstractActivity;
|
||||||
import ru.ulstu.ping.model.Ping;
|
import ru.ulstu.activity.ping.model.Ping;
|
||||||
import ru.ulstu.ping.model.PingInfo;
|
import ru.ulstu.activity.ping.model.PingInfo;
|
||||||
import ru.ulstu.ping.repository.PingRepository;
|
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.service.MailService;
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
@ -19,10 +18,10 @@ import java.util.Set;
|
|||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PingScheduler {
|
public class PingScheduler {
|
||||||
|
private final static String PING_MAIL_SUBJECT = "Ping статистика";
|
||||||
private final Logger log = LoggerFactory.getLogger(PingScheduler.class);
|
private final Logger log = LoggerFactory.getLogger(PingScheduler.class);
|
||||||
private final PingRepository pingRepository;
|
private final PingRepository pingRepository;
|
||||||
private final MailService mailService;
|
private final MailService mailService;
|
||||||
private final static String PING_MAIL_SUBJECT = "Ping статистика";
|
|
||||||
|
|
||||||
public PingScheduler(PingRepository pingRepository, MailService mailService) {
|
public PingScheduler(PingRepository pingRepository, MailService mailService) {
|
||||||
this.pingRepository = pingRepository;
|
this.pingRepository = pingRepository;
|
||||||
@ -37,8 +36,8 @@ public class PingScheduler {
|
|||||||
List<PingInfo> pingInfos = new ArrayList<>();
|
List<PingInfo> pingInfos = new ArrayList<>();
|
||||||
|
|
||||||
for (Ping ping : pingRepository.findByDate(java.sql.Date.valueOf(LocalDate.now().minusWeeks(1)))) {
|
for (Ping ping : pingRepository.findByDate(java.sql.Date.valueOf(LocalDate.now().minusWeeks(1)))) {
|
||||||
UserActivity pingActivity = ping.getActivity();
|
AbstractActivity pingActivity = ping.getActivity();
|
||||||
Set<User> users = pingActivity.getActivityUsers();
|
Set<User> users = pingActivity.getActivityMembers();
|
||||||
|
|
||||||
for (User user : users) {
|
for (User user : users) {
|
||||||
PingInfo userPing = pingInfos.stream().filter(u -> u.getUser() == user).findFirst().orElse(null);
|
PingInfo userPing = pingInfos.stream().filter(u -> u.getUser() == user).findFirst().orElse(null);
|
@ -1,14 +1,12 @@
|
|||||||
package ru.ulstu.ping.service;
|
package ru.ulstu.activity.ping.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.conference.model.Conference;
|
import ru.ulstu.activity.common.model.AbstractActivity;
|
||||||
import ru.ulstu.core.model.UserActivity;
|
import ru.ulstu.activity.conference.model.Conference;
|
||||||
import ru.ulstu.ping.model.Ping;
|
import ru.ulstu.activity.ping.model.Ping;
|
||||||
import ru.ulstu.ping.repository.PingRepository;
|
|
||||||
import ru.ulstu.user.service.UserService;
|
import ru.ulstu.user.service.UserService;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -19,14 +17,13 @@ public class PingService {
|
|||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
public PingService(PingRepository pingRepository,
|
public PingService(PingRepository pingRepository,
|
||||||
UserService userService,
|
UserService userService) {
|
||||||
PingScheduler pingScheduler) {
|
|
||||||
this.pingRepository = pingRepository;
|
this.pingRepository = pingRepository;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Ping addPing(UserActivity activity) throws IOException {
|
public Ping addPing(AbstractActivity activity) {
|
||||||
Ping newPing = new Ping(new Date(), userService.getCurrentUser());
|
Ping newPing = new Ping(new Date(), userService.getCurrentUser());
|
||||||
newPing.setActivity(activity);
|
newPing.setActivity(activity);
|
||||||
return pingRepository.save(newPing);
|
return pingRepository.save(newPing);
|
@ -0,0 +1,68 @@
|
|||||||
|
package ru.ulstu.activity.project.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ru.ulstu.activity.api.ActivityController;
|
||||||
|
import ru.ulstu.activity.project.model.ProjectDashboardDto;
|
||||||
|
import ru.ulstu.activity.project.model.ProjectDto;
|
||||||
|
import ru.ulstu.activity.project.model.ProjectListDto;
|
||||||
|
import ru.ulstu.activity.project.service.ProjectService;
|
||||||
|
import ru.ulstu.configuration.Constants;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
import ru.ulstu.core.model.response.Response;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(Constants.API_1_0 + "projects")
|
||||||
|
public class ProjectController implements ActivityController<ProjectListDto, ProjectDashboardDto, ProjectDto> {
|
||||||
|
private final ProjectService projectService;
|
||||||
|
|
||||||
|
public ProjectController(ProjectService projectService) {
|
||||||
|
this.projectService = projectService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("list")
|
||||||
|
public Response<PageableItems<ProjectListDto>> getList(@RequestParam(value = "offset", defaultValue = "0") int offset,
|
||||||
|
@RequestParam(value = "count", defaultValue = "10") int count) {
|
||||||
|
return new Response<>(projectService.findAllDto(offset, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("dashboard")
|
||||||
|
public Response<PageableItems<ProjectDashboardDto>> getDashboard(@RequestParam(value = "offset", defaultValue = "0") int offset,
|
||||||
|
@RequestParam(value = "count", defaultValue = "10") int count) {
|
||||||
|
return new Response<>(projectService.findAllActiveDto(offset, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("{project-id}")
|
||||||
|
public Response<ProjectDto> get(@PathVariable("project-id") Integer projectId) {
|
||||||
|
return new Response<>(projectService.findDtoById(projectId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public Response<ProjectDto> create(@RequestBody @Valid ProjectDto projectDto) {
|
||||||
|
return new Response<>(projectService.create(projectDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping
|
||||||
|
public Response<ProjectDto> update(@RequestBody @Valid ProjectDto projectDto) {
|
||||||
|
return new Response<>(projectService.update(projectDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{project-id}")
|
||||||
|
public Response<Boolean> delete(@PathVariable("project-id") Integer projectId) {
|
||||||
|
return new Response<>(projectService.delete(projectId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("ping/{project-id}")
|
||||||
|
public void ping(@PathVariable("project-id") int projectId) {
|
||||||
|
projectService.ping(projectId);
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,13 @@
|
|||||||
package ru.ulstu.project.model;
|
package ru.ulstu.activity.project.model;
|
||||||
|
|
||||||
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.activity.common.model.AbstractActivity;
|
||||||
import ru.ulstu.core.model.EventSource;
|
import ru.ulstu.activity.common.model.EventSource;
|
||||||
import ru.ulstu.core.model.UserActivity;
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.activity.file.model.FileData;
|
||||||
import ru.ulstu.file.model.FileData;
|
import ru.ulstu.activity.grant.model.Grant;
|
||||||
import ru.ulstu.grant.model.Grant;
|
import ru.ulstu.activity.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.CascadeType;
|
||||||
@ -32,7 +31,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@DiscriminatorValue("PROJECT")
|
@DiscriminatorValue("PROJECT")
|
||||||
public class Project extends BaseEntity implements UserActivity, EventSource {
|
public class Project extends AbstractActivity implements EventSource {
|
||||||
|
|
||||||
public enum ProjectStatus {
|
public enum ProjectStatus {
|
||||||
TECHNICAL_TASK("Техническое задание"),
|
TECHNICAL_TASK("Техническое задание"),
|
||||||
@ -96,6 +95,10 @@ public class Project extends BaseEntity implements UserActivity, EventSource {
|
|||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<User> getRecipients() {
|
public List<User> getRecipients() {
|
||||||
return executors != null ? new ArrayList<>(executors) : Collections.emptyList();
|
return executors != null ? new ArrayList<>(executors) : Collections.emptyList();
|
||||||
@ -106,8 +109,9 @@ public class Project extends BaseEntity implements UserActivity, EventSource {
|
|||||||
event.setProject(this);
|
event.setProject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String title) {
|
@Override
|
||||||
this.title = title;
|
public String getSuffix() {
|
||||||
|
return "проекта";
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectStatus getStatus() {
|
public ProjectStatus getStatus() {
|
||||||
@ -179,7 +183,7 @@ public class Project extends BaseEntity implements UserActivity, EventSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<User> getActivityUsers() {
|
public Set<User> getActivityMembers() {
|
||||||
return new HashSet<>();
|
return new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
|||||||
|
package ru.ulstu.activity.project.model;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.api.model.ActivityDashboardDto;
|
||||||
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
|
public class ProjectDashboardDto extends ActivityDashboardDto {
|
||||||
|
private final Project.ProjectStatus status;
|
||||||
|
private final List<ScienceGroupMemberDto> executors;
|
||||||
|
|
||||||
|
public ProjectDashboardDto(Project project) {
|
||||||
|
super(project.getId(), project.getTitle());
|
||||||
|
this.status = project.getStatus();
|
||||||
|
this.executors = convert(project.getExecutors(), ScienceGroupMemberDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Project.ProjectStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ScienceGroupMemberDto> getExecutors() {
|
||||||
|
return executors;
|
||||||
|
}
|
||||||
|
}
|
@ -1,99 +1,64 @@
|
|||||||
package ru.ulstu.project.model;
|
package ru.ulstu.activity.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 org.thymeleaf.util.StringUtils;
|
import ru.ulstu.activity.api.model.ActivityDto;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.DeadlineDto;
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
import ru.ulstu.activity.file.model.FileDataDto;
|
||||||
import ru.ulstu.grant.model.GrantDto;
|
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
import ru.ulstu.user.model.UserDto;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
public class ProjectDto {
|
public class ProjectDto extends ActivityDto {
|
||||||
private Integer id;
|
|
||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String title;
|
private String title;
|
||||||
private Project.ProjectStatus status;
|
private Project.ProjectStatus status;
|
||||||
private String description;
|
private String description;
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||||
private GrantDto grant;
|
|
||||||
private String repository;
|
private String repository;
|
||||||
private List<FileDataDto> files = new ArrayList<>();
|
private List<FileDataDto> files = new ArrayList<>();
|
||||||
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
|
||||||
private Set<Integer> executorIds;
|
private Set<Integer> executorIds;
|
||||||
private List<UserDto> executors;
|
|
||||||
private List<Integer> grantIds;
|
private List<Integer> grantIds;
|
||||||
private List<GrantDto> grants;
|
|
||||||
|
|
||||||
private final static int MAX_EXECUTORS_LENGTH = 40;
|
|
||||||
|
|
||||||
public ProjectDto() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProjectDto(String title) {
|
|
||||||
this.title = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public ProjectDto(@JsonProperty("id") Integer id,
|
public ProjectDto(@JsonProperty("id") Integer id,
|
||||||
@JsonProperty("title") String title,
|
@JsonProperty("title") String title,
|
||||||
@JsonProperty("status") Project.ProjectStatus status,
|
@JsonProperty("status") Project.ProjectStatus status,
|
||||||
@JsonProperty("description") String description,
|
@JsonProperty("description") String description,
|
||||||
@JsonProperty("grant") GrantDto grant,
|
|
||||||
@JsonProperty("repository") String repository,
|
@JsonProperty("repository") String repository,
|
||||||
@JsonProperty("files") List<FileDataDto> files,
|
@JsonProperty("files") List<FileDataDto> files,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||||
@JsonProperty("executorIds") Set<Integer> executorIds,
|
@JsonProperty("executorIds") Set<Integer> executorIds,
|
||||||
@JsonProperty("executors") List<UserDto> executors,
|
@JsonProperty("grantIds") List<Integer> grantIds) {
|
||||||
@JsonProperty("grantIds") List<Integer> grantIds,
|
super(id);
|
||||||
@JsonProperty("grants") List<GrantDto> grants) {
|
|
||||||
this.id = id;
|
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.grant = grant;
|
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
this.files = files;
|
this.files = files;
|
||||||
this.executorIds = executorIds;
|
this.executorIds = executorIds;
|
||||||
this.executors = executors;
|
|
||||||
this.grantIds = grantIds;
|
this.grantIds = grantIds;
|
||||||
this.grants = grants;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ProjectDto(Project project) {
|
public ProjectDto(Project project) {
|
||||||
Set<User> users = new HashSet<User>(project.getExecutors());
|
super(project.getId());
|
||||||
this.id = project.getId();
|
Set<User> users = new HashSet<>(project.getExecutors());
|
||||||
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.files = convert(project.getFiles(), FileDataDto::new);
|
this.files = convert(project.getFiles(), FileDataDto::new);
|
||||||
this.grant = project.getGrant() == null ? null : new GrantDto(project.getGrant());
|
|
||||||
this.repository = project.getRepository();
|
this.repository = project.getRepository();
|
||||||
this.deadlines = project.getDeadlines();
|
this.deadlines = convert(project.getDeadlines(), DeadlineDto::new);
|
||||||
this.executorIds = convert(users, user -> user.getId());
|
this.executorIds = convert(users, user -> user.getId());
|
||||||
this.executors = convert(project.getExecutors(), UserDto::new);
|
|
||||||
this.grantIds = convert(project.getGrants(), grant -> grant.getId());
|
this.grantIds = convert(project.getGrants(), grant -> grant.getId());
|
||||||
this.grants = convert(project.getGrants(), GrantDto::new);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Integer id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
@ -120,14 +85,6 @@ public class ProjectDto {
|
|||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GrantDto getGrant() {
|
|
||||||
return grant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrant(GrantDto grant) {
|
|
||||||
this.grant = grant;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRepository() {
|
public String getRepository() {
|
||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
@ -136,11 +93,11 @@ public class ProjectDto {
|
|||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Deadline> getDeadlines() {
|
public List<DeadlineDto> getDeadlines() {
|
||||||
return deadlines;
|
return deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeadlines(List<Deadline> deadlines) {
|
public void setDeadlines(List<DeadlineDto> deadlines) {
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,14 +109,6 @@ public class ProjectDto {
|
|||||||
this.files = files;
|
this.files = files;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> getRemovedDeadlineIds() {
|
|
||||||
return removedDeadlineIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRemovedDeadlineIds(List<Integer> removedDeadlineIds) {
|
|
||||||
this.removedDeadlineIds = removedDeadlineIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Integer> getExecutorIds() {
|
public Set<Integer> getExecutorIds() {
|
||||||
return executorIds;
|
return executorIds;
|
||||||
}
|
}
|
||||||
@ -168,21 +117,6 @@ public class ProjectDto {
|
|||||||
this.executorIds = 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() {
|
public List<Integer> getGrantIds() {
|
||||||
return grantIds;
|
return grantIds;
|
||||||
}
|
}
|
||||||
@ -190,12 +124,4 @@ public class ProjectDto {
|
|||||||
public void setGrantIds(List<Integer> grantIds) {
|
public void setGrantIds(List<Integer> grantIds) {
|
||||||
this.grantIds = grantIds;
|
this.grantIds = grantIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GrantDto> getGrants() {
|
|
||||||
return grants;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setGrants(List<GrantDto> grants) {
|
|
||||||
this.grants = grants;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package ru.ulstu.activity.project.model;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.api.model.ActivityListDto;
|
||||||
|
import ru.ulstu.activity.common.model.ScienceGroupMemberDto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
|
public class ProjectListDto extends ActivityListDto {
|
||||||
|
private final Project.ProjectStatus status;
|
||||||
|
private final List<ScienceGroupMemberDto> executors;
|
||||||
|
|
||||||
|
public ProjectListDto(Project project) {
|
||||||
|
super(project.getId(), project.getTitle());
|
||||||
|
this.status = project.getStatus();
|
||||||
|
this.executors = convert(project.getExecutors(), ScienceGroupMemberDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Project.ProjectStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ScienceGroupMemberDto> getExecutors() {
|
||||||
|
return executors;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package ru.ulstu.activity.project.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.activity.common.service.ActivityNotificationService;
|
||||||
|
import ru.ulstu.activity.project.model.Project;
|
||||||
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ProjectNotificationService extends ActivityNotificationService<Project> {
|
||||||
|
|
||||||
|
public ProjectNotificationService(MailService mailService) {
|
||||||
|
super(mailService);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCreateNotification(Project project) {
|
||||||
|
throw new RuntimeException("not implemented yet");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package ru.ulstu.activity.project.service;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import ru.ulstu.activity.api.ActivityRepository;
|
||||||
|
import ru.ulstu.activity.project.model.Project;
|
||||||
|
|
||||||
|
interface ProjectRepository extends JpaRepository<Project, Integer>, ActivityRepository<Project> {
|
||||||
|
@Query("SELECT p FROM Project p WHERE p.status NOT IN (:statuses)")
|
||||||
|
Page<Project> findAllWithoutStatuses(Pageable pageable, @Param("statuses") Project.ProjectStatus... statuses);
|
||||||
|
|
||||||
|
@Query("SELECT p.title FROM Project p WHERE (p.title = :name) AND (:id IS NULL OR p.id != :id) ")
|
||||||
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
package ru.ulstu.activity.project.service;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.activity.common.service.ActivityService;
|
||||||
|
import ru.ulstu.activity.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.activity.file.service.FileService;
|
||||||
|
import ru.ulstu.activity.ping.service.PingService;
|
||||||
|
import ru.ulstu.activity.project.model.Project;
|
||||||
|
import ru.ulstu.activity.project.model.ProjectDashboardDto;
|
||||||
|
import ru.ulstu.activity.project.model.ProjectDto;
|
||||||
|
import ru.ulstu.activity.project.model.ProjectListDto;
|
||||||
|
import ru.ulstu.activity.timeline.model.Event;
|
||||||
|
import ru.ulstu.activity.timeline.service.EventService;
|
||||||
|
import ru.ulstu.core.jpa.OffsetablePageRequest;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
import static ru.ulstu.activity.project.model.Project.ProjectStatus.CLOSED;
|
||||||
|
import static ru.ulstu.activity.project.model.Project.ProjectStatus.FAILED;
|
||||||
|
import static ru.ulstu.activity.project.model.Project.ProjectStatus.TECHNICAL_TASK;
|
||||||
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ProjectService extends ActivityService<ProjectListDto, Project, ProjectDto> {
|
||||||
|
private final ProjectRepository projectRepository;
|
||||||
|
private final DeadlineService deadlineService;
|
||||||
|
private final FileService fileService;
|
||||||
|
private final PingService pingService;
|
||||||
|
private final EventService eventService;
|
||||||
|
|
||||||
|
public ProjectService(ProjectRepository projectRepository,
|
||||||
|
ProjectNotificationService projectNotificationService,
|
||||||
|
DeadlineService deadlineService,
|
||||||
|
FileService fileService,
|
||||||
|
PingService pingService, EventService eventService) {
|
||||||
|
super(projectRepository, projectNotificationService, pingService, eventService);
|
||||||
|
this.projectRepository = projectRepository;
|
||||||
|
this.deadlineService = deadlineService;
|
||||||
|
this.fileService = fileService;
|
||||||
|
this.pingService = pingService;
|
||||||
|
this.eventService = eventService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageableItems<ProjectDashboardDto> findAllActiveDto(int offset, int count) {
|
||||||
|
return convertPageable(findAllActive(offset, count), ProjectDashboardDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageableItems<Project> findAllActive(int offset, int count) {
|
||||||
|
Page<Project> activeProjectPage = projectRepository.findAllWithoutStatuses(new OffsetablePageRequest(offset, count), CLOSED, FAILED);
|
||||||
|
return new PageableItems<>(activeProjectPage.getTotalElements(), activeProjectPage.getContent());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doActionsOnDiffObjects(Project oldEntity, Project entity) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<Event> getEvents(Project entity) {
|
||||||
|
return eventService.findByProject(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Project copyFromDto(Project project, ProjectDto projectDto) throws IOException {
|
||||||
|
project.setDescription(projectDto.getDescription());
|
||||||
|
project.setStatus(projectDto.getStatus() == null ? TECHNICAL_TASK : projectDto.getStatus());
|
||||||
|
project.setTitle(projectDto.getTitle());
|
||||||
|
project.setRepository(projectDto.getRepository());
|
||||||
|
project.setDeadlines(deadlineService.saveOrCreate(projectDto.getDeadlines()));
|
||||||
|
project.setFiles(fileService.saveOrCreate(projectDto.getFiles().stream()
|
||||||
|
.filter(f -> !f.isDeleted())
|
||||||
|
.collect(toList())));
|
||||||
|
project.getGrants().clear();
|
||||||
|
return project;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ProjectListDto getActivityListDto(Project entity) {
|
||||||
|
return new ProjectListDto(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Project getNewActivity() {
|
||||||
|
return new Project();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ProjectDto getNewActivityDto(Project entity) {
|
||||||
|
return new ProjectDto(entity);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package ru.ulstu.activity.students.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ru.ulstu.activity.api.ActivityController;
|
||||||
|
import ru.ulstu.activity.students.model.TaskDashboardDto;
|
||||||
|
import ru.ulstu.activity.students.model.TaskDto;
|
||||||
|
import ru.ulstu.activity.students.model.TaskListDto;
|
||||||
|
import ru.ulstu.activity.students.service.TaskService;
|
||||||
|
import ru.ulstu.configuration.Constants;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
|
import ru.ulstu.core.model.response.Response;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(Constants.API_1_0 + "students")
|
||||||
|
public class TaskController implements ActivityController<TaskListDto, TaskDashboardDto, TaskDto> {
|
||||||
|
|
||||||
|
private final TaskService taskService;
|
||||||
|
|
||||||
|
public TaskController(TaskService taskService) {
|
||||||
|
this.taskService = taskService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("list")
|
||||||
|
public Response<PageableItems<TaskListDto>> getList(@RequestParam(value = "offset", defaultValue = "0") int offset,
|
||||||
|
@RequestParam(value = "count", defaultValue = "10") int count) {
|
||||||
|
return new Response<>(taskService.findAllDto(offset, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("dashboard")
|
||||||
|
public Response<PageableItems<TaskDashboardDto>> getDashboard(@RequestParam(value = "offset", defaultValue = "0") int offset,
|
||||||
|
@RequestParam(value = "count", defaultValue = "10") int count) {
|
||||||
|
return new Response<>(taskService.findAllActiveDto(offset, count));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("{task-id}")
|
||||||
|
public Response<TaskDto> get(@PathVariable("task-id") Integer taskId) {
|
||||||
|
return new Response<>(taskService.findDtoById(taskId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public Response<TaskDto> create(@RequestBody @Valid TaskDto taskDto) {
|
||||||
|
return new Response<>(taskService.create(taskDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping
|
||||||
|
public Response<TaskDto> update(@RequestBody @Valid TaskDto paperDto) {
|
||||||
|
return new Response<>(taskService.update(paperDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("{task-id}")
|
||||||
|
public Response<Boolean> delete(@PathVariable("task-id") Integer taskId) {
|
||||||
|
return new Response<>(taskService.delete(taskId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("ping/{task-id}")
|
||||||
|
public void ping(@PathVariable("task-id") int taskId) {
|
||||||
|
taskService.ping(taskId);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.students.model;
|
package ru.ulstu.activity.students.model;
|
||||||
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import ru.ulstu.core.model.BaseEntity;
|
import ru.ulstu.core.model.BaseEntity;
|
@ -1,12 +1,12 @@
|
|||||||
package ru.ulstu.students.model;
|
package ru.ulstu.activity.students.model;
|
||||||
|
|
||||||
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.activity.common.model.AbstractActivity;
|
||||||
import ru.ulstu.core.model.EventSource;
|
import ru.ulstu.activity.common.model.EventSource;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
import ru.ulstu.tags.model.Tag;
|
import ru.ulstu.activity.tags.model.Tag;
|
||||||
import ru.ulstu.timeline.model.Event;
|
import ru.ulstu.activity.timeline.model.Event;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
@ -27,9 +27,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class Task extends BaseEntity implements EventSource {
|
public class Task extends AbstractActivity implements EventSource {
|
||||||
|
|
||||||
public enum TaskStatus {
|
public enum TaskStatus {
|
||||||
IN_WORK("В работе"),
|
IN_WORK("В работе"),
|
||||||
@ -90,6 +91,11 @@ public class Task extends BaseEntity implements EventSource {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSuffix() {
|
||||||
|
return "задачи";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addObjectToEvent(Event event) {
|
public void addObjectToEvent(Event event) {
|
||||||
event.setTask(this);
|
event.setTask(this);
|
||||||
@ -99,6 +105,16 @@ public class Task extends BaseEntity implements EventSource {
|
|||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<User> getActivityMembers() {
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Event> getEvents() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
public TaskStatus getStatus() {
|
public TaskStatus getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package ru.ulstu.activity.students.model;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.api.model.ActivityDashboardDto;
|
||||||
|
|
||||||
|
public class TaskDashboardDto extends ActivityDashboardDto {
|
||||||
|
private final Task.TaskStatus status;
|
||||||
|
|
||||||
|
public TaskDashboardDto(Task task) {
|
||||||
|
super(task.getId(), task.getTitle());
|
||||||
|
this.status = task.getStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task.TaskStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
@ -1,37 +1,30 @@
|
|||||||
package ru.ulstu.students.model;
|
package ru.ulstu.activity.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 org.apache.commons.lang3.StringUtils;
|
import ru.ulstu.activity.api.model.ActivityDto;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.activity.deadline.model.DeadlineDto;
|
||||||
import ru.ulstu.tags.model.Tag;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotEmpty;
|
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;
|
|
||||||
|
|
||||||
public class TaskDto {
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
||||||
|
|
||||||
|
public class TaskDto extends ActivityDto {
|
||||||
|
|
||||||
private final static int MAX_TAGS_LENGTH = 50;
|
private final static int MAX_TAGS_LENGTH = 50;
|
||||||
|
|
||||||
private Integer id;
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String title;
|
private String title;
|
||||||
private String description;
|
private String description;
|
||||||
private Task.TaskStatus status;
|
private Task.TaskStatus status;
|
||||||
private List<Deadline> deadlines = new ArrayList<>();
|
private List<DeadlineDto> deadlines = new ArrayList<>();
|
||||||
private Date createDate;
|
private Date createDate;
|
||||||
private Date updateDate;
|
private Date updateDate;
|
||||||
private Set<Integer> tagIds;
|
private Set<Integer> tagIds;
|
||||||
private List<Tag> tags = new ArrayList<>();
|
|
||||||
|
|
||||||
public TaskDto() {
|
|
||||||
deadlines.add(new Deadline());
|
|
||||||
}
|
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public TaskDto(@JsonProperty("id") Integer id,
|
public TaskDto(@JsonProperty("id") Integer id,
|
||||||
@ -40,36 +33,25 @@ public class TaskDto {
|
|||||||
@JsonProperty("createDate") Date createDate,
|
@JsonProperty("createDate") Date createDate,
|
||||||
@JsonProperty("updateDate") Date updateDate,
|
@JsonProperty("updateDate") Date updateDate,
|
||||||
@JsonProperty("status") Task.TaskStatus status,
|
@JsonProperty("status") Task.TaskStatus status,
|
||||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
@JsonProperty("deadlines") List<DeadlineDto> deadlines,
|
||||||
@JsonProperty("tagIds") Set<Integer> tagIds,
|
@JsonProperty("tagIds") Set<Integer> tagIds) {
|
||||||
@JsonProperty("tags") List<Tag> tags) {
|
super(id);
|
||||||
this.id = id;
|
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.deadlines = deadlines;
|
this.deadlines = deadlines;
|
||||||
this.createDate = createDate;
|
this.createDate = createDate;
|
||||||
this.updateDate = updateDate;
|
this.updateDate = updateDate;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.tags = tags;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskDto(Task task) {
|
public TaskDto(Task task) {
|
||||||
this.id = task.getId();
|
super(task.getId());
|
||||||
this.title = task.getTitle();
|
this.title = task.getTitle();
|
||||||
this.status = task.getStatus();
|
this.status = task.getStatus();
|
||||||
this.deadlines = task.getDeadlines();
|
this.deadlines = convert(task.getDeadlines(), DeadlineDto::new);
|
||||||
this.createDate = task.getCreateDate();
|
this.createDate = task.getCreateDate();
|
||||||
this.updateDate = task.getUpdateDate();
|
this.updateDate = task.getUpdateDate();
|
||||||
this.description = task.getDescription();
|
this.description = task.getDescription();
|
||||||
this.tags = task.getTags();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Integer id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
@ -96,14 +78,6 @@ public class TaskDto {
|
|||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Deadline> getDeadlines() {
|
|
||||||
return deadlines;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeadlines(List<Deadline> deadlines) {
|
|
||||||
this.deadlines = deadlines;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getCreateDate() {
|
public Date getCreateDate() {
|
||||||
return createDate;
|
return createDate;
|
||||||
}
|
}
|
||||||
@ -128,41 +102,7 @@ public class TaskDto {
|
|||||||
this.tagIds = tagIds;
|
this.tagIds = tagIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Tag> getTags() {
|
public List<DeadlineDto> getDeadlines() {
|
||||||
return tags;
|
return deadlines;
|
||||||
}
|
|
||||||
|
|
||||||
public void setTags(List<Tag> 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() {
|
|
||||||
return StringUtils.abbreviate(tags
|
|
||||||
.stream()
|
|
||||||
.map(tag -> tag.getTagName())
|
|
||||||
.collect(Collectors.joining(", ")), MAX_TAGS_LENGTH);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.students.model;
|
package ru.ulstu.activity.students.model;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -0,0 +1,16 @@
|
|||||||
|
package ru.ulstu.activity.students.model;
|
||||||
|
|
||||||
|
import ru.ulstu.activity.api.model.ActivityListDto;
|
||||||
|
|
||||||
|
public class TaskListDto extends ActivityListDto {
|
||||||
|
private final Task.TaskStatus status;
|
||||||
|
|
||||||
|
public TaskListDto(Task task) {
|
||||||
|
super(task.getId(), task.getTitle());
|
||||||
|
this.status = task.getStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task.TaskStatus getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package ru.ulstu.activity.students.service;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.ulstu.activity.students.model.Scheduler;
|
||||||
|
import ru.ulstu.activity.students.model.Task;
|
||||||
|
|
||||||
|
interface SchedulerRepository extends JpaRepository<Scheduler, Integer> {
|
||||||
|
|
||||||
|
Scheduler findOneByTask(Task task);
|
||||||
|
|
||||||
|
}
|
@ -1,11 +1,10 @@
|
|||||||
package ru.ulstu.students.service;
|
package ru.ulstu.activity.students.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.students.model.Scheduler;
|
import ru.ulstu.activity.students.model.Scheduler;
|
||||||
import ru.ulstu.students.model.Task;
|
import ru.ulstu.activity.students.model.Task;
|
||||||
import ru.ulstu.students.repository.SchedulerRepository;
|
import ru.ulstu.activity.tags.model.Tag;
|
||||||
import ru.ulstu.tags.model.Tag;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -31,13 +30,13 @@ public class SchedulerService {
|
|||||||
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private Scheduler create(Task task) {
|
public Scheduler create(Task task) {
|
||||||
Scheduler scheduler = new Scheduler(task, task.getDeadlines().get(task.getDeadlines().size() - 1).getDate());
|
Scheduler scheduler = new Scheduler(task, task.getDeadlines().get(task.getDeadlines().size() - 1).getDate());
|
||||||
return schedulerRepository.save(scheduler);
|
return schedulerRepository.save(scheduler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private void delete(Integer schedulerId) {
|
public void delete(Integer schedulerId) {
|
||||||
if (schedulerRepository.existsById(schedulerId)) {
|
if (schedulerRepository.existsById(schedulerId)) {
|
||||||
schedulerRepository.deleteById(schedulerId);
|
schedulerRepository.deleteById(schedulerId);
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.students.service;
|
package ru.ulstu.activity.students.service;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
@ -0,0 +1,24 @@
|
|||||||
|
package ru.ulstu.activity.students.service;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.activity.common.service.ActivityNotificationService;
|
||||||
|
import ru.ulstu.activity.students.model.Task;
|
||||||
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TaskNotificationService extends ActivityNotificationService<Task> {
|
||||||
|
private final static String TEMPLATE_CREATE = "taskCreateNotification";
|
||||||
|
private final static String TITLE_CREATE = "Создана задача";
|
||||||
|
|
||||||
|
public TaskNotificationService(MailService mailService) {
|
||||||
|
super(mailService);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCreateNotification(Task task) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("task", task);
|
||||||
|
sendForAllAuthors(variables, task, TEMPLATE_CREATE, TITLE_CREATE);
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,16 @@
|
|||||||
package ru.ulstu.students.repository;
|
package ru.ulstu.activity.students.service;
|
||||||
|
|
||||||
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.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import ru.ulstu.students.model.Task;
|
import ru.ulstu.activity.api.ActivityRepository;
|
||||||
import ru.ulstu.tags.model.Tag;
|
import ru.ulstu.activity.students.model.Task;
|
||||||
|
import ru.ulstu.activity.tags.model.Tag;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface TaskRepository extends JpaRepository<Task, Integer> {
|
interface TaskRepository extends JpaRepository<Task, Integer>, ActivityRepository<Task> {
|
||||||
|
|
||||||
@Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date DESC")
|
@Query("SELECT t FROM Task t WHERE (t.status = :status OR :status IS NULL) AND (:tag IS NULL OR :tag MEMBER OF t.tags) ORDER BY create_date DESC")
|
||||||
List<Task> filterNew(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag);
|
List<Task> filterNew(@Param("status") Task.TaskStatus status, @Param("tag") Tag tag);
|
||||||
@ -23,5 +24,7 @@ public interface TaskRepository extends JpaRepository<Task, Integer> {
|
|||||||
@Query("SELECT t FROM Task t WHERE (t.createDate >= :date) ORDER BY create_date DESC")
|
@Query("SELECT t FROM Task t WHERE (t.createDate >= :date) ORDER BY create_date DESC")
|
||||||
List<Task> findAllYear(@Param("date") Date date);
|
List<Task> findAllYear(@Param("date") Date date);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Query("SELECT title FROM Task t WHERE (t.title = :name) AND (:id IS NULL OR t.id != :id) ")
|
||||||
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
}
|
}
|
@ -1,27 +1,28 @@
|
|||||||
package ru.ulstu.students.service;
|
package ru.ulstu.activity.students.service;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.data.domain.Page;
|
||||||
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 ru.ulstu.activity.common.service.ActivityService;
|
||||||
|
import ru.ulstu.activity.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.activity.deadline.service.DeadlineService;
|
||||||
|
import ru.ulstu.activity.ping.service.PingService;
|
||||||
|
import ru.ulstu.activity.students.model.Scheduler;
|
||||||
|
import ru.ulstu.activity.students.model.Task;
|
||||||
|
import ru.ulstu.activity.students.model.TaskDashboardDto;
|
||||||
|
import ru.ulstu.activity.students.model.TaskDto;
|
||||||
|
import ru.ulstu.activity.students.model.TaskListDto;
|
||||||
|
import ru.ulstu.activity.tags.model.Tag;
|
||||||
|
import ru.ulstu.activity.tags.service.TagService;
|
||||||
|
import ru.ulstu.activity.timeline.model.Event;
|
||||||
|
import ru.ulstu.activity.timeline.service.EventService;
|
||||||
|
import ru.ulstu.core.jpa.OffsetablePageRequest;
|
||||||
|
import ru.ulstu.core.model.response.PageableItems;
|
||||||
import ru.ulstu.core.util.DateUtils;
|
import ru.ulstu.core.util.DateUtils;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
|
||||||
import ru.ulstu.students.model.Scheduler;
|
|
||||||
import ru.ulstu.students.model.Task;
|
|
||||||
import ru.ulstu.students.model.TaskDto;
|
|
||||||
import ru.ulstu.students.model.TaskFilterDto;
|
|
||||||
import ru.ulstu.students.repository.SchedulerRepository;
|
|
||||||
import ru.ulstu.students.repository.TaskRepository;
|
|
||||||
import ru.ulstu.tags.model.Tag;
|
|
||||||
import ru.ulstu.tags.service.TagService;
|
|
||||||
import ru.ulstu.timeline.service.EventService;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -29,66 +30,58 @@ import java.util.Set;
|
|||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static ru.ulstu.activity.students.model.Task.TaskStatus.IN_WORK;
|
||||||
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
import static ru.ulstu.core.util.StreamApiUtils.convertPageable;
|
||||||
import static ru.ulstu.students.model.Task.TaskStatus.IN_WORK;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class TaskService {
|
public class TaskService extends ActivityService<TaskListDto, Task, TaskDto> {
|
||||||
|
|
||||||
private final static int MAX_DISPLAY_SIZE = 40;
|
|
||||||
|
|
||||||
private final TaskRepository taskRepository;
|
private final TaskRepository taskRepository;
|
||||||
|
private final TaskNotificationService taskNotificationService;
|
||||||
private final SchedulerRepository schedulerRepository;
|
private final SchedulerRepository schedulerRepository;
|
||||||
private final DeadlineService deadlineService;
|
private final DeadlineService deadlineService;
|
||||||
private final TagService tagService;
|
private final TagService tagService;
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
|
private final PingService pingService;
|
||||||
|
|
||||||
|
|
||||||
public TaskService(TaskRepository taskRepository,
|
public TaskService(TaskRepository taskRepository,
|
||||||
DeadlineService deadlineService, TagService tagService, SchedulerRepository schedulerRepository, EventService eventService) {
|
TaskNotificationService taskNotificationService,
|
||||||
|
DeadlineService deadlineService,
|
||||||
|
TagService tagService,
|
||||||
|
SchedulerRepository schedulerRepository,
|
||||||
|
EventService eventService,
|
||||||
|
PingService pingService) {
|
||||||
|
super(taskRepository, taskNotificationService, pingService, eventService);
|
||||||
this.taskRepository = taskRepository;
|
this.taskRepository = taskRepository;
|
||||||
|
this.taskNotificationService = taskNotificationService;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
this.tagService = tagService;
|
this.tagService = tagService;
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
this.schedulerRepository = schedulerRepository;
|
this.schedulerRepository = schedulerRepository;
|
||||||
|
this.pingService = pingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Task> findAll() {
|
public PageableItems<Task> findAll(int offset, int count) {
|
||||||
return taskRepository.findAll(new Sort(Sort.Direction.DESC, "createDate"));
|
final Page<Task> page = taskRepository.findAll(new OffsetablePageRequest(offset, count));
|
||||||
|
return new PageableItems<>(page.getTotalElements(), page.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TaskDto> findAllDto() {
|
@Override
|
||||||
List<TaskDto> tasks = convert(findAll(), TaskDto::new);
|
protected TaskListDto getActivityListDto(Task entity) {
|
||||||
tasks.forEach(taskDto -> taskDto.setTitle(StringUtils.abbreviate(taskDto.getTitle(), MAX_DISPLAY_SIZE)));
|
return new TaskListDto(entity);
|
||||||
return tasks;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TaskDto findOneDto(Integer id) {
|
@Override
|
||||||
return new TaskDto(taskRepository.getOne(id));
|
protected Task getNewActivity() {
|
||||||
|
return new Task();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TaskDto> filter(TaskFilterDto filterDto) {
|
@Override
|
||||||
if (filterDto.getOrder().compareTo("new") == 0) {
|
protected TaskDto getNewActivityDto(Task entity) {
|
||||||
return convert(taskRepository.filterNew(
|
return new TaskDto(entity);
|
||||||
filterDto.getStatus(),
|
|
||||||
filterDto.getTag() == null ? null : tagService.findById(filterDto.getTag())), TaskDto::new);
|
|
||||||
} else {
|
|
||||||
return convert(taskRepository.filterOld(
|
|
||||||
filterDto.getStatus(),
|
|
||||||
filterDto.getTag() == null ? null : tagService.findById(filterDto.getTag())), TaskDto::new);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
protected Task copyFromDto(Task task, TaskDto taskDto) {
|
||||||
public Integer create(TaskDto taskDto) throws IOException {
|
|
||||||
Task newTask = copyFromDto(new Task(), taskDto);
|
|
||||||
newTask = taskRepository.save(newTask);
|
|
||||||
eventService.createFromObject(newTask, Collections.emptyList(), true, "задачи");
|
|
||||||
return newTask.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Task copyFromDto(Task task, TaskDto taskDto) throws IOException {
|
|
||||||
task.setTitle(taskDto.getTitle());
|
task.setTitle(taskDto.getTitle());
|
||||||
task.setDescription(taskDto.getDescription());
|
task.setDescription(taskDto.getDescription());
|
||||||
task.setStatus(taskDto.getStatus() == null ? IN_WORK : taskDto.getStatus());
|
task.setStatus(taskDto.getStatus() == null ? IN_WORK : taskDto.getStatus());
|
||||||
@ -96,39 +89,18 @@ public class TaskService {
|
|||||||
task.setCreateDate(task.getCreateDate() == null ? new Date() : task.getCreateDate());
|
task.setCreateDate(task.getCreateDate() == null ? new Date() : task.getCreateDate());
|
||||||
task.setUpdateDate(new Date());
|
task.setUpdateDate(new Date());
|
||||||
task.getTags().clear();
|
task.getTags().clear();
|
||||||
task.setTags(tagService.saveOrCreate(taskDto.getTags()));
|
//task.setTags(tagService.saveOrCreate(taskDto.getTags()));
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Override
|
||||||
private Integer update(TaskDto taskDto) throws IOException {
|
protected void doActionsOnDiffObjects(Task oldEntity, Task entity) {
|
||||||
Task task = taskRepository.getOne(taskDto.getId());
|
//TODO
|
||||||
taskRepository.save(copyFromDto(task, taskDto));
|
|
||||||
eventService.updateTaskDeadlines(task);
|
|
||||||
return task.getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Override
|
||||||
public boolean delete(Integer taskId) throws IOException {
|
protected List<Event> getEvents(Task entity) {
|
||||||
if (taskRepository.existsById(taskId)) {
|
return eventService.findByTask(entity);
|
||||||
Task scheduleTask = taskRepository.getOne(taskId);
|
|
||||||
Scheduler sch = schedulerRepository.findOneByTask(scheduleTask);
|
|
||||||
if (sch != null) {
|
|
||||||
schedulerRepository.deleteById(sch.getId());
|
|
||||||
}
|
|
||||||
taskRepository.deleteById(taskId);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(TaskDto taskDto) throws IOException {
|
|
||||||
if (isEmpty(taskDto.getId())) {
|
|
||||||
create(taskDto);
|
|
||||||
} else {
|
|
||||||
update(taskDto);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyMainPart(Task newTask, Task task) {
|
private void copyMainPart(Task newTask, Task task) {
|
||||||
@ -255,4 +227,14 @@ public class TaskService {
|
|||||||
taskRepository.save(newTask);
|
taskRepository.save(newTask);
|
||||||
return newTask;
|
return newTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageableItems<TaskDashboardDto> findAllActiveDto(int offset, int count) {
|
||||||
|
return convertPageable(findAllActive(offset, count), TaskDashboardDto::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageableItems<Task> findAllActive(int offset, int count) {
|
||||||
|
return findAll(offset, count);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package ru.ulstu.tags.model;
|
package ru.ulstu.activity.tags.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;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user