Skip to content

Commit

Permalink
#26459 include in 23.01.12
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Feb 13, 2024
1 parent 3412929 commit acee0e9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
import static com.dotcms.datagen.TestDataUtils.relateContentTypes;
import static com.dotcms.util.CollectionsUtils.list;
import static com.dotcms.util.CollectionsUtils.map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -21,12 +16,7 @@
import com.dotcms.content.elasticsearch.util.RestHighLevelClientProvider;
import com.dotcms.contenttype.business.ContentTypeAPI;
import com.dotcms.contenttype.business.FieldAPI;
import com.dotcms.contenttype.model.field.BinaryField;
import com.dotcms.contenttype.model.field.DateTimeField;
import com.dotcms.contenttype.model.field.Field;
import com.dotcms.contenttype.model.field.FieldBuilder;
import com.dotcms.contenttype.model.field.RelationshipField;
import com.dotcms.contenttype.model.field.TextField;
import com.dotcms.contenttype.model.field.*;
import com.dotcms.contenttype.model.type.ContentType;
import com.dotcms.contenttype.model.type.ContentTypeBuilder;
import com.dotcms.contenttype.model.type.SimpleContentType;
Expand Down Expand Up @@ -78,15 +68,10 @@
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.*;

import com.rainerhahnekamp.sneakythrow.Sneaky;
import java.util.Map;
import java.util.Optional;

import java.util.stream.Collectors;

import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -1881,4 +1866,34 @@ public void test_getUrlMapForContentlet_with_detail_page_and_pattern() throws Ex

assertEquals("/testing/urlMapValue1/urlMapValue2",contentletAPI.getUrlMapForContentlet(content, user, false));
}

/**
* Method to test: {@link ESContentletAPIImpl#copyContentlet(Contentlet, User, boolean)}
* Given Scenario:
* Unable to copy a contentlet with Host/Folder field. Error is thrown when the field name is "Host"
* ExpectedResult: Copy action should execute successfully without null-pointer error.
*
* @throws DotDataException
*/
@Test
public void test_copy_contentlet() throws DotDataException, DotSecurityException {
final List<Field> fields = new ArrayList<>();
fields.add(new FieldDataGen().name("Title").velocityVarName("title").next());
fields.add(new FieldDataGen().type(HostFolderField.class)
.name(Host.HOST_VELOCITY_VAR_NAME)
.velocityVarName(Host.HOST_VELOCITY_VAR_NAME)
.next());
final ContentType cType = new ContentTypeDataGen()
.host(APILocator.systemHost())
.fields(fields)
.nextPersisted();
final Contentlet contentlet = new ContentletDataGen(cType.id())
.host(APILocator.systemHost())
.nextPersisted();
final Contentlet respCont = contentletAPI.copyContentlet(contentlet, user, false);

assertNotEquals(respCont.getIdentifier(), contentlet.getIdentifier());
assertEquals(respCont.getHost(), APILocator.systemHost().getIdentifier());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8005,7 +8005,9 @@ public Contentlet copyContentlet(final Contentlet sourceContentlet, final Host h
}
}

if (tempField.getFieldType().equals(Field.FieldType.HOST_OR_FOLDER.toString())) {
//verify if the velocity var name is not Host to avoid override the host
if (tempField.getFieldType().equals(Field.FieldType.HOST_OR_FOLDER.toString())
&& !Host.HOST_VELOCITY_VAR_NAME.equalsIgnoreCase(tempField.getVelocityVarName())) {
if (folder != null || host != null){
newContentlet.setStringProperty(tempField.getVelocityVarName(), folder != null?folder.getInode():host.getIdentifier());
}else{
Expand Down
1 change: 1 addition & 0 deletions hotfix_tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,4 @@ This maintenance release includes the following code fixes:

160. https://github.com/dotCMS/core/issues/22372 : Users can create fields with reserved var names #22372
161. https://github.com/dotCMS/core/issues/26796 : Reserved names fields should be compared in a case-insensitive manner to avoid errors and inconsistencies. #26796
162. https://github.com/dotCMS/core/issues/26459 : Unable to copy a contentlet having Site/Folder Field #26459

0 comments on commit acee0e9

Please sign in to comment.