Skip to content
Snippets Groups Projects
Commit 4cec842a authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#565 - migrated fro deprecated CronSequenceGenerator to CronExpression

parent 2d810b53
No related branches found
No related tags found
No related merge requests found
Pipeline #4908 failed
...@@ -3,16 +3,19 @@ package de.deadlocker8.budgetmaster.backup; ...@@ -3,16 +3,19 @@ package de.deadlocker8.budgetmaster.backup;
import de.deadlocker8.budgetmaster.database.DatabaseService; import de.deadlocker8.budgetmaster.database.DatabaseService;
import de.deadlocker8.budgetmaster.settings.Settings; import de.deadlocker8.budgetmaster.settings.Settings;
import de.deadlocker8.budgetmaster.settings.SettingsService; import de.deadlocker8.budgetmaster.settings.SettingsService;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.support.CronSequenceGenerator; import org.springframework.scheduling.support.CronExpression;
import org.springframework.scheduling.support.CronTrigger; import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.TimeZone;
import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledFuture;
@Service @Service
...@@ -81,16 +84,16 @@ public class BackupService ...@@ -81,16 +84,16 @@ public class BackupService
return String.format("0 0 %d */%d * *", hour, days); return String.format("0 0 %d */%d * *", hour, days);
} }
public Optional<DateTime> getNextRun() public Optional<LocalDateTime> getNextRun()
{ {
final Settings settings = settingsService.getSettings(); final Settings settings = settingsService.getSettings();
if(settings.isAutoBackupActive()) if(settings.isAutoBackupActive())
{ {
final String cron = computeCron(settings.getAutoBackupTime(), settings.getAutoBackupDays()); final String cron = computeCron(settings.getAutoBackupTime(), settings.getAutoBackupDays());
CronSequenceGenerator cronTrigger = new CronSequenceGenerator(cron); final CronExpression cronExpression = CronExpression.parse(cron);
Date next = cronTrigger.next(new Date()); final LocalDateTime next = cronExpression.next(LocalDateTime.now());
return Optional.of(new DateTime(next)); return Optional.ofNullable(next);
} }
return Optional.empty(); return Optional.empty();
} }
......
...@@ -6,6 +6,9 @@ import org.joda.time.format.DateTimeFormat; ...@@ -6,6 +6,9 @@ import org.joda.time.format.DateTimeFormat;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@Service @Service
public class DateService public class DateService
{ {
...@@ -63,4 +66,10 @@ public class DateService ...@@ -63,4 +66,10 @@ public class DateService
{ {
return DateTime.now(); return DateTime.now();
} }
public String getDateTimeString(LocalDateTime localDateTime)
{
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateFormatStyle.DATE_TIME.getKey()).withLocale(settingsService.getSettings().getLanguage().getLocale());
return localDateTime.format(formatter);
}
} }
...@@ -25,7 +25,6 @@ import de.thecodelabs.utils.util.RandomUtils; ...@@ -25,7 +25,6 @@ import de.thecodelabs.utils.util.RandomUtils;
import de.thecodelabs.versionizer.UpdateItem; import de.thecodelabs.versionizer.UpdateItem;
import org.eclipse.jgit.transport.CredentialsProvider; import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
...@@ -42,6 +41,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -42,6 +41,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -416,7 +416,7 @@ public class SettingsController extends BaseController ...@@ -416,7 +416,7 @@ public class SettingsController extends BaseController
model.addAttribute("searchResultsPerPageOptions", SEARCH_RESULTS_PER_PAGE_OPTIONS); model.addAttribute("searchResultsPerPageOptions", SEARCH_RESULTS_PER_PAGE_OPTIONS);
model.addAttribute("autoBackupTimes", AutoBackupTime.values()); model.addAttribute("autoBackupTimes", AutoBackupTime.values());
final Optional<DateTime> nextBackupTimeOptional = backupService.getNextRun(); final Optional<LocalDateTime> nextBackupTimeOptional = backupService.getNextRun();
nextBackupTimeOptional.ifPresent(date -> model.addAttribute("nextBackupTime", date)); nextBackupTimeOptional.ifPresent(date -> model.addAttribute("nextBackupTime", date));
model.addAttribute("autoBackupStatus", backupService.getBackupStatus()); model.addAttribute("autoBackupStatus", backupService.getBackupStatus());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment