How to get the thin client URI of an Alfresco folder/document?

2.1k views Asked by At

A thin client URI is a web address that you can type to see details about a file or folder, on a nice web user interface.

For instance, my Android app uses Alfresco's CMIS API, but for complex operations (eg. to start a workflow on this file), you could click on a link and it would bring you to the fully-fledged web interface (provided by the Alfresco server).

How to calculate this thin client URI, for any Alfresco folder/document?

A good start is to use the thinClientURI feature of the CMIS protocol. Unfortunately it only work for the root of the repository.

A perfect algorithm would show Alfresco Share nodes in their Alfresco Share site, rather than in Share's generic Repository Browser.

2

There are 2 answers

0
Gagravarr On BEST ANSWER

Alfresco does have a little known feature to do just what you need! I believe it was implemented in Enterprise 4.0.3ish, ready for 4.1, and the main use of it so far is in Cloud Sync.

The webscript you're looking for is org.alfresco.repository.site.site-share-view-url.get and it is exposed as /api/sites/shareUrl?nodeRef=nodeRef . It returns a simple bit of JSON, such as:

{
   "site": "alfresco-test",
   "url": "https:\/\/my.alfresco.com\/share\/test.com\/page\/site\/alfresco-test\/document-details?nodeRef=workspace:\/\/SpacesStore\/aae3b33fd-23d4-4091-ae64-44a8e332091341"
}

(The above example is taken from the Alfresco cloud version, but it should be present in late 4.0 enterprise releases, enterprise 4.1, and community + enterprise 4.2 onwards)

If you want to see what kinds of content it supports, your best bet is to look at the java class which powers it, org.alfresco.repo.web.scripts.site.SiteShareViewUrlGet

However, one slight restriction is that it only supports nodes that are located within sites. If you have a non-site node, you'll have to calculate a repository browser URL for it yourself...

0
Nicolas Raoul On

Below is my current implementation.
It is (very) far from perfect, as it only works for folders, and only in Alfresco Share.

        string suffix1 = "alfresco/cmisatom";
        string suffix2 = "alfresco/service/cmis";
        if (repo.Address.AbsoluteUri.EndsWith(suffix1) || repo.Address.AbsoluteUri.EndsWith(suffix2))
        {
            // Detect suffix length.
            int suffixLength = 0;
            if (repo.Address.AbsoluteUri.EndsWith(suffix1))
                suffixLength = suffix1.Length;
            if (repo.Address.AbsoluteUri.EndsWith(suffix2))
                suffixLength = suffix2.Length;

            string root = repo.Address.AbsoluteUri.Substring(0, repo.Address.AbsoluteUri.Length - suffixLength);
            if (repo.RemotePath.StartsWith("/Sites"))
            {
                // Case of Alfresco Share.

                // Example RemotePath: /Sites/thesite
                // Result: http://server/share/page/site/thesite/documentlibrary
                // Example RemotePath: /Sites/thesite/documentLibrary/somefolder/anotherfolder
                // Result: http://server/share/page/site/thesite/documentlibrary#filter=path|%2Fsomefolder%2Fanotherfolder
                // Example RemotePath: /Sites/s1/documentLibrary/éß和ệ
                // Result: http://server/share/page/site/s1/documentlibrary#filter=path|%2F%25E9%25DF%25u548C%25u1EC7
                // Example RemotePath: /Sites/s1/documentLibrary/a#bc/éß和ệ
                // Result: http://server/share/page/site/thesite/documentlibrary#filter=path%7C%2Fa%2523bc%2F%25E9%25DF%25u548C%25u1EC7%7C

                string path = repo.RemotePath.Substring("/Sites/".Length);
                if (path.Contains("documentLibrary"))
                {
                    int firstSlashPosition = path.IndexOf('/');
                    string siteName = path.Substring(0, firstSlashPosition);
                    string pathWithinSite = path.Substring(firstSlashPosition + "/documentLibrary".Length);
                    string escapedPathWithinSite = HttpUtility.UrlEncode(pathWithinSite);
                    string reescapedPathWithinSite = HttpUtility.UrlEncode(escapedPathWithinSite);
                    string sharePath = reescapedPathWithinSite.Replace("%252f", "%2F");
                    return root + "share/page/site/" + siteName + "/documentlibrary#filter=path|" + sharePath;
                }
                else
                {
                    // Site name only.
                    return root + "share/page/site/" + path + "/documentlibrary";
                }
            }
            else
            {
                // Case of Alfresco Web Client. Difficult to build a direct URL, so return root.
                return root;
            }
        }