Skip to content

Commit

Permalink
Finish feature/OTC-596
Browse files Browse the repository at this point in the history
OTC-596: Fixed checking photos after validation
  • Loading branch information
dragos-dobre authored Jun 1, 2022
2 parents e9d0844 + 444afe5 commit fa6eb4b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 58 deletions.
21 changes: 14 additions & 7 deletions app/src/debug/java/org/openimis/imispolicies/tools/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.openimis.imispolicies.AppInformation;
import org.openimis.imispolicies.BuildConfig;
import org.openimis.imispolicies.Global;
import org.openimis.imispolicies.util.FileUtils;
import org.openimis.imispolicies.util.ZipUtils;

import java.io.File;
Expand Down Expand Up @@ -91,9 +92,11 @@ private static void log(String tag, String msg, int level) {
}

public static void zipLogFiles(Context context) {
File cacheDir = Global.getContext().getExternalCacheDir();
File[] logFiles = cacheDir.listFiles((dir, filename) -> filename.startsWith(logFilePrefix));
File targetFile = new File(cacheDir, logExportFileName);
File cacheDir = Global.getContext().getCacheDir();
File logsDir = new File(cacheDir, "logs");
FileUtils.createDirectoryWithSubdirectories(logsDir);
File[] logFiles = logsDir.listFiles((dir, filename) -> filename.startsWith(logFilePrefix));
File targetFile = new File(logsDir, logExportFileName);

if (logFiles != null) {
ArrayList<File> filesToZip = new ArrayList<>(Arrays.asList(logFiles));
Expand All @@ -108,8 +111,10 @@ public static void zipLogFiles(Context context) {
}

public static void deleteLogFiles() {
File cacheDir = Global.getContext().getExternalCacheDir();
File[] logFiles = cacheDir.listFiles((dir, filename) -> filename.startsWith(logFilePrefix));
File cacheDir = Global.getContext().getCacheDir();
File logsDir = new File(cacheDir, "logs");
FileUtils.createDirectoryWithSubdirectories(logsDir);
File[] logFiles = logsDir.listFiles((dir, filename) -> filename.startsWith(logFilePrefix));
if (logFiles != null) {
for (File f : logFiles) {
f.delete();
Expand All @@ -131,10 +136,12 @@ private synchronized static void storeLog(String tag, String msg, int level) {

private static void initializeLogFile(Date date) {
if (logFile == null || !logFile.exists()) {
File cacheDir = Global.getContext().getExternalCacheDir();
File cacheDir = Global.getContext().getCacheDir();
File logsDir = new File(cacheDir, "logs");
FileUtils.createDirectoryWithSubdirectories(logsDir);

String filename = String.format("%s%s.txt",logFilePrefix, AppInformation.DateTimeInfo.getDefaultFileDatetimeFormatter().format(date));
logFile = new File(cacheDir, filename);
logFile = new File(logsDir, filename);

try {
if (!logFile.createNewFile())
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@
tools:node="merge"
tools:overrideLibrary="com.google.zxing.client" />


</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2846,16 +2846,7 @@ public void uploadEnrolment() throws Exception {
new Thread(() -> {
try {
enrol_result = Enrol(0, 0, 0, 0, 1);
} catch (UserException e) {
finalPd.dismiss();
e.printStackTrace();
} catch (JSONException e) {
finalPd.dismiss();
e.printStackTrace();
} catch (IOException e) {
finalPd.dismiss();
e.printStackTrace();
} catch (NumberFormatException e) {
} catch (UserException | JSONException | IOException | NumberFormatException e) {
finalPd.dismiss();
e.printStackTrace();
}
Expand Down Expand Up @@ -2910,11 +2901,11 @@ public void CreateEnrolmentXML() {
if (enrol_result != 999) {
//if error is encountered
if (enrolMessages.size() > 0 && enrolMessages != null) {
CharSequence[] charSequence = enrolMessages.toArray(new CharSequence[(enrolMessages.size())]);
CharSequence[] charSequences = enrolMessages.toArray(new CharSequence[(enrolMessages.size())]);
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle(mContext.getResources().getString(R.string.UploadFailureReport));
builder.setCancelable(false);
builder.setItems(charSequence, null);
builder.setItems(charSequences, null);
builder.setPositiveButton(mContext.getResources().getString(R.string.Ok), (dialogInterface, i) -> dialogInterface.dismiss());
AlertDialog dialog = builder.create();
dialog.show();
Expand Down Expand Up @@ -3387,6 +3378,8 @@ private int Enrol(int oFamilyId, int oInsureeId, int oPolicyId, int oPremiumId,
String InsureePolicy = objEnrol.toString();

if (CallerId != 2) {
InsureeImages[] InsureeImages = FamilyPictures(insureesArray, CallerId);

if (mylist.size() == 0) {
JSONObject resultObj = new JSONObject();
JSONArray familyArr = new JSONArray();
Expand All @@ -3396,8 +3389,6 @@ private int Enrol(int oFamilyId, int oInsureeId, int oPolicyId, int oPremiumId,
// Insuree + picture
JSONArray tempInsureesArray = new JSONArray();

InsureeImages[] InsureeImages = FamilyPictures(insureesArray, CallerId);

for (int j = 0; j < insureesArray.length(); j++) {
tempInsureesArray = insureesArray;
JSONObject imgObj = new JSONObject();
Expand Down Expand Up @@ -3432,33 +3423,41 @@ private int Enrol(int oFamilyId, int oInsureeId, int oPolicyId, int oPremiumId,

ToRestApi rest = new ToRestApi();
HttpResponse response = rest.postToRestApiToken(resultObj, "family");

HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity);

boolean parsingErrorOccured = false;
try {
JSONObject responseObject = new JSONObject(responseString);
if (responseObject.has("error_occured") && responseObject.getBoolean("error_occured")) {
String responseString = rest.getContent(response);
if (response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK
|| response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_CREATED) {
boolean parsingErrorOccured = false;
try {
JSONObject responseObject = new JSONObject(responseString);
if (responseObject.has("error_occured") && responseObject.getBoolean("error_occured")) {
EnrolResult = -400;
enrolMessages.add(responseObject.getString("error_message"));
} else if (responseObject.has("response")) {
EnrolResult = responseObject.getInt("response");
} else {
throw new JSONException("Response does not have required information");
}
} catch (JSONException e) {
EnrolResult = -400;
enrolMessages.add(responseObject.getString("error_message"));
} else if (responseObject.has("response")) {
EnrolResult = responseObject.getInt("response");
} else {
throw new JSONException("Response does not have required information");
parsingErrorOccured = true;
}

if (parsingErrorOccured) {
try {
EnrolResult = Integer.parseInt(responseString);
} catch (NumberFormatException e) {
Log.e("ENROLL", "Sync response is not a valid json or int");
}
}
} catch (JSONException e) {
} else {
enrolMessages.add(mContext.getResources().getString(R.string.HttpResponse, response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()));
EnrolResult = -400;
parsingErrorOccured = true;
}

if (parsingErrorOccured) {
try {
EnrolResult = Integer.parseInt(responseString);
} catch (NumberFormatException e) {
Log.e("ENROLL", "Sync response is not a valid json or int");
}
if (EnrolResult != 0) {
Log.d("ENROL", "API RESPONSE: " + mContext.getResources().getString(R.string.HttpResponse, response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()) + "\n" + responseString);
}

} else {
ShowErrorMessages();
break;
Expand Down Expand Up @@ -3512,7 +3511,7 @@ private int Enrol(int oFamilyId, int oInsureeId, int oPolicyId, int oPremiumId,


} else {
String ErrMsg = null;
String ErrMsg;
switch (EnrolResult) {
case -1:
ErrMsg = "[" + CHFNumber + "] " + mContext.getString(R.string.MissingHOF);
Expand Down Expand Up @@ -4095,8 +4094,8 @@ public void uploadFeedbacks() {
}

File feedbackDir = new File(global.getSubdirectory("Feedback"));
File[] xmlFiles = feedbackDir.listFiles((file)->file.getName().endsWith(".xml"));
File[] jsonFiles = feedbackDir.listFiles((file)->file.getName().endsWith(".json"));
File[] xmlFiles = feedbackDir.listFiles((file) -> file.getName().endsWith(".xml"));
File[] jsonFiles = feedbackDir.listFiles((file) -> file.getName().endsWith(".json"));

if (xmlFiles == null || jsonFiles == null) {
ShowDialog(mContext.getResources().getString(R.string.NoFiles));
Expand Down Expand Up @@ -4191,8 +4190,8 @@ public void uploadRenewals() {
}

File renewalDir = new File(global.getSubdirectory("Renewal"));
File[] xmlFiles = renewalDir.listFiles((file)->file.getName().endsWith(".xml"));
File[] jsonFiles = renewalDir.listFiles((file)->file.getName().endsWith(".json"));
File[] xmlFiles = renewalDir.listFiles((file) -> file.getName().endsWith(".xml"));
File[] jsonFiles = renewalDir.listFiles((file) -> file.getName().endsWith(".json"));

if (xmlFiles == null || jsonFiles == null) {
ShowDialog(mContext.getResources().getString(R.string.NoFiles));
Expand Down Expand Up @@ -6097,7 +6096,7 @@ public void exportLogs() {
AndroidUtils.showConfirmDialog(
mContext,
R.string.ConfirmExportLogs,
(d, i) -> new Thread(()-> Log.zipLogFiles(mContext)).start()
(d, i) -> new Thread(() -> Log.zipLogFiles(mContext)).start()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,6 @@ public static String readFileAsUTF8String(@NonNull File file) {
return null;
}

public static File createOrCheckDirectory(File directory) {
if (directory.exists() || directory.mkdirs()) {
return directory;
} else {
return null;
}
}

public static int getFileCount(File directory) {
if (!directory.exists() || !directory.isDirectory()) {
Log.e(LOG_TAG, "Not a directory: " + directory.getAbsolutePath());
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,5 @@
<string name="ConfirmClearLogs">Do you want to clear logs?</string>
<string name="WithoutPolicy">without a policy</string>
<string name="WithoutPremium">without a premium</string>
<string name="HttpResponse">HTTP response: %1$d — %2$s</string>
</resources>

0 comments on commit fa6eb4b

Please sign in to comment.