From 07c14d2136f1dcfa6f88cfe3bb5b7cf0fe080caa Mon Sep 17 00:00:00 2001 From: Marvin Date: Sun, 30 Jan 2022 13:03:29 +0100 Subject: [PATCH] #v0.3.2 release - fix for startup crash due to bad api data --- CHANGELOG.md | 6 ++++++ pom.xml | 2 +- .../view/datatable/ColumnBuilderFactory.java | 17 ++++++++++++++++- .../clientstable/AbstractClientsTableView.java | 11 +++++++++-- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2db61f00..05e3a2c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [0.3.2](https://github.com/marvk/vatprism/compare/v0.3.1...v0.3.2) - 2022-01-30 + +### Fixed + +- VATprism no longer crashes on startup when the API serves bad `logon_time` client data + ## [0.3.1](https://github.com/marvk/vatprism/compare/v0.3.0...v0.3.1) - 2022-01-02 ### Added diff --git a/pom.xml b/pom.xml index 21445d9f..c81343b8 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ - 0.3.1 + 0.3.2 1 net.marvk.fs.vatsim.map.Application diff --git a/src/main/java/net/marvk/fs/vatsim/map/view/datatable/ColumnBuilderFactory.java b/src/main/java/net/marvk/fs/vatsim/map/view/datatable/ColumnBuilderFactory.java index 3b9984a5..0fe29a1e 100644 --- a/src/main/java/net/marvk/fs/vatsim/map/view/datatable/ColumnBuilderFactory.java +++ b/src/main/java/net/marvk/fs/vatsim/map/view/datatable/ColumnBuilderFactory.java @@ -7,7 +7,9 @@ import javafx.scene.layout.Pane; import javafx.scene.layout.Region; import javafx.scene.text.TextFlow; +import lombok.extern.log4j.Log4j2; import net.marvk.fs.vatsim.map.data.Data; +import net.marvk.fs.vatsim.map.data.ImmutableObjectProperty; import net.marvk.fs.vatsim.map.view.TextFlowHighlighter; import java.util.Comparator; @@ -15,6 +17,7 @@ import java.util.function.Consumer; import java.util.function.Function; +@Log4j2 public class ColumnBuilderFactory { private final SimpleTableViewModel viewModel; private final TextFlowHighlighter textFlowHighlighter; @@ -109,7 +112,7 @@ public BuildStep widthFactor(final double factor) { @Override public void build() { - result.setCellValueFactory(param -> valueFactory.apply(param.getValue(), viewModel.queryProperty())); + result.setCellValueFactory(this::valueOrNullPropertyProperty); result.setCellFactory(param -> new DataTableCell<>((cellValue, query) -> textFlowAdjusted(stringMapper.apply(cellValue, query), mono), valueNullable)); result.setReorderable(false); result.prefWidthProperty() @@ -117,6 +120,18 @@ public void build() { columnConsumer.accept(result); } + /* + * TODO Band aid fix for bad api data + */ + private ObservableValue valueOrNullPropertyProperty(final TableColumn.CellDataFeatures param) { + try { + return valueFactory.apply(param.getValue(), viewModel.queryProperty()); + } catch (final Exception e) { + log.error("Unexpected error while calculating cell value", e); + return new ImmutableObjectProperty<>(null); + } + } + private TextFlow textFlowAdjusted(final String cellValue, final boolean mono) { // TODO find cause of nullable cellValue if (cellValue == null) { diff --git a/src/main/java/net/marvk/fs/vatsim/map/view/datatable/clientstable/AbstractClientsTableView.java b/src/main/java/net/marvk/fs/vatsim/map/view/datatable/clientstable/AbstractClientsTableView.java index 5a2f489e..2965e5e8 100644 --- a/src/main/java/net/marvk/fs/vatsim/map/view/datatable/clientstable/AbstractClientsTableView.java +++ b/src/main/java/net/marvk/fs/vatsim/map/view/datatable/clientstable/AbstractClientsTableView.java @@ -56,8 +56,7 @@ protected void initializeColumns() { this.newColumnBuilder() .title("Online for") - .objectObservableValueFactory(e -> new ImmutableObjectProperty<>(Duration.between(e.getLogonTime(), ZonedDateTime - .now(ZoneId.of("Z"))))) + .objectObservableValueFactory(this::onlineForProperty) .toStringMapper(AbstractClientsTableView::formatDuration) .sortable() .mono(true) @@ -65,6 +64,14 @@ protected void initializeColumns() { .build(); } + private ImmutableObjectProperty onlineForProperty(final Data e) { + if (e.getLogonTime() == null) { + return null; + } + + return new ImmutableObjectProperty<>(Duration.between(e.getLogonTime(), ZonedDateTime.now(ZoneId.of("Z")))); + } + private static String formatDuration(final Duration duration) { return pad(duration.toHoursPart()) + ":" + pad(duration.toMinutesPart()); }