Search in sources :

Example 81 with FileInfo

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

the class RecordFolderChildrenRelation method readAll.

@Override
@WebApiDescription(title = "Return a paged list of records for the record folder identified by 'recordFolderId'")
public CollectionWithPagingInfo<Record> readAll(String recordFolderId, Parameters parameters) {
    checkNotBlank("recordFolderId", recordFolderId);
    mandatory("parameters", parameters);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(recordFolderId, RecordsManagementModel.TYPE_RECORD_FOLDER);
    // list record folders
    // FIXME searchParam
    Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesForUnfiledEndpoint(parameters, null);
    final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef, null, searchTypeQNames, null, apiUtils.getSortProperties(parameters), null, Util.getPagingRequest(parameters.getPaging()));
    final List<FileInfo> page = pagingResults.getPage();
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    List<Record> nodes = new AbstractList<Record>() {

        @Override
        public Record get(int index) {
            FileInfo info = page.get(index);
            return nodesModelFactory.createRecord(info, parameters, mapUserInfo, true);
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    RecordFolder sourceEntity = null;
    if (parameters.includeSource()) {
        FileInfo info = fileFolderService.getFileInfo(parentNodeRef);
        sourceEntity = nodesModelFactory.createRecordFolder(info, parameters, mapUserInfo, true);
    }
    return CollectionWithPagingInfo.asPaged(parameters.getPaging(), nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity);
}
Also used : AbstractList(java.util.AbstractList) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) UserInfo(org.alfresco.rest.api.model.UserInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RecordFolder(org.alfresco.rm.rest.api.model.RecordFolder) Record(org.alfresco.rm.rest.api.model.Record) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 82 with FileInfo

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

the class RecordFolderChildrenRelation method create.

@Override
@WebApiDescription(title = "Create one (or more) records as children of a record folder identified by 'recordFolderId'")
public List<Record> create(String recordFolderId, List<Record> nodeInfos, Parameters parameters) {
    checkNotBlank("recordFolderId", recordFolderId);
    mandatory("nodeInfos", nodeInfos);
    mandatory("parameters", parameters);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(recordFolderId, RecordsManagementModel.TYPE_RECORD_FOLDER);
    RetryingTransactionCallback<List<NodeRef>> callback = new RetryingTransactionCallback<List<NodeRef>>() {

        public List<NodeRef> execute() {
            List<NodeRef> createdNodes = new LinkedList<>();
            for (Record nodeInfo : nodeInfos) {
                NodeRef newNodeRef = apiUtils.createRMNode(parentNodeRef, nodeInfo, parameters);
                createdNodes.add(newNodeRef);
            }
            return createdNodes;
        }
    };
    List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    // Get the nodes info
    List<Record> result = new LinkedList<>();
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    for (NodeRef newNodeRef : createdNodes) {
        FileInfo info = fileFolderService.getFileInfo(newNodeRef);
        apiUtils.postActivity(info, parentNodeRef, ActivityType.FILE_ADDED);
        result.add(nodesModelFactory.createRecord(info, parameters, mapUserInfo, false));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) UserInfo(org.alfresco.rest.api.model.UserInfo) LinkedList(java.util.LinkedList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) AbstractList(java.util.AbstractList) LinkedList(java.util.LinkedList) List(java.util.List) Record(org.alfresco.rm.rest.api.model.Record) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 83 with FileInfo

use of org.alfresco.service.cmr.model.FileInfo 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 84 with FileInfo

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

the class RM1027Test method testCopyingAFolderWithADispositionSchedule.

public void testCopyingAFolderWithADispositionSchedule() throws Exception {
    final NodeRef recordFolder = doTestInTransaction(new Test<NodeRef>() {

        @Override
        public NodeRef run() {
            // create a folder
            NodeRef recordFolder = recordFolderService.createRecordFolder(rmContainer, "My Closed Record Folder");
            // show that the default disposition schedule has been applied
            assertTrue(nodeService.hasAspect(recordFolder, ASPECT_DISPOSITION_LIFECYCLE));
            return recordFolder;
        }
    });
    doTestInTransaction(new Test<NodeRef>() {

        @Override
        public NodeRef run() throws Exception {
            // create a destination for the copy
            NodeRef destination = filePlanService.createRecordCategory(filePlan, "Copy Destination");
            // try and copy the closed record folder
            FileInfo copyInfo = fileFolderService.copy(recordFolder, destination, null);
            return copyInfo.getNodeRef();
        }

        @Override
        public void test(NodeRef copy) throws Exception {
            assertNotNull(copy);
            assertNotNull(nodeService.getProperty(copy, PROP_IDENTIFIER));
            assertFalse(nodeService.hasAspect(copy, ASPECT_DISPOSITION_LIFECYCLE));
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo)

Example 85 with FileInfo

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

the class FilePlanChildrenRelation method create.

@Override
@WebApiDescription(title = "Create one (or more) record categories as children of container identified by 'filePlanId'")
public List<RecordCategory> create(String filePlanId, List<RecordCategory> nodeInfos, Parameters parameters) {
    checkNotBlank("filePlanId", filePlanId);
    mandatory("nodeInfos", nodeInfos);
    mandatory("parameters", parameters);
    QName filePlanType = apiUtils.getFilePlanType();
    if (// rm site not created
    filePlanType == null) {
        throw new EntityNotFoundException(filePlanId);
    }
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(filePlanId, filePlanType);
    RetryingTransactionCallback<List<NodeRef>> callback = new RetryingTransactionCallback<List<NodeRef>>() {

        public List<NodeRef> execute() {
            List<NodeRef> createdNodes = new LinkedList<>();
            for (RecordCategory nodeInfo : nodeInfos) {
                // Create the node
                nodeInfo.setNodeType(RECORD_CATEGORY_TYPE);
                NodeRef newNodeRef = apiUtils.createRMNode(parentNodeRef, nodeInfo, parameters);
                createdNodes.add(newNodeRef);
            }
            return createdNodes;
        }
    };
    List<NodeRef> createdNodes = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    // Get the nodes info
    List<RecordCategory> result = new ArrayList<>(nodeInfos.size());
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    for (NodeRef newNodeRef : createdNodes) {
        FileInfo info = fileFolderService.getFileInfo(newNodeRef);
        result.add(nodesModelFactory.createRecordCategory(info, parameters, mapUserInfo, false));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) RecordCategory(org.alfresco.rm.rest.api.model.RecordCategory) UserInfo(org.alfresco.rest.api.model.UserInfo) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) LinkedList(java.util.LinkedList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Aggregations

FileInfo (org.alfresco.service.cmr.model.FileInfo)101 NodeRef (org.alfresco.service.cmr.repository.NodeRef)82 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)34 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)26 HashMap (java.util.HashMap)20 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)20 QName (org.alfresco.service.namespace.QName)20 AbstractList (java.util.AbstractList)13 UserInfo (org.alfresco.rest.api.model.UserInfo)13 WebApiParam (org.alfresco.rest.framework.WebApiParam)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)10 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)9 IOException (java.io.IOException)8 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)8 Serializable (java.io.Serializable)7 List (java.util.List)7 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)7 FacesContext (javax.faces.context.FacesContext)6