diff --git a/src/main/java/de/assecutor/votianlt/config/MongoConfig.java b/src/main/java/de/assecutor/votianlt/config/MongoConfig.java index 1f0e060..161c377 100644 --- a/src/main/java/de/assecutor/votianlt/config/MongoConfig.java +++ b/src/main/java/de/assecutor/votianlt/config/MongoConfig.java @@ -79,6 +79,7 @@ public class MongoConfig { log.debug("Creating TodoListTask"); task = new TodoListTask(); if (source.containsKey("todo_items")) { + // Suppressing unchecked cast warning as MongoDB document structure is validated @SuppressWarnings("unchecked") List todoItems = (List) source.get("todo_items"); ((TodoListTask) task).setTodoItems(todoItems); diff --git a/src/main/java/de/assecutor/votianlt/controller/MessageController.java b/src/main/java/de/assecutor/votianlt/controller/MessageController.java index 29a8292..d72a5ab 100644 --- a/src/main/java/de/assecutor/votianlt/controller/MessageController.java +++ b/src/main/java/de/assecutor/votianlt/controller/MessageController.java @@ -145,7 +145,8 @@ public class MessageController { Object cid = request.get("clientId"); if (cid != null) clientId = cid.toString(); - } catch (Exception ignored) { + } catch (Exception e) { + log.debug("Could not extract clientId from request: {}", e.getMessage()); } if (clientId == null || clientId.isBlank()) { clientId = getClientIdForUserId(appUserId); @@ -210,7 +211,8 @@ public class MessageController { Object tt = payload != null ? payload.get("taskType") : null; if (tt != null) taskType = tt.toString(); - } catch (Exception ignored) { + } catch (Exception e) { + log.debug("Could not extract taskType from payload: {}", e.getMessage()); } handleTaskCompleted(payload, taskType); } @@ -272,13 +274,15 @@ public class MessageController { if (extra instanceof Map extraData) { Object barcodesObj = extraData.get("barcodes"); if (barcodesObj instanceof List barcodesList) { + // Suppressing unchecked cast warning as extraData structure is validated from MQTT payload @SuppressWarnings("unchecked") List barcodes = (List) barcodesList; if (!barcodes.isEmpty()) { for (String barcodeString : barcodes) { + String completedBy = task.getCompletedBy() != null ? task.getCompletedBy() : "Unknown"; Barcode barcodeEntry = new Barcode(new ObjectId(taskId.toString()), barcodeString, - task.getCompletedBy()); + completedBy); barcodeRepository.save(barcodeEntry); } @@ -325,8 +329,9 @@ public class MessageController { Object signatureSvgObj = extraData.get("signatureSvg"); if (signatureSvgObj instanceof String signatureSvg) { if (!signatureSvg.isBlank()) { + String completedBy = task.getCompletedBy() != null ? task.getCompletedBy() : "Unknown"; Signature signatureEntry = new Signature(new ObjectId(taskId.toString()), signatureSvg, - task.getCompletedBy()); + completedBy); signatureRepository.save(signatureEntry); extraDataSummary = "Unterschrift erfasst (SVG, " + signatureSvg.length() + " Zeichen)"; @@ -369,13 +374,15 @@ public class MessageController { if (extra instanceof Map extraData) { Object photosObj = extraData.get("photos"); if (photosObj instanceof List photosList) { + // Suppressing unchecked cast warning as extraData structure is validated from MQTT payload @SuppressWarnings("unchecked") List photos = (List) photosList; if (!photos.isEmpty()) { for (String photoString : photos) { + String completedBy = task.getCompletedBy() != null ? task.getCompletedBy() : "Unknown"; Photo photoEntry = new Photo(new ObjectId(taskId.toString()), photoString, - task.getCompletedBy()); + completedBy); photoRepository.save(photoEntry); } @@ -428,7 +435,8 @@ public class MessageController { String taskType = task.getTaskType() != null ? task.getTaskType().toString() : "Unknown"; String taskDisplayName = task.getDisplayName() != null ? task.getDisplayName() : taskType; - jobHistoryService.logTaskCompletion(jobId, taskType, taskIdStr, task.getCompletedBy(), taskDisplayName, + String completedBy = task.getCompletedBy() != null ? task.getCompletedBy() : "Unknown"; + jobHistoryService.logTaskCompletion(jobId, taskType, taskIdStr, completedBy, taskDisplayName, extraDataSummary); } catch (Exception e) { log.warn("Failed to log task completion history for task {}: {}", taskIdStr, e.getMessage()); @@ -438,7 +446,7 @@ public class MessageController { try { ObjectId jobId = new ObjectId(task.getJobIdAsString()); String taskType = task.getTaskType() != null ? task.getTaskType().toString() : "Unknown"; - String completedBy = task.getCompletedBy(); + String completedBy = task.getCompletedBy() != null ? task.getCompletedBy() : "Unknown"; emailService.sendTaskCompletionNotification(jobId, taskType, taskIdStr, completedBy); @@ -449,7 +457,8 @@ public class MessageController { e.getMessage()); } - log.info("Task marked completed. taskId={}, completedBy={}, extraData={}", taskIdStr, task.getCompletedBy(), + String completedBy = task.getCompletedBy() != null ? task.getCompletedBy() : "Unknown"; + log.info("Task marked completed. taskId={}, completedBy={}, extraData={}", taskIdStr, completedBy, extraDataSummary); } catch (IllegalArgumentException ex) { log.error("Invalid taskId format for completion: {}", taskIdStr); diff --git a/src/main/java/de/assecutor/votianlt/mqtt/MqttV5ClientManager.java b/src/main/java/de/assecutor/votianlt/mqtt/MqttV5ClientManager.java index d56e180..a08cb2e 100644 --- a/src/main/java/de/assecutor/votianlt/mqtt/MqttV5ClientManager.java +++ b/src/main/java/de/assecutor/votianlt/mqtt/MqttV5ClientManager.java @@ -58,7 +58,8 @@ public class MqttV5ClientManager implements SmartLifecycle { client = builder.buildAsync(); var connect = client.connectWith().cleanStart(props.isCleanStart()).keepAlive(props.getKeepAlive()) - .sessionExpiryInterval(props.getSessionExpiryInterval()).simpleAuth().username("app") + .sessionExpiryInterval(props.getSessionExpiryInterval()).simpleAuth() + .username("app") .password("apppwd".getBytes(StandardCharsets.UTF_8)).applySimpleAuth(); log.info("[MQTT] Connecting to {} with clientId={} ...", props.getBrokerUri(), clientId); diff --git a/src/main/java/de/assecutor/votianlt/pages/view/AddJobView.java b/src/main/java/de/assecutor/votianlt/pages/view/AddJobView.java index 2b8a6fa..cbd623f 100644 --- a/src/main/java/de/assecutor/votianlt/pages/view/AddJobView.java +++ b/src/main/java/de/assecutor/votianlt/pages/view/AddJobView.java @@ -1139,7 +1139,7 @@ public class AddJobView extends Main { } } catch (Exception e) { // Fehler beim Laden des Entwurfs sollten nicht die Anwendung blockieren - System.err.println("Fehler beim Laden des Entwurfs: " + e.getMessage()); + log.warn("Fehler beim Laden des Entwurfs: {}", e.getMessage()); } } @@ -1228,11 +1228,6 @@ public class AddJobView extends Main { CargoItem item = new CargoItem(); cargoItemsState.add(item); - // Pre-fill current input values into backing item - item.setDescription(desc.getValue()); - item.setQuantity(qty.getValue()); - item.setWeightKg(weight.getValue()); - item.setLengthMm(len.getValue()); // Initialize from current inputs item.setDescription(desc.getValue()); item.setQuantity(qty.getValue()); @@ -1240,8 +1235,6 @@ public class AddJobView extends Main { item.setLengthMm(len.getValue()); item.setWidthMm(wid.getValue()); item.setHeightMm(hei.getValue()); - item.setWidthMm(wid.getValue()); - item.setHeightMm(hei.getValue()); desc.addValueChangeListener(ev -> { item.setDescription(ev.getValue()); @@ -1340,8 +1333,8 @@ public class AddJobView extends Main { */ private String getCurrentUsername() { try { - // Hier würden Sie normalerweise den SecurityService verwenden - // Für diese Demo nehmen wir einen festen Wert + // TODO: Implement actual security service to get current username + // For demo purposes using fixed value return "test@votianlt.de"; } catch (Exception e) { return null; diff --git a/src/main/java/de/assecutor/votianlt/pages/view/JobSummaryView.java b/src/main/java/de/assecutor/votianlt/pages/view/JobSummaryView.java index 5a9e40f..0efe95c 100644 --- a/src/main/java/de/assecutor/votianlt/pages/view/JobSummaryView.java +++ b/src/main/java/de/assecutor/votianlt/pages/view/JobSummaryView.java @@ -27,6 +27,7 @@ import de.assecutor.votianlt.model.task.ConfirmationTask; import de.assecutor.votianlt.model.task.BarcodeTask; import de.assecutor.votianlt.model.AppUser; import de.assecutor.votianlt.pages.base.ui.component.ViewToolbar; +import lombok.extern.slf4j.Slf4j; import de.assecutor.votianlt.repository.CargoItemRepository; import de.assecutor.votianlt.repository.JobRepository; import de.assecutor.votianlt.repository.TaskRepository; @@ -48,6 +49,7 @@ import java.util.Objects; @Route(value = "job_summary", layout = de.assecutor.votianlt.pages.base.ui.view.MainLayout.class) @PageTitle("Zusammenfassung") @RolesAllowed("USER") +@Slf4j public class JobSummaryView extends Main implements HasUrlParameter { private final JobRepository jobRepository; @@ -303,7 +305,8 @@ public class JobSummaryView extends Main implements HasUrlParameter { if (au.getEmail() != null && !au.getEmail().isBlank()) return au.getEmail(); } - } catch (Exception ignored) { + } catch (Exception e) { + log.debug("Failed to resolve AppUser name for ID {}: {}", appUserIdString, e.getMessage()); } return appUserIdString; // Fallback: show raw string if lookup fails } @@ -368,7 +371,7 @@ public class JobSummaryView extends Main implements HasUrlParameter { + " }" + " });" + " if (!bounds.isEmpty()) { map.fitBounds(bounds); }" + " }});" + " }" + " if (!(window.google && window.google.maps)) {" + " var s=document.createElement('script');" - + " s.src='https://maps.googleapis.com/maps/api/js?key=AIzaSyDnbitL06iLp3elmj-WtPudCykX9xvXcVE&libraries=places';" + + " s.src='https://maps.googleapis.com/maps/api/js?key=" + getGoogleMapsApiKey() + "&libraries=places';" + " s.onload=init; document.head.appendChild(s);" + " } else { init(); }" + "})();"); map.getElement().executeJs(js, map.getElement(), routeInfo.getElement()); @@ -494,7 +497,7 @@ public class JobSummaryView extends Main implements HasUrlParameter { } } } catch (Exception e) { - // Ignore errors when loading photos + log.debug("Failed to load photos for task {}: {}", task.getId(), e.getMessage()); } } } else if (task instanceof ConfirmationTask confirmationTask) { @@ -535,7 +538,7 @@ public class JobSummaryView extends Main implements HasUrlParameter { } } } catch (Exception e) { - // Ignore errors when loading signature + log.debug("Failed to load signature for task {}: {}", task.getId(), e.getMessage()); } } } else if (task instanceof BarcodeTask barcodeTask) { @@ -573,7 +576,7 @@ public class JobSummaryView extends Main implements HasUrlParameter { } } } catch (Exception e) { - // Ignore errors when loading barcodes + log.debug("Failed to load barcodes for task {}: {}", task.getId(), e.getMessage()); } } } @@ -833,7 +836,7 @@ public class JobSummaryView extends Main implements HasUrlParameter { " { return null; } + private String getGoogleMapsApiKey() { + // TODO: Move API key to configuration properties + return "AIzaSyDnbitL06iLp3elmj-WtPudCykX9xvXcVE"; + } + private void resetAllTaskCardHoverStates() { // Reset hover state for all task cards for (Div taskCard : taskCards) {