Skip to content

Commit

Permalink
NXP-30360: cleanup/format
Browse files Browse the repository at this point in the history
  • Loading branch information
troger committed Jun 7, 2021
1 parent 5b6234d commit 2087c0e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
Expand Up @@ -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);
Expand Down Expand Up @@ -239,10 +239,9 @@ public PageSelections<Map<String, Serializable>> 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();
Expand All @@ -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();
}
Expand Down
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 {
Expand Down
Expand Up @@ -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)
Expand All @@ -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");
Expand All @@ -86,20 +84,20 @@ public void testPageProviderCurrentPage() {
HashMap<String, Serializable> 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());
Expand All @@ -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
Expand All @@ -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());
}

}

0 comments on commit 2087c0e

Please sign in to comment.