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

Add offline search feature #741

Closed
wants to merge 1 commit into
base: master
from
Jump to file or symbol
Failed to load files and symbols.
+266 −5
Diff settings

Always

Just for now

@@ -97,7 +97,6 @@ public DataManagerClient(BaseApiManager baseApiManager,
return mDatabaseHelperClient.readAllClients(); return mDatabaseHelperClient.readAllClients();
} }
/** /**
* This Method * This Method
* *
@@ -1,8 +1,16 @@
package com.mifos.api.datamanager; package com.mifos.api.datamanager;
import com.mifos.api.BaseApiManager; import com.mifos.api.BaseApiManager;
import com.mifos.api.local.databasehelper.DatabaseHelperCenter;
import com.mifos.api.local.databasehelper.DatabaseHelperClient;
import com.mifos.api.local.databasehelper.DatabaseHelperGroups;
import com.mifos.api.local.databasehelper.DatabaseHelperLoan;
import com.mifos.api.local.databasehelper.DatabaseHelperSavings;
import com.mifos.objects.SearchedEntity; import com.mifos.objects.SearchedEntity;
import com.mifos.utils.Constants;
import com.mifos.utils.PrefManager;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
@@ -17,14 +25,53 @@
public class DataManagerSearch { public class DataManagerSearch {
public final BaseApiManager baseApiManager; public final BaseApiManager baseApiManager;
public final DatabaseHelperClient mDatabaseHelperClient;
public final DatabaseHelperGroups mDatabaseHelperGroup;
public final DatabaseHelperCenter mDatabaseHelperCenter;
public final DatabaseHelperLoan mDatabaseHelperLoan;
public final DatabaseHelperSavings mDatabaseHelperSaving;
@Inject @Inject
public DataManagerSearch(BaseApiManager baseApiManager) { public DataManagerSearch(BaseApiManager baseApiManager,
DatabaseHelperClient databaseHelperClient,
DatabaseHelperGroups databaseHelperGroup,
DatabaseHelperCenter databaseHelperCenter,
DatabaseHelperLoan databaseHelperLoan,
DatabaseHelperSavings databaseHelperSaving) {
this.baseApiManager = baseApiManager; this.baseApiManager = baseApiManager;
mDatabaseHelperClient = databaseHelperClient;
mDatabaseHelperGroup = databaseHelperGroup;
mDatabaseHelperCenter = databaseHelperCenter;
mDatabaseHelperLoan = databaseHelperLoan;
mDatabaseHelperSaving = databaseHelperSaving;
} }
public Observable<List<SearchedEntity>> searchResources(String query, String resources, public Observable<List<SearchedEntity>> searchResources(final String query, String resources,
Boolean exactMatch) { final Boolean exactMatch) {
return baseApiManager.getSearchApi().searchResources(query, resources, exactMatch); switch (PrefManager.getUserStatus()) {
case 0:
return baseApiManager.getSearchApi().searchResources(query, resources, exactMatch);
case 1:
if (resources.equals(Constants.ENTITY_TYPE_CLIENTS)) {
return mDatabaseHelperClient.readAllClientsByQuery(query, exactMatch);
} else if (resources.equals(Constants.ENTITY_TYPE_GROUPS)) {
return Observable.merge(mDatabaseHelperGroup.readAllGroupsByQuery(query, exactMatch),

This comment has been minimized.

@mayank-kgp

mayank-kgp Aug 5, 2017

Contributor

@therajanmaurya updated.

@mayank-kgp

This comment has been minimized.

@mayank-kgp

mayank-kgp Aug 11, 2017

Contributor

@therajanmaurya I am waiting for your reply. I have tried by myself but still, I was not able to resolve the error.
The error is same -
#741 (comment)

@mayank-kgp

mayank-kgp Aug 11, 2017

Contributor

@therajanmaurya I am waiting for your reply. I have tried by myself but still, I was not able to resolve the error.
The error is same -
#741 (comment)

mDatabaseHelperCenter.readAllCentersByQuery(query, exactMatch));
} else if (resources.equals(Constants.ENTITY_TYPE_LOANS)) {
return mDatabaseHelperLoan.readAllLoansByQuery(query, exactMatch);
} else if (resources.equals(Constants.ENTITY_TYPE_SAVINGS)) {
return mDatabaseHelperSaving.readAllSavingsByQuery(query, exactMatch);
} else {
return Observable.merge(mDatabaseHelperClient.readAllClientsByQuery(query, exactMatch),
(mDatabaseHelperGroup.readAllGroupsByQuery(query, exactMatch)),
(mDatabaseHelperLoan.readAllLoansByQuery(query,
exactMatch)),
(mDatabaseHelperSaving.readAllSavingsByQuery(query,
exactMatch)));
}
default:
return Observable.just((List<SearchedEntity>) new ArrayList<SearchedEntity>());
}
} }
} }
@@ -3,21 +3,25 @@
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import com.mifos.objects.SearchedEntity;
import com.mifos.objects.accounts.CenterAccounts; import com.mifos.objects.accounts.CenterAccounts;
import com.mifos.objects.accounts.loan.LoanAccount; import com.mifos.objects.accounts.loan.LoanAccount;
import com.mifos.objects.accounts.savings.SavingsAccount; import com.mifos.objects.accounts.savings.SavingsAccount;
import com.mifos.objects.client.Page; import com.mifos.objects.client.Page;
import com.mifos.objects.group.Center; import com.mifos.objects.group.Center;
import com.mifos.objects.group.CenterDate; import com.mifos.objects.group.CenterDate;
import com.mifos.objects.group.CenterWithAssociations; import com.mifos.objects.group.CenterWithAssociations;
import com.mifos.objects.group.Center_Table;
import com.mifos.objects.group.Group; import com.mifos.objects.group.Group;
import com.mifos.objects.group.Group_Table; import com.mifos.objects.group.Group_Table;
import com.mifos.objects.response.SaveResponse; import com.mifos.objects.response.SaveResponse;
import com.mifos.services.data.CenterPayload; import com.mifos.services.data.CenterPayload;
import com.mifos.services.data.CenterPayload_Table; import com.mifos.services.data.CenterPayload_Table;
import com.mifos.utils.Constants;
import com.raizlabs.android.dbflow.sql.language.Delete; import com.raizlabs.android.dbflow.sql.language.Delete;
import com.raizlabs.android.dbflow.sql.language.SQLite; import com.raizlabs.android.dbflow.sql.language.SQLite;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
@@ -83,6 +87,42 @@ public void call(Subscriber<? super Page<Center>> subscriber) {
} }
public Observable<List<SearchedEntity>> readAllCentersByQuery(
final String query, final Boolean exactMatch) {
return Observable.create(new Observable.OnSubscribe<List<SearchedEntity>>() {
@Override
public void call(Subscriber<? super List<SearchedEntity>> subscriber) {
List<Center> centerList;
List<SearchedEntity> searchedEntities = new ArrayList<SearchedEntity>();
if (exactMatch) {
centerList = SQLite.select()
.from(Center.class)
.where(Center_Table.name.like(query))
.queryList();
} else {
centerList = SQLite.select()
.from(Center.class)
.where(Center_Table.name.like(("%" + query + "%")))
.queryList();
}
for (Center center : centerList) {
SearchedEntity searchedEntity = new SearchedEntity();
searchedEntity.setEntityId(center.getId());
searchedEntity.setEntityAccountNo(center.getAccountNo());
searchedEntity.setEntityType(Constants.SEARCH_ENTITY_CENTER);
searchedEntity.setEntityName(center.getName());
searchedEntity.setParentId(center.getOfficeId());
searchedEntity.setParentName(center.getOfficeName());
searchedEntities.add(searchedEntity);
}
subscriber.onNext(searchedEntities);
subscriber.onCompleted();
}
});
}
public Observable<SaveResponse> saveCenterPayload(final CenterPayload centerPayload) { public Observable<SaveResponse> saveCenterPayload(final CenterPayload centerPayload) {
return Observable.defer(new Func0<Observable<SaveResponse>>() { return Observable.defer(new Func0<Observable<SaveResponse>>() {
@Override @Override
@@ -4,6 +4,7 @@
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.mifos.objects.SearchedEntity;
import com.mifos.objects.accounts.ClientAccounts; import com.mifos.objects.accounts.ClientAccounts;
import com.mifos.objects.accounts.loan.LoanAccount; import com.mifos.objects.accounts.loan.LoanAccount;
import com.mifos.objects.accounts.loan.LoanAccount_Table; import com.mifos.objects.accounts.loan.LoanAccount_Table;
@@ -36,6 +37,7 @@
import com.raizlabs.android.dbflow.sql.language.Delete; import com.raizlabs.android.dbflow.sql.language.Delete;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@@ -122,6 +124,48 @@ public void call(Subscriber<? super Page<Client>> subscriber) {
} }
public Observable<List<SearchedEntity>> readAllClientsByQuery(
final String query, final Boolean exactMatch) {
return Observable.create(new Observable.OnSubscribe<List<SearchedEntity>>() {
@Override
public void call(Subscriber<? super List<SearchedEntity>> subscriber) {
List<Client> clientList;
List<SearchedEntity> searchedEntities = new ArrayList<SearchedEntity>();
if (exactMatch) {
clientList = select()
.from(Client.class)
.where(Client_Table.displayName.like(query))
.queryList();
} else {
clientList = select()
.from(Client.class)
.where(Client_Table.displayName.like(("%" + query + "%")))
.queryList();
}
for (Client client : clientList) {
SearchedEntity searchedEntity = new SearchedEntity();
com.mifos.objects.common.InterestType interestType =
new com.mifos.objects.common.InterestType();
searchedEntity.setEntityId(client.getId());
searchedEntity.setEntityAccountNo(client.getAccountNo());
searchedEntity.setEntityType(Constants.SEARCH_ENTITY_CLIENT);
searchedEntity.setEntityName(client.getDisplayName());
searchedEntity.setParentId(client.getOfficeId());
searchedEntity.setParentName(client.getOfficeName());
interestType.setId(client.getStatus().getId());
interestType.setCode(client.getStatus().getCode());
interestType.setValue(client.getStatus().getValue());
searchedEntity.setEntityStatus(interestType);
searchedEntities.add(searchedEntity);
}
subscriber.onNext(searchedEntities);
subscriber.onCompleted();
}
});
}
public Observable<GroupWithAssociations> getGroupAssociateClients(final int groupId) { public Observable<GroupWithAssociations> getGroupAssociateClients(final int groupId) {
return Observable.defer(new Func0<Observable<GroupWithAssociations>>() { return Observable.defer(new Func0<Observable<GroupWithAssociations>>() {
@Override @Override
@@ -1,5 +1,6 @@
package com.mifos.api.local.databasehelper; package com.mifos.api.local.databasehelper;
import com.mifos.objects.SearchedEntity;
import com.mifos.objects.accounts.GroupAccounts; import com.mifos.objects.accounts.GroupAccounts;
import com.mifos.objects.accounts.loan.LoanAccount; import com.mifos.objects.accounts.loan.LoanAccount;
import com.mifos.objects.accounts.loan.LoanAccount_Table; import com.mifos.objects.accounts.loan.LoanAccount_Table;
@@ -12,16 +13,19 @@
import com.mifos.objects.group.GroupPayload_Table; import com.mifos.objects.group.GroupPayload_Table;
import com.mifos.objects.group.Group_Table; import com.mifos.objects.group.Group_Table;
import com.mifos.objects.response.SaveResponse; import com.mifos.objects.response.SaveResponse;
import com.mifos.utils.Constants;
import com.raizlabs.android.dbflow.sql.language.Delete; import com.raizlabs.android.dbflow.sql.language.Delete;
import com.raizlabs.android.dbflow.sql.language.SQLite; import com.raizlabs.android.dbflow.sql.language.SQLite;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import rx.Observable; import rx.Observable;
import rx.Subscriber;
import rx.functions.Func0; import rx.functions.Func0;
/** /**
@@ -80,6 +84,47 @@ public DatabaseHelperGroups() {
}); });
} }
public Observable<List<SearchedEntity>> readAllGroupsByQuery(
final String query, final Boolean exactMatch) {
return Observable.create(new Observable.OnSubscribe<List<SearchedEntity>>() {
@Override
public void call(Subscriber<? super List<SearchedEntity>> subscriber) {
List<Group> groupList;
List<SearchedEntity> searchedEntities = new ArrayList<SearchedEntity>();
if (exactMatch) {
groupList = SQLite.select()
.from(Group.class)
.where(Group_Table.name.like(query))
.queryList();
} else {
groupList = SQLite.select()
.from(Group.class)
.where(Group_Table.name.like(("%" + query + "%")))
.queryList();
}
for (Group group : groupList) {
SearchedEntity searchedEntity = new SearchedEntity();
com.mifos.objects.common.InterestType interestType =
new com.mifos.objects.common.InterestType();
searchedEntity.setEntityId(group.getId());
searchedEntity.setEntityAccountNo(group.getAccountNo());
searchedEntity.setEntityType(Constants.SEARCH_ENTITY_GROUP);
searchedEntity.setEntityName(group.getName());
searchedEntity.setParentId(group.getOfficeId());
searchedEntity.setParentName(group.getOfficeName());
interestType.setId(group.getStatus().getId());
interestType.setCode(group.getStatus().getCode());
interestType.setValue(group.getStatus().getValue());
searchedEntity.setEntityStatus(interestType);
searchedEntities.add(searchedEntity);
}
subscriber.onNext(searchedEntities);
subscriber.onCompleted();
}
});
}
/** /**
* This Method Retrieving the Group from the Local Database. * This Method Retrieving the Group from the Local Database.
* *
@@ -1,6 +1,7 @@
package com.mifos.api.local.databasehelper; package com.mifos.api.local.databasehelper;
import com.mifos.objects.PaymentTypeOption; import com.mifos.objects.PaymentTypeOption;
import com.mifos.objects.SearchedEntity;
import com.mifos.objects.accounts.loan.ActualDisbursementDate; import com.mifos.objects.accounts.loan.ActualDisbursementDate;
import com.mifos.objects.accounts.loan.LoanRepaymentRequest; import com.mifos.objects.accounts.loan.LoanRepaymentRequest;
import com.mifos.objects.accounts.loan.LoanRepaymentRequest_Table; import com.mifos.objects.accounts.loan.LoanRepaymentRequest_Table;
@@ -10,16 +11,19 @@
import com.mifos.objects.accounts.loan.Timeline; import com.mifos.objects.accounts.loan.Timeline;
import com.mifos.objects.templates.loans.LoanRepaymentTemplate; import com.mifos.objects.templates.loans.LoanRepaymentTemplate;
import com.mifos.objects.templates.loans.LoanRepaymentTemplate_Table; import com.mifos.objects.templates.loans.LoanRepaymentTemplate_Table;
import com.mifos.utils.Constants;
import com.raizlabs.android.dbflow.sql.language.Delete; import com.raizlabs.android.dbflow.sql.language.Delete;
import com.raizlabs.android.dbflow.sql.language.SQLite; import com.raizlabs.android.dbflow.sql.language.SQLite;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import rx.Observable; import rx.Observable;
import rx.Subscriber;
import rx.functions.Func0; import rx.functions.Func0;
/** /**
@@ -109,6 +113,43 @@ public DatabaseHelperLoan() {
}); });
} }
public Observable<List<SearchedEntity>> readAllLoansByQuery(
final String query, final Boolean exactMatch) {
return Observable.create(new Observable.OnSubscribe<List<SearchedEntity>>() {
@Override
public void call(Subscriber<? super List<SearchedEntity>> subscriber) {
List<LoanWithAssociations> loanList;
List<SearchedEntity> searchedEntities = new ArrayList<SearchedEntity>();
if (exactMatch) {
loanList = SQLite.select()
.from(LoanWithAssociations.class)
.where(LoanWithAssociations_Table.loanProductName.like(query))
.queryList();
} else {
loanList = SQLite.select()
.from(LoanWithAssociations.class)
.where(LoanWithAssociations_Table.loanProductName.like(
("%" + query + "%")))
.queryList();
}
for (LoanWithAssociations loan : loanList) {
SearchedEntity searchedEntity = new SearchedEntity();
searchedEntity.setEntityId(loan.getId());
searchedEntity.setEntityAccountNo(loan.getAccountNo());
searchedEntity.setEntityType(Constants.SEARCH_ENTITY_LOAN);
searchedEntity.setEntityName(loan.getLoanProductName());
searchedEntity.setParentId(loan.getClientId());
searchedEntity.setParentName(loan.getClientName());
searchedEntities.add(searchedEntity);
}
subscriber.onNext(searchedEntities);
subscriber.onCompleted();
}
});
}
/** /**
* This Method Saving the Loan Transaction Offline in Database Table * This Method Saving the Loan Transaction Offline in Database Table
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.