- prepareDataModel(KernelUtils.openAdminSession(deployedNodeRepository));
- Hashtable<String, String> regProps = new Hashtable<String, String>();
- regProps.put(NodeConstants.CN, ArgeoJcrConstants.ALIAS_HOME);
- regProps.put(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS, ArgeoJcrConstants.ALIAS_HOME);
- homeRepository = new HomeRepository(deployedNodeRepository);
- // register
- bc.registerService(Repository.class, homeRepository, regProps);
+ // home
+ prepareDataModel(NodeConstants.NODE_REPOSITORY, deployedNodeRepository);
+ }
+
+ private void prepareHomeRepository(RepositoryImpl deployedRepository) {
+ Session adminSession = KernelUtils.openAdminSession(deployedRepository);
+ try {
+ argeoDataModelExtensionsAvailable = Arrays
+ .asList(adminSession.getWorkspace().getNamespaceRegistry().getURIs())
+ .contains(ArgeoNames.ARGEO_NAMESPACE);
+ } catch (RepositoryException e) {
+ log.warn("Cannot check whether Argeo namespace is registered assuming it isn't.", e);
+ argeoDataModelExtensionsAvailable = false;
+ } finally {
+ JcrUtils.logoutQuietly(adminSession);
+ }
+
+ // Publish home with the highest service ranking
+ Hashtable<String, Object> regProps = new Hashtable<>();
+ regProps.put(NodeConstants.CN, NodeConstants.EGO_REPOSITORY);
+ regProps.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
+ Repository egoRepository = new EgoRepository(deployedRepository, false);
+ bc.registerService(Repository.class, egoRepository, regProps);
+
+ // Keyring only if Argeo extensions are available
+ if (argeoDataModelExtensionsAvailable) {
+ new ServiceTracker<CallbackHandler, CallbackHandler>(bc, CallbackHandler.class, null) {
+
+ @Override
+ public CallbackHandler addingService(ServiceReference<CallbackHandler> reference) {
+ NodeKeyRing nodeKeyring = new NodeKeyRing(egoRepository);
+ CallbackHandler callbackHandler = bc.getService(reference);
+ nodeKeyring.setDefaultCallbackHandler(callbackHandler);
+ bc.registerService(LangUtils.names(Keyring.class, CryptoKeyring.class, ManagedService.class),
+ nodeKeyring, LangUtils.dico(Constants.SERVICE_PID, NodeConstants.NODE_KEYRING_PID));
+ return callbackHandler;
+ }
+
+ }.open();
+ }