fields)
+ {
+ super.setFields(fields);
+ return this;
+ }
+
+}
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CmisQueryTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CmisQueryTests.java
new file mode 100644
index 0000000000..7c703f9727
--- /dev/null
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/CmisQueryTests.java
@@ -0,0 +1,220 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2020 Alfresco Software Limited
+ * %%
+ * This file is part of the Alfresco software.
+ * -
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ * -
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * -
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ * -
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ * #L%
+ */
+
+package org.alfresco.rest.rm.community.search;
+
+import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_MANAGER;
+import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
+import static org.alfresco.utility.report.log.Step.STEP;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+
+import org.alfresco.dataprep.ContentActions;
+import org.alfresco.rest.rm.community.base.BaseRMRestTest;
+import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
+import org.alfresco.rest.rm.community.model.user.UserPermissions;
+import org.alfresco.test.AlfrescoTest;
+import org.alfresco.utility.Utility;
+import org.alfresco.utility.constants.UserRole;
+import org.alfresco.utility.model.FileModel;
+import org.alfresco.utility.model.FileType;
+import org.alfresco.utility.model.SiteModel;
+import org.alfresco.utility.model.UserModel;
+import org.apache.chemistry.opencmis.client.api.ItemIterable;
+import org.apache.chemistry.opencmis.client.api.OperationContext;
+import org.apache.chemistry.opencmis.client.api.QueryResult;
+import org.apache.chemistry.opencmis.client.runtime.OperationContextImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * Test to check that RM doesn't break CMIS query
+ *
+ * @author jcule, Rodica Sutu
+ * @since 2.5.4
+ * @since 3.3
+ */
+public class CmisQueryTests extends BaseRMRestTest
+{
+ private static final String SEARCH_TERM = generateTestPrefix(CmisQueryTests.class);
+ private static final String SQL_WITH_NAME =
+ "SELECT cmis:name FROM cmis:document where CONTAINS('cmis:name:*" + SEARCH_TERM + "*')";
+
+ private SiteModel collaborationSite;
+ private UserModel nonRMUser, rmUser;
+ private RecordCategoryChild recordFolder;
+
+ @Autowired
+ private ContentActions contentActions;
+
+ /**
+ * Create some test data:
+ *
+ * - a collaboration site with documents
+ * - in place records
+ * - category with folder and records
+ * - a user with no rm rights (no rights to see the record from file plan)
+ * - a user with rights to see the records and the other documents created
+ *
+ */
+ @BeforeClass (alwaysRun = true)
+ public void setupCmisQuery() throws Exception
+ {
+ STEP("Create a collaboration site");
+ collaborationSite = dataSite.usingAdmin().createPrivateRandomSite();
+
+ STEP("Create 10 documents ending with SEARCH_TERM");
+ for (int i = 0; ++i <= 10; )
+ {
+ FileModel fileModel = new FileModel(String.format("%s.%s", "Doc" + i + SEARCH_TERM,
+ FileType.TEXT_PLAIN.extention));
+ dataContent.usingAdmin().usingSite(collaborationSite).createContent(fileModel);
+ }
+
+ STEP("Create a collaborator user for the collaboration site");
+ nonRMUser = getDataUser().createRandomTestUser();
+ getDataUser().addUserToSite(nonRMUser, collaborationSite, UserRole.SiteManager);
+
+ STEP("Create 10 documents and declare as records");
+ for (int i = 0; ++i <= 10; )
+ {
+ FileModel fileModel = new FileModel(String.format("%s.%s", "InPlace " + SEARCH_TERM + i,
+ FileType.TEXT_PLAIN.extention));
+ fileModel = dataContent.usingUser(nonRMUser).usingSite(collaborationSite).createContent(fileModel);
+ getRestAPIFactory().getFilesAPI(nonRMUser).declareAsRecord(fileModel.getNodeRefWithoutVersion());
+ }
+
+ STEP("Create record folder and some records ");
+ recordFolder = createCategoryFolderInFilePlan();
+ for (int i = 0; ++i <= 10; )
+ {
+ createElectronicRecord(recordFolder.getId(), "Record " + SEARCH_TERM + i);
+ }
+ STEP("Create an rm user with read permission over the category created and contributor role within the " +
+ "collaboration site");
+ rmUser = getDataUser().createRandomTestUser();
+ getRestAPIFactory().getRMUserAPI().assignRoleToUser(rmUser.getUsername(), ROLE_RM_MANAGER.roleId);
+ getRestAPIFactory().getRMUserAPI().addUserPermission(recordFolder.getParentId(), rmUser, UserPermissions.PERMISSION_READ_RECORDS);
+ getDataUser().addUserToSite(rmUser, collaborationSite, UserRole.SiteContributor);
+
+
+ //do a cmis query to wait for solr indexing
+ Utility.sleep(5000, 80000, () ->
+ {
+ ItemIterable results = contentActions.getCMISSession(getAdminUser().getUsername(),
+ getAdminUser().getPassword()).query(SQL_WITH_NAME, false);
+ Assert.assertEquals(results.getTotalNumItems(), 30,
+ "Total number of items is not 10, got " + results.getTotalNumItems() + " total items");
+ });
+ }
+
+ /**
+ *
+ * Given the RM site created
+ * When I execute a cmis query to get all the documents names
+ * Then I get all documents names 100 per page
+ *
+ */
+ @Test (enabled = false, description = "Disabling test because there's no version of ACS that supports this yet")
+ @AlfrescoTest (jira = "MNT-19442")
+ public void getAllDocumentsNamesCmisQuery()
+ {
+ // execute the cmis query
+ String cq = "SELECT cmis:name FROM cmis:document";
+ ItemIterable results =
+ contentActions.getCMISSession(getAdminUser().getUsername(), getAdminUser().getPassword()).query(cq,
+ false);
+
+ // check the total number of items is greater than 100 and has more items is true
+ assertTrue("Has more items not true.", results.getHasMoreItems());
+ assertTrue("Total number of items is not greater than 100. Total number of items received" + results.getTotalNumItems(),
+ results.getTotalNumItems() > 100);
+ assertEquals("Expected 100 items per page and got " + results.getPageNumItems() + " per page.", 100,
+ results.getPageNumItems());
+ }
+
+ /**
+ *
+ * Given the RM site created
+ * When I execute a cmis query to get all the documents names with a particular name
+ * Then I get all documents names user has permission
+ *
+ */
+ @Test
+ @AlfrescoTest (jira = "MNT-19442")
+ public void getDocumentsWithSpecificNamesCmisQuery()
+ {
+ // execute the cmis query
+ ItemIterable results =
+ contentActions.getCMISSession(nonRMUser.getUsername(), nonRMUser.getPassword()).query(SQL_WITH_NAME,
+ false);
+ assertEquals("Total number of items is not 20, got " + results.getTotalNumItems() + " total items",
+ 20, results.getTotalNumItems());
+ // check the has more items is false
+ assertFalse("Has more items not false.", results.getHasMoreItems());
+ assertEquals("Expected 20 items per page and got " + results.getPageNumItems() + " per page.", 20,
+ results.getPageNumItems());
+ }
+
+ /**
+ *
+ * Given the RM site created
+ * When I execute a cmis query to get all the documents names with a specific number per page
+ * Then I get all documents names paged as requested that the user has permission
+ *
+ */
+ @Test
+ @AlfrescoTest (jira = "MNT-19442")
+ public void getDocumentsCmisQueryWithPagination()
+ {
+ OperationContext oc = new OperationContextImpl();
+ oc.setMaxItemsPerPage(10);
+ ItemIterable results =
+ contentActions.getCMISSession(rmUser.getUsername(), rmUser.getPassword()).query(SQL_WITH_NAME,
+ false, oc);
+
+ // check the total number of items and has more items is true
+ assertTrue("Has more items not true. ", results.getHasMoreItems());
+ assertEquals("Total number of items is not 30 " + results.getTotalNumItems(), 30,
+ results.getTotalNumItems());
+ assertEquals("Expected 10 items per page and got " + results.getPageNumItems() + " per page.",
+ 10, results.getPageNumItems());
+ }
+
+ @AfterClass
+ private void clearCmisQueryTests()
+ {
+ dataSite.usingAdmin().deleteSite(collaborationSite);
+ getRestAPIFactory().getRecordCategoryAPI().deleteRecordCategory(recordFolder.getParentId());
+ getDataUser().usingAdmin().deleteUser(rmUser);
+ getDataUser().usingAdmin().deleteUser(nonRMUser);
+ }
+}
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1Test.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1Test.java
new file mode 100644
index 0000000000..df28b05ac4
--- /dev/null
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchDocumentsV1Test.java
@@ -0,0 +1,192 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2020 Alfresco Software Limited
+ * %%
+ * This file is part of the Alfresco software.
+ * -
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ * -
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * -
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ * -
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ * #L%
+ */
+package org.alfresco.rest.rm.community.search;
+
+import static java.util.Arrays.asList;
+
+import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
+import static org.alfresco.utility.report.log.Step.STEP;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import org.alfresco.rest.core.search.SearchRequestBuilder;
+import org.alfresco.rest.rm.community.base.BaseRMRestTest;
+import org.alfresco.rest.search.RestRequestQueryModel;
+import org.alfresco.rest.search.SearchResponse;
+import org.alfresco.rest.v0.UserTrashcanAPI;
+import org.alfresco.utility.Utility;
+import org.alfresco.utility.model.FileModel;
+import org.alfresco.utility.model.FileType;
+import org.alfresco.utility.model.SiteModel;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+/**
+ * This class contains the tests for v1 Search API with documents with CMIS and AFTS queries
+ */
+public class SearchDocumentsV1Test extends BaseRMRestTest
+{
+ private static final String SEARCH_TERM = generateTestPrefix(SearchDocumentsV1Test.class);
+ private SiteModel collaborationSite;
+ private FileModel fileModel;
+
+ @Autowired
+ private UserTrashcanAPI userTrashcanAPI;
+
+ /**
+ * Data Provider with: queries using CMIS and AFTS languages
+ */
+ @DataProvider
+ public static Object[][] queryTypes()
+ {
+ RestRequestQueryModel cmisQueryModel = new RestRequestQueryModel();
+ cmisQueryModel.setQuery("select * from cmis:document WHERE cmis:name LIKE '%" + SEARCH_TERM + ".txt'");
+ cmisQueryModel.setLanguage("cmis");
+
+ RestRequestQueryModel aftsQueryModel = new RestRequestQueryModel();
+ aftsQueryModel.setQuery("cm:name:*" + SEARCH_TERM);
+ aftsQueryModel.setLanguage("afts");
+
+ return new RestRequestQueryModel[][] {
+ { cmisQueryModel },
+ { aftsQueryModel }
+ };
+ }
+
+ /**
+ * Create a collaboration site and some documents.
+ */
+ @BeforeClass (alwaysRun = true)
+ public void setupSearchDocumentsV1Test() throws Exception
+ {
+ STEP("Create a collaboration site");
+ collaborationSite = dataSite.usingAdmin().createPrivateRandomSite();
+
+ STEP("Create 10 documents ending with SEARCH_TERM");
+ for (int i = 0; ++i <= 10; )
+ {
+ fileModel = new FileModel(String.format("%s.%s", "Doc" + i + SEARCH_TERM, FileType.TEXT_PLAIN.extention));
+ dataContent.usingAdmin().usingSite(collaborationSite).createContent(fileModel);
+ }
+ waitIndexing();
+ }
+
+ /**
+ * Do the query to wait for solr indexing
+ *
+ * @throws Exception when maximum retry period is reached
+ */
+ private void waitIndexing() throws Exception
+ {
+ RestRequestQueryModel queryType = new RestRequestQueryModel();
+ queryType.setQuery("cm:name:*" + SEARCH_TERM);
+ queryType.setLanguage("afts");
+ Utility.sleep(1000, 80000, () ->
+ {
+ SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType)
+ .setPagingBuilder(new SearchRequestBuilder().setPagination(100, 0))
+ .setFieldsBuilder(asList("id", "name"));
+ SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest);
+ assertEquals(searchResponse.getPagination().getTotalItems().intValue(), 10,
+ "Total number of items is not retrieved yet");
+ });
+ }
+
+ /**
+ * Given some documents ending with a particular text
+ * When executing the search query with paging
+ * And setting the skipCount and maxItems to reach the number of total items
+ * Then hasMoreItems will be set to false
+ */
+ @Test(dataProvider = "queryTypes")
+ public void searchWhenMaxItemsReach(RestRequestQueryModel queryType) throws Exception
+ {
+ final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType)
+ .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 5))
+ .setFieldsBuilder(asList("id", "name"));
+
+ SearchResponse searchResponse = getRestAPIFactory().getSearchAPI().search(sqlRequest);
+ assertEquals(searchResponse.getPagination().getCount(), 5, "Expected maxItems to be five");
+ assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five");
+ assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
+ assertEquals(searchResponse.getEntries().size(), 5, "Expected total entries to be five");
+ }
+
+ /**
+ * Given some documents ending with a particular text
+ * When executing the search query with paging
+ * And setting skipCount and maxItems to exceed the number of total items
+ * Then hasMoreItems will be set to false
+ */
+ @Test(dataProvider = "queryTypes")
+ public void searchWhenTotalItemsExceed(RestRequestQueryModel queryType) throws Exception
+ {
+ final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType)
+ .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 6))
+ .setFieldsBuilder(asList("id", "name"));
+
+ SearchResponse searchResponse = getRestAPIFactory().getSearchAPI().search(sqlRequest);
+ assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
+ assertEquals(searchResponse.getPagination().getSkipCount(), 6, "Expected skip count to be six");
+ assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
+ assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
+ }
+
+ /**
+ * Given some documents ending with a particular text
+ * When executing the search query with paging
+ * And setting skipCount and maxItems under the number of total items
+ * Then hasMoreItems will be set to true
+ */
+ @Test (dataProvider = "queryTypes",
+ enabled = false, description = "Disabling test because there's no version of ACS that supports this yet")
+ public void searchResultsUnderTotalItems(RestRequestQueryModel queryType) throws Exception
+ {
+ final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryType)
+ .setPagingBuilder(new SearchRequestBuilder().setPagination(4, 5))
+ .setFieldsBuilder(asList("id", "name"));
+
+ SearchResponse searchResponse = getRestAPIFactory().getSearchAPI().search(sqlRequest);
+ assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
+ assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five");
+ assertTrue(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be true");
+ assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
+ }
+
+ @AfterClass (alwaysRun = true)
+ public void tearDown()
+ {
+ dataSite.usingAdmin().deleteSite(collaborationSite);
+ userTrashcanAPI.emptyTrashcan(getAdminUser().getUsername(), getAdminUser().getPassword());
+ }
+
+}
diff --git a/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java
new file mode 100644
index 0000000000..11296ff8dc
--- /dev/null
+++ b/rm-automation/rm-automation-community-rest-api/src/test/java/org/alfresco/rest/rm/community/search/SearchRecordsV1CmisTests.java
@@ -0,0 +1,230 @@
+/*
+ * #%L
+ * Alfresco Records Management Module
+ * %%
+ * Copyright (C) 2005 - 2020 Alfresco Software Limited
+ * %%
+ * This file is part of the Alfresco software.
+ * -
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ * -
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * -
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ * -
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ * #L%
+ */
+package org.alfresco.rest.rm.community.search;
+
+import static java.util.Arrays.asList;
+
+import static org.alfresco.rest.rm.community.model.user.UserRoles.ROLE_RM_MANAGER;
+import static org.alfresco.rest.rm.community.util.CommonTestUtils.generateTestPrefix;
+import static org.alfresco.utility.report.log.Step.STEP;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import org.alfresco.rest.core.search.SearchRequestBuilder;
+import org.alfresco.rest.rm.community.base.BaseRMRestTest;
+import org.alfresco.rest.rm.community.model.recordcategory.RecordCategoryChild;
+import org.alfresco.rest.rm.community.model.user.UserPermissions;
+import org.alfresco.rest.search.RestRequestQueryModel;
+import org.alfresco.rest.search.SearchResponse;
+import org.alfresco.rest.v0.UserTrashcanAPI;
+import org.alfresco.rest.v0.service.RoleService;
+import org.alfresco.utility.Utility;
+import org.alfresco.utility.constants.UserRole;
+import org.alfresco.utility.model.FileModel;
+import org.alfresco.utility.model.FileType;
+import org.alfresco.utility.model.SiteModel;
+import org.alfresco.utility.model.UserModel;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * This class contains the tests for v1 Search API with records with CMIS query
+ */
+public class SearchRecordsV1CmisTests extends BaseRMRestTest
+{
+ private static final String SEARCH_TERM = generateTestPrefix(SearchRecordsV1CmisTests.class);
+ private SiteModel collaborationSite;
+ private UserModel nonRMUser, rmUser;
+ private FileModel fileModel;
+ private RestRequestQueryModel queryModel;
+
+ @Autowired
+ private UserTrashcanAPI userTrashcanAPI;
+
+ @Autowired
+ private RoleService roleService;
+
+ /**
+ * Create a collaboration site and some in place records.
+ */
+ @BeforeClass (alwaysRun = true)
+ public void setupSearchRecordsV1Cmis() throws Exception
+ {
+ STEP("Create a collaboration site");
+ collaborationSite = dataSite.usingAdmin().createPrivateRandomSite();
+
+ STEP("Create a site manager user for the collaboration site");
+ nonRMUser = getDataUser().createRandomTestUser();
+ getDataUser().addUserToSite(nonRMUser, collaborationSite, UserRole.SiteManager);
+
+ STEP("Create an rm user");
+ rmUser = getDataUser().createRandomTestUser();
+
+ STEP("Create 10 documents and declare as records");
+ for (int i = 0; ++i <= 10; )
+ {
+ fileModel = new FileModel(String.format("%s.%s", "Record" + SEARCH_TERM + i, FileType.TEXT_PLAIN.extention));
+ fileModel = dataContent.usingUser(nonRMUser).usingSite(collaborationSite).createContent(fileModel);
+ getRestAPIFactory().getFilesAPI(nonRMUser).declareAsRecord(fileModel.getNodeRefWithoutVersion());
+ }
+ STEP("Create record folder and some records ");
+ RecordCategoryChild recordFolder = createCategoryFolderInFilePlan();
+ roleService.assignUserPermissionsOnCategoryAndRMRole(rmUser, recordFolder.getId(),
+ UserPermissions.PERMISSION_READ_RECORDS, ROLE_RM_MANAGER.roleId);
+ for (int i = 0; ++i <= 10; )
+ {
+ createElectronicRecord(recordFolder.getId(), "Record" + SEARCH_TERM + i);
+ }
+
+ queryModel = new RestRequestQueryModel();
+ queryModel.setQuery("select * from cmis:document WHERE cmis:name LIKE 'Record" + SEARCH_TERM + "%'");
+ queryModel.setLanguage("cmis");
+
+ //wait for solr indexing
+ Utility.sleep(1000, 80000, () ->
+ {
+ SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
+ .setPagingBuilder(new SearchRequestBuilder().setPagination(100, 0))
+ .setFieldsBuilder(asList("id", "name"));
+ SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(null).search(sqlRequest);
+ assertEquals(searchResponse.getPagination().getTotalItems().intValue(), 20,
+ "Total number of items is not retrieved yet");
+ });
+ }
+
+ /**
+ * Given some documents with names starting with a particular test
+ * When executing the search query with paging
+ * And setting the skipCount and maxItems to reach the number of total items
+ * Then hasMoreItems will be set to false
+ */
+ @Test
+ public void searchWhenTotalItemsReach() throws Exception
+ {
+ final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
+ .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 15))
+ .setFieldsBuilder(asList("id", "name"));
+
+ SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest);
+ assertEquals(searchResponse.getPagination().getCount(), 5, "Expected maxItems to be five");
+ assertEquals(searchResponse.getPagination().getSkipCount(), 15, "Expected skip count to be fifteen");
+ assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
+ assertEquals(searchResponse.getEntries().size(), 5, "Expected total entries to be five");
+ }
+
+ @Test
+ public void searchWhenTotalItemsReachWithNonRM() throws Exception
+ {
+ final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
+ .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 0))
+ .setFieldsBuilder(asList("id", "name"));
+
+ SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest);
+ assertEquals(searchResponse.getPagination().getCount(), 5, "Expected maxItems to be five");
+ assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five");
+ assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
+ assertEquals(searchResponse.getEntries().size(), 5, "Expected total entries to be five");
+ }
+
+ /**
+ * Given some documents with names starting with a particular text
+ * When executing the search query with paging
+ * And setting skipCount and maxItems to exceed the number of total items
+ * Then hasMoreItems will be set to false
+ */
+ @Test
+ public void searchWhenTotalItemsExceedRMUser() throws Exception
+ {
+ final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
+ .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 16))
+ .setFieldsBuilder(asList("id", "name"));
+
+ SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest);
+ assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
+ assertEquals(searchResponse.getPagination().getSkipCount(), 16, "Expected skip count to be sixteen");
+ assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
+ assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
+ }
+
+ @Test
+ public void searchWhenTotalItemsExceedNonRMUser() throws Exception
+ {
+ final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
+ .setPagingBuilder(new SearchRequestBuilder().setPagination(5, 6))
+ .setFieldsBuilder(asList("id", "name"));
+
+ SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest);
+ assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
+ assertEquals(searchResponse.getPagination().getSkipCount(), 6, "Expected skip count to be six");
+ assertFalse(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be false");
+ assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
+ }
+
+ /**
+ * Given some documents ending with a particular text
+ * When executing the search query with paging
+ * And setting skipCount and maxItems under the number of total items
+ * Then hasMoreItems will be set to true
+ */
+ @Test
+ public void searchResultsUnderTotalItemsRMUser() throws Exception
+ {
+ final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
+ .setPagingBuilder(new SearchRequestBuilder().setPagination(4, 15))
+ .setFieldsBuilder(asList("id", "name"));
+
+ SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(rmUser).search(sqlRequest);
+ assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
+ assertEquals(searchResponse.getPagination().getSkipCount(), 15, "Expected skip count to be fifteen");
+ assertTrue(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be true");
+ assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
+ }
+
+ @Test
+ public void searchResultsUnderTotalItemsNonRMUser() throws Exception
+ {
+ final SearchRequestBuilder sqlRequest = new SearchRequestBuilder().setQueryBuilder(queryModel)
+ .setPagingBuilder(new SearchRequestBuilder().setPagination(4, 5))
+ .setFieldsBuilder(asList("id", "name"));
+
+ SearchResponse searchResponse = getRestAPIFactory().getSearchAPI(nonRMUser).search(sqlRequest);
+ assertEquals(searchResponse.getPagination().getCount(), 4, "Expected maxItems to be four");
+ assertEquals(searchResponse.getPagination().getSkipCount(), 5, "Expected skip count to be five");
+ assertTrue(searchResponse.getPagination().isHasMoreItems(), "Expected hasMoreItems to be true");
+ assertEquals(searchResponse.getEntries().size(), 4, "Expected total entries to be four");
+ }
+
+ @AfterClass (alwaysRun = true)
+ public void tearDown()
+ {
+ dataSite.usingAdmin().deleteSite(collaborationSite);
+ userTrashcanAPI.emptyTrashcan(getAdminUser().getUsername(), getAdminUser().getPassword());
+ }
+}
diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-services-security-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-services-security-context.xml
index ce4d04e6f8..2fcb3340c2 100644
--- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-services-security-context.xml
+++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-public-services-security-context.xml
@@ -159,6 +159,7 @@
${system.acl.maxPermissionChecks}
+
diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMAfterInvocationProvider.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMAfterInvocationProvider.java
index ac37edeb46..f7ae3fc6c0 100644
--- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMAfterInvocationProvider.java
+++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMAfterInvocationProvider.java
@@ -46,10 +46,10 @@ import net.sf.acegisecurity.vote.AccessDecisionVoter;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
+import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil;
import org.alfresco.repo.search.SimpleResultSetMetaData;
import org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet;
import org.alfresco.repo.search.impl.querymodel.QueryEngineResults;
-import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.permissions.PermissionCheckCollection;
import org.alfresco.repo.security.permissions.PermissionCheckValue;
import org.alfresco.repo.security.permissions.PermissionCheckedCollection.PermissionCheckedCollectionMixin;
@@ -80,8 +80,8 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
private static final String AFTER_RM = "AFTER_RM";
+ private AuthenticationUtil authenticationUtil;
private int maxPermissionChecks;
-
private long maxPermissionCheckTimeMillis;
public boolean supports(ConfigAttribute configAttribute)
@@ -131,6 +131,16 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
this.maxPermissionCheckTimeMillis = maxPermissionCheckTimeMillis;
}
+ /**
+ * Sets the authentication util
+ *
+ * @param authenticationUtil The authentication util to set
+ */
+ public void setAuthenticationUtil(AuthenticationUtil authenticationUtil)
+ {
+ this.authenticationUtil = authenticationUtil;
+ }
+
@SuppressWarnings("rawtypes")
public Object decide(Authentication authentication, Object object, ConfigAttributeDefinition config, Object returnedObject)
{
@@ -148,7 +158,7 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
}
try
{
- if (AuthenticationUtil.isRunAsUserTheSystemUser())
+ if (authenticationUtil.isRunAsUserTheSystemUser())
{
if (logger.isDebugEnabled())
{
@@ -564,6 +574,13 @@ public class RMAfterInvocationProvider extends RMSecurityCommon
}
}
+ if (maxSize != null)
+ {
+ LimitBy limitBy = returnedObject.length() > maxSize ? LimitBy.FINAL_SIZE : LimitBy.UNLIMITED;
+ filteringResultSet.setResultSetMetaData(new SimpleResultSetMetaData(limitBy,
+ PermissionEvaluationMode.EAGER, returnedObject.getResultSetMetaData().getSearchParameters()));
+ }
+
filteringResultSet.setNumberFound(returnedObject.getNumberFound());
return filteringResultSet;