ActiveUI relies on the Content Server to persist things like bookmarks and settings.
Everything related to ActiveUI is located under the /ui
folder.
The root folder name is /ui
by default but you can change it.
When starting fresh Content Server for the first time, the /ui
folder does not exist yet.
It has to be created as well as the /ui/bookmarks
and /ui/settings
directories and their specific underlying structure.
The Content Server can be initialized for ActiveUI in two ways: client-side or server-side:
Open ActiveUI, add a Content Server and log in with a user that has the ROLE_CS_ROOT
role.
You must have the ROLE_CS_ROOT
role because the /ui
folder needs its owner role to be ROLE_CS_ROOT
to prevent regular users from being able to delete it.
Once logged in, ActiveUI will detect that the /ui
folder is missing and will send several remote requests to create all the required directories and files.
When this process is finished, you can log out and log back in with a regular user without the ROLE_CS_ROOT
role and start saving bookmarks and editing settings.
The initialization process explained above works especially well during the development phase of your project.
However, you need to have a user with the ROLE_CS_ROOT
role configured in your security layer, launch a browser and open ActiveUI to make it work.
The Content Server can also be initialized server-side thanks to the export and import feature detailed below. In particular, the use cases might prove useful.
The following paragraphs refer to server-side classes, interfaces and methods. Their names might changes in future releases of the Content Server.
The next Java code blocks have been tested against the 5.6.1 server-side stack which uses version 3 of the Content Server REST API.
The ContentServiceSnapshotter
class can export and import subtrees of the Content Server structure.
The only object needed to create a ContentServiceSnapshotter
is an implementation of IContentService
.
Thus, you can instantiate a ContentServiceSnapshotter
during the Content Server startup process or later on in a small class with a static main
by using a RemoteContentService
.
Once you have created the bookmarks and configured the settings in the Content Server according to your project requirements, call:
contentServiceSnapshotter.export("/ui", Paths.get("ActiveUI.json"));
It will create an ActiveUI.json
file containing all the entries (owner and reader roles included) under the /ui
folder.
When you want to import the structure saved in ActiveUI.json
into a fresh Content Server, call:
contentServiceSnapshotter.importSafely("/ui", Paths.get("ActiveUI.json"));
It will recreate the whole structure if there is nothing at the target path (/ui
) yet.
If it does already exist, the import will be aborted and nothing will change.
There is a similar eraseAndImport
method that will first erase everything under the target path and call importSafely
afterwards.
Use it with caution!
If you want your project to always start with the same bookmarks and settings: add the ActiveUI.json
to Git and call eraseAndImport
with its path during the Content Server startup process.
public class LocalContentServiceConfig {
// ...
@Bean
@Override
public IContentService contentService() {
IContentService contentService = activePivotContentService().getContentService().getUnderlying();
ContentServiceSnapshotter snapshotter = new ContentServiceSnapshotter(contentService.withRootPrivileges());
// StoreActiveUI.json with your project resources to have it bundled into the .war file.
Path fileToImport = Paths.get(getClass().getClassLoader().getResource("ActiveUI.json").toURI());
snapshotter.eraseAndImport("/ui", fileToImport);
return contentService;
}
// ...
}
Similar to the situation above but this time you want to make sure to call importSafely
so that the modifications made by your production users to bookmarks and settings won’t be lost.
public class RemoteContentServiceConfig {
// ...
@Bean
@Override
public IContentService contentService() {
IContentService contentService = activePivotContentService().getContentService().getUnderlying();
ContentServiceSnapshotter snapshotter = new ContentServiceSnapshotter(contentService.withRootPrivileges());
// StoreActiveUI.json with your project resources to have it bundled into the .war file.
Path fileToImport = Paths.get(getClass().getClassLoader().getResource("ActiveUI.json").toURI());
snapshotter.importSafely("/ui", fileToImport);
return contentService;
}
// ...
}
public class ImportOnServerAlreadyRunning {
public static void main(String[] args) {
String url = "http://localhost:9090/content";
// The credentials used here must be the one of a user with the ROLE_CS_ROOT role.
UserAuthenticator adminAuth = new UserAuthenticator("admin", "admin");
RemoteContentService contentService = new RemoteContentService(url, adminAuth, adminAuth);
ContentServiceSnapshotter snapshotter = new ContentServiceSnapshotter(contentService);
snapshotter.eraseAndImport("/ui", Paths.get("ActiveUI.json"));
}
}