Migrating from Open ENT NG
Open ENT NG is the predecessor platform. Open ENT v3 runs on Quarkus and Vert.x 4, so code written for Open ENT NG has to be adapted. This page lists the changes.
Approach
- Update dependencies. Replace the Vert.x 3 dependencies in
pom.xmlorbuild.gradlewith their Vert.x 4 equivalents. - Review API changes. Read the Vert.x 4 documentation, with
particular attention to
Vertx,EventBusandContext. - Turn Vert.x mods into Quarkus modules. Adopt the Quarkus conventions: CDI annotations for dependency injection, and Quarkus configuration.
Build tools
The server side is built with Maven and the user interfaces with Yarn. Current versions of the tools can be used directly, without a build container. Where a container is used, standard images replace the custom ones:
| Tool | Open ENT NG | Open ENT v3 |
|---|---|---|
| Node.js | opendigitaleducation/node:20-alpine-pnpm | node:lts-alpine3.20 |
| Java build | opendigitaleducation/gradle:4.5.1 (Gradle, Java 8) | maven:3.9.8-amazoncorretto-21 (Maven, Java 21) |
docker run -it --rm --name openent -v "$(pwd)":/workspace -w /workspace maven:3.9.8-amazoncorretto-21 mvn clean install
Frameworks
| Function | Open ENT NG | Open ENT v3 |
|---|---|---|
| Templating | JMustache | Qute |
| Cryptography | fr.wseduc.webutils.security | Bouncy Castle |
| REST endpoints | Web Utils | JAX-RS |
| Unit tests | VertxUnitRunner | @QuarkusTest |
Templates
| Open ENT NG | Open ENT v3 | |
|---|---|---|
| Translation | {{#i18n}}admin.title{{/i18n}} | {i18n:['admin.title']} |
Password hashing
BCrypt.hashpw(password, BCrypt.gensalt());
SecureRandom secureRandom = new SecureRandom();
byte[] salt = new byte[12];
secureRandom.nextBytes(salt);
BCrypt.generate(password.getBytes(), salt, 12);
API equivalents
| Open ENT NG | Open ENT v3 |
|---|---|
QueryBuilder.start("_id").is(resourceId) | new JsonObject().put("_id", resourceId) |
fr.wseduc.mongodb.MongoDB.parseIsoDate | org.entcore.common.utils.DateUtils.parseIsoDate |
MongoDb.parseDate(date) | org.entcore.common.utils.DateUtils.parseIsoDate |
MongoDb.formatDate(date) | org.entcore.common.utils.DateUtils.formatDate |
MongoDb.find(collection, matcher, sort, keys, callback) | io.vertx.ext.mongo.MongoClient.findOne(collection, query, handler) |
getPathPrefix(config) | DefaultResourcePath.DIRECTORY_HTTP_ROOT_PATH |
Server.getEventBus(vertx) | vertx.eventBus() |
@ResourceFilter(SuperAdminFilter.class) | @Secured(roles = {Roles.SUPER_ADMIN}) |
@ResourceFilter(AdminFilter.class) | @Secured(roles = {Roles.SUPER_ADMIN, Roles.ADMIN_LOCAL}) |
@BusAddress("event.store") | @ConsumeEvent("event.store") |
notFound(request) | return Response.status(Response.Status.NOT_FOUND).build(); |
badRequest(request) | return Response.status(Response.Status.BAD_REQUEST).entity(message).build(); |
renderError(request) | return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(message).build(); |
The dependency on the MongoDB helper library is removed.
The authenticated member is read from the token instead of the session:
UserUtils.getAuthenticatedUserInfos(eb, request)
.onSuccess(userInfos -> {
@Inject
JsonWebToken jwt;
UserInfos userInfos = new UserInfos(jwt);
Vert.x 3 to Vert.x 4
See the Vert.x 4 migration guide for the full list.
| Vert.x 3 | Vert.x 4 |
|---|---|
client.putAbs(...) | client.request(HttpMethod.PUT, ...) |
eb.send(...) with a reply handler | eb.request(...) |
Future<T> result = Future.future(); | Promise<T> promise = Promise.promise(); |
return future; | return promise.future(); |
futures.setHandler(res -> ...) | futures.onComplete(res -> ...) |
Web Utils to JAX-RS
Open ENT NG declared its routes with Web Utils, which works only with Vert.x. Open ENT v3 uses JAX-RS, the Java standard for REST services.
@GET("/tenant/:id")
public void get(HttpServerRequest request) {
final String id = request.params().get("id");
@GET
@Path("/tenant/{id}")
public void get(HttpServerRequest request, @PathParam("id") String id) {
Singletons to CDI beans
A singleton class becomes a CDI bean:
@ApplicationScopedlets the container manage the life cycle of the bean: one instance for the whole application.@Injectinjects the instances the class depends on.- The
getInstancemethod and the code that managed the single instance are removed.
Verticle initialization
In Open ENT NG, the start method of each verticle declared the controllers and built the
classes they shared:
@Override
public void start() throws Exception {
final EventBus eb = getEventBus(vertx);
super.start();
setDefaultResourceFilter(new DirectoryResourcesProvider());
EmailFactory emailFactory = new EmailFactory(vertx, config);
EmailSender emailSender = emailFactory.getSender();
final JsonObject userBookData = config.getJsonObject("user-book-data");
UserService userService = new DefaultUserService(emailSender, eb, userBookData);
ClassService classService = new DefaultClassService(eb);
DirectoryController directoryController = new DirectoryController();
directoryController.setClassService(classService);
directoryController.setUserService(userService);
addController(directoryController);
// ...
}
In Open ENT v3, controllers become JAX-RS resources, and what they share is produced by a configuration bean and injected:
@ApplicationScoped
@Startup
public class DirectoryConfigService {
private JsonObject config;
@Inject
public DirectoryConfigService() {
this.config = ConfigManager.getQuarkusConfig("directory");
}
@Produces
@OpenENT("directory")
public JsonObject getConfig() {
return config;
}
@Produces
@OpenENT("userBookData")
public JsonObject getConfigUserBookData() {
return config.getJsonObject("user-book-data");
}
@Produces
@OpenENT("emailSender")
public EmailSender getEmailSender(Vertx vertx, @OpenENT("directory") JsonObject config) {
EmailFactory emailFactory = new EmailFactory(vertx, config);
return emailFactory.getSender();
}
}
See Module architecture.
Unit tests
@RunWith(VertxUnitRunner.class)
public class FeederTest {
}
@QuarkusTest
@TestProfile(CustomTestProfile.class)
public class FeederTest {
}
Each test can have its own profile and settings. See Unit tests.
File system
With Vert.x 3, the files of a mod were unpacked in the mods directory and read through
vertx.fileSystem(). With Quarkus modules, files stay inside the JAR and are read as classpath
resources.
URLs
Very few URLs differ, to keep upgrades simple. Only the authentication API changes, since the
auth module is replaced by Keycloak.
| URL for signing in | |
|---|---|
| Open ENT NG | /auth/login |
| Open ENT v3 | /realms/{realm}/protocol/openid-connect/token, where the realm is usually openent |