From ad2283008c5df86cb7fe86cd94b7b95ba4fb321e Mon Sep 17 00:00:00 2001 From: Dominik Przybyl Date: Thu, 2 Nov 2023 01:08:28 +0100 Subject: [PATCH] refactor --- .../com/cognifide/apm/api/scripts/Script.java | 2 +- .../apm/api/scripts/TransientScript.java | 2 +- .../apm/core/endpoints/ScriptUploadForm.java | 6 +-- .../apm/core/grammar/ReferenceFinder.java | 2 +- .../apm/core/scripts/LaunchMetadata.java | 53 +++++++++---------- .../apm/core/scripts/ScriptFilters.java | 2 +- .../apm/core/scripts/ScriptModel.java | 9 ++-- .../apm/core/scripts/ScriptStorageImpl.java | 8 +-- .../ScriptsResourceChangeListener.java | 24 ++++----- 9 files changed, 52 insertions(+), 56 deletions(-) diff --git a/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/Script.java b/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/Script.java index 68e0ecb8..59dead26 100644 --- a/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/Script.java +++ b/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/Script.java @@ -53,7 +53,7 @@ public interface Script { /** * Get CRON expression */ - String getCronExpression(); + String getLaunchCronExpression(); /** * Get last execution date diff --git a/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/TransientScript.java b/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/TransientScript.java index cfd84bd7..2a5d660d 100644 --- a/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/TransientScript.java +++ b/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/TransientScript.java @@ -83,7 +83,7 @@ public Date getLaunchSchedule() { } @Override - public String getCronExpression() { + public String getLaunchCronExpression() { return null; } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptUploadForm.java b/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptUploadForm.java index 0d01a343..62eb668b 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptUploadForm.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptUploadForm.java @@ -79,11 +79,11 @@ public class ScriptUploadForm { private LocalDateTime launchSchedule; @Inject - @RequestParameter(ScriptNode.APM_LAUNCH_HOOK) - private String cronExpression; + @RequestParameter(ScriptNode.APM_LAUNCH_CRON_EXPRESSION) + private String launchCronExpression; public LaunchMetadata toLaunchMetadata() { - return new LaunchMetadata(launchEnabled, launchMode, launchEnvironment, launchRunModes, launchHook, launchSchedule, cronExpression); + return new LaunchMetadata(launchEnabled, launchMode, launchEnvironment, launchRunModes, launchHook, launchSchedule, launchCronExpression); } public String getFileName() { diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/ReferenceFinder.java b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/ReferenceFinder.java index 646a11ab..57f87fd2 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/ReferenceFinder.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/grammar/ReferenceFinder.java @@ -209,7 +209,7 @@ public Date getLaunchSchedule() { } @Override - public String getCronExpression() { + public String getLaunchCronExpression() { return null; } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/scripts/LaunchMetadata.java b/app/aem/core/src/main/java/com/cognifide/apm/core/scripts/LaunchMetadata.java index 4f4254c5..cbca9a2f 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/scripts/LaunchMetadata.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/scripts/LaunchMetadata.java @@ -23,34 +23,36 @@ import com.cognifide.apm.api.scripts.LaunchEnvironment; import com.cognifide.apm.api.scripts.LaunchMode; import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.Optional; -import java.util.stream.Stream; -import org.apache.commons.lang3.StringUtils; public class LaunchMetadata { - private final boolean executionEnabled; + private final boolean launchEnabled; + private final LaunchMode launchMode; + private final LaunchEnvironment launchEnvironment; + private final String[] launchRunModes; - private final String executionHook; - private final LocalDateTime executionSchedule; - private final String cronExpression; - public LaunchMetadata(boolean executionEnabled, LaunchMode launchMode, LaunchEnvironment launchEnvironment, - String[] launchRunModes, String executionHook, LocalDateTime executionSchedule, String cronExpression) { - this.executionEnabled = executionEnabled; + private final String launchHook; + + private final LocalDateTime launchSchedule; + + private final String launchCronExpression; + + public LaunchMetadata(boolean launchEnabled, LaunchMode launchMode, LaunchEnvironment launchEnvironment, + String[] launchRunModes, String launchHook, LocalDateTime launchSchedule, String launchCronExpression) { + this.launchEnabled = launchEnabled; this.launchMode = launchMode; this.launchEnvironment = launchEnvironment; this.launchRunModes = launchRunModes; - this.executionHook = executionHook; - this.executionSchedule = executionSchedule; - this.cronExpression = cronExpression; + this.launchHook = launchHook; + this.launchSchedule = launchSchedule; + this.launchCronExpression = launchCronExpression; } - public boolean isExecutionEnabled() { - return executionEnabled; + public boolean isLaunchEnabled() { + return launchEnabled; } public LaunchMode getLaunchMode() { @@ -62,23 +64,18 @@ public LaunchEnvironment getLaunchEnvironment() { } public String[] getLaunchRunModes() { - return Optional.ofNullable(launchRunModes) - .map(Arrays::stream) - .orElse(Stream.empty()) - .filter(StringUtils::isNotBlank) - .distinct() - .toArray(String[]::new); + return launchRunModes; } - public String getExecutionHook() { - return executionHook; + public String getLaunchHook() { + return launchHook; } - public LocalDateTime getExecutionSchedule() { - return executionSchedule; + public LocalDateTime getLaunchSchedule() { + return launchSchedule; } - public String getCronExpression() { - return cronExpression; + public String getLaunchCronExpression() { + return launchCronExpression; } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/scripts/ScriptFilters.java b/app/aem/core/src/main/java/com/cognifide/apm/core/scripts/ScriptFilters.java index 0b45bd2d..820e28a3 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/scripts/ScriptFilters.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/scripts/ScriptFilters.java @@ -98,7 +98,7 @@ private static Predicate