Friday, 31 March 2017

Select folder from document library in custom portlet

 To get specific folder folderId from Document media folders hierarchy.

 Need to do, like that other than using loops.

Step-1  Make your folders hierarchy.

public static final String  Base_Folder= "Documents/ABC/XYZ";

In this Base_Folder Variable we need to get FolderId to XYZ folder

    public static long getBaseLiferayFolderId(long groupId) throws PortalException,
     SystemException {
        //here we are geting parentFolderId
      String liferayBasePath = Base_Folder;
      long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
      List<String> folderNames = Arrays.asList(liferayBasePath.split(StringPool.SLASH));
      for (String folderName : folderNames) {
       if (!StringPool.BLANK.equalsIgnoreCase(folderName)) {
        parentFolderId = DLFolderLocalServiceUtil.getFolder(groupId, parentFolderId, folderName).getFolderId();
       }
      }
      return parentFolderId;
     }

Thursday, 30 March 2017

Run liferay on other then default root context

Simple 5 steps to change the context

 

Step1: Rename the folder ROOT dir to yours own context name(Example: liferay)

Step2: Rename file ROOT.xml to liferay.xml in %LIFERAY-HOME%\conf\Catalina\localhost

Step3: Create empty Directory/Folder ROOT in %LIFERAY-HOME%\webapps\

Step4:

Original Code

<Context path="" crossContext="true">
    ......
        ....................
</Context>
 

Modified Code

 
<Context path="/liferay" crossContext="true">
    ......
        ....................
</Context>
 
Step5: Create file portal-ext.properties in %LIFERAY-HOME%\webapps\liferay\WEB_INF\classes\

copy paste the below code

portal.ctx=/liferay
 

 

Wednesday, 29 March 2017

Different ways of getting a Journal Article Content in LIFERAY

This blog helps you to fetch the “Journal Article Content “or “web content “in different ways based upon our requirement.

(i) Getting the Journal Article of Particular Name :-

String articleName =  “sourabh”;// I need the sourabh web content details

String content = StringPool.BLANK;

JournalArticlejournalArticle = JournalArticleLocalServiceUtil.getArticleByUrlTitle (themeDisplay.getScopeGroupId(), articleName);// getting the journalArticle Object based on name

String articleId = journalArticle.getArticleId();

JournalArticleDisplayarticleDisplay =  JournalContentUtil.getDisplay (themeDisplay.getScopeGroupId(), articleId,””,themeDisplay.getLanguageId(),themeDisplay);

content = articleDisplay.getContent();// by using display content object I am fetching the data of my sourabh Web content.

 

(ii) Getting the Journal Article based on Tag Name :-

 

If we want to fetch the specific tag based web content details then the following code will be useful.

 

String content = StringPool.BLANK;

AssetTagassetTag = AssetTagLocalServiceUtil.getTag(themeDisplay.getScopeGroupId(), “mytagname”);
long assetTagId = assetTag.getTagId();
List assetEntrylist = AssetEntryLocalServiceUtil.getAssetTagAssetEntries(assetTagId);

for(AssetEntryassetEntry : assetEntrylist) {
JournalArticleResourcejournalArticleResourceObj = JournalArticleResourceLocalServiceUtil.getJournalArticleResource(assetEntry.getClassPK());
JournalArticlejournalArticleObj = JournalArticleLocalServiceUtil.getArticle(themeDisplay.getScopeGroupId(),journalArticleResourceObj.getArticleId());
String articleId = journalArticleObj.getArticleId();
JournalArticleDisplayarticleDisplay =  JournalContentUtil.getDisplay (themeDisplay.getScopeGroupId(), articleId,””,themeDisplay.getLanguageId(),themeDisplay);
content = articleDisplay.getContent();

}

 

(iii) Getting the Journal Article based on Structure Id or Template Id:-

 

If we want to fetch the specific Structure of template based web content details then the following code will be useful.


String content = StringPool.BLANK;
List articleList = JournalArticleLocalServiceUtil.getStructureArticles(themeDisplay.getScopeGroupId(), “tagId”);
// for template use API  getTemplateArticles
for(JournalArticlejournalArticle : articleList) {

String articleId = journalArticle.getArticleId();

JournalArticleDisplayarticleDisplay =  JournalContentUtil.getDisplay (themeDisplay.getScopeGroupId(), articleId,””,themeDisplay.getLanguageId(),themeDisplay);

content = articleDisplay.getContent();
}

 

(iv) Fetching the Journal Article content in template file in Liferay

 

If we want to fetch the journal article of web content details in template file then the following code will be useful. 

The following code will shows the tag based journal Article content in template.

 

#set($assetTag =$serviceLocator.findService(‘com.liferay.portlet.asset.service.AssetTagLocalService’))
#set($assetEntryService =$serviceLocator.findService(‘com.liferay.portlet.asset.service.AssetEntryLocalService’))
#set($journalArticleResourceLocal=$serviceLocator.findService(‘com.liferay.portlet.journal.service.JournalArticleResourceLocalService’))
#set($journalArticleLocal=$serviceLocator.findService(‘com.liferay.portlet.journal.service.JournalArticleLocalService’))
#set($journalContentUtil =$utilLocator.findUtil(‘com.liferay.portlet.journalcontent.util.JournalContent’))
#set($groupId = $getterUtil.getLong($groupId))
#set($languageId = $request.theme-display.language-id)

#set($assetTagObj=$assetTag.getTag($groupId,”myTag”))
#set($assetId = $assetTagObj.getTagId())
#set($assestList= $assetEntryService.getAssetTagAssetEntries($assetId))
#set($assetEntry = “”)
#foreach($assetEntry in $assestList)
#set($journalArticleResource =$journalArticleResourceLocal.getJournalArticleResource($assetEntry.getClassPK()))
#set($journalArticle = $journalArticleLocal.getArticle($groupId,$journalArticleResource.getArticleId()))
#set($latestArticle= $journalArticleLocal.getLatestArticle($groupId,$journalArticle.getArticleId()))
#set( $journalArticleDisplay= $journalContentUtil.getDisplay($groupId,$latestArticle.getArticleId(), null,null,$languageId,null, 1, $xmlRequest))
$journalArticleDisplay.getContent()
#end