Search in sources :

Example 11 with NetworkFile

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

the class ContentDiskDriverTest method testZeroByteRules.

// Scenario frame maker save
/**
 * Test that rules fire on zero byte long files.
 * In this case check that a new file gets the versionable
 * aspect added.
 */
public void testZeroByteRules() throws Exception {
    logger.debug("testZeroByteRules");
    final String FILE_NAME_ZERO = "Zero.docx";
    final String FILE_NAME_NON_ZERO = "NonZero.docx";
    class TestContext {

        NodeRef testDirNodeRef;

        NodeRef testZeroNodeRef;

        NodeRef testNonZeroNodeRef;

        NetworkFile firstFileHandle;

        NetworkFile secondFileHandle;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testZeroByteRules";
    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();
    /**
     * Clean up just in case garbage is left from a previous run
     */
    RetryingTransactionCallback<Void> deleteGarbageDirCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteDirectory(testSession, testConnection, TEST_DIR);
            return null;
        }
    };
    try {
        tran.doInTransaction(deleteGarbageDirCB);
    } catch (Exception e) {
    // expect to go here
    }
    logger.debug("create Test directory" + TEST_DIR);
    RetryingTransactionCallback<Void> createTestDirCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the test directory we are going to use
             */
            FileOpenParams createRootDirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 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);
            testContext.testDirNodeRef = getNodeForPath(testConnection, TEST_DIR);
            assertNotNull("testDirNodeRef is null", testContext.testDirNodeRef);
            return null;
        }
    };
    tran.doInTransaction(createTestDirCB);
    logger.debug("Create rule on test dir");
    RetryingTransactionCallback<Void> createRuleCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            Rule rule = new Rule();
            rule.setRuleType(RuleType.INBOUND);
            rule.applyToChildren(true);
            rule.setRuleDisabled(false);
            rule.setTitle("Make Versionable");
            rule.setDescription("ContentDiskDriverTest Test Zero Byte files");
            Map<String, Serializable> props = new HashMap<String, Serializable>(1);
            props.put("aspect-name", ContentModel.ASPECT_VERSIONABLE);
            Action addVersionable = actionService.createAction("add-features", props);
            ActionCondition noCondition1 = actionService.createActionCondition(NoConditionEvaluator.NAME);
            addVersionable.addActionCondition(noCondition1);
            ActionCondition noCondition2 = actionService.createActionCondition(NoConditionEvaluator.NAME);
            CompositeAction compAction = actionService.createCompositeAction();
            compAction.setTitle("Make Versionablea");
            compAction.setDescription("Add Aspect - Versionable");
            compAction.addAction(addVersionable);
            compAction.addActionCondition(noCondition2);
            rule.setAction(compAction);
            ruleService.saveRule(testContext.testDirNodeRef, rule);
            logger.debug("add aspect versionable rule created");
            return null;
        }
    };
    tran.doInTransaction(createRuleCB, false, true);
    /**
     * Create a file in the test directory
     */
    logger.debug("create test file in test directory");
    RetryingTransactionCallback<Void> createFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            /**
             * Create the zero byte file we are going to use to test
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME_ZERO, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.firstFileHandle);
            testContext.testZeroNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME_ZERO);
            assertNotNull("testContext.testNodeRef is null", testContext.testZeroNodeRef);
            /**
             * Create the non zero byte file we are going to use to test
             */
            FileOpenParams createFileParams2 = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME_NON_ZERO, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.secondFileHandle = driver.createFile(testSession, testConnection, createFileParams2);
            assertNotNull(testContext.secondFileHandle);
            testContext.testNonZeroNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME_NON_ZERO);
            assertNotNull("testContext.testNodeRef is null", testContext.testNonZeroNodeRef);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    logger.debug("step b: close the file with zero byte content");
    /**
     * Write ContentDiskDriverTest1.docx to the test file,
     */
    RetryingTransactionCallback<Void> writeFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            logger.debug("close the file, firstFileHandle");
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            // Write hello world into the second file
            byte[] stuff = "Hello World".getBytes();
            driver.writeFile(testSession, testConnection, testContext.secondFileHandle, stuff, 0, stuff.length, 0);
            logger.debug("close the second non zero file, secondFileHandle");
            driver.closeFile(testSession, testConnection, testContext.secondFileHandle);
            return null;
        }
    };
    tran.doInTransaction(writeFileCB, false, true);
    logger.debug("Step c: validate versioble aspect has been applied.");
    /**
     * c: check zero byte file has the versionable aspect.
     */
    RetryingTransactionCallback<Void> validateFirstExtractionCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            assertTrue("versionable aspect not applied to non zero file.", nodeService.hasAspect(testContext.testNonZeroNodeRef, ContentModel.ASPECT_VERSIONABLE));
            assertTrue("versionable aspect not applied to zero byte file.", nodeService.hasAspect(testContext.testZeroNodeRef, ContentModel.ASPECT_VERSIONABLE));
            return null;
        }
    };
    tran.doInTransaction(validateFirstExtractionCB, false, true);
}
Also used : Serializable(java.io.Serializable) CompositeAction(org.alfresco.service.cmr.action.CompositeAction) FileAction(org.alfresco.jlan.server.filesys.FileAction) Action(org.alfresco.service.cmr.action.Action) SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) HashMap(java.util.HashMap) 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) ActionCondition(org.alfresco.service.cmr.action.ActionCondition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) CompositeAction(org.alfresco.service.cmr.action.CompositeAction) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) Rule(org.alfresco.service.cmr.rule.Rule) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 12 with NetworkFile

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

the class ContentDiskDriverTest method testScenarioMountainLionWord2011.

// testMacDragAndDrop
/**
 * Mountain Lion 2011 Word
 * a) Create new file (Word Work File D2.tmp)
 * (Actually in real life its renamed from a temp directory.
 * c) Existing file rename out of the way.   (Word Work File L_5.tmp)
 * d) New file rename into place. (MacWord1.docx)
 * e) Old file deleted
 */
public void testScenarioMountainLionWord2011() throws Exception {
    logger.debug("testScenarioMountainLionWord2011");
    final String FILE_NAME = "MacWord1.docx";
    final String FILE_OLD_TEMP = "Word Work File L_5.tmp";
    final String FILE_NEW_TEMP = "Word Work File D_2.tmp";
    class TestContext {

        NetworkFile firstFileHandle;

        String mimetype;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testScenarioMountainLionWord2011";
    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();
    /**
     * Clean up just in case garbage is left from a previous run
     */
    RetryingTransactionCallback<Void> deleteGarbageFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    try {
        tran.doInTransaction(deleteGarbageFileCB);
    } catch (Exception e) {
    // expect to go here
    }
    logger.debug("a) create new file");
    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_DOS_PATH, 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 test
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.firstFileHandle);
            ClassPathResource fileResource = new ClassPathResource("filesys/ContentDiskDriverTest3.doc");
            assertNotNull("unable to find test resource filesys/ContentDiskDriverTest3.doc", fileResource);
            writeResourceToNetworkFile(fileResource, testContext.firstFileHandle);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            nodeService.addAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    /**
     * b) Save the new file
     * Write ContentDiskDriverTest3.doc,
     */
    logger.debug("b) move new file into place");
    RetryingTransactionCallback<Void> writeFileCB = 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.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            ClassPathResource fileResource = new ClassPathResource("filesys/ContentDiskDriverTest3.doc");
            assertNotNull("unable to find test resource filesys/ContentDiskDriverTest3.doc", fileResource);
            writeResourceToNetworkFile(fileResource, testContext.firstFileHandle);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            Map<QName, Serializable> props = nodeService.getProperties(file1NodeRef);
            ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
            // assertNotNull("data is null", data);
            // assertEquals("size is wrong", 166912, data.getSize());
            testContext.mimetype = data.getMimetype();
            return null;
        }
    };
    tran.doInTransaction(writeFileCB, false, true);
    /**
     * c) rename the old file
     */
    logger.debug("c) rename 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
     */
    logger.debug("d) move new file into place");
    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);
    /**
     * d) Delete the old file
     */
    logger.debug("d) delete the old file");
    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);
    logger.debug("e) validate results");
    /**
     * Now validate everything is correct
     */
    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);
            ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
            // assertNotNull("data is null", data);
            // assertEquals("size is wrong", 123904, data.getSize());
            NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            assertTrue("file has lost versionable aspect", nodeService.hasAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE));
            assertEquals("mimeType is wrong", testContext.mimetype, data.getMimetype());
            return null;
        }
    };
    tran.doInTransaction(validateCB, true, 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) 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) ClassPathResource(org.springframework.core.io.ClassPathResource) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentData(org.alfresco.service.cmr.repository.ContentData) 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 13 with NetworkFile

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

the class ContentDiskDriverTest method testScenarioMSPowerpoint2011MacSaveShuffle.

// testScenarioLionTextEdit
/**
 * Simulates a Save from Powerpoint 2011 Mac
 * 0. FileA.pptx already exists.
 * 1. Create new document FileA1.pptx
 * 2. Delete FileA.pptx
 * 3. Rename FileA1.pptx to FileA.pptx
 */
public void testScenarioMSPowerpoint2011MacSaveShuffle() throws Exception {
    logger.debug("testScenarioMSPowerpoint2011MacSaveShuffle(");
    final String FILE_NAME = "FileA.pptx";
    final String FILE_NEW_TEMP = "FileA1.pptx";
    class TestContext {

        NetworkFile firstFileHandle;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testScenarioMSPowerpoint2011MacSaveShuffle";
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    final SrvSession testSession = new TestSrvSession(666, testServer, "cifs", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    final TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    /**
     * Clean up just in case garbage is left from a previous run
     */
    RetryingTransactionCallback<Void> deleteGarbageFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    try {
        logger.debug("expect to get exception - cleaning garbage");
        tran.doInTransaction(deleteGarbageFileCB);
    } catch (Exception e) {
    // expect to go here
    }
    logger.debug("0) create new file");
    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_DOS_PATH, 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 (FileA.pptx)
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.firstFileHandle);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            nodeService.addAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    /**
     * b) Save the new file
     * Write ContentDiskDriverTest3.doc to the test file,
     */
    logger.debug("b) write some content");
    RetryingTransactionCallback<Void> writeFileCB = 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.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            ClassPathResource fileResource = new ClassPathResource("filesys/ContentDiskDriverTest3.doc");
            assertNotNull("unable to find test resource filesys/ContentDiskDriverTest3.doc", fileResource);
            byte[] buffer = new byte[1000];
            InputStream is = fileResource.getInputStream();
            try {
                long offset = 0;
                int i = is.read(buffer, 0, buffer.length);
                while (i > 0) {
                    testContext.firstFileHandle.writeFile(buffer, i, 0, offset);
                    offset += i;
                    i = is.read(buffer, 0, buffer.length);
                }
            } finally {
                is.close();
            }
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            return null;
        }
    };
    tran.doInTransaction(writeFileCB, false, true);
    /**
     * c) delete the old file
     */
    logger.debug("c) delete old file");
    RetryingTransactionCallback<Void> renameOldFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    tran.doInTransaction(renameOldFileCB, false, true);
    /**
     * d) Move the new file into place, stuff should get shuffled
     */
    logger.debug("d) rename new file into place");
    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);
    logger.debug("e) validate results");
    /**
     * Now validate everything is correct
     */
    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);
            ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
            assertNotNull("data is null", data);
            assertEquals("size is wrong", 26112, data.getSize());
            assertEquals("mimeType is wrong", "application/msword", data.getMimetype());
            assertTrue("versionable aspect missing", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
            assertTrue("hidden aspect still applied", !nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_HIDDEN));
            assertTrue("temporary aspect still applied", !nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_TEMPORARY));
            return null;
        }
    };
    tran.doInTransaction(validateCB, true, true);
}
Also used : Serializable(java.io.Serializable) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentData(org.alfresco.service.cmr.repository.ContentData) NetworkFile(org.alfresco.jlan.server.filesys.NetworkFile) SrvSession(org.alfresco.jlan.server.SrvSession) InputStream(java.io.InputStream) QName(org.alfresco.service.namespace.QName) 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) ClassPathResource(org.springframework.core.io.ClassPathResource) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) TreeConnection(org.alfresco.jlan.server.filesys.TreeConnection) DiskSharedDevice(org.alfresco.jlan.server.filesys.DiskSharedDevice)

Example 14 with NetworkFile

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

the class ContentDiskDriverTest method testScenarioRenameVersionableFile.

// testRenameFile
/**
 * Unit test of rename versionable file
 */
public void testScenarioRenameVersionableFile() throws Exception {
    logger.debug("testScenarioRenameVersionableFile");
    ServerConfiguration scfg = new ServerConfiguration("testServer");
    TestServer testServer = new TestServer("testServer", scfg);
    SrvSession testSession = new TestSrvSession(666, testServer, "test", "remoteName");
    DiskSharedDevice share = getDiskSharedDevice();
    final TreeConnection testConnection = testServer.getTreeConnection(share);
    final RetryingTransactionHelper tran = transactionService.getRetryingTransactionHelper();
    final String FILE_PATH1 = TEST_ROOT_DOS_PATH + "\\SourceFile1.new";
    final String FILE_PATH2 = TEST_ROOT_DOS_PATH + "\\SourceFile2.new";
    class TestContext {
    }
    ;
    final TestContext testContext = new TestContext();
    FileOpenParams dirParams = new FileOpenParams(TEST_ROOT_DOS_PATH, 0, AccessMode.ReadOnly, FileAttribute.NTDirectory, 0);
    driver.createDirectory(testSession, testConnection, dirParams);
    FileOpenParams params1 = new FileOpenParams(FILE_PATH1, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
    NetworkFile file1 = driver.createFile(testSession, testConnection, params1);
    /**
     * Make Node 1 versionable
     */
    final String LAST_NAME = "Bloggs";
    RetryingTransactionCallback<Void> makeVersionableCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef file1NodeRef = getNodeForPath(testConnection, FILE_PATH1);
            nodeService.addAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            ContentWriter contentWriter2 = contentService.getWriter(file1NodeRef, ContentModel.PROP_CONTENT, true);
            contentWriter2.putContent("test rename versionable");
            nodeService.setProperty(file1NodeRef, ContentModel.PROP_LASTNAME, LAST_NAME);
            nodeService.setProperty(file1NodeRef, TransferModel.PROP_ENDPOINT_PROTOCOL, "http");
            return null;
        }
    };
    tran.doInTransaction(makeVersionableCB, false, true);
    /**
     * Step 1: Successfully rename a versionable file - check the name, props and content.
     * TODO Check primary assoc, peer assocs, child assocs, modified date, created date, nodeid, permissions.
     */
    driver.renameFile(testSession, testConnection, FILE_PATH1, FILE_PATH2);
    RetryingTransactionCallback<Void> validateVersionableCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef file2NodeRef = getNodeForPath(testConnection, FILE_PATH2);
            assertNotNull("file2 node ref is null", file2NodeRef);
            // assertEquals(nodeService.getProperty(file2NodeRef, ContentModel.PROP_LASTNAME), LAST_NAME);
            assertTrue("does not have versionable aspect", nodeService.hasAspect(file2NodeRef, ContentModel.ASPECT_VERSIONABLE));
            assertTrue("sample property is null", nodeService.getProperty(file2NodeRef, TransferModel.PROP_ENDPOINT_PROTOCOL) != null);
            return null;
        }
    };
    tran.doInTransaction(validateVersionableCB, false, true);
}
Also used : SrvSession(org.alfresco.jlan.server.SrvSession) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) ServerConfiguration(org.alfresco.jlan.server.config.ServerConfiguration) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) 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 15 with NetworkFile

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

the class ContentDiskDriverTest method testWindows7Explorer.

// testGedit
/**
 * Windows7 Explorer update
 * 0) Existing file mark.jpg
 * a) Create new file (~ark.tmp)
 * b) Existing file rename out of the way.   (mark.jpg~RF5bb356.TMP)
 * c) New file rename into place. (~ark.tmp - mark.jpg)
 * d) Old file opened attributes only
 * e) set delete on close
 * f) close
 */
public void testWindows7Explorer() throws Exception {
    logger.debug("testWindows7Explorer");
    final String FILE_NAME = "mark.jpg";
    final String FILE_OLD_TEMP = "mark.jpg~RF5bb356.TMP";
    final String FILE_NEW_TEMP = "~ark.tmp";
    class TestContext {

        NodeRef testNodeRef;

        NetworkFile firstFileHandle;

        NetworkFile secondFileHandle;
    }
    ;
    final TestContext testContext = new TestContext();
    final String TEST_DIR = TEST_ROOT_DOS_PATH + "\\testWindows7Explorer";
    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();
    /**
     * Clean up just in case garbage is left from a previous run
     */
    RetryingTransactionCallback<Void> deleteGarbageFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            driver.deleteFile(testSession, testConnection, TEST_DIR + "\\" + FILE_NAME);
            return null;
        }
    };
    try {
        tran.doInTransaction(deleteGarbageFileCB);
    } catch (Exception e) {
    // expect to go here
    }
    logger.debug("0) create new file");
    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_DOS_PATH, 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 test
             */
            FileOpenParams createFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_NAME, 0, AccessMode.ReadWrite, FileAttribute.NTNormal, 0);
            testContext.firstFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            assertNotNull(testContext.firstFileHandle);
            ClassPathResource fileResource = new ClassPathResource("filesys/ContentDiskDriverTestMark.jpg");
            assertNotNull("unable to find test resource filesys/ContentDiskDriverTestMark.jpg", fileResource);
            writeResourceToNetworkFile(fileResource, testContext.firstFileHandle);
            driver.closeFile(testSession, testConnection, testContext.firstFileHandle);
            NodeRef file1NodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            testContext.testNodeRef = file1NodeRef;
            nodeService.addAspect(file1NodeRef, ContentModel.ASPECT_VERSIONABLE, null);
            return null;
        }
    };
    tran.doInTransaction(createFileCB, false, true);
    /**
     * a) Save the new file
     */
    logger.debug("a) save new file");
    RetryingTransactionCallback<Void> writeFileCB = 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.secondFileHandle = driver.createFile(testSession, testConnection, createFileParams);
            ClassPathResource fileResource = new ClassPathResource("filesys/ContentDiskDriverTestMark2.jpg");
            assertNotNull("unable to find test resource filesys/ContentDiskDriverTestMark2.jpg", fileResource);
            writeResourceToNetworkFile(fileResource, testContext.secondFileHandle);
            driver.closeFile(testSession, testConnection, testContext.secondFileHandle);
            return null;
        }
    };
    tran.doInTransaction(writeFileCB, false, true);
    /**
     * b) rename the old file
     */
    logger.debug("c) rename 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);
    /**
     * c) Move the new file into place, stuff should get shuffled
     */
    logger.debug("d) move new file into place");
    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);
    /**
     * d) Delete the old file
     */
    logger.debug("d) delete on close the old file");
    RetryingTransactionCallback<Void> deleteOldFileCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            FileOpenParams openFileParams = new FileOpenParams(TEST_DIR + "\\" + FILE_OLD_TEMP, 0, AccessMode.NTReadAttributesOnly, FileAttribute.NTNormal, 0);
            testContext.secondFileHandle = driver.openFile(testSession, testConnection, openFileParams);
            assertNotNull(testContext.secondFileHandle);
            FileInfo info = new FileInfo();
            info.setFileInformationFlags(FileInfo.SetDeleteOnClose);
            driver.setFileInformation(testSession, testConnection, TEST_DIR + "\\" + FILE_OLD_TEMP, info);
            testContext.secondFileHandle.setDeleteOnClose(true);
            driver.closeFile(testSession, testConnection, testContext.secondFileHandle);
            return null;
        }
    };
    tran.doInTransaction(deleteOldFileCB, false, true);
    logger.debug("e) validate results");
    /**
     * Now validate everything is correct
     */
    RetryingTransactionCallback<Void> validateCB = new RetryingTransactionCallback<Void>() {

        @Override
        public Void execute() throws Throwable {
            NodeRef shuffledNodeRef = getNodeForPath(testConnection, TEST_DIR + "\\" + FILE_NAME);
            assertTrue("file has lost versionable aspect", nodeService.hasAspect(shuffledNodeRef, ContentModel.ASPECT_VERSIONABLE));
            assertEquals("node ref has changed", shuffledNodeRef, testContext.testNodeRef);
            Map<QName, Serializable> props = nodeService.getProperties(shuffledNodeRef);
            ContentData data = (ContentData) props.get(ContentModel.PROP_CONTENT);
            assertNotNull("data is null", data);
            assertEquals("size is wrong", 10407, data.getSize());
            assertEquals("mimeType is wrong", "image/jpeg", data.getMimetype());
            return null;
        }
    };
    tran.doInTransaction(validateCB, true, 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) 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) ClassPathResource(org.springframework.core.io.ClassPathResource) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileOpenParams(org.alfresco.jlan.server.filesys.FileOpenParams) ContentData(org.alfresco.service.cmr.repository.ContentData) 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)

Aggregations

NetworkFile (org.alfresco.jlan.server.filesys.NetworkFile)54 NodeRef (org.alfresco.service.cmr.repository.NodeRef)48 SrvSession (org.alfresco.jlan.server.SrvSession)44 ServerConfiguration (org.alfresco.jlan.server.config.ServerConfiguration)44 DiskSharedDevice (org.alfresco.jlan.server.filesys.DiskSharedDevice)44 FileOpenParams (org.alfresco.jlan.server.filesys.FileOpenParams)44 TreeConnection (org.alfresco.jlan.server.filesys.TreeConnection)44 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)44 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)44 IOException (java.io.IOException)36 Serializable (java.io.Serializable)33 AccessDeniedException (org.alfresco.jlan.server.filesys.AccessDeniedException)29 QName (org.alfresco.service.namespace.QName)27 FileNotFoundException (java.io.FileNotFoundException)24 FileExistsException (org.alfresco.jlan.server.filesys.FileExistsException)24 PermissionDeniedException (org.alfresco.jlan.server.filesys.PermissionDeniedException)24 DeviceContextException (org.alfresco.jlan.server.core.DeviceContextException)23 ContentData (org.alfresco.service.cmr.repository.ContentData)14 ClassPathResource (org.springframework.core.io.ClassPathResource)12 InputStream (java.io.InputStream)7