Thursday, January 5, 2017

Category checking to particular DLFile in liferay

This blog will help you to check the particular categorie assigned to DLFile or not, and also helps to fectch all the categories from database,

import com.liferay.portlet.asset.model.AssetCategory;
import com.liferay.portal.kernel.dao.orm.DynamicQuery;
import com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil;
import com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil;

 List categoryList = null;
//Using dynamic query to fetch all the categories with the name "IMTHIYAZ"
DynamicQuery query = DynamicQueryFactoryUtil.forClass(AssetCategory.class).add(PropertyFactoryUtil.forName("name").eq("IMTHIYAZ"));
               categoryList = AssetCategoryLocalServiceUtil.dynamicQuery(query, 0,1);
//Result list contains all the list of AssetCategory Objects with the Name "IMTHIYAZ"

import com.liferay.portlet.documentlibrary.model.DLFileEntry;
import com.liferay.portlet.asset.model.AssetEntry;

AssetEntry assetentry = null;
DLFileEntry fileEntryObj ; Assuming this object conatins file
//getting assetentry of particular file
 assetentry = AssetEntryLocalServiceUtil.getEntry( DLFileEntry.class.getName(), fileEntryObj.getPrimaryKey());
//fetching all categories of particular assetentry
long assetCategoryId[] = assetentry.getCategoryIds();
List assetCategories = assetentry.getCategories();
 if(assetCategories.contains(categoryList.get(0))){
//This file contains IMTHIYAZ category
}

1 comment:

Unknown said...


Its very useful to me. Wonderful blog.. Thanks for sharing informative Post.

Installment loans
Payday loans
Title loans

Liferay DXP JNDI Data Source Cofiguration

 This Blog will help us to learn about the JNDI Data Source Configuration in Liferay DXP. We have tested this with Liferay 7.3 with Tomcat. ...