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
}
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
//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
if(assetCategories.contains(categoryList.get(0))){
//This file contains IMTHIYAZ category
}
1 comment:
Its very useful to me. Wonderful blog.. Thanks for sharing informative Post.
Installment loans
Payday loans
Title loans
Post a Comment