/** * {@inheritDoc} */ public JcrPackage open(Node node, boolean allowInvalid) throws RepositoryException { JcrPackageManager pMgr = getPackageManager(node.getSession()); return pMgr.open(node, allowInvalid); } }
/** * Opens a package that is based on the given node. If {@code allowInvalid} * is {@code true} also invalid packages are returned, but only if the * node is file like (i.e. is nt:hierarchyNode and has a * jcr:content/jcr:data property). * * This is a shortcut version of {@link JcrPackageManager#open(Node, boolean)} * which does not create a package manager instance. * * @param node the underlying node * @param allowInvalid if {@code true} invalid packages are openend, too. * @return the new package or {@code null} it the package is not * valid unless {@code allowInvalid} is {@code true}. * @throws RepositoryException if an error occurs * * @since 2.3.0 */ public static JcrPackage open(Node node, boolean allowInvalid) throws RepositoryException { JcrPackageManager pMgr = getPackageManager(node.getSession()); return pMgr.open(node, allowInvalid); } }
/** * {@inheritDoc} */ public void removePackage(final JcrPackageManager jcrPackageManager, final String groupName, final String name, final String version) throws RepositoryException { final PackageId packageId = new PackageId(groupName, name, version); final JcrPackage jcrPackage = jcrPackageManager.open(packageId); if (jcrPackage != null && jcrPackage.getNode() != null) { jcrPackage.getNode().remove(); jcrPackage.getNode().getSession().save(); } else { log.debug("Nothing to remove at: ", packageId.getInstallationPath()); } }
private void processSubpackage(Session admin, JcrPackageManager manager, PackageId packageId, PackageId parentId, final boolean preInstall) { JcrPackage jcrPackage = null; try { jcrPackage = manager.open(packageId); if (!preInstall) { progressChecks.forEach(handler -> handler.identifySubpackage(packageId, parentId)); } processPackage(admin, manager, jcrPackage, preInstall); } catch (IOException | PackageException | RepositoryException e) { getErrorListener().onSubpackageException(e, packageId); } finally { if (jcrPackage != null) { jcrPackage.close(); } } }
public void excute() throws RepositoryException, PackageException, IOException, ReplicationException { boolean succeeded = false; try (ResourceResolver resolver = ConfigurationUpdateListener.getResourceResolver(resolverFactory)){ Session session = resolver.adaptTo(Session.class); JcrPackageManager pkgMgr = PackagingService.getPackageManager(session); PackageId packageId = new PackageId(packagePath); // check if the package exists JcrPackage jcrPackage = pkgMgr.open(packageId); if (jcrPackage == null || jcrPackage.getNode() == null) { log.warn("Package at path " + packagePath + " does not exist"); throw new IllegalArgumentException("Package at path " + packagePath + " does not exist"); } log.debug("Assembling package {}", packagePath); pkgMgr.assemble(jcrPackage, null); log.debug("Replicating package {}", packagePath); replicator.replicate(session, ReplicationActionType.ACTIVATE, jcrPackage.getNode().getPath()); log.debug("Package {} replicated successfully!", packagePath); fireEvent(OSGI_EVENT_REPLICATED_TOPIC); succeeded = true; } finally { if(!succeeded){ fireEvent(OSGI_EVENT_FAILED_TOPIC); } } }
/** * Delete package from the JCR. * * @param request The current request. * @param groupName The name of the package group to install * @param packageName The name of the package to install * @param version The version of the package to install * @return true if package was installed successfully */ public boolean deletePackage(final SlingHttpServletRequest request, final String groupName, final String packageName, final String version) { Session session = request.getResourceResolver().adaptTo(Session.class); boolean result; final JcrPackageManager packageManager = packaging.getPackageManager(session); final PackageId packageId = new PackageId(groupName, packageName, version); try { final JcrPackage jcrPackage = packageManager.open(packageId); packageManager.remove(jcrPackage); result = true; } catch (RepositoryException e) { LOGGER.error("Could not remove package", e); result = false; } return result; }
final Node child = children.nextNode(); final JcrPackage jcrPackage = jcrPackageManager.open(child, true); if (jcrPackage == null || jcrPackage.getDefinition() == null
final JcrPackage jcrPackage = packageManager.open(packageId); final ImportOptions opts = VltUtils.getImportOptions(aclHandling, importMode);
/** * computes configured package based on expression configuration (either existing or creating it) * @throws IOException problem with binary * @throws RepositoryException problem with package persistence * @throws IOException problem with package build * @throws ScriptException problem with some expression/path compute */ protected void init() throws IOException, RepositoryException, ScriptException { if (jcrPackage == null){ String packagePath = getExpr(); if (StringUtils.isNotBlank(packagePath)) { JcrPackageManager mgr = PackagingService.getPackageManager(resolver.adaptTo(Session.class)); Resource packageResource = resolver.getResource(packagePath); if (packageResource != null) { jcrPackage = mgr.open(packageResource.adaptTo(Node.class)); } else { String parent = Text.getRelativeParent(packagePath, 1); Resource folderResource = resolver.getResource(parent); if (folderResource == null) { LOGGER.error("folder of configured path should exists"); } else { String name = Text.getName(packagePath); jcrPackage = mgr.create(folderResource.adaptTo(Node.class), name); } } } else { LOGGER.error("expression should not be blank as it's supposed to hold package path"); } } }