Skip to content

Commit

Permalink
Static imports
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Dec 19, 2024
1 parent 2f7cf58 commit af188b3
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static myconext.model.UserInactivity.*;

@Component
public class InactivityMail {

Expand Down Expand Up @@ -48,7 +50,7 @@ public void mailInactiveUsers() {
return;
}
try {
Stream.of(UserInactivity.values()).forEach(this::doMailInactiveUsers);
Stream.of(values()).forEach(this::doMailInactiveUsers);
this.doDeleteInactiveUsers();
} catch (Exception e) {
//swallow exception as the scheduling stops then
Expand All @@ -75,7 +77,7 @@ private void doMailInactiveUsers(UserInactivity userInactivity) {
localeVariables.put("account_delete_date_nl", dateFormatNL.format(date));
users.forEach(user -> {
mailBox.sendUserInactivityMail(user, localeVariables,
userInactivity.equals(UserInactivity.YEAR_1_INTERVAL) || userInactivity.equals(UserInactivity.YEAR_3_INTERVAL));
userInactivity.equals(YEAR_1_INTERVAL) || userInactivity.equals(YEAR_3_INTERVAL));
user.setUserInactivity(userInactivity);
userRepository.save(user);
});
Expand All @@ -88,7 +90,7 @@ private void doDeleteInactiveUsers() {
long oneDayInMillis = 24 * 60 * 60 * 1000L;

long lastLoginBefore = nowInMillis - (oneDayInMillis * 5L * 365);
List<User> users = userRepository.findByLastLoginBeforeAndUserInactivity(lastLoginBefore, UserInactivity.WEEK_1_BEFORE_5_YEARS);
List<User> users = userRepository.findByLastLoginBeforeAndUserInactivity(lastLoginBefore, WEEK_1_BEFORE_5_YEARS);
userRepository.deleteAll(users);
LOG.info(String.format("Deleted %s users (%s) who has been inactive for 5 years in for %s ms",
users.size(), users.stream().map(User::getEmail).collect(Collectors.joining(", ")),
Expand Down

0 comments on commit af188b3

Please sign in to comment.