Merge branch 'master' into 10-savePaper

This commit is contained in:
Elena 2018-11-09 13:43:08 +04:00
commit 0f9bbc13cc
27 changed files with 411 additions and 100 deletions

View File

@ -1,4 +1,4 @@
https://212.8.234.87:8443 demo https://193.110.3.124:8443 demo
Developer mode Developer mode

View File

@ -15,6 +15,16 @@ public class ApplicationProperties {
private String undeadUserLogin; private String undeadUserLogin;
private boolean devMode; private boolean devMode;
private boolean useHttps;
public boolean isUseHttps() {
return useHttps;
}
public void setUseHttps(boolean useHttps) {
this.useHttps = useHttps;
}
public String getBaseUrl() { public String getBaseUrl() {
return baseUrl; return baseUrl;
} }

View File

@ -17,6 +17,8 @@ class ControllersConfiguration {
config.addAllowedHeader("*"); config.addAllowedHeader("*");
config.addAllowedMethod("GET"); config.addAllowedMethod("GET");
config.addAllowedMethod("POST"); config.addAllowedMethod("POST");
config.addAllowedMethod("PUT");
config.addAllowedMethod("OPTIONAL");
config.addAllowedMethod("DELETE"); config.addAllowedMethod("DELETE");
source.registerCorsConfiguration("/**", config); source.registerCorsConfiguration("/**", config);
return new CorsFilter(source); return new CorsFilter(source);

View File

@ -86,13 +86,16 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
.deleteCookies(Constants.COOKIES_NAME) .deleteCookies(Constants.COOKIES_NAME)
.permitAll(); .permitAll();
} }
http.portMapper() if (applicationProperties.isUseHttps()) {
.http(httpPort) http.portMapper()
.mapsTo(httpsPort) .http(httpPort)
.and() .mapsTo(httpsPort)
.requiresChannel() .and()
.anyRequest() .requiresChannel()
.requiresSecure(); .anyRequest()
.requiresSecure();
}
} }
@Override @Override

View File

@ -0,0 +1,9 @@
package ru.ulstu.core.model;
import ru.ulstu.user.model.User;
import java.util.Set;
public interface UserContainer {
Set<User> getUsers();
}

View File

@ -43,4 +43,10 @@ public class DateUtils {
public static Date localTimeToDate(LocalTime localTime) { public static Date localTimeToDate(LocalTime localTime) {
return Date.from(localTime.atDate(LocalDate.now()).atZone(ZoneId.systemDefault()).toInstant()); return Date.from(localTime.atDate(LocalDate.now()).atZone(ZoneId.systemDefault()).toInstant());
} }
public static Date addDays(Date date, int count) {
Calendar cal = getCalendar(date);
cal.add(Calendar.DAY_OF_MONTH, count);
return cal.getTime();
}
} }

View File

@ -2,6 +2,7 @@ package ru.ulstu.core.util;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -9,7 +10,13 @@ public class StreamApiUtils {
public static <T, R> List<T> convert(List<R> entities, Function<R, T> converter) { public static <T, R> List<T> convert(List<R> entities, Function<R, T> converter) {
return entities == null return entities == null
? Collections.EMPTY_LIST ? Collections.emptyList()
: entities.stream().map(e -> converter.apply(e)).collect(Collectors.toList()); : entities.stream().map(e -> converter.apply(e)).collect(Collectors.toList());
} }
public static <T, R> Set<T> convert(Set<R> entities, Function<R, T> converter) {
return entities == null
? Collections.emptySet()
: entities.stream().map(e -> converter.apply(e)).collect(Collectors.toSet());
}
} }

View File

@ -14,6 +14,7 @@ import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperStatusDto; import ru.ulstu.paper.model.PaperStatusDto;
import ru.ulstu.paper.service.PaperService; import ru.ulstu.paper.service.PaperService;
import javax.validation.Valid;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -32,16 +33,16 @@ public class PaperController {
@GetMapping @GetMapping
public Response<List<PaperDto>> getPapers() { public Response<List<PaperDto>> getPapers() {
return new Response<>(paperService.findAll()); return new Response<>(paperService.findAllDto());
} }
@PostMapping @PostMapping
public Response createPaper(@RequestBody PaperDto paperDto) throws IOException { public Response createPaper(@RequestBody @Valid PaperDto paperDto) throws IOException {
return new Response(paperService.create(paperDto)); return new Response(paperService.create(paperDto));
} }
@PutMapping @PutMapping
public Response updatePaper(@RequestBody PaperDto paperDto) throws IOException { public Response updatePaper(@RequestBody @Valid PaperDto paperDto) throws IOException {
return new Response(paperService.update(paperDto)); return new Response(paperService.update(paperDto));
} }

View File

@ -2,15 +2,26 @@ package ru.ulstu.paper.model;
import org.hibernate.validator.constraints.NotBlank; import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.core.model.UserContainer;
import ru.ulstu.file.model.FileData; import ru.ulstu.file.model.FileData;
import ru.ulstu.user.model.User; import ru.ulstu.user.model.User;
import javax.persistence.*; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
@Entity @Entity
public class Paper extends BaseEntity { public class Paper extends BaseEntity implements UserContainer {
public enum PaperStatus { public enum PaperStatus {
ATTENTION("Обратить внимание"), ON_PREPARATION("На подготовке"), DRAFT("Черновик"), COMPLETED("Завершена"); ATTENTION("Обратить внимание"), ON_PREPARATION("На подготовке"), DRAFT("Черновик"), COMPLETED("Завершена");
@ -29,27 +40,28 @@ public class Paper extends BaseEntity {
private String title; private String title;
@Enumerated(value = EnumType.STRING) @Enumerated(value = EnumType.STRING)
private PaperStatus status; private PaperStatus status = PaperStatus.DRAFT;
@Column(name = "create_date") @Column(name = "create_date")
private Date createDate; private Date createDate = new Date();
@Column(name = "update_date") @Column(name = "update_date")
private Date updateDate; private Date updateDate = new Date();
@Column(name = "deadline_date") @Column(name = "deadline_date")
@NotNull
private Date deadlineDate; private Date deadlineDate;
private String comment; private String comment;
private Boolean locked; private Boolean locked = false;
@ManyToOne @ManyToOne
@JoinColumn(name = "file_id") @JoinColumn(name = "file_id")
private FileData fileData; private FileData fileData;
@ManyToMany @ManyToMany(fetch = FetchType.EAGER)
private List<User> authors; private Set<User> authors = new HashSet<>();
public PaperStatus getStatus() { public PaperStatus getStatus() {
return status; return status;
@ -115,11 +127,16 @@ public class Paper extends BaseEntity {
this.title = title; this.title = title;
} }
public List<User> getAuthors() { public Set<User> getAuthors() {
return authors; return authors;
} }
public void setAuthors(List<User> authors) { public void setAuthors(Set<User> authors) {
this.authors = authors; this.authors = authors;
} }
@Override
public Set<User> getUsers() {
return getAuthors();
}
} }

View File

@ -2,19 +2,23 @@ package ru.ulstu.paper.model;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.NotEmpty;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserDto;
import javax.validation.constraints.NotNull;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.Set;
import static ru.ulstu.core.util.StreamApiUtils.convert; import static ru.ulstu.core.util.StreamApiUtils.convert;
public class PaperDto { public class PaperDto {
private final Integer id; private final Integer id;
@NotEmpty
private final String title; private final String title;
private final Paper.PaperStatus status; private final Paper.PaperStatus status;
private final Date createDate; private final Date createDate;
private final Date updateDate; private final Date updateDate;
@NotNull
private final Date deadlineDate; private final Date deadlineDate;
private final String comment; private final String comment;
private final Boolean locked; private final Boolean locked;
@ -22,7 +26,7 @@ public class PaperDto {
private final Integer fileId; private final Integer fileId;
private final String fileName; private final String fileName;
private final Date fileCreateDate; private final Date fileCreateDate;
private final List<UserDto> authors; private final Set<UserDto> authors;
@JsonCreator @JsonCreator
public PaperDto(@JsonProperty("id") Integer id, public PaperDto(@JsonProperty("id") Integer id,
@ -34,7 +38,7 @@ public class PaperDto {
@JsonProperty("comment") String comment, @JsonProperty("comment") String comment,
@JsonProperty("locked") Boolean locked, @JsonProperty("locked") Boolean locked,
@JsonProperty("tmpFileName") String tmpFileName, @JsonProperty("tmpFileName") String tmpFileName,
@JsonProperty("authors") List<UserDto> authors) { @JsonProperty("authors") Set<UserDto> authors) {
this.id = id; this.id = id;
this.title = title; this.title = title;
this.status = status; this.status = status;
@ -86,7 +90,9 @@ public class PaperDto {
return updateDate; return updateDate;
} }
public Date getDeadlineDate() {return deadlineDate;} public Date getDeadlineDate() {
return deadlineDate;
}
public String getComment() { public String getComment() {
return comment; return comment;
@ -112,7 +118,7 @@ public class PaperDto {
return fileCreateDate; return fileCreateDate;
} }
public List<UserDto> getAuthors() { public Set<UserDto> getAuthors() {
return authors; return authors;
} }
} }

View File

@ -4,62 +4,34 @@ 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.paper.model.Paper;
import ru.ulstu.paper.repository.PaperRepository;
import ru.ulstu.user.model.User;
import ru.ulstu.user.scheduler.UserScheduler;
import ru.ulstu.user.service.MailService;
import java.util.Calendar;
import java.util.List;
@Service @Service
public class DeadlineScheduler { public class DeadlineScheduler {
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
private final Logger log = LoggerFactory.getLogger(DeadlineScheduler.class); private final Logger log = LoggerFactory.getLogger(DeadlineScheduler.class);
private final PaperRepository paperRepository; private final PaperNotificationService paperNotificationService;
private final PaperService paperService;
private final MailService mailService; public DeadlineScheduler(PaperNotificationService paperNotificationService,
PaperService paperService) {
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true; this.paperNotificationService = paperNotificationService;
this.paperService = paperService;
public DeadlineScheduler(PaperRepository paperRepository, MailService mailService) {
this.paperRepository = paperRepository;
this.mailService = mailService;
} }
@Scheduled(cron = "0 0 8 * 1 ?") @Scheduled(cron = "0 0 8 * 1 ?")
public void checkDeadlineBeforeWeek() { public void checkDeadlineBeforeWeek() {
log.debug("DeadlineScheduler.checkDeadlineBeforeWeek started"); log.debug("DeadlineScheduler.checkDeadlineBeforeWeek started");
sendNotifications(IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); paperNotificationService.sendDeadlineNotifications(paperService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
log.debug("DeadlineScheduler.checkDeadlineBeforeWeek finished"); log.debug("DeadlineScheduler.checkDeadlineBeforeWeek finished");
} }
@Scheduled(cron = "0 0 8 * * ?") @Scheduled(cron = "0 0 8 * * ?")
public void checkDeadlineAfterWeek() { public void checkDeadlineAfterWeek() {
log.debug("DeadlineScheduler.checkDeadlineAfterWeek started"); log.debug("DeadlineScheduler.checkDeadlineAfterWeek started");
sendNotifications(!IS_DEADLINE_NOTIFICATION_BEFORE_WEEK); paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
log.debug("DeadlineScheduler.checkDeadlineAfterWeek finished"); log.debug("DeadlineScheduler.checkDeadlineAfterWeek finished");
} }
private void sendNotifications(boolean isDeadlineBeforeWeek) {
List<Paper> allPapers = paperRepository.findAll();
for (Paper paper : allPapers) {
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_YEAR, 7);
if (((c.getTime().compareTo(paper.getDeadlineDate()) < 0) && isDeadlineBeforeWeek) ||
(c.getTime().compareTo(paper.getDeadlineDate()) >= 0) && !isDeadlineBeforeWeek) {
sendMessageDeadline(paper);
}
}
}
private void sendMessageDeadline(Paper paper){
for (User user : paper.getAuthors()) {
mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи",
"Срок сдачи статьи " + paper.getTitle() + " " + paper.getDeadlineDate().toString());
}
}
} }

View File

@ -0,0 +1,57 @@
package ru.ulstu.paper.service;
import com.google.common.collect.ImmutableMap;
import org.springframework.stereotype.Service;
import ru.ulstu.core.util.DateUtils;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.user.service.MailService;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class PaperNotificationService {
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
private final MailService mailService;
public PaperNotificationService(MailService mailService) {
this.mailService = mailService;
}
public void sendDeadlineNotifications(List<Paper> papers, boolean isDeadlineBeforeWeek) {
Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION);
papers
.stream()
.filter(paper -> needToSendDeadlineNotification(paper, now, isDeadlineBeforeWeek))
.forEach(paper -> sendMessageDeadline(paper));
}
private boolean needToSendDeadlineNotification(Paper paper, Date compareDate, boolean isDeadlineBeforeWeek) {
return (paper.getDeadlineDate() != null)
&& (compareDate.after(paper.getDeadlineDate()) && isDeadlineBeforeWeek
|| compareDate.before(paper.getDeadlineDate()) && !isDeadlineBeforeWeek);
}
private void sendMessageDeadline(Paper paper) {
paper.getAuthors().forEach(user -> {
mailService.sendEmail(user.getEmail(), "Приближается срок сдачи статьи",
"Срок сдачи статьи " + paper.getTitle() + " " + paper.getDeadlineDate().toString());
});
}
public void sendCreateNotification(Paper paper) {
Map<String, Object> variables = ImmutableMap.of("paper", paper);
paper.getAuthors().forEach(author -> {
mailService.sendEmailFromTemplate(variables, author, "paperCreateNotification", "Создана статья");
});
}
public void statusChangeNotification(Paper paper, Paper.PaperStatus oldStatus) {
Map<String, Object> variables = ImmutableMap.of("paper", paper, "oldStatus", oldStatus);
paper.getAuthors().forEach(author -> {
mailService.sendEmailFromTemplate(variables, author, "paperStatusChangeNotification", "Изменился статус статьи");
});
}
}

View File

@ -7,11 +7,12 @@ import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperStatusDto; import ru.ulstu.paper.model.PaperStatusDto;
import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.paper.repository.PaperRepository;
import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.User;
import ru.ulstu.user.service.MailService; import ru.ulstu.user.service.UserService;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -19,22 +20,24 @@ import static ru.ulstu.core.util.StreamApiUtils.convert;
@Service @Service
public class PaperService { public class PaperService {
private final PaperNotificationService paperNotificationService;
private final PaperRepository paperRepository; private final PaperRepository paperRepository;
private final UserService userService;
private final FileService fileService; private final FileService fileService;
public final MailService mailService;
public PaperService(PaperRepository paperRepository, public PaperService(PaperRepository paperRepository,
FileService fileService, MailService mailService) { FileService fileService,
PaperNotificationService paperNotificationService,
UserService userService) {
this.paperRepository = paperRepository; this.paperRepository = paperRepository;
this.fileService = fileService; this.fileService = fileService;
this.mailService = mailService; this.paperNotificationService = paperNotificationService;
this.userService = userService;
} }
public List<PaperDto> findAll() { public List<Paper> findAll() {
List<Paper> allPapers = paperRepository.findAll(); return paperRepository.findAll().stream().sorted((paper1, paper2) -> {
allPapers = allPapers.stream().sorted((paper1, paper2) -> {
int statusCompareResult = int statusCompareResult =
Integer.valueOf(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper1.getStatus())) Integer.valueOf(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper1.getStatus()))
.compareTo(Integer.valueOf(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper2.getStatus()))); .compareTo(Integer.valueOf(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper2.getStatus())));
@ -43,37 +46,53 @@ public class PaperService {
} }
return paper1.getTitle().compareTo(paper2.getTitle()); return paper1.getTitle().compareTo(paper2.getTitle());
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return convert(allPapers, PaperDto::new); }
public List<PaperDto> findAllDto() {
return convert(findAll(), PaperDto::new);
} }
@Transactional @Transactional
public int create(PaperDto paperDto) throws IOException { public int create(PaperDto paperDto) throws IOException {
return paperRepository.save(copyFromDto(new Paper(), paperDto)).getId(); Paper newPaper = copyFromDto(new Paper(), paperDto);
newPaper = paperRepository.save(newPaper);
paperNotificationService.sendCreateNotification(newPaper);
return newPaper.getId();
} }
private Paper copyFromDto(Paper paper, PaperDto paperDto) throws IOException { private Paper copyFromDto(Paper paper, PaperDto paperDto) throws IOException {
paper.setComment(paperDto.getComment()); paper.setComment(paperDto.getComment());
paper.setCreateDate(paperDto.getCreateDate()); paper.setCreateDate(paper.getCreateDate() == null ? new Date() : paper.getCreateDate());
paper.setLocked(paperDto.getLocked()); paper.setLocked(paperDto.getLocked());
paper.setStatus(paperDto.getStatus()); paper.setStatus(paperDto.getStatus() == null ? Paper.PaperStatus.DRAFT : paperDto.getStatus());
paper.setTitle(paperDto.getTitle()); paper.setTitle(paperDto.getTitle());
paper.setUpdateDate(paperDto.getUpdateDate()); paper.setUpdateDate(new Date());
paper.setDeadlineDate(paperDto.getDeadlineDate());
if (paperDto.getTmpFileName() != null) { if (paperDto.getTmpFileName() != null) {
paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName())); paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName()));
} }
if (paperDto.getAuthors() != null && !paperDto.getAuthors().isEmpty()) {
paperDto.getAuthors().forEach(authorIds -> {
paper.getAuthors().add(userService.findById(authorIds.getId()));
});
}
return paper; return paper;
} }
@Transactional @Transactional
public Integer update(PaperDto paperDto) throws IOException { public Integer update(PaperDto paperDto) throws IOException {
Paper paper = paperRepository.findOne(paperDto.getId()); Paper paper = paperRepository.findOne(paperDto.getId());
if(paper != null && paper.getStatus() != paperDto.getStatus()){ Paper.PaperStatus oldStatus = paper.getStatus();
sendMessageAboutStatusChange(paper.getStatus(),paperDto);
}
if (paperDto.getTmpFileName() != null && paper.getFileData() != null) { if (paperDto.getTmpFileName() != null && paper.getFileData() != null) {
fileService.deleteFile(paper.getFileData()); fileService.deleteFile(paper.getFileData());
} }
return paperRepository.save(copyFromDto(paper, paperDto)).getId(); paperRepository.save(copyFromDto(paper, paperDto));
if (paper.getStatus() != oldStatus) {
paperNotificationService.statusChangeNotification(paper, oldStatus);
}
return paper.getId();
} }
@Transactional @Transactional
@ -86,14 +105,22 @@ public class PaperService {
} }
public List<PaperStatusDto> getPaperStatuses() { public List<PaperStatusDto> getPaperStatuses() {
return convert(Arrays.asList(Paper.PaperStatus.values()), status ->new PaperStatusDto(status)); return convert(Arrays.asList(Paper.PaperStatus.values()), status -> new PaperStatusDto(status));
} }
private void sendMessageAboutStatusChange(Paper.PaperStatus oldStatus, PaperDto paper){ @Transactional
for (UserDto user: paper.getAuthors()) { public Paper create(String title, User user, Date deadlineDate) {
mailService.sendEmail(user.getEmail(), "Обновление статуса статьи", Paper paper = new Paper();
"Статус статьи " + paper.getTitle() + " сменился с " + oldStatus.getName() paper.setTitle(title);
+ " на " + paper.getStatus().getName()); paper.getAuthors().add(user);
} paper.setDeadlineDate(deadlineDate);
paper.setCreateDate(new Date());
paper.setUpdateDate(new Date());
paper.setStatus(Paper.PaperStatus.DRAFT);
paper = paperRepository.save(paper);
paperNotificationService.sendCreateNotification(paper);
return paper;
} }
} }

View File

@ -0,0 +1,28 @@
package ru.ulstu.strategy.api;
import ru.ulstu.core.model.UserContainer;
import ru.ulstu.user.model.User;
import java.util.List;
import java.util.stream.Collectors;
public abstract class EntityCreateStrategy<T extends UserContainer> {
protected abstract List<T> getActiveEntities();
protected abstract void createEntity(User user);
protected void createDefaultEntityIfNeed(List<User> allUsers, List<? extends UserContainer> entities) {
allUsers.forEach(user -> {
if (entities
.stream()
.filter(entity -> entity.getUsers().contains(user))
.collect(Collectors.toSet()).isEmpty()) {
createEntity(user);
}
});
}
public void createEntityIfNeed(List<User> allUsers) {
createDefaultEntityIfNeed(allUsers, getActiveEntities());
}
}

View File

@ -0,0 +1,35 @@
package ru.ulstu.strategy.api;
import org.springframework.stereotype.Service;
import ru.ulstu.core.util.DateUtils;
import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.service.PaperService;
import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService;
import java.util.Date;
import java.util.List;
@Service
public class PaperCreateStrategy extends EntityCreateStrategy<Paper> {
private static final String DEFAULT_NAME = "Статья создана автоматически";
private static final int DEFAULT_DEADLINE_DAYS = 14;
private final PaperService paperService;
private final UserService userService;
public PaperCreateStrategy(PaperService paperService,
UserService userService) {
this.paperService = paperService;
this.userService = userService;
}
@Override
protected List<Paper> getActiveEntities() {
return paperService.findAll();
}
@Override
protected void createEntity(User user) {
paperService.create(DEFAULT_NAME, user, DateUtils.addDays(new Date(), DEFAULT_DEADLINE_DAYS));
}
}

View File

@ -0,0 +1,25 @@
package ru.ulstu.strategy.api;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import ru.ulstu.user.service.UserService;
import java.util.List;
@Service
public class StrategyEntityCreateExecutor {
private final List<EntityCreateStrategy> entityCreateStrategies;
private final UserService userService;
public StrategyEntityCreateExecutor(List<EntityCreateStrategy> entityCreateStrategies,
UserService userService) {
this.entityCreateStrategies = entityCreateStrategies;
this.userService = userService;
}
@Scheduled(cron = "0 0 8 * * *")
public void scheduleExecuteStrategies() {
entityCreateStrategies.forEach(strategy -> strategy.createEntityIfNeed(userService.findAll()));
}
}

View File

@ -77,6 +77,11 @@ public class UserService implements UserDetailsService {
return new PageableItems<>(page.getTotalElements(), userMapper.userEntitiesToUserListDtos(page.getContent())); return new PageableItems<>(page.getTotalElements(), userMapper.userEntitiesToUserListDtos(page.getContent()));
} }
// TODO: read only active users
public List<User> findAll() {
return userRepository.findAll();
}
@Transactional(readOnly = true) @Transactional(readOnly = true)
public PageableItems<UserRoleDto> getUserRoles() { public PageableItems<UserRoleDto> getUserRoles() {
final List<UserRoleDto> roles = userRoleRepository.findAll().stream() final List<UserRoleDto> roles = userRoleRepository.findAll().stream()
@ -286,4 +291,8 @@ public class UserService implements UserDetailsService {
public List<User> findByIds(List<Integer> ids) { public List<User> findByIds(List<Integer> ids) {
return userRepository.findAll(ids); return userRepository.findAll(ids);
} }
public User findById(Integer id) {
return userRepository.findOne(id);
}
} }

View File

@ -16,8 +16,8 @@ logging.level.ru.ulstu=DEBUG
# Mail Settings # Mail Settings
spring.mail.host=smtp.yandex.ru spring.mail.host=smtp.yandex.ru
spring.mail.port=465 spring.mail.port=465
spring.mail.username=balance@soft.kitchen spring.mail.username=nio17.ulstu@yandex.ru
spring.mail.password=fkvfpbalance spring.mail.password=nio17.ulstu.ru
spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.ssl.enable=true spring.mail.properties.mail.smtp.ssl.enable=true
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
@ -34,4 +34,5 @@ liquibase.change-log=classpath:db/changelog-master.xml
# Application Settings # Application Settings
ng-tracker.base-url=https://127.0.0.1:8443 ng-tracker.base-url=https://127.0.0.1:8443
ng-tracker.undead-user-login=admin ng-tracker.undead-user-login=admin
ng-tracker.dev-mode=true ng-tracker.dev-mode=true
ng-tracker.use-https=false

View File

@ -0,0 +1,11 @@
<?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="20181108_000000-1">
<sql>
update users
set email = 'romanov73@gmail.com' where id = 1;
</sql>
</changeSet>
</databaseChangeLog>

View File

@ -13,4 +13,5 @@
<include file="db/changelog-20180505_000000-schema.xml"/> <include file="db/changelog-20180505_000000-schema.xml"/>
<include file="db/changelog-20181027_000000-schema.xml"/> <include file="db/changelog-20181027_000000-schema.xml"/>
<include file="db/changelog-20181030_000000-schema.xml"/> <include file="db/changelog-20181030_000000-schema.xml"/>
<include file="db/changelog-20181108_000000-data.xml"/>
</databaseChangeLog> </databaseChangeLog>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Уведомление о создании статьи</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
</head>
<body>
<p>
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
</p>
<p>
Вам нужно поработать над статьей "<span th:text="${paper.title}">Title</span>".
</p>
<p>
Срок исполнения: <span th:text="${#dates.format(paper.deadlineDate, 'dd.MM.yyyy HH:mm')}"></span>.
</p>
<p>
Regards,
<br/>
<em>NG-tracker.</em>
</p>
</body>
</html>

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Уведомление дедлайне статьи</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
</head>
<body>
<p>
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
</p>
<p>
Приближается срок сдачи статьи "<span th:text="${paper.title}">Title</span>".
</p>
<p>
Срок исполнения: <span th:text="${#dates.format(paper.deadlineDate, 'dd.MM.yyyy HH:mm')}"></span>.
</p>
<p>
Regards,
<br/>
<em>NG-tracker.</em>
</p>
</body>
</html>

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Уведомление о смене статуса статьи</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
</head>
<body>
<p>
Уважаемый(ая) <span th:text="${user.firstName + ' ' + user.lastName}">Ivan Ivanov</span>
</p>
<p>
Статус статьи "<span th:text="${paper.title}">Title</span>" сменился с
"<span th:text="${oldStatus.name}">oldStatus</span>" на "<span th:text="${paper.status.name}">newStatus</span>".
</p>
<p>
Regards,
<br/>
<em>NG-tracker.</em>
</p>
</body>
</html>

View File

@ -62,7 +62,7 @@ section h3.section-subheading {
@media (min-width: 768px) { @media (min-width: 768px) {
section { section {
padding: 150px 0; padding: 100px 0;
} }
} }
@ -741,6 +741,11 @@ ul.social-buttons li a:active, ul.social-buttons li a:focus, ul.social-buttons l
border-radius: 5px; border-radius: 5px;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05); box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
} }
.toolbar-button {
width: 100%;
margin: 5px;
}
/* --------------------------------------------------- /* ---------------------------------------------------
FEEDBACK STYLE FEEDBACK STYLE
----------------------------------------------------- */ ----------------------------------------------------- */

View File

@ -1,7 +1,7 @@
// from config.js // from config.js
/* global urlVersions */ /* global urlVersions */
var urlFileUpload = "https://localhost:8443/api/1.0/papers/uploadTmpFile"; var urlFileUpload = "/api/1.0/papers/uploadTmpFile";
/* exported MessageTypesEnum */ /* exported MessageTypesEnum */
var MessageTypesEnum = { var MessageTypesEnum = {

View File

@ -1,5 +1,5 @@
var urlPapers = "https://localhost:8443/api/1.0/papers"; var urlPapers = "/api/1.0/papers";
var urlPaperStatuses = "https://localhost:8443/api/1.0/papers/statuses"; var urlPaperStatuses = "/api/1.0/papers/statuses";
function showPapers(papersElement) { function showPapers(papersElement) {
getFromRest(urlPapers, function (paperList) { getFromRest(urlPapers, function (paperList) {
@ -10,7 +10,7 @@ function showPapers(papersElement) {
" <i class='fa fa-circle fa-stack-2x " + getPaperStatusClass(paper.status) + "'></i>" + " <i class='fa fa-circle fa-stack-2x " + getPaperStatusClass(paper.status) + "'></i>" +
" <i class='fa fa-file-text-o fa-stack-1x fa-inverse'></i>" + " <i class='fa fa-file-text-o fa-stack-1x fa-inverse'></i>" +
" </span>" + " </span>" +
" <a href='paper.html?id=" + paper.id + "" + " <a href='paper?id=" + paper.id + "" +
"'><span>" + paper.title + "</span></a>" + "'><span>" + paper.title + "</span></a>" +
" </div></div>"); " </div></div>");
}); });

View File

@ -12,8 +12,17 @@
<div class="row" id="paper-list"> <div class="row" id="paper-list">
<div class="col-lg-12 text-center"> <div class="col-lg-12 text-center">
<h2 class="section-heading text-uppercase">Статьи</h2> <h2 class="section-heading text-uppercase">Статьи</h2>
<a href="./dashboard"><h5>Перейти на тестовую страницу Алёны</h5></a>
<a href = "./paper"><h4>Добавить статью</h4></a> <div class="row justify-content-center">
<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="./paper" class="btn btn-light toolbar-button"><i class="fa fa-plus-circle" aria-hidden="true"></i>
Добавить статью</a>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -21,7 +30,7 @@
<script src="/js/papers.js"></script> <script src="/js/papers.js"></script>
<script> <script>
$( document ).ready(function() { $(document).ready(function () {
showPapers($("#paper-list")); showPapers($("#paper-list"));
// only for demo // only for demo
//addPaper("название", "DRAFT", "comment", false); //addPaper("название", "DRAFT", "comment", false);