Search in sources :

Example 31 with DiskSharedDevice

use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testFileInformationUpdatingByEditorUserForAlf8808.

// testDirListing
public void testFileInformationUpdatingByEditorUserForAlf8808() throws Exception {
    final Holder<org.alfresco.service.cmr.model.FileInfo> editorFolder = new Holder<org.alfresco.service.cmr.model.FileInfo>();
    final Holder<org.alfresco.service.cmr.model.FileInfo> testFile = new Holder<org.alfresco.service.cmr.model.FileInfo>();
    // Configuring test server with test server configuration and getting test tree connection for test shared device
    ServerConfiguration config = new ServerConfiguration(ContentDiskDriverTest.TEST_SERVER_NAME);
    TestServer server = new TestServer(ContentDiskDriverTest.TEST_SERVER_NAME, config);
    DiskSharedDevice device = getDiskSharedDevice();
    final TreeConnection treeConnection = server.getTreeConnection(device);
    // Getting target entity for testing - ContentDiskDriver
    final ExtendedDiskInterface deviceInterface = (ExtendedDiskInterface) treeConnection.getInterface();
    // Creating mock-session
    final SrvSession session = new TestSrvSession(13, server, ContentDiskDriverTest.TEST_PROTOTYPE_NAME, ContentDiskDriverTest.TEST_REMOTE_NAME);
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            try {
                NodeRef rootNode = repositoryHelper.getCompanyHome();
                // Creating test user to invite him as Editor for test content. This user will be created correctly (with person and authentication options)
                createUser(ContentDiskDriverTest.TEST_USER_AUTHORITY, ContentDiskDriverTest.TEST_USER_AUTHORITY, rootNode);
                // Safely creating folder for test content
                editorFolder.value = getOrCreateNode(rootNode, PermissionService.EDITOR, ContentModel.TYPE_FOLDER).getFirst();
                // Creating test content which will be editable by user created above
                testFile.value = getOrCreateNode(rootNode, "Test.txt", ContentModel.TYPE_CONTENT).getFirst();
                // Applying 'Editor' role for test user to test file
                permissionService.setPermission(testFile.value.getNodeRef(), ContentDiskDriverTest.TEST_USER_AUTHORITY, PermissionService.EDITOR, true);
                try {
                    // Creating data for target method invocation
                    final FileInfo updatedInfo = new FileInfo();
                    updatedInfo.setFileName(testFile.value.getName());
                    updatedInfo.setFileId(DefaultTypeConverter.INSTANCE.intValue(testFile.value.getProperties().get(ContentModel.PROP_NODE_DBID)));
                    // Testing ContentDiskDriver.setFileInformation() with test user authenticated who has 'Editor' role for test content.
                    // This method should fail if check on 'DELETE' permission was not moved to 'DeleteOnClose' context
                    AuthenticationUtil.runAs(new RunAsWork<Void>() {

                        @Override
                        public Void doWork() throws Exception {
                            deviceInterface.setFileInformation(session, treeConnection, testFile.value.getName(), updatedInfo);
                            return null;
                        }
                    }, ContentDiskDriverTest.TEST_USER_AUTHORITY);
                } catch (Exception e) {
                    // Informing about test failure. Expected exception is 'org.alfresco.jlan.server.filesys.AccessDeniedException'
                    if (e.getCause() instanceof AccessDeniedException) {
                        fail("For user='" + TEST_USER_AUTHORITY + "' " + e.getCause().toString());
                    } else {
                        fail("Unexpected exception was caught: " + e.toString());
                    }
                }
            } finally {
                if (authenticationService.authenticationExists(ContentDiskDriverTest.TEST_USER_AUTHORITY)) {
                    authenticationService.deleteAuthentication(ContentDiskDriverTest.TEST_USER_AUTHORITY);
                }
                if (personService.personExists(ContentDiskDriverTest.TEST_USER_AUTHORITY)) {
                    personService.deletePerson(ContentDiskDriverTest.TEST_USER_AUTHORITY);
                }
                try {
                    if (null != testFile.value) {
                        nodeService.deleteNode(testFile.value.getNodeRef());
                    }
                } catch (Exception e) {
                // Doing nothing
                }
                try {
                    if (null != editorFolder.value) {
                        nodeService.deleteNode(editorFolder.value.getNodeRef());
                    }
                } catch (Exception e) {
                // Doing nothing
                }
            }
            return null;
        }
    }, false, true);
}
Also used : AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) SrvSession(org.alfresco.jlan.server.SrvSession) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) ExtendedDiskInterface(org.alfresco.filesys.alfresco.ExtendedDiskInterface) Holder(javax.xml.ws.Holder) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) FileExistsException(org.alfresco.jlan.server.filesys.FileExistsException) FileNotFoundException(java.io.FileNotFoundException) PermissionDeniedException(org.alfresco.jlan.server.filesys.PermissionDeniedException) AccessDeniedException(org.alfresco.jlan.server.filesys.AccessDeniedException) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.jlan.server.filesys.FileInfo) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 32 with DiskSharedDevice

use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testScenarioMSWord2007Save.

// testScenarioMSWord2003SaveShuffleWithBackup
/**
 * This test tries to simulate the cifs shuffling that is done to
 * support MS Word 2007
 *
 * a) TEST.DOCX
 * b) Save new to 00000001.TMP
 * c) Rename TEST.DOCX to 00000002.TMP
 * d) Rename 000000001.TMP to TEST.DOCX
 * e) Delete 000000002.TMP
 */
public void testScenarioMSWord2007Save() throws Exception {
    logger.debug("testScenarioMSWord2007SaveShuffle");
    final String FILE_NAME = "TEST.DOCX";
    final String FILE_OLD_TEMP = "788A1D3D.tmp";
    final String FILE_NEW_TEMP = "19ECA1A.tmp";
    class TestContext {

        NetworkFile firstFileHandle;

        NetworkFile newFileHandle;

        // node ref of test.doc
        NodeRef testNodeRef;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_ROOT_DIR = "\\ContentDiskDriverTest";
    final String TEST_DIR = "\\ContentDiskDriverTest\\testScenarioMSWord2007Save";
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    final TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    /**
     * Create a file in the test directory
     */
    RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the test directory we are going to use
             */
            FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            driver.createDirectory(testSession, testConnection, createRootDirParams);
            driver.createDirectory(testSession, testConnection, createDirParams);
            /**
             * Create the file we are going to use
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.firstFileHandle);
            // no need to test lots of different properties, that's already been tested above
            testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            nodeService.setProperty(testContext.testNodeRef, TransferModel.PROP_ENABLED, true);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    /**
     * a) Write some content to the test file
     */
    RetryingTransactionCallback<Void> writeFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            String testContent = "MS Word 2007 shuffle test";
            byte[] testContentBytes = testContent.getBytes();
            testContext.firstFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
            testContext.firstFileHandle.close();
            return null;
        }
    };
    tran.doInTransaction(writeFileCB, false, true);
    /**
     * b) Save the new file
     */
    RetryingTransactionCallback<Void> saveNewFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NEW_TEMP, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.newFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.newFileHandle);
            String testContent = "MS Word 2007 shuffle test This is new content";
            byte[] testContentBytes = testContent.getBytes();
            testContext.newFileHandle.writeFile(testContentBytes, testContentBytes.length, 0, 0);
            testContext.newFileHandle.close();
            return null;
        }
    };
    tran.doInTransaction(saveNewFileCB, false, true);
    /**
     * c) rename the old file
     */
    RetryingTransactionCallback<Void> renameOldFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_OLD_TEMP);
            return null;
        }
    };
    tran.doInTransaction(renameOldFileCB, false, true);
    /**
     * d) Move the new file into place, stuff should get shuffled
     */
    RetryingTransactionCallback<Void> moveNewFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NEW_TEMP, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(moveNewFileCB, false, true);
    RetryingTransactionCallback<Void> deleteOldFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_OLD_TEMP);
            return null;
        }
    };
    tran.doInTransaction(deleteOldFileCB, false, true);
    RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
            assertTrue("node does not contain shuffled ENABLED property", props.containsKey(TransferModel.PROP_ENABLED));
            assertEquals("name wrong", FILE_NAME, nodeService.getProperty(shuffledNodeRef, ContentModel.PROP_NAME));
            return null;
        }
    };
    tran.doInTransaction(validateCB, false, true);
}
Also used : Serializable(java.io.Serializable) SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) QName(org.alfresco.service.namespace.QName) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 33 with DiskSharedDevice

use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testScenarioMacMountainLionPreview_MNT_317.

// testScenarioMacMountainLionPreview_MNT_263
/**
 * This test tries to simulate the cifs shuffling that is done
 * from Save from Mac Mountain Lion by Preview when document is opened/saved few time a row
 *
 * a) Temp file created in temporary folder (temp\image.jpg)
 * b) Original file is renamed for deletion(test\image.jpg -> test\.smbdeleteAAA1b994.4)
 * c) Renamed file has got deleteOnClose flag
 * d) Renamed file is closed.
 * e) Temp file is moved into original file location(temp\image.jpg -> test\image.jgp)
 */
public void testScenarioMacMountainLionPreview_MNT_317() throws Exception {
    logger.debug("testScenarioMacMountainLionPreview_MNT_317");
    final String FILE_NAME = "image.jpg";
    final String TEMP_FILE_NAME = ".smbdeleteAAA1b994.4";
    final String UPDATED_TEXT = "Mac Lion Preview Updated Content";
    class TestContext {

        NetworkFile firstFileHandle;

        NetworkFile tempFileHandle;

        // node ref image.jpg
        NodeRef testNodeRef;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_ROOT_DIR = "\\ContentDiskDriverTest";
    final String TEST_DIR = "\\ContentDiskDriverTest\\testScenarioMountainLionPreview";
    final String TEST_TEMP_DIR = "\\ContentDiskDriverTest\\testScenarioMountainLionPreview\\.Temporary Items";
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    final TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    /**
     * Create a file in the test directory
     */
    RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the test directory we are going to use
             */
            FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            FileOpenParams createDirParams = new FileOpenParams(TEST_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            FileOpenParams createTempDirParams = new FileOpenParams(TEST_TEMP_DIR, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            driver.createDirectory(testSession, testConnection, createRootDirParams);
            driver.createDirectory(testSession, testConnection, createDirParams);
            driver.createDirectory(testSession, testConnection, createTempDirParams);
            /**
             * Create the file we are going to use
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.firstFileHandle);
            String testContent = "Mac Lion Preview Content";
            byte[] testContentBytes = testContent.getBytes();
            driver.writeFile(testSession, testConnection, testContext.firstFileHandle, testContentBytes, 0, testContentBytes.length, 0);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            /**
             * Create the temp file we are going to use
             */
            FileOpenParams createTempFileParams = new FileOpenParams(TEST_TEMP_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.tempFileHandle = driver.createFile(testSession, testConnection, createTempFileParams);
            assertNotNull(testContext.tempFileHandle);
            testContent = UPDATED_TEXT;
            testContentBytes = testContent.getBytes();
            driver.writeFile(testSession, testConnection, testContext.tempFileHandle, testContentBytes, 0, testContentBytes.length, 0);
            driver.closeFile(testSession, testConnection, testContext.tempFileHandle);
            /**
             * Also add versionable to target file
             */
            testContext.testNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            nodeService.addAspect(testContext.testNodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    RetryingTransactionCallback<Void> renameFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            FileOpenParams openFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.tempFileHandle = driver.openFile(testSession, testConnection, openFileParams);
            driver.renameFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + TEMP_FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(renameFileCB, false, true);
    /**
     * Delete file via deleteOnClose flag.
     */
    RetryingTransactionCallback<Void> deleteOnCloseCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            FileInfo info = new FileInfo();
            info.setFileInformationFlags(FileInfo.SetDeleteOnClose);
            info.setDeleteOnClose(true);
            testContext.tempFileHandle.setDeleteOnClose(true);
            driver.setFileInformation(testSession, testConnection, TEST_DIR + "\\" + TEMP_FILE_NAME, info);
            assertNotNull(testContext.tempFileHandle);
            logger.debug("this close should result in a file being deleted");
            driver.closeFile(testSession, testConnection, testContext.tempFileHandle);
            return null;
        }
    };
    tran.doInTransaction(deleteOnCloseCB, false, true);
    // /**
    // * Delete file directly.
    // */
    // RetryingTransactionCallback<Void> deleteTargetFileCB = new RetryingTransactionCallback<Void>()
    // {
    // 
    // @Override
    // public Void execute() throws Throwable
    // {
    // 
    // driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + TEMP_FILE_NAME);
    // return null;
    // }
    // };
    // tran.doInTransaction(deleteTargetFileCB, false, true);
    RetryingTransactionCallback<Void> moveRenamedTempFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.renameFile(testSession, testConnection, TEST_TEMP_DIR + "\\" + FILE_NAME, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(moveRenamedTempFileCB, false, true);
    RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            assertTrue("node is not versionable", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
            assertEquals("shuffledNode ref is different", shuffledNodeRef, testContext.testNodeRef);
            assertEquals("Unexpected content size", contentService.getReader(shuffledNodeRef, ContentModel.PROP_CONTENT).getSize(), UPDATED_TEXT.length());
            return null;
        }
    };
    tran.doInTransaction(validateCB, false, true);
}
Also used : SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) FileInfo(org.alfresco.jlan.server.filesys.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 34 with DiskSharedDevice

use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.

the class ServerConfigurationBean method processFilesystemsConfig.

/**
 * Process the filesystems configuration
 */
protected void processFilesystemsConfig() {
    // Create the filesystems configuration section
    FilesystemsConfigSection fsysConfig = new FilesystemsConfigSection(this);
    // Access the security configuration section
    SecurityConfigSection secConfig = (SecurityConfigSection) getConfigSection(SecurityConfigSection.SectionName);
    if (this.filesystemContexts != null) {
        for (DeviceContext filesystem : this.filesystemContexts) {
            try {
                // Check the filesystem type and use the appropriate driver
                DiskSharedDevice filesys = null;
                // Create a new filesystem driver instance and register a context for
                // the new filesystem
                ExtendedDiskInterface filesysDriver = getRepoDiskInterface();
                ContentContext filesysContext = (ContentContext) filesystem;
                // Create state cache here and inject
                StandaloneFileStateCache standaloneCache = new StandaloneFileStateCache();
                standaloneCache.initializeCache(new GenericConfigElement(""), this);
                filesysContext.setStateCache(standaloneCache);
                if (filesysContext.hasStateCache()) {
                    // Register the state cache with the reaper thread
                    // has many side effects including initialisation of the cache
                    fsysConfig.addFileStateCache(filesystem.getDeviceName(), filesysContext.getStateCache());
                    // Create the lock manager for the context.
                    FileStateLockManager lockMgr = new FileStateLockManager(filesysContext.getStateCache());
                    filesysContext.setLockManager(lockMgr);
                    filesysContext.setOpLockManager(lockMgr);
                }
                if (!ftpConfigBean.getServerEnabled() && isContentDiskDriver2(filesysDriver)) {
                    ((ContentContext) filesystem).setDisableNodeMonitor(true);
                }
                filesysDriver.registerContext(filesystem);
                // Check if an access control list has been specified
                AccessControlList acls = null;
                AccessControlListBean accessControls = filesysContext.getAccessControlList();
                if (accessControls != null) {
                    // Parse the access control list
                    acls = accessControls.toAccessControlList(secConfig);
                } else if (secConfig.hasGlobalAccessControls()) {
                    // Use the global access control list for this disk share
                    acls = secConfig.getGlobalAccessControls();
                }
                // Create the shared filesystem
                filesys = new DiskSharedDevice(filesystem.getDeviceName(), filesysDriver, filesysContext);
                filesys.setConfiguration(this);
                // Add any access controls to the share
                filesys.setAccessControlList(acls);
                if (filesysContext.getDisableChangeNotifications() == false)
                    filesysContext.enableChangeHandler(true);
                // Start the filesystem
                filesysContext.startFilesystem(filesys);
                // Add the new filesystem
                fsysConfig.addShare(filesys);
            } catch (DeviceContextException ex) {
                throw new AlfrescoRuntimeException("Error creating filesystem " + filesystem.getDeviceName(), ex);
            } catch (InvalidConfigurationException ex) {
                throw new AlfrescoRuntimeException(ex.getMessage(), ex);
            }
        }
    } else {
        // No filesystems defined
        logger.warn("No filesystems defined");
    }
// home folder share mapper could be declared in security config
}
Also used : AccessControlList(org.alfresco.jlan.server.auth.acl.AccessControlList) DeviceContextException(org.alfresco.jlan.server.core.DeviceContextException) SecurityConfigSection(org.alfresco.jlan.server.config.SecurityConfigSection) GenericConfigElement(org.springframework.extensions.config.element.GenericConfigElement) ExtendedDiskInterface(org.alfresco.filesys.alfresco.ExtendedDiskInterface) StandaloneFileStateCache(org.alfresco.jlan.server.filesys.cache.StandaloneFileStateCache) AccessControlListBean(org.alfresco.filesys.config.acl.AccessControlListBean) InvalidConfigurationException(org.alfresco.jlan.server.config.InvalidConfigurationException) FilesystemsConfigSection(org.alfresco.jlan.server.filesys.FilesystemsConfigSection) DeviceContext(org.alfresco.jlan.server.core.DeviceContext) FileStateLockManager(org.alfresco.jlan.server.filesys.cache.FileStateLockManager) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) ContentContext(org.alfresco.filesys.repo.ContentContext) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 35 with DiskSharedDevice

use of org.alfresco.jlan.server.filesys.DiskSharedDevice in project alfresco-repository by Alfresco.

the class ContentDiskDriverTest method testCreateFile.

/**
 * Test Create File
 */
public void testCreateFile() throws Exception {
    logger.debug("testCreatedFile");
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    final SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    final TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    class TestContext {

        NodeRef testNodeRef;
    }
    ;
    final TestContext testContext = new TestContext();
    /**
     * Step 1 : Create a new file in read/write mode and add some content.
     */
    int openAction = FileAction.CreateNotExist;
    final String FILE_NAME = "testCreateFileX.new";
    final String FILE_PATH = "\\" + FILE_NAME;
    FileOpenParams params = new FileOpenParams(FILE_PATH, openAction, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
    final NetworkFile file = driver.createFile(testSession, testConnection, params);
    assertNotNull("file is null", file);
    assertFalse("file is read only, should be read-write", file.isReadOnly());
    assertFalse("file is not closed ", file.isClosed());
    RetryingTransactionCallback<Void> writeStuffCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            byte[] stuff = "Hello World".getBytes();
            driver.writeFile(testSession, testConnection, file, stuff, 0, stuff.length, 0);
            driver.closeFile(testSession, testConnection, file);
            return null;
        }
    };
    tran.doInTransaction(writeStuffCB);
    RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef companyHome = repositoryHelper.getCompanyHome();
            NodeRef newNode = nodeService.getChildByName(companyHome, ContentModel.ASSOC_CONTAINS, FILE_NAME);
            testContext.testNodeRef = newNode;
            assertNotNull("can't find new node", newNode);
            Serializable content = nodeService.getProperty(newNode, ContentModel.PROP_CONTENT);
            assertNotNull("content is null", content);
            return null;
        }
    };
    tran.doInTransaction(validateCB);
    // now validate that the new node is in the correct location and has the correct name
    FileInfo info = driver.getFileInformation(testSession, testConnection, FILE_PATH);
    assertNotNull("info is null", info);
    NodeRef n2 = getNodeForPath(testConnection, FILE_PATH);
    assertEquals("get Node For Path returned different node", testContext.testNodeRef, n2);
    /**
     * Step 2 : Negative Test Attempt to create the same file again
     */
    try {
        driver.createFile(testSession, testConnection, params);
        fail("File exists not detected");
    } catch (FileExistsException fe) {
    // expect to go here
    }
    // Clean up so we could run the test again
    driver.deleteFile(testSession, testConnection, FILE_PATH);
    /**
     * Step 3 : create a file in a new directory in read only mode
     */
    String FILE2_PATH = TEST_ROOT_DOS_PATH + FILE_PATH;
    FileOpenParams dirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, openAction, AccessMode.ReadOnly, FileAttribute.NTDirectory, 0);
    driver.createDirectory(testSession, testConnection, dirParams);
    FileOpenParams file2Params = new FileOpenParams(FILE2_PATH, openAction, AccessMode.ReadOnly, FileAttribute.NTNormal, 0);
    NetworkFile file2 = driver.createFile(testSession, testConnection, file2Params);
    // clean up so we could run the test again
    driver.deleteFile(testSession, testConnection, FILE2_PATH);
}
Also used : Serializable(java.io.Serializable) SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) FileInfo(org.alfresco.jlan.server.filesys.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice) FileExistsException(org.alfresco.jlan.server.filesys.FileExistsException)

Aggregations

DiskSharedDevice (org.alfresco.jlan.server.filesys.DiskSharedDevice)50 SrvSession (org.alfresco.jlan.server.SrvSession)47 ServerConfiguration (org.alfresco.jlan.server.config.ServerConfiguration)47 TreeConnection (org.alfresco.jlan.server.filesys.TreeConnection)47 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)46 NodeRef (org.alfresco.service.cmr.repository.NodeRef)46 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)45 FileOpenParams (org.alfresco.jlan.server.filesys.FileOpenParams)44 NetworkFile (org.alfresco.jlan.server.filesys.NetworkFile)44 IOException (java.io.IOException)31 Serializable (java.io.Serializable)31 QName (org.alfresco.service.namespace.QName)26 DeviceContextException (org.alfresco.jlan.server.core.DeviceContextException)25 FileExistsException (org.alfresco.jlan.server.filesys.FileExistsException)25 FileNotFoundException (java.io.FileNotFoundException)24 AccessDeniedException (org.alfresco.jlan.server.filesys.AccessDeniedException)24 PermissionDeniedException (org.alfresco.jlan.server.filesys.PermissionDeniedException)24 ContentData (org.alfresco.service.cmr.repository.ContentData)14 ClassPathResource (org.springframework.core.io.ClassPathResource)12 InputStream (java.io.InputStream)7