Foren

Programmatically creating tags for an asset

zzzz8 zzzz8, geändert vor 13 Jahren.

Programmatically creating tags for an asset

Junior Member Beiträge: 62 Beitrittsdatum: 11.11.08 Neueste Beiträge
I've searched far and wide in the Liferay Forums and search engines trying to find code that demonstrates how one would programmatically create tags for a particular asset. Unfortunately, I cannot find that snippet of code. I'm currently using Liferay 5.2.3 and developing custom portlets (Seam portlets, in particular - but that's probably not important).

I have an entity that I want to treat as an asset. It has a particular class name and primary key. I don't have trouble with other Liferay classes such as SocialActivityLocalServiceUtil (e.g. in creating social activities associated with a particular classname/primary key combo), but I cannot figure out how it works for the TagsAssetLocalServiceUtil. I was thinking of using the addTagsAsset method for a new asset - but I have to pass it a TagsAsset class. I was going to use TagsAssetImpl, but then it looks as though I need to set the asset ID. Where would I set the asset ID.

And even after someone will hopefully help me to figure out how to add an asset into the TagsAsset table, how does one add one or more tags for an asset? I looked at the API but couldn't really tell. Would I call updateAsset method and pass an array of entryNames that represent an array of tags? If I wanted to remove tags for this asset, would I just pass null for that parameter?

The documentation just seems to be sparse and nonexistent - and looking through the TagsAssetLocalServiceImpl class left me even more confused. I would appreciate any pointers and especially any snippets of code. Thanks!
zzzz8 zzzz8, geändert vor 13 Jahren.

[RESOLVED] RE: Programmatically creating tags for an asset

Junior Member Beiträge: 62 Beitrittsdatum: 11.11.08 Neueste Beiträge
OK, I found the solution to this issue. All one needs to do is using the updateAsset method in TagsAssetLocalServiceUtil. I used the "simplest" overloaded updateAsset method:

TagsAssetLocalServiceUtil.updateAsset(long userId, long groupId, java.lang.String className, long classPK, java.lang.String[] categoryNames, java.lang.String[] entryNames)

If the asset does not already exist, it will be created and added to the TagsAsset table.

Unfortunately, I had to use up some time setting up breakpoints on Eclipse in the portal-impl code to figure out which method was being used. I tracked it down by creating a blog entry and setting a number of breakpoints and debugged the issue. The Javadocs nor the documentation certainly didn't shed light into which class/method to use. It should have stated that an asset record would be added to the TagAssets table if it did not already exist... The source code comments (or lack thereof) didn't help either. This is one of the most frustrating things for a Liferay novice like me who's trying to develop and work with it. The documentation is extremely lacking in numerous places. I looked at the source code and was astounded to see such few comments in the source code. For example, there are essentially no class or method level comments in the code. It must be a nightmare for a new employee to go into Liferay and understand the code (and make changes)... Just wanted to express some of my frustration. emoticon
thumbnail
technology evangelist, geändert vor 10 Jahren.

RE: [RESOLVED] RE: Programmatically creating tags for an asset

Junior Member Beiträge: 35 Beitrittsdatum: 02.08.13 Neueste Beiträge
lsli lsli:
OK, I found the solution to this issue. All one needs to do is using the updateAsset method in TagsAssetLocalServiceUtil. I used the "simplest" overloaded updateAsset method:

TagsAssetLocalServiceUtil.updateAsset(long userId, long groupId, java.lang.String className, long classPK, java.lang.String[] categoryNames, java.lang.String[] entryNames)

If the asset does not already exist, it will be created and added to the TagsAsset table.

Unfortunately, I had to use up some time setting up breakpoints on Eclipse in the portal-impl code to figure out which method was being used. I tracked it down by creating a blog entry and setting a number of breakpoints and debugged the issue. The Javadocs nor the documentation certainly didn't shed light into which class/method to use. It should have stated that an asset record would be added to the TagAssets table if it did not already exist... The source code comments (or lack thereof) didn't help either. This is one of the most frustrating things for a Liferay novice like me who's trying to develop and work with it. The documentation is extremely lacking in numerous places. I looked at the source code and was astounded to see such few comments in the source code. For example, there are essentially no class or method level comments in the code. It must be a nightmare for a new employee to go into Liferay and understand the code (and make changes)... Just wanted to express some of my frustration. emoticon




I agree all the things ,Even I also working on these task past one week,I can able to find single code snippet regarding these.People who having bunch year of experience is also not at all giving any comments reagrding these..

Best wishes