掲示板
How to add Related Asset to web content?
10年前 に Gwowen Fu によって更新されました。
How to add Related Asset to web content?
Expert 投稿: 315 参加年月日: 10/12/27 最新の投稿
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
10年前 に Gwowen Fu によって更新されました。
RE: How to add Related Asset to web content?
Expert 投稿: 315 参加年月日: 10/12/27 最新の投稿
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();
}
}