Resolve "Реализовать уведомления на почту" #211
@ -23,7 +23,9 @@ import java.io.IOException;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||||
@ -41,6 +43,7 @@ public class GrantService {
|
|||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
private final PaperService paperService;
|
private final PaperService paperService;
|
||||||
private final EventService eventService;
|
private final EventService eventService;
|
||||||
|
private final GrantNotificationService grantNotificationService;
|
||||||
|
|
||||||
public GrantService(GrantRepository grantRepository,
|
public GrantService(GrantRepository grantRepository,
|
||||||
FileService fileService,
|
FileService fileService,
|
||||||
@ -48,7 +51,8 @@ public class GrantService {
|
|||||||
ProjectService projectService,
|
ProjectService projectService,
|
||||||
UserService userService,
|
UserService userService,
|
||||||
PaperService paperService,
|
PaperService paperService,
|
||||||
EventService eventService) {
|
EventService eventService,
|
||||||
|
GrantNotificationService grantNotificationService) {
|
||||||
this.grantRepository = grantRepository;
|
this.grantRepository = grantRepository;
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
this.deadlineService = deadlineService;
|
this.deadlineService = deadlineService;
|
||||||
@ -56,6 +60,7 @@ public class GrantService {
|
|||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.paperService = paperService;
|
this.paperService = paperService;
|
||||||
this.eventService = eventService;
|
this.eventService = eventService;
|
||||||
|
this.grantNotificationService = grantNotificationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Grant> findAll() {
|
public List<Grant> findAll() {
|
||||||
@ -77,6 +82,7 @@ public class GrantService {
|
|||||||
Grant newGrant = copyFromDto(new Grant(), grantDto);
|
Grant newGrant = copyFromDto(new Grant(), grantDto);
|
||||||
newGrant = grantRepository.save(newGrant);
|
newGrant = grantRepository.save(newGrant);
|
||||||
eventService.createFromGrant(newGrant);
|
eventService.createFromGrant(newGrant);
|
||||||
|
grantNotificationService.sendCreateNotification(newGrant);
|
||||||
return newGrant.getId();
|
return newGrant.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +119,8 @@ public class GrantService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public Integer update(GrantDto grantDto) throws IOException {
|
public Integer update(GrantDto grantDto) throws IOException {
|
||||||
Grant grant = grantRepository.findOne(grantDto.getId());
|
Grant grant = grantRepository.findOne(grantDto.getId());
|
||||||
|
Set<User> oldAuthors = new HashSet<>(grant.getAuthors());
|
||||||
|
User oldLeader = grant.getLeader();
|
||||||
for (FileDataDto file : grantDto.getFiles().stream()
|
for (FileDataDto file : grantDto.getFiles().stream()
|
||||||
.filter(f -> f.isDeleted() && f.getId() != null)
|
.filter(f -> f.isDeleted() && f.getId() != null)
|
||||||
.collect(toList())) {
|
.collect(toList())) {
|
||||||
@ -120,6 +128,20 @@ public class GrantService {
|
|||||||
}
|
}
|
||||||
grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
|
||||||
grantRepository.save(copyFromDto(grant, grantDto));
|
grantRepository.save(copyFromDto(grant, grantDto));
|
||||||
|
|
||||||
|
grant.getAuthors().forEach(author -> {
|
||||||
|
if (!oldAuthors.contains(author)) {
|
||||||
|
grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
oldAuthors.forEach(oldAuthor -> {
|
||||||
|
if (!grant.getAuthors().contains(oldAuthor)) {
|
||||||
|
grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (grant.getLeader() != oldLeader) {
|
||||||
|
grantNotificationService.sendLeaderChangeNotification(grant, oldLeader);
|
||||||
|
}
|
||||||
eventService.updateGrantDeadlines(grant);
|
eventService.updateGrantDeadlines(grant);
|
||||||
return grant.getId();
|
return grant.getId();
|
||||||
}
|
}
|
||||||
@ -148,6 +170,7 @@ public class GrantService {
|
|||||||
grant = grantRepository.save(grant);
|
grant = grantRepository.save(grant);
|
||||||
|
|
||||||
eventService.createFromGrant(grant);
|
eventService.createFromGrant(grant);
|
||||||
|
grantNotificationService.sendCreateNotification(grant);
|
||||||
|
|
||||||
return grant;
|
return grant;
|
||||||
}
|
}
|
||||||
@ -222,7 +245,6 @@ public class GrantService {
|
|||||||
.filter(paper -> paper.getAuthors() != null)
|
.filter(paper -> paper.getAuthors() != null)
|
||||||
.flatMap(paper -> paper.getAuthors().stream())
|
.flatMap(paper -> paper.getAuthors().stream())
|
||||||
.collect(toList());
|
.collect(toList());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<User> getBAKAuthors() {
|
private List<User> getBAKAuthors() {
|
||||||
|
Loading…
Reference in New Issue
Block a user