-
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.
* harvester will stop for fatal errors * adds accepts header for url check * adding mock stats * adding mock stats * added committed at to the HarvesterRun * added committed while harvesting * collecting stats during harvester
- Loading branch information
Showing
40 changed files
with
646 additions
and
34 deletions.
There are no files selected for viewing
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
35 changes: 35 additions & 0 deletions
35
src/main/java/it/gov/innovazione/ndc/controller/SemanticAssetStats.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,35 @@ | ||
package it.gov.innovazione.ndc.controller; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
|
||
@Data | ||
@Builder | ||
public class SemanticAssetStats { | ||
private final SemanticAssetTypeStats totalStats; | ||
private final SemanticAssetTypeStats controlledVocabularyStats; | ||
private final SemanticAssetTypeStats ontologyStats; | ||
private final SemanticAssetTypeStats schemaStats; | ||
|
||
@Data | ||
@Builder | ||
public static class SemanticAssetTypeStats { | ||
private final long current; | ||
private final long lastYear; | ||
|
||
public long getIncrementOverLastYear() { | ||
return current - lastYear; | ||
} | ||
|
||
public double getIncrementPercentageOverLastYear() { | ||
BigDecimal bigDecimal = BigDecimal.valueOf( | ||
lastYear == 0 | ||
? 0 | ||
: ((double) current - lastYear) / lastYear * 100); | ||
return bigDecimal.setScale(1, RoundingMode.HALF_UP).doubleValue(); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.