Skip to content

Commit

Permalink
#v0.3.2 release - fix for startup crash due to bad api data
Browse files Browse the repository at this point in the history
  • Loading branch information
marvk committed Jan 30, 2022
1 parent 981d695 commit 07c14d2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

<properties>
<!--Defaults, should be passed as command line argument for real builds-->
<versionName>0.3.1</versionName>
<versionName>0.3.2</versionName>
<buildNumber>1</buildNumber>

<mainClass>net.marvk.fs.vatsim.map.Application</mainClass>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
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;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;

@Log4j2
public class ColumnBuilderFactory<Model extends Data> {
private final SimpleTableViewModel<Model> viewModel;
private final TextFlowHighlighter textFlowHighlighter;
Expand Down Expand Up @@ -109,14 +112,26 @@ 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()
.bind(viewModel.fontSizeProperty().divide(12.0).multiply(100.0).multiply(widthFactor));
columnConsumer.accept(result);
}

/*
* TODO Band aid fix for bad api data
*/
private ObservableValue<CellValue> valueOrNullPropertyProperty(final TableColumn.CellDataFeatures<Model, CellValue> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,22 @@ protected void initializeColumns() {

this.<Duration>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)
.widthFactor(0.7)
.build();
}

private ImmutableObjectProperty<Duration> 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());
}
Expand Down

0 comments on commit 07c14d2

Please sign in to comment.