Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-99880

JournalArticleLocalServiceUtil.getArticleDisplay() is not consistent about including Global as a fallback scope



      There is an issue with the way we fetch the web content template in JournalArticleLocalServiceImpl.getArticleDisplay(), for an article using a template from Global.

      The relevant code is:

      // Try with specified template first (in the current group and the
      			// global group). If a template is not specified, use the default
      			// one. If the specified template does not exist, use the default
      			// one. If the default one does not exist, throw an exception.
      			DDMTemplate ddmTemplate = null;
      			try {
      				ddmTemplate = ddmTemplateLocalService.getTemplate(
      					ddmTemplateKey, true);
      				Group companyGroup = groupLocalService.getCompanyGroup(
      				if (companyGroup.getGroupId() == ddmTemplate.getGroupId()) {
      			catch (NoSuchTemplateException nste) {
      				if (!defaultDDMTemplateKey.equals(ddmTemplateKey)) {
      					ddmTemplate = ddmTemplateLocalService.getTemplate(
      				else {
      					throw nste;

      Basically what it does, is that it looks for the provided template in the article's site, and if it doesn't find it, it also looks for it in the parent sites and Global, due to getTemplate() being called with the includeAncestorTemplates parameter.

      If it still doesn't find it, we take the article's default template (I guess what is DDMTemplateKey on the journalarticle record) and try to fetch that with getTemplate again. But this time a different version of getTemplate() is called, the one without the includeAncestorTemplates parameter, resulting in the template being looked for only in the article's site. Causing this to fail with

      NoSuchTemplateException: No DDMTemplate exists with the key {groupId=20126, classNameId=22909, templateKey=dhgfdh}

      if the article is using a template from Global.

      This second getTemplate call should also use that includeAncestorTemplates parameter (passed as true here as well): this would be more consistent and failsafe.

      Steps that show the problem:

      1. Go to the Global site and create a new template for the Basic Web Content structure. Fill its contents with

      ${content.getData()} template2

      for example.
      2. In the guest site, create a new basic web content, making sure it uses the new template. (Actually, the error comes just as well with the built-in BASIC WEB CONTENT template, but I wanted to use a different one because it might be relevant for the test results on 7.1.x)
      3. From the database, get the articleId and DDMTemplateKey from the journal article record and replace them in the attached Groovy script, then run it.
      Checkpoint: The content is returned according to the template.
      4. Try it with an empty templateKey
      Checkpoint: It still works fine. (because in this case, it looks for the article's default template already in the first getTemplate() call)
      5. Try it with some non-existent templateKey.
      Result: The script execution fails with the above-mentioned error. Because it looks for the article's default template with the second getTemplate call)
      Expected: It should be able to find the article's default template in the Global site, and print out its content according to that template.


       master @df0c4a2e1929cf9e9712b49956802b7c8c78effd




            lu.liu Lu Liu
            laszlo.pap Laszlo Pap
            Participants of an Issue:
            Recent user:
            Jason Pince
            Engineering Assignee:
            Laszlo Pap
            0 Vote for this issue
            1 Start watching this issue


              Days since last comment:
              1 year, 48 weeks, 6 days ago


                Version Package
                7.1.10 DXP FP14
                7.2.10 DXP FP2
       DXP SP1
                7.2.1 CE GA2
                7.3.10 DXP GA1