Alfresco REST Core API retrive Version by node-uuid

336 views Asked by At

I am developing an Alfresco client based on REST APIs.

But I haven't found a method that allows to retrieve a version with its node-uuid without knowing its parent UUID

[ base url: /alfresco/api/-default-/public/alfresco/versions/1 , api version: 1 ] 

enter image description here

1

There are 1 answers

4
Arjun On BEST ANSWER

Below Rest api retrieve the version history for the file without knowing parent uuid.

http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/{{fileId}}/versions

This one will provide the exact information's of version 1.0, same way you can retrieve all the versions. http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/695b8a62-b566-4d49-9a4f-8f509f8cae59/versions/1.0

{
    "list": {
        "pagination": {
            "count": 2,
            "hasMoreItems": false,
            "totalItems": 2,
            "skipCount": 0,
            "maxItems": 100
        },
        "entries": [
            {
                "entry": {
                    "isFolder": false,
                    "isFile": true,
                    "modifiedAt": "2021-02-26T14:56:05.677+0000",
                    "modifiedByUser": {
                        "id": "admin",
                        "displayName": "Administrator"
                    },
                    "name": "CustomPage.PNG",
                    "id": "2.0",
                    "nodeType": "cm:content",
                    "content": {
                        "mimeType": "image/png",
                        "mimeTypeName": "PNG Image",
                        "sizeInBytes": 39779,
                        "encoding": "UTF-8"
                    }
                }
            },
            {
                "entry": {
                    "isFolder": false,
                    "isFile": true,
                    "modifiedAt": "2021-02-26T14:52:31.315+0000",
                    "modifiedByUser": {
                        "id": "admin",
                        "displayName": "Administrator"
                    },
                    "name": "CustomPage.PNG",
                    "id": "1.0",
                    "nodeType": "cm:content",
                    "content": {
                        "mimeType": "image/png",
                        "mimeTypeName": "PNG Image",
                        "sizeInBytes": 39779,
                        "encoding": "UTF-8"
                    }
                }
            }
        ]
    }
}

The below code Return version history as a paged list of version node infos.

@Override
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());
}