Merge branch 'master' into 10-savePaper
commit
fe6e52a19c
@ -0,0 +1,24 @@
|
|||||||
|
package ru.ulstu.paper.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
public class PaperFilterDto {
|
||||||
|
private final Integer authorId;
|
||||||
|
private final Integer year;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public PaperFilterDto(@JsonProperty("authorId") Integer authorId,
|
||||||
|
@JsonProperty("year") Integer year) {
|
||||||
|
this.authorId = authorId;
|
||||||
|
this.year = year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getAuthorId() {
|
||||||
|
return authorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getYear() {
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,15 @@
|
|||||||
package ru.ulstu.paper.repository;
|
package ru.ulstu.paper.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface PaperRepository extends JpaRepository<Paper, Integer> {
|
public interface PaperRepository extends JpaRepository<Paper, Integer> {
|
||||||
|
|
||||||
|
@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);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
package ru.ulstu.timeline.model;
|
||||||
|
|
||||||
|
public class EventStatusDto {
|
||||||
|
private final String id;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public EventStatusDto(Event.EventStatus status) {
|
||||||
|
this.id = status.name();
|
||||||
|
this.name = status.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package ru.ulstu.timeline.model;
|
||||||
|
|
||||||
|
import java.time.Period;
|
||||||
|
|
||||||
|
public enum PeriodEvent {
|
||||||
|
EVERY_YEAR(Period.ofYears(1), "Каждый год"),
|
||||||
|
EVERY_MONTH(Period.ofMonths(1), "Каждый месяц"),
|
||||||
|
EVERY_WEEK(Period.ofWeeks(1), "Каждую неделю"),
|
||||||
|
EVERY_DAY(Period.ofDays(1), "Каждый день");
|
||||||
|
|
||||||
|
private Period period;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
PeriodEvent(Period period, String message) {
|
||||||
|
this.period = period;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Period getPeriod() {
|
||||||
|
return period;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
package ru.ulstu.timeline.service;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.core.util.DateUtils;
|
||||||
|
import ru.ulstu.timeline.model.Event;
|
||||||
|
import ru.ulstu.timeline.model.PeriodEvent;
|
||||||
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class EventScheduler {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(EventScheduler.class);
|
||||||
|
private final EventService eventService;
|
||||||
|
private final MailService mailService;
|
||||||
|
|
||||||
|
public EventScheduler(EventService eventService,
|
||||||
|
MailService mailService) {
|
||||||
|
this.eventService = eventService;
|
||||||
|
this.mailService = mailService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 8 * * ?")
|
||||||
|
public void sendNotifications() {
|
||||||
|
List<Event> events = eventService.findByCurrentDate();
|
||||||
|
events.forEach(event -> {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("description", event.getDescription());
|
||||||
|
event.getRecipients()
|
||||||
|
.forEach(recipient -> mailService.sendEmailFromTemplate(variables, recipient, "eventNotification", event.getTitle()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 * * * ?")
|
||||||
|
public void checkPeriodEvents() {
|
||||||
|
log.debug("EventScheduler.checkPeriodEvents started");
|
||||||
|
//TODO: filter
|
||||||
|
for (Event event : eventService.findAll()) {
|
||||||
|
if (halfOfThePeriodHasPassed(event)) {
|
||||||
|
eventService.createBasedOn(event, DateUtils.addDays(event.getExecuteDate(), getShiftInDays(event.getPeriod())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("EventScheduler.checkPeriodEvents finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getShiftInDays(PeriodEvent periodEvent) {
|
||||||
|
switch (periodEvent) {
|
||||||
|
case EVERY_DAY:
|
||||||
|
return periodEvent.getPeriod().getDays();
|
||||||
|
case EVERY_WEEK:
|
||||||
|
return periodEvent.getPeriod().getDays();
|
||||||
|
case EVERY_MONTH:
|
||||||
|
return periodEvent.getPeriod().getMonths() * 30;
|
||||||
|
case EVERY_YEAR:
|
||||||
|
return periodEvent.getPeriod().getYears() * 365;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("period event not exists");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean halfOfThePeriodHasPassed(Event event) {
|
||||||
|
return event.getPeriod() != null && event.getChild() == null
|
||||||
|
&& new Date().after(
|
||||||
|
DateUtils.addDays(event.getExecuteDate(), (int) Math.round((double) getShiftInDays(event.getPeriod()) / 2)));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="alyona" id="20181031_000000-1">
|
||||||
|
<preConditions onFail="MARK_RAN">
|
||||||
|
<not><columnExists columnName="status" tableName="event"/></not>
|
||||||
|
</preConditions>
|
||||||
|
<addColumn tableName="event">
|
||||||
|
<column name="status" type="varchar(255)"/>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="orion" id="20181111_000000-1">
|
||||||
|
<preConditions onFail="MARK_RAN">
|
||||||
|
<not><columnExists columnName="period" tableName="event"/></not>
|
||||||
|
</preConditions>
|
||||||
|
<addColumn tableName="event">
|
||||||
|
<column name="period" type="varchar(50)"/>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
<changeSet author="orion" id="20181111_000000-2">
|
||||||
|
<preConditions onFail="MARK_RAN">
|
||||||
|
<not><columnExists columnName="child_id" tableName="event"/></not>
|
||||||
|
</preConditions>
|
||||||
|
<addColumn tableName="event">
|
||||||
|
<column name="child_id" type="integer"/>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
|
<changeSet author="orion" id="20181111_000000-3">
|
||||||
|
<addForeignKeyConstraint baseTableName="event" baseColumnNames="child_id"
|
||||||
|
constraintName="fk_event_child_event" referencedTableName="event"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
@ -0,0 +1,27 @@
|
|||||||
|
var urlTimeline = "/api/1.0/events/future";
|
||||||
|
|
||||||
|
function showTimeline(timelineElement) {
|
||||||
|
$(timelineElement).empty();
|
||||||
|
getFromRest(urlTimeline, function (eventList) {
|
||||||
|
eventList.forEach(function (event, index) {
|
||||||
|
var date = new Date(event.executeDate);
|
||||||
|
var formated_date = date.toLocaleDateString();
|
||||||
|
|
||||||
|
$(timelineElement).append("<li class='" + eventInverted(index) + "'>" +
|
||||||
|
"<div class=\"timeline-image\"><h4><br/>" + formated_date + "</h4></div>" +
|
||||||
|
"<div class=\"timeline-panel\">" +
|
||||||
|
"<div class=\"timeline-heading\">" +
|
||||||
|
"<h4>" + event.title + "</h4>" +
|
||||||
|
"</div>" +
|
||||||
|
"<div class=\"timeline-body\">" +
|
||||||
|
"<p class=\"text-muted\">" + event.description + "</p>" +
|
||||||
|
"</div>" +
|
||||||
|
"</div>" +
|
||||||
|
"</li>");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function eventInverted(index) {
|
||||||
|
return index % 2 == 1 ? "timeline-inverted" : "";
|
||||||
|
}
|
@ -0,0 +1,177 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en"
|
||||||
|
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||||
|
layout:decorator="default">
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="container" layout:fragment="content">
|
||||||
|
<!-- Services -->
|
||||||
|
<section id="services">
|
||||||
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-12 text-center">
|
||||||
|
<h2 class="section-heading text-uppercase">Dashboard</h2>
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
|
||||||
|
<a href="./grants" class="btn btn-light toolbar-button"><i class="fa fa-list-alt"></i>
|
||||||
|
Список</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
|
||||||
|
<a href="./dashboard" class="btn btn-light toolbar-button"><i class="fa fa-newspaper-o"
|
||||||
|
aria-hidden="true"></i> Панель управления</a>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3">
|
||||||
|
<a href="./grant" class="btn btn-light toolbar-button"><i class="fa fa-plus-circle" aria-hidden="true"></i>
|
||||||
|
Добавить грант</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row justify-content-center">
|
||||||
|
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2">
|
||||||
|
<span class="fa-stack fa-1x">
|
||||||
|
<i class="fa fa-circle fa-stack-2x text-primary"></i>
|
||||||
|
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col col-10 text-right">
|
||||||
|
<h7 class="service-heading"><a href="./grant">Название гранта</a></h7>
|
||||||
|
<p class="text-muted">Краткое описание</p>
|
||||||
|
<p class="text-muted">Статус: статус</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2">
|
||||||
|
<span class="fa-stack fa-1x">
|
||||||
|
<i class="fa fa-circle fa-stack-2x text-primary"></i>
|
||||||
|
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="col col-10 text-right">
|
||||||
|
<h7 class="service-heading">Название гранта</h7>
|
||||||
|
<p class="text-muted">Краткое описание</p>
|
||||||
|
<p class="text-muted">Статус: статус</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2">
|
||||||
|
<span class="fa-stack fa-1x">
|
||||||
|
<i class="fa fa-circle fa-stack-2x text-primary"></i>
|
||||||
|
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="col col-10 text-right">
|
||||||
|
<h7 class="service-heading">Название гранта</h7>
|
||||||
|
<p class="text-muted">Краткое описание</p>
|
||||||
|
<p class="text-muted">Статус: статус</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2">
|
||||||
|
<span class="fa-stack fa-1x">
|
||||||
|
<i class="fa fa-circle fa-stack-2x text-primary"></i>
|
||||||
|
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="col col-10 text-right">
|
||||||
|
<h7 class="service-heading">Название гранта</h7>
|
||||||
|
<p class="text-muted">Краткое описание</p>
|
||||||
|
<p class="text-muted">Статус: статус</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2">
|
||||||
|
<span class="fa-stack fa-1x">
|
||||||
|
<i class="fa fa-circle fa-stack-2x text-primary"></i>
|
||||||
|
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="col col-10 text-right">
|
||||||
|
<h7 class="service-heading">Название гранта</h7>
|
||||||
|
<p class="text-muted">Краткое описание</p>
|
||||||
|
<p class="text-muted">Статус: статус</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2">
|
||||||
|
<span class="fa-stack fa-1x">
|
||||||
|
<i class="fa fa-circle fa-stack-2x text-primary"></i>
|
||||||
|
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="col col-10 text-right">
|
||||||
|
<h7 class="service-heading">Название гранта</h7>
|
||||||
|
<p class="text-muted">Краткое описание</p>
|
||||||
|
<p class="text-muted">Статус: статус</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2">
|
||||||
|
<span class="fa-stack fa-1x">
|
||||||
|
<i class="fa fa-circle fa-stack-2x text-primary"></i>
|
||||||
|
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="col col-10 text-right">
|
||||||
|
<h7 class="service-heading">Название гранта</h7>
|
||||||
|
<p class="text-muted">Краткое описание</p>
|
||||||
|
<p class="text-muted">Статус: статус</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2">
|
||||||
|
<span class="fa-stack fa-1x">
|
||||||
|
<i class="fa fa-circle fa-stack-2x text-primary"></i>
|
||||||
|
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="col col-10 text-right">
|
||||||
|
<h7 class="service-heading">Название гранта</h7>
|
||||||
|
<p class="text-muted">Краткое описание</p>
|
||||||
|
<p class="text-muted">Статус: статус</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2">
|
||||||
|
<span class="fa-stack fa-1x">
|
||||||
|
<i class="fa fa-circle fa-stack-2x text-primary"></i>
|
||||||
|
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="col col-10 text-right">
|
||||||
|
<h7 class="service-heading">Название гранта</h7>
|
||||||
|
<p class="text-muted">Краткое описание</p>
|
||||||
|
<p class="text-muted">Статус: статус</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,22 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorator="default">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<div class="container" layout:fragment="content">
|
|
||||||
<section id="papers">
|
|
||||||
<div class="container">
|
|
||||||
<div class="row" id="paper-list">
|
|
||||||
<div class="col-lg-12 text-center">
|
|
||||||
<h2 class="section-heading text-uppercase">Пустая страница</h2>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue