Search in sources :

Example 1 with ExportOptions

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

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

the class VltUtils method getExportOptions.

public static ExportOptions getExportOptions(WorkspaceFilter filter, String[] packageRoots, String packageGroup, String packageName, String packageVersion, boolean useBinaryReferences) {
    DefaultMetaInf inf = new DefaultMetaInf();
    ExportOptions opts = new ExportOptions();
    inf.setFilter(filter);
    Properties props = new Properties();
    props.setProperty(VaultPackage.NAME_GROUP, packageGroup);
    props.setProperty(VaultPackage.NAME_NAME, packageName);
    props.setProperty(VaultPackage.NAME_VERSION, packageVersion);
    props.setProperty(PackageProperties.NAME_USE_BINARY_REFERENCES, String.valueOf(useBinaryReferences));
    inf.setProperties(props);
    opts.setMetaInf(inf);
    String root = getPackageRoot(filter.getFilterSets(), packageRoots);
    opts.setRootPath(root);
    opts.setMountPath(root);
    return opts;
}
Also used : DefaultMetaInf(org.apache.jackrabbit.vault.fs.config.DefaultMetaInf) ExportOptions(org.apache.jackrabbit.vault.packaging.ExportOptions) Properties(java.util.Properties) PackageProperties(org.apache.jackrabbit.vault.packaging.PackageProperties)

Example 3 with ExportOptions

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

the class FileVaultContentSerializer method exportToStream.

@Override
public void exportToStream(ResourceResolver resourceResolver, DistributionExportOptions exportOptions, OutputStream outputStream) throws DistributionException {
    Session session = null;
    try {
        session = getSession(resourceResolver);
        String packageGroup = PACKAGE_GROUP;
        String packageName = TYPE + "_" + System.currentTimeMillis() + "_" + UUID.randomUUID();
        WorkspaceFilter filter = VltUtils.createFilter(exportOptions.getRequest(), nodeFilters, propertyFilters);
        ExportOptions opts = VltUtils.getExportOptions(filter, packageRoots, packageGroup, packageName, VERSION, useBinaryReferences);
        log.debug("assembling package {} user {}", packageGroup + '/' + packageName + "-" + VERSION, resourceResolver.getUserID());
        packaging.getPackageManager().assemble(session, opts, outputStream);
    } catch (Exception e) {
        throw new DistributionException(e);
    } finally {
        ungetSession(session);
    }
}
Also used : DistributionExportOptions(org.apache.sling.distribution.serialization.DistributionExportOptions) ExportOptions(org.apache.jackrabbit.vault.packaging.ExportOptions) WorkspaceFilter(org.apache.jackrabbit.vault.fs.api.WorkspaceFilter) DistributionException(org.apache.sling.distribution.common.DistributionException) DistributionException(org.apache.sling.distribution.common.DistributionException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Aggregations

ExportOptions (org.apache.jackrabbit.vault.packaging.ExportOptions)3 Session (javax.jcr.Session)2 DistributionExportOptions (org.apache.sling.distribution.serialization.DistributionExportOptions)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 Properties (java.util.Properties)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 WorkspaceFilter (org.apache.jackrabbit.vault.fs.api.WorkspaceFilter)1 DefaultMetaInf (org.apache.jackrabbit.vault.fs.config.DefaultMetaInf)1 AccessControlHandling (org.apache.jackrabbit.vault.fs.io.AccessControlHandling)1 PackageManager (org.apache.jackrabbit.vault.packaging.PackageManager)1 PackageProperties (org.apache.jackrabbit.vault.packaging.PackageProperties)1 Packaging (org.apache.jackrabbit.vault.packaging.Packaging)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 DistributionRequest (org.apache.sling.distribution.DistributionRequest)1 DistributionException (org.apache.sling.distribution.common.DistributionException)1 DistributionExportFilter (org.apache.sling.distribution.serialization.DistributionExportFilter)1