Skip to content

Commit 1c5d021

Browse files
committed
ENG-5526: Added missing filter in countContents method
1 parent a723240 commit 1c5d021

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

cms-plugin/src/main/java/com/agiletec/plugins/jacms/aps/system/services/content/PublicContentSearcherDAO.java

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.HashSet;
2323
import java.util.List;
2424
import java.util.Set;
25+
import org.apache.commons.lang3.ArrayUtils;
2526
import org.entando.entando.ent.util.EntLogging.EntLogFactory;
2627
import org.entando.entando.ent.util.EntLogging.EntLogger;
2728

@@ -31,6 +32,14 @@
3132
public class PublicContentSearcherDAO extends AbstractContentSearcherDAO implements IContentSearcherDAO {
3233

3334
private static final EntLogger _logger = EntLogFactory.getSanitizedLogger(PublicContentSearcherDAO.class);
35+
36+
@Override
37+
public int countContents(String[] categories, boolean orClauseCategoryFilter,
38+
EntitySearchFilter[] filters, Collection<String> userGroupCodes) {
39+
EntitySearchFilter onLineFilter = new EntitySearchFilter(IContentManager.CONTENT_ONLINE_FILTER_KEY, false);
40+
EntitySearchFilter[] updatedFilters = (null != filters) ? ArrayUtils.add(filters, onLineFilter) : new EntitySearchFilter[]{onLineFilter};
41+
return super.countContents(categories, orClauseCategoryFilter, updatedFilters, userGroupCodes);
42+
}
3443

3544
@Override
3645
public List<String> loadContentsId(String[] categories,

cms-plugin/src/test/java/org/entando/entando/plugins/jacms/web/content/ContentControllerIntegrationTest.java

+25-5
Original file line numberDiff line numberDiff line change
@@ -2663,9 +2663,31 @@ private ResultActions performDeleteResource(String accessToken, String type, Str
26632663
delete(path)
26642664
.header("Authorization", "Bearer " + accessToken));
26652665
}
2666-
2666+
2667+
@Test
2668+
void testGetAllPaginatedContents() throws Exception {
2669+
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
2670+
String accessToken = mockOAuthInterceptor(user);
2671+
this.executeTestGetAllPaginatedContents(accessToken, IContentService.STATUS_DRAFT, 25);
2672+
this.executeTestGetAllPaginatedContents(accessToken, IContentService.STATUS_ONLINE, 24);
2673+
}
2674+
2675+
void executeTestGetAllPaginatedContents(String accessToken, String status, int expected) throws Exception {
2676+
ResultActions result = mockMvc
2677+
.perform(get("/plugins/cms/contents?page=1&pageSize=100")
2678+
.param("sort", IContentManager.CONTENT_CREATION_DATE_FILTER_KEY)
2679+
.param("direction", FieldSearchFilter.DESC_ORDER)
2680+
.param("status", status)
2681+
.header("Authorization", "Bearer " + accessToken));
2682+
String bodyResult = result.andReturn().getResponse().getContentAsString();
2683+
Integer payloadSize = JsonPath.read(bodyResult, "$.payload.size()");
2684+
Assertions.assertEquals(expected, payloadSize.intValue());
2685+
result.andExpect(status().isOk());
2686+
result.andExpect(jsonPath("$.metaData.totalItems", is(payloadSize)));
2687+
}
2688+
26672689
@Test
2668-
void testGetContentsPaginated() throws Exception {
2690+
void testGetEvnContentsPaginated() throws Exception {
26692691
UserDetails user = new OAuth2TestUtils.UserBuilder("jack_bauer", "0x24").grantedToRoleAdmin().build();
26702692
String accessToken = mockOAuthInterceptor(user);
26712693
ResultActions result = mockMvc
@@ -2676,9 +2698,7 @@ void testGetContentsPaginated() throws Exception {
26762698
.param("filter[0].operator", "eq")
26772699
.param("filter[0].value", "EVN")
26782700
.header("Authorization", "Bearer " + accessToken));
2679-
result
2680-
.andDo(resultPrint())
2681-
.andExpect(status().isOk())
2701+
result.andExpect(status().isOk())
26822702
.andExpect(jsonPath("$.payload.size()", is(2)))
26832703
.andExpect(jsonPath("$.metaData.page", is(1)))
26842704
.andExpect(jsonPath("$.metaData.pageSize", is(2)))

0 commit comments

Comments
 (0)