use of com.liferay.asset.kernel.model.AssetEntry in project liferay-db-setup-core by ableneo.
the class TaggingUtil method associateTagsAndCategories.
public static void associateTagsAndCategories(long groupId, Article article, JournalArticle journalArticle) throws PortalException {
List<Tag> tags = article.getTag();
String[] tagNames = null;
if (tags != null) {
tagNames = tags.stream().map(Tag::getName).toArray(String[]::new);
}
long[] categoryIds = article.getCategory().stream().map(category -> ResolverUtil.lookupAll(groupId, journalArticle.getCompanyId(), category.getUuid(), article.getPath())).filter(Validator::isNumber).mapToLong(Long::parseLong).toArray();
AssetEntry entry = AssetEntryLocalServiceUtil.getEntry(JournalArticle.class.getName(), journalArticle.getResourcePrimKey());
AssetEntryLocalServiceUtil.updateEntry(SetupConfigurationThreadLocal.getRunAsUserId(), groupId, JournalArticle.class.getName(), entry.getClassPK(), categoryIds, tagNames);
}
use of com.liferay.asset.kernel.model.AssetEntry in project liferay-db-setup-core by ableneo.
the class SetupArticles method processRelatedAssets.
public static void processRelatedAssets(final Article article, final JournalArticle ja, final long runAsUserId, final long groupId, final long companyId) {
if (article.getRelatedAssets() != null) {
RelatedAssets ras = article.getRelatedAssets();
AssetEntry ae = null;
if (ras.isClearAllAssets()) {
try {
ae = AssetEntryLocalServiceUtil.getEntry(JournalArticle.class.getName(), ja.getResourcePrimKey());
AssetLinkLocalServiceUtil.deleteLinks(ae.getEntryId());
} catch (PortalException | SystemException e) {
LOG.error(String.format("Problem clearing related assets of article %1$s", ja.getArticleId()), e);
}
}
if (ras.getRelatedAsset() != null && !ras.getRelatedAsset().isEmpty()) {
List<RelatedAsset> ra = ras.getRelatedAsset();
for (RelatedAsset r : ra) {
String clazz = r.getAssetClass();
String clazzPrimKey = r.getAssetClassPrimaryKey();
String resolverHint = "Related asset for article " + ja.getArticleId() + " clazz " + clazz + ", " + "primary key " + clazzPrimKey;
clazzPrimKey = ResolverUtil.lookupAll(groupId, companyId, clazzPrimKey, resolverHint);
long id = 0;
try {
id = Long.parseLong(clazzPrimKey);
} catch (Exception ex) {
LOG.error("Class primary key is not parseable as long value.", ex);
}
try {
AssetEntry ae2 = AssetEntryLocalServiceUtil.getEntry(clazz, id);
AssetLinkLocalServiceUtil.addLink(runAsUserId, ae.getEntryId(), ae2.getEntryId(), AssetLinkConstants.TYPE_RELATED, 1);
} catch (PortalException | SystemException e) {
LOG.error("Problem resolving related asset of article " + ja.getArticleId() + " with clazz " + clazz + " primary key " + clazzPrimKey, e);
}
}
}
}
}
Aggregations