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;
}
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));
}
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();
}
Aggregations