Skip to main content

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​

  1. Update dependencies. Replace the Vert.x 3 dependencies in pom.xml or build.gradle with their Vert.x 4 equivalents.
  2. Review API changes. Read the Vert.x 4 documentation, with particular attention to Vertx, EventBus and Context.
  3. 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:

ToolOpen ENT NGOpen ENT v3
Node.jsopendigitaleducation/node:20-alpine-pnpmnode:lts-alpine3.20
Java buildopendigitaleducation/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​

FunctionOpen ENT NGOpen ENT v3
TemplatingJMustacheQute
Cryptographyfr.wseduc.webutils.securityBouncy Castle
REST endpointsWeb UtilsJAX-RS
Unit testsVertxUnitRunner@QuarkusTest

Templates​

Open ENT NGOpen ENT v3
Translation{{#i18n}}admin.title{{/i18n}}{i18n:['admin.title']}

Password hashing​

Open ENT NG
BCrypt.hashpw(password, BCrypt.gensalt());
Open ENT v3
SecureRandom secureRandom = new SecureRandom();
byte[] salt = new byte[12];
secureRandom.nextBytes(salt);
BCrypt.generate(password.getBytes(), salt, 12);

API equivalents​

Open ENT NGOpen ENT v3
QueryBuilder.start("_id").is(resourceId)new JsonObject().put("_id", resourceId)
fr.wseduc.mongodb.MongoDB.parseIsoDateorg.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:

Open ENT NG
UserUtils.getAuthenticatedUserInfos(eb, request)
.onSuccess(userInfos -> {
Open ENT v3
@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 3Vert.x 4
client.putAbs(...)client.request(HttpMethod.PUT, ...)
eb.send(...) with a reply handlereb.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.

Web Utils
@GET("/tenant/:id")
public void get(HttpServerRequest request) {
final String id = request.params().get("id");
JAX-RS
@GET
@Path("/tenant/{id}")
public void get(HttpServerRequest request, @PathParam("id") String id) {

Singletons to CDI beans​

A singleton class becomes a CDI bean:

  • @ApplicationScoped lets the container manage the life cycle of the bean: one instance for the whole application.
  • @Inject injects the instances the class depends on.
  • The getInstance method 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:

Open ENT NG: org.entcore.directory.Directory
@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:

Open ENT v3: DirectoryConfigService
@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​

Open ENT NG
@RunWith(VertxUnitRunner.class)
public class FeederTest {
}
Open ENT v3
@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