Importing bookmarks

Importing bookmarks is part of the Content Service configuration of your project. Similar to the exporting setup, you must create a snapshotter object, and then use it in the library call to BookmarkTool.importBookmarks(snapshotter, "folder-name", defaultPermissionsMap) to import the bookmarks into your content server at startup. The folder path will be resolved using a Spring PathMatchingResourcePatternResolver, and the properties conform to its required format.

Atoti Solutions already contain this functionality as part of the LocalContentServiceConfig class:

	@Bean
	@Override
	public IContentService contentService() {
		// Return the real content service used by the activePivotContentService instead of the wrapped one
		IContentService contentService = activePivotContentService().getContentService().getUnderlying();

		String defaultOwners = env.getProperty(FRTBEnvConstants.CONTENT_SERVER_BOOKMARKS_DEFAULT_OWNERS_PROP);
		String defaultReaders = env.getProperty(FRTBEnvConstants.CONTENT_SERVER_BOOKMARKS_DEFAULT_READERS_PROP);

		switch(env.getProperty(CONTENT_SERVER_FACTORY_RESET_PROPERTY).toLowerCase()) {
			case NO_RESET: return contentService;
			case LEGACY_RESET:
			case RESET_FROM_FILE: {
				ContentServiceSnapshotter snapshotter = new ContentServiceSnapshotter(contentService.withRootPrivileges());
				String fileName = env.getProperty(CONTENT_SERVER_FACTORY_RESET_FILENAME_PROPERTY);
				if (fileName != null) {
					// Try to import.
					Path fileToImport = null;
					try {
						fileToImport = Paths.get(getClass().getClassLoader().getResource(fileName).toURI());
					} catch (URISyntaxException e) {
						LOGGER.log(Level.SEVERE, "Error reseting content server: cannot find file: " + fileName, e);
					}
					snapshotter.eraseAndImport("/ui", fileToImport);
				} else {
					LOGGER.log(Level.WARNING, "Property " + CONTENT_SERVER_FACTORY_RESET_FILENAME_PROPERTY + " not set.");
				}
				return contentService;
			}
			case RESET_FROM_FOLDER: {
				ContentServiceSnapshotter snapshotter = new ContentServiceSnapshotter(contentService.withRootPrivileges());
				String folderName = env.getProperty(CONTENT_SERVER_FACTORY_RESET_FOLDER_NAME_PROPERTY);
				if(folderName != null) {
					BookmarkTool.importBookmarks(snapshotter, folderName, BookmarkTool.transformPermissionsStringsToMap(defaultOwners, defaultReaders));
				} else {
					LOGGER.log(Level.WARNING, "Property " + CONTENT_SERVER_FACTORY_RESET_FOLDER_NAME_PROPERTY + " not set.");
				}
				return contentService;
			}
			default: {
				LOGGER.log(Level.WARNING, "Property " + CONTENT_SERVER_FACTORY_RESET_PROPERTY + " has an invalid value. Factory reset will not be performed.");
				return contentService;
			}
		}
	}