Skip to content

Commit 5d93c0a

Browse files
committed
chore: fix some of the sonar issues
1 parent 382f0d9 commit 5d93c0a

File tree

1 file changed

+49
-69
lines changed

1 file changed

+49
-69
lines changed

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

Lines changed: 49 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import com.liferay.dynamic.data.lists.service.DDLRecordSetLocalServiceUtil;
2828
import com.liferay.dynamic.data.mapping.constants.DDMTemplateConstants;
2929
import com.liferay.dynamic.data.mapping.exception.TemplateDuplicateTemplateKeyException;
30-
import com.liferay.dynamic.data.mapping.model.DDMForm;
31-
import com.liferay.dynamic.data.mapping.model.DDMFormLayout;
3230
import com.liferay.dynamic.data.mapping.model.DDMStructure;
3331
import com.liferay.dynamic.data.mapping.model.DDMTemplate;
3432
import com.liferay.dynamic.data.mapping.service.DDMStructureLocalServiceUtil;
@@ -53,7 +51,6 @@
5351
import com.liferay.portal.kernel.template.TemplateConstants;
5452
import com.liferay.portal.kernel.util.LocaleUtil;
5553
import com.liferay.portal.kernel.util.LocalizationUtil;
56-
import com.liferay.portal.kernel.util.MapUtil;
5754
import com.liferay.portal.kernel.util.PortalUtil;
5855
import com.liferay.portal.kernel.util.StringUtil;
5956
import com.liferay.portal.kernel.util.Validator;
@@ -173,7 +170,7 @@ public static void setupSiteArticles(
173170
try {
174171
addDDMTemplate(template, groupId);
175172
} catch (TemplateDuplicateTemplateKeyException | IOException e) {
176-
LOG.error(String.format("Error in adding ADT: %1$s", template.getName()), e);
173+
LOG.error("The template can not be added: {}", template.getName(), e);
177174
}
178175
}
179176
}
@@ -182,7 +179,7 @@ public static void setupSiteArticles(
182179
try {
183180
addDDLRecordSet(recordSet, groupId);
184181
} catch (TemplateDuplicateTemplateKeyException e) {
185-
LOG.error(String.format("Error in adding DDLRecordSet: %1$s", recordSet.getName()), e);
182+
LOG.error("Error in adding DDLRecordSet: {}", recordSet.getName(), e);
186183
}
187184
}
188185
}
@@ -206,20 +203,16 @@ public static void addDDMStructure(final StructureType structure, final long gro
206203

207204
String content = null;
208205
DataDefinition dataDefinition = null;
209-
DDMForm ddmForm = null;
210-
DDMFormLayout ddmFormLayout = null;
211206
try {
212207
content = ResourcesUtil.getFileContent(structure.getPath());
213208
dataDefinition = DataDefinition.toDTO(content);
214209
} catch (IOException e) {
215-
LOG.error(String.format("Error Reading Structure File content for: %1$s", structure.getName()));
210+
LOG.error("The structure can not be added: {}", structure.getName(), e);
216211
return;
217212
} catch (Exception e) {
218213
LOG.error(
219-
String.format(
220-
"Other error while trying to get content of the structure file. Possibly wrong filesystem path (%1$s)?",
221-
structure.getPath()
222-
),
214+
"Other error while trying to get content of the structure file. Possibly wrong filesystem path ({})?",
215+
structure.getPath(),
223216
e
224217
);
225218
return;
@@ -311,7 +304,7 @@ private static String getStructureNameOrKey(final StructureType structure) {
311304
}
312305

313306
public static void addDDMTemplate(final ArticleTemplate template, long groupId) throws PortalException {
314-
LOG.info(String.format("Adding Article template %1$s", template.getName()));
307+
LOG.info("Adding template: {}", template.getName());
315308
long classNameId = ClassNameLocalServiceUtil.getClassNameId(DDMStructure.class);
316309
long resourceClassnameId = ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class);
317310
Map<Locale, String> nameMap = new HashMap<>();
@@ -331,7 +324,7 @@ public static void addDDMTemplate(final ArticleTemplate template, long groupId)
331324
try {
332325
script = ResourcesUtil.getFileContent(template.getPath());
333326
} catch (Exception e) {
334-
LOG.error(String.format("Error Reading Template File content for: %1$s", template.getName()));
327+
LOG.error("The template can not be added: {}", template.getName(), e);
335328
return;
336329
}
337330

@@ -346,10 +339,8 @@ public static void addDDMTemplate(final ArticleTemplate template, long groupId)
346339
);
347340
} catch (PortalException e) {
348341
LOG.error(
349-
String.format(
350-
"Given article structure with ID: %1$s can not be found. Therefore, article template can not be added/changed.",
351-
template.getArticleStructureKey()
352-
),
342+
"Given article structure with ID: {} can not be found. Therefore, article template can not be added/changed.",
343+
template.getArticleStructureKey(),
353344
e
354345
);
355346
return;
@@ -360,7 +351,7 @@ public static void addDDMTemplate(final ArticleTemplate template, long groupId)
360351
try {
361352
ddmTemplate = DDMTemplateLocalServiceUtil.fetchTemplate(groupId, classNameId, template.getKey());
362353
} catch (SystemException e) {
363-
LOG.error(String.format("Error while trying to find template with key: %1$s", template.getKey()), e);
354+
LOG.error("The template can not be added: {}", template.getKey(), e);
364355
}
365356

366357
if (ddmTemplate != null) {
@@ -372,7 +363,7 @@ public static void addDDMTemplate(final ArticleTemplate template, long groupId)
372363
ddmTemplate.setCacheable(template.isCacheable());
373364

374365
DDMTemplateLocalServiceUtil.updateDDMTemplate(ddmTemplate);
375-
LOG.info(String.format("Template successfully updated: %1$s", ddmTemplate.getName()));
366+
LOG.info("Template successfully updated: {}", ddmTemplate.getName());
376367
return;
377368
}
378369

@@ -399,11 +390,11 @@ public static void addDDMTemplate(final ArticleTemplate template, long groupId)
399390
new ServiceContext()
400391
);
401392

402-
LOG.info(String.format("Added Article template: %1$s", newTemplate.getName()));
393+
LOG.info("Added Article template: {}", newTemplate.getName());
403394
}
404395

405396
public static void addDDMTemplate(final Adt template, final long groupId) throws PortalException, IOException {
406-
LOG.info(String.format("Adding ADT %1$s", template.getName()));
397+
LOG.info("Adding structure: {}", template.getName());
407398
long classNameId = PortalUtil.getClassNameId(template.getClassName());
408399
long resourceClassnameId = Validator.isBlank(template.getResourceClassName())
409400
? ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class)
@@ -430,7 +421,7 @@ public static void addDDMTemplate(final Adt template, final long groupId) throws
430421
try {
431422
ddmTemplate = DDMTemplateLocalServiceUtil.fetchTemplate(groupId, classNameId, template.getTemplateKey());
432423
} catch (SystemException e) {
433-
LOG.error(String.format("Error while trying to find ADT with key: %1$s", template.getTemplateKey()));
424+
LOG.error("The template can not be added: {}", template.getTemplateKey(), e);
434425
}
435426

436427
String script = ResourcesUtil.getFileContent(template.getPath());
@@ -445,7 +436,7 @@ public static void addDDMTemplate(final Adt template, final long groupId) throws
445436
ddmTemplate.setScript(script);
446437

447438
DDMTemplateLocalServiceUtil.updateDDMTemplate(ddmTemplate);
448-
LOG.info(String.format("ADT successfully updated: %1$s", ddmTemplate.getName()));
439+
LOG.info("ADT successfully updated: {}", ddmTemplate.getName());
449440
return;
450441
}
451442
long runAsUserId = SetupConfigurationThreadLocal.getRunAsUserId();
@@ -469,11 +460,9 @@ public static void addDDMTemplate(final Adt template, final long groupId) throws
469460
null,
470461
new ServiceContext()
471462
);
472-
LOG.info(String.format("Added ADT: %1$s", newTemplate.getName()));
463+
LOG.info("Added ADT: {}", newTemplate.getName());
473464
}
474465

475-
public static void getJournalArticleByPath(String folder, String file) {}
476-
477466
public static long getCreateFolderId(String folder, long groupId, RolePermissions roles) {
478467
long folderId = 0L;
479468
long companyId = SetupConfigurationThreadLocal.getRunInCompanyId();
@@ -506,7 +495,7 @@ public static void addJournalArticle(final Article article, final long groupId)
506495
article.getPath()
507496
);
508497
} catch (IOException e) {
509-
LOG.error(String.format("Error Reading Article File content for article ID: %1$s", article.getArticleId()));
498+
LOG.error("The article can not be added: {}", article.getArticleId(), e);
510499
}
511500
Map<Locale, String> titleMap = TranslationMapUtil.getTranslationMap(
512501
article.getTitleTranslation(),
@@ -539,7 +528,7 @@ public static void addJournalArticle(final Article article, final long groupId)
539528

540529
boolean generatedId = (article.getArticleId().isEmpty());
541530
if (generatedId) {
542-
LOG.info(String.format("Article %1$s will have autogenerated ID.", article.getTitle()));
531+
LOG.info("Article {} will have autogenerated ID.", article.getTitle());
543532
} else {
544533
journalArticle = getJournalArticle(
545534
article.getArticleId(),
@@ -606,7 +595,7 @@ public static void addJournalArticle(final Article article, final long groupId)
606595
bi.reindex(journalArticle);
607596
}
608597
} catch (PortalException e) {
609-
LOG.error(String.format("Error while trying to add Article with Title: %1$s", article.getTitle()), e);
598+
LOG.error("The article can not be added: {}", article.getTitle(), e);
610599
}
611600
} else {
612601
try {
@@ -692,11 +681,12 @@ public static JournalArticle getJournalArticle(
692681
if (articleId.equalsIgnoreCase(art.getArticleId())) {
693682
// liferay inside: uses 'ignore-case'
694683
if (art.getStatus() == WorkflowConstants.STATUS_APPROVED) {
695-
LOG.info(String.format(" - found article [%1$s] with same name [%1$s]", articleId));
684+
LOG.info("Found article with ID: {} and directory: {} ({})", articleId, folderPathForTheLog, folderId);
696685
withSameArticleId.add(art);
697686
} else {
698687
LOG.info(
699-
String.format(" - found article which is not 'approved' [%1$s], leave-alone", articleId)
688+
"Found article which is not 'approved' [{}], leave-alone",
689+
articleId
700690
);
701691
}
702692
}
@@ -705,22 +695,18 @@ public static JournalArticle getJournalArticle(
705695
if (!withSameArticleId.isEmpty()) {
706696
if (withSameArticleId.size() == 1) {
707697
LOG.info(
708-
String.format(
709-
"FOUND article with ID: %1$s and directory:%2$s (%3$s)",
710-
articleId,
711-
folderPathForTheLog,
712-
folderId
713-
)
698+
"Found article with ID: {} and directory: {} ({})",
699+
articleId,
700+
folderPathForTheLog,
701+
folderId
714702
);
715703
journalArticle = withSameArticleId.get(0);
716704
} else {
717705
LOG.warn(
718-
String.format(
719-
"MULTIPLE article with ID: %1$s and directory:%2$s (%3$s)",
720-
articleId,
721-
folderPathForTheLog,
722-
folderId
723-
)
706+
"Multiple article with ID: {} and directory: {} ({})",
707+
articleId,
708+
folderPathForTheLog,
709+
folderId
724710
);
725711
//
726712
for (int i = 0; i < withSameArticleId.size(); i++) {
@@ -740,42 +726,36 @@ public static JournalArticle getJournalArticle(
740726
}
741727
if (journalArticle == null) {
742728
LOG.warn(
743-
String.format(
744-
"No article amongst multiple: %1$s and directory:%2$s (%3$s)",
745-
articleId,
746-
folderPathForTheLog,
747-
folderId
748-
)
729+
"No article amongst multiple: {} and directory: {} ({})",
730+
articleId,
731+
folderPathForTheLog,
732+
folderId
749733
);
750734
} else {
751735
LOG.info(
752-
String.format(
753-
"SELECTED article with ID: %1$s and directory:%2$s (%3$s)",
754-
articleId,
755-
folderPathForTheLog,
756-
folderId
757-
)
736+
"Selected article with ID: {} and directory: {} ({})",
737+
articleId,
738+
folderPathForTheLog,
739+
folderId
758740
);
759741
}
760742
}
761743
} else {
762744
LOG.warn(
763-
String.format(
764-
"Cannot find article with ID: %1$s and directory:%2$s (%3$s)",
765-
articleId,
766-
folderPathForTheLog,
767-
folderId
768-
)
745+
"Cannot find article with ID: {} and directory: {} ({})",
746+
articleId,
747+
folderPathForTheLog,
748+
folderId
769749
);
770750
}
771751
} catch (SystemException e) {
772-
LOG.error(String.format("Error while trying to find article with ID: %1$s", articleId), e);
752+
LOG.error("Error while trying to find article with ID: {}", articleId, e);
773753
}
774754
return journalArticle;
775755
}
776756

777757
private static void addDDLRecordSet(final DdlRecordset recordSet, final long groupId) throws PortalException {
778-
LOG.info(String.format("Adding DDLRecordSet %1$s", recordSet.getName()));
758+
LOG.info("Adding DDLRecordSet: {}", recordSet.getName());
779759
Map<Locale, String> nameMap = new HashMap<>();
780760
Locale siteDefaultLocale = PortalUtil.getSiteDefaultLocale(groupId);
781761
nameMap.put(siteDefaultLocale, recordSet.getName());
@@ -785,7 +765,7 @@ private static void addDDLRecordSet(final DdlRecordset recordSet, final long gro
785765
try {
786766
ddlRecordSet = DDLRecordSetLocalServiceUtil.fetchRecordSet(groupId, recordSet.getKey());
787767
} catch (SystemException e) {
788-
LOG.error(String.format("Error while trying to find DDLRecordSet with key: %1$s", recordSet.getKey()), e);
768+
LOG.error("Could not find recordset with key: {}", recordSet.getKey(), e);
789769
}
790770

791771
if (ddlRecordSet != null) {
@@ -801,7 +781,7 @@ private static void addDDLRecordSet(final DdlRecordset recordSet, final long gro
801781
)
802782
);
803783
DDLRecordSetLocalServiceUtil.updateDDLRecordSet(ddlRecordSet);
804-
LOG.info(String.format("DDLRecordSet successfully updated: %1$s", recordSet.getName()));
784+
LOG.info("DDLRecordSet successfully updated: {}", recordSet.getName());
805785
return;
806786
}
807787

@@ -817,7 +797,7 @@ private static void addDDLRecordSet(final DdlRecordset recordSet, final long gro
817797
0,
818798
new ServiceContext()
819799
);
820-
LOG.info(String.format("Added DDLRecordSet: %1$s", newDDLRecordSet.getName()));
800+
LOG.info("Added DDLRecordSet: {}", newDDLRecordSet.getName());
821801
}
822802

823803
public static Long getJournalAssetEntryId(JournalArticle ja) {
@@ -828,7 +808,7 @@ public static Long getJournalAssetEntryId(JournalArticle ja) {
828808
);
829809
return ae.getEntryId();
830810
} catch (PortalException | SystemException e) {
831-
LOG.error(String.format("Problem clearing related assets of article %1$s", ja.getArticleId()), e);
811+
LOG.error("Problem clearing related assets of article {}", ja.getArticleId(), e);
832812
}
833813
return null;
834814
}
@@ -848,7 +828,7 @@ public static void processRelatedAssets(
848828
ae = AssetEntryLocalServiceUtil.getEntry(JournalArticle.class.getName(), ja.getResourcePrimKey());
849829
AssetLinkLocalServiceUtil.deleteLinks(ae.getEntryId());
850830
} catch (PortalException | SystemException e) {
851-
LOG.error(String.format("Problem clearing related assets of article %1$s", ja.getArticleId()), e);
831+
LOG.error("Problem clearing related assets of article {}", ja.getArticleId(), e);
852832
}
853833
}
854834
if (ras.getRelatedAsset() != null && !ras.getRelatedAsset().isEmpty()) {

0 commit comments

Comments
 (0)