Monday, 20 April 2015

Alfresco OOTB Webscript to search folders/contents by path

For searching alfresco contents/folders, we have a couple of webscripts readily available which are exposed by alfresco out of the box.
We can search the contents or folders just by hitting the following search URLs and we can get the appropriate response which we can parse and
get the required metadata.


http://localhost:8080/alfresco/service/api/search/keyword.atom?q={searchTerms}&p={startPage?}&c={count?}&l={language?}
(In above url, you can pick keyword.atom, keyword.rss, keyword.html, keyword.portlet, anyone based on your response/parsing needs.)

Apart from this, there is one more OOTB search webscript used by alfresco:

http://localhost:8080/alfresco/service/slingshot/search?term={term?}&tag={tag?}&site={site?}&container={container?}&sort={sort?}&query={query?}&repo={repo?}

In this URL, there are a few parameters which are not exposed for passing parameters into.
You can look at those parameters by exploring the search.get.js file and further search.lib.js.

Here, you will find parameters like rootNode, maxResults, sort, pageSize, startIndex - which facilities specific folder level search, limiting the search
result, sorting, pagination, etc.

For someone who would like to search in a folder (lets say - Company Home > XYZ > MyFolder), can pick up the nodeRef of MyFolder and pass its value in the
rootNode parameter which would restrict the search inside MyFolder only.
Also, by default this webscript would conduct a search inside all the sites created in alfresco share. So you would also need to pass repo=true for conducting
search inside Company Home > XYZ > MyFolder; else the search would be conducted inside Company Home > Sites folder.

Example URL:

http://localhost:8080/alfresco/service/slingshot/search?term=alfresco&repo=true&pageSize=10&startIndex=0&maxResults=100&rootNode=workspace://SpacesStore/1bcef6d2-792d-4224-9f98-2438b93e76a5

Please note that the user who will call this webscript URL, should have atleast consumer (view) rights on the noderef that he is going to pass in the value of rootNode parameter.

If the nodeRef value he passes in rootNode parameter is something on which he doesnot have permissions, then
the search will return all the results that matches with the keyword (without checking any permission).

Also, if you are looking for all contents/folders inside a folder, then you can pass
"*" in the term parameter (i.e term=*) which will give all results (with permissions checked).


Thank you for going through the blog.
Hope this may be helpful to you.

Monday, 6 April 2015

Thumbnail generation failing in alfresco

Many of us might be facing issues in alfresco while generating thumbnails for uploaded files.
My alfresco version : Alfresco 4.2.f Community Edition

I have just applied an inbound rule on a folder in alfresco which 'Executes a script' named 'generateThumbnail.js' when a file
is uploaded in that space.

Code in js:
document.createThumbnail("doclib", true);
document.save();

I was facing a problem that for all other mimetypes except images, the thumbnail was not generated in alfresco.
I was getting 'Creation of thumbnail 'doclib' failed' error.

The issue in my case was : The path of imagemagick was incorrectly picked up.
I had previously installed an ephesoft instance on my local machine (Windows 7 64-bit);
which had set multiple paths in my environment variables and had set a couple of entries in windows registry.
This made alfresco pick up incorrect path of imagemagick everytime from windows registry.
I had to go to the registry (edit/modify the path set) and give my alfresco's imagemagick path.
This worked for me.

Reference Link : http://www.imagemagick.org/discourse-server/viewtopic.php?t=15056#p52945


In some other scenarios, where you might face this issue, you can try some of the following steps:

1) Make sure your thumbnail generation property is set to true (you will find it in repository.properties if not overridden; if you have
   overridden it then it may exist in alfresco-global.properties):
   system.thumbnail.generate=true 

   Based on the file(s) size you upload; there are a certain properties which are defaulted to -1.
   Check them based on your requirement.

    # Default thumbnail limits
# When creating thumbnails, only use the first pageLimit pages
system.thumbnail.definition.default.timeoutMs=-1
system.thumbnail.definition.default.readLimitTimeMs=-1
system.thumbnail.definition.default.maxSourceSizeKBytes=-1
system.thumbnail.definition.default.readLimitKBytes=-1
system.thumbnail.definition.default.pageLimit=1
system.thumbnail.definition.default.maxPages=-1

# Max mimetype sizes to create thumbnail icons
system.thumbnail.mimetype.maxSourceSizeKBytes.pdf=-1
system.thumbnail.mimetype.maxSourceSizeKBytes.txt=-1
system.thumbnail.mimetype.maxSourceSizeKBytes.docx=-1
system.thumbnail.mimetype.maxSourceSizeKBytes.xlsx=-1
system.thumbnail.mimetype.maxSourceSizeKBytes.pptx=-1
system.thumbnail.mimetype.maxSourceSizeKBytes.odt=-1
system.thumbnail.mimetype.maxSourceSizeKBytes.ods=-1
system.thumbnail.mimetype.maxSourceSizeKBytes.odp=-1



2) Check the alfresco logs which may be trying to point out something related to root cause.
   Enable transformer debug in log4j.properties to get the transformation logs:
log4j.logger.org.alfresco.repo.content.transform.TransformerDebug=DEBUG

3) Verify the path of your imagemagick is correct and alfresco is not picking up some other imagemagick instance (which may be an older version or
   may not be compatible with your alfresco version)

4) You can try switching from OOoDirect to JODConvertor; by setting the following properties to true|false and vice versa.
   ooo.enabled=false
   jodconverter.enabled=true

5) You can update some binaries or libraries used by Imagemagick to newer version.

6) Also check that you are not getting the error - An initial OpenOffice connection could not be established.
   In this case, you need to check your openoffice connection. The following link has some pointers :
   https://forums.alfresco.com/forum/installation-upgrades-configuration-integration/configuration/share-document-preview-fails

7) In some cases, you may try reinstalling imagemagick :
   http://docs.alfresco.com/4.1/tasks/imagemagick-config.html

8) For Windows/ImageMagick 6.5.x issue and other related issues, you can go through : https://wiki.alfresco.com/wiki/ImageMagick_Configuration

9) Some ImageMagick configuration file related stuff can be found at :
   http://www.imagemagick.org/script/resources.php

10) For normal content transformation problems and limits in alfresco, I think this is the best link :
   https://wiki.alfresco.com/wiki/Content_Transformation_Limits

11) For some scenarios, this link be useful :
http://keytocontent.blogspot.in/2010/03/reviving-alfresco-share-thumbnail-and.html

Thank you for going through the blog.

Tuesday, 13 January 2015

Integration of CKEditor in Alfresco 4.2.2


The following steps are required to be performed in order to integrate CKEditor in Alfresco 4.2.2.

Steps :

     1)     
      Add the entries mentioned in ckeditor-config-custom.xml in your share-config-custom.xml. Location of ckeditor-config-custom.xml :

After performing step 1, edit your share-config-custom.xml file (shared\classes\alfresco\web-extension) and add the following code in it.
                     <dependencies>
                                                                <js src="/modules/editors/ckeditor/ckeditor.js" />
                                                                <js src="/components/editors/ckeditor/ckeditorloader.js" />
                        </dependencies>
        So your share-config-custom.xml would look something like :
<alfresco-config>
 
   <!-- cm:content type (existing nodes) -->
   <config evaluator="node-type" condition="cm:content">
      <forms>
           <dependencies>
               <js src="/modules/editors/ckeditor/ckeditor.js" />
               <js src="/components/editors/ckeditor/ckeditorloader.js" />
           </dependencies>
        <form>
        <field-visibility>
               <show id="cm:name" />
               …
               …
Also add the above <dependencies…/> in the following <config> section.
<config evaluator="model-type" condition="cm:content">
    2)     
      Now I am assuming that you already have the JAR file (downloaded from https://code.google.com/p/share-extras/downloads/detail?name=ckeditor-form-control-0.2.jar&can=2&q=
OR
    3)      
      Extract/Open the JAR to a temporary location and start putting the contents inside it in your extension environment of Alfresco 4.2.2. NOTE: Do it carefully if you already have some other customized files added in your extension environment. Don’t directly copy the folders. Copy the custom files one by one. That is :
    4)     
     Copy  \ckeditor-form-control-0.2\alfresco\messages\   to   shared\classes\alfresco\messages\
    5)    
          Copy  \ckeditor-form-control-0.2\alfresco\site-data\   to   shared\classes\alfresco\web-extension\site-data\
    6)    
           Copy  \ ckeditor-form-control-0.2\alfresco\site-webscripts\  to  shared\classes\alfresco\web-extension\site-webscripts\
    7)    
         Copy \ ckeditor-form-control-0.2\alfresco\templates\   to   shared\classes\alfresco\web-extension\templates\
    8)    
          Copy \ ckeditor-form-control-0.2\org\springframework\extensions\surf\  to   tomcat\webapps\share\WEB-INF\classes\org\springframework\extensions\surf\
Comment out the values from the list of <property name=”configs”> that are not required.
It should be fine if you just keep this single entry :

 <value>classpath:alfresco/web-extension/ckeditor-config-custom.xml</value>

And comment out the rest (other two).
As you make this entry, you would need to put the file (ckeditor-config-custom.xml - http://share-extras.googlecode.com/svn/trunk/CKEditor%20Form%20Control/ckeditor-config-custom.xml.sample) in your shared\classes\alfresco\web-extension.
But as you already have made the entry (of the contents inside it) in your share-config-custom.xml; you may rename it to ckeditor-config-custom.xml.sample.

   9)    
        Copy ckeditor-form-control-0.2\META-INF\components\editors\    to   tomcat\webapps\share\components\editors\
   10)  
     Copy ckeditor-form-control-0.2\META-INF\modules\editors\ckeditor\   to   tomcat\webapps\share\modules\editors\ckeditor\
Also copy  ckeditor-form-control-0.2\META-INF\components\   to  shared\classes\alfresco\web-extension\site-webscripts\
And
Copy  ckeditor-form-control-0.2\META-INF\modules\   to   tomcat\shared\classes\alfresco\web-extension\site-webscripts\

   11)  
     The most important step – put the entries of your custom js and css files for ckeditor in form.js.ftl and form.css.ftl.
Location of form.js.ftl  &  form.css.ftl  - tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\form\

The following entries will go inside form.js.ftl :

<@script type="text/javascript" src="${url.context}/res/components/editors/ckeditor/ckeditorloader.js" group="form"/>
<@script type="text/javascript" src="${url.context}/res/components/editors/ckeditor/config.js" group="form"/>
<@script type="text/javascript" src="${url.context}/res/modules/editors/ckeditor/ckeditor.js" group="form"/>
<@script type="text/javascript" src="${url.context}/res/modules/editors/ckeditor/config.js" group="form"/>
<@script type="text/javascript" src="${url.context}/res/modules/editors/ckeditor/lang/en.js" group="form"/>
<@script type="text/javascript" src="${url.context}/res/modules/editors/ckeditor/plugins/image/dialogs/image.js" group="form"/>
<@script type="text/javascript" src="${url.context}/res/modules/editors/ckeditor/plugins/styles/styles/default.js" group="form"/>

The following entries will go inside form.css.ftl:

<@link href="${url.context}/res/modules/editors/ckeditor/skins/kama/editor.css" group="form"/>
<@link href="${url.context}/res/modules/editors/ckeditor/skins/kama/dialog.css" group="form"/>
<@link href="${url.context}/res/modules/editors/ckeditor/contents.css" group="form"/>

In previous alfresco versions, the above entries were made in form.get.head.ftl but from 4.2.2 onwards it is deprecated; so we need to put the entries here (form.js.ftl and form.css.ftl).  It would be even great if we can override the above files and put them in extension environment.

   12)  
       Restart the server and check by creating a new HTML file or editing an existing HTML file (inline-edit).  If you have already restarted the server before, you don’t need to restart it again after making the above entries. Just refresh the webscripts from http://server:port/share/service/index and check the functionality.

Courtesy :

     a)      JAR download location :   https://addons.alfresco.com/addons/ckeditor-form-control

     b)      Source code :  https://github.com/share-extras/ckeditor-forms


*Directly putting the JAR into shared/lib and adding the ckeditor-config-custom.xml file in extension environment  didn’t work; so I have followed the manual procedure of putting the custom files in ext envt.

Thank you for going through the blog.

Also do provide your inputs/suggestions/feedback on this.