From 8924cf7af926b7a9794aa0c603dd1120f211b641 Mon Sep 17 00:00:00 2001 From: Michal Volf Date: Fri, 23 Oct 2020 17:10:54 +0200 Subject: [PATCH] added check for class name existence in the db for adt setup --- .../liferay/db/setup/core/SetupArticles.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/eu/lundegaard/liferay/db/setup/core/SetupArticles.java b/src/main/java/eu/lundegaard/liferay/db/setup/core/SetupArticles.java index 4e4b5d1..69c45a3 100644 --- a/src/main/java/eu/lundegaard/liferay/db/setup/core/SetupArticles.java +++ b/src/main/java/eu/lundegaard/liferay/db/setup/core/SetupArticles.java @@ -43,6 +43,7 @@ import com.liferay.portal.kernel.exception.SystemException; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; +import com.liferay.portal.kernel.model.ClassName; import com.liferay.portal.kernel.model.RoleConstants; import com.liferay.portal.kernel.search.Indexer; import com.liferay.portal.kernel.search.IndexerRegistryUtil; @@ -67,6 +68,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Optional; /** * Created by mapa, guno.. @@ -354,6 +356,16 @@ public static void addDDMTemplate(final Adt template, final long groupId) throws SystemException, PortalException, IOException, URISyntaxException { LOG.info("Adding ADT " + template.getName()); + + Optional className = + ClassNameLocalServiceUtil.getClassNames(0, ClassNameLocalServiceUtil.getClassNamesCount()).stream() + .filter(cName -> cName.getClassName().equals(template.getClassName())).findFirst(); + + if (!className.isPresent()) { + throw new IllegalArgumentException( + "The class name " + template.getClassName() + " does not exist within Liferay."); + } + long classNameId = PortalUtil.getClassNameId(template.getClassName()); long resourceClassnameId = Validator.isBlank(template.getResourceClassName())