Skip to content

Commit

Permalink
fixed script, history delete
Browse files Browse the repository at this point in the history
  • Loading branch information
dprzybyl committed Nov 4, 2023
1 parent 0a0f5a4 commit 77faf4b
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@

package com.cognifide.apm.core.history;

import com.cognifide.apm.api.services.ExecutionMode;
import java.util.Comparator;
import javax.inject.Inject;
import javax.inject.Named;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Model;
Expand Down Expand Up @@ -72,20 +75,28 @@ public static ScriptHistoryImpl empty(String scriptPath) {

@Override
public HistoryEntry getLastLocalRun() {
lastLocalRun = getHistoryEntry(lastLocalRun, lastLocalRunPath);
lastLocalRun = getHistoryEntry(lastLocalRun, lastLocalRunPath, ExecutionMode.RUN);
return lastLocalRun;
}

@Override
public HistoryEntry getLastLocalDryRun() {
lastLocalDryRun = getHistoryEntry(lastLocalDryRun, lastLocalDryRunPath);
lastLocalDryRun = getHistoryEntry(lastLocalDryRun, lastLocalDryRunPath, ExecutionMode.DRY_RUN);
return lastLocalDryRun;
}

private HistoryEntry getHistoryEntry(HistoryEntry entry, String historyEntryPath) {
private HistoryEntry getHistoryEntry(HistoryEntry entry, String historyEntryPath, ExecutionMode mode) {
HistoryEntry historyEntry = entry;
if (historyEntry == null && resource != null && historyEntryPath != null) {
historyEntry = history.findHistoryEntry(resource.getResourceResolver(), historyEntryPath);
if (historyEntry == null) {
historyEntry = history.findAllHistoryEntries(resource.getResourceResolver())
.stream()
.filter(it -> StringUtils.equals(it.getScriptPath(), scriptPath)
&& StringUtils.equals(it.getMode(), mode.toString()))
.max(Comparator.comparing(HistoryEntry::getExecutionTime))
.orElse(new HistoryEntryImpl());
}
}
return historyEntry;
}
Expand Down

0 comments on commit 77faf4b

Please sign in to comment.