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.