From 2087c0edd1cea5c219b9ecac6c137909018c7edc Mon Sep 17 00:00:00 2001 From: Thomas Roger Date: Fri, 4 Jun 2021 15:53:23 +0200 Subject: [PATCH] NXP-30360: cleanup/format --- .../nxql/CoreQueryAndFetchPageProvider.java | 26 +++++++++---------- .../nxql/CoreQueryDocumentPageProvider.java | 5 ++-- .../core/TestPageProviderCurrentPage.java | 20 +++++++------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/modules/platform/nuxeo-platform-query-api/src/main/java/org/nuxeo/ecm/platform/query/nxql/CoreQueryAndFetchPageProvider.java b/modules/platform/nuxeo-platform-query-api/src/main/java/org/nuxeo/ecm/platform/query/nxql/CoreQueryAndFetchPageProvider.java index 8b1ccc27d373..85aaac5c137f 100644 --- a/modules/platform/nuxeo-platform-query-api/src/main/java/org/nuxeo/ecm/platform/query/nxql/CoreQueryAndFetchPageProvider.java +++ b/modules/platform/nuxeo-platform-query-api/src/main/java/org/nuxeo/ecm/platform/query/nxql/CoreQueryAndFetchPageProvider.java @@ -207,8 +207,8 @@ protected void buildQuery() { String originalPattern = def.getPattern(); String pattern = quickFiltersClause.isEmpty() ? originalPattern : StringUtils.containsIgnoreCase(originalPattern, " WHERE ") - ? NXQLQueryBuilder.appendClause(originalPattern, quickFiltersClause) - : originalPattern + " WHERE " + quickFiltersClause; + ? NXQLQueryBuilder.appendClause(originalPattern, quickFiltersClause) + : originalPattern + " WHERE " + quickFiltersClause; newQuery = NXQLQueryBuilder.getQuery(pattern, getParameters(), def.getQuotePatternParameters(), def.getEscapePatternParameters(), getSearchDocumentModel(), sortArray); @@ -239,10 +239,9 @@ public PageSelections> getCurrentSelectPage() { } /** - * Fetch a page that can be selected. It loads the last page if we're targeting a page beyond the last one or - * the first page if there are no results to show and we're targeting anything other than the first page. - * - * Fix for NXP-8564. + * Fetch a page that can be selected. It loads the last page if we're targeting a page beyond the last one or the + * first page if there are no results to show and we're targeting anything other than the first page. Fix for + * NXP-8564. */ protected void rewindSelectablePage() { long pageSize = getPageSize(); @@ -251,19 +250,20 @@ protected void rewindSelectablePage() { if (resultsCount == 0) { // fetch first page directly if (log.isDebugEnabled()) { - log.debug(String.format( - "Current page %s is not the first one but " + "shows no result and there are " - + "no results => rewind to first page", - Long.valueOf(getCurrentPageIndex()))); + log.debug( + String.format( + "Current page %s is not the first one but " + "shows no result and there are " + + "no results => rewind to first page", + Long.valueOf(getCurrentPageIndex()))); } firstPage(); } else { // fetch last page if (log.isDebugEnabled()) { log.debug(String.format( - "Current page %s is not the first one but " + "shows no result and there are " - + "%s results => fetch last page", - Long.valueOf(getCurrentPageIndex()), Long.valueOf(resultsCount))); + "Current page %s is not the first one but " + "shows no result and there are " + + "%s results => fetch last page", + Long.valueOf(getCurrentPageIndex()), Long.valueOf(resultsCount))); } lastPage(); } diff --git a/modules/platform/nuxeo-platform-query-api/src/main/java/org/nuxeo/ecm/platform/query/nxql/CoreQueryDocumentPageProvider.java b/modules/platform/nuxeo-platform-query-api/src/main/java/org/nuxeo/ecm/platform/query/nxql/CoreQueryDocumentPageProvider.java index 4588c38b22a9..cd885aef1de3 100644 --- a/modules/platform/nuxeo-platform-query-api/src/main/java/org/nuxeo/ecm/platform/query/nxql/CoreQueryDocumentPageProvider.java +++ b/modules/platform/nuxeo-platform-query-api/src/main/java/org/nuxeo/ecm/platform/query/nxql/CoreQueryDocumentPageProvider.java @@ -293,8 +293,7 @@ public long getMaxResults() { if (maxResultsStr != null) { if (DEFAULT_NAVIGATION_RESULTS_KEY.equals(maxResultsStr)) { ConfigurationService cs = Framework.getService(ConfigurationService.class); - maxResultsStr = cs.getString(DEFAULT_NAVIGATION_RESULTS_PROPERTY, - DEFAULT_NAVIGATION_RESULTS_VALUE); + maxResultsStr = cs.getString(DEFAULT_NAVIGATION_RESULTS_PROPERTY, DEFAULT_NAVIGATION_RESULTS_VALUE); } else if (PAGE_SIZE_RESULTS_KEY.equals(maxResultsStr)) { maxResultsStr = Long.valueOf(getPageSize()).toString(); } @@ -367,7 +366,7 @@ protected void rewindSelectablePage() { String.format( "Current page %s is not the first one but " + "shows no result and there are " + "no results => rewind to first page", - Long.valueOf(getCurrentPageIndex()))); + Long.valueOf(getCurrentPageIndex()))); } firstPage(); } else { diff --git a/modules/platform/nuxeo-platform-query-api/src/test/java/org/nuxeo/ecm/platform/query/core/TestPageProviderCurrentPage.java b/modules/platform/nuxeo-platform-query-api/src/test/java/org/nuxeo/ecm/platform/query/core/TestPageProviderCurrentPage.java index 488510e9a053..056d395540dd 100644 --- a/modules/platform/nuxeo-platform-query-api/src/test/java/org/nuxeo/ecm/platform/query/core/TestPageProviderCurrentPage.java +++ b/modules/platform/nuxeo-platform-query-api/src/test/java/org/nuxeo/ecm/platform/query/core/TestPageProviderCurrentPage.java @@ -45,9 +45,7 @@ import org.nuxeo.runtime.test.runner.FeaturesRunner; /** - * @since 9.3 - * - * see NXP-23092 + * @since 9.3 see NXP-23092 */ @RunWith(FeaturesRunner.class) @Features(CoreFeature.class) @@ -71,7 +69,7 @@ public class TestPageProviderCurrentPage { public void createTestDocuments() { PageProviderDefinition ppd = pps.getPageProviderDefinition(DUMMY_FETCH_DOCUMENTS); long num_docs = ppd.getMaxPageSize() + SECOND_PAGE_NUM_DOCS; - for (int i=0; i < num_docs;i++) { + for (int i = 0; i < num_docs; i++) { DocumentModel doc = session.createDocumentModel("File"); doc.setPathInfo("/", "File " + i); doc.setPropertyValue("dc:source", "dummy"); @@ -86,20 +84,20 @@ public void testPageProviderCurrentPage() { HashMap props = new HashMap<>(); props.put(CoreQueryDocumentPageProvider.CORE_SESSION_PROPERTY, (Serializable) session); PageProvider pp = pps.getPageProvider(DUMMY_FETCH_DOCUMENTS, ppd, null, null, ppd.getMaxPageSize(), 0L, - props); + props); // check that both pages are different assertEquals(0, pp.getCurrentPageIndex()); assertEquals(pp.getMaxPageSize(), pp.getCurrentPageSize()); assertEquals(2, pp.getNumberOfPages()); List page = pp.getCurrentPage(); - String prevId = ((DocumentModel)page.get(0)).getId(); + String prevId = ((DocumentModel) page.get(0)).getId(); pp.setCurrentPage(1); assertEquals(1, pp.getCurrentPageIndex()); assertEquals(SECOND_PAGE_NUM_DOCS, pp.getCurrentPageSize()); assertEquals(2, pp.getNumberOfPages()); page = pp.getCurrentPage(); - assertNotEquals(prevId, ((DocumentModel)page.get(0)).getId()); - prevId = ((DocumentModel)page.get(0)).getId(); + assertNotEquals(prevId, ((DocumentModel) page.get(0)).getId()); + prevId = ((DocumentModel) page.get(0)).getId(); // since we only have two pages, requesting a third one should return an empty page pp.setCurrentPage(2); assertEquals(2, pp.getCurrentPageIndex()); @@ -108,7 +106,7 @@ public void testPageProviderCurrentPage() { // however, fetching the current selected page should return the last one instead PageSelections selections = pp.getCurrentSelectPage(); assertEquals(SECOND_PAGE_NUM_DOCS, selections.getSize()); - assertEquals(prevId, ((DocumentModel)selections.getEntries().get(0).getData()).getId()); + assertEquals(prevId, ((DocumentModel) selections.getEntries().get(0).getData()).getId()); } @Test @@ -122,13 +120,13 @@ public void testPageProviderCurrentPageWithoutPageSize() { assertEquals(pp.getMaxPageSize(), pp.getCurrentPageSize()); assertEquals(1, pp.getNumberOfPages()); List page = pp.getCurrentPage(); - String prevId = ((DocumentModel)page.get(0)).getId(); + String prevId = ((DocumentModel) page.get(0)).getId(); pp.setCurrentPage(1); assertEquals(0, pp.getCurrentPageIndex()); assertEquals(pp.getMaxPageSize(), pp.getCurrentPageSize()); assertEquals(1, pp.getNumberOfPages()); page = pp.getCurrentPage(); - assertEquals(prevId, ((DocumentModel)page.get(0)).getId()); + assertEquals(prevId, ((DocumentModel) page.get(0)).getId()); } }