Foros de discusión
How to add Related Asset to web content?
Gwowen Fu, modificado hace 11 años.
How to add Related Asset to web content?
Expert Mensajes: 315 Fecha de incorporación: 27/12/10 Mensajes recientes
Hi,
Is this the right wayto add related asset (Bookmark) to web content?
Is there an better way, looks like this could be done in one call? Something like article.setRelatedAsset(bookmarkID).
Any help is appreciated!!!
Gwowen
Is this the right wayto add related asset (Bookmark) to web content?
AssetEntry assetEntry = AssetEntryLocalServiceUtil.createAssetEntry(getNextPK());
assetEntry.setClassPK(currentArticle.getClassPK());
AssetEntryLocalServiceUtil.addAssetEntry(assetEntry);
AssetLink assetLink = AssetLinkLocalServiceUtil.createAssetLink(getNextPK());
assetLink.setEntryId1(assetEntry.getEntryId());
assetLink.setEntryId2(bookmarkEntryID);
AssetLinkLocalServiceUtil.addAssetLink(assetLink);
Is there an better way, looks like this could be done in one call? Something like article.setRelatedAsset(bookmarkID).
Any help is appreciated!!!
Gwowen
Gwowen Fu, modificado hace 11 años.
RE: How to add Related Asset to web content?
Expert Mensajes: 315 Fecha de incorporación: 27/12/10 Mensajes recientes
Just to share what I have done to set a related asset bookmark for a journal article.
private void setRelatedAsset(final JournalArticle article, final String bookmarkName, final long userId, final long companyId) {
AssetEntry articleEntry, bookmarkEntry;
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(BookmarksEntry.class, PortalClassLoaderUtil.getClassLoader());
DynamicQuery assetLinkDynamicQuery = DynamicQueryFactoryUtil.forClass(AssetLinkModel.class, PortalClassLoaderUtil.getClassLoader());
try {
dynamicQuery.add(PropertyFactoryUtil.forName("name").eq(bookmarkName));
list = BookmarksEntryLocalServiceUtil.dynamicQuery(dynamicQuery);
for (BookmarksEntry bookmark : list) {
articleEntry = AssetEntryLocalServiceUtil.getEntry(JournalArticle.class.getName(), article.getResourcePrimKey());
bookmarkEntry = AssetEntryLocalServiceUtil.getEntry(BookmarksEntry.class.getName(), bookmark.getEntryId());
assetLinkDynamicQuery.add(PropertyFactoryUtil.forName("entryId1").eq(articleEntry.getEntryId()));
assetLinkDynamicQuery.add(PropertyFactoryUtil.forName("entryId2").eq(bookmarkEntry.getEntryId()));
list = AssetLinkLocalServiceUtil.dynamicQuery(assetLinkDynamicQuery);
if (list.size() == 0) {
AssetLinkLocalServiceUtil.addLink(userId, articleEntry.getEntryId(), bookmarkEntry.getEntryId(), 0, 0);
}
}
}
catch (PortalException e) {
e.printStackTrace();
}
catch (SystemException e) {
e.printStackTrace();
}
}