Commit f69caf79 authored by George Adrian Stoica's avatar George Adrian Stoica
Browse files

Merge branch 'master' into 24-refactoring-of-waitfornode

parents c6c46465 1def2e00
<FindBugsFilter>
<Match>
<Bug pattern="SA_LOCAL_SELF_COMPARISON" />
</Match>
<Match>
<Bug pattern="EI_EXPOSE_REP" />
</Match>
<Match>
<Bug pattern="EI_EXPOSE_REP2" />
</Match>
</FindBugsFilter>
module todolist.core {
requires transitive com.fasterxml.jackson.databind;
exports todolist.core;
exports todolist.json;
}
package todolist.json;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
......@@ -10,6 +11,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import todolist.core.TodoModel;
import todolist.json.internal.TodoModule;
/**
* Wrapper class for JSON serialization,
......@@ -20,8 +22,16 @@ public class TodoPersistence {
private ObjectMapper mapper;
public TodoPersistence() {
mapper = new ObjectMapper();
mapper.registerModule(new TodoModule());
mapper = createObjectMapper();
}
public static SimpleModule createJacksonModule(boolean deep) {
return new TodoModule(deep);
}
public static ObjectMapper createObjectMapper() {
return new ObjectMapper()
.registerModule(createJacksonModule(true));
}
public TodoModel readTodoModel(Reader reader) throws IOException {
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
......
package todolist.json;
package todolist.json.internal;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.module.SimpleModule;
......
......@@ -14,6 +14,7 @@ import todolist.core.AbstractTodoList;
import todolist.core.TodoItem;
import todolist.core.TodoList;
import todolist.core.TodoModel;
import todolist.json.internal.TodoModule;
public class TodoModuleTest {
......
......@@ -11,6 +11,10 @@
<artifactId>fxui</artifactId>
<properties>
<skipUiTests>false</skipUiTests>
</properties>
<dependencies>
<dependency>
<groupId>it1901.todolist</groupId>
......@@ -173,6 +177,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skipUiTests}</skipTests>
<argLine>
--add-opens todolist.ui/todolist.ui=ALL-UNNAMED --add-exports javafx.graphics/com.sun.javafx.application=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
......
module todolist.ui {
requires com.fasterxml.jackson.databind;
requires java.net.http;
requires javafx.base;
requires javafx.controls;
requires javafx.fxml;
requires todolist.core;
requires fxutil;
opens todolist.ui to javafx.graphics, javafx.fxml;
}
......@@ -14,7 +14,7 @@ import java.util.Collection;
import todolist.core.AbstractTodoList;
import todolist.core.TodoList;
import todolist.core.TodoModel;
import todolist.json.TodoModule;
import todolist.json.TodoPersistence;
/**
* Class that centralizes access to a TodoModel. Makes it easier to support transparent use of a
......@@ -30,7 +30,7 @@ public class RemoteTodoModelAccess implements TodoModelAccess {
public RemoteTodoModelAccess(URI endpointBaseUri) {
this.endpointBaseUri = endpointBaseUri;
objectMapper = new ObjectMapper().registerModule(new TodoModule());
objectMapper = TodoPersistence.createObjectMapper();
}
private TodoModel getTodoModel() {
......@@ -44,7 +44,6 @@ public class RemoteTodoModelAccess implements TodoModelAccess {
HttpClient.newBuilder().build().send(request, HttpResponse.BodyHandlers.ofString());
final String responseString = response.body();
this.todoModel = objectMapper.readValue(responseString, TodoModel.class);
System.out.println("TodoModel: " + this.todoModel);
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
......
......@@ -6,6 +6,9 @@ import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
* Standalone version of the app.
*/
public class TodoApp extends Application {
@Override
......
......@@ -14,11 +14,31 @@ import todolist.core.TodoList;
import todolist.core.TodoModel;
import todolist.json.TodoPersistence;
/**
* Top-level controller.
*/
public class TodoAppController {
private static final String todoListWithTwoItems =
"{\"lists\":[" + "{\"name\":\"todo\",\"items\":[{\"text\":\"item1\",\"checked\":false},"
+ "{\"text\":\"item2\",\"checked\":true,\"deadline\":\"2020-10-01T14:53:11\"}]}" + "]}";
private static final String todoListWithTwoItems = """
{
"lists" : [
{
"name": "todo",
"items": [
{
"text": "item1",
"checked":false
},
{
"text": "item2",
"checked": true,
"deadline": "2020-10-01T14:53:11"
}
]
}
]
}
""";
@FXML
String userTodoModelPath;
......
......@@ -6,6 +6,9 @@ import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
* Variant of the app with document metaphor and File menu.
*/
public class TodoDocumentApp extends Application {
private TodoDocumentAppController controller;
......
......@@ -18,6 +18,9 @@ import java.util.List;
import javafx.fxml.FXML;
import todolist.core.TodoModel;
/**
* Controller for the document metaphor variant of the app.
*/
public class TodoDocumentAppController implements DocumentListener<TodoModel, File> {
private final TodoModelStorage todoModelStorage;
......
......@@ -10,6 +10,10 @@ import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import todolist.core.TodoItem;
/**
* ListCell for TodoItems.
* Supports editing the text and checking the item.
*/
public class TodoItemListCell extends ListCell<TodoItem> {
// for whole row
......
......@@ -15,6 +15,10 @@ import todolist.core.TodoItem;
import todolist.core.TodoList;
import todolist.core.TodoListListener;
/**
* Controller for a TodoList.
* Supports adding, editing and removing elements.
*/
public class TodoListController {
@FXML
......@@ -33,7 +37,7 @@ public class TodoListController {
private TodoList todoList = null;
public TodoList getTodoList() {
TodoList getTodoList() {
return todoList;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment