Search in sources :

Example 11 with JcrPackage

use of org.apache.jackrabbit.vault.packaging.JcrPackage in project acs-aem-commons by Adobe-Consulting-Services.

the class PackageHelperImpl method createPackageFromPathFilterSets.

/**
 * {@inheritDoc}
 */
public JcrPackage createPackageFromPathFilterSets(final Collection<PathFilterSet> pathFilterSets, final Session session, final String groupName, final String name, String version, final ConflictResolution conflictResolution, final Map<String, String> packageDefinitionProperties) throws IOException, RepositoryException {
    final JcrPackageManager jcrPackageManager = packaging.getPackageManager(session);
    if (ConflictResolution.Replace.equals(conflictResolution)) {
        this.removePackage(jcrPackageManager, groupName, name, version);
    } else if (ConflictResolution.IncrementVersion.equals(conflictResolution)) {
        version = this.getNextVersion(jcrPackageManager, groupName, name, version).toString();
    }
    final JcrPackage jcrPackage = jcrPackageManager.create(groupName, name, version);
    final JcrPackageDefinition jcrPackageDefinition = jcrPackage.getDefinition();
    final DefaultWorkspaceFilter workspaceFilter = new DefaultWorkspaceFilter();
    for (final PathFilterSet pathFilterSet : pathFilterSets) {
        workspaceFilter.add(pathFilterSet);
    }
    jcrPackageDefinition.setFilter(workspaceFilter, true);
    for (final Map.Entry<String, String> entry : packageDefinitionProperties.entrySet()) {
        jcrPackageDefinition.set(entry.getKey(), entry.getValue(), false);
    }
    session.save();
    return jcrPackage;
}
Also used : DefaultWorkspaceFilter(org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter) PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) JcrPackage(org.apache.jackrabbit.vault.packaging.JcrPackage) JcrPackageManager(org.apache.jackrabbit.vault.packaging.JcrPackageManager) Map(java.util.Map) JcrPackageDefinition(org.apache.jackrabbit.vault.packaging.JcrPackageDefinition)

Aggregations

JcrPackage (org.apache.jackrabbit.vault.packaging.JcrPackage)11 HashMap (java.util.HashMap)4 PackageId (org.apache.jackrabbit.vault.packaging.PackageId)4 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)4 JcrPackageManager (org.apache.jackrabbit.vault.packaging.JcrPackageManager)3 Resource (org.apache.sling.api.resource.Resource)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Node (javax.jcr.Node)2 RepositoryException (javax.jcr.RepositoryException)2 Session (javax.jcr.Session)2 PathFilterSet (org.apache.jackrabbit.vault.fs.api.PathFilterSet)2 JcrPackageDefinition (org.apache.jackrabbit.vault.packaging.JcrPackageDefinition)2 LoginException (org.apache.sling.api.resource.LoginException)2 BufferedInputStream (java.io.BufferedInputStream)1 Map (java.util.Map)1 ZipInputStream (java.util.zip.ZipInputStream)1 NodeIterator (javax.jcr.NodeIterator)1 DefaultWorkspaceFilter (org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter)1 VaultPackage (org.apache.jackrabbit.vault.packaging.VaultPackage)1