Search in sources :

Example 1 with UploadInfo

use of org.alfresco.rm.rest.api.model.UploadInfo 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 2 with UploadInfo

use of org.alfresco.rm.rest.api.model.UploadInfo in project records-management by Alfresco.

the class UnfiledContainerChildrenRelation method create.

@Override
@WebApiDescription(title = "Upload file content and meta-data into a unfiled record container identified by 'unfiledContainerId'.")
@WebApiParam(name = "formData", title = "A single form data", description = "A single form data which holds FormFields.")
public UnfiledContainerChild create(String unfiledContainerId, FormData formData, Parameters parameters, WithResponse withResponse) {
    checkNotBlank("unfiledContainerId", unfiledContainerId);
    mandatory("formData", formData);
    mandatory("parameters", parameters);
    UploadInfo uploadInfo = new UploadInfo(formData);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledContainerId, RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
    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.createUnfiledContainerChild(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 3 with UploadInfo

use of org.alfresco.rm.rest.api.model.UploadInfo in project records-management by Alfresco.

the class UnfiledRecordFolderChildrenRelation 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 UnfiledRecordFolderChild create(String unfiledRecordFolderId, FormData formData, Parameters parameters, WithResponse withResponse) {
    checkNotBlank("unfiledRecordFolderId", unfiledRecordFolderId);
    mandatory("formData", formData);
    mandatory("parameters", parameters);
    // Retrieve the input data and resolve the parent node
    final UploadInfo uploadInfo = new UploadInfo(formData);
    // Create the record  - returns pair(newNode,parentNode)
    RetryingTransactionCallback<Pair<NodeRef, NodeRef>> callback = new RetryingTransactionCallback<Pair<NodeRef, NodeRef>>() {

        public Pair<NodeRef, NodeRef> execute() {
            final NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledRecordFolderId, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER, uploadInfo.getRelativePath());
            NodeRef newNode = apiUtils.uploadRecord(parentNodeRef, uploadInfo, parameters);
            return new Pair<NodeRef, NodeRef>(newNode, parentNodeRef);
        }
    };
    Pair<NodeRef, NodeRef> nodeAndParentInfo = transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    NodeRef newNode = nodeAndParentInfo.getFirst();
    NodeRef parent = nodeAndParentInfo.getSecond();
    // Get file info for response
    FileInfo info = fileFolderService.getFileInfo(newNode);
    apiUtils.postActivity(info, parent, ActivityType.FILE_ADDED);
    return nodesModelFactory.createUnfiledRecordFolderChild(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) Pair(org.alfresco.util.Pair) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) WebApiParam(org.alfresco.rest.framework.WebApiParam)

Aggregations

RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)3 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)3 WebApiParam (org.alfresco.rest.framework.WebApiParam)3 UploadInfo (org.alfresco.rm.rest.api.model.UploadInfo)3 FileInfo (org.alfresco.service.cmr.model.FileInfo)3 NodeRef (org.alfresco.service.cmr.repository.NodeRef)3 Pair (org.alfresco.util.Pair)1