@@ -324,7 +324,7 @@ public static void addDDMTemplate(final ArticleTemplate template, long groupId)
324
324
try {
325
325
script = ResourcesUtil .getFileContent (template .getPath ());
326
326
} 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 );
328
328
return ;
329
329
}
330
330
@@ -347,12 +347,7 @@ public static void addDDMTemplate(final ArticleTemplate template, long groupId)
347
347
}
348
348
}
349
349
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 );
356
351
357
352
if (ddmTemplate != null ) {
358
353
LOG .info ("Template already exists and will be overwritten." );
@@ -417,12 +412,7 @@ public static void addDDMTemplate(final Adt template, final long groupId) throws
417
412
418
413
String language = template .getLanguage () == null ? TemplateConstants .LANG_TYPE_FTL : template .getLanguage ();
419
414
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 );
426
416
427
417
String script = ResourcesUtil .getFileContent (template .getPath ());
428
418
@@ -463,6 +453,16 @@ public static void addDDMTemplate(final Adt template, final long groupId) throws
463
453
LOG .info ("Added ADT: {}" , newTemplate .getName ());
464
454
}
465
455
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
+
466
466
public static long getCreateFolderId (String folder , long groupId , RolePermissions roles ) {
467
467
long folderId = 0L ;
468
468
long companyId = SetupConfigurationThreadLocal .getRunInCompanyId ();
0 commit comments