-
Notifications
You must be signed in to change notification settings - Fork 3
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
Process skipped clients #506
base: master
Are you sure you want to change the base?
Changes from 1 commit
b5b5dbb
21b014b
16470ec
443625a
b322055
77e7122
c405d49
51d9247
0402130
d3d2cfd
277e50c
89fb705
35ca072
fa8589f
eb00e3d
e2a4098
0c4106b
2f54b4b
5c5cf23
b4bb240
6bd8dfa
a834abb
07c67a8
4626b37
7e93ddf
27b7787
502694f
eeab005
57aa2d3
af4d112
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.smartregister.giz.job; | ||
|
||
import android.content.Intent; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.evernote.android.job.Job; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.smartregister.AllConstants; | ||
import org.smartregister.giz.service.ReProcessSyncIntentService; | ||
import org.smartregister.job.BaseJob; | ||
|
||
public class GizReProcessJob extends BaseJob { | ||
|
||
public static final String TAG = "GizReValidationJob"; | ||
|
||
@NonNull | ||
@NotNull | ||
@Override | ||
protected Result onRunJob(@NonNull @NotNull Job.Params params) { | ||
Intent intent = new Intent(getApplicationContext(), ReProcessSyncIntentService.class); | ||
getApplicationContext().startService(intent); | ||
return params != null && params.getExtras().getBoolean(AllConstants.INTENT_KEY.TO_RESCHEDULE, false) ? Result.RESCHEDULE : Result.SUCCESS; | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.smartregister.giz.recievers; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
|
||
import org.smartregister.domain.FetchStatus; | ||
import org.smartregister.giz.job.GizReProcessJob; | ||
|
||
import java.io.Serializable; | ||
|
||
import timber.log.Timber; | ||
|
||
import static org.smartregister.receiver.SyncStatusBroadcastReceiver.EXTRA_FETCH_STATUS; | ||
|
||
public class SyncStatusReciever extends BroadcastReceiver { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename this to |
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
Bundle data = intent.getExtras(); | ||
if (data != null) { | ||
Serializable fetchStatusSerializable = data.getSerializable(EXTRA_FETCH_STATUS); | ||
if (fetchStatusSerializable instanceof FetchStatus) { | ||
FetchStatus fetchStatus = (FetchStatus) fetchStatusSerializable; | ||
if (fetchStatus.equals(FetchStatus.fetched)) { | ||
GizReProcessJob.scheduleJobImmediately(GizReProcessJob.TAG); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we want to call the job once sync is complete eg sync is done fetching all the latest records and not successfully fetched one batch. I'm not sure if this is what is currently implemented |
||
Timber.d("Broadcast data fetched"); | ||
} else if (fetchStatus.equals(FetchStatus.nothingFetched)) { | ||
Timber.d("Broadcast data not fetched"); | ||
} else if (fetchStatus.equals(FetchStatus.noConnection)) { | ||
Timber.d("Broadcast data fetch failed"); | ||
} | ||
|
||
//} | ||
} | ||
} | ||
|
||
System.out.println("Broadcast Recieved"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,12 @@ | |
import net.sqlcipher.Cursor; | ||
import net.sqlcipher.database.SQLiteDatabase; | ||
|
||
import org.smartregister.giz.util.GizUtils; | ||
import org.smartregister.repository.BaseRepository; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class GizEventRepository extends BaseRepository { | ||
|
||
public boolean hasEvent(@NonNull String baseEntityId, @NonNull String eventType) { | ||
|
@@ -21,4 +25,37 @@ public boolean hasEvent(@NonNull String baseEntityId, @NonNull String eventType) | |
} | ||
return hasEvent; | ||
} | ||
|
||
public void ReprocessClients() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😄 |
||
{ | ||
String missingClientRegister = "SELECT DISTINCT baseEntityId, formSubmissionId AS formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM client_register_type)) AND eventType LIKE '%Registration%'"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure we need to alias formSubmissionId here |
||
String missingECClient = "SELECT DISTINCT baseEntityId, formSubmissionId AS formSubmissionId FROM event WHERE baseEntityId IN (SELECT baseEntityId FROM client WHERE baseEntityId NOT IN (SELECT DISTINCT base_entity_id FROM ec_client)) AND eventType LIKE '%Registration%'"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check previous comment on formSubmissionId |
||
List<String> formSubmissionIDs = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This list allows duplicates which might not be handled |
||
addFormSubmissionIds(formSubmissionIDs, missingClientRegister); | ||
addFormSubmissionIds(formSubmissionIDs,missingECClient); | ||
|
||
|
||
try { | ||
if(formSubmissionIDs.size()>0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reformat the code to fix spacing in the if statement |
||
GizUtils.initiateEventProcessing(formSubmissionIDs); | ||
} catch (Exception e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should be generally catching Exception here |
||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use Timber to print exceptions. It sends exceptions to Crashlytics |
||
|
||
|
||
public void addFormSubmissionIds(List<String> ids, String query) | ||
{ | ||
SQLiteDatabase database = getReadableDatabase(); | ||
Cursor cursor = database.rawQuery(query, null); | ||
int columnIndex = cursor.getColumnIndex("formSubmissionId"); | ||
if(cursor.getCount() > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reformat the code file to fix the spacing |
||
cursor.moveToFirst(); | ||
do { | ||
ids.add(cursor.getString(columnIndex)); | ||
} while (cursor.moveToNext()); | ||
} | ||
cursor.close(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.smartregister.giz.service; | ||
|
||
import android.app.IntentService; | ||
import android.content.Intent; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import org.smartregister.giz.application.GizMalawiApplication; | ||
|
||
public class ReProcessSyncIntentService extends IntentService { | ||
|
||
public static final String TAG = "ReValidateSyncIntentService"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's have the tag similar to the name of the service |
||
|
||
public ReProcessSyncIntentService() | ||
{ | ||
super(TAG); | ||
} | ||
|
||
public ReProcessSyncIntentService(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
protected void onHandleIntent(@Nullable Intent intent) { | ||
GizMalawiApplication.getInstance().gizEventRepository().ReprocessClients(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename this to
GIZClientReprocessJob
for now