Search in sources :

Example 1 with AccessControlHandling

use of org.apache.jackrabbit.vault.fs.io.AccessControlHandling 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 AccessControlHandling

use of org.apache.jackrabbit.vault.fs.io.AccessControlHandling 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 3 with AccessControlHandling

use of org.apache.jackrabbit.vault.fs.io.AccessControlHandling in project sling by apache.

the class VaultDistributionPackageBuilderFactory method activate.

@Activate
public void activate(BundleContext context, Map<String, Object> config) {
    String name = PropertiesUtil.toString(config.get(NAME), null);
    String type = PropertiesUtil.toString(config.get(TYPE), null);
    String importModeString = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(IMPORT_MODE), null));
    String aclHandlingString = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(ACL_HANDLING), null));
    String[] packageRoots = SettingsUtils.removeEmptyEntries(PropertiesUtil.toStringArray(config.get(PACKAGE_ROOTS), null));
    String[] packageNodeFilters = SettingsUtils.removeEmptyEntries(PropertiesUtil.toStringArray(config.get(PACKAGE_FILTERS), null));
    String[] packagePropertyFilters = SettingsUtils.removeEmptyEntries(PropertiesUtil.toStringArray(config.get(PROPERTY_FILTERS), null));
    long cleanupDelay = PropertiesUtil.toLong(config.get(PACKAGE_CLEANUP_DELAY), DEFAULT_PACKAGE_CLEANUP_DELAY);
    String tempFsFolder = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(TEMP_FS_FOLDER), null));
    boolean useBinaryReferences = PropertiesUtil.toBoolean(config.get(USE_BINARY_REFERENCES), false);
    int autosaveThreshold = PropertiesUtil.toInteger(config.get(AUTOSAVE_THRESHOLD), -1);
    String digestAlgorithm = PropertiesUtil.toString(config.get(DIGEST_ALGORITHM), DEFAULT_DIGEST_ALGORITHM);
    if (DEFAULT_DIGEST_ALGORITHM.equals(digestAlgorithm)) {
        digestAlgorithm = null;
    }
    ImportMode importMode = null;
    if (importModeString != null) {
        importMode = ImportMode.valueOf(importModeString.trim());
    }
    AccessControlHandling aclHandling = null;
    if (aclHandlingString != null) {
        aclHandling = AccessControlHandling.valueOf(aclHandlingString.trim());
    }
    DistributionContentSerializer contentSerializer = new FileVaultContentSerializer(name, packaging, importMode, aclHandling, packageRoots, packageNodeFilters, packagePropertyFilters, useBinaryReferences, autosaveThreshold);
    DistributionPackageBuilder wrapped;
    if ("filevlt".equals(type)) {
        wrapped = new FileDistributionPackageBuilder(name, contentSerializer, tempFsFolder, digestAlgorithm, packageNodeFilters, packagePropertyFilters);
    } else {
        final int fileThreshold = PropertiesUtil.toInteger(config.get(FILE_THRESHOLD), DEFAULT_FILE_THRESHOLD_VALUE);
        String memoryUnitName = PropertiesUtil.toString(config.get(MEMORY_UNIT), DEFAULT_MEMORY_UNIT);
        final MemoryUnit memoryUnit = MemoryUnit.valueOf(memoryUnitName);
        final boolean useOffHeapMemory = PropertiesUtil.toBoolean(config.get(USE_OFF_HEAP_MEMORY), DEFAULT_USE_OFF_HEAP_MEMORY);
        ResourceDistributionPackageBuilder resourceDistributionPackageBuilder = new ResourceDistributionPackageBuilder(contentSerializer.getName(), contentSerializer, tempFsFolder, fileThreshold, memoryUnit, useOffHeapMemory, digestAlgorithm, packageNodeFilters, packagePropertyFilters);
        Runnable cleanup = new ResourceDistributionPackageCleanup(resolverFactory, resourceDistributionPackageBuilder);
        Dictionary<String, Object> props = new Hashtable<String, Object>();
        props.put(Scheduler.PROPERTY_SCHEDULER_CONCURRENT, false);
        props.put(Scheduler.PROPERTY_SCHEDULER_PERIOD, cleanupDelay);
        packageCleanup = context.registerService(Runnable.class.getName(), cleanup, props);
        wrapped = resourceDistributionPackageBuilder;
    }
    int monitoringQueueSize = PropertiesUtil.toInteger(config.get(MONITORING_QUEUE_SIZE), DEFAULT_MONITORING_QUEUE_SIZE);
    packageBuilder = new MonitoringDistributionPackageBuilder(monitoringQueueSize, wrapped, context);
}
Also used : ResourceDistributionPackageCleanup(org.apache.sling.distribution.packaging.impl.ResourceDistributionPackageCleanup) AccessControlHandling(org.apache.jackrabbit.vault.fs.io.AccessControlHandling) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) MemoryUnit(org.apache.sling.distribution.util.impl.FileBackedMemoryOutputStream.MemoryUnit) ResourceDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.ResourceDistributionPackageBuilder) Hashtable(java.util.Hashtable) DistributionContentSerializer(org.apache.sling.distribution.serialization.DistributionContentSerializer) MonitoringDistributionPackageBuilder(org.apache.sling.distribution.monitor.impl.MonitoringDistributionPackageBuilder) ImportMode(org.apache.jackrabbit.vault.fs.api.ImportMode) FileDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder) DistributionPackageBuilder(org.apache.sling.distribution.packaging.DistributionPackageBuilder) ResourceDistributionPackageBuilder(org.apache.sling.distribution.packaging.impl.ResourceDistributionPackageBuilder) MonitoringDistributionPackageBuilder(org.apache.sling.distribution.monitor.impl.MonitoringDistributionPackageBuilder)

Aggregations

ImportMode (org.apache.jackrabbit.vault.fs.api.ImportMode)3 AccessControlHandling (org.apache.jackrabbit.vault.fs.io.AccessControlHandling)3 Session (javax.jcr.Session)2 Workspace (javax.jcr.Workspace)2 ObservationManager (javax.jcr.observation.ObservationManager)2 PackageManager (org.apache.jackrabbit.vault.packaging.PackageManager)2 Packaging (org.apache.jackrabbit.vault.packaging.Packaging)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 OutputStream (java.io.OutputStream)1 Hashtable (java.util.Hashtable)1 ExportOptions (org.apache.jackrabbit.vault.packaging.ExportOptions)1 VaultPackage (org.apache.jackrabbit.vault.packaging.VaultPackage)1 DistributionRequest (org.apache.sling.distribution.DistributionRequest)1 MonitoringDistributionPackageBuilder (org.apache.sling.distribution.monitor.impl.MonitoringDistributionPackageBuilder)1 DistributionPackageBuilder (org.apache.sling.distribution.packaging.DistributionPackageBuilder)1 FileDistributionPackageBuilder (org.apache.sling.distribution.packaging.impl.FileDistributionPackageBuilder)1