Search in sources :

Example 1 with Operation

use of org.alfresco.rest.framework.Operation 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 2 with Operation

use of org.alfresco.rest.framework.Operation 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 3 with Operation

use of org.alfresco.rest.framework.Operation 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 4 with Operation

use of org.alfresco.rest.framework.Operation in project alfresco-remote-api by Alfresco.

the class NodeVersionsRelation method revertById.

@Operation("revert")
@WebApiDescription(title = "Revert Version", description = "Reverts (ie. promotes) specified version to become a new, most recent, version", successStatus = HttpServletResponse.SC_OK)
public Node revertById(String nodeId, String versionId, VersionOptions versionOptions, Parameters parameters, WithResponse withResponse) {
    Version v = findVersion(nodeId, versionId);
    if (v != null) {
        CheckOutCheckInService cociService = sr.getCheckOutCheckInService();
        NodeRef nodeRef = v.getVersionedNodeRef();
        String versionComment = versionOptions.getComment();
        VersionType versionType = VersionType.MINOR;
        Boolean versionMajor = versionOptions.getMajorVersion();
        if ((versionMajor != null) && (versionMajor)) {
            versionType = VersionType.MAJOR;
        }
        Map<String, Serializable> versionProperties = new HashMap<>(2);
        versionProperties.put(VersionModel.PROP_VERSION_TYPE, versionType);
        if (versionComment != null) {
            versionProperties.put(VersionModel.PROP_DESCRIPTION, versionComment);
        }
        // cancel editing if we want to revert
        if (sr.getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_WORKING_COPY)) {
            nodeRef = cociService.cancelCheckout(nodeRef);
        }
        // TODO review default for deep and/or whether we should make it an option
        versionService.revert(nodeRef, v, false);
        // Checkout/Checkin the node - to store the new version in version history
        NodeRef wcNodeRef = cociService.checkout(nodeRef);
        cociService.checkin(wcNodeRef, versionProperties);
        // get latest version
        v = versionService.getVersionHistory(nodeRef).getHeadVersion();
        Node node = nodes.getFolderOrDocumentFullInfo(v.getFrozenStateNodeRef(), null, null, parameters, null);
        mapVersionInfo(v, node);
        return node;
    }
    throw new EntityNotFoundException(nodeId + "-" + versionId);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) CheckOutCheckInService(org.alfresco.service.cmr.coci.CheckOutCheckInService) Version(org.alfresco.service.cmr.version.Version) HashMap(java.util.HashMap) Node(org.alfresco.rest.api.model.Node) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) VersionType(org.alfresco.service.cmr.version.VersionType) WebApiDescription(org.alfresco.rest.framework.WebApiDescription) Operation(org.alfresco.rest.framework.Operation)

Aggregations

Operation (org.alfresco.rest.framework.Operation)4 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)4 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)3 IntegrityException (org.alfresco.repo.node.integrity.IntegrityException)2 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 RecordMissingMetadataException (org.alfresco.module.org_alfresco_module_rm.record.RecordMissingMetadataException)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 Node (org.alfresco.rest.api.model.Node)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 CheckOutCheckInService (org.alfresco.service.cmr.coci.CheckOutCheckInService)1 FileExistsException (org.alfresco.service.cmr.model.FileExistsException)1 FileNotFoundException (org.alfresco.service.cmr.model.FileNotFoundException)1 Version (org.alfresco.service.cmr.version.Version)1 VersionType (org.alfresco.service.cmr.version.VersionType)1 ConcurrencyFailureException (org.springframework.dao.ConcurrencyFailureException)1