Search in sources :

Example 16 with PathFilterSet

use of org.apache.jackrabbit.vault.fs.api.PathFilterSet 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)

Example 17 with PathFilterSet

use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project acs-aem-commons by Adobe-Consulting-Services.

the class PackageHelperImplTest method setUp.

@Before
public void setUp() throws Exception {
    packageOneFilterSets = new ArrayList<PathFilterSet>();
    packageOneFilterSets.add(new PathFilterSet("/a/b/c"));
    packageOneFilterSets.add(new PathFilterSet("/d/e/f"));
    packageOneFilterSets.add(new PathFilterSet("/g/h/i"));
    packageTwoFilterSets = new ArrayList<PathFilterSet>();
    when(packaging.getPackageManager(any(Session.class))).thenReturn(jcrPackageManager);
    when(jcrPackageManager.getPackageRoot(false)).thenReturn(packageRoot);
    when(packageRoot.hasNode(packageGroup)).thenReturn(true);
    when(packageRoot.getNode(packageGroup)).thenReturn(packageGroupRoot);
    when(packageGroupRoot.getNodes()).thenReturn(packageGroupNodeIterator);
    when(packageGroupNodeIterator.hasNext()).thenReturn(true, true, false);
    when(packageGroupNodeIterator.nextNode()).thenReturn(packageOneNode, packageTwoNode, null);
    when(jcrPackageManager.open(packageOneNode, true)).thenReturn(packageOne);
    when(jcrPackageManager.open(packageTwoNode, true)).thenReturn(packageTwo);
    when(packageOne.getDefinition()).thenReturn(packageOneDef);
    when(packageTwo.getDefinition()).thenReturn(packageTwoDef);
    when(packageOneDef.getId()).thenReturn(packageOneID);
    when(packageTwoDef.getId()).thenReturn(packageTwoID);
    when(packageOneDef.getNode()).thenReturn(packageOneDefNode);
    when(packageTwoDef.getNode()).thenReturn(packageTwoDefNode);
    when(packageOneDef.getMetaInf()).thenReturn(packageOneMetaInf);
    when(packageTwoDef.getMetaInf()).thenReturn(packageTwoMetaInf);
    when(packageOneMetaInf.getFilter()).thenReturn(packageOneFilter);
    when(packageTwoMetaInf.getFilter()).thenReturn(packageTwoFilter);
    when(packageOneFilter.getFilterSets()).thenReturn(packageOneFilterSets);
    when(packageTwoFilter.getFilterSets()).thenReturn(packageTwoFilterSets);
    when(packageOne.getNode()).thenReturn(packageOneNode);
    when(packageTwo.getNode()).thenReturn(packageTwoNode);
    when(packageOneNode.getPath()).thenReturn("/etc/packages/" + packageGroup + "/" + packageName + "-" + packageOneVersion + ".zip");
    when(packageTwoNode.getPath()).thenReturn("/etc/packages/" + packageGroup + "/" + packageName + "-" + packageTwoVersion + ".zip");
    when(packageOneID.getName()).thenReturn(packageName);
    when(packageTwoID.getName()).thenReturn(packageName);
    when(packageOneID.getVersion()).thenReturn(Version.create(packageOneVersion));
    when(packageTwoID.getVersion()).thenReturn(Version.create(packageTwoVersion));
}
Also used : PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) Session(javax.jcr.Session) Before(org.junit.Before)

Example 18 with PathFilterSet

use of org.apache.jackrabbit.vault.fs.api.PathFilterSet in project acs-aem-commons by Adobe-Consulting-Services.

the class PackageHelperImplTest method testCreatePackageFromPathFilterSets.

@Test
public void testCreatePackageFromPathFilterSets() throws Exception {
    Map<String, String> properties = new HashMap<String, String>();
    final List<PathFilterSet> pathFilterSets = new ArrayList<PathFilterSet>();
    pathFilterSets.add(new PathFilterSet("/a/b/c"));
    pathFilterSets.add(new PathFilterSet("/d/e/f"));
    pathFilterSets.add(new PathFilterSet("/g/h/i"));
    when(jcrPackageManager.create(packageGroup, packageName, packageOneVersion)).thenReturn(packageOne);
    packageHelper.createPackageFromPathFilterSets(pathFilterSets, session, packageGroup, packageName, packageOneVersion, PackageHelper.ConflictResolution.None, properties);
    // Verify the session was saved, creating the package
    verify(session, times(1)).save();
}
Also used : PathFilterSet(org.apache.jackrabbit.vault.fs.api.PathFilterSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

PathFilterSet (org.apache.jackrabbit.vault.fs.api.PathFilterSet)18 ArrayList (java.util.ArrayList)7 RepositoryException (javax.jcr.RepositoryException)4 WorkspaceFilter (org.apache.jackrabbit.vault.fs.api.WorkspaceFilter)4 DefaultWorkspaceFilter (org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter)4 Test (org.junit.Test)4 DefaultPathFilter (org.apache.jackrabbit.vault.fs.filter.DefaultPathFilter)3 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)3 ValueMap (org.apache.sling.api.resource.ValueMap)3 JSONArray (org.apache.sling.commons.json.JSONArray)3 JSONObject (org.apache.sling.commons.json.JSONObject)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)2 UserManager (org.apache.jackrabbit.api.security.user.UserManager)2 JcrPackage (org.apache.jackrabbit.vault.packaging.JcrPackage)2 Resource (org.apache.sling.api.resource.Resource)2 JSONException (org.apache.sling.commons.json.JSONException)2