Exporting bookmarks
Connect your project to the content service and create a ContentServiceSnapshotter
object. You can then use this object in the library call
BookmarkTool.exportBookmarks(snapshotter, "export-folder-name", defaultPermissionsMap)
- which will export the defined bookmarks in the required directory structure. The folder path is relative to theuser.dir
system variable - usually the base path of your project structure or the application server. ThedefaultPermissionsMap
object is a map of permission type (“owners” or “readers”) to a list of user roles (dependent on your project setup).
Accelerator projects already include this connection as part of the ExportReferenceContentServer
class:
/*******************************************************************************
* (C) ActiveViam 2018-2021
* ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY
* property of ActiveViam. Any unauthorized use,
* reproduction or transfer of this material is strictly prohibited
*******************************************************************************/
package com.activeviam.frtb.starter.server;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.Properties;
import com.activeviam.frtb.ref.cfg.constants.FRTBEnvConstants;
import com.qfs.content.service.impl.RemoteContentService;
import com.qfs.content.snapshot.impl.ContentServiceSnapshotter;
import com.qfs.rest.client.impl.UserAuthenticator;
import com.activeviam.tools.bookmark.BookmarkTool;
public class ExportReferenceContentServer implements IServerContentExporter {
private static final String DEFAULT_URL = "http://localhost:" + FRTBServer.DEFAULT_PORT + FRTBServer.DEFAULT_PATH + "/content";
private static final Properties PROPERTIES = new Properties();
private static final InputStream PROPERTIES_FILE = ExportReferenceContentServer.class.getClassLoader()
.getResourceAsStream(FRTBEnvConstants.TEST_PROPERTIES_FILE);
static {
try {
PROPERTIES.load(PROPERTIES_FILE);
} catch (IOException ioe) {
System.out.println("Could not load export properties.");
}
}
public static void main(String[] args) {
ContentServiceSnapshotter snapshotter = (new ExportReferenceContentServer()).createSnapshotter();
System.out.println("Exporting bookmarks...");
if (Boolean.parseBoolean(PROPERTIES.getProperty(FRTBEnvConstants.EXPORT_BOOKMARKS_TO_FILE))) {
snapshotter.export("/ui", Paths.get("frtb-bookmarks.json"));
}
if (Boolean.parseBoolean(PROPERTIES.getProperty(FRTBEnvConstants.EXPORT_BOOKMARKS_TO_FOLDER))) {
String defaultOwners = PROPERTIES.getProperty(FRTBEnvConstants.CONTENT_SERVER_BOOKMARKS_DEFAULT_OWNERS_PROP);
String defaultReaders = PROPERTIES.getProperty(FRTBEnvConstants.CONTENT_SERVER_BOOKMARKS_DEFAULT_READERS_PROP);
BookmarkTool.exportBookmarks(snapshotter, "frtb-content-server", BookmarkTool.transformPermissionsStringsToMap(defaultOwners, defaultReaders));
}
}
public ContentServiceSnapshotter createSnapshotter() {
String url = PROPERTIES.getProperty(FRTBEnvConstants.CONTENT_SERVER_URL, DEFAULT_URL);
// 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);
return snapshotter;
}
}