diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/business/UniqueFieldAPI.java b/dotCMS/src/main/java/com/dotcms/contenttype/business/UniqueFieldAPI.java deleted file mode 100644 index e37471e9d47c..000000000000 --- a/dotCMS/src/main/java/com/dotcms/contenttype/business/UniqueFieldAPI.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.dotcms.contenttype.business; - -import com.dotmarketing.exception.DotDataException; - -/** - * This API allow you to interact with the unique_fields table - */ -public interface UniqueFieldAPI { - - /** - * Insert a new unique field value, if the value is duplicated then a {@link java.sql.SQLException} is thrown. - * - * @param uniqueFieldCriteria - * @param contentletId - * - * @throws UniqueFieldValueDupliacatedException when the Value is duplicated - * @throws DotDataException when a DotDataException is throws - */ - void insert(final UniqueFieldCriteria uniqueFieldCriteria, final String contentletId) - throws UniqueFieldValueDupliacatedException, DotDataException; -} diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/business/UniqueFieldAPIImpl.java b/dotCMS/src/main/java/com/dotcms/contenttype/business/UniqueFieldAPIHelper.java similarity index 83% rename from dotCMS/src/main/java/com/dotcms/contenttype/business/UniqueFieldAPIImpl.java rename to dotCMS/src/main/java/com/dotcms/contenttype/business/UniqueFieldAPIHelper.java index 124a15773614..7a3b6fa817ab 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/business/UniqueFieldAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/business/UniqueFieldAPIHelper.java @@ -10,31 +10,30 @@ import java.util.Map; /** - * Default implementation of {@link UniqueFieldAPI} + * This Helper allow you to interact with the unique_fields table */ -public class UniqueFieldAPIImpl implements UniqueFieldAPI { +public class UniqueFieldAPIHelper { private final UniqueFieldFactory uniqueFieldFactory; - public UniqueFieldAPIImpl(){ + public UniqueFieldAPIHelper(){ this(FactoryLocator.getUniqueFieldFactory()); } - public UniqueFieldAPIImpl(final UniqueFieldFactory uniqueFieldFactory) { + public UniqueFieldAPIHelper(final UniqueFieldFactory uniqueFieldFactory) { this.uniqueFieldFactory = uniqueFieldFactory; } + /** - * Default implementation of {@link UniqueFieldAPI#insert(UniqueFieldCriteria, String)} + * Insert a new unique field value, if the value is duplicated then a {@link java.sql.SQLException} is thrown. * * @param uniqueFieldCriteria * @param contentletId * - * @throws UniqueFieldValueDupliacatedException - * @throws DotDataException + * @throws UniqueFieldValueDupliacatedException when the Value is duplicated + * @throws DotDataException when a DotDataException is throws */ - @Override - @WrapInTransaction public void insert(final UniqueFieldCriteria uniqueFieldCriteria, final String contentletId) throws UniqueFieldValueDupliacatedException, DotDataException { diff --git a/dotCMS/src/main/java/com/dotmarketing/business/APILocator.java b/dotCMS/src/main/java/com/dotmarketing/business/APILocator.java index d859293cca2f..c18ac4f3ed0d 100644 --- a/dotCMS/src/main/java/com/dotmarketing/business/APILocator.java +++ b/dotCMS/src/main/java/com/dotmarketing/business/APILocator.java @@ -1182,15 +1182,6 @@ public static ContentAnalyticsAPI getContentAnalyticsAPI() { return (ContentAnalyticsAPI) getInstance(APIIndex.CONTENT_ANALYTICS_API); } - /** - * Returns a singleton instance of the {@link UniqueFieldAPIImpl} class. - * - * @return The {@link UniqueFieldAPI} instance. - */ - public static UniqueFieldAPI getUniqueFieldAPI() { - return (UniqueFieldAPI) getInstance(APIIndex.UNIQUE_FIELD_API); - } - /** * Generates a unique instance of the specified dotCMS API. * @@ -1348,8 +1339,7 @@ enum APIIndex SYSTEM_API, ACHECKER_API, CONTENT_ANALYTICS_API, - JOB_QUEUE_MANAGER_API, - UNIQUE_FIELD_API; + JOB_QUEUE_MANAGER_API; Object create() { switch(this) { @@ -1444,7 +1434,6 @@ Object create() { case ACHECKER_API: return new ACheckerAPIImpl(); case CONTENT_ANALYTICS_API: CDIUtils.getBean(ContentAnalyticsAPI.class).orElseThrow(() -> new DotRuntimeException("Content Analytics API not found")); case JOB_QUEUE_MANAGER_API: return CDIUtils.getBean(JobQueueManagerAPI.class).orElseThrow(() -> new DotRuntimeException("JobQueueManagerAPI not found")); - case UNIQUE_FIELD_API: return new UniqueFieldAPIImpl(); } throw new AssertionError("Unknown API index: " + this); } diff --git a/dotcms-integration/src/test/java/com/dotcms/MainSuite2b.java b/dotcms-integration/src/test/java/com/dotcms/MainSuite2b.java index f14db99f2a96..acb88b40bd21 100644 --- a/dotcms-integration/src/test/java/com/dotcms/MainSuite2b.java +++ b/dotcms-integration/src/test/java/com/dotcms/MainSuite2b.java @@ -385,7 +385,7 @@ Task241013RemoveFullPathLcColumnFromIdentifierTest.class, Task241009CreatePostgresJobQueueTablesTest.class, UniqueFieldFactoryImplTest.class, - UniqueFieldAPIImplTest.class + UniqueFieldAPIHelperTest.class }) public class MainSuite2b { diff --git a/dotcms-integration/src/test/java/com/dotcms/contenttype/business/UniqueFieldAPIImplTest.java b/dotcms-integration/src/test/java/com/dotcms/contenttype/business/UniqueFieldAPIHelperTest.java similarity index 87% rename from dotcms-integration/src/test/java/com/dotcms/contenttype/business/UniqueFieldAPIImplTest.java rename to dotcms-integration/src/test/java/com/dotcms/contenttype/business/UniqueFieldAPIHelperTest.java index 525c4305d2ce..ea456618996e 100644 --- a/dotcms-integration/src/test/java/com/dotcms/contenttype/business/UniqueFieldAPIImplTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/contenttype/business/UniqueFieldAPIHelperTest.java @@ -1,6 +1,5 @@ package com.dotcms.contenttype.business; -import com.dotcms.contenttype.business.UniqueFieldFactoryImpl; import com.dotcms.contenttype.model.field.Field; import com.dotcms.contenttype.model.field.TextField; import com.dotcms.contenttype.model.type.ContentType; @@ -14,12 +13,10 @@ import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.languagesmanager.model.Language; import com.dotmarketing.util.StringUtils; -import com.liferay.portal.language.LanguageException; import net.bytebuddy.utility.RandomString; import org.junit.BeforeClass; import org.junit.Test; -import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -28,7 +25,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -public class UniqueFieldAPIImplTest { +public class UniqueFieldAPIHelperTest { @BeforeClass public static void prepare() throws Exception { @@ -46,7 +43,7 @@ public static void prepare() throws Exception { } /** - * Method to test: {@link UniqueFieldAPIImpl#insert(UniqueFieldCriteria, String)} + * Method to test: {@link UniqueFieldAPIHelper#insert(UniqueFieldCriteria, String)} * When: Called the method with the right parameters * Should: Insert a register in the unique_fields table */ @@ -71,13 +68,14 @@ public void insert() throws DotDataException, UniqueFieldValueDupliacatedExcepti .host(site) .next(); - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria, contentlet.getIdentifier()); + final UniqueFieldAPIHelper uniqueFieldAPIHelper = new UniqueFieldAPIHelper(); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria, contentlet.getIdentifier()); validateAfterInsert(uniqueFieldCriteria, contentlet); } /** - * Method to test: {@link UniqueFieldAPIImpl#insert(UniqueFieldCriteria, String)} + * Method to test: {@link UniqueFieldAPIHelper#insert(UniqueFieldCriteria, String)} * When: Called the method with a 'unique_key_val' duplicated * Should: Throw a {@link UniqueFieldValueDupliacatedException} */ @@ -102,7 +100,8 @@ public void tryToInsertDuplicated() throws DotDataException, UniqueFieldValueDup .host(site) .next(); - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria, contentlet.getIdentifier()); + final UniqueFieldAPIHelper uniqueFieldAPIHelper = new UniqueFieldAPIHelper(); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria, contentlet.getIdentifier()); final String hash = StringUtils.hashText(contentType.id() + uniqueField.variable() + language.getId() + value); @@ -110,7 +109,7 @@ public void tryToInsertDuplicated() throws DotDataException, UniqueFieldValueDup .setSQL("SELECT COUNT(*) as count FROM unique_fields WHERE unique_key_val = ?") .addParam(hash).loadObjectResults().get(0).get("count").toString()); try { - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria, contentlet.getIdentifier()); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria, contentlet.getIdentifier()); throw new AssertionError("UniqueFieldValueDupliacatedException expected"); } catch (UniqueFieldValueDupliacatedException e) { @@ -123,7 +122,7 @@ public void tryToInsertDuplicated() throws DotDataException, UniqueFieldValueDup } /** - * Method to test: {@link UniqueFieldAPIImpl#insert(UniqueFieldCriteria, String)} + * Method to test: {@link UniqueFieldAPIHelper#insert(UniqueFieldCriteria, String)} * When: Called the method with a field with uniquePerSite set to true * Should: Allow insert the same values in different Host */ @@ -160,7 +159,8 @@ public void insertWithUniquePerSiteSetToTrue() throws DotDataException, UniqueFi .host(site) .next(); - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria_1, contentlet_1.getIdentifier()); + final UniqueFieldAPIHelper uniqueFieldAPIHelper = new UniqueFieldAPIHelper(); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria_1, contentlet_1.getIdentifier()); final UniqueFieldCriteria uniqueFieldCriteria_2 = new UniqueFieldCriteria.Builder() .setContentType(contentType) @@ -175,7 +175,7 @@ public void insertWithUniquePerSiteSetToTrue() throws DotDataException, UniqueFi .host(site_2) .next(); - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria_2, contentlet_2.getIdentifier()); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria_2, contentlet_2.getIdentifier()); final List> results = new DotConnect() .setSQL("SELECT * FROM unique_fields WHERE supporting_values->>'contentTypeID' = ?") @@ -201,7 +201,7 @@ public void insertWithUniquePerSiteSetToTrue() throws DotDataException, UniqueFi } /** - * Method to test: {@link UniqueFieldAPIImpl#insert(UniqueFieldCriteria, String)} + * Method to test: {@link UniqueFieldAPIHelper#insert(UniqueFieldCriteria, String)} * When: Called the method with a Not Unique Field * Should: thrown an {@link IllegalArgumentException} */ @@ -227,7 +227,8 @@ public void insertNotUniqueField() throws DotDataException, UniqueFieldValueDupl .next(); try { - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria, contentlet.getIdentifier()); + final UniqueFieldAPIHelper uniqueFieldAPIHelper = new UniqueFieldAPIHelper(); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria, contentlet.getIdentifier()); throw new AssertionError("IllegalArgumentExceptionΩ Expected"); } catch (IllegalArgumentException e) { //expected @@ -264,7 +265,7 @@ private static void validateAfterInsert(UniqueFieldCriteria uniqueFieldCriteria, } /** - * Method to test: {@link UniqueFieldAPIImpl#insert(UniqueFieldCriteria, String)} + * Method to test: {@link UniqueFieldAPIHelper#insert(UniqueFieldCriteria, String)} * When: Called the method twice with different Content Type * Should: Insert a register in the unique_fields table */ @@ -289,7 +290,8 @@ public void insertWithDifferentContentType() throws DotDataException, UniqueFiel .host(site) .next(); - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria_1, contentlet_1.getIdentifier()); + final UniqueFieldAPIHelper uniqueFieldAPIHelper = new UniqueFieldAPIHelper(); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria_1, contentlet_1.getIdentifier()); validateAfterInsert(uniqueFieldCriteria_1, contentlet_1); final Field field_2 = new FieldDataGen().type(TextField.class).velocityVarName("unique").unique(true).next(); @@ -308,12 +310,12 @@ public void insertWithDifferentContentType() throws DotDataException, UniqueFiel .setSite(site) .build(); - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria_2, contentlet_2.getIdentifier()); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria_2, contentlet_2.getIdentifier()); validateAfterInsert(uniqueFieldCriteria_2, contentlet_2); } /** - * Method to test: {@link UniqueFieldAPIImpl#insert(UniqueFieldCriteria, String)} + * Method to test: {@link UniqueFieldAPIHelper#insert(UniqueFieldCriteria, String)} * When: Called the method twice with different Field * Should: Insert a register in the unique_fields table */ @@ -343,7 +345,8 @@ public void insertWithDifferentField() throws DotDataException, UniqueFieldValue .setSite(site) .build(); - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria_1, contentlet.getIdentifier()); + final UniqueFieldAPIHelper uniqueFieldAPIHelper = new UniqueFieldAPIHelper(); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria_1, contentlet.getIdentifier()); final UniqueFieldCriteria uniqueFieldCriteria_2 = new UniqueFieldCriteria.Builder() .setContentType(contentType) @@ -353,14 +356,14 @@ public void insertWithDifferentField() throws DotDataException, UniqueFieldValue .setSite(site) .build(); - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria_2, contentlet.getIdentifier()); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria_2, contentlet.getIdentifier()); validateAfterInsert(uniqueFieldCriteria_1, contentlet); validateAfterInsert(uniqueFieldCriteria_2, contentlet); } /** - * Method to test: {@link UniqueFieldAPIImpl#insert(UniqueFieldCriteria, String)} + * Method to test: {@link UniqueFieldAPIHelper#insert(UniqueFieldCriteria, String)} * When: Called the method twice with different Value * Should: Insert a register in the unique_fields table */ @@ -388,7 +391,8 @@ public void insertWithDifferentValue() throws DotDataException, UniqueFieldValue .setSite(site) .build(); - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria_1, contentlet.getIdentifier()); + final UniqueFieldAPIHelper uniqueFieldAPIHelper = new UniqueFieldAPIHelper(); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria_1, contentlet.getIdentifier()); final UniqueFieldCriteria uniqueFieldCriteria_2 = new UniqueFieldCriteria.Builder() .setContentType(contentType) @@ -398,14 +402,14 @@ public void insertWithDifferentValue() throws DotDataException, UniqueFieldValue .setSite(site) .build(); - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria_2, contentlet.getIdentifier()); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria_2, contentlet.getIdentifier()); validateAfterInsert(uniqueFieldCriteria_1, contentlet); validateAfterInsert(uniqueFieldCriteria_2, contentlet); } /** - * Method to test: {@link UniqueFieldAPIImpl#insert(UniqueFieldCriteria, String)} + * Method to test: {@link UniqueFieldAPIHelper#insert(UniqueFieldCriteria, String)} * When: Called the method twice with different Language * Should: Insert a register in the unique_fields table */ @@ -434,9 +438,9 @@ public void insertWithDifferentLanguage() throws DotDataException, UniqueFieldVa .setSite(site) .build(); - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria_1, contentlet.getIdentifier()); - - + final UniqueFieldAPIHelper uniqueFieldAPIHelper = new UniqueFieldAPIHelper(); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria_1, contentlet.getIdentifier()); + final UniqueFieldCriteria uniqueFieldCriteria_2 = new UniqueFieldCriteria.Builder() .setContentType(contentType) .setField(field) @@ -445,7 +449,7 @@ public void insertWithDifferentLanguage() throws DotDataException, UniqueFieldVa .setSite(site) .build(); - APILocator.getUniqueFieldAPI().insert(uniqueFieldCriteria_2, contentlet.getIdentifier()); + uniqueFieldAPIHelper.insert(uniqueFieldCriteria_2, contentlet.getIdentifier()); validateAfterInsert(uniqueFieldCriteria_1, contentlet); validateAfterInsert(uniqueFieldCriteria_2, contentlet);