Skip to content

Commit 9f11070

Browse files
committed
chore: fix some more sonar issues
1 parent 6f324db commit 9f11070

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/main/java/com/ableneo/liferay/portal/setup/core/SetupArticles.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public static void addDDMTemplate(final ArticleTemplate template, long groupId)
324324
try {
325325
script = ResourcesUtil.getFileContent(template.getPath());
326326
} catch (Exception e) {
327-
LOG.error("The template can not be added: {}", template.getName(), e);
327+
LOG.error("The template {} can not be read from {}", template.getName(), template.getPath(), e);
328328
return;
329329
}
330330

@@ -347,12 +347,7 @@ public static void addDDMTemplate(final ArticleTemplate template, long groupId)
347347
}
348348
}
349349

350-
DDMTemplate ddmTemplate = null;
351-
try {
352-
ddmTemplate = DDMTemplateLocalServiceUtil.fetchTemplate(groupId, classNameId, template.getKey());
353-
} catch (SystemException e) {
354-
LOG.error("The template can not be added: {}", template.getKey(), e);
355-
}
350+
final DDMTemplate ddmTemplate = getDdmTemplate(template.getName(), template.getKey(), groupId, classNameId);
356351

357352
if (ddmTemplate != null) {
358353
LOG.info("Template already exists and will be overwritten.");
@@ -417,12 +412,7 @@ public static void addDDMTemplate(final Adt template, final long groupId) throws
417412

418413
String language = template.getLanguage() == null ? TemplateConstants.LANG_TYPE_FTL : template.getLanguage();
419414

420-
DDMTemplate ddmTemplate = null;
421-
try {
422-
ddmTemplate = DDMTemplateLocalServiceUtil.fetchTemplate(groupId, classNameId, template.getTemplateKey());
423-
} catch (SystemException e) {
424-
LOG.error("The template can not be added: {}", template.getTemplateKey(), e);
425-
}
415+
final DDMTemplate ddmTemplate = getDdmTemplate(template.getName(), template.getTemplateKey(), groupId, classNameId);
426416

427417
String script = ResourcesUtil.getFileContent(template.getPath());
428418

@@ -463,6 +453,16 @@ public static void addDDMTemplate(final Adt template, final long groupId) throws
463453
LOG.info("Added ADT: {}", newTemplate.getName());
464454
}
465455

456+
private static DDMTemplate getDdmTemplate(String templateName, String templateKey, long groupId, long classNameId) {
457+
DDMTemplate ddmTemplate = null;
458+
try {
459+
ddmTemplate = DDMTemplateLocalServiceUtil.fetchTemplate(groupId, classNameId, templateKey);
460+
} catch (SystemException e) {
461+
LOG.error("The template {} can not be fetched by key: {}", templateName, templateKey, e);
462+
}
463+
return ddmTemplate;
464+
}
465+
466466
public static long getCreateFolderId(String folder, long groupId, RolePermissions roles) {
467467
long folderId = 0L;
468468
long companyId = SetupConfigurationThreadLocal.getRunInCompanyId();

0 commit comments

Comments
 (0)