Search code examples
metadataliferay-7liferay-dxp

How to get web content meta-data categories & tags information in custom module in Liferay 7?


How to get webcontent meta-data categories & tags information in custom module in liferay 7. I need to override the service wrapper hook of Journal Article

addArticle(long userId, long groupId, long folderId, long classNameId, long classPK, String articleId, boolean autoArticleId, double version, Map titleMap, Map descriptionMap, String content, String ddmStructureKey, String ddmTemplateKey, String layoutUuid, int displayDateMonth, int displayDateDay, int displayDateYear, int displayDateHour, int displayDateMinute, int expirationDateMonth, int expirationDateDay, int expirationDateYear, int expirationDateHour, int expirationDateMinute, boolean neverExpire, int reviewDateMonth, int reviewDateDay, int reviewDateYear, int reviewDateHour, int reviewDateMinute, boolean neverReview, boolean indexable, boolean smallImage, String smallImageURL, File smallImageFile, Map images, String articleURL, ServiceContext serviceContext) throws PortalException { }

there is no parameters for meta-data information in this method how to get the metadata information of journal article.


Solution

  • There are 2 ways how to approach this. The model listener way is a bit tricky because the association between Article and categories are established after the model listener is called. The id is already assigned (article.getId()) but there would need to be some trickery in place to overcome this.

    The straightforward approach would be to create a service wrapper, call the original code and then use the service context to determine further actions.

    Consider decoupling the code that will send the mail with the usage of an async message over Liferay message bus.

    If you configured the SMTP server in Liferay you can also use the MailService to send emails from the portal.

    See the sample code

    @Component(immediate = true, property = {}, service = 
    ServiceWrapper.class)
    public class MailServiceWrapper extends JournalArticleServiceWrapper {
    
      private static final Log _log = LogFactoryUtil.getLog(MailServiceWrapper.class);
    
      @Reference
      private  MailService mailService;
    
      @Reference
      private AssetCategoryService assetCategoryService;
    
    
      @Override
      public JournalArticle addArticle(long groupId, long folderId, long classNameId, long classPK, String articleId, boolean autoArticleId, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String content, String ddmStructureKey, String ddmTemplateKey, String layoutUuid, int displayDateMonth, int displayDateDay, int displayDateYear, int displayDateHour, int displayDateMinute, int expirationDateMonth, int expirationDateDay, int expirationDateYear, int expirationDateHour, int expirationDateMinute, boolean neverExpire, int reviewDateMonth, int reviewDateDay, int reviewDateYear, int reviewDateHour, int reviewDateMinute, boolean neverReview, boolean indexable, String articleURL, ServiceContext serviceContext) throws PortalException {
        JournalArticle journalArticle = super.addArticle(groupId, folderId, classNameId, classPK, articleId, autoArticleId, titleMap, descriptionMap, content, ddmStructureKey, ddmTemplateKey, layoutUuid, displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, neverReview, indexable, articleURL, serviceContext);
        sendNotification(serviceContext.getAssetCategoryIds(), journalArticle);
        return journalArticle;
      }
    
    
      @Override
      public JournalArticle addArticle(long groupId, long folderId, long classNameId, long classPK, String articleId, boolean autoArticleId, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String content, String ddmStructureKey, String ddmTemplateKey, String layoutUuid, int displayDateMonth, int displayDateDay, int displayDateYear, int displayDateHour, int displayDateMinute, int expirationDateMonth, int expirationDateDay, int expirationDateYear, int expirationDateHour, int expirationDateMinute, boolean neverExpire, int reviewDateMonth, int reviewDateDay, int reviewDateYear, int reviewDateHour, int reviewDateMinute, boolean neverReview, boolean indexable, boolean smallImage, String smallImageURL, File smallFile, Map<String, byte[]> images, String articleURL, ServiceContext serviceContext) throws PortalException {
        JournalArticle journalArticle = super.addArticle(groupId, folderId, classNameId, classPK, articleId, autoArticleId, titleMap, descriptionMap, content, ddmStructureKey, ddmTemplateKey, layoutUuid, displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, neverReview, indexable, smallImage, smallImageURL, smallFile, images, articleURL, serviceContext);
        sendNotification(serviceContext.getAssetCategoryIds(), journalArticle);
        return journalArticle;
      }
    
      private void sendNotification(long[] assetCategoryIds, JournalArticle journalArticle) throws PortalException {
        // send mail
    
      }
    }