Search in sources :

Example 1 with JcrPackageDefinition

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

the class JcrPackageReplicationStatusEventHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    calendar = Calendar.getInstance();
    final List<String> contentPaths = new ArrayList<String>();
    contentPaths.add("/content/foo/jcr:content");
    contentPaths.add("/content/bar");
    contentPaths.add("/content/dam/folder/jcr:content");
    final Resource packageResource = mock(Resource.class);
    final Node packageNode = mock(Node.class);
    final JcrPackage jcrPackage = mock(JcrPackage.class);
    final VaultPackage vaultPackage = mock(VaultPackage.class);
    final Node jcrPackageNode = mock(Node.class);
    final JcrPackageDefinition jcrPackageDefinition = mock(JcrPackageDefinition.class);
    final Resource jcrPackageJcrContent = mock(Resource.class);
    final Resource contentResource1parent = mock(Resource.class);
    final Resource contentResource3parent = mock(Resource.class);
    final Node contentNode1 = mock(Node.class);
    final Node contentNode1parent = mock(Node.class);
    final Node contentNode2 = mock(Node.class);
    final Node contentNode3 = mock(Node.class);
    final Node contentNode3parent = mock(Node.class);
    final String[] paths = new String[] { PACKAGE_PATH };
    when(job.getProperty("paths")).thenReturn(paths);
    when(resourceResolverFactory.getServiceResourceResolver(anyMap())).thenReturn(resourceResolver);
    when(resourceResolver.getResource(PACKAGE_PATH)).thenReturn(packageResource);
    when(packageResource.adaptTo(Node.class)).thenReturn(packageNode);
    when(packaging.open(packageNode, false)).thenReturn(jcrPackage);
    when(packageHelper.getContents(jcrPackage)).thenReturn(contentPaths);
    when(jcrPackage.getDefinition()).thenReturn(jcrPackageDefinition);
    when(jcrPackageDefinition.getId()).thenReturn(mock(PackageId.class));
    when(jcrPackage.getNode()).thenReturn(jcrPackageNode);
    when(jcrPackageNode.getPath()).thenReturn(PACKAGE_PATH);
    when(packageResource.getChild("jcr:content")).thenReturn(jcrPackageJcrContent);
    when(jcrPackage.getPackage()).thenReturn(vaultPackage);
    when(vaultPackage.getCreated()).thenReturn(calendar);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(JcrConstants.JCR_LASTMODIFIED, calendar);
    when(jcrPackageJcrContent.adaptTo(ValueMap.class)).thenReturn(new ValueMapDecorator(properties));
    when(resourceResolver.getResource("/content/foo/jcr:content")).thenReturn(contentResource1);
    when(contentResource1.adaptTo(Node.class)).thenReturn(contentNode1);
    when(contentNode1.isNodeType("cq:PageContent")).thenReturn(true);
    when(contentResource1.getParent()).thenReturn(contentResource1parent);
    when(contentResource1parent.adaptTo(Node.class)).thenReturn(contentNode1parent);
    when(contentNode1parent.isNodeType("cq:Page")).thenReturn(true);
    when(resourceResolver.getResource("/content/bar")).thenReturn(contentResource2);
    when(contentResource2.adaptTo(Node.class)).thenReturn(contentNode2);
    when(contentNode2.isNodeType("dam:AssetContent")).thenReturn(true);
    when(resourceResolver.getResource("/content/dam/folder/jcr:content")).thenReturn(contentResource3);
    when(contentResource3.adaptTo(Node.class)).thenReturn(contentNode3);
    when(contentNode3.isNodeType("nt:unstructured")).thenReturn(true);
    when(contentResource3.getParent()).thenReturn(contentResource3parent);
    when(contentResource3parent.adaptTo(Node.class)).thenReturn(contentNode3parent);
    when(contentNode3parent.isNodeType("sling:OrderedFolder")).thenReturn(true);
}
Also used : HashMap(java.util.HashMap) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) JcrPackage(org.apache.jackrabbit.vault.packaging.JcrPackage) PackageId(org.apache.jackrabbit.vault.packaging.PackageId) VaultPackage(org.apache.jackrabbit.vault.packaging.VaultPackage) JcrPackageDefinition(org.apache.jackrabbit.vault.packaging.JcrPackageDefinition) Before(org.junit.Before)

Example 2 with JcrPackageDefinition

use of org.apache.jackrabbit.vault.packaging.JcrPackageDefinition 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)2 JcrPackageDefinition (org.apache.jackrabbit.vault.packaging.JcrPackageDefinition)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Node (javax.jcr.Node)1 PathFilterSet (org.apache.jackrabbit.vault.fs.api.PathFilterSet)1 DefaultWorkspaceFilter (org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter)1 JcrPackageManager (org.apache.jackrabbit.vault.packaging.JcrPackageManager)1 PackageId (org.apache.jackrabbit.vault.packaging.PackageId)1 VaultPackage (org.apache.jackrabbit.vault.packaging.VaultPackage)1 Resource (org.apache.sling.api.resource.Resource)1 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)1 Before (org.junit.Before)1