Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue268 #273

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ buildscript {

dependencies {
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.11.0"
classpath 'com.android.tools.build:gradle:3.4.0'
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#Tue May 15 18:45:24 EAT 2018
#Mon Jul 15 16:46:41 BDT 2019
org.gradle.daemon=true
zipStorePath=wrapper/dists
org.gradle.parallel=true
zipStoreBase=GRADLE_USER_HOME
org.gradle.jvmargs=-Xmx2048m -XX\:MaxPermSize\=512m -XX\:+HeapDumpOnOutOfMemoryError -Dfile.encoding\=UTF-8
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
org.gradle.configureondemand=true
distributionPath=wrapper/dists
distributionBase=GRADLE_USER_HOME
3 changes: 0 additions & 3 deletions opensrp-app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="16" />

<application
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public abstract class RecyclerViewFragment extends
public String mainCondition = "";
public String Sortqueries;
public String tablename;

public String countSelect;
public String registerCondition = "";
public String joinTable = "";
public String joinTables[];
public RecyclerView clientsView;
Expand Down Expand Up @@ -450,12 +452,22 @@ private String filterandSortJoinArrayQuery() {
String query = "";
try {
if (isValidFilterForFts(commonRepository())) {
String sql = sqb
.searchQueryFts(tablename, joinTables, mainCondition, filters, Sortqueries,
clientAdapter.getCurrentlimit(), clientAdapter.getCurrentoffset());
List<String> ids = commonRepository().findSearchIds(sql);
query = sqb.toStringFts(ids, tablename, CommonRepository.ID_COLUMN,
Sortqueries);
String sql;
List<String> ids;
if(StringUtils.isBlank(registerCondition)){
sql = sqb
.searchQueryFts(tablename, joinTables, mainCondition, filters, Sortqueries,
clientAdapter.getCurrentlimit(), clientAdapter.getCurrentoffset());
ids = commonRepository().findSearchIds(sql);
query = sqb.toStringFts(ids, tablename, CommonRepository.ID_COLUMN,
Sortqueries);
}else{
sql = sqb.searchQueryFts(tablename,mainSelect,mainCondition,registerCondition,joinTables,filters,Sortqueries,clientAdapter.getCurrentlimit(), clientAdapter.getCurrentoffset());
ids = commonRepository().findSearchIds(sql);
query = sqb.toStringFts(ids, tablename, CommonRepository.ID_COLUMN,
Sortqueries,registerCondition);
}

query = sqb.Endquery(query);
} else {
sqb.addCondition(filters);
Expand All @@ -477,7 +489,12 @@ public void countExecute() {
SmartRegisterQueryBuilder sqb = new SmartRegisterQueryBuilder(countSelect);
String query = "";
if (isValidFilterForFts(commonRepository())) {
String sql = sqb.countQueryFts(tablename, joinTable, mainCondition, filters);
String sql = "";
if(StringUtils.isBlank(registerCondition)) {
sql = sqb.countQueryFts(tablename, joinTable, mainCondition, filters);
}else{
sql = countSelect;
}
Log.i(getClass().getName(), query);

clientAdapter.setTotalcount(commonRepository().countSearchIds(sql));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.smartregister.commonregistry.CommonFtsObject;
import org.smartregister.util.StringUtil;

import java.util.List;

Expand Down Expand Up @@ -175,7 +176,40 @@ public String toStringFts(List<String> ids, String idColumn) {

return res;
}
public String toStringFts(List<String> foundIds, String tName, String idCol, String sortBy,String condition) {
String res = Selectquery;
List<String> ids = foundIds;
String tableName = tName;
String idColumn = idCol;
String sort = sortBy;

if (StringUtils.containsIgnoreCase(res, "JOIN") && StringUtils.isNotBlank(tableName)) {
idColumn = tableName + "." + idColumn;
if (StringUtils.isNotBlank(sort)) {
sort = tableName + "." + sort;
}
}
// Remove where clause, Already used when fetching ids
if (StringUtils.containsIgnoreCase(res, "WHERE")) {
res = res.substring(0, res.toUpperCase().lastIndexOf("WHERE"));
}

if (ids.isEmpty()) {
res += String.format(" WHERE %s IN () ", idColumn);
} else {
String joinedIds = "'" + StringUtils.join(ids, "','") + "'";
res += String.format(" WHERE %s IN (%s) ", idColumn, joinedIds);

if(StringUtils.isNotBlank(condition)){
res += " AND " + condition;
}
if (StringUtils.isNotBlank(sort)) {
res += " ORDER BY " + sort;
}
}

return res;
}
public String toStringFts(List<String> foundIds, String tName, String idCol, String sortBy) {
String res = Selectquery;
List<String> ids = foundIds;
Expand Down Expand Up @@ -293,6 +327,25 @@ private String phraseClause(String tableName, String joinTable[], String mainCon
return phraseClause;
}

public String searchQueryFts(String tablename,String mainselect,String mainCondition,String condition,String searchJoinTable[],String searchFilter, String sort,int limit, int offset) {

String search_phrase = "";
if(StringUtils.isNotBlank(searchFilter)){
search_phrase = phraseClause(tablename, searchJoinTable,
mainCondition, searchFilter);
search_phrase = search_phrase.replaceFirst("WHERE"," AND ");
search_phrase = search_phrase.replaceFirst(CommonFtsObject.idColumn," id ");
}

String query;
if(mainselect.contains(mainCondition)){
query = mainselect + " AND " + condition + " " +search_phrase + orderByClause(sort) + limitClause(limit, offset);
}else{
query = mainselect + " WHERE " + mainCondition + " AND " + condition + search_phrase + orderByClause(sort) + limitClause(limit, offset);
}

return query;
}
public String searchQueryFts(String tablename, String searchJoinTable[], String mainCondition,
String searchFilter, String sort, int limit, int offset) {
if (ArrayUtils.isNotEmpty(searchJoinTable) && StringUtils.isNotBlank(searchFilter)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public LoginResponse isValidRemoteLogin(String userName, String password) {
LoginResponse loginResponse = httpAgent
.urlCanBeAccessWithGivenCredentials(requestURL, userName, password);

if (loginResponse.equals(LoginResponse.SUCCESS)) {
if (loginResponse!=null&&loginResponse.equals(LoginResponse.SUCCESS)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Android Studio formatter to format this (and other files)

saveUserGroup(userName, password, loginResponse.payload());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ public boolean onOptionsItemSelected(MenuItem item) {

return super.onOptionsItemSelected(item);
}
}
}