-
Notifications
You must be signed in to change notification settings - Fork 66
Lab3testing #24
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
Lab3testing #24
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 |
|---|---|---|
|
|
@@ -18,4 +18,4 @@ updates: | |
| groups: | ||
| maven-deps: | ||
| patterns: | ||
| - "*" | ||
| - "*" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| target/ | ||
| /.idea/ | ||
| .env |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| wrapperVersion=3.3.4 | ||
| distributionType=only-script | ||
| distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip | ||
| distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,52 @@ | ||
| 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()); | ||
|
|
||
| @FXML | ||
| private ListView<NtfyMessageDto> messageView; | ||
|
|
||
| @FXML | ||
| private Label messageLabel; | ||
|
|
||
| @FXML | ||
| private TextField messageInput; | ||
|
|
||
| @FXML | ||
| private void initialize() { | ||
| if (messageLabel != null) { | ||
| messageLabel.setText(model.getGreeting()); | ||
| messageLabel.setText(model.getGreeting()); | ||
| messageView.setItems(model.getMessages()); | ||
|
|
||
| // Bind textfältet till modellen | ||
| messageInput.textProperty().bindBidirectional(model.messageToSendProperty()); | ||
|
|
||
| // Skicka meddelande när användaren trycker Enter | ||
| messageInput.setOnAction(event -> { | ||
| model.sendMessage(); | ||
| messageInput.clear(); // töm fältet efter skick | ||
| }); | ||
| } | ||
| @FXML | ||
| private void attachFile(ActionEvent event) { | ||
| FileChooser fileChooser = new FileChooser(); | ||
| fileChooser.setTitle("Select file to send"); | ||
| File file = fileChooser.showOpenDialog(messageView.getScene().getWindow()); | ||
| if (file != null) { | ||
| model.sendFile(file.toPath()); | ||
| } | ||
| } | ||
|
|
||
| } |
| 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) { | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
|
|
||||||
| 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. Fix the main method signature. The method signature is invalid for a Java entry point. It's missing the Apply this diff: - static void main() {
+ public static void main(String[] args) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| ManyParametersBuilder builder = new ManyParametersBuilder(); | ||||||
| builder | ||||||
| .setComputerName("localhost") //Fluent API | ||||||
| .setTimeout(10) | ||||||
| .setSize(0) | ||||||
| .createManyParameters(); | ||||||
| } | ||||||
| } | ||||||
| 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; | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| public ManyParameters createManyParameters() { | ||
| return new ManyParameters(computerName, timeout, method, size, data); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.example; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.util.function.Consumer; | ||
|
|
||
| public interface NtfyConnection { | ||
|
|
||
| public boolean send(String message); | ||
|
|
||
| public void receive(Consumer<NtfyMessageDto> messageHandler); | ||
| boolean sendFile(Path filePath); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package com.example; | ||
|
|
||
| import io.github.cdimascio.dotenv.Dotenv; | ||
| import tools.jackson.databind.ObjectMapper; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.http.HttpClient; | ||
| import java.net.http.HttpRequest; | ||
| import java.net.http.HttpResponse; | ||
| import java.nio.file.Path; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.function.Consumer; | ||
|
|
||
| public class NtfyConnectionImpl implements NtfyConnection { | ||
|
|
||
| private final HttpClient http = HttpClient.newHttpClient(); | ||
| private final String hostName; | ||
| private final ObjectMapper mapper = new ObjectMapper(); | ||
|
|
||
| public NtfyConnectionImpl() { | ||
| Dotenv dotenv = Dotenv.load(); | ||
| hostName = Objects.requireNonNull(dotenv.get("HOST_NAME")); | ||
| } | ||
|
|
||
| public NtfyConnectionImpl(String hostName) { | ||
| this.hostName = hostName; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| @Override | ||
| public boolean send(String message) { | ||
| try { | ||
| String json = mapper.writeValueAsString(Map.of("message", message)); | ||
| HttpRequest httpRequest = HttpRequest.newBuilder() | ||
| .POST(HttpRequest.BodyPublishers.ofString(json)) | ||
| .header("Content-Type", "application/json") | ||
| .uri(URI.create(hostName + "/mytopic")) | ||
| .build(); | ||
| http.send(httpRequest, HttpResponse.BodyHandlers.discarding()); | ||
| return true; | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| return false; | ||
| } | ||
| } | ||
| public boolean sendFile(Path filePath) { | ||
| try { | ||
| HttpRequest httpRequest = HttpRequest.newBuilder() | ||
| .POST(HttpRequest.BodyPublishers.ofFile(filePath)) | ||
| .header("Content-Type", "application/octet-stream") | ||
| .uri(URI.create(hostName + "/mytopic")) | ||
| .build(); | ||
| http.send(httpRequest, HttpResponse.BodyHandlers.discarding()); | ||
| return true; | ||
| } catch (Exception e) { | ||
| e.printStackTrace(); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| @Override | ||
| public void receive(Consumer<NtfyMessageDto> messageHandler) { | ||
| HttpRequest httpRequest = HttpRequest.newBuilder() | ||
| .GET() | ||
| .uri(URI.create(hostName + "/mytopic/json")) | ||
| .build(); | ||
|
|
||
| http.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofLines()) | ||
| .thenAccept(response -> response.body() | ||
| .map(s -> | ||
| mapper.readValue(s, NtfyMessageDto.class)) | ||
| .filter(message -> message.event().equals("message")) | ||
| .peek(System.out::println) | ||
| .forEach(messageHandler)); | ||
| } | ||
|
Comment on lines
+3
to
+79
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. 🧩 Analysis chainFix Jackson import and checked-exception handling in Two problems here will prevent this class from compiling reliably:
You can address both and also make the filtering a bit safer (avoid nulls and use constant-first -import io.github.cdimascio.dotenv.Dotenv;
-import tools.jackson.databind.ObjectMapper;
+import io.github.cdimascio.dotenv.Dotenv;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.IOException;
@@
- http.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofLines())
- .thenAccept(response -> response.body()
- .map(s ->
- mapper.readValue(s, NtfyMessageDto.class))
- .filter(message -> message.event().equals("message"))
- .peek(System.out::println)
- .forEach(messageHandler));
+ http.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofLines())
+ .thenAccept(response -> response.body()
+ .map(s -> {
+ try {
+ return mapper.readValue(s, NtfyMessageDto.class);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ })
+ .filter(Objects::nonNull)
+ .filter(message -> "message".equals(message.event()))
+ .peek(System.out::println)
+ .forEach(messageHandler));This keeps the async streaming behavior but ensures the code compiles and won’t crash the stream on a single bad line. 🌐 Web query: 💡 Result:
Fix Jackson import and checked-exception handling in Two issues prevent this class from compiling:
Fix both by correcting the import and wrapping the -import io.github.cdimascio.dotenv.Dotenv;
-import tools.jackson.databind.ObjectMapper;
+import io.github.cdimascio.dotenv.Dotenv;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.IOException;
@@
- http.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofLines())
- .thenAccept(response -> response.body()
- .map(s ->
- mapper.readValue(s, NtfyMessageDto.class))
- .filter(message -> message.event().equals("message"))
- .peek(System.out::println)
- .forEach(messageHandler));
+ http.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofLines())
+ .thenAccept(response -> response.body()
+ .map(s -> {
+ try {
+ return mapper.readValue(s, NtfyMessageDto.class);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ })
+ .filter(Objects::nonNull)
+ .filter(message -> "message".equals(message.event()))
+ .peek(System.out::println)
+ .forEach(messageHandler));🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package com.example; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
|
||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| public record NtfyMessageDto( | ||
| String id, | ||
| long time, | ||
| String event, | ||
| String topic, | ||
| String message, | ||
| Attachment attachment // nytt fält | ||
| ) { | ||
| @JsonIgnoreProperties(ignoreUnknown = true) | ||
| public record Attachment(String name, String type, long size, String url) { } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,14 @@ | ||||||
| package com.example; | ||||||
|
|
||||||
| public class Singelton { | ||||||
|
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. Fix the typo in the class name. The class name Apply this diff to fix the typo: -public class Singelton {
+public class Singleton {Also rename the file from - private final static Singelton instance = new Singelton();
+ private final static Singleton instance = new Singleton();And update line 11: - public static Singelton getInstance(){
+ public static Singleton getInstance(){📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| private final static Singelton instance = new Singelton(); | ||||||
|
|
||||||
| private Singelton(){ | ||||||
|
|
||||||
| } | ||||||
|
|
||||||
| public static Singelton getInstance(){ | ||||||
| return instance; | ||||||
| } | ||||||
|
Comment on lines
+5
to
+13
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. 🧩 Analysis chainVerify usage and consider adding functionality or documentation. The eager initialization pattern is correctly implemented and thread-safe. However, the class currently has no fields or methods beyond the singleton pattern itself, and no usages are observed in this PR. Run the following script to check if this class is used elsewhere in the codebase: If unused, consider whether this is dead code that should be removed or if it's intentionally prepared for future use. In the latter case, adding a class-level comment explaining the intended purpose would improve maintainability. 🏁 Script executed: #!/bin/bash
# Description: Search for usages of Singelton class in the codebase.
# Search for imports and references
rg -n --type java -C3 'Singelton'Length of output: 827 Fix class name spelling and remove unused class or add documentation. The class name "Singelton" should be "Singleton". Additionally, the search confirms this class is unused anywhere in the codebase. Either remove it if it's dead code, or add a class-level comment explaining its intended purpose if it's being prepared for future use. 🤖 Prompt for AI Agents |
||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| module hellofx { | ||
| requires javafx.controls; | ||
| requires javafx.fxml; | ||
| requires io.github.cdimascio.dotenv.java; | ||
| requires java.net.http; | ||
| requires tools.jackson.databind; | ||
| requires javafx.graphics; | ||
|
Comment on lines
+4
to
+7
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. 🧩 Analysis chainVerify module names match the actual library modules. The module name Run the following script to check the actual module names from the dependencies: 🏁 Script executed: #!/bin/bash
# Description: Extract module names from the JAR files to verify correct module references
# Check dotenv module name
echo "=== Checking dotenv-java module name ==="
mvn dependency:copy -Dartifact=io.github.cdimascio:dotenv-java:3.2.0 -DoutputDirectory=./temp-deps 2>/dev/null
if [ -f ./temp-deps/dotenv-java-*.jar ]; then
unzip -p ./temp-deps/dotenv-java-*.jar module-info.class 2>/dev/null | strings | grep -E "module|requires" | head -5 || echo "No module-info found"
fi
echo ""
echo "=== Checking jackson-databind module name ==="
mvn dependency:copy -Dartifact=tools.jackson.core:jackson-databind:3.0.1 -DoutputDirectory=./temp-deps 2>/dev/null
if [ -f ./temp-deps/jackson-databind-*.jar ]; then
unzip -p ./temp-deps/jackson-databind-*.jar module-info.class 2>/dev/null | strings | grep -E "module|requires" | head -5 || echo "No module-info found"
fi
# Cleanup
rm -rf ./temp-deps
# If the above fails due to wrong coordinates, try the correct Jackson groupId
echo ""
echo "=== Attempting with standard Jackson groupId ==="
mvn dependency:copy -Dartifact=com.fasterxml.jackson.core:jackson-databind:2.18.0 -DoutputDirectory=./temp-deps 2>/dev/null
if [ -f ./temp-deps/jackson-databind-*.jar ]; then
unzip -p ./temp-deps/jackson-databind-*.jar module-info.class 2>/dev/null | strings | grep -E "module|requires" | head -5 || echo "No module-info found"
fi
rm -rf ./temp-depsLength of output: 137 I need to verify the actual dependencies and module names. Let me check the pom.xml and search for the correct module names.Now let me search for information on the dotenv-java module name: Now let me check the actual pom.xml file to verify the dependencies declared: Length of output: 763 🏁 Script executed: #!/bin/bash
# Find and display pom.xml
if [ -f ./pom.xml ]; then
echo "=== pom.xml found ==="
cat pom.xml | grep -A 100 "<dependencies>"
else
echo "pom.xml not found in root"
find . -name "pom.xml" 2>/dev/null | head -5
fiLength of output: 2425 Let me search for information on the correct Jackson coordinates and module names: Now let me search for the specific module names exported by these libraries: Based on my verification through web searches and Maven repository analysis: Correct module names for the declared dependencies: For Jackson 3.x, the Java package is However, the dotenv-java module name appears incorrect. The pom build configuration shows moditect is used to add module-info with a Correct Change from: 🤖 Prompt for AI Agents |
||
|
|
||
| opens com.example to javafx.fxml; | ||
| exports com.example; | ||
|
|
||
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 the Jackson dependency coordinates.
The groupId
tools.jackson.coreappears non-standard. Jackson typically usescom.fasterxml.jackson.coreas its groupId, and version 3.0.1 is atypical (Jackson 2.x is the widely-used stable version).🌐 Web query:
💡 Result:
groupId: com.fasterxml.jackson.core. [1]
Latest Jackson Databind (2.x) release (as of Nov 14, 2025): 2.20.1 (2.20.0 was released Aug 28, 2025). [2][3]
References:
[1] mvnrepository listing for jackson-databind.
[2] javadoc.io group listing showing jackson-databind 2.20.1.
[3] FasterXML (Jackson) project releases / README noting 2.20 release date.
Fix incorrect Jackson Maven coordinates in pom.xml.
The groupId and version are both incorrect. The correct coordinates are:
com.fasterxml.jackson.core(nottools.jackson.core)2.20.1(not3.0.1)Update lines 53-57 to use the standard FasterXML Jackson groupId and the current stable version.
The correct Maven groupId for Jackson Databind is
com.fasterxml.jackson.core, and the latest release as of November 14, 2025 is version 2.20.1.🤖 Prompt for AI Agents