Skip to content

Commit 77faf4b

Browse files
committed
fixed script, history delete
1 parent 0a0f5a4 commit 77faf4b

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020

2121
package com.cognifide.apm.core.history;
2222

23+
import com.cognifide.apm.api.services.ExecutionMode;
24+
import java.util.Comparator;
2325
import javax.inject.Inject;
2426
import javax.inject.Named;
27+
import org.apache.commons.lang3.StringUtils;
2528
import org.apache.sling.api.resource.Resource;
2629
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
2730
import org.apache.sling.models.annotations.Model;
@@ -72,20 +75,28 @@ public static ScriptHistoryImpl empty(String scriptPath) {
7275

7376
@Override
7477
public HistoryEntry getLastLocalRun() {
75-
lastLocalRun = getHistoryEntry(lastLocalRun, lastLocalRunPath);
78+
lastLocalRun = getHistoryEntry(lastLocalRun, lastLocalRunPath, ExecutionMode.RUN);
7679
return lastLocalRun;
7780
}
7881

7982
@Override
8083
public HistoryEntry getLastLocalDryRun() {
81-
lastLocalDryRun = getHistoryEntry(lastLocalDryRun, lastLocalDryRunPath);
84+
lastLocalDryRun = getHistoryEntry(lastLocalDryRun, lastLocalDryRunPath, ExecutionMode.DRY_RUN);
8285
return lastLocalDryRun;
8386
}
8487

85-
private HistoryEntry getHistoryEntry(HistoryEntry entry, String historyEntryPath) {
88+
private HistoryEntry getHistoryEntry(HistoryEntry entry, String historyEntryPath, ExecutionMode mode) {
8689
HistoryEntry historyEntry = entry;
8790
if (historyEntry == null && resource != null && historyEntryPath != null) {
8891
historyEntry = history.findHistoryEntry(resource.getResourceResolver(), historyEntryPath);
92+
if (historyEntry == null) {
93+
historyEntry = history.findAllHistoryEntries(resource.getResourceResolver())
94+
.stream()
95+
.filter(it -> StringUtils.equals(it.getScriptPath(), scriptPath)
96+
&& StringUtils.equals(it.getMode(), mode.toString()))
97+
.max(Comparator.comparing(HistoryEntry::getExecutionTime))
98+
.orElse(new HistoryEntryImpl());
99+
}
89100
}
90101
return historyEntry;
91102
}

0 commit comments

Comments
 (0)