Search in sources :

Example 31 with WebApiDescription

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

the class NodeVersionsRelation method delete.

@Override
@WebApiDescription(title = "Delete version")
public void delete(String nodeId, String versionId, Parameters parameters) {
    Version v = findVersion(nodeId, versionId);
    // live (aka versioned) nodeRef
    NodeRef nodeRef = v.getVersionedNodeRef();
    if (sr.getPermissionService().hasPermission(nodeRef, PermissionService.DELETE) != AccessStatus.ALLOWED) {
        throw new PermissionDeniedException("Cannot delete version");
    }
    versionService.deleteVersion(nodeRef, v);
    Map<QName, Serializable> props = sr.getNodeService().getProperties(nodeRef);
    if (props.get(ContentModel.PROP_VERSION_LABEL) == null) {
        // note: alternatively, the client can remove the "cm:versionable" aspect (if permissions allow) to clear the version history and disable versioning
        throw new IntegrityException("Cannot delete last version (did you mean to disable versioning instead ?) [" + nodeId + "," + versionId + "]", null);
    /*
            if (props.get(ContentModel.PROP_VERSION_TYPE) != null)
            {
                // minor fix up to versionable aspect - ie. remove versionType
                behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
                behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
                try
                {
                    sr.getNodeService().removeProperty(nodeRef, ContentModel.PROP_VERSION_TYPE);
                }
                finally
                {
                    behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
                    behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_VERSIONABLE);
                }
            }
            */
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) Serializable(java.io.Serializable) Version(org.alfresco.service.cmr.version.Version) QName(org.alfresco.service.namespace.QName) IntegrityException(org.alfresco.repo.node.integrity.IntegrityException) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 32 with WebApiDescription

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

the class NodeVersionsRelation method readAll.

/**
 * List version history
 *
 * @param nodeId String id of (live) node
 */
@Override
@WebApiDescription(title = "Return version history as a paged list of version node infos")
public CollectionWithPagingInfo<Node> readAll(String nodeId, Parameters parameters) {
    NodeRef nodeRef = nodes.validateOrLookupNode(nodeId, null);
    VersionHistory vh = versionService.getVersionHistory(nodeRef);
    Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
    List<String> includeParam = parameters.getInclude();
    List<Node> collection = null;
    if (vh != null) {
        collection = new ArrayList<>(vh.getAllVersions().size());
        for (Version v : vh.getAllVersions()) {
            Node node = nodes.getFolderOrDocument(v.getFrozenStateNodeRef(), null, null, includeParam, mapUserInfo);
            mapVersionInfo(v, node);
            collection.add(node);
        }
    }
    return listPage(collection, parameters.getPaging());
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) HashMap(java.util.HashMap) Version(org.alfresco.service.cmr.version.Version) Node(org.alfresco.rest.api.model.Node) UserInfo(org.alfresco.rest.api.model.UserInfo) VersionHistory(org.alfresco.service.cmr.version.VersionHistory) WebApiDescription(org.alfresco.rest.framework.WebApiDescription)

Example 33 with WebApiDescription

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

the class UnfiledContainerEntityResource method update.

@Override
@WebApiDescription(title = "Update unfiled record container", description = "Updates an unfiled record container with id 'unfiledContainerId'")
public UnfiledContainer update(String unfiledContainerId, UnfiledContainer unfiledContainerInfo, Parameters parameters) {
    checkNotBlank("unfiledContainerId", unfiledContainerId);
    mandatory("unfiledContainerInfo", unfiledContainerInfo);
    mandatory("parameters", parameters);
    NodeRef nodeRef = apiUtils.lookupAndValidateNodeType(unfiledContainerId, RecordsManagementModel.TYPE_UNFILED_RECORD_CONTAINER);
    RetryingTransactionCallback<Void> callback = new RetryingTransactionCallback<Void>() {

        public Void execute() {
            apiUtils.updateNode(nodeRef, unfiledContainerInfo, 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);
    apiUtils.postActivity(info, unfiledContainerInfo.getParentId(), ActivityType.FILE_UPDATED);
    return nodesModelFactory.createUnfiledContainer(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 34 with WebApiDescription

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

Example 35 with WebApiDescription

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

the class UnfiledRecordFolderChildrenRelation method readAll.

@Override
@WebApiDescription(title = "Return a paged list of unfiled container children for the container identified by 'unfiledContainerId'")
public CollectionWithPagingInfo<UnfiledRecordFolderChild> readAll(String unfileRecordFolderId, Parameters parameters) {
    checkNotBlank("unfileRecordFolderId", unfileRecordFolderId);
    mandatory("parameters", parameters);
    String relativePath = parameters.getParameter(Nodes.PARAM_RELATIVE_PATH);
    NodeRef parentNodeRef = apiUtils.lookupAndValidateNodeType(unfileRecordFolderId, RecordsManagementModel.TYPE_UNFILED_RECORD_FOLDER, relativePath, true);
    // list unfiled record folders and records
    Set<QName> searchTypeQNames = searchTypesFactory.buildSearchTypesForUnfiledEndpoint(parameters, LIST_UNFILED_RECORD_FOLDER_CHILDREN_EQUALS_QUERY_PROPERTIES);
    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<UnfiledRecordFolderChild> nodes = new AbstractList<UnfiledRecordFolderChild>() {

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

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

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