Skip to content

Commit

Permalink
#25666 include in 22.03.9
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Aug 22, 2023
1 parent 7a3fa66 commit 4723ebc
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
3 changes: 2 additions & 1 deletion HOTFIX_TRACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,5 @@ This maintenance release includes the following code fixes:
138. https://github.com/dotCMS/core/issues/21944 : Remove unnecessary Spring jars #21944
139. https://github.com/dotCMS/core/issues/22014 : PageCache is caching non-200 responses #22014
140. https://github.com/dotCMS/core/issues/22068 : lazy load workflow history in workflowprocessor #22068
141. https://github.com/dotCMS/core/issues/22131 : Remove invalid "View Statistics" Link #22131
141. https://github.com/dotCMS/core/issues/22131 : Remove invalid "View Statistics" Link #22131
142. https://github.com/dotCMS/core/issues/25666 : Pagination not working on related endpoint #25666
Original file line number Diff line number Diff line change
Expand Up @@ -1084,4 +1084,82 @@ public void testPullRelatedFieldShouldRespectDefaultOrder()
}
}
}

/**
* Method to test: {@link ContentUtils#pullRelatedField(Relationship, String, String, int, int, String, User, String, boolean, long, Boolean)}
* Given Scenario: Pulling related content when the offset is greater than the limit
* ExpectedResult: Should return results, if they're available.
*
* In this test 5 items are related, and we're passing offset = 3 and limit = 1, so 1 item should be returned.
* @throws DotDataException
* @throws DotSecurityException
*/
@Test
public void testPullRelatedField_withOffsetGreaterThanLimit()
throws DotDataException, DotSecurityException {

final long languageId = languageAPI.getDefaultLanguage().getId();
final ContentType news = getNewsLikeContentType("News");
final ContentType comments = getCommentsLikeContentType("Comments");
relateContentTypes(news, comments);

final ContentType newsContentType = contentTypeAPI.find("News");
final ContentType commentsContentType = contentTypeAPI.find("Comments");

Contentlet newsContentlet = null;
Contentlet commentsContentlet;
final List<Contentlet> relatedComments = new ArrayList<>();

try {
//creates parent contentlet
ContentletDataGen dataGen = new ContentletDataGen(newsContentType.id());

//English version
newsContentlet = dataGen.languageId(languageId)
.setProperty("title", "News Test")
.setProperty("urlTitle", "news-test").setProperty("byline", "news-test")
.setProperty("sysPublishDate", new Date()).setProperty("story", "news-test")
.next();

//creates child contentlet
dataGen = new ContentletDataGen(commentsContentType.id());

for (int i=1; i<5 ;i++){
commentsContentlet = dataGen
.languageId(languageId)
.setProperty("title", "Comment for News " + i)
.setProperty("email", "testing@dotcms.com")
.setProperty("comment", "Comment for News " + i)
.setPolicy(IndexPolicy.FORCE).nextPersisted();
relatedComments.add(commentsContentlet);

}

//Saving relationship
final Relationship relationship = relationshipAPI.byTypeValue("News-Comments");

newsContentlet.setIndexPolicy(IndexPolicy.FORCE);

newsContentlet = contentletAPI.checkin(newsContentlet,
map(relationship, relatedComments),
null, user, false);

//Pull related content from comment child
List<Contentlet> result = ContentUtils.
pullRelatedField(relationship, newsContentlet.getIdentifier(), "+languageId:1",
1, 3, "", user, null, false, languageId, false);

assertNotNull(result);
assertEquals(1,result.size());

} finally {
if (null != newsContentlet && UtilMethods.isSet(newsContentlet.getInode())) {
ContentletDataGen.remove(newsContentlet);
}

for (final Contentlet contentlet: relatedComments){
ContentletDataGen.remove(contentlet);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ public static List<Contentlet> pullRelated(String relationshipName, String conte
* Logic used for `pullRelated` and `pullRelatedField` methods
*/
public static List<Contentlet> getPullResults(final Relationship relationship,
String contentletIdentifier, final String condition, final int limit, final int offset,
String contentletIdentifier, final String condition, final int limit, int offset,
String sort, final User user, final String tmDate, final boolean pullParents,
final long language, final Boolean live) {

Expand Down Expand Up @@ -624,7 +624,8 @@ public static List<Contentlet> getPullResults(final Relationship relationship,
final List<Contentlet> filteredList = relatedContent.stream().filter(c->results.contains(c.getIdentifier()))
.collect(Collectors.toList());

return filteredList.subList(offset>=0?offset:0, (limit > 0 && limit <= filteredList.size())? limit: filteredList.size());
offset = offset >=0 ? offset : 0;
return filteredList.subList(offset, (limit <= 0 || limit >= filteredList.size() ) ? filteredList.size() : offset+limit);
}

//pulling parents
Expand Down

0 comments on commit 4723ebc

Please sign in to comment.