-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
95 additions
and
9 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/main/java/it/gov/innovazione/ndc/eventhandler/event/HarvesterUpdateCommitDateEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package it.gov.innovazione.ndc.eventhandler.event; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.time.Instant; | ||
|
||
@Builder | ||
@Data | ||
public class HarvesterUpdateCommitDateEvent { | ||
private final String runId; | ||
private final Instant commitDate; | ||
} |
42 changes: 42 additions & 0 deletions
42
...a/it/gov/innovazione/ndc/eventhandler/handler/HarvesterCommitDateUpdateEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package it.gov.innovazione.ndc.eventhandler.handler; | ||
|
||
import it.gov.innovazione.ndc.eventhandler.NdcEventHandler; | ||
import it.gov.innovazione.ndc.eventhandler.NdcEventWrapper; | ||
import it.gov.innovazione.ndc.eventhandler.event.HarvesterUpdateCommitDateEvent; | ||
import it.gov.innovazione.ndc.harvester.service.HarvesterRunService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class HarvesterCommitDateUpdateEventListener implements NdcEventHandler { | ||
|
||
private static final Collection<Class<?>> SUPPORTED_EVENTS = List.of(HarvesterUpdateCommitDateEvent.class); | ||
|
||
private final HarvesterRunService harvesterRunService; | ||
|
||
@Override | ||
public boolean canHandle(NdcEventWrapper<?> event) { | ||
return SUPPORTED_EVENTS.contains(event.getPayload().getClass()); | ||
} | ||
|
||
@Override | ||
public void handle(NdcEventWrapper<?> event) { | ||
HarvesterUpdateCommitDateEvent payload = (HarvesterUpdateCommitDateEvent) event.getPayload(); | ||
if (Objects.isNull(payload) || Objects.isNull(payload.getCommitDate())) { | ||
log.warn("Received invalid HarvesterUpdateCommitDateEvent: {}", payload); | ||
return; | ||
} | ||
harvesterRunService.getAllRuns().stream() | ||
.filter(harvesterRun -> payload.getRunId().equals(harvesterRun.getId())) | ||
.findAny() | ||
.map(harvesterRun -> harvesterRun.withRevisionCommittedAt(payload.getCommitDate())) | ||
.ifPresent(harvesterRunService::updateHarvesterRunCommittedAt); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters