Skip to content

Commit a8b12a0

Browse files
committed
Merge branch 'master' into add-data-source-support
2 parents 3fc6671 + 0653f43 commit a8b12a0

File tree

18 files changed

+91
-185
lines changed

18 files changed

+91
-185
lines changed

app/aem/api/src/main/java/com/cognifide/apm/api/scripts/Script.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public interface Script {
5353
/**
5454
* Get CRON expression
5555
*/
56-
String getCronExpression();
56+
String getLaunchCronExpression();
5757

5858
/**
5959
* Get last execution date

app/aem/api/src/main/java/com/cognifide/apm/api/scripts/TransientScript.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public Date getLaunchSchedule() {
8383
}
8484

8585
@Override
86-
public String getCronExpression() {
86+
public String getLaunchCronExpression() {
8787
return null;
8888
}
8989

app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/ScriptUploadForm.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222

2323
import com.cognifide.apm.api.scripts.LaunchEnvironment;
2424
import com.cognifide.apm.api.scripts.LaunchMode;
25-
import com.cognifide.apm.core.endpoints.params.DateFormat;
2625
import com.cognifide.apm.core.endpoints.params.FileName;
2726
import com.cognifide.apm.core.endpoints.params.RequestParameter;
2827
import com.cognifide.apm.core.scripts.LaunchMetadata;
2928
import com.cognifide.apm.core.scripts.ScriptNode;
3029
import java.io.InputStream;
31-
import java.time.LocalDateTime;
30+
import java.time.OffsetDateTime;
3231
import javax.inject.Inject;
3332
import org.apache.sling.api.SlingHttpServletRequest;
3433
import org.apache.sling.models.annotations.Model;
@@ -75,15 +74,14 @@ public class ScriptUploadForm {
7574

7675
@Inject
7776
@RequestParameter(ScriptNode.APM_LAUNCH_SCHEDULE)
78-
@DateFormat("yyyy-MM-dd'T'HH:mm:ss")
79-
private LocalDateTime launchSchedule;
77+
private OffsetDateTime launchSchedule;
8078

8179
@Inject
82-
@RequestParameter(ScriptNode.APM_LAUNCH_HOOK)
83-
private String cronExpression;
80+
@RequestParameter(ScriptNode.APM_LAUNCH_CRON_EXPRESSION)
81+
private String launchCronExpression;
8482

8583
public LaunchMetadata toLaunchMetadata() {
86-
return new LaunchMetadata(launchEnabled, launchMode, launchEnvironment, launchRunModes, launchHook, launchSchedule, cronExpression);
84+
return new LaunchMetadata(launchEnabled, launchMode, launchEnvironment, launchRunModes, launchHook, launchSchedule, launchCronExpression);
8785
}
8886

8987
public String getFileName() {

app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/params/DateFormat.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

app/aem/core/src/main/java/com/cognifide/apm/core/endpoints/params/RequestParameterInjector.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.lang.reflect.AnnotatedElement;
2727
import java.lang.reflect.ParameterizedType;
2828
import java.lang.reflect.Type;
29-
import java.time.LocalDateTime;
29+
import java.time.OffsetDateTime;
3030
import java.time.format.DateTimeFormatter;
3131
import java.util.Arrays;
3232
import java.util.Map;
@@ -84,8 +84,8 @@ private Object getValue(SlingHttpServletRequest request, Class<?> type, String p
8484
return BooleanUtils.toBoolean(parameterValue.getString());
8585
} else if (type == InputStream.class) {
8686
return toInputStream(parameterValue);
87-
} else if (type == LocalDateTime.class) {
88-
return toLocalDateTime(annotatedElement, parameterValue);
87+
} else if (type == OffsetDateTime.class) {
88+
return toOffsetDateTime(parameterValue);
8989
} else if (type.isEnum()) {
9090
return toEnum(type, parameterValue);
9191
} else if (type == String[].class) {
@@ -120,11 +120,8 @@ private Map<String, String> extractParams(SlingHttpServletRequest request, Strin
120120
));
121121
}
122122

123-
private LocalDateTime toLocalDateTime(AnnotatedElement annotatedElement, org.apache.sling.api.request.RequestParameter parameterValue) {
124-
String dateFormat = Optional.ofNullable(annotatedElement.getAnnotation(DateFormat.class))
125-
.map(DateFormat::value)
126-
.orElse(DateTimeFormatter.ISO_LOCAL_DATE_TIME.toString());
127-
return LocalDateTime.parse(parameterValue.getString(), DateTimeFormatter.ofPattern(dateFormat));
123+
private OffsetDateTime toOffsetDateTime(org.apache.sling.api.request.RequestParameter parameterValue) {
124+
return OffsetDateTime.parse(parameterValue.getString(), DateTimeFormatter.ISO_OFFSET_DATE_TIME);
128125
}
129126

130127
@Override

app/aem/core/src/main/java/com/cognifide/apm/core/grammar/ReferenceFinder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public Date getLaunchSchedule() {
213213
}
214214

215215
@Override
216-
public String getCronExpression() {
216+
public String getLaunchCronExpression() {
217217
return null;
218218
}
219219

app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryWriter.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ public void writeTo(Resource historyLogResource) throws IOException {
7373
valueMap.put(HistoryEntryImpl.SCRIPT_PATH, filePath);
7474
valueMap.put(HistoryEntryImpl.AUTHOR, author);
7575
valueMap.put(HistoryEntryImpl.MODE, mode);
76-
try (InputStream progressLogInput = IOUtils.toInputStream(progressLog, StandardCharsets.UTF_8)) {
77-
valueMap.put(HistoryEntryImpl.PROGRESS_LOG, progressLogInput);
76+
int logWarnStringSizeThreshold = Integer.getInteger("oak.repository.node.property.logWarnStringSizeThreshold", 102400);
77+
if (progressLog.length() > logWarnStringSizeThreshold) {
78+
try (InputStream progressLogInput = IOUtils.toInputStream(progressLog, StandardCharsets.UTF_8)) {
79+
valueMap.put(HistoryEntryImpl.PROGRESS_LOG, progressLogInput);
80+
}
81+
} else {
82+
valueMap.put(HistoryEntryImpl.PROGRESS_LOG, progressLog);
7883
}
7984
valueMap.put(HistoryEntryImpl.IS_RUN_SUCCESSFUL, isRunSuccessful);
8085
valueMap.put(HistoryEntryImpl.EXECUTION_TIME, executionTime);

app/aem/core/src/main/java/com/cognifide/apm/core/scripts/LaunchMetadata.java

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,37 @@
2222

2323
import com.cognifide.apm.api.scripts.LaunchEnvironment;
2424
import com.cognifide.apm.api.scripts.LaunchMode;
25-
import java.time.LocalDateTime;
26-
import java.util.Arrays;
27-
import java.util.Optional;
28-
import java.util.stream.Stream;
29-
import org.apache.commons.lang3.StringUtils;
25+
import java.time.OffsetDateTime;
3026

3127
public class LaunchMetadata {
3228

33-
private final boolean executionEnabled;
29+
private final boolean launchEnabled;
30+
3431
private final LaunchMode launchMode;
32+
3533
private final LaunchEnvironment launchEnvironment;
34+
3635
private final String[] launchRunModes;
37-
private final String executionHook;
38-
private final LocalDateTime executionSchedule;
39-
private final String cronExpression;
4036

41-
public LaunchMetadata(boolean executionEnabled, LaunchMode launchMode, LaunchEnvironment launchEnvironment,
42-
String[] launchRunModes, String executionHook, LocalDateTime executionSchedule, String cronExpression) {
43-
this.executionEnabled = executionEnabled;
37+
private final String launchHook;
38+
39+
private final OffsetDateTime launchSchedule;
40+
41+
private final String launchCronExpression;
42+
43+
public LaunchMetadata(boolean launchEnabled, LaunchMode launchMode, LaunchEnvironment launchEnvironment,
44+
String[] launchRunModes, String launchHook, OffsetDateTime launchSchedule, String launchCronExpression) {
45+
this.launchEnabled = launchEnabled;
4446
this.launchMode = launchMode;
4547
this.launchEnvironment = launchEnvironment;
4648
this.launchRunModes = launchRunModes;
47-
this.executionHook = executionHook;
48-
this.executionSchedule = executionSchedule;
49-
this.cronExpression = cronExpression;
49+
this.launchHook = launchHook;
50+
this.launchSchedule = launchSchedule;
51+
this.launchCronExpression = launchCronExpression;
5052
}
5153

52-
public boolean isExecutionEnabled() {
53-
return executionEnabled;
54+
public boolean isLaunchEnabled() {
55+
return launchEnabled;
5456
}
5557

5658
public LaunchMode getLaunchMode() {
@@ -62,23 +64,18 @@ public LaunchEnvironment getLaunchEnvironment() {
6264
}
6365

6466
public String[] getLaunchRunModes() {
65-
return Optional.ofNullable(launchRunModes)
66-
.map(Arrays::stream)
67-
.orElse(Stream.empty())
68-
.filter(StringUtils::isNotBlank)
69-
.distinct()
70-
.toArray(String[]::new);
67+
return launchRunModes;
7168
}
7269

73-
public String getExecutionHook() {
74-
return executionHook;
70+
public String getLaunchHook() {
71+
return launchHook;
7572
}
7673

77-
public LocalDateTime getExecutionSchedule() {
78-
return executionSchedule;
74+
public OffsetDateTime getLaunchSchedule() {
75+
return launchSchedule;
7976
}
8077

81-
public String getCronExpression() {
82-
return cronExpression;
78+
public String getLaunchCronExpression() {
79+
return launchCronExpression;
8380
}
8481
}

app/aem/core/src/main/java/com/cognifide/apm/core/scripts/ScriptFilters.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static Predicate<Script> withSchedule() {
9898
}
9999

100100
private static Predicate<Script> withCronExpression() {
101-
return script -> script.getLaunchMode() == LaunchMode.ON_CRON_EXPRESSION && StringUtils.isNotEmpty(script.getCronExpression());
101+
return script -> script.getLaunchMode() == LaunchMode.ON_CRON_EXPRESSION && StringUtils.isNotEmpty(script.getLaunchCronExpression());
102102
}
103103

104104
private static Predicate<Script> enabled() {

app/aem/core/src/main/java/com/cognifide/apm/core/scripts/ScriptModel.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import javax.inject.Named;
4545
import javax.jcr.RepositoryException;
4646
import org.apache.commons.lang3.BooleanUtils;
47-
import org.apache.commons.lang3.StringUtils;
4847
import org.apache.sling.api.resource.ModifiableValueMap;
4948
import org.apache.sling.api.resource.PersistenceException;
5049
import org.apache.sling.api.resource.Resource;
@@ -96,7 +95,7 @@ public class ScriptModel implements MutableScript {
9695

9796
@Inject
9897
@Named(ScriptNode.APM_LAUNCH_CRON_EXPRESSION)
99-
private String cronExpression;
98+
private String launchCronExpression;
10099

101100
@Inject
102101
@Named(ScriptNode.APM_LAST_EXECUTED)
@@ -171,8 +170,8 @@ public Date getLaunchSchedule() {
171170
}
172171

173172
@Override
174-
public String getCronExpression() {
175-
return StringUtils.defaultString(cronExpression);
173+
public String getLaunchCronExpression() {
174+
return launchCronExpression;
176175
}
177176

178177
@Override
@@ -284,7 +283,7 @@ public boolean equals(Object obj) {
284283
&& Arrays.equals(launchRunModes, that.launchRunModes)
285284
&& Objects.equals(launchHook, that.launchHook)
286285
&& Objects.equals(launchSchedule, that.launchSchedule)
287-
&& Objects.equals(cronExpression, that.cronExpression)
286+
&& Objects.equals(launchCronExpression, that.launchCronExpression)
288287
&& Objects.equals(checksum, that.checksum)
289288
&& Objects.equals(verified, that.verified);
290289
}

0 commit comments

Comments
 (0)