Skip to content

Commit 2572e68

Browse files
authored
Merge pull request openimis#215 from mngoe/feature-33539
add glitchip/sentry configurations
2 parents d091727 + 36e3522 commit 2572e68

6 files changed

Lines changed: 126 additions & 95 deletions

File tree

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,14 @@ fastlane/test_output
6060
fastlane/readme.md
6161

6262
app/release/output.json
63-
.DS_Store
6463

6564
# Custom product flavours
6665

6766
*custom-flavours.gradle
6867
*.aab
68+
69+
#DS_Store files
70+
*.DS_Store
71+
.DS_Store
72+
./.DS_Store
73+
./.git/.DS_Store

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Parameters:
4949
* ```RAR_PASSWORD``` represents the password to be used for the offline extract.
5050
* ```SHOW_CONTROL_NUMBER_MENU``` allow to show or hide the Control Number menu item in case the implementation does not implement the ePayment module.
5151
* ```app_name_policies``` is a resource string allowing to change the name of the application.
52+
* ```sentry_dsn``` allow to define the sentry dsn of your project where error and exception events from your application will be sent
5253

5354
Escape procedures can be configured and language resource files can be changed. Please follow the ```sourceSets``` record. Look in ```app\src\demo``` folder for an example.
5455

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ android {
5252
buildConfigField "boolean", "IS_PAYMENT_ENABLED", 'false'
5353
resValue "string", "app_name_policies", "Policies"
5454
resValue "string", "ReleaseDateValue", getDate()
55+
resValue "string", "sentry_dsn", ""
5556
}
5657
buildTypes {
5758
release {
@@ -263,6 +264,7 @@ dependencies {
263264

264265
// unit tests
265266
testImplementation 'junit:junit:4.13.2'
267+
implementation 'io.sentry:sentry-android:8.25.0'
266268
testImplementation 'org.mockito:mockito-core:5.5.0'
267269
testImplementation 'org.robolectric:robolectric:4.11.1'
268270
}

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
android:resource="@xml/paths" />
6464
</provider>
6565

66+
<meta-data android:name="io.sentry.dsn" android:value="@string/sentry_dsn" />
67+
6668
<activity
6769
android:name=".MainActivity"
6870
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden|locale"

app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@
125125
import javax.crypto.spec.SecretKeySpec;
126126
import javax.net.ssl.HttpsURLConnection;
127127

128+
import io.sentry.Sentry;
129+
128130
public class ClientAndroidInterface {
129131
private static final String LOG_TAG_RENEWAL = "RENEWAL";
130132
public static String filePath = null;
@@ -786,6 +788,7 @@ public int SaveFamily(String FamilyData, String InsureeData) {
786788
return FamilyId;
787789

788790
} catch (UserException e) {
791+
Sentry.captureException(e);
789792
e.printStackTrace();
790793
if (InsureeId != 0)
791794
sqlHandler.deleteData("tblInsuree", "InsureeId = ?", new String[]{String.valueOf(InsureeId)});
@@ -1045,6 +1048,7 @@ else if (ExceedThreshold == 0)
10451048
);
10461049
}
10471050
} catch (NumberFormatException | UserException e) {
1051+
Sentry.captureException(e);
10481052
e.printStackTrace();
10491053
throw new Exception(e.getMessage());
10501054
}
@@ -1699,8 +1703,10 @@ public int SavePolicy(String PolicyData, int FamilyId, int PolicyId) throws Exce
16991703
}
17001704
inProgress = false;
17011705
} catch (NumberFormatException e) {
1706+
Sentry.captureException(e);
17021707
e.printStackTrace();
17031708
} catch (UserException e) {
1709+
Sentry.captureException(e);
17041710
e.printStackTrace();
17051711
throw new Exception(e.getMessage());
17061712
}
@@ -1891,8 +1897,10 @@ public int SavePremiums(String PremiumData, int PolicyId, int PremiumId, int Fam
18911897
}
18921898
inProgress = false;
18931899
} catch (NumberFormatException e) {
1900+
Sentry.captureException(e);
18941901
e.printStackTrace();
18951902
} catch (UserException e) {
1903+
Sentry.captureException(e);
18961904
e.printStackTrace();
18971905
throw new Exception(e.getMessage());
18981906
}
@@ -3157,6 +3165,7 @@ protected int uploadEnrols(
31573165
List<Family.Policy> policies = familyPolicyFromJSONObject(family.getUuid(), policiesArray);
31583166
new UpdateFamily().execute(family, policies);
31593167
} catch (Exception e) {
3168+
Sentry.captureException(e);
31603169
e.printStackTrace();
31613170
enrolMessages.add(Objects.requireNonNullElse(e.getMessage(), "Something went wrong updating the family"));
31623171
return -400;
@@ -3582,9 +3591,9 @@ protected void onPostExecute(Boolean aBoolean) {
35823591
}
35833592
}
35843593

3585-
protected void DeleteUploadedData(final int FamilyId, ArrayList<String> FamilyIDs, int CallerId) {
3586-
if (FamilyIDs.size() == 0) {
3587-
FamilyIDs = new ArrayList<>() {{
3594+
private void DeleteUploadedData(final int FamilyId, ArrayList<String> FamilyIDs, int CallerId) {
3595+
if (FamilyIDs.isEmpty()) {
3596+
FamilyIDs = new ArrayList<String>() {{
35883597
add(String.valueOf(FamilyId));
35893598
}};
35903599
}
@@ -3675,6 +3684,7 @@ public void uploadFeedbacks() {
36753684
MoveFile(xmlFiles[i], 1);
36763685
MoveFile(jsonFiles[i], 1);
36773686
} catch (Exception e) {
3687+
Sentry.captureException(e);
36783688
e.printStackTrace();
36793689
if (
36803690
e instanceof HttpException &&
@@ -3913,6 +3923,7 @@ public void downloadMasterData() {
39133923
((MainActivity) activity).ShowEnrolmentOfficerDialog();
39143924
});
39153925
} catch (JSONException e) {
3926+
Sentry.captureException(e);
39163927
Log.e("MASTERDATA", "Error while parsing master data", e);
39173928
} catch (UserException e) {
39183929
Log.e("MASTERDATA", "Error while downloading master data", e);
@@ -3935,6 +3946,7 @@ public void importMasterData(String data) throws JSONException, UserException {
39353946
try {
39363947
processOldFormat(new JSONArray(data));
39373948
} catch (JSONException e) {
3949+
Sentry.captureException(e);
39383950
try {
39393951
processNewFormat(new JSONObject(data));
39403952
} catch (JSONException e2) {
@@ -3949,6 +3961,7 @@ public void startDownloadingMasterData() throws JSONException, UserException, Us
39493961
try {
39503962
importMasterData(new FetchMasterData().execute());
39513963
} catch (Exception e) {
3964+
Sentry.captureException(e);
39523965
if (e instanceof UserNotAuthenticatedException) {
39533966
throw (UserNotAuthenticatedException) e;
39543967
}
@@ -4066,6 +4079,7 @@ private void processOldFormat(@NonNull JSONArray masterData) throws UserExceptio
40664079
insertPhoneDefaults(PhoneDefaults);
40674080
insertGenders(Genders);
40684081
} catch (JSONException e) {
4082+
Sentry.captureException(e);
40694083
e.printStackTrace();
40704084
throw new UserException(activity.getResources().getString(R.string.DownloadMasterDataFailed), e);
40714085
}
@@ -4573,6 +4587,7 @@ public void SaveInsureePolicy(int InsureId, int FamilyId, Boolean Activate, int
45734587
ExpiryDate = PolicyObject2.getString("ExpiryDate");
45744588
EnrollDate = PolicyObject2.getString("EnrollDate");
45754589
} catch (JSONException e) {
4590+
Sentry.captureException(e);
45764591
e.printStackTrace();
45774592
}
45784593
values.put("InsureePolicyId", MaxInsureePolicyId);

app/src/main/java/org/openimis/imispolicies/MainActivity.java

Lines changed: 97 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.json.JSONArray;
7272
import org.json.JSONException;
7373
import org.json.JSONObject;
74+
import org.openimis.imispolicies.network.exception.HttpException;
7475
import org.openimis.imispolicies.network.exception.UserNotAuthenticatedException;
7576
import org.openimis.imispolicies.tools.LanguageManager;
7677
import org.openimis.imispolicies.tools.Log;
@@ -88,6 +89,8 @@
8889
import java.io.OutputStream;
8990
import java.lang.ref.WeakReference;
9091

92+
import io.sentry.Sentry;
93+
9194
public class MainActivity extends AppCompatActivity
9295
implements NavigationView.OnNavigationItemSelectedListener {
9396

@@ -161,6 +164,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
161164
if (f.exists() || f.createNewFile())
162165
new FileOutputStream(f).write(bytes);
163166
} catch (IOException e) {
167+
Sentry.captureException(e);
164168
e.printStackTrace();
165169
}
166170
ShowDialogTex2();
@@ -230,100 +234,100 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
230234
protected void onCreate(Bundle savedInstanceState) {
231235
global = (Global) getApplicationContext();
232236
super.onCreate(savedInstanceState);
233-
instance = this;
234-
setContentView(R.layout.activity_main);
235-
SQLHandler sqlHandler = new SQLHandler(this);
236-
sqlHandler.isPrivate = true;
237-
//Set the Image folder path
238-
global.setImageFolder(global.getSubdirectory("Images"));
239-
//Check if database exists
240-
File database = global.getDatabasePath(SQLHandler.DBNAME);
241-
if (!database.exists()) {
242-
sqlHandler.getReadableDatabase();
243-
if (copyDatabase(this)) {
244-
Toast.makeText(this, "Copy database success", Toast.LENGTH_SHORT).show();
245-
} else {
246-
Toast.makeText(this, "Copy database failed", Toast.LENGTH_SHORT).show();
247-
return;
248-
}
249-
} else
250-
sqlHandler.getReadableDatabase();
251-
252-
//Create image folder
253-
createImageFolder();
254-
255-
Toolbar toolbar = findViewById(R.id.toolbar);
256-
setSupportActionBar(toolbar);
257-
258-
FloatingActionButton fab = findViewById(R.id.fab);
259-
fab.setOnClickListener(view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
260-
.setAction("Action", null).show());
261-
262-
DrawerLayout drawer = findViewById(R.id.drawer_layout);
263-
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
264-
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
265-
//noinspection deprecation
266-
drawer.setDrawerListener(toggle);
267-
toggle.syncState();
268-
269-
navigationView = findViewById(R.id.nav_view);
237+
try {
238+
instance = this;
239+
setContentView(R.layout.activity_main);
240+
SQLHandler sqlHandler = new SQLHandler(this);
241+
sqlHandler.isPrivate = true;
242+
//Set the Image folder path
243+
global.setImageFolder(global.getSubdirectory("Images"));
244+
//Check if database exists
245+
File database = global.getDatabasePath(SQLHandler.DBNAME);
246+
if (!database.exists()) {
247+
sqlHandler.getReadableDatabase();
248+
if (copyDatabase(this)) {
249+
Toast.makeText(this, "Copy database success", Toast.LENGTH_SHORT).show();
250+
} else {
251+
Toast.makeText(this, "Copy database failed", Toast.LENGTH_SHORT).show();
252+
return;
253+
}
254+
} else
255+
sqlHandler.getReadableDatabase();
256+
257+
//Create image folder
258+
createImageFolder();
259+
260+
Toolbar toolbar = findViewById(R.id.toolbar);
261+
setSupportActionBar(toolbar);
262+
263+
FloatingActionButton fab = findViewById(R.id.fab);
264+
fab.setOnClickListener(view -> Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
265+
.setAction("Action", null).show());
266+
267+
DrawerLayout drawer = findViewById(R.id.drawer_layout);
268+
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
269+
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
270+
//noinspection deprecation
271+
drawer.setDrawerListener(toggle);
272+
toggle.syncState();
273+
274+
navigationView = findViewById(R.id.nav_view);
275+
276+
navigationView.setNavigationItemSelectedListener(this);
277+
wv = findViewById(R.id.webview);
278+
WebSettings settings = wv.getSettings();
279+
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
280+
settings.setJavaScriptEnabled(true);
281+
//noinspection deprecation
282+
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
283+
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
284+
settings.setDomStorageEnabled(true);
285+
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
286+
settings.setUseWideViewPort(true);
287+
settings.setSaveFormData(true);
288+
settings.setAllowFileAccess(true);
289+
//noinspection deprecation
290+
settings.setEnableSmoothTransition(true);
291+
settings.setLoadWithOverviewMode(true);
292+
wv.addJavascriptInterface(new ClientAndroidInterface(this), "Android");
293+
294+
//Register for context acquire_menu
295+
registerForContextMenu(wv);
270296

271-
navigationView.setNavigationItemSelectedListener(this);
272-
wv = findViewById(R.id.webview);
273-
WebSettings settings = wv.getSettings();
274-
wv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
275-
settings.setJavaScriptEnabled(true);
276-
//noinspection deprecation
277-
settings.setRenderPriority(WebSettings.RenderPriority.HIGH);
278-
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
279-
settings.setDomStorageEnabled(true);
280-
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
281-
settings.setUseWideViewPort(true);
282-
settings.setSaveFormData(true);
283-
settings.setAllowFileAccess(true);
284-
//noinspection deprecation
285-
settings.setEnableSmoothTransition(true);
286-
settings.setLoadWithOverviewMode(true);
287-
wv.addJavascriptInterface(new ClientAndroidInterface(this), "Android");
288-
289-
//Register for context acquire_menu
290-
registerForContextMenu(wv);
291-
292-
wv.loadUrl("file:///android_asset/pages/Home.html");
293-
wv.setWebViewClient(new MyWebViewClient(MainActivity.this));
294-
295-
wv.setWebChromeClient(new WebChromeClient() {
296-
@Override
297-
public void onReceivedTitle(WebView view, String title) {
298-
super.onReceivedTitle(view, title);
299-
//noinspection ConstantConditions
300-
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);
301-
getSupportActionBar().setSubtitle(title);
297+
wv.loadUrl("file:///android_asset/pages/Home.html");
298+
wv.setWebViewClient(new MyWebViewClient(MainActivity.this));
299+
300+
wv.setWebChromeClient(new WebChromeClient() {
301+
@Override
302+
public void onReceivedTitle(WebView view, String title) {
303+
super.onReceivedTitle(view, title);
304+
//noinspection ConstantConditions
305+
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);
306+
getSupportActionBar().setSubtitle(title);
307+
}
308+
});
309+
NavigationView navigationView = findViewById(R.id.nav_view);
310+
View headerview = navigationView.getHeaderView(0);
311+
Login = headerview.findViewById(R.id.tvLogin);
312+
OfficerName = headerview.findViewById(R.id.tvOfficerName);
313+
314+
Login.setOnClickListener(v -> {
315+
wv.loadUrl("file:///android_asset/pages/Login.html?s=3");
316+
drawer.closeDrawer(GravityCompat.START);
317+
SetLoggedIn();
318+
});
319+
ca = new ClientAndroidInterface(this);
320+
if (ca.isMasterDataAvailable() > 0) {
321+
loadLanguages();
302322
}
303-
});
304-
NavigationView navigationView = findViewById(R.id.nav_view);
305-
View headerview = navigationView.getHeaderView(0);
306-
Login = headerview.findViewById(R.id.tvLogin);
307-
OfficerName = headerview.findViewById(R.id.tvOfficerName);
308-
309-
Login.setOnClickListener(v -> {
310-
wv.loadUrl("file:///android_asset/pages/Login.html?s=3");
311-
drawer.closeDrawer(GravityCompat.START);
312-
SetLoggedIn();
313-
});
314-
ca = new ClientAndroidInterface(this);
315-
if (ca.isMasterDataAvailable() > 0) {
316-
loadLanguages();
317-
}
318-
319-
320-
navigationView.setCheckedItem(R.id.nav_home);
321-
322-
if (checkRequirements()) {
323-
onAllRequirementsMet();
323+
navigationView.setCheckedItem(R.id.nav_home);
324+
if (checkRequirements()) {
325+
onAllRequirementsMet();
326+
}
327+
setVisibilityOfPaymentMenu();
328+
} catch (Exception e) {
329+
Sentry.captureException(e);
324330
}
325-
326-
setVisibilityOfPaymentMenu();
327331
}
328332

329333
private void setVisibilityOfPaymentMenu() {
@@ -508,6 +512,7 @@ public void ShowEnrolmentOfficerDialog() {
508512
//ShowDialogTex();
509513
}
510514
} catch (JSONException e) {
515+
Sentry.captureException(e);
511516
e.printStackTrace();
512517
}
513518
})
@@ -567,6 +572,7 @@ public void ShowDialogTex2() {
567572
ConfirmDialogPage((f.getName()));
568573
}
569574
} catch (Exception e) {
575+
Sentry.captureException(e);
570576
e.getMessage();
571577
}
572578
})

0 commit comments

Comments
 (0)