Skip to content

Commit 010976d

Browse files
committed
#178: cleanup static code analysis
1 parent 3920b06 commit 010976d

File tree

4 files changed

+32
-80
lines changed

4 files changed

+32
-80
lines changed

src/main/java/de/doubleslash/keeptime/controller/HeimatController.java

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
149149
final HeimatTask heimatTask = heimatTasks.stream()
150150
.filter(t -> t.id() == times.get(0).taskId())
151151
.findAny()
152-
.get();
152+
.orElseThrow();
153153
final Mapping mapping = new Mapping(id, false,
154154
"Not mapped in KeepTime\n\n" + heimatTask.name() + "\n" + heimatTask.taskHolderName(), times,
155155
new ArrayList<>(0), heimatNotes, "", heimatTimeSeconds, 0);
@@ -158,7 +158,7 @@ public List<Mapping> getTableRows(final LocalDate currentReportDate, final List<
158158
return list;
159159
}
160160

161-
public List<HeimatErrors> saveDay(final List<Asdf> items, LocalDate date) {
161+
public List<HeimatErrors> saveDay(final List<UserMapping> items, LocalDate date) {
162162
List<HeimatErrors> errors = new ArrayList<>();
163163

164164
items.stream().filter(tr -> tr.shouldSync).forEach(item -> {
@@ -206,51 +206,11 @@ public List<HeimatTask> getTasks(final LocalDate forDate) {
206206
return new ArrayList<>(uniqueMap.values());
207207
}
208208

209-
public static class Asdf {
210-
private final Mapping mapping;
211-
private boolean shouldSync;
212-
private String userNotes;
213-
private int userMinutes;
214-
215-
public Asdf(Mapping mapping, boolean shouldSync, String userNotes, int userMinutes) {
216-
this.mapping = mapping;
217-
this.shouldSync = shouldSync;
218-
this.userNotes = userNotes;
219-
this.userMinutes = userMinutes;
220-
}
221-
222-
public void setShouldSync(final boolean shouldSync) {
223-
this.shouldSync = shouldSync;
224-
}
225-
226-
public void setUserNotes(final String userNotes) {
227-
this.userNotes = userNotes;
228-
}
229-
230-
public void setUserMinutes(final int userMinutes) {
231-
this.userMinutes = userMinutes;
232-
}
233-
234-
public Mapping getMapping() {
235-
return mapping;
236-
}
237-
238-
public boolean isShouldSync() {
239-
return shouldSync;
240-
}
241-
242-
public String getUserNotes() {
243-
return userNotes;
244-
}
245-
246-
public int getUserMinutes() {
247-
return userMinutes;
248-
}
249-
}
209+
public record UserMapping(Mapping mapping, boolean shouldSync, String userNotes, int userMinutes){ }
250210

251211
public record Mapping(long heimatTaskId, boolean canBeSynced, String syncMessage, List<HeimatTime> existingTimes,
252212
List<Project> projects, String heimatNotes, String keeptimeNotes, long heimatSeconds,
253213
long keeptimeSeconds) {}
254214

255-
public record HeimatErrors(Asdf mapping, String errorMessage) {}
215+
public record HeimatErrors(UserMapping mapping, String errorMessage) {}
256216
}

src/main/java/de/doubleslash/keeptime/view/ExternalProjectsSyncController.java

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import de.doubleslash.keeptime.controller.HeimatController;
88
import de.doubleslash.keeptime.model.Project;
99
import de.doubleslash.keeptime.model.Work;
10+
import javafx.animation.Animation;
1011
import javafx.animation.PauseTransition;
1112
import javafx.animation.RotateTransition;
1213
import javafx.application.Platform;
@@ -143,7 +144,7 @@ private void initialize() {
143144
TableColumn<TableRow, TableRow> shouldSyncColumn = new TableColumn<>("Sync");
144145
shouldSyncColumn.setCellValueFactory(data -> new SimpleObjectProperty<>(data.getValue()));
145146
// Custom Cell Factory to disable CheckBoxes
146-
shouldSyncColumn.setCellFactory(col -> new TableCell<TableRow, TableRow>() {
147+
shouldSyncColumn.setCellFactory(col -> new TableCell<>() {
147148
private final CheckBox checkBox = new CheckBox();
148149
private ChangeListener<Boolean> boolChangeListener;
149150

@@ -158,9 +159,7 @@ protected void updateItem(TableRow item, boolean empty) {
158159
} else {
159160
checkBox.setDisable(!item.mapping.canBeSynced());
160161
checkBox.setSelected(item.shouldSyncCheckBox.get());
161-
boolChangeListener = (obs, oldText, newBoolean) -> {
162-
item.shouldSyncCheckBox.set(newBoolean);
163-
};
162+
boolChangeListener = (obs, oldText, newBoolean) -> item.shouldSyncCheckBox.set(newBoolean);
164163
checkBox.selectedProperty().addListener(boolChangeListener);
165164

166165
setGraphic(checkBox);
@@ -171,7 +170,7 @@ protected void updateItem(TableRow item, boolean empty) {
171170
shouldSyncColumn.setEditable(true);
172171

173172
TableColumn<TableRow, List<Project>> projectColumn = new TableColumn<>("Project");
174-
projectColumn.setCellValueFactory(data -> new SimpleObjectProperty(data.getValue().mapping.projects()));
173+
projectColumn.setCellValueFactory(data -> new SimpleObjectProperty<>(data.getValue().mapping.projects()));
175174
projectColumn.setCellFactory(column -> new TableCell<>() {
176175
@Override
177176
protected void updateItem(List<Project> item, boolean empty) {
@@ -181,9 +180,7 @@ protected void updateItem(List<Project> item, boolean empty) {
181180
setText(null);
182181
} else {
183182
VBox vbox = new VBox(5);
184-
item.forEach(project -> {
185-
vbox.getChildren().add(createRow(project.getColor(), project.getName()));
186-
});
183+
item.forEach(project -> vbox.getChildren().add(createRow(project.getColor(), project.getName())));
187184
setGraphic(vbox);
188185
}
189186
}
@@ -230,7 +227,7 @@ protected void updateItem(TableRow item, boolean empty) {
230227
} else {
231228
keeptimeLabel.setText("KeepTime: " + localTimeStringConverter.toString(
232229
LocalTime.ofSecondOfDay(item.keeptimeTimeSeconds.get())));
233-
heimatLabel.setText("Heimat: " + localTimeStringConverter.toString(
230+
heimatLabel.setText("HEIMAT: " + localTimeStringConverter.toString(
234231
LocalTime.ofSecondOfDay(item.heimatTimeSeconds.get())));
235232
timeSpinner.setDisable(!item.mapping.canBeSynced());
236233
timeSpinner.getValueFactory().setValue(LocalTime.ofSecondOfDay(0));
@@ -289,7 +286,7 @@ protected void updateItem(TableRow item, boolean empty) {
289286
copyHeimatNotes.setOnAction(me -> copyToClipboard(heimatNotesLabel.getText()));
290287

291288
hbox.getChildren().addAll(copyKeepTimeNotes, new Label("KeepTime:"), keepTimeNotesLabel);
292-
hbox2.getChildren().addAll(copyHeimatNotes, new Label("Heimat:"), heimatNotesLabel);
289+
hbox2.getChildren().addAll(copyHeimatNotes, new Label("HEIMAT:"), heimatNotesLabel);
293290
container.getChildren().addAll(textArea, hbox, hbox2);
294291
}
295292

@@ -325,23 +322,21 @@ protected void updateItem(TableRow item, boolean empty) {
325322
shouldSyncColumn.setPrefWidth(50);
326323
projectColumn.setPrefWidth(100);
327324
timeColumn.setPrefWidth(125);
328-
notesColumn.prefWidthProperty().bind(mappingTableView.widthProperty().subtract(525+17));
325+
notesColumn.prefWidthProperty().bind(mappingTableView.widthProperty().subtract(525 + 17));
329326
syncColumn.setPrefWidth(250);
330327

331328
mappingTableView.getColumns().addAll(shouldSyncColumn, projectColumn, timeColumn, notesColumn, syncColumn);
332329
mappingTableView.setSelectionModel(null);
333330
mappingTableView.getColumns().forEach(column -> column.setSortable(false));
334331

335-
336-
saveButton.setOnAction((ae) -> {
337-
LOG.debug("New mappings to be synced '{}'.", "TODO");
332+
saveButton.setOnAction(ae -> {
338333
showLoadingScreen(true);
339334

340335
Task<List<HeimatController.HeimatErrors>> task = new Task<>() {
341336
@Override
342337
protected List<HeimatController.HeimatErrors> call() {
343338
return heimatController.saveDay(items.stream()
344-
.map(item -> new HeimatController.Asdf(item.mapping,
339+
.map(item -> new HeimatController.UserMapping(item.mapping,
345340
item.shouldSyncCheckBox.get(), item.userNotes.get(),
346341
(int) (item.userTimeSeconds.get() / 60)))
347342
.toList(), currentReportDate);
@@ -353,11 +348,12 @@ protected List<HeimatController.HeimatErrors> call() {
353348
final List<HeimatController.HeimatErrors> errors = task.getValue();
354349
if (!errors.isEmpty()) {
355350
loadingScreenShowSyncing("Something did not work :(", loadingFailure);
356-
List<String> a = errors.stream().map(error -> {
357-
return error.mapping().getMapping().heimatTaskId() + ": " + error.errorMessage()
358-
+ ". Wanted to store '" + error.mapping().getUserMinutes() + "' minutes with notes '"
359-
+ error.mapping().getUserNotes() + "'";
360-
}).toList();
351+
List<String> a = errors.stream()
352+
.map(error -> error.mapping().mapping().heimatTaskId() + ": "
353+
+ error.errorMessage() + ". Wanted to store '" + error.mapping()
354+
.userMinutes()
355+
+ "' minutes with notes '" + error.mapping().userNotes() + "'")
356+
.toList();
361357

362358
showErrorDialog(a);
363359
} else {
@@ -385,9 +381,7 @@ protected List<HeimatController.HeimatErrors> call() {
385381
Platform.runLater(() -> new Thread(task).start());
386382
});
387383

388-
cancelButton.setOnAction(ae -> {
389-
thisStage.close();
390-
});
384+
cancelButton.setOnAction(ae -> thisStage.close());
391385

392386
// TODO offer some way to book time to an additional project?
393387
}
@@ -408,7 +402,7 @@ private void initializeLoadingScreen() {
408402

409403
RotateTransition rotateTransition = new RotateTransition(Duration.seconds(1), loadingSpinner);
410404
rotateTransition.setByAngle(360);
411-
rotateTransition.setCycleCount(RotateTransition.INDEFINITE);
405+
rotateTransition.setCycleCount(Animation.INDEFINITE);
412406
rotateTransition.play();
413407
}
414408

@@ -452,7 +446,7 @@ private void showErrorDialog(List<String> errorMessages) {
452446
}
453447

454448
private void setUpTimeSpinner(final Spinner<LocalTime> spinner) {
455-
spinner.focusedProperty().addListener((e) -> {
449+
spinner.focusedProperty().addListener(e -> {
456450
final LocalTimeStringConverter stringConverter = new LocalTimeStringConverter(FormatStyle.MEDIUM);
457451
final StringProperty text = spinner.getEditor().textProperty();
458452
try {
@@ -464,7 +458,7 @@ private void setUpTimeSpinner(final Spinner<LocalTime> spinner) {
464458
}
465459
});
466460

467-
spinner.setValueFactory(new SpinnerValueFactory<LocalTime>() {
461+
spinner.setValueFactory(new SpinnerValueFactory<>() {
468462

469463
@Override
470464
public void decrement(final int steps) {

src/main/java/de/doubleslash/keeptime/view/MapExternalProjectsController.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
import de.doubleslash.keeptime.model.Model;
2424
import de.doubleslash.keeptime.model.Project;
2525
import de.doubleslash.keeptime.model.repos.ExternalProjectsMappingsRepository;
26-
import de.doubleslash.keeptime.model.settings.HeimatSettings;
27-
import de.doubleslash.keeptime.rest.integration.heimat.HeimatAPI;
2826
import de.doubleslash.keeptime.rest.integration.heimat.model.HeimatTask;
2927
import javafx.application.Platform;
3028
import javafx.beans.property.SimpleObjectProperty;
@@ -138,7 +136,7 @@ private void initialize() {
138136
externalProjects.add(0, null); // option to clear selection
139137
final ObservableList<HeimatTask> externalProjectsObservableList = FXCollections.observableArrayList(
140138
externalProjects);
141-
TableColumn<ProjectMapping, HeimatTask> externalColumn = new TableColumn<>("Heimat Project");
139+
TableColumn<ProjectMapping, HeimatTask> externalColumn = new TableColumn<>("HEIMAT Project");
142140
externalColumn.setCellValueFactory(data -> new SimpleObjectProperty<>(data.getValue().heimatTask));
143141
externalColumn.setCellFactory(col -> new TableCell<>() {
144142
// TODO search in box would be nice
@@ -233,7 +231,7 @@ protected void updateItem(HeimatTask item, boolean empty) {
233231
});
234232
addNewProjectComboBox.setItems(FXCollections.observableArrayList(externalProjects));
235233

236-
saveButton.setOnAction((ae) -> {
234+
saveButton.setOnAction(ae -> {
237235
LOG.debug("New mappings to be saved '{}'.", observableMappings);
238236

239237
final List<ExternalProjectMapping> mappingsToCreateOrUpdate = observableMappings.stream()
@@ -250,7 +248,8 @@ protected void updateItem(HeimatTask item, boolean empty) {
250248
final HeimatTask heimatTask = projectMapping.getHeimatTask();
251249
if (any.isPresent()) {
252250
final ExternalProjectMapping projectMapping1 = any.get();
253-
if(projectMapping1.getExternalTaskId() == heimatTask.id()){
251+
if (projectMapping1.getExternalTaskId()
252+
== heimatTask.id()) {
254253
// mapping did not change
255254
return null;
256255
}
@@ -274,7 +273,8 @@ protected void updateItem(HeimatTask item, boolean empty) {
274273
// TODO to json
275274
,
276275
projectMapping.project);
277-
}).filter(Objects::nonNull)
276+
})
277+
.filter(Objects::nonNull)
278278
.toList();
279279
externalProjectsMappingsRepository.saveAll(mappingsToCreateOrUpdate);
280280

@@ -296,9 +296,7 @@ protected void updateItem(HeimatTask item, boolean empty) {
296296
thisStage.close();
297297
});
298298

299-
cancelButton.setOnAction(ae -> {
300-
thisStage.close();
301-
});
299+
cancelButton.setOnAction(ae -> thisStage.close());
302300

303301
final List<String> invalidMappingsAsString = invalidExternalMappings.stream()
304302
.map(em -> "Task no longer exists: "

src/test/java/de/doubleslash/keeptime/controller/HeimatControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void beforeEach() {
5959

6060
availableTasks.add(
6161
new HeimatTask(project1To1Mapping.getExternalTaskId(), project1To1Mapping.getExternalTaskName(),
62-
project1To1Mapping.getExternalProjectName(), false, "", false, false));
62+
project1To1Mapping.getExternalProjectName(),"PROJECT", false, "", false, false));
6363
when(mockedHeimatAPI.getMyTasks(now.toLocalDate())).thenReturn(availableTasks);
6464
}
6565

0 commit comments

Comments
 (0)