Search in sources :

Example 1 with DistributionExportOptions

use of org.apache.sling.distribution.serialization.DistributionExportOptions in project sling by apache.

the class FileVaultContentSerializerTest method testExportToStream.

@Test
public void testExportToStream() throws Exception {
    Packaging packaging = mock(Packaging.class);
    ImportMode importMode = ImportMode.REPLACE;
    AccessControlHandling aclHandling = AccessControlHandling.IGNORE;
    String[] packageRoots = new String[] { "/etc/packages" };
    String[] nodeFilters = new String[0];
    String[] propertyFilters = new String[0];
    boolean useReferences = false;
    int threshold = 1024;
    FileVaultContentSerializer fileVaultContentSerializer = new FileVaultContentSerializer("vlt", packaging, importMode, aclHandling, packageRoots, nodeFilters, propertyFilters, useReferences, threshold);
    ResourceResolver sessionResolver = mock(ResourceResolver.class);
    Session session = mock(Session.class);
    PackageManager pm = mock(PackageManager.class);
    when(packaging.getPackageManager()).thenReturn(pm);
    OutputStream outputStream = new ByteArrayOutputStream();
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
            return null;
        }
    }).when(pm).assemble(same(session), any(ExportOptions.class), same(outputStream));
    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);
    DistributionExportFilter filter = mock(DistributionExportFilter.class);
    DistributionRequest request = mock(DistributionRequest.class);
    when(request.getPaths()).thenReturn(new String[] { "/libs" });
    when(request.getFilters("/libs")).thenReturn(new String[0]);
    DistributionExportOptions exportOptions = new DistributionExportOptions(request, filter);
    fileVaultContentSerializer.exportToStream(sessionResolver, exportOptions, outputStream);
}
Also used : AccessControlHandling(org.apache.jackrabbit.vault.fs.io.AccessControlHandling) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObservationManager(javax.jcr.observation.ObservationManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DistributionExportOptions(org.apache.sling.distribution.serialization.DistributionExportOptions) DistributionRequest(org.apache.sling.distribution.DistributionRequest) ImportMode(org.apache.jackrabbit.vault.fs.api.ImportMode) PackageManager(org.apache.jackrabbit.vault.packaging.PackageManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DistributionExportOptions(org.apache.sling.distribution.serialization.DistributionExportOptions) ExportOptions(org.apache.jackrabbit.vault.packaging.ExportOptions) Packaging(org.apache.jackrabbit.vault.packaging.Packaging) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) DistributionExportFilter(org.apache.sling.distribution.serialization.DistributionExportFilter) Session(javax.jcr.Session) Workspace(javax.jcr.Workspace) Test(org.junit.Test)

Example 2 with DistributionExportOptions

use of org.apache.sling.distribution.serialization.DistributionExportOptions in project sling by apache.

the class AvroContentSerializerTest method testExtractDeep.

@Test
public void testExtractDeep() throws Exception {
    AvroContentSerializer avroContentSerializer = new AvroContentSerializer("avro");
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, true, "/libs");
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
    NavigableMap<String, List<String>> propertyFilters = new TreeMap<String, List<String>>();
    try {
        DistributionExportFilter filter = DistributionExportFilter.createFilter(request, nodeFilters, propertyFilters);
        avroContentSerializer.exportToStream(resourceResolver, new DistributionExportOptions(request, filter), outputStream);
        byte[] bytes = outputStream.toByteArray();
        assertNotNull(bytes);
        assertTrue(bytes.length > 0);
    } finally {
        outputStream.close();
    }
}
Also used : DistributionExportOptions(org.apache.sling.distribution.serialization.DistributionExportOptions) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) List(java.util.List) DistributionExportFilter(org.apache.sling.distribution.serialization.DistributionExportFilter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 3 with DistributionExportOptions

use of org.apache.sling.distribution.serialization.DistributionExportOptions in project sling by apache.

the class AvroContentSerializerTest method testExtractShallow.

@Test
public void testExtractShallow() throws Exception {
    AvroContentSerializer avroContentSerializer = new AvroContentSerializer("avro");
    DistributionRequest request = new SimpleDistributionRequest(DistributionRequestType.ADD, "/libs");
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    NavigableMap<String, List<String>> nodeFilters = new TreeMap<String, List<String>>();
    NavigableMap<String, List<String>> propertyFilters = new TreeMap<String, List<String>>();
    try {
        DistributionExportFilter filter = DistributionExportFilter.createFilter(request, nodeFilters, propertyFilters);
        avroContentSerializer.exportToStream(resourceResolver, new DistributionExportOptions(request, filter), outputStream);
        byte[] bytes = outputStream.toByteArray();
        assertNotNull(bytes);
        assertTrue(bytes.length > 0);
    } finally {
        outputStream.close();
    }
}
Also used : DistributionExportOptions(org.apache.sling.distribution.serialization.DistributionExportOptions) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) DistributionRequest(org.apache.sling.distribution.DistributionRequest) SimpleDistributionRequest(org.apache.sling.distribution.SimpleDistributionRequest) List(java.util.List) DistributionExportFilter(org.apache.sling.distribution.serialization.DistributionExportFilter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 4 with DistributionExportOptions

use of org.apache.sling.distribution.serialization.DistributionExportOptions in project sling by apache.

the class FileDistributionPackageBuilder method createPackageForAdd.

@Override
protected DistributionPackage createPackageForAdd(@Nonnull ResourceResolver resourceResolver, @Nonnull final DistributionRequest request) throws DistributionException {
    DistributionPackage distributionPackage;
    OutputStream outputStream = null;
    String digestMessage = null;
    final File file;
    try {
        file = File.createTempFile("distrpck-create-" + randomUUID(), "." + getType(), tempDirectory);
        if (digestAlgorithm != null) {
            outputStream = openDigestOutputStream(new FileOutputStream(file), digestAlgorithm);
        } else {
            outputStream = new FileOutputStream(file);
        }
        final DistributionExportFilter filter = distributionContentSerializer.isRequestFiltering() ? null : DistributionExportFilter.createFilter(request, nodeFilters, propertyFilters);
        DistributionExportOptions distributionExportOptions = new DistributionExportOptions(request, filter);
        distributionContentSerializer.exportToStream(resourceResolver, distributionExportOptions, outputStream);
        outputStream.flush();
        if (digestAlgorithm != null) {
            digestMessage = readDigestMessage((DigestOutputStream) outputStream);
        }
        distributionPackage = new FileDistributionPackage(file, getType(), digestAlgorithm, digestMessage);
    } catch (IOException e) {
        throw new DistributionException(e);
    } finally {
        IOUtils.closeQuietly(outputStream);
    }
    return distributionPackage;
}
Also used : DistributionExportOptions(org.apache.sling.distribution.serialization.DistributionExportOptions) DistributionPackage(org.apache.sling.distribution.packaging.DistributionPackage) DigestUtils.openDigestOutputStream(org.apache.sling.distribution.util.impl.DigestUtils.openDigestOutputStream) DigestOutputStream(java.security.DigestOutputStream) OutputStream(java.io.OutputStream) DigestUtils.openDigestOutputStream(org.apache.sling.distribution.util.impl.DigestUtils.openDigestOutputStream) FileOutputStream(java.io.FileOutputStream) DigestOutputStream(java.security.DigestOutputStream) FileOutputStream(java.io.FileOutputStream) DistributionExportFilter(org.apache.sling.distribution.serialization.DistributionExportFilter) DistributionException(org.apache.sling.distribution.common.DistributionException) IOException(java.io.IOException) File(java.io.File)

Example 5 with DistributionExportOptions

use of org.apache.sling.distribution.serialization.DistributionExportOptions in project sling by apache.

the class ResourceDistributionPackageBuilder method export.

private void export(@Nonnull ResourceResolver resourceResolver, @Nonnull final DistributionRequest request, OutputStream outputStream) throws DistributionException {
    final DistributionExportFilter filter = distributionContentSerializer.isRequestFiltering() ? null : DistributionExportFilter.createFilter(request, nodeFilters, propertyFilters);
    DistributionExportOptions distributionExportOptions = new DistributionExportOptions(request, filter);
    distributionContentSerializer.exportToStream(resourceResolver, distributionExportOptions, outputStream);
}
Also used : DistributionExportOptions(org.apache.sling.distribution.serialization.DistributionExportOptions) DistributionExportFilter(org.apache.sling.distribution.serialization.DistributionExportFilter)

Aggregations

DistributionExportOptions (org.apache.sling.distribution.serialization.DistributionExportOptions)7 DistributionExportFilter (org.apache.sling.distribution.serialization.DistributionExportFilter)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DistributionRequest (org.apache.sling.distribution.DistributionRequest)4 Test (org.junit.Test)4 List (java.util.List)3 TreeMap (java.util.TreeMap)3 SimpleDistributionRequest (org.apache.sling.distribution.SimpleDistributionRequest)3 OutputStream (java.io.OutputStream)2 Session (javax.jcr.Session)2 ExportOptions (org.apache.jackrabbit.vault.packaging.ExportOptions)2 DistributionException (org.apache.sling.distribution.common.DistributionException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 DigestOutputStream (java.security.DigestOutputStream)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