Sunday, August 31, 2014

Display web-preview of document on form in Alfresco share



Environment:  Alfresco 4.2.1 Enterprise Version

Recently we had requirement to have web-preview of the content on work flow task form.
Actually, in out of the box web-preview is an independent component and form itself is an independent component.
On form we can have only different types of controls not the component.
So there is no direct way to display web-preview of the content on any form as we don't have direct facility to render component on form.

One possible solution is make a custom control and render the response of the web-preview component in custom control.

That is what exactly I did.

Let's have brief idea what we are going to do.

we will create one custom control for that we need to create one ftl and one client side java-script file.
In ftl we will just add div in which we will render web-preview component response.
From ftl file, we will call client side js file.
From onReady method of client side js, we will call web-preview component and will embed its response in div which is defined in ftl.

I created custom control and added the following code in ftl file.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<@script type="text/javascript" src="${page.url.context}/res/components/form/custom-web-preview.js"></@script>
   <@script type="text/javascript" src="${page.url.context}/res/components/preview/web-preview.js"></@script>
   <@script src="${url.context}/res/components/preview/web-preview.js" />
   <@script src="${url.context}/res/components/preview/WebPreviewer.js" />
   <@script src="${url.context}/res/js/flash/extMouseWheel.js" />
   <@script src="${url.context}/res/components/preview/StrobeMediaPlayback.js" />
   <@script src="${url.context}/res/components/preview/Video.js" />
   <@script src="${url.context}/res/components/preview/Audio.js" />
   <@script src="${url.context}/res/components/preview/Flash.js" />
   <@script src="${url.context}/res/components/preview/Image.js" />

 <script type="text/javascript">//<![CDATA[
(
function()
{
    new Alfresco.customControl("${fieldHtmlId}").setMessages(${messages});
}
)
();

//]]></script>

<div id="${fieldHtmlId}">
   <div id="web-preview">
     
 </div>
</div>

Here, I have added dependences java-script files and added Div with id as "web-preview" which will be used to render response of the web-preview component.

In onReady method of client js, I called ootb web-preview component and added its response in to defined "web-preview" div.
Following code I added in onReady method of client side java-script.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
Alfresco.util.Ajax.request(
         {
           method: "GET",
           url: Alfresco.constants.URL_SERVICECONTEXT + "components/preview/web-preview?nodeRef=${NODEREF}&htmlid=${ID}",,
           successCallback:
           {
            fn: function(o)
            {
        Dom.get("web-preview").innerHTML = o.serverResponse.responseText;
            },
            scope: this
           },
           failureMessage: "Failed"
        });
         }
         

       
That's it we are done.Now we need to just add this custom control on any form and it will display web-preview of content on form UI.

Tuesday, May 20, 2014

Execute Alfresco RESTful APIs using "Advanced REST client "

     There are numerous of plugins are available in Google Chrome and FireFox browsers for doing rest calls like Poster,Rest-Console etc.

I found "Advanced REST client" is the best one as it is providing advanced facility like saving history and project but its user interface is pretty awful.I dont like that one  :)

For understanding How one can use "Advanced REST client"  in actual scenarios, I am taking example of doing post request with json data as body.

First we need to install "Advanced REST client" chrome extension in Google Chrome browser.
You can find it here https://chrome.google.com/webstore/search/advanced%20rest%20client .

After installing "Advanced REST client" chrome extension in Google chrome, go to chrome://apps/.

You can find the icon for "Advanced REST client" extension.Click on it.Its home will look like :






Now, enter the URL of your rest call in URL tab.

Select Post request method and add header parameters in "Header" panel.

By clicking on "Form" tab, you can add your credentials as header parameters.
You can also new header parameter by click on "Add new Header" link.

Write your raw json data in "Payload" panel.
By clicking on "Raw" tab, you can add your raw json data in payload.

As we are passing json data in body,we will  select "application/json" from drop down.
Now our page look like following :






Now click on "send" button, you will get response in response tab.
You can also save the request and in future you can use it.

Sunday, December 29, 2013

Resolving Error : "ContentIOException: Failed to open stream onto channel"

Recently I faced the error "ContentIOException: Failed to open stream onto channel"  suddenly when I started my alfresco server.













Here it is showing that content which has uuid as 31b2337-2bc3-11dc-80cf-4rt94d7e2324 does not exists in ${alfresco_setup}/alf_data folder or it can not be accessed.

Reason : 

It may possible that file has been deleted or corrupted or it can not be accessed.

Solution : 

I have created the 31b2337-2bc3-11dc-80cf-4rt94d7e2324.bin file manually at location /2013/12/3/9/20/ with blank json data i.e. { } only curly braces.
Then I  restarted my server and it works fine for me.

On the other hand ,if file is present at specified location then make him accessible and restart the server.

Sunday, December 8, 2013

Alfresco Cold BackUp and Restore using In built postgres database



Alfresco Cold Backup
For the sake of this article here we are assuming that we are using alfresco 3.4.3 version with in-built postgresql server installed on linux machine.For taking cold back up of alfresco server, follow the below steps.
Step 1 ::Stop the Alfresco server from which you want to take the backup.
--> Go to {ALFRESCO_HOME} and run the command sh alfresco.sh stop or kill tomcat process manually.
Step 2 ::Now take copy of alf_data folder which is inside alfresco home folder.
Step 3 ::Now we need to take the dump from the postgres database .For that manually start the postgres server. For that use command
$pg_ctl start -D [Database location]
Example: pg_ctl start -D /opt/alf3.4.3/postgresql
-->Now go to location {ALFRESCO_HOME}/postgresql/bin and run the command
$./pg_dump -U [username] [Database Name] > output.backup
Now we have database dump in output.backup file and copy of alf_data.Lets restore dump on new alfresco server.
Restore the dump to other alfresco server
I am assuming that new fresh alfresco server is using inbuilt postgres database.For restoring the dump follow the below steps.
Step 1::First we need to drop the database of the new server.For that Go to location {ALFRESCO_HOME}/postgresql/bin and run the command
$./dropdb -U alfresco alfresco
Now we have dropped the database and we need to create a new database.
Step 2: Create a new database. For that do following steps.
-->execute the command on command prompt ::
$./psql
It will ask for password :: (Enter the password of default user postgres)
--> create database named alfresco :: run below commands.
#postgres > CREATE DATABASE alfresco WITH OWNER = alfresco TABLESPACE = pg_default
#postgres > \q (Quiting the postgres)
Step 3 :: Restoring the database from the dump file.For that go to location {ALFRESCO_HOME}/postgresql/bin and run the following command.
$./psql -U alfresco -f [backup file]
Step 4:: Copy all the contents alf_data except postgresql folder to alf_data.
Step 5 :: Restart the alfresco server.
The permission for postgresql folder under alf_data should be 700 and the owner of the folder should start the server.
Thats it !!!!!!!!!!we have restored the dump on new alfresco server.