Tuesday 30 October 2012

Finding RAM Size in Linux

Problem: Finding RAM size in Red Hat Linux
Solution: 
Top command gives you the RAM size
 
[root@dragon~]# top
top - 00:03:46 up 15:52,  1 user,  load average: 0.00, 0.00, 0.00
Tasks:  96 total,   2 running,  94 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.3%sy,  0.0%ni, 99.7%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   4044540k total,   688452k used,  3356088k free,   137140k buffers
Swap:  2064376k total,        0k used,  2064376k free,   380340k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 8289 root      15   0 12740 1068  808 R  0.3  0.0   0:00.03 top
    1 root      15   0 10348  684  572 S  0.0  0.0   0:00.97 init

Check in the meminfo file.
[root@dragon~]#  cat /proc/meminfo
MemTotal:      4044540 kB
MemFree:       3356088 kB
Buffers:        137140 kB
Cached:         380348 kB
SwapCached:          0 kB
Active:         308108 kB
Inactive:       312956 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:      4044540 kB
LowFree:       3356088 kB
SwapTotal:     2064376 kB
SwapFree:      2064376 kB
Dirty:              28 kB
Writeback:           0 kB

 

Getting all the assets related to a category Liferay

Problem: Want to list all the assets related to a category.
Solution: Below template takes category name as parameter in the URL and lists all the assets that relates to provided category


#set ($current_url = $request.get("attributes").CURRENT_COMPLETE_URL)
#set ($paramName='categoryName')
#set ($catName = $httpUtil.getParameter($current_url, $paramName))
#set ( $AssetCategoryLocalService = $serviceLocator.findService( "com.liferay.portlet.asset.service.AssetCategoryLocalService" ))
#set ( $CatListDQ = $AssetCategoryLocalService.getCategories() )
#foreach( $catItem in $CatListDQ )
    #if($catItem.getName()==$catName)
     #set ( $catId=$catItem.getCategoryId())
    #end
#end
#set ( $assetEntryQuery = $portal.getClass().forName( "com.liferay.portlet.asset.service.persistence.AssetEntryQuery" ).newInstance()) 
#set ( $V = $assetEntryQuery.setAllCategoryIds( $catId))
#set ( $acsUtil = $portal.getClass().forName( "com.liferay.portlet.asset.service.AssetEntryLocalServiceUtil" ).newInstance()) 
#set ( $AssetEntryList = $acsUtil.getEntries( $assetEntryQuery ))
#foreach( $asset in $AssetEntryList )
$asset.getTitle() 
#end

Sunday 21 October 2012

Web Content Display portlet to display article dynamically - Liferay

Problem: I want to use web content display portlet to display articles dynamically  (i.e) I will pass article-id as an argument to page and web content display portlet has to read the article-id and display the content.

Solution: 
The above problem can be solved by creating an template. Have the below script in your template.
Sample URL for page would be http://localhost:8080/web/carlovers/dynamic-page?articleId=10712
 
## Get Article Id from the request URL
#set ($current_url = $request.get("attributes").CURRENT_COMPLETE_URL)
#set ($paramName='articleId')
#set ($articleId = $httpUtil.getParameter($current_url, $paramName))
#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
## Get article based on article id
#set ($article = $journalArticleLocalService.getArticle($getterUtil.getLong($request.theme-display.scope-group-id),$articleId))

## display relavent information
$article.getUrlTitle()
$article.getContentByLocale($request.theme-display.language-id)



Setting browser title as article title - Liferay

Problem:  I want to set web content title (article title) as browser title in liferay.

Solution: Create a template for your web content and you can use predefined velocity variables like "$reserved-article-title.data" to get the title of the article that is currently displayed. Set the title to document.title

Example:
 



Monday 15 October 2012

Reading URL Parameters in Liferay template

Problem: Reading URL parameters that are passed to a page in web content display portlet.

Solution: Create a template for your web content and read url parameters in the template.

#set ($current_url = $request.get("attributes").CURRENT_COMPLETE_URL)
#set ($paramName='articleId')
#set ($articleId = $httpUtil.getParameter($current_url, $paramName))

In the above code we are trying to read url paramter articleId. Example URL is http://localhost:8080/web/carlovers/myhome?articleId=10740