|
20 | 20 |
|
21 | 21 | package com.cognifide.apm.core.history;
|
22 | 22 |
|
| 23 | +import com.cognifide.apm.api.services.ExecutionMode; |
| 24 | +import java.util.Comparator; |
23 | 25 | import javax.inject.Inject;
|
24 | 26 | import javax.inject.Named;
|
| 27 | +import org.apache.commons.lang3.StringUtils; |
25 | 28 | import org.apache.sling.api.resource.Resource;
|
26 | 29 | import org.apache.sling.models.annotations.DefaultInjectionStrategy;
|
27 | 30 | import org.apache.sling.models.annotations.Model;
|
@@ -72,20 +75,28 @@ public static ScriptHistoryImpl empty(String scriptPath) {
|
72 | 75 |
|
73 | 76 | @Override
|
74 | 77 | public HistoryEntry getLastLocalRun() {
|
75 |
| - lastLocalRun = getHistoryEntry(lastLocalRun, lastLocalRunPath); |
| 78 | + lastLocalRun = getHistoryEntry(lastLocalRun, lastLocalRunPath, ExecutionMode.RUN); |
76 | 79 | return lastLocalRun;
|
77 | 80 | }
|
78 | 81 |
|
79 | 82 | @Override
|
80 | 83 | public HistoryEntry getLastLocalDryRun() {
|
81 |
| - lastLocalDryRun = getHistoryEntry(lastLocalDryRun, lastLocalDryRunPath); |
| 84 | + lastLocalDryRun = getHistoryEntry(lastLocalDryRun, lastLocalDryRunPath, ExecutionMode.DRY_RUN); |
82 | 85 | return lastLocalDryRun;
|
83 | 86 | }
|
84 | 87 |
|
85 |
| - private HistoryEntry getHistoryEntry(HistoryEntry entry, String historyEntryPath) { |
| 88 | + private HistoryEntry getHistoryEntry(HistoryEntry entry, String historyEntryPath, ExecutionMode mode) { |
86 | 89 | HistoryEntry historyEntry = entry;
|
87 | 90 | if (historyEntry == null && resource != null && historyEntryPath != null) {
|
88 | 91 | 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 | + } |
89 | 100 | }
|
90 | 101 | return historyEntry;
|
91 | 102 | }
|
|
0 commit comments