Search in sources :

Example 51 with FileInfo

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

the class RecordsEntityResource method readProperty.

/**
 * Download content
 *
 * @param recordId the id of the record to get the content from
 * @param parameters {@link Parameters}
 * @return binary content resource
 * @throws EntityNotFoundException
 */
@Override
@WebApiDescription(title = "Download content", description = "Download content for a record with id 'recordId'")
@BinaryProperties({ "content" })
public BinaryResource readProperty(String recordId, Parameters parameters) throws EntityNotFoundException {
    checkNotBlank("recordId", recordId);
    mandatory("parameters", parameters);
    NodeRef record = apiUtils.validateRecord(recordId);
    if (nodeService.getType(record).equals(RecordsManagementModel.TYPE_NON_ELECTRONIC_DOCUMENT)) {
        throw new IllegalArgumentException("Cannot read content from Non-electronic record " + recordId + ".");
    }
    BinaryResource content = apiUtils.getContent(record, parameters, true);
    NodeRef primaryParent = nodeService.getPrimaryParent(record).getParentRef();
    FileInfo info = fileFolderService.getFileInfo(record);
    apiUtils.postActivity(info, primaryParent, ActivityPoster.DOWNLOADED);
    return content;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) BinaryResource(org.alfresco.rest.framework.resource.content.BinaryResource) FileInfo(org.alfresco.service.cmr.model.FileInfo) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) BinaryProperties(org.alfresco.rest.framework.BinaryProperties)

Example 52 with FileInfo

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

the class RecordsEntityResource method completeRecord.

@Operation("complete")
@WebApiDescription(title = "Complete record", description = "Complete a record.")
public Record completeRecord(String recordId, Void body, Parameters parameters, WithResponse withResponse) {
    checkNotBlank("recordId", recordId);
    mandatory("parameters", parameters);
    // Get record
    NodeRef record = apiUtils.validateRecord(recordId);
    // Complete the record
    try {
        recordService.complete(record);
    } catch (RecordMissingMetadataException e) {
        throw new IntegrityException("The record has missing mandatory properties.", null);
    }
    // return record state
    FileInfo info = fileFolderService.getFileInfo(record);
    return nodesModelFactory.createRecord(info, parameters, null, false);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) RecordMissingMetadataException(org.alfresco.module.org_alfresco_module_rm.record.RecordMissingMetadataException) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) Operation(org.alfresco.rest.framework.Operation)

Example 53 with FileInfo

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

the class TransferContainerChildrenRelation method readAll.

@Override
@WebApiDescription(title = "Return a paged list of transfers for the transfer container identified by 'transferContainerId'")
public CollectionWithPagingInfo<Transfer> readAll(String transferContainerId, Parameters parameters) {
    checkNotBlank("transferContainerId", transferContainerId);
    mandatory("parameters", parameters);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(transferContainerId, RecordsManagementModel.TYPE_TRANSFER_CONTAINER);
    // list transfers
    Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesForTransferContainersEndpoint();
    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<Transfer> nodes = new AbstractList<Transfer>() {

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

        @Override
        public int size() {
            return page.size();
        }
    };
    TransferContainer sourceEntity = null;
    if (parameters.includeSource()) {
        FileInfo info = fileFolderService.getFileInfo(parentNodeRef);
        sourceEntity = nodesModelFactory.createTransferContainer(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) TransferContainer(org.alfresco.rm.rest.api.model.TransferContainer) FileInfo(org.alfresco.service.cmr.model.FileInfo) Transfer(org.alfresco.rm.rest.api.model.Transfer) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 54 with FileInfo

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

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

the class UnfiledContainerChildrenRelation method readAll.

@Override
@WebApiDescription(title = "Return a paged list of unfiled container children for the container identified by 'unfiledContainerId'")
public CollectionWithPagingInfo<UnfiledContainerChild> readAll(String unfiledContainerId, Parameters parameters) {
    // validate parameters
    checkNotBlank("unfiledContainerId", unfiledContainerId);
    mandatory("parameters", parameters);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfiledContainerId, RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
    // list unfiled record folders and records
    Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesForUnfiledEndpoint(parameters, LIST_UNFILED_CONTAINER_CHILDREN_EQUALS_QUERY_PROPERTIES);
    List<FilterProp> filterProps = apiUtils.getListChildrenFilterProps(parameters, LIST_UNFILED_CONTAINER_CHILDREN_EQUALS_QUERY_PROPERTIES);
    final PagingResults<FileInfo> pagingResults = fileFolderService.list(parentNodeRef, null, searchTypeQNames, null, apiUtils.getSortProperties(parameters), filterProps, Util.getPagingRequest(parameters.getPaging()));
    final List<FileInfo> page = pagingResults.getPage();
    Map<String, UserInfo> mapUserInfo = new HashMap<>();
    List<UnfiledContainerChild> nodes = new AbstractList<UnfiledContainerChild>() {

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

        @Override
        public int size() {
            return page.size();
        }
    };
    UnfiledContainer sourceEntity = null;
    if (parameters.includeSource()) {
        FileInfo info = fileFolderService.getFileInfo(parentNodeRef);
        sourceEntity = nodesModelFactory.createUnfiledContainer(info, parameters, mapUserInfo, true);
    }
    return CollectionWithPagingInfo.asPaged(parameters.getPaging(), nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity);
}
Also used : AbstractList(java.util.AbstractList) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) HashMap(java.util.HashMap) UnfiledContainerChild(org.alfresco.rm.rest.api.model.UnfiledContainerChild) QName(org.alfresco.service.namespace.QName) UserInfo(org.alfresco.rest.api.model.UserInfo) UnfiledContainer(org.alfresco.rm.rest.api.model.UnfiledContainer) NodeRef(org.alfresco.service.cmr.repository.NodeRef) FileInfo(org.alfresco.service.cmr.model.FileInfo) 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