Saturday, 14 May 2016

2 out-of-the-box repository REST APIs you must keep handy while working with content in Alfresco

As an Alfresco developer, you should always know some of the basic things about content, such as - How to view a content? How to download a content? How to list down all the content from a folder and so on. In Alfresco, you have out-of-the-box repository web scripts available which takes care of all of the above. You must keep yourself familiar with these web scripts.

Let's take a look at 2 very useful content related repository web scripts (which basically are useful for 4 things). In my opinion, you must keep these 2 web scripts handy with you while working on any alfresco implementation. I have used Alfresco 5.1 Community Edition here.

1. View Content

In order to view a content, you should make a GET request to the following URL.

http://localhost:8080/alfresco/service/api/node/content/workspace/SpacesStore/18d2fa04-70ba-4865-afe6-e097b75f0576
Note:You must replace server, port and nodeid in the above URL as per your implementation.

When you hit the above URL, it will display the content in your browser. You may use it for previewing the content.

You can take a look at the description document of this web script at the following URL and can also try out the different URL options supported for viewing a content as mentioned there.
http://localhost:8080/alfresco/service/description/org/alfresco/content/content.get

2. Download Content

To download a content, you will be using the same web script we used above however only additional option that you will provide is a querystring parameter a=true

http://localhost:8080/alfresco/service/api/node/content/workspace/SpacesStore/18d2fa04-70ba-4865-afe6-e097b75f0576?a=true

When you hit the above URL, it will download the content.

3. Get list of contents from a specific folder

To  get a list of all the contents of a folder, you can hit the following web script.

http://localhost:8080/alfresco/service/slingshot/doclib/doclist/documents/node/workspace/SpacesStore/e0856836-ed5e-4eee-b8e5-bd7e8fb9384c

As highlighted in above URL, when you specify documents, it fetches all the documents for a given folder.

Description document for this web script can be found at
http://localhost:8080/alfresco/service/script/org/alfresco/slingshot/documentlibrary/doclist.get

3. Get list of  the contents & folders from a specific folder

To get a list of both contents & folders from a specific folder, you can hit the following web script. It is basically the same web script we used in #3. Only difference is, instead of specifying documents we will specify all there. If you specify anything except documents then it will list down both content & folders.

http://localhost:8080/alfresco/service/slingshot/doclib/doclist/all/node/workspace/SpacesStore/e0856836-ed5e-4eee-b8e5-bd7e8fb9384c
OR
http://localhost:8080/alfresco/service/slingshot/doclib/doclist/both/node/workspace/SpacesStore/e0856836-ed5e-4eee-b8e5-bd7e8fb9384c

One important thing to take a note over here is that both the above web scripts have lifecycle mentioned as internal. Hence, they are for alfresco internal use only and there may be the chances that it may get changed in future versions of alfresco. Hence, if you want to use them for integration purpose in your project then you must keep this point in consideration before using them. However, from a developer perspective it is a must to know about these web scripts available in Alfresco so as it will be helpful to you while working on any content related issue.

Hope this will be useful to you.

Saturday, 30 April 2016

Quick way to disable upload file button for a specific folder in Alfresco Share

We all like to develop based on the best practices and that is what I recommend as well. However, sometimes in the interest of time, we may have to go for a quick solution considering the practical situation. For example, think of a scenario where you are preparing for a demo and at last moment you realize that you need to take care of some specific use case. I am sure, you must be looking forward to know how quickly and easily you can achieve it. That's where quick solutions would be very helpful. Here I am going to share with you one such quick trick which may be helpful to you somewhere sometime.

While working on Alfresco you may have come across a use case that, you want to disable upload file button in Alfresco Share for some specific folder and all folders under it.

Here is how you can have it working just in 5 minutes for your Alfresco Community 5.1 installation.

1. In your Alfresco installed directory, copy code from toolbar.js to toolbar-min.js at the location tomcat/webapps/share/components/documentlibrary/
[Note : It is always recommended to have your client side JS files minified for having a better page load performance. Although we are knowing that, however in order to get the things ready in the interest of time, we are not minifying the JS here]

2. Add following code snippet under onFilterChanged function in toolbar-min.js.Provide the folder name for which you want to hide the upload button.

//Custom start
if(this.doclistMetadata.parent.properties["cm:name"] == "Folder Name|| this.currentPath.indexOf("Folde Name") !== -1) {                       
        this.widgets.fileUpload.set("disabled", true);
} else {
        this.widgets.fileUpload.set("disabled", false); 
}
//Custom end

Above change in toolbar-min.js, will appear as shown in the following screenprint. Highlighted in blue is the custom code we have added to disable the upload file button for a folder named MyFolder and all its subfolder.

code snippet to disable upload file button for a specific folder and its subfolders
Hope this would be helpful.


Thursday, 10 March 2016

2 Quick & Easy ways to know your Alfresco version details...

With each new release of Alfresco, there are many new features getting added to Alfresco which are really useful and makes Alfresco product really cool. The most recent release was Alfresco 5.1. Hope you have checked about the new features of the latest release Alfresco 5.1 Community Edition and Alfresco One 5.1 (Enterprise Edition)

Now, while working on Alfresco and especially if you are new to Alfresco, it may sometimes happen that you want to know the details about the exact version of your Alfresco in order to refer to the appropriate documentation link and even to ask the question in Alfresco forum with specific Alfresco version details.

I am sure you must also have had figured it out as well. However, here are the two quick and easy ways you can easily find your Alfresco version detail when your Alfresco is up and running and even when your Alfresco is not running.

Know Alfresco version details when Alfresco is NOT running

You need not to wait for your Alfresco to be up and running in order to know the Alfresco version details. You can get to know the details even when Alfresco is not running. Following is how you can know it. Inside your Alfresco installed directory, you can find version.properties at the location \tomcat\webapps\alfresco\WEB-INF\classes\alfresco.This file contains all the required details about the alfresco version as shown in the following screen-print. It contains all the details you should know about your Alfresco.
Alfresco version details


Know Alfresco version details when Alfresco is up and running

When Alfresco is up and running, it is even simpler to know the version details. Simply hit the url http://localhost:8080/alfresco (modify the host and port as per your installation) and you will be shown with the following screen. You get to know Alfresco version details such as label, edition and version build number as highlighted below.
Alfresco version details

These are the 2 quick and easy ways to find your Alfresco version details.