Search in sources :

Example 1 with VaultPackage

use of org.apache.jackrabbit.vault.packaging.VaultPackage in project sling by apache.

the class FileVaultContentSerializerTest method testImportFromStream.

@Test
public void testImportFromStream() throws Exception {
    Packaging packaging = mock(Packaging.class);
    ImportMode importMode = ImportMode.REPLACE;
    AccessControlHandling aclHandling = AccessControlHandling.IGNORE;
    String[] packageRoots = new String[] { "/" };
    String[] nodeFilters = new String[0];
    String[] propertyFilters = new String[0];
    boolean useReferences = false;
    int thershold = 1024;
    FileVaultContentSerializer fileVaultContentSerializer = new FileVaultContentSerializer("vlt", packaging, importMode, aclHandling, packageRoots, nodeFilters, propertyFilters, useReferences, thershold);
    ResourceResolver sessionResolver = mock(ResourceResolver.class);
    Session session = mock(Session.class);
    File file = new File(getClass().getResource("/vlt/dp.vlt").getFile());
    PackageManager pm = mock(PackageManager.class);
    VaultPackage vaultPackage = mock(VaultPackage.class);
    when(pm.open(any(File.class))).thenReturn(vaultPackage);
    when(packaging.getPackageManager()).thenReturn(pm);
    Workspace workspace = mock(Workspace.class);
    ObservationManager observationManager = mock(ObservationManager.class);
    when(workspace.getObservationManager()).thenReturn(observationManager);
    when(session.getWorkspace()).thenReturn(workspace);
    when(sessionResolver.adaptTo(Session.class)).thenReturn(session);
    fileVaultContentSerializer.importFromStream(sessionResolver, new FileInputStream(file));
}
Also used : AccessControlHandling(org.apache.jackrabbit.vault.fs.io.AccessControlHandling) ObservationManager(javax.jcr.observation.ObservationManager) FileInputStream(java.io.FileInputStream) ImportMode(org.apache.jackrabbit.vault.fs.api.ImportMode) PackageManager(org.apache.jackrabbit.vault.packaging.PackageManager) Packaging(org.apache.jackrabbit.vault.packaging.Packaging) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) File(java.io.File) VaultPackage(org.apache.jackrabbit.vault.packaging.VaultPackage) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 2 with VaultPackage

use of org.apache.jackrabbit.vault.packaging.VaultPackage in project sling by apache.

the class FileVaultContentSerializer method importFromStream.

@Override
public void importFromStream(ResourceResolver resourceResolver, InputStream inputStream) throws DistributionException {
    Session session = null;
    OutputStream outputStream = null;
    File file = null;
    boolean isTmp = true;
    try {
        session = getSession(resourceResolver);
        ImportOptions importOptions = VltUtils.getImportOptions(aclHandling, importMode, autosaveThreshold);
        if (inputStream instanceof FileDistributionPackage.PackageInputStream) {
            file = ((FileDistributionPackage.PackageInputStream) inputStream).getFile();
            isTmp = false;
        } else {
            file = File.createTempFile("distrpck-tmp-" + System.nanoTime(), "." + TYPE);
        }
        outputStream = new BufferedOutputStream(new FileOutputStream(file));
        IOUtils.copy(inputStream, outputStream);
        IOUtils.closeQuietly(outputStream);
        PackageManager packageManager = packaging.getPackageManager();
        VaultPackage vaultPackage = packageManager.open(file);
        vaultPackage.extract(session, importOptions);
        vaultPackage.close();
    } catch (Exception e) {
        throw new DistributionException(e);
    } finally {
        IOUtils.closeQuietly(outputStream);
        if (isTmp) {
            FileUtils.deleteQuietly(file);
        }
        ungetSession(session);
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) DistributionException(org.apache.sling.distribution.common.DistributionException) RepositoryException(javax.jcr.RepositoryException) PackageManager(org.apache.jackrabbit.vault.packaging.PackageManager) FileOutputStream(java.io.FileOutputStream) DistributionException(org.apache.sling.distribution.common.DistributionException) File(java.io.File) FileDistributionPackage(org.apache.sling.distribution.packaging.impl.FileDistributionPackage) BufferedOutputStream(java.io.BufferedOutputStream) ImportOptions(org.apache.jackrabbit.vault.fs.io.ImportOptions) VaultPackage(org.apache.jackrabbit.vault.packaging.VaultPackage) Session(javax.jcr.Session)

Example 3 with VaultPackage

use of org.apache.jackrabbit.vault.packaging.VaultPackage 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)

Aggregations

VaultPackage (org.apache.jackrabbit.vault.packaging.VaultPackage)3 File (java.io.File)2 Session (javax.jcr.Session)2 PackageManager (org.apache.jackrabbit.vault.packaging.PackageManager)2 BufferedOutputStream (java.io.BufferedOutputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 Workspace (javax.jcr.Workspace)1 ObservationManager (javax.jcr.observation.ObservationManager)1 ImportMode (org.apache.jackrabbit.vault.fs.api.ImportMode)1 AccessControlHandling (org.apache.jackrabbit.vault.fs.io.AccessControlHandling)1 ImportOptions (org.apache.jackrabbit.vault.fs.io.ImportOptions)1 JcrPackage (org.apache.jackrabbit.vault.packaging.JcrPackage)1 JcrPackageDefinition (org.apache.jackrabbit.vault.packaging.JcrPackageDefinition)1 PackageId (org.apache.jackrabbit.vault.packaging.PackageId)1