This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit 09ee0868 authored by Michael Breu's avatar Michael Breu :speech_balloon:
Browse files

Refactoring Tests and simplifying Mail Sending

parent 6cf42517
Branches
Tags
2 merge requests!55June Release,!52Resolve "Extend Bookmarklists and implement stored searches"
......@@ -119,7 +119,7 @@ public class MailService {
/**
* send an info mail to user, if relevant.
* For test purposes mainly
* For test purposes mainly.
* @param user
* @return
*/
......@@ -139,13 +139,22 @@ public class MailService {
user = userRepository.save(user);
}
Map<SearchResultDTO, UserWatchList> findChangesSince = null;
for(CheckFrequency freq: new CheckFrequency[] {CheckFrequency.DAILY, CheckFrequency.WEEKLY, CheckFrequency.MONTHLY}) {
if(lastMailSending.isBefore(freq.getChangedBefore())) {
findChangesSince = userWatchListService.findChangesSince(freq, user);
if(!findChangesSince.isEmpty()) break;
}
}
hasContent = hasContent || findChangesSince!=null && !findChangesSince.isEmpty();
findChangesSince = userWatchListService.findChangesSince(lastMailSending, user);
boolean dailyRelevant = findChangesSince.entrySet().stream().anyMatch(entry -> entry.getValue().getCheckFrequency() == CheckFrequency.DAILY);
boolean weeklyRelevant = findChangesSince.entrySet().stream().anyMatch(entry -> entry.getValue().getCheckFrequency() == CheckFrequency.WEEKLY);
boolean monthlyRelevant = findChangesSince.entrySet().stream().anyMatch(entry -> entry.getValue().getCheckFrequency() == CheckFrequency.MONTHLY);
boolean shouldSend =
(dailyRelevant && lastMailSending.isBefore(CheckFrequency.DAILY.getChangedBefore())) ||
(weeklyRelevant && lastMailSending.isBefore(CheckFrequency.WEEKLY.getChangedBefore())) ||
(monthlyRelevant && lastMailSending.isBefore(CheckFrequency.MONTHLY.getChangedBefore()));
hasContent = hasContent || shouldSend;
if(hasContent) {
final List<Entry<SearchResultDTO, UserWatchList>> changedExercises = findChangesSince.entrySet().stream().collect(Collectors.toList());
......
......@@ -222,12 +222,13 @@ public class UserWatchListService {
return result;
}
public Map<SearchResultDTO, UserWatchList> findChangesSince(CheckFrequency checkFrequency, at.ac.uibk.gitsearch.domain.User user) {
Map<SearchResultDTO, UserWatchList> changesSince = findChangesSince(checkFrequency.getChangedBefore(), user);
return changesSince.entrySet().stream().
filter(entry -> entry.getValue().getCheckFrequency().ordinal() <= checkFrequency.ordinal())
.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
}
// falscher Weg
// public Map<SearchResultDTO, UserWatchList> findChangesSince(CheckFrequency checkFrequency, at.ac.uibk.gitsearch.domain.User user) {
// Map<SearchResultDTO, UserWatchList> changesSince = findChangesSince(checkFrequency.getChangedBefore(), user);
// return changesSince.entrySet().stream().
// filter(entry -> entry.getValue().getCheckFrequency().ordinal() <= checkFrequency.ordinal())
// .collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
//
// }
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment