Foros de discusión

Updating Web Content Categories Programmatically

Xav NYC, modificado hace 11 años.

Updating Web Content Categories Programmatically

New Member Mensajes: 23 Fecha de incorporación: 27/09/12 Mensajes recientes
Hi,
I'm trying to achieve the following workflow:
  • Users capture web content in a structure
  • The Velocity template linked to the structure calls an external webservice to enrich the information based on the captured fields.
  • The template calls internal webservices to assign categories based on the results returned by the external webservice


I have managed 1 and 2 but I'm struggling to find the right api to set the categories.
I found on this forum how to get the categories for a given asset (see code below) but I can't find in the javadocs how to SET them.

Any help appreciated.

Xav.


#set($journalLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))

 #set($scopeId = $request.theme-display.scope-group-id)
 
 ## get article's primaryKey
 ## NOTE: be careful about input parameters types should match
 #set($articlePrimKey = $journalLocalService.getArticle($getterUtil.getLong($scopeId), $reserved-article-id.data).resourcePrimKey)
 
#set($catLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetCategoryLocalService"))
 
## get article's category names by primaryKey
#set($articleCatNames = $catLocalService.getCategoryNames("com.liferay.portlet.journal.model.JournalArticle", $getterUtil.getLong($articlePrimKey)))

<div>Article Categories: 
        <span>
            #foreach ($catName in $articleCatNames)
                $catName 
            #end
        </span>
</div>
Xav NYC, modificado hace 11 años.

RE: Updating Web Content Categories Programmatically

New Member Mensajes: 23 Fecha de incorporación: 27/09/12 Mensajes recientes
I made some progress but I'm not there yet.
I Managed to use

#set ($assetEntryPersistence = $serviceLocator.findService("com.liferay.portlet.asset.service.persistence.AssetEntryPersistence" )) 
#set ($assetCategoryPersistence = $assetEntryPersistence.addAssetCategory($getterUtil.getLong($articlePrimKey),$getterUtil.getLong("230738")))


It does populate assetentries_assetcategories table in the background but the the primary key of the journal article is not the coorect value. Empirically I managed to determine that the correct value was in my case $articlePrimKey + 2.
I suspect that it's the asset primary key.

Hence my question : How can I get the primary ley of the asset from the primary key of the journal article?

Thanks in advance.
Xav NYC, modificado hace 11 años.

RE: Updating Web Content Categories Programmatically

New Member Mensajes: 23 Fecha de incorporación: 27/09/12 Mensajes recientes
I figured out how to get the asset Id using the following service in a velocity template

#set ($assetEntryPersistence = $serviceLocator.findService("com.liferay.portlet.asset.service.persistence.AssetEntryPersistence" )) 
#set ($assetEntryId = $assetEntryPersistence.findByC_C($getterUtil.getLong("10108"),$getterUtil.getLong($articlePrimKey)))
$assetEntryId.entryId


For now the classNameId is hardcoded (10108) but a call to ClassNameLocalServiceUtil.getClassNameId() should do the trick.