Search in sources :

Example 26 with FileNotFoundException

use of org.alfresco.service.cmr.model.FileNotFoundException in project records-management by Alfresco.

the class RM2190Test method testUploadDocumentsSimultaneouslyWithRules.

public void testUploadDocumentsSimultaneouslyWithRules() {
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() {
            rootFolder = fileFolderService.create(documentLibrary, generate(), TYPE_FOLDER).getNodeRef();
            Action createAction = actionService.createAction(CreateRecordAction.NAME);
            createAction.setParameterValue(CreateRecordAction.PARAM_FILE_PLAN, filePlan);
            Rule declareRule = new Rule();
            declareRule.setRuleType(INBOUND);
            declareRule.setTitle(generate());
            declareRule.setAction(createAction);
            declareRule.setExecuteAsynchronously(true);
            declareRule.applyToChildren(true);
            ruleService.saveRule(rootFolder, declareRule);
            folder1 = fileFolderService.create(rootFolder, generate(), TYPE_FOLDER).getNodeRef();
            folder2 = fileFolderService.create(rootFolder, generate(), TYPE_FOLDER).getNodeRef();
            Action fileAction = actionService.createAction(FileToAction.NAME);
            fileAction.setParameterValue(FileToAction.PARAM_PATH, PATH);
            fileAction.setParameterValue(FileToAction.PARAM_CREATE_RECORD_PATH, true);
            Rule fileRule = new Rule();
            fileRule.setRuleType(INBOUND);
            fileRule.setTitle(generate());
            fileRule.setAction(fileAction);
            fileRule.setExecuteAsynchronously(true);
            ruleService.saveRule(unfiledContainer, fileRule);
            return null;
        }

        @Override
        public void test(Void result) throws Exception {
            assertFalse(ruleService.getRules(rootFolder).isEmpty());
            assertFalse(ruleService.getRules(unfiledContainer).isEmpty());
        }
    });
    doTestInTransaction(new Test<Void>() {

        @Override
        public Void run() throws FileNotFoundException, InterruptedException {
            Thread thread1 = new Thread() {

                public void run() {
                    List<NodeRef> files = addFilesToFolder(folder1);
                    waitForFilesToBeDeclared(files);
                }
            };
            Thread thread2 = new Thread() {

                public void run() {
                    List<NodeRef> files = addFilesToFolder(folder2);
                    waitForFilesToBeDeclared(files);
                }
            };
            thread1.start();
            thread2.start();
            thread1.join(300000);
            thread2.join(300000);
            return null;
        }

        @Override
        public void test(Void result) throws Exception {
            FileInfo category = fileFolderService.resolveNamePath(filePlan, asList(tokenizeToStringArray(PATH, "/", false, true)));
            assertEquals(NUMBER_IN_BATCH * 2, nodeService.getChildAssocs(category.getNodeRef()).size());
        }
    });
}
Also used : FileToAction(org.alfresco.module.org_alfresco_module_rm.action.impl.FileToAction) CreateRecordAction(org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction) Action(org.alfresco.service.cmr.action.Action) FileInfo(org.alfresco.service.cmr.model.FileInfo) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Rule(org.alfresco.service.cmr.rule.Rule) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException)

Example 27 with FileNotFoundException

use of org.alfresco.service.cmr.model.FileNotFoundException in project records-management by Alfresco.

the class CopyMoveLinkFileToBaseAction method executeImpl.

/**
 * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
 */
@Override
protected synchronized void executeImpl(final Action action, final NodeRef actionedUponNodeRef) {
    String actionName = action.getActionDefinitionName();
    if (isOkToProceedWithAction(actionedUponNodeRef, actionName)) {
        QName actionedUponType = getNodeService().getType(actionedUponNodeRef);
        boolean targetIsUnfiledRecords;
        if (ACTION_FILETO.equals(action.getActionDefinitionName())) {
            targetIsUnfiledRecords = false;
        } else {
            targetIsUnfiledRecords = (getDictionaryService().isSubClass(actionedUponType, ContentModel.TYPE_CONTENT) && !getRecordService().isFiled(actionedUponNodeRef)) || TYPE_UNFILED_RECORD_FOLDER.equals(actionedUponType);
        }
        // first look to see if the destination record folder has been specified
        NodeRef recordFolder = (NodeRef) action.getParameterValue(PARAM_DESTINATION_RECORD_FOLDER);
        if (recordFolder == null) {
            recordFolder = createOrResolvePath(action, actionedUponNodeRef, targetIsUnfiledRecords);
        }
        // now we have the reference to the target folder we can do some final checks to see if the action is valid
        validateActionPostPathResolution(actionedUponNodeRef, recordFolder, actionName, targetIsUnfiledRecords);
        final NodeRef finalRecordFolder = recordFolder;
        AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {

            @Override
            public Void doWork() {
                try {
                    if (getMode() == CopyMoveLinkFileToActionMode.MOVE) {
                        fileFolderService.move(actionedUponNodeRef, finalRecordFolder, null);
                    } else if (getMode() == CopyMoveLinkFileToActionMode.COPY) {
                        fileFolderService.copy(actionedUponNodeRef, finalRecordFolder, null);
                    } else if (getMode() == CopyMoveLinkFileToActionMode.LINK) {
                        getRecordService().link(actionedUponNodeRef, finalRecordFolder);
                    }
                } catch (FileNotFoundException fileNotFound) {
                    throw new AlfrescoRuntimeException("Unable to execute file to action, because the " + (mode == CopyMoveLinkFileToActionMode.MOVE ? "move" : "copy") + " operation failed.", fileNotFound);
                }
                return null;
            }
        });
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QName(org.alfresco.service.namespace.QName) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 28 with FileNotFoundException

use of org.alfresco.service.cmr.model.FileNotFoundException in project records-management by Alfresco.

the class RM978Test method testCopyDocumentInFolderInRmSite.

public void testCopyDocumentInFolderInRmSite() {
    doBehaviourDrivenTest(new BehaviourDrivenTest(AlfrescoRuntimeException.class, user) {

        private NodeRef folder1;

        private NodeRef document1;

        private String document1Name = GUID.generate();

        private NodeRef rmCategory;

        private NodeRef rmFolder;

        public void given() {
            folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
            document1 = fileFolderService.create(folder1, document1Name, ContentModel.TYPE_CONTENT).getNodeRef();
            runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    rmCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
                    rmFolder = recordFolderService.createRecordFolder(rmCategory, GUID.generate());
                    return null;
                }
            }, getAdminUserName());
        }

        public void when() throws FileExistsException, FileNotFoundException {
            runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    filePlanPermissionService.setPermission(rmFolder, user, RMPermissionModel.FILING);
                    return null;
                }
            }, getAdminUserName());
            fileFolderService.copy(document1, rmFolder, null);
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Example 29 with FileNotFoundException

use of org.alfresco.service.cmr.model.FileNotFoundException in project records-management by Alfresco.

the class RM978Test method testMoveFolderInFolderInRmSite.

public void testMoveFolderInFolderInRmSite() {
    doBehaviourDrivenTest(new BehaviourDrivenTest(AlfrescoRuntimeException.class, user) {

        private NodeRef folder1;

        private NodeRef rmCategory;

        private NodeRef rmFolder;

        public void given() {
            folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
            runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    rmCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
                    rmFolder = recordFolderService.createRecordFolder(rmCategory, GUID.generate());
                    return null;
                }
            }, getAdminUserName());
        }

        public void when() throws FileExistsException, FileNotFoundException {
            fileFolderService.move(folder1, rmFolder, GUID.generate());
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Example 30 with FileNotFoundException

use of org.alfresco.service.cmr.model.FileNotFoundException in project records-management by Alfresco.

the class RM978Test method testMoveDocumentInFolderInRmSite.

public void testMoveDocumentInFolderInRmSite() {
    doBehaviourDrivenTest(new BehaviourDrivenTest(user) {

        private NodeRef folder1;

        private NodeRef document1;

        private String document1Name = GUID.generate();

        private NodeRef rmCategory;

        private NodeRef rmFolder;

        public void given() {
            folder1 = fileFolderService.create(documentLibrary, GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
            document1 = fileFolderService.create(folder1, document1Name, ContentModel.TYPE_CONTENT).getNodeRef();
            runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    rmCategory = filePlanService.createRecordCategory(filePlan, GUID.generate());
                    rmFolder = recordFolderService.createRecordFolder(rmCategory, GUID.generate());
                    return null;
                }
            }, getAdminUserName());
        }

        public void when() throws FileExistsException, FileNotFoundException {
            runAs(new RunAsWork<Void>() {

                public Void doWork() throws Exception {
                    filePlanPermissionService.setPermission(rmFolder, user, RMPermissionModel.FILING);
                    return null;
                }
            }, getAdminUserName());
            fileFolderService.move(document1, rmFolder, null);
        }

        public void then() {
            List<ChildAssociationRef> folder1ChildAssocs = nodeService.getChildAssocs(folder1);
            assertEquals(0, folder1ChildAssocs.size());
            List<ChildAssociationRef> rmFolderChildAssocs = nodeService.getChildAssocs(rmFolder);
            assertEquals(1, rmFolderChildAssocs.size());
            NodeRef movedDocument = rmFolderChildAssocs.iterator().next().getChildRef();
            String recordIdentifier = (String) nodeService.getProperty(movedDocument, RecordsManagementModel.PROP_IDENTIFIER);
            assertNotNull(recordIdentifier);
            String movedDocumentName = (String) nodeService.getProperty(movedDocument, ContentModel.PROP_NAME);
            assertEquals(document1Name + " (" + recordIdentifier + ")", movedDocumentName);
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) FileExistsException(org.alfresco.service.cmr.model.FileExistsException)

Aggregations

FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)31 NodeRef (org.alfresco.service.cmr.repository.NodeRef)23 FileInfo (org.alfresco.service.cmr.model.FileInfo)22 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)7 FileExistsException (org.alfresco.service.cmr.model.FileExistsException)6 ArrayList (java.util.ArrayList)5 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)5 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)5 QName (org.alfresco.service.namespace.QName)4 HashMap (java.util.HashMap)3 List (java.util.List)3 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)3 WebDavService (org.alfresco.service.cmr.webdav.WebDavService)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 StringTokenizer (java.util.StringTokenizer)2 TimerTask (java.util.TimerTask)2 FileContentReader (org.alfresco.repo.content.filestore.FileContentReader)2