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

added Client Migration for changing the validation status to Invalid #2109

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ allprojects {
maven { url "https://cloudant.github.io/cloudant-sync-eap/repository" }
maven { url 'https://maven.fabric.io/public' }
maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
maven { url 'https://nexus.pentaho.org/content/groups/omni/' }
// maven { url 'https://nexus.pentaho.org/content/groups/omni/' }
maven {
url 'https://dl.bintray.com/ibm-watson-health/ibm-fhir-server-releases'
content {
Expand Down
8 changes: 4 additions & 4 deletions opensrp-chw/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ android {
versionName "1.0.8"
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '10000'
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '10000'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '1'
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this changed?

Copy link
Author

@junaidwarsivd junaidwarsivd Feb 2, 2023

Choose a reason for hiding this comment

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

it was not pulling the unique ids from source 2

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this section is under ba and not DRC

Copy link
Author

Choose a reason for hiding this comment

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

no this is under DRC

Copy link
Author

Choose a reason for hiding this comment

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

yes its under Ba it was originally '1' in BA (master branch) i've updated the correction

buildConfigField "String", 'opensrp_url', '"https://boresha-afya.smartregister.org/opensrp/"'
buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/ba/"'
buildConfigField "String", 'opensrp_url_debug', '"https://boresha-afya-stage.smartregister.org/opensrp/"'
Expand Down Expand Up @@ -272,8 +272,8 @@ android {
applicationIdSuffix ".drc"
versionCode 11
versionName "1.0.16"
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '10000'
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '10000'
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '10'
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '10'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2'
buildConfigField "String", 'opensrp_url', '"https://wcaro-cd.smartregister.org/opensrp/"'
buildConfigField "String", 'guidebooks_url', '"https://opensrp.s3.amazonaws.com/media/drc/"'
Expand All @@ -286,7 +286,7 @@ android {
buildConfigField "String", 'DEFAULT_LOCATION', '"VILLAGE/COMMUNAUTE"'
buildConfigField "int", "MAX_CONNECTION_TIMEOUT", '5'
buildConfigField "int", "MAX_READ_TIMEOUT", '5'
buildConfigField "int", "DATABASE_VERSION", '12'
buildConfigField "int", "DATABASE_VERSION", '13'
}
guinea {
dimension = 'baseDimension'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public static void onUpgrade(Context context, SQLiteDatabase db, int oldVersion,
case 12:
upgradeToVersion12(db);
break;
case 13:
Copy link
Contributor

Choose a reason for hiding this comment

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

Make these changes for all the flavours

  • DB migrations

Copy link
Author

Choose a reason for hiding this comment

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

@ekigamba different flavors use different DB versions for instance ba is at version 23 chad using 15 drc using 13 and so on should i upgrade all the versions to the same value?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, we should upgrade all the versions but to different values

upgradeToVersion13(db);
break;
default:
break;
}
Expand Down Expand Up @@ -165,4 +168,8 @@ private static void upgradeToVersion11(SQLiteDatabase db) {
private static void upgradeToVersion12(SQLiteDatabase db) {
RepositoryUtils.updateNullEventIds(db);
}
private static void upgradeToVersion13 (SQLiteDatabase db)
{
RepositoryUtils.updateClientValidateStatus(db);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public interface RepositoryUtils {

String EVENT_ID = "id";
String _ID = "_id";
String VALIDATION_STATUS = "validationStatus";
String STATUS_INVALID = "Invalid";

String ADD_MISSING_REPORTING_COLUMN = "ALTER TABLE 'indicator_queries' ADD COLUMN expected_indicators TEXT NULL;";
String FAMILY_MEMBER_ADD_REASON_FOR_REGISTRATION = "ALTER TABLE 'ec_family_member' ADD COLUMN reasons_for_registration TEXT NULL;";
Expand Down Expand Up @@ -132,4 +134,9 @@ static String getEventId(String jsonString) {
return eventId;
}

static void updateClientValidateStatus (SQLiteDatabase db)
{
db.execSQL(String.format("UPDATE client Set %s = '%s'",VALIDATION_STATUS,STATUS_INVALID));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.smartregister.chw.repository;

import net.sqlcipher.database.SQLiteDatabase;

import org.junit.Test;
import org.mockito.Mockito;
import org.smartregister.immunization.repository.VaccineRepository;

import static org.mockito.Mockito.verify;


public class ChwRepositoryFlvTest {

@Test
public void testOnUpgrade() {
SQLiteDatabase db = Mockito.mock(SQLiteDatabase.class);
ChwRepositoryFlv.onUpgrade(null, db, 1, 2);
verify(db).execSQL(VaccineRepository.UPDATE_TABLE_ADD_EVENT_ID_COL);
verify(db).execSQL(VaccineRepository.EVENT_ID_INDEX);
verify(db).execSQL(VaccineRepository.UPDATE_TABLE_ADD_FORMSUBMISSION_ID_COL);
verify(db).execSQL(VaccineRepository.FORMSUBMISSION_INDEX);
verify(db).execSQL(VaccineRepository.UPDATE_TABLE_ADD_OUT_OF_AREA_COL);
verify(db).execSQL(VaccineRepository.UPDATE_TABLE_ADD_OUT_OF_AREA_COL_INDEX);
verify(db).execSQL(VaccineRepository.UPDATE_TABLE_ADD_HIA2_STATUS_COL);


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.smartregister.chw.util;

import android.app.Activity;
import android.os.Bundle;

import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.smartregister.chw.anc.util.DBConstants;
import org.smartregister.commonregistry.CommonPersonObjectClient;

import java.util.Map;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class AllClientUtilsTest {

@Mock
private Activity mockActivity;

@Mock
private CommonPersonObjectClient mockPatient;

@Mock
private Bundle mockBundle;

@Mock
private Map<String,String> map;


@Before
public void setup (){
MockitoAnnotations.initMocks(this);
}

@Test
public void testGoToChildProfileAboveFiveYears() {
String dobString = "15";
when(mockPatient.getColumnmaps()).thenReturn(map);
when(map.get(DBConstants.KEY.DOB)).thenReturn(dobString);
AllClientsUtils.goToChildProfile(mockActivity, mockPatient, mockBundle);
verify(mockActivity).startActivity(ArgumentMatchers.any());
Copy link
Contributor

Choose a reason for hiding this comment

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

Kindly specify the specific activity called in this argument/param


}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.smartregister.chw.util;

import net.sqlcipher.Cursor;
import net.sqlcipher.MatrixCursor;
import net.sqlcipher.database.SQLiteDatabase;

import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -13,7 +16,18 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.smartregister.chw.application.ChwApplication;
import org.smartregister.domain.Event;
import org.smartregister.repository.EventClientRepository;
import org.smartregister.sync.helper.ECSyncHelper;

import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@RunWith(RobolectricTestRunner.class)
@Config(application = ChwApplication.class, sdk = 22)
Expand All @@ -22,6 +36,13 @@ public class RepositoryUtilsTest {
@Mock
private SQLiteDatabase database;

@Mock
private Cursor cursor;

@Mock
private ECSyncHelper ecSyncHelper;


@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
Expand All @@ -35,7 +56,7 @@ public void updateNullEventIdsUpdatesCorrectEvents() {
ArgumentMatchers.any(String[].class), ArgumentMatchers.eq("eventId IS NULL AND validationStatus = ?"),
ArgumentMatchers.any(String[].class), ArgumentMatchers.isNull(), ArgumentMatchers.isNull(), ArgumentMatchers.isNull());
RepositoryUtils.updateNullEventIds(database);
Mockito.verify(database).execSQL("UPDATE event SET eventId = '3b598b80-13ee-4a9a-8cd1-8e66fa76bbe9', " +
verify(database).execSQL("UPDATE event SET eventId = '3b598b80-13ee-4a9a-8cd1-8e66fa76bbe9', " +
"syncStatus = 'Synced' WHERE formSubmissionId = '45a294f5-ec2f-4233-847a-6f7910a6e63f';");
}

Expand Down Expand Up @@ -131,4 +152,41 @@ private static String getSampleEventJSONString() {
"}";
}

@Test
public void testReadEvents() throws JSONException {
List<Event> expectedEvents = new ArrayList<>();
Event event1 = new Event();
event1.setEventId("event1");
event1.setBaseEntityId("158cb2d0-a78f-4087-9ccc-0a0de9724548");
expectedEvents.add(event1);
when(cursor.getCount()).thenReturn(1);
when(cursor.moveToFirst()).thenReturn(true);
when(cursor.isAfterLast()).thenReturn(false, false, true);
when(cursor.getString(cursor.getColumnIndex("json"))).thenReturn(getSampleEventJSONString(), getSampleEventJSONString());
when(ecSyncHelper.convert(new JSONObject(getSampleEventJSONString()), Event.class)).thenReturn(event1);

List<Event> actualEvents = RepositoryUtils.readEvents(cursor);

assertEquals(expectedEvents.get(0).getBaseEntityId(), actualEvents.get(0).getBaseEntityId());
}


@Test
public void addDetailsColumnToFamilySearchTableShouldAddColumnsSuccessfully() {
// When
RepositoryUtils.addDetailsColumnToFamilySearchTable(database);

// Then
verify(database, times(1)).execSQL("ALTER TABLE ec_family ADD COLUMN entity_type VARCHAR; " +
"UPDATE ec_family SET entity_type = 'ec_family' WHERE id is not null;");
verify(database, times(5)).execSQL(anyString());
}

@Test
public void updateClientValidationStatusTest()
{
RepositoryUtils.updateClientValidateStatus(database);
verify(database, times(1)).execSQL(anyString());
}

}