Search in sources :

Example 1 with AssetEntry

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);
}
Also used : NoSuchTagException(com.liferay.asset.kernel.exception.NoSuchTagException) LogFactoryUtil(com.liferay.portal.kernel.log.LogFactoryUtil) AssetTagLocalServiceUtil(com.liferay.asset.kernel.service.AssetTagLocalServiceUtil) AssetTag(com.liferay.asset.kernel.model.AssetTag) Validator(com.liferay.portal.kernel.util.Validator) ServiceContext(com.liferay.portal.kernel.service.ServiceContext) AssetEntryLocalServiceUtil(com.liferay.asset.kernel.service.AssetEntryLocalServiceUtil) Log(com.liferay.portal.kernel.log.Log) PortalException(com.liferay.portal.kernel.exception.PortalException) Tag(com.ableneo.liferay.portal.setup.domain.Tag) SystemException(com.liferay.portal.kernel.exception.SystemException) List(java.util.List) JournalArticle(com.liferay.journal.model.JournalArticle) SetupConfigurationThreadLocal(com.ableneo.liferay.portal.setup.SetupConfigurationThreadLocal) AssetEntry(com.liferay.asset.kernel.model.AssetEntry) Article(com.ableneo.liferay.portal.setup.domain.Article) AssetEntry(com.liferay.asset.kernel.model.AssetEntry) AssetTag(com.liferay.asset.kernel.model.AssetTag) Tag(com.ableneo.liferay.portal.setup.domain.Tag) Validator(com.liferay.portal.kernel.util.Validator) JournalArticle(com.liferay.journal.model.JournalArticle)

Example 2 with AssetEntry

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);
                }
            }
        }
    }
}
Also used : AssetEntry(com.liferay.asset.kernel.model.AssetEntry) RelatedAsset(com.ableneo.liferay.portal.setup.domain.RelatedAsset) SystemException(com.liferay.portal.kernel.exception.SystemException) RelatedAssets(com.ableneo.liferay.portal.setup.domain.RelatedAssets) PortalException(com.liferay.portal.kernel.exception.PortalException) TemplateDuplicateTemplateKeyException(com.liferay.dynamic.data.mapping.exception.TemplateDuplicateTemplateKeyException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) IOException(java.io.IOException)

Aggregations

AssetEntry (com.liferay.asset.kernel.model.AssetEntry)2 PortalException (com.liferay.portal.kernel.exception.PortalException)2 SystemException (com.liferay.portal.kernel.exception.SystemException)2 SetupConfigurationThreadLocal (com.ableneo.liferay.portal.setup.SetupConfigurationThreadLocal)1 Article (com.ableneo.liferay.portal.setup.domain.Article)1 RelatedAsset (com.ableneo.liferay.portal.setup.domain.RelatedAsset)1 RelatedAssets (com.ableneo.liferay.portal.setup.domain.RelatedAssets)1 Tag (com.ableneo.liferay.portal.setup.domain.Tag)1 NoSuchTagException (com.liferay.asset.kernel.exception.NoSuchTagException)1 AssetTag (com.liferay.asset.kernel.model.AssetTag)1 AssetEntryLocalServiceUtil (com.liferay.asset.kernel.service.AssetEntryLocalServiceUtil)1 AssetTagLocalServiceUtil (com.liferay.asset.kernel.service.AssetTagLocalServiceUtil)1 TemplateDuplicateTemplateKeyException (com.liferay.dynamic.data.mapping.exception.TemplateDuplicateTemplateKeyException)1 JournalArticle (com.liferay.journal.model.JournalArticle)1 Log (com.liferay.portal.kernel.log.Log)1 LogFactoryUtil (com.liferay.portal.kernel.log.LogFactoryUtil)1 ServiceContext (com.liferay.portal.kernel.service.ServiceContext)1 Validator (com.liferay.portal.kernel.util.Validator)1 IOException (java.io.IOException)1 List (java.util.List)1