Skip to content
Snippets Groups Projects
Commit c246022e authored by Hallvard Trætteberg's avatar Hallvard Trætteberg
Browse files

Fixed problems with update to jakarta

parent bb3a0932
Branches
Tags
No related merge requests found
Showing
with 112 additions and 136 deletions
......@@ -2,7 +2,7 @@ image:
file: .gitpod.Dockerfile
tasks:
- init: sdk use 16.0.0.j9-adpt
- init: sdk use java 16.0.0.j9-adpt
command: cd todolist
ports:
......
......@@ -2,6 +2,9 @@ package todolist.core;
import java.time.LocalDateTime;
/**
* Core data of items in a TodoList.
*/
public class TodoItem {
private String text;
......
......@@ -6,6 +6,9 @@ import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
/**
* Lists of items in a todo list.
*/
public class TodoList extends AbstractTodoList {
private List<TodoItem> items = new ArrayList<>();
......
......@@ -3,6 +3,9 @@ package todolist.core;
import java.time.LocalDateTime;
import java.util.Objects;
/**
* TodoItems that belong to a TodoList.
*/
public class TodoListItem extends TodoItem {
private final TodoList todoList;
......
package todolist.core;
/**
* Listener interface for changes to a TodoList.
*/
public interface TodoListListener {
/**
* Notifies that the given TodoList has changed.
*
* @param list the changed TodoList
*/
public void todoListChanged(TodoList list);
}
......@@ -4,6 +4,9 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* The root container of Todo-related data.
*/
public class TodoModel implements Iterable<AbstractTodoList> {
private Map<String, AbstractTodoList> todoLists = new LinkedHashMap<>();
......
......@@ -6,6 +6,9 @@ import todolist.core.AbstractTodoList;
import todolist.core.TodoItem;
import todolist.core.TodoModel;
/**
* A Jackson module for configuring JSON serialization of TodoModel instances.
*/
@SuppressWarnings("serial")
public class TodoModule extends SimpleModule {
......
......@@ -11,6 +11,10 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import todolist.core.TodoModel;
/**
* Wrapper class for JSON serialization,
* to avoid direct compile dependencies on Jackson for other modules.
*/
public class TodoPersistence {
private ObjectMapper mapper;
......
package fxutil.doc;
/**
* Interface for the documents that can be loaded and saved,
* so they can support the operations of a file menu.
*
* @param <D>
* @param <L>
*/
public interface DocumentPersistence<D, L> extends DocumentLoader<D>, DocumentSaver<D, L> {
}
......@@ -23,6 +23,9 @@ import javafx.scene.control.MenuItem;
import javafx.scene.control.TextInputDialog;
import javafx.stage.FileChooser;
/**
* Controller for the file menu
*/
public class FileMenuController {
private DocumentStorage<File> documentStorage;
......
......@@ -31,7 +31,7 @@
<dependency>
<groupId>it1901.todolist</groupId>
<artifactId>restserver</artifactId>
<artifactId>rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!--
https://pragmaticintegrator.wordpress.com/2010/10/22/using-a-war-module-as-dependency-in-maven/
......
......@@ -8,7 +8,7 @@
<servlet-name>todo</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-name>jakarta.ws.rs.Application</param-name>
<param-value>todolist.restserver.TodoConfig</param-value>
</init-param>
</servlet>
......
......@@ -157,8 +157,7 @@
<module>core</module>
<module>fxutil</module>
<module>fxui</module>
<module>restapi</module>
<module>restserver</module>
<module>rest</module>
<module>integrationtests</module>
<module>springboot/restserver</module>
</modules>
......
......@@ -9,8 +9,7 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>restserver</artifactId>
<packaging>jar</packaging>
<artifactId>rest</artifactId>
<properties>
<slf4jVersion>1.7.25</slf4jVersion>
......@@ -25,9 +24,22 @@
</dependency>
<dependency>
<groupId>it1901.todolist</groupId>
<artifactId>restapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Logging med slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
......@@ -55,14 +67,13 @@
<artifactId>mockito-core</artifactId>
</dependency>
<!-- Her kommer web-server-avhengighetene -->
<!-- Logging med slf4j -->
<!-- Logging med slf4j
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
</dependency>
-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
......@@ -80,14 +91,19 @@
<artifactId>jersey-server</artifactId>
<version>${jerseyVersion}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jerseyVersion}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<artifactId>jersey-media-json-processing</artifactId>
<version>${jerseyVersion}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>${jerseyVersion}</version>
</dependency>
......@@ -124,6 +140,7 @@
<version>1.1.1</version>
<scope>runtime</scope>
</dependency>
<!--
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
......@@ -142,7 +159,7 @@
<version>2.3.0</version>
<scope>runtime</scope>
</dependency>
-->
</dependencies>
<build>
......@@ -171,17 +188,6 @@
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
<!--
https://pragmaticintegrator.wordpress.com/2010/10/22/using-a-war-module-as-dependency-in-maven/
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1-beta-1</version>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
-->
</plugins>
</build>
</project>
package todolist.restapi;
import java.io.IOException;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
......@@ -9,7 +8,9 @@ import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import todolist.core.AbstractTodoList;
......@@ -18,8 +19,9 @@ import todolist.core.TodoModel;
import todolist.json.TodoPersistence;
/**
* Used for all requests referring to TodoLists by name.
* Used for all requests referring to a TodoList by name.
*/
@Produces(MediaType.APPLICATION_JSON)
public class TodoListResource {
private static final Logger LOG = LoggerFactory.getLogger(TodoListResource.class);
......@@ -28,6 +30,7 @@ public class TodoListResource {
private final String name;
private final AbstractTodoList todoList;
@Context
private TodoPersistence todoPersistence;
public void setTodoPersistence(TodoPersistence todoPersistence) {
......@@ -60,7 +63,6 @@ public class TodoListResource {
* @return the corresponding TodoList
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public AbstractTodoList getTodoList() {
checkTodoList();
LOG.debug("getTodoList({})", name);
......@@ -85,7 +87,6 @@ public class TodoListResource {
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public boolean putTodoList(AbstractTodoList todoListArg) {
LOG.debug("putTodoList({})", todoListArg);
AbstractTodoList oldTodoList = this.todoModel.putTodoList(todoListArg);
......@@ -99,7 +100,6 @@ public class TodoListResource {
* @return true if it was added, false if it replaced
*/
@PUT
@Produces(MediaType.APPLICATION_JSON)
public boolean putTodoList() {
return putTodoList(new TodoList(name));
}
......@@ -111,7 +111,6 @@ public class TodoListResource {
*/
@POST
@Path("/rename")
@Produces(MediaType.APPLICATION_JSON)
public boolean renameTodoList(@QueryParam("newName") String newName) {
checkTodoList();
if (this.todoModel.getTodoList(newName) != null) {
......@@ -126,7 +125,6 @@ public class TodoListResource {
* Removes the TodoList.
*/
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public boolean removeTodoList() {
checkTodoList();
this.todoModel.removeTodoList(this.todoList);
......
package todolist.restapi;
import javax.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import todolist.core.AbstractTodoList;
import todolist.core.TodoModel;
import todolist.json.TodoPersistence;
/**
* The top-level rest service for TodoModel.
*/
@Path(TodoModelService.TODO_MODEL_SERVICE_PATH)
@Produces(MediaType.APPLICATION_JSON)
public class TodoModelService {
public static final String TODO_MODEL_SERVICE_PATH = "todo";
private static final Logger LOG = LoggerFactory.getLogger(TodoModelService.class);
@Inject
@Context
private TodoModel todoModel;
@Inject
@Context
private TodoPersistence todoPersistence;
/**
......@@ -31,8 +36,8 @@ public class TodoModelService {
* @return the TodoModel
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public TodoModel getTodoModel() {
LOG.debug("getTodoModel: " + todoModel);
return todoModel;
}
......
......@@ -13,6 +13,11 @@ import todolist.core.TodoModel;
import todolist.json.TodoPersistence;
import todolist.restapi.TodoModelService;
/**
* Configures the rest service,
* e.g. JSON support with Jackson and
* injectable TodoModel and TodoPersistance
*/
public class TodoConfig extends ResourceConfig {
private TodoModel todoModel;
......
......@@ -8,6 +8,9 @@ import jakarta.ws.rs.ext.ContextResolver;
import jakarta.ws.rs.ext.Provider;
import todolist.json.TodoModule;
/**
* Provides the Jackson module used for JSON serialization.
*/
@Provider
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
......
......@@ -40,21 +40,17 @@ public class TodoServiceTest extends JerseyTest {
return config;
}
@Override
protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
return new GrizzlyTestContainerFactory();
}
private ObjectMapper objectMapper;
@Override
@BeforeEach
@Override
public void setUp() throws Exception {
super.setUp();
objectMapper = new TodoModuleObjectMapperProvider().getContext(getClass());
}
@AfterEach
@Override
public void tearDown() throws Exception {
super.tearDown();
}
......
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>it1901.todolist</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>restapi</artifactId>
<properties>
<slf4jVersion>1.7.25</slf4jVersion>
</properties>
<dependencies>
<dependency>
<groupId>it1901.todolist</groupId>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Logging med slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<!-- Run the checkstyle code quality tool -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<!-- Run the spotbugs code quality tool -->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
</plugin>
<!-- Configure jacoco code coverage -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment