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

Fix: show center details without network #753

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

Always

Just for now

@@ -112,9 +112,42 @@ public DataManagerCenter(BaseApiManager baseApiManager,
* @return Collection Sheet * @return Collection Sheet
*/ */
public Observable<CenterWithAssociations> getCentersGroupAndMeeting(int id) { public Observable<CenterWithAssociations> getCentersGroupAndMeeting(int id) {
return mBaseApiManager switch (PrefManager.getUserStatus()) {
.getCenterApi() case 0:
.getCenterWithGroupMembersAndCollectionMeetingCalendar(id); return mBaseApiManager
.getCenterApi()
.getCenterWithGroupMembersAndCollectionMeetingCalendar(id);
case 1:
/**
* Return Center details from DatabaseHelperCenter.
*/
return mDatabaseHelperCenter.getCentersGroupAndMeeting(id);
default:
return Observable.just(new CenterWithAssociations());
}
}
/**
* This Method Fetching the Center Details from REST API
* and then Saving all details into the Database and then returns the Center Details
*
* @param centerId Center Id
* @return CenterWithAssociations
*/
public Observable<CenterWithAssociations> syncCentersGroupAndMeeting(
final int centerId) {
return mBaseApiManager.getCenterApi().
getCenterWithGroupMembersAndCollectionMeetingCalendar(centerId)
.concatMap(new Func1<CenterWithAssociations, Observable<? extends
CenterWithAssociations>>() {
@Override
public Observable<? extends CenterWithAssociations> call(
CenterWithAssociations centerWithAssociations) {
return mDatabaseHelperCenter.saveCentersGroupAndMeeting(
centerWithAssociations);
}
});
} }
public Observable<SaveResponse> createCenter(CenterPayload centerPayload) { public Observable<SaveResponse> createCenter(CenterPayload centerPayload) {
@@ -1,14 +1,18 @@
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.DatabaseHelperRunReport;
import com.mifos.objects.group.CenterInfo; import com.mifos.objects.group.CenterInfo;
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;
import javax.inject.Singleton; import javax.inject.Singleton;
import rx.Observable; import rx.Observable;
import rx.functions.Func1;
/** /**
* Created by Rajan Maurya on 05/02/17. * Created by Rajan Maurya on 05/02/17.
@@ -17,15 +21,51 @@
public class DataManagerRunReport { public class DataManagerRunReport {
public final BaseApiManager mBaseApiManager; public final BaseApiManager mBaseApiManager;
public final DatabaseHelperRunReport mDatabaseHelperRunReport;
@Inject @Inject
public DataManagerRunReport(BaseApiManager baseApiManager) { public DataManagerRunReport(BaseApiManager baseApiManager,
DatabaseHelperRunReport databaseHelperRunReport) {
mBaseApiManager = baseApiManager; mBaseApiManager = baseApiManager;
mDatabaseHelperRunReport = databaseHelperRunReport;
} }
public Observable<List<CenterInfo>> getCenterSummarInfo(int centerId, /**
* This Method sending the Request to REST API if UserStatus is 0 and
* get list of the center information. The response will pass Presenter to show in the view
* <p/>
*/
public Observable<List<CenterInfo>> getCenterSummaryInfo(int centerId,
boolean genericResultSet) { boolean genericResultSet) {
return mBaseApiManager.getRunReportsService() switch (PrefManager.getUserStatus()) {
.getCenterSummaryInfo(centerId, genericResultSet); case 0:
return mBaseApiManager.getRunReportsService()
.getCenterSummaryInfo(centerId, genericResultSet);
case 1:
return mDatabaseHelperRunReport.readCenterSummaryInfo(centerId);
default:
return Observable.just((List<CenterInfo>) new ArrayList<CenterInfo>());
}
}
/**
* This Method Fetching the center information from REST API
* and then Saving all center information into the Database and
* then returns the list of center info
* @param centerId Center Id
* @return List of CenterInfo
*/
public Observable<List<CenterInfo>> syncCenterSummaryInfo(final int centerId) {
return mBaseApiManager.getRunReportsService().getCenterSummaryInfo(centerId, false)
.concatMap(new Func1<List<CenterInfo>, Observable<? extends List<CenterInfo>>>() {
@Override
public Observable<? extends List<CenterInfo>> call(List<CenterInfo>
centerInfos) {
return mDatabaseHelperRunReport.saveCenterSummaryInfo(
centerInfos, centerId);
}
});
} }
} }
@@ -13,4 +13,4 @@
//Always Increase the Version Number //Always Increase the Version Number
public static final int VERSION = 2; public static final int VERSION = 2;
} }
@@ -4,6 +4,7 @@
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.group.Center; import com.mifos.objects.group.Center;
import com.mifos.objects.group.Group;
import com.raizlabs.android.dbflow.annotation.Migration; import com.raizlabs.android.dbflow.annotation.Migration;
import com.raizlabs.android.dbflow.sql.SQLiteType; import com.raizlabs.android.dbflow.sql.SQLiteType;
import com.raizlabs.android.dbflow.sql.migration.AlterTableMigration; import com.raizlabs.android.dbflow.sql.migration.AlterTableMigration;
@@ -56,4 +57,19 @@ public void onPreMigrate() {
addColumn(SQLiteType.INTEGER, "centerDate_year"); addColumn(SQLiteType.INTEGER, "centerDate_year");
} }
} }
@Migration(version = MifosDatabase.VERSION, database = MifosDatabase.class)

This comment has been minimized.

@mayank-kgp

mayank-kgp Aug 16, 2017

Contributor

@therajanmaurya Migration code added.

@mayank-kgp

mayank-kgp Aug 16, 2017

Contributor

@therajanmaurya Migration code added.

public static class Migration4 extends AlterTableMigration<Group> {
public Migration4(Class<Group> table) {
super(table);
}
@Override
public void onPreMigrate() {
addColumn(SQLiteType.INTEGER, "status_id");
addColumn(SQLiteType.TEXT, "status_code");
addColumn(SQLiteType.TEXT, "status_value");
}
}
} }
@@ -10,6 +10,7 @@
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.CenterWithAssociations_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;
@@ -18,6 +19,8 @@
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.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
@@ -152,6 +155,79 @@ public void call(Subscriber<? super Page<Center>> subscriber) {
}); });
} }
/**
* This Method write the Center Information in tho DB. According to Schema Defined in Model
* @param centerWithAssociations Model of Center Information
* @return CenterWithAssociations
*/
public Observable<CenterWithAssociations> saveCentersGroupAndMeeting(
final CenterWithAssociations centerWithAssociations) {
return Observable.defer(new Func0<Observable<CenterWithAssociations>>() {
@Override
public Observable<CenterWithAssociations> call() {
if (centerWithAssociations.getActivationDate().size() != 0) {
CenterDate centerDate = new CenterDate(centerWithAssociations.getId(), 0,
centerWithAssociations.getActivationDate().get(0),
centerWithAssociations.getActivationDate().get(1),
centerWithAssociations.getActivationDate().get(2));
centerWithAssociations.setCenterDate(centerDate);
List<List<Integer>> nextTenRecurringDates = centerWithAssociations.
getCollectionMeetingCalendar().getNextTenRecurringDates();
if (nextTenRecurringDates.size() > 0) {
CenterDate centerMeetingDate =
new CenterDate(centerWithAssociations.getId(), 0,
nextTenRecurringDates.get(0).get(0),
nextTenRecurringDates.get(0).get(1),
nextTenRecurringDates.get(0).get(2));
centerWithAssociations.getCollectionMeetingCalendar().
setCenterDate(centerMeetingDate);
}
}
centerWithAssociations.save();
return Observable.just(centerWithAssociations);
}
});
}
/**
* This Method Fetch the Center Info that are attached to the Center.
* @param centerId Center Id
* @return CenterWithAssociations
*/
public Observable<CenterWithAssociations> getCentersGroupAndMeeting(final int centerId) {
return Observable.defer(new Func0<Observable<CenterWithAssociations>>() {
@Override
public Observable<CenterWithAssociations> call() {
CenterWithAssociations centerWithAssociations = SQLite.select()
.from(CenterWithAssociations.class)
.where(CenterWithAssociations_Table.id.eq(centerId))
.querySingle();
if (centerWithAssociations != null) {
CenterDate centerDate = centerWithAssociations.getCenterDate();
centerWithAssociations.setActivationDate(Arrays.asList(centerDate.getDay(),
centerDate.getMonth(), centerDate.getYear()));
CenterDate nextMeeting = centerWithAssociations.
getCollectionMeetingCalendar().getCenterDate();
if (nextMeeting != null) {
List<List<Integer>> nextTenRecurringDates =
new ArrayList<List<Integer>>();
nextTenRecurringDates.add(0, (Arrays.asList(nextMeeting.getDay(),
nextMeeting.getMonth(), nextMeeting.getYear())));
centerWithAssociations.getCollectionMeetingCalendar()
.setNextTenRecurringDates(nextTenRecurringDates);
}
}
return Observable.just(centerWithAssociations);
}
});
}
/** /**
* This Method for deleting the center payload from the Database according to Id and * This Method for deleting the center payload from the Database according to Id and
* again fetch the center List from the Database CenterPayload_Table * again fetch the center List from the Database CenterPayload_Table
@@ -48,7 +48,6 @@ public DatabaseHelperGroups() {
return Observable.defer(new Func0<Observable<Group>>() { return Observable.defer(new Func0<Observable<Group>>() {
@Override @Override
public Observable<Group> call() { public Observable<Group> call() {
if (group.getActivationDate().size() != 0) { if (group.getActivationDate().size() != 0) {
GroupDate groupDate = new GroupDate(group.getId(), 0, GroupDate groupDate = new GroupDate(group.getId(), 0,
group.getActivationDate().get(0), group.getActivationDate().get(0),
@@ -96,9 +95,9 @@ public DatabaseHelperGroups() {
.where(Group_Table.id.eq(groupId)) .where(Group_Table.id.eq(groupId))
.querySingle(); .querySingle();
if (group != null) { if (group != null && group.getGroupDate() != null) {
group.setActivationDate(Arrays.asList(group.getGroupDate().getDay(), group.setActivationDate(Arrays.asList(group.getGroupDate().getDay(),
group.getGroupDate().getMonth(), group.getGroupDate().getYear())); group.getGroupDate().getMonth(), group.getGroupDate().getYear()));
} }
return Observable.just(group); return Observable.just(group);
@@ -0,0 +1,64 @@
package com.mifos.api.local.databasehelper;
import com.mifos.objects.group.CenterInfo;
import com.mifos.objects.group.CenterInfo_Table;
import com.raizlabs.android.dbflow.sql.language.SQLite;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Singleton;
import rx.Observable;
import rx.functions.Func0;
/**
* Created by mayankjindal on 09/08/17.
*/
@Singleton
public class DatabaseHelperRunReport {
@Inject
public DatabaseHelperRunReport() {
}
/**
* This Method Fetch the Center Summary that are attached to the Center.
* @param centerId Center Id
* @return List<CenterInfo>
*/
public Observable<List<CenterInfo>> readCenterSummaryInfo(final int centerId) {
return Observable.defer(new Func0<Observable<List<CenterInfo>>>() {
@Override
public Observable<List<CenterInfo>> call() {
List<CenterInfo> centerInfos = SQLite.select()
.from(CenterInfo.class)
.where(CenterInfo_Table.id.eq(centerId))
.queryList();
return Observable.just(centerInfos);
}
});
}
/**
* This Method write the Center Summary in tho DB. According to Schema Defined in Model
* @param centerInfos Model of List of Center Info
* @param centerId Center Id
* @return List<CenterInfo>
*/
public Observable<List<CenterInfo>> saveCenterSummaryInfo(final List<CenterInfo> centerInfos,
final int centerId) {
return Observable.defer(new Func0<Observable<List<CenterInfo>>>() {
@Override
public Observable<List<CenterInfo>> call() {
for (CenterInfo centerInfo : centerInfos) {
centerInfo.setId(centerId);
centerInfo.save();
}
return Observable.just(centerInfos);
}
});
}
}
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.