diff --git a/core/build.gradle b/core/build.gradle index 38baea1874..c681da0c3d 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -36,8 +36,8 @@ ext { buildToolsVersion: "28.0.3", minSdkVersion : 19, targetSdkVersion : 28, - versionCode : 129, - versionName : "0.15.4-SNAPSHOT" + versionCode : 130, + versionName : "0.15.5-SNAPSHOT" ] libraries = [ diff --git a/core/gradle.properties b/core/gradle.properties index f376f574d8..c50a07fa94 100644 --- a/core/gradle.properties +++ b/core/gradle.properties @@ -29,8 +29,8 @@ # Properties which are consumed by plugins/gradle-mvn-push.gradle plugin. # They are used for publishing artifact to snapshot repository. -VERSION_NAME=0.15.4-SNAPSHOT -VERSION_CODE=129 +VERSION_NAME=0.15.5-SNAPSHOT +VERSION_CODE=130 GROUP=org.hisp.dhis diff --git a/core/src/main/java/org/hisp/dhis/android/core/arch/db/OrderByClauseBuilder.java b/core/src/main/java/org/hisp/dhis/android/core/arch/db/OrderByClauseBuilder.java index 0109a3901b..5a46ffeaa0 100644 --- a/core/src/main/java/org/hisp/dhis/android/core/arch/db/OrderByClauseBuilder.java +++ b/core/src/main/java/org/hisp/dhis/android/core/arch/db/OrderByClauseBuilder.java @@ -79,6 +79,7 @@ public static void addSortingClauses(WhereClauseBuilder whereClauseBuilder, .direction(RepositoryScope.OrderByDirection.ASC).build()); } + WhereClauseBuilder wrapperClause = new WhereClauseBuilder(); do { List nextIterationItems = new ArrayList<>(); WhereClauseBuilder subWhereClause = new WhereClauseBuilder(); @@ -91,10 +92,12 @@ public static void addSortingClauses(WhereClauseBuilder whereClauseBuilder, nextIterationItems.add(item); } } - whereClauseBuilder.appendOrComplexQuery(subWhereClause.build()); + wrapperClause.appendOrComplexQuery(subWhereClause.build()); items = nextIterationItems; } while (!items.isEmpty()); + + whereClauseBuilder.appendComplexQuery(wrapperClause.build()); } private static void addItemOperator(WhereClauseBuilder whereClauseBuilder, RepositoryScopeOrderByItem item, diff --git a/core/src/test/java/org/hisp/dhis/android/core/arch/repositories/collection/RepositoryPagingShould.java b/core/src/test/java/org/hisp/dhis/android/core/arch/repositories/collection/RepositoryPagingShould.java index d1b1c34016..692f8aa027 100644 --- a/core/src/test/java/org/hisp/dhis/android/core/arch/repositories/collection/RepositoryPagingShould.java +++ b/core/src/test/java/org/hisp/dhis/android/core/arch/repositories/collection/RepositoryPagingShould.java @@ -34,6 +34,7 @@ import org.hisp.dhis.android.core.arch.repositories.paging.RepositoryDataSource; import org.hisp.dhis.android.core.arch.repositories.paging.RepositoryPagingConfig; import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope; +import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScopeFilterItem; import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScopeHelper; import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScopeOrderByItem; import org.hisp.dhis.android.core.category.CategoryOption; @@ -137,22 +138,26 @@ public void get_initial_page_objects_with_two_order_by() { } @Test - public void get_after_page_objects_with_order_by() { + public void get_after_page_objects_with_order_by_and_filter() { when(key.toContentValues()).thenReturn(keyContentValues); when(keyContentValues.getAsString("_id")).thenReturn("5"); when(keyContentValues.getAsString("code")).thenReturn("key-code"); when(keyContentValues.getAsString("name")).thenReturn("key-name"); - RepositoryScope updatedScope = RepositoryScopeHelper.withOrderBy(emptyScope, + RepositoryScope filterScope = RepositoryScopeHelper.withFilterItem(emptyScope, + RepositoryScopeFilterItem.builder().key("program").operator("=").value("'uid'").build()); + + RepositoryScope updatedScope = RepositoryScopeHelper.withOrderBy(filterScope, RepositoryScopeOrderByItem.builder().column("code").direction(RepositoryScope.OrderByDirection.DESC).build()); RepositoryScope updatedScope2 = RepositoryScopeHelper.withOrderBy(updatedScope, RepositoryScopeOrderByItem.builder().column("name").direction(RepositoryScope.OrderByDirection.ASC).build()); RepositoryDataSource dataSource = new RepositoryDataSource<>(store, updatedScope2, childrenAppenders); dataSource.loadAfter(new ItemKeyedDataSource.LoadParams<>(key, 3), initialCallback); verify(store).selectWhere( - "(code = 'key-code' AND name = 'key-name' AND _id > '5') OR " + + "((code = 'key-code' AND name = 'key-name' AND _id > '5') OR " + "(code = 'key-code' AND name > 'key-name') OR " + - "(code < 'key-code')", + "(code < 'key-code')) " + + "AND program = 'uid'", "code DESC, name ASC, _id ASC", 3); verify(initialCallback).onResult(objects);