Search in sources :

Example 41 with FileInfo

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

the class RecordFolderChildrenRelation method create.

@Override
@WebApiDescription(title = "Upload file content and meta-data into the repository.")
@WebApiParam(name = "formData", title = "A single form data", description = "A single form data which holds FormFields.")
public Record create(String recordFolderId, FormData formData, Parameters parameters, WithResponse withResponse) {
    checkNotBlank("recordFolderId", recordFolderId);
    mandatory("formData", formData);
    mandatory("parameters", parameters);
    // Retrieve the input data and resolve the parent node
    final UploadInfo uploadInfo = new UploadInfo(formData);
    final NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(recordFolderId, RecordsManagementModel.TYPE_RECORD_FOLDER, uploadInfo.getRelativePath());
    // Create the record
    RetryingTransactionCallback<NodeRef> callback = new RetryingTransactionCallback<NodeRef>() {

        public NodeRef execute() {
            return apiUtils.uploadRecord(parentNodeRef, uploadInfo, parameters);
        }
    };
    NodeRef newNode = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    // Get file info for response
    FileInfo info = fileFolderService.getFileInfo(newNode);
    apiUtils.postActivity(info, parentNodeRef, ActivityType.FILE_ADDED);
    return nodesModelFactory.createRecord(info, parameters, null, false);
}
Also used : UploadInfo(org.alfresco.rm.rest.api.model.UploadInfo) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) WebApiParam(org.alfresco.rest.framework.WebApiParam)

Example 42 with FileInfo

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

the class TransferContainerEntityResource method update.

@Override
@WebApiDescription(title = "Update transfer container", description = "Updates a transfer container with id 'transferContainerId'")
public TransferContainer update(String transferContainerId, TransferContainer transferContainerInfo, Parameters parameters) {
    checkNotBlank("transferContainerId", transferContainerId);
    mandatory("transferContainerInfo", transferContainerInfo);
    mandatory("parameters", parameters);
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(transferContainerId, RecordsManagementModel.TYPE_TRANSFER_CONTAINER);
    // update info
    RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {

        public Void execute() {
            apiUtils.updateTransferContainer(nodeRef, transferContainerInfo, parameters);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    RetryingTransactionCallback<FileInfo> readCallback = new RetryingTransactionCallback<FileInfo>() {

        public FileInfo execute() {
            return fileFolderService.getFileInfo(nodeRef);
        }
    };
    FileInfo info = transactionService.getRetryingTransactionHelper().doInTransaction(readCallback, false, true);
    return nodesModelFactory.createTransferContainer(info, parameters, null, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 43 with FileInfo

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

the class TransferContainerEntityResource method readById.

@WebApiDescription(title = "Get transfer container information", description = "Gets information for a transfer container with id 'transferContainerId'")
@WebApiParam(name = "transferContainerId", title = "The transfer container id")
@Override
public TransferContainer readById(String transferContainerId, Parameters parameters) throws EntityNotFoundException {
    checkNotBlank("transferContainerId", transferContainerId);
    mandatory("parameters", parameters);
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(transferContainerId, RecordsManagementModel.TYPE_TRANSFER_CONTAINER);
    FileInfo info = fileFolderService.getFileInfo(nodeRef);
    return nodesModelFactory.createTransferContainer(info, parameters, null, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) WebApiParam(org.alfresco.rest.framework.WebApiParam)

Example 44 with FileInfo

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

the class TransferChildrenRelation method readAll.

@Override
@WebApiDescription(title = "Return a paged list of record folders or records for the transfer identified by 'transferId'")
public CollectionWithPagingInfo<TransferChild> readAll(String transferId, Parameters parameters) {
    checkNotBlank("transferId", transferId);
    mandatory("parameters", parameters);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(transferId, RecordsManagementModel.TYPE_TRANSFER);
    // list record folder, electronic record or non electronic record
    final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef, null, null, null, apiUtils.getSortProperties(parameters), null, Util.getPagingRequest(parameters.getPaging()));
    final List<FileInfo> page = pagingResults.getPage();
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    List<TransferChild> nodes = new AbstractList<TransferChild>() {

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

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

Example 45 with FileInfo

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

the class RM1027Test method testCopyingAClosedFolder.

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

        @Override
        public NodeRef run() {
            // create a folder and close it
            NodeRef recordFolder = recordFolderService.createRecordFolder(rmContainer, "My Closed Record Folder");
            utils.closeFolder(recordFolder);
            assertTrue((Boolean) nodeService.getProperty(recordFolder, PROP_IS_CLOSED));
            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((Boolean) nodeService.getProperty(copy, PROP_IS_CLOSED));
        }
    });
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo)

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