- private void prepareNodeRepository(Repository deployedNodeRepository) {
- if (availableSince != null) {
- throw new CmsException("Deployment is already available");
- }
-
- // home
- prepareDataModel(KernelUtils.openAdminSession(deployedNodeRepository));
- }
-
- private void prepareHomeRepository(Repository deployedRepository) {
- Hashtable<String, String> regProps = new Hashtable<String, String>();
- regProps.put(NodeConstants.CN, NodeConstants.HOME);
- regProps.put(LEGACY_JCR_REPOSITORY_ALIAS, NodeConstants.HOME);
- homeRepository = new HomeRepository(deployedRepository);
- // register
- bc.registerService(Repository.class, homeRepository, regProps);
-
- new ServiceTracker<CallbackHandler, CallbackHandler>(bc, CallbackHandler.class, null) {
-
- @Override
- public CallbackHandler addingService(ServiceReference<CallbackHandler> reference) {
- NodeKeyRing nodeKeyring = new NodeKeyRing(homeRepository);
- CallbackHandler callbackHandler = bc.getService(reference);
- nodeKeyring.setDefaultCallbackHandler(callbackHandler);
- bc.registerService(LangUtils.names(CryptoKeyring.class, ManagedService.class), nodeKeyring,
- LangUtils.dico(Constants.SERVICE_PID, NodeConstants.NODE_KEYRING_PID));
- return callbackHandler;
- }
-
- }.open();
- }
-
- /** Session is logged out. */
- private void prepareDataModel(Session adminSession) {
- try {
- Set<String> processed = new HashSet<String>();
- bundles: for (Bundle bundle : bc.getBundles()) {
- BundleWiring wiring = bundle.adapt(BundleWiring.class);
- if (wiring == null)
- continue bundles;
- processWiring(adminSession, wiring, processed);
- }
- } finally {
- JcrUtils.logoutQuietly(adminSession);
- }
- }
-
- private void processWiring(Session adminSession, BundleWiring wiring, Set<String> processed) {
- // recursively process requirements first
- List<BundleWire> requiredWires = wiring.getRequiredWires(CMS_DATA_MODEL_NAMESPACE);
- for (BundleWire wire : requiredWires) {
- processWiring(adminSession, wire.getProviderWiring(), processed);
- // registerCnd(adminSession, wire.getCapability(), processed);
- }
- List<BundleCapability> capabilities = wiring.getCapabilities(CMS_DATA_MODEL_NAMESPACE);
- for (BundleCapability capability : capabilities) {
- registerCnd(adminSession, capability, processed);
- }
- }
-
- private void registerCnd(Session adminSession, BundleCapability capability, Set<String> processed) {
- Map<String, Object> attrs = capability.getAttributes();
- String name = (String) attrs.get(DataModelNamespace.CAPABILITY_NAME_ATTRIBUTE);
- if (processed.contains(name)) {
- if (log.isTraceEnabled())
- log.trace("Data model " + name + " has already been processed");
- return;
- }
- String path = (String) attrs.get(DataModelNamespace.CAPABILITY_CND_ATTRIBUTE);
- URL url = capability.getRevision().getBundle().getResource(path);
- try (Reader reader = new InputStreamReader(url.openStream())) {
- CndImporter.registerNodeTypes(reader, adminSession, true);
- processed.add(name);
- if (log.isDebugEnabled())
- log.debug("Registered CND " + url);
- } catch (Exception e) {
- throw new CmsException("Cannot import CND " + url, e);
- }
-
- if (!asBoolean((String) attrs.get(DataModelNamespace.CAPABILITY_ABSTRACT_ATTRIBUTE))) {
- Hashtable<String, Object> properties = new Hashtable<>();
- properties.put(LEGACY_JCR_REPOSITORY_ALIAS, name);
- properties.put(NodeConstants.CN, name);
- if (name.equals(NodeConstants.NODE))
- properties.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
- LocalRepository localRepository = new LocalRepository(adminSession.getRepository(), capability);
- bc.registerService(Repository.class, localRepository, properties);
- if (log.isDebugEnabled())
- log.debug("Published data model " + name);
- }
- }
-
- private boolean asBoolean(String value) {
- if (value == null)
- return false;
- switch (value) {
- case "true":
- return true;
- case "false":
- return false;
- default:
- throw new CmsException("Unsupported value for attribute " + DataModelNamespace.CAPABILITY_ABSTRACT_ATTRIBUTE
- + ": " + value);
- }
- }
-