From 157d8bd99e172b162516216243269b6e8b179ed4 Mon Sep 17 00:00:00 2001 From: Eric Darchis Date: Wed, 20 Oct 2021 16:05:12 +0200 Subject: [PATCH 1/9] Allow customisation of Niger app Niger will have different apps depending on the district where they'll be deployed. The manual build was all manual or niger, not a mix. --- app/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index efe39ba5..f069d888 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -150,9 +150,9 @@ android { } niger { applicationId "org.openimis.imispolicies.niger" - buildConfigField "String", "API_BASE_URL", '"http://oiniger.bluesquare.org/rest/"' - buildConfigField "String", "APP_DIR", '"IMIS-NIGER"' - resValue "string", "app_name_policies", "Polices Niger" + buildConfigField "String", "API_BASE_URL", '"' + (System.getenv("API_BASE_URL") ?: 'http://192.168.0.100/') + '"' + buildConfigField "String", "APP_DIR", '"' + (System.getenv("CLI_APP_DIR") ?: 'IMIS-POL') + '"' + resValue "string", "app_name_policies", System.getenv("CLI_APP_NAME") ?: "Polices Niger" } cli { applicationIdSuffix System.getenv("APPLICATION_ID") ?: "org.openimis.imispolicies.cli" From 30f05d027c5dc5b397ee03e820bd557b08e375d7 Mon Sep 17 00:00:00 2001 From: Eric Darchis Date: Thu, 21 Oct 2021 13:52:31 +0200 Subject: [PATCH 2/9] Debug information --- .github/workflows/manual.yml | 4 ++++ app/build.gradle | 4 +++- app/src/main/java/org/openimis/imispolicies/ToRestApi.java | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml index 2b452b3b..cd4847a0 100644 --- a/.github/workflows/manual.yml +++ b/.github/workflows/manual.yml @@ -43,6 +43,10 @@ jobs: gradle --version echo url ${{ github.event.inputs.api_base_url }} echo app name ${{ github.event.inputs.app_name }} + echo app dir ${{ github.event.inputs.app_dir }} + echo CLI_JAVA_DIR "${{ github.event.inputs.cli_java_dir }}" + echo CLI_RES_DIR "${{ github.event.inputs.cli_res_dir }}" + echo APPLICATION_ID "${{ github.event.inputs.application_id }}" - name: build run: | diff --git a/app/build.gradle b/app/build.gradle index f069d888..3c292333 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,7 +6,7 @@ apply from: "$project.rootDir/script-git-version.gradle" apply plugin: 'com.android.application' // Load keystore -def keystorePropertiesFile = file("keystore.properties"); +def keystorePropertiesFile = file("keystore.properties") def keystoreProperties = new Properties() if ( keystorePropertiesFile.exists() ) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) @@ -149,6 +149,8 @@ android { resValue "string", "app_name_policies", "Policies CHF SIT" } niger { + print("Building niger flavour" + "API_BASE_URL" + '"' + (System.getenv("API_BASE_URL") ?: 'http://192.168.0.100/') + '"') + print("App name: " + System.getenv("CLI_APP_NAME") ?: "Polices Niger") applicationId "org.openimis.imispolicies.niger" buildConfigField "String", "API_BASE_URL", '"' + (System.getenv("API_BASE_URL") ?: 'http://192.168.0.100/') + '"' buildConfigField "String", "APP_DIR", '"' + (System.getenv("CLI_APP_DIR") ?: 'IMIS-POL') + '"' diff --git a/app/src/main/java/org/openimis/imispolicies/ToRestApi.java b/app/src/main/java/org/openimis/imispolicies/ToRestApi.java index 16c52cdc..2de6e17a 100644 --- a/app/src/main/java/org/openimis/imispolicies/ToRestApi.java +++ b/app/src/main/java/org/openimis/imispolicies/ToRestApi.java @@ -95,6 +95,9 @@ public HttpResponse postToRestApi(JSONObject object, String functionName, boolea int responseCode = response.getStatusLine().getStatusCode(); Log.i("HTTP_POST", uri + functionName + " - " + responseCode); + if (object != null && (responseCode == 400 || responseCode >= 500)) { + Log.e("HTTP_POST", object.toString()); + } return response; } catch (IOException e) { e.printStackTrace(); From 9b7340eb0b855400b1d354888cb32dc149d506db Mon Sep 17 00:00:00 2001 From: Eric Darchis Date: Thu, 21 Oct 2021 19:02:43 +0200 Subject: [PATCH 3/9] Example script to run manual task from cli --- run_cli.sh | 1 + 1 file changed, 1 insertion(+) create mode 100755 run_cli.sh diff --git a/run_cli.sh b/run_cli.sh new file mode 100755 index 00000000..c162139e --- /dev/null +++ b/run_cli.sh @@ -0,0 +1 @@ +echo '{"api_base_url":"http://192.168.0.100/rest/", "app_name":"IMIS Polices Gaya", "app_dir":"IMIS-POL-GAYA", "application_id":"org.openimis.imispolicies.niger", "cli_java_dir": "src/niger/java", "cli_res_dir": "src/niger/res"}' | gh workflow run manual.yml --ref develop --json From 8388dde4ad646191e9435faec5b346fbcf6c20fc Mon Sep 17 00:00:00 2001 From: Eric Darchis Date: Thu, 4 Nov 2021 17:58:16 +0100 Subject: [PATCH 4/9] Log HTTP Post error payloads --- app/src/main/java/org/openimis/imispolicies/ToRestApi.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/openimis/imispolicies/ToRestApi.java b/app/src/main/java/org/openimis/imispolicies/ToRestApi.java index 2de6e17a..22866d71 100644 --- a/app/src/main/java/org/openimis/imispolicies/ToRestApi.java +++ b/app/src/main/java/org/openimis/imispolicies/ToRestApi.java @@ -95,8 +95,13 @@ public HttpResponse postToRestApi(JSONObject object, String functionName, boolea int responseCode = response.getStatusLine().getStatusCode(); Log.i("HTTP_POST", uri + functionName + " - " + responseCode); - if (object != null && (responseCode == 400 || responseCode >= 500)) { + if (object != null && responseCode >= 400) { Log.e("HTTP_POST", object.toString()); + HttpEntity entity = response.getEntity(); + if (entity != null) { + String errorPayload = EntityUtils.toString(entity); + Log.e("HTTP_POST", "error payload" + errorPayload); + } } return response; } catch (IOException e) { From 9c8b2842ba3baeeba2ae7554d0730fa427253674 Mon Sep 17 00:00:00 2001 From: Eric Darchis Date: Fri, 5 Nov 2021 10:26:09 +0100 Subject: [PATCH 5/9] Improve error logging --- app/src/main/java/org/openimis/imispolicies/ToRestApi.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/org/openimis/imispolicies/ToRestApi.java b/app/src/main/java/org/openimis/imispolicies/ToRestApi.java index 22866d71..7f505c3e 100644 --- a/app/src/main/java/org/openimis/imispolicies/ToRestApi.java +++ b/app/src/main/java/org/openimis/imispolicies/ToRestApi.java @@ -65,6 +65,13 @@ public HttpResponse getFromRestApi(String functionName, boolean addToken) { } int responseCode = response.getStatusLine().getStatusCode(); Log.i("HTTP_GET", uri + functionName + " - " + responseCode); + if (responseCode >= 400) { + HttpEntity entity = response.getEntity(); + if (entity != null) { + String errorPayload = EntityUtils.toString(entity); + Log.e("HTTP_POST", "error payload" + errorPayload); + } + } return response; } catch (IOException e) { e.printStackTrace(); From 589ac8481127ef8997b42a4d8a037b33538ec949 Mon Sep 17 00:00:00 2001 From: Eric Darchis Date: Fri, 5 Nov 2021 11:11:34 +0100 Subject: [PATCH 6/9] Silly copy/paste in app title for manual build --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 3c292333..c9f93930 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -160,7 +160,7 @@ android { applicationIdSuffix System.getenv("APPLICATION_ID") ?: "org.openimis.imispolicies.cli" buildConfigField "String", "API_BASE_URL", '"' + (System.getenv("API_BASE_URL") ?: 'http://10.0.2.2:35787/') + '"' buildConfigField "String", "APP_DIR", '"' + (System.getenv("CLI_APP_DIR") ?: 'IMIS-CLI') + '"' - resValue "string", "app_name_claims", System.getenv("CLI_APP_NAME") ?: "Policies CLI" + resValue "string", "app_name_policies", System.getenv("CLI_APP_NAME") ?: "Policies CLI" dimension 'std' } mauritaniaTrain { From 4ad2175b3975d149ddf564698d81d187482be987 Mon Sep 17 00:00:00 2001 From: Eric Darchis Date: Tue, 9 Nov 2021 00:04:15 +0100 Subject: [PATCH 7/9] Try to cache android debug key --- .github/workflows/manual.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml index cd4847a0..f0ac8c69 100644 --- a/.github/workflows/manual.yml +++ b/.github/workflows/manual.yml @@ -38,6 +38,14 @@ jobs: with: java-version: 1.8 + - uses: actions/cache@v2 + with: + path: | + ~/.android + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-${{ github.event.inputs.application_id }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }} + - name: Environment info run: | gradle --version From 79dc723d3d5a47a54c247d6460aa83e6599dde72 Mon Sep 17 00:00:00 2001 From: Eric Darchis Date: Tue, 9 Nov 2021 00:11:34 +0100 Subject: [PATCH 8/9] Fix error reporting log The error logging was consuming the response body and crashed the app in some conditions, like a failed login. --- .../imispolicies/ClientAndroidInterface.java | 4 ++++ .../org/openimis/imispolicies/ToRestApi.java | 20 ++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java b/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java index a08e11a6..b23cf98d 100644 --- a/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java +++ b/app/src/main/java/org/openimis/imispolicies/ClientAndroidInterface.java @@ -4227,6 +4227,10 @@ public boolean LoginToken(final String Username, final String Password) { if (respEntity != null) { try { content = EntityUtils.toString(respEntity); + if (content != null && content.length() > 0 + && response.getStatusLine().getStatusCode() >= 400) { + Log.e("HTTP", "Error response: " + content); + } } catch (IOException e) { e.printStackTrace(); } diff --git a/app/src/main/java/org/openimis/imispolicies/ToRestApi.java b/app/src/main/java/org/openimis/imispolicies/ToRestApi.java index 7f505c3e..c40511a1 100644 --- a/app/src/main/java/org/openimis/imispolicies/ToRestApi.java +++ b/app/src/main/java/org/openimis/imispolicies/ToRestApi.java @@ -65,13 +65,6 @@ public HttpResponse getFromRestApi(String functionName, boolean addToken) { } int responseCode = response.getStatusLine().getStatusCode(); Log.i("HTTP_GET", uri + functionName + " - " + responseCode); - if (responseCode >= 400) { - HttpEntity entity = response.getEntity(); - if (entity != null) { - String errorPayload = EntityUtils.toString(entity); - Log.e("HTTP_POST", "error payload" + errorPayload); - } - } return response; } catch (IOException e) { e.printStackTrace(); @@ -103,12 +96,11 @@ public HttpResponse postToRestApi(JSONObject object, String functionName, boolea int responseCode = response.getStatusLine().getStatusCode(); Log.i("HTTP_POST", uri + functionName + " - " + responseCode); if (object != null && responseCode >= 400) { - Log.e("HTTP_POST", object.toString()); - HttpEntity entity = response.getEntity(); - if (entity != null) { - String errorPayload = EntityUtils.toString(entity); - Log.e("HTTP_POST", "error payload" + errorPayload); + String body = object.toString(); + if (body.length() > 1000) { + body = body.substring(0,1000); } + Log.e("HTTP_POST", "Body: " + body); } return response; } catch (IOException e) { @@ -172,6 +164,10 @@ public String getContent(HttpResponse response) { if (respEntity != null) { try { content = EntityUtils.toString(respEntity); + if (content != null && content.length() > 0 + && response.getStatusLine().getStatusCode() >= 400) { + Log.e("HTTP", "Error response: " + content); + } } catch (IOException e) { e.printStackTrace(); } From 24c1ee211712d501e333bd1536f928b4ce9cf8d6 Mon Sep 17 00:00:00 2001 From: Eric Darchis Date: Tue, 9 Nov 2021 00:31:44 +0100 Subject: [PATCH 9/9] Split the android cache from the gradle one --- .github/workflows/manual.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml index f0ac8c69..e355c3fa 100644 --- a/.github/workflows/manual.yml +++ b/.github/workflows/manual.yml @@ -41,11 +41,16 @@ jobs: - uses: actions/cache@v2 with: path: | - ~/.android ~/.gradle/caches ~/.gradle/wrapper key: ${{ runner.os }}-${{ github.event.inputs.application_id }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }} + - uses: actions/cache@v2 + with: + path: | + ~/.android + key: ${{ runner.os }}-${{ github.event.inputs.application_id }} + - name: Environment info run: | gradle --version