-
Notifications
You must be signed in to change notification settings - Fork 66
Viklin #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Viklin #21
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,55 @@ | ||
| package com.example; | ||
|
|
||
| import javafx.event.ActionEvent; | ||
| import javafx.fxml.FXML; | ||
| import javafx.scene.control.Label; | ||
| import javafx.scene.control.ListView; | ||
| import javafx.scene.control.TextField; | ||
| import javafx.stage.FileChooser; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| /** | ||
| * Controller layer: mediates between the view (FXML) and the model. | ||
| */ | ||
| public class HelloController { | ||
|
|
||
| private final HelloModel model = new HelloModel(); | ||
| private final HelloModel model = new HelloModel(new NtfyConnectionImpl()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NtfyConnectionImpl requires a base URL parameter. The Please provide the base URL, potentially reading it from environment variables using the dotenv library that was added to dependencies. Apply this diff to fix: +import io.github.cdimascio.dotenv.Dotenv;
+
public class HelloController {
- private final HelloModel model = new HelloModel(new NtfyConnectionImpl());
+ private final Dotenv dotenv = Dotenv.load();
+ private final HelloModel model = new HelloModel(
+ new NtfyConnectionImpl(dotenv.get("NTFY_BASE_URL", "https://ntfy.sh"))
+ );🤖 Prompt for AI Agents |
||
|
|
||
| @FXML | ||
| private Label messageLabel; | ||
|
|
||
| @FXML | ||
| private ListView<NtfyMessageDto> messageView; | ||
|
|
||
| @FXML | ||
| private TextField inputMessage; | ||
|
|
||
| @FXML | ||
| private void initialize() { | ||
| if (messageLabel != null) { | ||
| messageLabel.setText(model.getGreeting()); | ||
| messageLabel.setText(model.getGreeting()); | ||
|
|
||
|
|
||
| messageView.setItems(model.getMessages()); | ||
| } | ||
|
|
||
| @FXML | ||
| private void sendMessage(ActionEvent event) { | ||
| String text = inputMessage.getText(); | ||
|
|
||
|
|
||
| model.setMessageToSend(text); | ||
| model.sendMessage(); | ||
|
|
||
|
|
||
| inputMessage.clear(); | ||
| } | ||
|
|
||
| @FXML | ||
| private void attachFile(ActionEvent event) { | ||
| FileChooser chooser = new FileChooser(); | ||
| File file = chooser.showOpenDialog(messageView.getScene().getWindow()); | ||
| if (file != null) { | ||
| model.sendFile(file); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,63 @@ | ||
| package com.example; | ||
|
|
||
| /** | ||
| * Model layer: encapsulates application data and business logic. | ||
| */ | ||
| import javafx.application.Platform; | ||
| import javafx.collections.FXCollections; | ||
| import javafx.collections.ObservableList; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
|
|
||
| public class HelloModel { | ||
| /** | ||
| * Returns a greeting based on the current Java and JavaFX versions. | ||
| */ | ||
|
|
||
| private final NtfyConnection connection; | ||
| private final ObservableList<NtfyMessageDto> messages = FXCollections.observableArrayList(); | ||
|
|
||
| private String messageToSend = ""; | ||
|
|
||
| public HelloModel(NtfyConnection connection) { | ||
| this.connection = connection; | ||
|
|
||
| messages.add(new NtfyMessageDto("init", 0, "message", "mytopic", "Initial message")); | ||
|
|
||
| receiveMessages(); | ||
| } | ||
|
Comment on lines
+18
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't call receiveMessages() in the constructor. Invoking Move the call outside the constructor: public HelloModel(NtfyConnection connection) {
this.connection = connection;
messages.add(new NtfyMessageDto("init", 0, "message", "mytopic", "Initial message"));
- receiveMessages();
}Then, ensure the caller (e.g., HelloModel model = new HelloModel(connection);
model.receiveMessages();🤖 Prompt for AI Agents |
||
|
|
||
| public ObservableList<NtfyMessageDto> getMessages() { | ||
| return messages; | ||
| } | ||
|
|
||
| public String getMessageToSend() { | ||
| return messageToSend; | ||
| } | ||
|
|
||
| public void setMessageToSend(String messageToSend) { | ||
| this.messageToSend = messageToSend; | ||
| } | ||
|
|
||
| public void sendMessage() { | ||
| if (messageToSend != null && !messageToSend.isBlank()) { | ||
| connection.send(messageToSend); | ||
| } | ||
| messageToSend = ""; | ||
| } | ||
|
|
||
| public void sendFile(File file) { | ||
| try { | ||
| byte[] data = Files.readAllBytes(file.toPath()); | ||
| connection.sendFile(file.getName(), data); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| } | ||
|
Comment on lines
+45
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add null check, handle large files, and use proper logging. This method has several issues:
Apply this diff: public void sendFile(File file) {
+ if (file == null || !file.exists() || !file.canRead()) {
+ // Log error or throw IllegalArgumentException
+ return;
+ }
try {
byte[] data = Files.readAllBytes(file.toPath());
connection.sendFile(file.getName(), data);
} catch (IOException e) {
- e.printStackTrace();
+ // Use proper logging: logger.error("Failed to send file: " + file.getName(), e);
}
}For large files, consider streaming the data instead of reading it all at once, if
🤖 Prompt for AI Agents |
||
|
|
||
| public void receiveMessages() { | ||
| connection.receive(m -> Platform.runLater(() -> messages.add(m))); | ||
| } | ||
|
|
||
| public String getGreeting() { | ||
| String javaVersion = System.getProperty("java.version"); | ||
| String javafxVersion = System.getProperty("javafx.version"); | ||
| return "Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + "."; | ||
| return "Hello, JavaFX!"; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,19 @@ | ||||||||||||||||||||||||||||
| package com.example; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| public class ManyParameters { | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| public ManyParameters(String computerName, int timeout, | ||||||||||||||||||||||||||||
| String method, int size, byte[] data) { | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Constructor ignores all parameters. The constructor accepts five parameters but the body is empty - none of the values are stored. This makes the Add fields and store the parameters: public class ManyParameters {
+ private final String computerName;
+ private final int timeout;
+ private final String method;
+ private final int size;
+ private final byte[] data;
public ManyParameters(String computerName, int timeout,
String method, int size, byte[] data) {
-
+ this.computerName = computerName;
+ this.timeout = timeout;
+ this.method = method;
+ this.size = size;
+ this.data = data != null ? data.clone() : null;
}
+
+ // Add getters as needed
+ public String getComputerName() { return computerName; }
+ public int getTimeout() { return timeout; }
+ public String getMethod() { return method; }
+ public int getSize() { return size; }
+ public byte[] getData() { return data != null ? data.clone() : null; }
}
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| static void main() { | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect main method signature. The Apply this diff to fix the signature: - static void main() {
+ public static void main(String[] args) {
ManyParametersBuilder builder = new ManyParametersBuilder();📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| ManyParametersBuilder builder = new ManyParametersBuilder(); | ||||||||||||||||||||||||||||
| builder | ||||||||||||||||||||||||||||
| .setComputerName("localhost") | ||||||||||||||||||||||||||||
| .setTimeout(10) | ||||||||||||||||||||||||||||
| .setSize(0) | ||||||||||||||||||||||||||||
| .createManyParameters(); | ||||||||||||||||||||||||||||
|
Comment on lines
+12
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Builder result is unused and incomplete. The Apply this diff to complete the demonstration: public static void main(String[] args) {
- ManyParametersBuilder builder = new ManyParametersBuilder();
- builder
+ ManyParameters params = new ManyParametersBuilder()
.setComputerName("localhost") //Fluent API
.setTimeout(10)
+ .setMethod("GET")
.setSize(0)
.createManyParameters();
+ // Use params as needed
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.example; | ||
|
|
||
| public class ManyParametersBuilder { | ||
| private String computerName; | ||
| private int timeout = 0; | ||
| private String method; | ||
| private int size = 0; | ||
| private byte[] data = null; | ||
|
Comment on lines
+3
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Builder allows construction with uninitialized required fields. The builder permits creating a Consider either:
public class ManyParametersBuilder {
private String computerName;
private int timeout = 0;
private String method;
private int size = 0;
private byte[] data = null;
+
+ public ManyParametersBuilder(String computerName, String method) {
+ this.computerName = computerName;
+ this.method = method;
+ }
public ManyParameters createManyParameters() {
if (computerName == null || method == null) {
throw new IllegalStateException("computerName and method are required");
}
return new ManyParameters(computerName, timeout, method, size, data);
}🤖 Prompt for AI Agents |
||
|
|
||
| public ManyParametersBuilder setComputerName(String computerName) { | ||
| this.computerName = computerName; | ||
| return this; | ||
| } | ||
|
|
||
| public ManyParametersBuilder setTimeout(int timeout) { | ||
| this.timeout = timeout; | ||
| return this; | ||
| } | ||
|
|
||
| public ManyParametersBuilder setMethod(String method) { | ||
| this.method = method; | ||
| return this; | ||
| } | ||
|
|
||
| public ManyParametersBuilder setSize(int size) { | ||
| this.size = size; | ||
| return this; | ||
| } | ||
|
|
||
| public ManyParametersBuilder setData(byte[] data) { | ||
| this.data = data; | ||
| return this; | ||
| } | ||
|
Comment on lines
+30
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing defensive copy of byte array. The Apply this diff to add a defensive copy: public ManyParametersBuilder setData(byte[] data) {
- this.data = data;
+ this.data = data != null ? data.clone() : null;
return this;
}🤖 Prompt for AI Agents |
||
|
|
||
| public ManyParameters createManyParameters() { | ||
| return new ManyParameters(computerName, timeout, method, size, data); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.example; | ||
|
|
||
| import java.util.function.Consumer; | ||
|
|
||
| public interface NtfyConnection { | ||
|
|
||
| /** | ||
| * Skickar ett textmeddelande till servern. | ||
| * | ||
| * @param message meddelandet som ska skickas | ||
| * @return true om det lyckades, false annars | ||
| */ | ||
| boolean send(String message); | ||
|
|
||
| /** | ||
| * Registrerar en mottagare som hanterar inkommande meddelanden. | ||
| * | ||
| * @param messageHandler funktion som hanterar inkommande NtfyMessageDto | ||
| */ | ||
| void receive(Consumer<NtfyMessageDto> messageHandler); | ||
|
|
||
| /** | ||
| * Skickar en fil till servern. | ||
| * | ||
| * @param filename namnet på filen | ||
| * @param data innehållet i filen som byte-array | ||
| */ | ||
| void sendFile(String filename, byte[] data); | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify WireMock beta version is intentional.
WireMock 4.0.0-beta.15 is a beta release. While test dependencies are lower risk, verify whether a stable release is available and should be used instead. Beta versions may introduce breaking changes or lack stability guarantees.
🌐 Web query:
💡 Result:
The latest stable WireMock release is 3.13.1 (released June 12, 2025). [1][2]
Sources:
[1] WireMock community announcement for 3.13.1.
[2] WireMock website release notes / changelog (3.x series).
Use WireMock stable version 3.13.1 or document justification for beta.
Verification confirms WireMock 3.13.1 is the latest stable release. Update to the stable version unless there's a specific reason to use 4.0.0-beta.15 (e.g., testing new major version features). Even for test dependencies, stable releases are preferred.
🤖 Prompt for AI Agents