diff --git a/build.gradle b/build.gradle index a9e183a0d..3d7910799 100644 --- a/build.gradle +++ b/build.gradle @@ -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.1.4' } } @@ -47,7 +48,7 @@ subprojects { mavenCentral() maven { url 'https://jitpack.io' } maven { url "http://acra.googlecode.com/svn/repository/releases" } - maven { url "http://repo.maven.apache.org/maven2" } + maven { url "https://repo.maven.apache.org/maven2" } maven { url "http://cloudant.github.io/cloudant-sync-eap/repository" } maven { url "https://s3.amazonaws.com/repo.commonsware.com" diff --git a/gradle.properties b/gradle.properties index 9649d3537..3c0fa8cfb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=1.7.4-SNAPSHOT +VERSION_NAME=2.6.51-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Core Application diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3d717e315..f10422191 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#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 diff --git a/opensrp-app/AndroidManifest.xml b/opensrp-app/AndroidManifest.xml index c1b6e72f1..7431d16d6 100644 --- a/opensrp-app/AndroidManifest.xml +++ b/opensrp-app/AndroidManifest.xml @@ -18,9 +18,6 @@ - ids = commonRepository().findSearchIds(sql); - query = sqb.toStringFts(ids, tablename, CommonRepository.ID_COLUMN, - Sortqueries); + String sql; + List 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); @@ -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)); diff --git a/opensrp-app/src/main/java/org/smartregister/cursoradapter/SmartRegisterQueryBuilder.java b/opensrp-app/src/main/java/org/smartregister/cursoradapter/SmartRegisterQueryBuilder.java index ceacf5ed1..41f3d809f 100644 --- a/opensrp-app/src/main/java/org/smartregister/cursoradapter/SmartRegisterQueryBuilder.java +++ b/opensrp-app/src/main/java/org/smartregister/cursoradapter/SmartRegisterQueryBuilder.java @@ -176,6 +176,41 @@ public String toStringFts(List ids, String idColumn) { return res; } + public String toStringFts(List foundIds, String tName, String idCol, String sortBy, String condition) { + String res = Selectquery; + List 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 foundIds, String tName, String idCol, String sortBy) { String res = Selectquery; List ids = foundIds; @@ -293,6 +328,26 @@ 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)) { diff --git a/opensrp-app/src/main/java/org/smartregister/service/UserService.java b/opensrp-app/src/main/java/org/smartregister/service/UserService.java index 531e8c1c6..537cf8ee3 100644 --- a/opensrp-app/src/main/java/org/smartregister/service/UserService.java +++ b/opensrp-app/src/main/java/org/smartregister/service/UserService.java @@ -6,11 +6,7 @@ import android.util.Base64; import android.util.Log; -import org.apache.commons.lang3.StringUtils; -import org.smartregister.CoreLibrary; import org.smartregister.DristhiConfiguration; -import org.smartregister.SyncConfiguration; -import org.smartregister.SyncFilter; import org.smartregister.domain.LoginResponse; import org.smartregister.domain.Response; import org.smartregister.domain.TimeStatus; @@ -18,7 +14,6 @@ import org.smartregister.domain.jsonmapping.Time; import org.smartregister.domain.jsonmapping.User; import org.smartregister.domain.jsonmapping.util.LocationTree; -import org.smartregister.domain.jsonmapping.util.TeamLocation; import org.smartregister.domain.jsonmapping.util.TeamMember; import org.smartregister.repository.AllSettings; import org.smartregister.repository.AllSharedPreferences; @@ -297,7 +292,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)) { saveUserGroup(userName, password, loginResponse.payload()); } @@ -313,8 +308,7 @@ public Response getLocationInformation() { return httpAgent.fetch(requestURL); } - private boolean loginWith(String userName, String password) { - boolean loginSuccessful = true; + private void loginWith(String userName, String password) { if (usesGroupIdAsDBPassword(userName)) { String encryptedGroupId = allSharedPreferences.fetchEncryptedGroupId(userName); try { @@ -325,13 +319,11 @@ private boolean loginWith(String userName, String password) { } } catch (Exception e) { e.printStackTrace(); - loginSuccessful = false; } } else { setupContextForLogin(userName, password); } allSettings.registerANM(userName, password); - return loginSuccessful; } /** @@ -358,23 +350,15 @@ public void localLogin(String userName, String password) { } public void remoteLogin(String userName, String password, LoginResponseData userInfo) { - boolean loginSuccessful = loginWith(userName, password); + allSharedPreferences.saveForceRemoteLogin(false); + loginWith(userName, password); saveAnmLocation(getUserLocation(userInfo)); saveAnmTeam(getUserTeam(userInfo)); saveUserInfo(getUserData(userInfo)); saveDefaultLocationId(userName, getUserDefaultLocationId(userInfo)); - saveUserLocationId(userName, getUserLocationId(userInfo)); saveDefaultTeam(userName, getUserDefaultTeam(userInfo)); saveDefaultTeamId(userName, getUserDefaultTeamId(userInfo)); saveServerTimeZone(userInfo); - if (loginSuccessful && - (StringUtils.isBlank(getUserDefaultLocationId(userInfo)) || - StringUtils.isNotBlank(allSharedPreferences.fetchDefaultLocalityId(userName))) && - (StringUtils.isBlank(getUserDefaultTeamId(userInfo)) || - StringUtils.isNotBlank(allSharedPreferences.fetchDefaultTeamId(userName))) && - (getUserLocation(userInfo) != null || - StringUtils.isNotBlank(allSettings.fetchANMLocation()))) - allSharedPreferences.saveForceRemoteLogin(false); } public void forceRemoteLogin() { @@ -387,7 +371,7 @@ public User getUserData(LoginResponseData userInfo) { return userInfo.user; } } catch (Exception e) { - Log.e("Error : ", e.getMessage()); + Log.v("Error : ", e.getMessage()); } return null; } @@ -398,7 +382,7 @@ public LocationTree getUserLocation(LoginResponseData userInfo) { return userInfo.locations; } } catch (Exception e) { - Log.e("Error : ", e.getMessage()); + Log.v("Error : ", e.getMessage()); } return null; } @@ -409,7 +393,7 @@ public TeamMember getUserTeam(LoginResponseData userInfo) { return userInfo.team; } } catch (Exception e) { - Log.e("Error : ", e.getMessage()); + Log.v("Error : ", e.getMessage()); } return null; } @@ -426,7 +410,7 @@ public String getUserDefaultTeam(LoginResponseData userInfo) { return userInfo.team.team.teamName; } } catch (Exception e) { - Log.e("Error : ", e.getMessage()); + Log.v("Error : ", e.getMessage()); } return null; } @@ -443,7 +427,7 @@ public String getUserDefaultTeamId(LoginResponseData userInfo) { return userInfo.team.team.uuid; } } catch (Exception e) { - Log.e("Error : ", e.getMessage()); + Log.v("Error : ", e.getMessage()); } return null; @@ -461,32 +445,11 @@ public String getUserDefaultLocationId(LoginResponseData userInfo) { return userInfo.team.team.location.uuid; } } catch (Exception e) { - Log.e("Error : ", e.getMessage()); + Log.v("Error : ", e.getMessage()); } return null; } - public String getUserLocationId(LoginResponseData userInfo) { - try { - if (userInfo != null && userInfo.team != null && userInfo.team.locations != null && !userInfo.team.locations.isEmpty()) { - for (TeamLocation teamLocation : userInfo.team.locations) { - if (teamLocation != null) { - return teamLocation.uuid; - } - } - } - } catch (Exception e) { - Log.e("Error : ", e.getMessage()); - } - return null; - } - - public void saveUserLocationId(String userName, String locationId) { - if (userName != null) { - allSharedPreferences.saveUserLocalityId(userName, locationId); - } - } - public void saveAnmLocation(LocationTree anmLocation) { String amnLocationString = AssetHandler.javaToJsonString(anmLocation); saveANMLocationTask.save(amnLocationString); @@ -525,36 +488,13 @@ public void saveUserGroup(String userName, String password, LoginResponseData us if (keyStore != null && userName != null) { try { KeyStore.PrivateKeyEntry privateKeyEntry = createUserKeyPair(userName); - - if (password == null) { - return; - } - - - String groupId = null; - - SyncConfiguration syncConfiguration = CoreLibrary.getInstance().getSyncConfiguration(); - if (syncConfiguration.getEncryptionParam() != null) { - SyncFilter syncFilter = syncConfiguration.getEncryptionParam(); - if (SyncFilter.TEAM.equals(syncFilter) || SyncFilter.TEAM_ID.equals(syncFilter)) { - groupId = getUserDefaultTeamId(userInfo); - } else if (SyncFilter.LOCATION.equals(syncFilter)) { - groupId = getUserLocationId(userInfo); - } else if (SyncFilter.PROVIDER.equals(syncFilter)) { - groupId = password; - } - } - - if (StringUtils.isBlank(groupId)) { - return; - } - - if (privateKeyEntry != null) { + if (privateKeyEntry != null && userInfo.team != null && userInfo.team.team != null && userInfo.team.team.uuid != null) { // First save the encrypted password String encryptedPassword = encryptString(privateKeyEntry, password); allSharedPreferences.saveEncryptedPassword(userName, encryptedPassword); // Then save the encrypted group + String groupId = userInfo.team.team.uuid; String encryptedGroupId = encryptString(privateKeyEntry, groupId); allSharedPreferences.saveEncryptedGroupId(userName, encryptedGroupId); @@ -719,4 +659,4 @@ private String encryptString(KeyStore.PrivateKeyEntry privateKeyEntry, String pl return Base64.encodeToString(vals, Base64.DEFAULT); } -} +} \ No newline at end of file diff --git a/opensrp-app/src/main/java/org/smartregister/util/OpenSRPImageLoader.java b/opensrp-app/src/main/java/org/smartregister/util/OpenSRPImageLoader.java index c624ff87c..d229a8891 100644 --- a/opensrp-app/src/main/java/org/smartregister/util/OpenSRPImageLoader.java +++ b/opensrp-app/src/main/java/org/smartregister/util/OpenSRPImageLoader.java @@ -63,7 +63,7 @@ public class OpenSRPImageLoader extends ImageLoader { private static final int HALF_FADE_IN_TIME = AllConstants.ANIMATION_FADE_IN_TIME / 2; - + public static int IMAGE_QUALITY = 20; private static final float IMAGE_SCALE_PROPORTION = 0.95F; private static final String TAG = "OpenSRPImageLoader"; @@ -366,7 +366,7 @@ public static void saveStaticImageToDisk(String entityId, Bitmap image) { CompressFormat compressFormat = OpenSRPImageLoader .getCompressFormat(absoluteFileName); if (compressFormat != null) { - image.compress(compressFormat, 100, os); + image.compress(compressFormat, IMAGE_QUALITY, os); } else { throw new IllegalArgumentException( "Failed to save static image, could " + "not" diff --git a/sample/src/main/java/org/smartregister/sample/MainActivity.java b/sample/src/main/java/org/smartregister/sample/MainActivity.java index 4b740c076..56b6ef136 100644 --- a/sample/src/main/java/org/smartregister/sample/MainActivity.java +++ b/sample/src/main/java/org/smartregister/sample/MainActivity.java @@ -135,4 +135,4 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } -} +} \ No newline at end of file