@Test public void testReadInstallableResourceFromNode_noRepositoryException() throws Exception { OakpalPlan.fromJson(key(keys().repoInits(), arr().val("create path (nt:unstructured) /apps/config/Test")).get()) .toOakMachineBuilder(null, getClass().getClassLoader()) .build().initAndInspect(session -> { Result<Optional<SlingInstallableParams<?>>> result = slingSimulator .readInstallableParamsFromNode(session.getNode("/apps/config/Test")); assertTrue("expect null config", result.isSuccess() && !result.getOrDefault(null).isPresent()); }); }
@NotNull Result<Optional<SlingInstallableParams<?>>> readInstallableParamsFromNode(final @NotNull Node node) { return result0(() -> { final String path = node.getPath(); NodeRes nodeRes = new NodeRes(node, path); if (Arrays.asList(node.getSession().getWorkspace().getNamespaceRegistry().getURIs()).contains(SLING_NS) && node.isNodeType(SLING_OSGI_CONFIG)) { loadJcrProperties(nodeRes.getProps(), node); return maybeConfigResource(nodeRes); } else if (node.hasProperty(JCR_CONTENT_DATA)) { nodeRes.getProps().put(InstallableResource.INSTALLATION_HINT, node.getParent().getName()); EmbeddedPackageInstallableParams packageInstallableParams = maybePackageResource(nodeRes); if (packageInstallableParams != null) { return packageInstallableParams; } if (isConfigExtension(path)) { try (InputStream is = node.getProperty(JCR_CONTENT_DATA).getBinary().getStream()) { nodeRes.getProps().putAll(readDictionary(is, nodeRes.getPath())); } catch (Exception e) { nodeRes.setParseError(e); } return maybeConfigResource(nodeRes); } } return null; }).get().map(Optional::ofNullable); }
DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator { @NotNull Result<Optional<SlingInstallableParams<?>>> readInstallableParamsFromNode(final @NotNull Node node) { return result0(() -> { final String path = node.getPath(); NodeRes nodeRes = new NodeRes(node, path); if (Arrays.asList(node.getSession().getWorkspace().getNamespaceRegistry().getURIs()).contains(SLING_NS) && node.isNodeType(SLING_OSGI_CONFIG)) { loadJcrProperties(nodeRes.getProps(), node); return maybeConfigResource(nodeRes); } else if (node.hasProperty(JCR_CONTENT_DATA)) { nodeRes.getProps().put(InstallableResource.INSTALLATION_HINT, node.getParent().getName()); EmbeddedPackageInstallableParams packageInstallableParams = maybePackageResource(nodeRes); if (packageInstallableParams != null) { return packageInstallableParams; } if (isConfigExtension(path)) { try (InputStream is = node.getProperty(JCR_CONTENT_DATA).getBinary().getStream()) { nodeRes.getProps().putAll(readDictionary(is, nodeRes.getPath())); } catch (Exception e) { nodeRes.setParseError(e); } return maybeConfigResource(nodeRes); } } return null; }).get().map(Optional::ofNullable); } }
DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator { @NotNull Result<Optional<SlingInstallableParams<?>>> readInstallableParamsFromNode(final @NotNull Node node) { return result0(() -> { final String path = node.getPath(); NodeRes nodeRes = new NodeRes(node, path); if (Arrays.asList(node.getSession().getWorkspace().getNamespaceRegistry().getURIs()).contains(SLING_NS) && node.isNodeType(SLING_OSGI_CONFIG)) { loadJcrProperties(nodeRes.getProps(), node); return maybeConfigResource(nodeRes); } else if (node.hasProperty(JCR_CONTENT_DATA)) { nodeRes.getProps().put(InstallableResource.INSTALLATION_HINT, node.getParent().getName()); EmbeddedPackageInstallableParams packageInstallableParams = maybePackageResource(nodeRes); if (packageInstallableParams != null) { return packageInstallableParams; } if (isConfigExtension(path)) { try (InputStream is = node.getProperty(JCR_CONTENT_DATA).getBinary().getStream()) { nodeRes.getProps().putAll(readDictionary(is, nodeRes.getPath())); } catch (Exception e) { nodeRes.setParseError(e); } return maybeConfigResource(nodeRes); } } return null; }).get().map(Optional::ofNullable); }  }
DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator { @NotNull Result<Optional<SlingInstallableParams<?>>> readInstallableParamsFromNode(final @NotNull Node node) { return result0(() -> { final String path = node.getPath(); NodeRes nodeRes = new NodeRes(node, path); if (Arrays.asList(node.getSession().getWorkspace().getNamespaceRegistry().getURIs()).contains(SLING_NS) && node.isNodeType(SLING_OSGI_CONFIG)) { loadJcrProperties(nodeRes.getProps(), node); return maybeConfigResource(nodeRes); } else if (node.hasProperty(JCR_CONTENT_DATA)) { nodeRes.getProps().put(InstallableResource.INSTALLATION_HINT, node.getParent().getName()); EmbeddedPackageInstallableParams packageInstallableParams = maybePackageResource(nodeRes); if (packageInstallableParams != null) { return packageInstallableParams; } if (isConfigExtension(path)) { try (InputStream is = node.getProperty(JCR_CONTENT_DATA).getBinary().getStream()) { nodeRes.getProps().putAll(readDictionary(is, nodeRes.getPath())); } catch (Exception e) { nodeRes.setParseError(e); } return maybeConfigResource(nodeRes); } } return null; }).get().map(Optional::ofNullable); }  static SlingSimulatorBackend instance(); @Override void startedScan(); @Override void setSession(final Session session); @Override void setPackageManager(final JcrPackageManager packageManager); @Override void setErrorListener(final ErrorListener errorListener); @Override @Nullable SlingInstallable dequeueInstallable(); @SuppressWarnings("unchecked") @Override @NotNull Fun.ThrowingSupplier<ResourceType> open(@NotNull final SlingOpenable<ResourceType> installable); @NotNull JcrPackage openEmbeddedPackage(@NotNull final EmbeddedPackageInstallable installable); @Override @Nullable SlingInstallable addInstallableNode(final @NotNull PackageId parentPackageId,
                                                         final @NotNull Node node); }
DefaultSlingSimulator implements SlingSimulatorBackend, SlingSimulator { @NotNull Result<Optional<SlingInstallableParams<?>>> readInstallableParamsFromNode(final @NotNull Node node) { return result0(() -> { final String path = node.getPath(); NodeRes nodeRes = new NodeRes(node, path); if (Arrays.asList(node.getSession().getWorkspace().getNamespaceRegistry().getURIs()).contains(SLING_NS) && node.isNodeType(SLING_OSGI_CONFIG)) { loadJcrProperties(nodeRes.getProps(), node); return maybeConfigResource(nodeRes); } else if (node.hasProperty(JCR_CONTENT_DATA)) { nodeRes.getProps().put(InstallableResource.INSTALLATION_HINT, node.getParent().getName()); EmbeddedPackageInstallableParams packageInstallableParams = maybePackageResource(nodeRes); if (packageInstallableParams != null) { return packageInstallableParams; } if (isConfigExtension(path)) { try (InputStream is = node.getProperty(JCR_CONTENT_DATA).getBinary().getStream()) { nodeRes.getProps().putAll(readDictionary(is, nodeRes.getPath())); } catch (Exception e) { nodeRes.setParseError(e); } return maybeConfigResource(nodeRes); } } return null; }).get().map(Optional::ofNullable); }  static SlingSimulatorBackend instance(); @Override void startedScan(); @Override void setSession(final Session session); @Override void setPackageManager(final JcrPackageManager packageManager); @Override void setErrorListener(final ErrorListener errorListener); @Override @Nullable SlingInstallable dequeueInstallable(); @SuppressWarnings("unchecked") @Override @NotNull Fun.ThrowingSupplier<ResourceType> open(@NotNull final SlingOpenable<ResourceType> installable); @NotNull JcrPackage openEmbeddedPackage(@NotNull final EmbeddedPackageInstallable installable); @Override @Nullable SlingInstallable addInstallableNode(final @NotNull PackageId parentPackageId,
                                                         final @NotNull Node node);  }