#119 add send notification functions

merge-requests/84/head
T-Midnight 5 years ago
parent 74a8dcbd8a
commit 77e2ad0651

@ -23,7 +23,9 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static java.util.stream.Collectors.toList;
import static org.springframework.util.ObjectUtils.isEmpty;
@ -41,6 +43,7 @@ public class GrantService {
private final UserService userService;
private final PaperService paperService;
private final EventService eventService;
private final GrantNotificationService grantNotificationService;
public GrantService(GrantRepository grantRepository,
FileService fileService,
@ -48,7 +51,8 @@ public class GrantService {
ProjectService projectService,
UserService userService,
PaperService paperService,
EventService eventService) {
EventService eventService,
GrantNotificationService grantNotificationService) {
this.grantRepository = grantRepository;
this.fileService = fileService;
this.deadlineService = deadlineService;
@ -56,6 +60,7 @@ public class GrantService {
this.userService = userService;
this.paperService = paperService;
this.eventService = eventService;
this.grantNotificationService = grantNotificationService;
}
public List<Grant> findAll() {
@ -77,6 +82,7 @@ public class GrantService {
Grant newGrant = copyFromDto(new Grant(), grantDto);
newGrant = grantRepository.save(newGrant);
eventService.createFromGrant(newGrant);
grantNotificationService.sendCreateNotification(newGrant);
return newGrant.getId();
}
@ -113,6 +119,8 @@ public class GrantService {
@Transactional
public Integer update(GrantDto grantDto) throws IOException {
Grant grant = grantRepository.findOne(grantDto.getId());
Set<User> oldAuthors = new HashSet<>(grant.getAuthors());
User oldLeader = grant.getLeader();
for (FileDataDto file : grantDto.getFiles().stream()
.filter(f -> f.isDeleted() && f.getId() != null)
.collect(toList())) {
@ -120,6 +128,20 @@ public class GrantService {
}
grantDto.getRemovedDeadlineIds().forEach(deadlineService::remove);
grantRepository.save(copyFromDto(grant, grantDto));
grant.getAuthors().forEach(author -> {
if (!oldAuthors.contains(author)) {
grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors);
}
});
oldAuthors.forEach(oldAuthor -> {
if (!grant.getAuthors().contains(oldAuthor)) {
grantNotificationService.sendAuthorsChangeNotification(grant, oldAuthors);
}
});
if (grant.getLeader() != oldLeader) {
grantNotificationService.sendLeaderChangeNotification(grant, oldLeader);
}
eventService.updateGrantDeadlines(grant);
return grant.getId();
}
@ -148,6 +170,7 @@ public class GrantService {
grant = grantRepository.save(grant);
eventService.createFromGrant(grant);
grantNotificationService.sendCreateNotification(grant);
return grant;
}
@ -222,7 +245,6 @@ public class GrantService {
.filter(paper -> paper.getAuthors() != null)
.flatMap(paper -> paper.getAuthors().stream())
.collect(toList());
}
private List<User> getBAKAuthors() {

Loading…
Cancel
Save