Message Boards

get the category from journal article

liron bar, modified 12 Years ago.

get the category from journal article

Junior Member Posts: 29 Join Date: 9/28/11 Recent Posts
hello,

i want to display journal article by a given category.
so i'm trying to get from the journal article object his categiries

my question is how do i do it.

i saw in the forum this example:
List<AssetCategory> categories = AssetCategoryServiceUtil.getCategories(JournalArticle.class.getName(), new Long(article1.getArticleId()).longValue());

but it doesnt work.

can anyone help me?

thanks!
liron
thumbnail
Ravi Kumar Gupta, modified 12 Years ago.

RE: get the category from journal article

Liferay Legend Posts: 1302 Join Date: 6/24/09 Recent Posts
Try with AssetCategoryLocalServiceUtil and article.getId() in place of getArticleId
liron bar, modified 12 Years ago.

RE: get the category from journal article

Junior Member Posts: 29 Join Date: 9/28/11 Recent Posts
thaks for the quick response!

but it's still not working...
liron bar, modified 12 Years ago.

RE: get the category from journal article

Junior Member Posts: 29 Join Date: 9/28/11 Recent Posts
i found the problem,

this is the right way:
List<AssetCategory> categories = AssetCategoryLocalServiceUtil.getCategories(JournalArticle.class.getName(), article1.getResourcePrimKey());

enjoy emoticon
thumbnail
Ravi Kumar Gupta, modified 12 Years ago.

RE: get the category from journal article

Liferay Legend Posts: 1302 Join Date: 6/24/09 Recent Posts
hmm.. thanks for this... i was trying with id, primaryKey, articleId but could not see the resourcePrimKey... will remember this now.. emoticon
shima shima, modified 9 Years ago.

RE: get the category from journal article

Junior Member Posts: 46 Join Date: 4/14/14 Recent Posts
hi Liron
would u plz explain it more. I use liferay 6.2 and free marker .I have used it as this
<#assign article = assetRenderer.getArticle() >
<#assign AssetCategoryLocalService = serviceLocator.findService("com.liferay.portlet.asset.service.AssetCategoryLocalService")>
<#assign categories = AssetCategoryLocalService.getCategories(JournalArticle.class.getName(), article.getResourcePrimKey())/>
but it dose not realize journalArticle
Heiko Ottenbacher, modified 9 Years ago.

RE: get the category from journal article

New Member Posts: 20 Join Date: 9/5/14 Recent Posts
Hello everybody,

I am trying to get the category from a webcontent article using exactly the way u show here :

List<assetcategory> categories = AssetCategoryLocalServiceUtil.getCategories( JournalArticle.class.getName(), oneArt.getResourcePrimKey() );</assetcategory>


But I always get an empty list.

I assign the category (actually I can only select one, so it is a bit curious that above method returns a list ;))) by using Content->Web Content -> Categorization and then selecting News from the Select-Box.

So - am I using liferay wrong? Is it the wrong usage of API? Or is it a bug? ;)

Thanks a lot!

Regards, Heiko
thumbnail
Manali Lalaji, modified 9 Years ago.

RE: get the category from journal article

Expert Posts: 362 Join Date: 3/9/10 Recent Posts
Heiko Ottenbacher:
Hello everybody,

I am trying to get the category from a webcontent article using exactly the way u show here :

List<assetcategory> categories = AssetCategoryLocalServiceUtil.getCategories( JournalArticle.class.getName(), oneArt.getResourcePrimKey() );</assetcategory>


But I always get an empty list.

I assign the category (actually I can only select one, so it is a bit curious that above method returns a list ;))) by using Content->Web Content -> Categorization and then selecting News from the Select-Box.

So - am I using liferay wrong? Is it the wrong usage of API? Or is it a bug? ;)

Thanks a lot!

Regards, Heiko


Hi,

I think above code shall give you entire information of categories associated with article.

You can try below code, which gives categoryNames:


String[] categoryName = AssetCategoryLocalServiceUtil.getCategoryNames(JournalArticle.class.getName(), 13607); // replace with your classPK
System.out.println(Arrays.toString(categoryName));
thumbnail
Nagendra Kumar Busam, modified 9 Years ago.

RE: R: get the category from journal article

Liferay Master Posts: 678 Join Date: 7/7/09 Recent Posts
It seems Heiko talking about web content type under categorization section - you are speaking about categories/tags related pop up
Heiko Ottenbacher, modified 9 Years ago.

RE: R: get the category from journal article

New Member Posts: 20 Join Date: 9/5/14 Recent Posts
Thanks Nagendra, thanks Manali for ur help. Nagendra, you are totally right - and with the help of ur example it works now using a Dynamic Query instead of trying to filter it on the fly!

Regards, Heiko
thumbnail
Nagendra Kumar Busam, modified 9 Years ago.

R: get the category from journal article

Liferay Master Posts: 678 Join Date: 7/7/09 Recent Posts
Heiko,

I think here solution is for asset category selector - they are referring to pop up of categories which is near tags. Not the journal article's type - news/test.

I didn't find one direct method to get articles by type.

You can give it a try with one of search overloaded methods. One more option is dynamic query ( these you can try with JournalArticleLocalServiceUtil). Another have a look at AssetEntryQuery.

Sent from my iPhone with Liferay.com Forums
thumbnail
Nagendra Kumar Busam, modified 9 Years ago.

R: get the category from journal article

Liferay Master Posts: 678 Join Date: 7/7/09 Recent Posts
Alberto Imaginanet, modified 3 Years ago.

RE: get the category from journal article

New Member Posts: 12 Join Date: 2/14/20 Recent Posts
Hi everyone! I'm looking for how delete one type of categories from all articles? If somebody know, please tell me.
Thanks!
thumbnail
Christoph Rabel, modified 3 Years ago.

RE: get the category from journal article

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
You shouldn't capture other peoples old threads. your question is different then the thread topic.
You could use AssetEntryLocalService.clearAssetCategoryAssetEntries(long categoryId) to delete all of them or fetch a list of entries getAssetCategoryAssetEntries, iterate through it and remove only some of them. Depends on your usecase.