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..f43e0519 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 @@ -22,13 +22,12 @@ import com.cognifide.apm.api.scripts.LaunchEnvironment; import com.cognifide.apm.api.scripts.LaunchMode; -import com.cognifide.apm.core.endpoints.params.DateFormat; import com.cognifide.apm.core.endpoints.params.FileName; import com.cognifide.apm.core.endpoints.params.RequestParameter; import com.cognifide.apm.core.scripts.LaunchMetadata; import com.cognifide.apm.core.scripts.ScriptNode; import java.io.InputStream; -import java.time.LocalDateTime; +import java.time.OffsetDateTime; import javax.inject.Inject; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.models.annotations.Model; @@ -75,15 +74,14 @@ public class ScriptUploadForm { @Inject @RequestParameter(ScriptNode.APM_LAUNCH_SCHEDULE) - @DateFormat("yyyy-MM-dd'T'HH:mm:ss") - private LocalDateTime launchSchedule; + private OffsetDateTime 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/endpoints/params/DateFormat.java b/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/params/DateFormat.java deleted file mode 100644 index faf19aad..00000000 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/params/DateFormat.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * ========================LICENSE_START================================= - * AEM Permission Management - * %% - * Copyright (C) 2013 Wunderman Thompson Technology - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * =========================LICENSE_END================================== - */ - -package com.cognifide.apm.core.endpoints.params; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Target({ElementType.FIELD, ElementType.PARAMETER}) -@Retention(RetentionPolicy.RUNTIME) -public @interface DateFormat { - - String value(); -} diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/params/RequestParameterInjector.java b/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/params/RequestParameterInjector.java index 90db5949..8e374377 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/params/RequestParameterInjector.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/params/RequestParameterInjector.java @@ -26,7 +26,7 @@ import java.lang.reflect.AnnotatedElement; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.time.LocalDateTime; +import java.time.OffsetDateTime; import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Map; @@ -84,8 +84,8 @@ private Object getValue(SlingHttpServletRequest request, Class type, String p return BooleanUtils.toBoolean(parameterValue.getString()); } else if (type == InputStream.class) { return toInputStream(parameterValue); - } else if (type == LocalDateTime.class) { - return toLocalDateTime(annotatedElement, parameterValue); + } else if (type == OffsetDateTime.class) { + return toOffsetDateTime(parameterValue); } else if (type.isEnum()) { return toEnum(type, parameterValue); } else if (type == String[].class) { @@ -120,11 +120,8 @@ private Map extractParams(SlingHttpServletRequest request, Strin )); } - private LocalDateTime toLocalDateTime(AnnotatedElement annotatedElement, org.apache.sling.api.request.RequestParameter parameterValue) { - String dateFormat = Optional.ofNullable(annotatedElement.getAnnotation(DateFormat.class)) - .map(DateFormat::value) - .orElse(DateTimeFormatter.ISO_LOCAL_DATE_TIME.toString()); - return LocalDateTime.parse(parameterValue.getString(), DateTimeFormatter.ofPattern(dateFormat)); + private OffsetDateTime toOffsetDateTime(org.apache.sling.api.request.RequestParameter parameterValue) { + return OffsetDateTime.parse(parameterValue.getString(), DateTimeFormatter.ISO_OFFSET_DATE_TIME); } @Override 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 8deeb5eb..24caaea4 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 @@ -213,7 +213,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/history/HistoryEntryWriter.java b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryWriter.java index 34f7047a..d400c76d 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryWriter.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryWriter.java @@ -73,8 +73,13 @@ public void writeTo(Resource historyLogResource) throws IOException { valueMap.put(HistoryEntryImpl.SCRIPT_PATH, filePath); valueMap.put(HistoryEntryImpl.AUTHOR, author); valueMap.put(HistoryEntryImpl.MODE, mode); - try (InputStream progressLogInput = IOUtils.toInputStream(progressLog, StandardCharsets.UTF_8)) { - valueMap.put(HistoryEntryImpl.PROGRESS_LOG, progressLogInput); + int logWarnStringSizeThreshold = Integer.getInteger("oak.repository.node.property.logWarnStringSizeThreshold", 102400); + if (progressLog.length() > logWarnStringSizeThreshold) { + try (InputStream progressLogInput = IOUtils.toInputStream(progressLog, StandardCharsets.UTF_8)) { + valueMap.put(HistoryEntryImpl.PROGRESS_LOG, progressLogInput); + } + } else { + valueMap.put(HistoryEntryImpl.PROGRESS_LOG, progressLog); } valueMap.put(HistoryEntryImpl.IS_RUN_SUCCESSFUL, isRunSuccessful); valueMap.put(HistoryEntryImpl.EXECUTION_TIME, executionTime); 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..296d205b 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 @@ -22,35 +22,37 @@ 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; +import java.time.OffsetDateTime; 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 OffsetDateTime launchSchedule; + + private final String launchCronExpression; + + public LaunchMetadata(boolean launchEnabled, LaunchMode launchMode, LaunchEnvironment launchEnvironment, + String[] launchRunModes, String launchHook, OffsetDateTime 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 OffsetDateTime 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