Search in sources :

Example 16 with WebApiDescription

use of org.alfresco.rest.framework.WebApiDescription in project records-management by Alfresco.

the class FilesEntityResource method declareAsRecord.

@Operation("declare")
@WebApiDescription(title = "Declare as record", description = "Declare a file as record.")
public Record declareAsRecord(String fileId, Void body, Parameters parameters, WithResponse withResponse) {
    // Get fileplan
    NodeRef filePlan = authenticationUtil.runAsSystem(new RunAsWork<NodeRef>() {

        @Override
        public NodeRef doWork() {
            return filePlanService.getFilePlanBySiteId(FilePlanService.DEFAULT_RM_SITE_ID);
        }
    });
    // default false (if not provided)
    boolean hideRecord = Boolean.valueOf(parameters.getParameter(Record.PARAM_HIDE_RECORD));
    // Create the record
    NodeRef file = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, fileId);
    RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {

        public Void execute() {
            recordService.createRecord(filePlan, file, !hideRecord);
            return null;
        }
    };
    transactionService.getRetryingTransactionHelper().doInTransaction(callback, false, true);
    // Return record state
    FileInfo info = fileFolderService.getFileInfo(file);
    return nodesModelFactory.createRecord(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) Operation(org.alfresco.rest.framework.Operation)

Example 17 with WebApiDescription

use of org.alfresco.rest.framework.WebApiDescription in project records-management by Alfresco.

the class RecordFolderEntityResource method delete.

@Override
@WebApiDescription(title = "Delete record folder", description = "Deletes a record folder with id 'recordFolderId'")
public void delete(String recordFolderId, Parameters parameters) {
    checkNotBlank("recordFolderId", recordFolderId);
    mandatory("parameters", parameters);
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(recordFolderId, RecordsManagementModel.TYPE_RECORD_FOLDER);
    fileFolderService.delete(nodeRef);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 18 with WebApiDescription

use of org.alfresco.rest.framework.WebApiDescription in project records-management by Alfresco.

the class RecordFolderEntityResource method update.

@Override
@WebApiDescription(title = "Update record folder", description = "Updates a record folder with id 'recordFolderId'")
public RecordFolder update(String recordFolderId, RecordFolder recordFolderInfo, Parameters parameters) {
    checkNotBlank("recordFolderId", recordFolderId);
    mandatory("recordFolderInfo", recordFolderInfo);
    mandatory("parameters", parameters);
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(recordFolderId, RecordsManagementModel.TYPE_RECORD_FOLDER);
    RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {

        public Void execute() {
            apiUtils.updateNode(nodeRef, recordFolderInfo, 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.createRecordFolder(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 19 with WebApiDescription

use of org.alfresco.rest.framework.WebApiDescription in project records-management by Alfresco.

the class RecordsEntityResource method fileRecord.

@Operation("file")
@WebApiDescription(title = "File record", description = "File a record into fileplan.")
public Record fileRecord(String recordId, TargetContainer target, Parameters parameters, WithResponse withResponse) {
    checkNotBlank("recordId", recordId);
    mandatory("target", target);
    mandatory("targetParentId", target.getTargetParentId());
    mandatory("parameters", parameters);
    // Get record and target folder
    NodeRef record = apiUtils.validateRecord(recordId);
    NodeRef targetRecordFolder = apiUtils.lookupAndValidateNodeType(target.getTargetParentId(), RecordsManagementModel.TYPE_RECORD_FOLDER);
    // Get the current parent type to decide if we link or move the record
    NodeRef primaryParent = nodeService.getPrimaryParent(record).getParentRef();
    if (RecordsManagementModel.TYPE_RECORD_FOLDER.equals(nodeService.getType(primaryParent))) {
        recordService.link(record, targetRecordFolder);
    } else {
        try {
            fileFolderService.moveFrom(record, primaryParent, targetRecordFolder, null);
        } catch (FileExistsException e) {
            throw new IntegrityException(e.getMessage(), null);
        } catch (FileNotFoundException e) {
            throw new ConcurrencyFailureException("The record was deleted while filing it", e);
        }
    }
    // 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) ConcurrencyFailureException(org.springframework.dao.ConcurrencyFailureException) FileNotFoundException(org.alfresco.service.cmr.model.FileNotFoundException) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) FileExistsException(org.alfresco.service.cmr.model.FileExistsException) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) Operation(org.alfresco.rest.framework.Operation)

Example 20 with WebApiDescription

use of org.alfresco.rest.framework.WebApiDescription 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)

Aggregations

WebApiDescription (org.alfresco.rest.framework.WebApiDescription)52 NodeRef (org.alfresco.service.cmr.repository.NodeRef)47 FileInfo (org.alfresco.service.cmr.model.FileInfo)34 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)16 HashMap (java.util.HashMap)14 UserInfo (org.alfresco.rest.api.model.UserInfo)13 WebApiParam (org.alfresco.rest.framework.WebApiParam)13 AbstractList (java.util.AbstractList)12 QName (org.alfresco.service.namespace.QName)11 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)8 LinkedList (java.util.LinkedList)5 List (java.util.List)5 QNamePattern (org.alfresco.service.namespace.QNamePattern)5 ArrayList (java.util.ArrayList)4 Operation (org.alfresco.rest.framework.Operation)4 Version (org.alfresco.service.cmr.version.Version)4 RegexQNamePattern (org.alfresco.service.namespace.RegexQNamePattern)4 FilterProp (org.alfresco.repo.node.getchildren.FilterProp)3 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)3 Node (org.alfresco.rest.api.model.Node)3