diff --git a/dotCMS/src/integration-test/java/com/dotcms/contenttype/test/ContentTypeResourceTest.java b/dotCMS/src/integration-test/java/com/dotcms/contenttype/test/ContentTypeResourceTest.java index d8fc596f92e5..ed6df70d9f10 100644 --- a/dotCMS/src/integration-test/java/com/dotcms/contenttype/test/ContentTypeResourceTest.java +++ b/dotCMS/src/integration-test/java/com/dotcms/contenttype/test/ContentTypeResourceTest.java @@ -9,7 +9,9 @@ import javax.servlet.http.HttpServletRequest; +import com.dotcms.util.ConfigTestHelper; import org.apache.commons.io.IOUtils; +import org.junit.Assert; import org.junit.Test; import com.dotcms.contenttype.exception.NotFoundInDbException; @@ -30,8 +32,9 @@ public class ContentTypeResourceTest extends ContentTypeBaseTest { @Test public void jsonTests() throws Exception { - URL resource = this.getClass().getResource(base); - File directory = new File(resource.toURI()); + URL resource = ConfigTestHelper.getUrlToTestResource("com/dotcms/contenttype/test/file-asset.json"); + File pivotResource = new File(resource.toURI()); + File directory = pivotResource.getParentFile(); assertThat("we have a testing directory with json in it", directory != null); for (String file : directory.list()) { @@ -68,7 +71,7 @@ public void testJson(String jsonFile) throws Exception { Response response = resource.createType(getHttpRequest(), json); int x = response.getStatus(); - assertThat("result:200 with json " + jsonFile, x == 200); + assertThat("result:200 with json " + jsonFile + "got :" + x, x == 200); } /** diff --git a/dotCMS/src/integration-test/java/com/dotmarketing/portlets/contentlet/business/ContentletAPITest.java b/dotCMS/src/integration-test/java/com/dotmarketing/portlets/contentlet/business/ContentletAPITest.java index 506a867444ce..381943b0f58b 100644 --- a/dotCMS/src/integration-test/java/com/dotmarketing/portlets/contentlet/business/ContentletAPITest.java +++ b/dotCMS/src/integration-test/java/com/dotmarketing/portlets/contentlet/business/ContentletAPITest.java @@ -11,9 +11,11 @@ import java.io.StringWriter; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -28,6 +30,7 @@ import com.dotcms.content.business.DotMappingException; import com.dotcms.content.elasticsearch.business.ESMappingAPIImpl; import com.dotcms.contenttype.model.type.BaseContentType; +import com.dotcms.contenttype.model.type.ContentType; import com.dotcms.datagen.ContainerDataGen; import com.dotcms.datagen.ContentletDataGen; import com.dotcms.datagen.FileAssetDataGen; @@ -39,6 +42,7 @@ import com.dotcms.mock.response.BaseResponse; import com.dotcms.repackage.org.apache.commons.io.FileUtils; import com.dotcms.repackage.org.apache.commons.lang.time.FastDateFormat; +import com.dotcms.repackage.twitter4j.IDs; import com.dotmarketing.beans.Host; import com.dotmarketing.beans.Identifier; import com.dotmarketing.beans.MultiTree; @@ -1159,6 +1163,93 @@ public void archive () throws DotDataException, DotSecurityException { } } + /** + * https://github.com/dotCMS/core/issues/11716 + * @throws DotDataException + * @throws DotSecurityException + */ + + @Test + public void addRemoveContentFromIndex () throws DotDataException, DotSecurityException { + // respect CMS Anonymous permissions + boolean respectFrontendRoles = false; + int num = 5; + Host host = APILocator.getHostAPI().findDefaultHost(user, respectFrontendRoles); + Folder folder = APILocator.getFolderAPI().findSystemFolder(); + + Language lang = APILocator.getLanguageAPI().getDefaultLanguage(); + ContentType type = APILocator.getContentTypeAPI(user).find("webPageContent"); + List origCons = new ArrayList<>(); + + Map map = new HashMap<>(); + map.put("stInode", type.id()); + map.put("host", host.getIdentifier()); + map.put("folder", folder.getInode()); + map.put("languageId", lang.getId()); + map.put("sortOrder", new Long(0)); + map.put("body", "body"); + + + //add 5 contentlets + for(int i = 0;i0); + } + + + HibernateUtil.startTransaction(); + try{ + List checkedOut=contentletAPI.checkout(origCons, user, respectFrontendRoles); + for(Contentlet c : checkedOut){ + c.setStringProperty("title", c.getStringProperty("title") + " new"); + c = contentletAPI.checkin(c,user, respectFrontendRoles); + contentletAPI.publish(c, user, respectFrontendRoles); + assertTrue( c.isLive()); + } + throw new DotDataException("uh oh, what happened?"); + } + catch(DotDataException e){ + HibernateUtil.rollbackTransaction(); + + } + finally{ + HibernateUtil.closeSession(); + } + for(Contentlet c : origCons){ + assertTrue(contentletAPI.indexCount("+live:true +identifier:" +c.getIdentifier() + " +inode:" + c.getInode() , user, respectFrontendRoles)>0); + } + + } + + + + + + + + + + /** * Testing {@link ContentletAPI#delete(com.dotmarketing.portlets.contentlet.model.Contentlet, com.liferay.portal.model.User, boolean)} * diff --git a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/content-type-array-insert.json b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/content-type-array-insert.json index 0ba6514b3598..d69485ec9556 100644 --- a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/content-type-array-insert.json +++ b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/content-type-array-insert.json @@ -14,11 +14,12 @@ "modDate": 1479496985000, "name": "", "userId": "dotcms.org.1", - "value": "werew" + "value": "werew", + "clazz" : "com.dotcms.contenttype.model.field.ImmutableFieldVariable" } ], "fixed": false, - "implClass": "com.dotcms.contenttype.model.field.ImmutableHostFolderField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableHostFolderField", "indexed": true, "inode": "ee91a37d-9d9f-4488-a1ce-50516e5309dc", "listed": false, @@ -43,7 +44,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1308941148000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableTextField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableTextField", "indexed": true, "inode": "5c21daa4-1482-4bc9-9d61-04b42d35a6ee", "listed": true, @@ -64,7 +65,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1453474468000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableTagField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableTagField", "indexed": true, "inode": "0030b173-41c4-40ae-8331-1c438fcb514e", "listed": false, @@ -87,7 +88,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1411763369000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableWysiwygField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableWysiwygField", "indexed": false, "inode": "abb57118-7979-400e-9e7d-208e9dfe1f64", "listed": false, @@ -114,7 +115,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1453472236000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableSelectField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableSelectField", "indexed": false, "inode": "bd07dab3-c559-4d1b-873a-050e8cc6359c", "listed": false, @@ -136,7 +137,7 @@ "fixed": false, "hint": "Recommended size 940x350", "iDate": 1308941399000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableBinaryField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableBinaryField", "indexed": false, "inode": "fff86d86-7908-4922-aaed-a3e8b0c6aae4", "listed": false, @@ -161,7 +162,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1412016702000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableCustomField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableCustomField", "indexed": true, "inode": "c4712e56-ec64-4795-8613-63dff910b34e", "listed": true, @@ -186,7 +187,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1412187539000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableCustomField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableCustomField", "indexed": true, "inode": "46e98b70-d4f8-4dbe-9e12-eb65ae00a07e", "listed": true, @@ -205,7 +206,7 @@ "folder": "SYSTEM_FOLDER", "host": "48190c8c-42c4-46af-8d1a-0cd5db894797", "iDate": 1453474503000, - "implClass": "com.dotcms.contenttype.model.type.ImmutableSimpleContentType", + "clazz": "com.dotcms.contenttype.model.type.ImmutableSimpleContentType", "inode": "4c441ada-944a-43af-a653-9bb4f3f0cb2b", "modDate": 1478557845000, "multilingualable": false, @@ -230,12 +231,13 @@ "modDate": 1479506692000, "name": "", "userId": "dotcms.org.1", - "value": "asdasdasd" + "value": "asdasdasd", + "clazz" : "com.dotcms.contenttype.model.field.ImmutableFieldVariable" } ], "fixed": false, "iDate": 1352489401000, - "implClass": "com.dotcms.contenttype.model.field.HostFolderField", + "clazz": "com.dotcms.contenttype.model.field.HostFolderField", "indexed": false, "listed": false, "modDate": 1395411079000, @@ -253,7 +255,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1352489482000, - "implClass": "com.dotcms.contenttype.model.field.DateTimeField", + "clazz": "com.dotcms.contenttype.model.field.DateTimeField", "indexed": true, "listed": true, "modDate": 1395411079000, @@ -271,7 +273,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1352489522000, - "implClass": "com.dotcms.contenttype.model.field.TextField", + "clazz": "com.dotcms.contenttype.model.field.TextField", "indexed": true, "listed": true, "modDate": 1395411079000, @@ -290,7 +292,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1352489564000, - "implClass": "com.dotcms.contenttype.model.field.CustomField", + "clazz": "com.dotcms.contenttype.model.field.CustomField", "indexed": true, "listed": false, "modDate": 1407252812000, @@ -309,7 +311,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1352489616000, - "implClass": "com.dotcms.contenttype.model.field.TextField", + "clazz": "com.dotcms.contenttype.model.field.TextField", "indexed": true, "listed": true, "modDate": 1395411079000, @@ -328,7 +330,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1352489643000, - "implClass": "com.dotcms.contenttype.model.field.TextAreaField", + "clazz": "com.dotcms.contenttype.model.field.TextAreaField", "indexed": false, "listed": false, "modDate": 1395411079000, @@ -347,7 +349,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1352489664000, - "implClass": "com.dotcms.contenttype.model.field.WysiwygField", + "clazz": "com.dotcms.contenttype.model.field.WysiwygField", "indexed": false, "listed": false, "modDate": 1395411079000, @@ -365,7 +367,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1352489688000, - "implClass": "com.dotcms.contenttype.model.field.BinaryField", + "clazz": "com.dotcms.contenttype.model.field.BinaryField", "indexed": false, "listed": false, "modDate": 1395411079000, @@ -383,7 +385,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1352489743000, - "implClass": "com.dotcms.contenttype.model.field.TextField", + "clazz": "com.dotcms.contenttype.model.field.TextField", "indexed": false, "listed": false, "modDate": 1395411079000, @@ -402,7 +404,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1352489779000, - "implClass": "com.dotcms.contenttype.model.field.LineDividerField", + "clazz": "com.dotcms.contenttype.model.field.LineDividerField", "indexed": false, "listed": false, "modDate": 1395411079000, @@ -420,7 +422,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1352489810000, - "implClass": "com.dotcms.contenttype.model.field.CategoryField", + "clazz": "com.dotcms.contenttype.model.field.CategoryField", "indexed": true, "listed": false, "modDate": 1395411079000, @@ -439,7 +441,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1352489845000, - "implClass": "com.dotcms.contenttype.model.field.TagField", + "clazz": "com.dotcms.contenttype.model.field.TagField", "indexed": true, "listed": false, "modDate": 1395411079000, @@ -457,7 +459,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1352489885000, - "implClass": "com.dotcms.contenttype.model.field.TextField", + "clazz": "com.dotcms.contenttype.model.field.TextField", "indexed": true, "listed": false, "modDate": 1395411079000, @@ -476,7 +478,7 @@ "fieldVariables": [], "fixed": false, "iDate": 1352489917000, - "implClass": "com.dotcms.contenttype.model.field.LineDividerField", + "clazz": "com.dotcms.contenttype.model.field.LineDividerField", "indexed": false, "listed": false, "modDate": 1395411079000, @@ -493,7 +495,7 @@ "dbColumn": "system_field2", "fieldVariables": [], "fixed": false, - "implClass": "com.dotcms.contenttype.model.field.RelationshipsTabField", + "clazz": "com.dotcms.contenttype.model.field.RelationshipsTabField", "indexed": false, "listed": false, "name": "Relationships", @@ -508,7 +510,7 @@ "fixed": false, "folder": "SYSTEM_FOLDER", "host": "SYSTEM_HOST", - "implClass": "com.dotcms.contenttype.model.type.SimpleContentType", + "clazz": "com.dotcms.contenttype.model.type.SimpleContentType", "name": "Wiki", "owner": "dotcms.org.1", "system": false, diff --git a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/content-type-object-insert.json b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/content-type-object-insert.json index 728e8324a41a..c10ca67f391c 100644 --- a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/content-type-object-insert.json +++ b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/content-type-object-insert.json @@ -9,7 +9,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1308941714000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableHostFolderField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableHostFolderField", "indexed": true, "listed": false, "modDate": 1478557845000, @@ -33,7 +33,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1308941148000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableTextField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableTextField", "indexed": true, "listed": true, "modDate": 1478557845000, @@ -52,7 +52,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1453474468000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableTagField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableTagField", "indexed": true, "listed": false, "modDate": 1478557845000, @@ -73,7 +73,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1411763369000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableWysiwygField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableWysiwygField", "indexed": false, "listed": false, "modDate": 1478557845000, @@ -98,7 +98,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1453472236000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableSelectField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableSelectField", "indexed": false, "listed": false, "modDate": 1478557845000, @@ -118,7 +118,7 @@ "fixed": false, "hint": "Recommended size 940x350", "iDate": 1308941399000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableBinaryField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableBinaryField", "indexed": false, "listed": false, "modDate": 1478557845000, @@ -141,7 +141,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1412016702000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableCustomField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableCustomField", "indexed": true, "listed": true, "modDate": 1478557845000, @@ -164,7 +164,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1412187539000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableCustomField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableCustomField", "indexed": true, "listed": true, "modDate": 1478557845000, @@ -181,7 +181,7 @@ "fixed": false, "folder": "SYSTEM_FOLDER", "host": "48190c8c-42c4-46af-8d1a-0cd5db894797", - "implClass": "com.dotcms.contenttype.model.type.ImmutableSimpleContentType", + "clazz": "com.dotcms.contenttype.model.type.ImmutableSimpleContentType", "multilingualable": false, "name": "Banner", "owner": "dotcms.org.1", diff --git a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/content-type-object.json b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/content-type-object.json index 5193ededdd31..9b79c17b608a 100644 --- a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/content-type-object.json +++ b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/content-type-object.json @@ -6,7 +6,7 @@ "folder": "SYSTEM_FOLDER", "host": "48190c8c-42c4-46af-8d1a-0cd5db894797", "iDate": 1453474503000, - "implClass": "com.dotcms.contenttype.model.type.ImmutableSimpleContentType", + "clazz": "com.dotcms.contenttype.model.type.ImmutableSimpleContentType", "inode": "4c441ada-944a-43af-a653-9bb4f3f0cb2b", "modDate": 1478557845000, "multilingualable": false, @@ -25,7 +25,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1308941714000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableHostFolderField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableHostFolderField", "indexed": true, "inode": "ee91a37d-9d9f-4488-a1ce-50516e5309dc", "listed": false, @@ -51,7 +51,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1308941148000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableTextField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableTextField", "indexed": true, "inode": "5c21daa4-1482-4bc9-9d61-04b42d35a6ee", "listed": true, @@ -72,7 +72,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1453474468000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableTagField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableTagField", "indexed": true, "inode": "0030b173-41c4-40ae-8331-1c438fcb514e", "listed": false, @@ -95,7 +95,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1411763369000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableWysiwygField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableWysiwygField", "indexed": false, "inode": "abb57118-7979-400e-9e7d-208e9dfe1f64", "listed": false, @@ -122,7 +122,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1453472236000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableSelectField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableSelectField", "indexed": false, "inode": "bd07dab3-c559-4d1b-873a-050e8cc6359c", "listed": false, @@ -144,7 +144,7 @@ "fixed": false, "hint": "Recommended size 940x350", "iDate": 1308941399000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableBinaryField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableBinaryField", "indexed": false, "inode": "fff86d86-7908-4922-aaed-a3e8b0c6aae4", "listed": false, @@ -169,7 +169,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1412016702000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableCustomField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableCustomField", "indexed": true, "inode": "c4712e56-ec64-4795-8613-63dff910b34e", "listed": true, @@ -194,7 +194,7 @@ "fieldVariales": [], "fixed": false, "iDate": 1412187539000, - "implClass": "com.dotcms.contenttype.model.field.ImmutableCustomField", + "clazz": "com.dotcms.contenttype.model.field.ImmutableCustomField", "indexed": true, "inode": "46e98b70-d4f8-4dbe-9e12-eb65ae00a07e", "listed": true, diff --git a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/empty-widget.json b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/empty-widget.json index bd0becbcbd1c..efb461d85175 100644 --- a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/empty-widget.json +++ b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/empty-widget.json @@ -7,5 +7,5 @@ "variable" : "testWidget", "folder" : "SYSTEM_FOLDER", "host" : "demo.dotcms.com", - "implClass" : "com.dotcms.contenttype.model.type.WidgetContentType" + "clazz" : "com.dotcms.contenttype.model.type.WidgetContentType" } ] \ No newline at end of file diff --git a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/file-asset.json b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/file-asset.json index d15f205d95cd..69bcc499b1f4 100644 --- a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/file-asset.json +++ b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/file-asset.json @@ -8,12 +8,12 @@ "variable": "testFileAsset", "folder": "SYSTEM_FOLDER", "host": "demo.dotcms.com", - "implClass": "com.dotcms.contenttype.model.type.FileAssetContentType", + "clazz": "com.dotcms.contenttype.model.type.FileAssetContentType", "fields": [ { "dataType": "TEXT", "fixed": false, - "implClass": "com.dotcms.contenttype.model.field.TextField", + "clazz": "com.dotcms.contenttype.model.field.TextField", "indexed": true, "listed": true, "modDate": 1478557845000, diff --git a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/page-content-type.json b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/page-content-type.json index a7ff0ccc69bd..2e3ecd4eb929 100644 --- a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/page-content-type.json +++ b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/page-content-type.json @@ -3,7 +3,7 @@ "variable": "SimpleHtmlPage3", "host": "SYSTEM_HOST", "folder": "SYSTEM_FOLDER", - "implClass": "com.dotcms.contenttype.model.type.PageContentType", + "clazz": "com.dotcms.contenttype.model.type.PageContentType", "fields": [{ "dataType": "TEXT", "searchable": true, @@ -14,7 +14,7 @@ "variable": "title", "values": "$velutil.mergeTemplate('/static/htmlpage_assets/title_custom_field.vtl')", "fixed": true, - "implClass": "com.dotcms.contenttype.model.field.CustomField" + "clazz": "com.dotcms.contenttype.model.field.CustomField" }, { "indexed": true, @@ -24,7 +24,7 @@ "required": true, "variable": "hostfolder", "fixed": true, - "implClass": "com.dotcms.contenttype.model.field.HostFolderField", + "clazz": "com.dotcms.contenttype.model.field.HostFolderField", "fieldVariables": [] }, { "dataType": "TEXT", @@ -35,7 +35,7 @@ "name": "Url", "required": true, "variable": "url", - "implClass": "com.dotcms.contenttype.model.field.TextField", + "clazz": "com.dotcms.contenttype.model.field.TextField", "fieldVariables": [] }, { "dataType": "TEXT", @@ -48,7 +48,7 @@ "values": "$velutil.mergeTemplate('/static/htmlpage_assets/cachettl_custom_field.vtl')", "regexCheck": "^[0-9]+$", "fixed": true, - "implClass": "com.dotcms.contenttype.model.field.CustomField", + "clazz": "com.dotcms.contenttype.model.field.CustomField", "fieldVariables": [] }, { "dataType": "TEXT", @@ -59,7 +59,7 @@ "variable": "template", "values": "$velutil.mergeTemplate('/static/htmlpage_assets/template_custom_field.vtl')", "fixed": true, - "implClass": "com.dotcms.contenttype.model.field.CustomField", + "clazz": "com.dotcms.contenttype.model.field.CustomField", "fieldVariables": [] }, { "dataType": "TEXT", @@ -70,20 +70,20 @@ "values": "|true", "defaultValue": "false", "fixed": true, - "implClass": "com.dotcms.contenttype.model.field.CheckboxField", + "clazz": "com.dotcms.contenttype.model.field.CheckboxField", "fieldVariables": [] }, { "dataType": "LONG_TEXT", "name": "Content", "variable": "content", - "implClass": "com.dotcms.contenttype.model.field.WysiwygField", + "clazz": "com.dotcms.contenttype.model.field.WysiwygField", "fieldVariables": [] }, { "dataType": "SYSTEM", "name": "Advanced Properties", "variable": "advancedtab", "dbColumn": "section_divider1", - "implClass": "com.dotcms.contenttype.model.field.TabDividerField", + "clazz": "com.dotcms.contenttype.model.field.TabDividerField", "fieldVariables": [] }, { "dataType": "INTEGER", @@ -95,7 +95,7 @@ "variable": "sortOrder", "defaultValue": "0", "fixed": true, - "implClass": "com.dotcms.contenttype.model.field.TextField", + "clazz": "com.dotcms.contenttype.model.field.TextField", "fieldVariables": [] }, { "dataType": "TEXT", @@ -104,7 +104,7 @@ "name": "Friendly Name", "variable": "friendlyname", "fixed": true, - "implClass": "com.dotcms.contenttype.model.field.TextField", + "clazz": "com.dotcms.contenttype.model.field.TextField", "fieldVariables": [] }, { "dataType": "TEXT", @@ -117,7 +117,7 @@ "values": "$velutil.mergeTemplate('/static/htmlpage_assets/redirect_custom_field.vtl')", "fixed": true, - "implClass": "com.dotcms.contenttype.model.field.CustomField", + "clazz": "com.dotcms.contenttype.model.field.CustomField", "fieldVariables": [] }, { "dataType": "TEXT", @@ -129,7 +129,7 @@ "values": "|true", "defaultValue": "false", "fixed": true, - "implClass": "com.dotcms.contenttype.model.field.CheckboxField", + "clazz": "com.dotcms.contenttype.model.field.CheckboxField", "fieldVariables": [] }, { "dataType": "LONG_TEXT", @@ -138,7 +138,7 @@ "name": "SEO Description", "variable": "seodescription", "fixed": true, - "implClass": "com.dotcms.contenttype.model.field.TextAreaField", + "clazz": "com.dotcms.contenttype.model.field.TextAreaField", "fieldVariables": [] }, { "dataType": "LONG_TEXT", @@ -147,7 +147,7 @@ "name": "SEO Keywords", "variable": "seokeywords", "fixed": true, - "implClass": "com.dotcms.contenttype.model.field.TextAreaField", + "clazz": "com.dotcms.contenttype.model.field.TextAreaField", "fieldVariables": [] }, { "dataType": "LONG_TEXT", @@ -161,7 +161,7 @@ "sortOrder": 15, "fixed": true, - "implClass": "com.dotcms.contenttype.model.field.TextAreaField", + "clazz": "com.dotcms.contenttype.model.field.TextAreaField", "fieldVariables": [] }] }] \ No newline at end of file diff --git a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/persona-type-object.json b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/persona-type-object.json index b3fffff418f9..d26b226819b1 100644 --- a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/persona-type-object.json +++ b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/persona-type-object.json @@ -1,5 +1,5 @@ { - "implClass": "com.dotcms.contenttype.model.type.PersonaContentType", + "clazz": "com.dotcms.contenttype.model.type.PersonaContentType", "description": "ANOTHER Structure for Personas", "defaultType": false, "system": false, @@ -10,7 +10,7 @@ "fixed": false, "fields": [ { - "implClass": "com.dotcms.contenttype.model.field.HostFolderField", + "clazz": "com.dotcms.contenttype.model.field.HostFolderField", "indexed": true, "dataType": "SYSTEM", "readOnly": false, @@ -24,7 +24,7 @@ "fixed": true }, { - "implClass": "com.dotcms.contenttype.model.field.TextField", + "clazz": "com.dotcms.contenttype.model.field.TextField", "indexed": true, "dataType": "TEXT", "readOnly": false, @@ -38,7 +38,7 @@ "fixed": true }, { - "implClass": "com.dotcms.contenttype.model.field.CustomField", + "clazz": "com.dotcms.contenttype.model.field.CustomField", "indexed": true, "dataType": "TEXT", "values": "$velutil.mergeTemplate('/static/personas/keytag_custom_field.vtl')", @@ -54,7 +54,7 @@ "fixed": true }, { - "implClass": "com.dotcms.contenttype.model.field.BinaryField", + "clazz": "com.dotcms.contenttype.model.field.BinaryField", "indexed": false, "dataType": "SYSTEM", "readOnly": false, @@ -69,7 +69,7 @@ "id": "07cfbc2c-47de-4c78-a411-176fe8bb24a5" }, { - "implClass": "com.dotcms.contenttype.model.field.TagField", + "clazz": "com.dotcms.contenttype.model.field.TagField", "indexed": true, "dataType": "LONG_TEXT", "readOnly": false, @@ -83,7 +83,7 @@ "fixed": true }, { - "implClass": "com.dotcms.contenttype.model.field.TextAreaField", + "clazz": "com.dotcms.contenttype.model.field.TextAreaField", "indexed": true, "dataType": "LONG_TEXT", "readOnly": false, diff --git a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/widget-type-object.json b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/widget-type-object.json index 33e56e107268..d5262b6a4b16 100644 --- a/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/widget-type-object.json +++ b/dotCMS/src/integration-test/resources/com/dotcms/contenttype/test/widget-type-object.json @@ -6,7 +6,7 @@ "system" : false, "variable" : "PhotoGallery", "folder" : "SYSTEM_FOLDER", - "implClass" : "com.dotcms.contenttype.model.type.WidgetContentType", + "clazz" : "com.dotcms.contenttype.model.type.WidgetContentType", "fields" : [ { "dataType" : "TEXT", "searchable" : true, @@ -20,7 +20,7 @@ "sortOrder" : 1, "fixed" : true, "dbColumn" : "text1", - "implClass" : "com.dotcms.contenttype.model.field.TextField", + "clazz" : "com.dotcms.contenttype.model.field.TextField", "fieldVariables" : [ ] }, { "dataType" : "SYSTEM", @@ -39,7 +39,7 @@ "contentTypeId" : "4b1fc848-87f0-4efb-94a8-d04e11f5d3fc", "dbColumn" : "constant", "iDate" : 1408051358000, - "implClass" : "com.dotcms.contenttype.model.field.TextAreaField", + "clazz" : "com.dotcms.contenttype.model.field.TextAreaField", "fieldVariables" : [ ] }, { "dataType" : "SYSTEM", @@ -59,7 +59,7 @@ "contentTypeId" : "4b1fc848-87f0-4efb-94a8-d04e11f5d3fc", "dbColumn" : "constant", "iDate" : 1408051358000, - "implClass" : "com.dotcms.contenttype.model.field.HiddenField", + "clazz" : "com.dotcms.contenttype.model.field.HiddenField", "fieldVariables" : [ ] }, { "dataType" : "SYSTEM", @@ -78,7 +78,7 @@ "contentTypeId" : "4b1fc848-87f0-4efb-94a8-d04e11f5d3fc", "dbColumn" : "constant", "iDate" : 1408051358000, - "implClass" : "com.dotcms.contenttype.model.field.HiddenField", + "clazz" : "com.dotcms.contenttype.model.field.HiddenField", "fieldVariables" : [ ] }, { "indexed" : true, @@ -97,7 +97,7 @@ "contentTypeId" : "4b1fc848-87f0-4efb-94a8-d04e11f5d3fc", "dbColumn" : "system_field1", "iDate" : 1408051454000, - "implClass" : "com.dotcms.contenttype.model.field.HostFolderField", + "clazz" : "com.dotcms.contenttype.model.field.HostFolderField", "fieldVariables" : [ ] }, { "dataType" : "INTEGER", @@ -116,7 +116,7 @@ "contentTypeId" : "4b1fc848-87f0-4efb-94a8-d04e11f5d3fc", "dbColumn" : "integer1", "iDate" : 1408051502000, - "implClass" : "com.dotcms.contenttype.model.field.TextField", + "clazz" : "com.dotcms.contenttype.model.field.TextField", "fieldVariables" : [ ] } ] } ] \ No newline at end of file diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeAPIImpl.java b/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeAPIImpl.java index 8104f19e0e18..3746f53cbe37 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeAPIImpl.java @@ -25,6 +25,7 @@ import com.dotcms.repackage.com.google.common.base.Preconditions; import com.dotcms.repackage.com.google.common.collect.ImmutableList; import com.dotcms.util.ContentTypeUtil; +import com.dotmarketing.beans.Host; import com.dotmarketing.beans.PermissionableProxy; import com.dotmarketing.business.APILocator; import com.dotmarketing.business.CacheLocator; @@ -37,6 +38,7 @@ import com.dotmarketing.db.LocalTransaction; import com.dotmarketing.exception.DotDataException; import com.dotmarketing.exception.DotSecurityException; +import com.dotmarketing.portlets.contentlet.business.HostAPI; import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.folders.model.Folder; import com.dotmarketing.portlets.structure.model.SimpleStructureURLMap; @@ -44,6 +46,7 @@ import com.dotmarketing.util.ActivityLogger; import com.dotmarketing.util.AdminLogger; import com.dotmarketing.util.Logger; +import com.dotmarketing.util.UUIDUtil; import com.dotmarketing.util.UtilMethods; import com.dotmarketing.util.json.JSONArray; import com.dotmarketing.util.json.JSONObject; @@ -195,10 +198,6 @@ public int count(String condition, BaseContentType base) throws DotDataException - public void validateFields(ContentType type) { - - fac.validateFields( type); - } diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/transform/contenttype/JsonContentTypeTransformer.java b/dotCMS/src/main/java/com/dotcms/contenttype/transform/contenttype/JsonContentTypeTransformer.java index 96bad91afb84..5556054ce556 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/transform/contenttype/JsonContentTypeTransformer.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/transform/contenttype/JsonContentTypeTransformer.java @@ -38,7 +38,7 @@ public JsonContentTypeTransformer(String json) { if (json != null && json.trim().startsWith("[")) { types = ImmutableList.copyOf(fromJsonArrayStr(json)); } else { - types = ImmutableList.of(fromJsonStr(json)); + types = ImmutableList.of(fromJsonObject(new JSONObject(json))); } } catch (JSONException arrEx) { throw new DotStateException(arrEx); @@ -75,9 +75,20 @@ public JSONObject jsonObject() { } - private ContentType fromJsonStr(String input) { + private ContentType fromJsonObject(JSONObject jo) { try { - return (ContentType) mapper.readValue(input, ContentType.class); + + if (jo.has("inode") && !jo.has("id")) { + jo.put("id", jo.get("inode")); + } + ContentType type = (ContentType) mapper.readValue(jo.toString(), ContentType.class); + + + if (jo.has("fields")) { + List fields = new JsonFieldTransformer(jo.getJSONArray("fields").toString()).asList(); + type.constructWithFields(fields); + } + return type; } catch (Exception e) { throw new DotStateException(e); } @@ -88,26 +99,8 @@ private List fromJsonArrayStr(String input) throws JSONException { List types = new ArrayList<>(); JSONArray jarr = new JSONArray(input); for (int i = 0; i < jarr.length(); i++) { - JSONObject jo = jarr.getJSONObject(i); - if (jo.has("inode") && !jo.has("id")) { - jo.put("id", jo.get("inode")); - } - HostAPI hapi = APILocator.getHostAPI(); - ContentType type = fromJsonStr(jo.toString()); - try { - Host host = UUIDUtil.isUUID(type.host()) || "SYSTEM_HOST".equalsIgnoreCase(type.host()) - ? hapi.find(type.host(), APILocator.systemUser(), true) - : hapi.resolveHostName(type.host(), APILocator.systemUser(), true); - type = ContentTypeBuilder.builder(type).host(host.getIdentifier()).build(); - } catch (DotDataException | DotSecurityException e) { - throw new DotStateException("unable to resolve host:" + type.host(), e); - } + types.add(fromJsonObject(jarr.getJSONObject(i))); - if (jo.has("fields")) { - List fields = new JsonFieldTransformer(jo.getJSONArray("fields").toString()).asList(); - type.constructWithFields(fields); - } - types.add(type); } return types; } diff --git a/dotCMS/src/main/java/com/dotcms/rest/api/v1/contenttype/ContentTypeResource.java b/dotCMS/src/main/java/com/dotcms/rest/api/v1/contenttype/ContentTypeResource.java index 2383b6a2eac0..afe98b7c54e5 100644 --- a/dotCMS/src/main/java/com/dotcms/rest/api/v1/contenttype/ContentTypeResource.java +++ b/dotCMS/src/main/java/com/dotcms/rest/api/v1/contenttype/ContentTypeResource.java @@ -33,6 +33,7 @@ import com.dotmarketing.business.DotStateException; import com.dotmarketing.exception.DotDataException; import com.dotmarketing.exception.DotSecurityException; +import com.dotmarketing.util.UUIDUtil; import com.dotmarketing.util.UtilMethods; import com.dotmarketing.util.json.JSONException; import com.dotmarketing.util.json.JSONObject; @@ -76,20 +77,16 @@ public final Response createType(@Context final HttpServletRequest req, final St try { List typesToSave = new JsonContentTypeTransformer(json).asList(); + List retTypes = new ArrayList<>(); + + // Validate input + for (ContentType type : typesToSave) { + if (UtilMethods.isSet(type.id()) && !UUIDUtil.isUUID(type.id())) { + return ExceptionMapperUtil.createResponse(null, "ContentType 'id' if set, should be a uuid"); + } + retTypes.add(APILocator.getContentTypeAPI(user, true).save(type)); + } - // Validate input - for (ContentType type : typesToSave) { - if (UtilMethods.isSet(type.id())) { - return ExceptionMapperUtil.createResponse(null, "Field 'id' should not be set"); - } - } - - List retTypes = new ArrayList<>(); - - // Persist input - for (ContentType type :typesToSave) { - retTypes.add(APILocator.getContentTypeAPI(user, true).save(type)); - } response = Response.ok(new ResponseEntityView(new JsonContentTypeTransformer(retTypes).mapList())).build();