Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fastlane/test_output
fastlane/readme.md

app/release/output.json
**/.DS_Store
.DS_Store

# Custom product flavours

Expand Down
20 changes: 20 additions & 0 deletions app/src/main/graphql/org.openimis.imispolicies/GetFamily.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ query GetFamily($headChfId: String) {
}
}
}
policies{
edges {
node {
id
uuid
product {
id
}
officer {
id
}
value
enrollDate
effectiveDate
startDate
expiryDate
status
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3173,7 +3173,8 @@ private Family familyFromJSONObject(
/* confirmationNumber = */ JsonUtils.getStringOrDefault(json, "ConfirmationNo"),
/* confirmationType = */ JsonUtils.getStringOrDefault(json, "ConfirmationType"),
/* isOffline = */ JsonUtils.getBooleanOrDefault(json, "isOffline", false),
/* members = */ members
/* members = */ members,
null
);
}

Expand Down Expand Up @@ -4722,6 +4723,7 @@ public int ModifyFamily(final String insuranceNumber) {
Family family = new FetchFamily().execute(insuranceNumber);
InsertFamilyDataFromOnline(family);
InsertInsureeDataFromOnline(family.getMembers());
InsertPolicyDataFromOnline(family.getPolicies());
return 1;
} catch (Exception e) {
Log.e("MODIFYFAMILY", "Error while downloading a family", e);
Expand Down Expand Up @@ -4793,6 +4795,21 @@ private void InsertInsureeDataFromOnline(@NonNull List<Family.Member> members) t
sqlHandler.insertData("tblInsuree", Columns, array, "");
}

private void InsertPolicyDataFromOnline(@NonNull List<Family.Policy> policies) throws JSONException {
JSONArray array = new JSONArray();
for (Family.Policy policy: policies) {
@Language("SQL")
String QueryCheck = "SELECT PolicyId FROM tblPolicy WHERE PolicyId = " + policy.getId();
if (sqlHandler.getResult(QueryCheck, null).length() == 0) {
array.put(toPolicyJSONObject(policy));
}
}
Log.e("policies", array.toString());
String[] Columns = {"PolicyId", "FamilyId", "EnrollDate", "StartDate", "EffectiveDate", "ExpiryDate", "PolicyStatus",
"PolicyValue", "ProdId", "OfficerId", "IsOffline"};
sqlHandler.insertData("tblPolicy", Columns, array, "");
}

@NonNull
private JSONObject toJSONObject(@NonNull Family.Member member) throws JSONException {
JSONObject jsonObject = new JSONObject();
Expand Down Expand Up @@ -4824,6 +4841,23 @@ private JSONObject toJSONObject(@NonNull Family.Member member) throws JSONExcept
return jsonObject;
}

@NonNull
private JSONObject toPolicyJSONObject (Family.Policy policy) throws JSONException {
JSONObject policyObject = new JSONObject();
policyObject.put("PolicyId",policy.getId());
policyObject.put("FamilyId",policy.getFamilyId());
policyObject.put("EnrollDate",policy.getEnrollDate());
policyObject.put("StartDate",policy.getStartDate());
policyObject.put("EffectiveDate", policy.getEffectiveDate() != null ? DateUtils.toDateString(Objects.requireNonNull(policy.getEffectiveDate())): null);
policyObject.put("ExpiryDate", policy.getExpiryDate());
policyObject.put("PolicyStatus",policy.getStatus());
policyObject.put("PolicyValue",policy.getValue());
policyObject.put("ProdId",policy.getProductId());
policyObject.put("OfficerId",policy.getOfficerId());
policyObject.put("IsOffline",false);
return policyObject;
}

//****************************Online Statistics ******************************//
@JavascriptInterface
@SuppressWarnings("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class Family implements Parcelable {
private final boolean isOffline;
@NonNull
private final List<Member> members;
@Nullable
private final List<Policy> policies;

@Nullable
private Member head = null;
Expand All @@ -53,7 +55,8 @@ public Family(
@Nullable String confirmationNumber,
@Nullable String confirmationType,
boolean isOffline,
@NonNull List<Member> members
@NonNull List<Member> members,
@Nullable List<Policy> policies
) {
this.headChfId = headChfId;
this.id = id;
Expand All @@ -68,6 +71,7 @@ public Family(
this.confirmationType = confirmationType;
this.isOffline = isOffline;
this.members = members;
this.policies = policies;
}

protected Family(Parcel in) {
Expand All @@ -89,6 +93,7 @@ protected Family(Parcel in) {
confirmationType = in.readString();
isOffline = in.readByte() != 0;
members = Objects.requireNonNull(in.createTypedArrayList(Member.CREATOR));
policies = in.createTypedArrayList(Policy.CREATOR);
}

@Override
Expand All @@ -106,6 +111,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(confirmationType);
dest.writeByte((byte) (isOffline ? 1 : 0));
dest.writeTypedList(members);
dest.writeTypedList(policies);
}

@Override
Expand Down Expand Up @@ -198,6 +204,9 @@ public List<Member> getMembers() {
return members;
}

@Nullable
public List<Policy> getPolicies (){ return policies; }

public static final Creator<Family> CREATOR = new Creator<>() {
@Override
public Family createFromParcel(Parcel in) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import okhttp3.Response;

public class AuthorizationInterceptor implements Interceptor {
private static final String REQUESTED_WITH = "webapp";
private static final String USER_AGENT = "mobile_app";

@NonNull
private final LoginRepository repository;
Expand All @@ -33,10 +33,9 @@ public Response intercept(@NonNull Chain chain) throws IOException {
}
Request.Builder builder = chain.request().newBuilder();
builder.addHeader("Authorization", "bearer " + token.trim());
//builder.addHeader("Content-Type", "application/json");
builder.addHeader("User-Agent", USER_AGENT);
if(!StringUtils.isEmpty(csrfToken)){
builder.addHeader("X-Csrftoken", csrfToken);
builder.addHeader("X-Requested-With", REQUESTED_WITH);
}
Response response = chain.proceed(builder.build());
if (response.code() == HttpURLConnection.HTTP_UNAUTHORIZED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public abstract class BaseGraphQLRequest {

private static final ApolloClient apolloClient = ApolloClient.builder()
.okHttpClient(OkHttpUtils.getDefaultOkHttpClient())
.useHttpGetMethodForQueries(true)
.serverUrl(URI)
.addCustomTypeAdapter(CustomType.DATE, new DateCustomTypeAdapter())
.addCustomTypeAdapter(CustomType.DATETIME, new DateTimeCustomTypeAdapter())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Objects;

public class FetchFamily {
Expand Down Expand Up @@ -52,7 +53,8 @@ public Family execute(@NonNull String headChfId) throws Exception {
/* confirmationNumber = */ node.confirmationNo(),
/* confirmationType = */ node.confirmationType() != null ? Objects.requireNonNull(node.confirmationType()).code() : null,
/* isOffline = */ node.isOffline() != null ? Objects.requireNonNull(node.isOffline()) : false,
/* insurees = */ Mapper.map(node.members().edges(), (edge) -> toMember(edge, node))
/* insurees = */ Mapper.map(node.members().edges(), (edge) -> toMember(edge, node)),
/* policies = */ Mapper.map(node.policies().edges(), (edge) -> toPolicy(edge, node))
);
}

Expand Down Expand Up @@ -89,6 +91,29 @@ private Family.Member toMember(@NonNull GetFamilyQuery.Edge1 edge, @NonNull GetF
);
}

@NonNull
private Family.Policy toPolicy(@NonNull GetFamilyQuery.Edge2 edge, @NonNull GetFamilyQuery.Node family){
GetFamilyQuery.Node2 policy = Objects.requireNonNull(edge.node());
return new Family.Policy(
/* id = */IdUtils.getIdFromGraphQLString(policy.id()),
/* uuid = */ policy.uuid(),
/* familyId = */ IdUtils.getIdFromGraphQLString(family.id()),
/* familyUuid = */ family.uuid(),
/* enrollDate = */ policy.enrollDate(),
/* startDate = */ policy.startDate(),
/* effectiveDate = */ policy.effectiveDate(),
/* expiryDate = */ Objects.requireNonNull(policy.expiryDate()),
/* status = */ String.valueOf(policy.status()),
/* value = */ policy.value(),
/* productId = */ IdUtils.getIdFromGraphQLString(policy.product().id()),
/* officerId = */ IdUtils.getIdFromGraphQLString(policy.officer().id()),
null,
true,
null,
new ArrayList<>()
);
}

@Nullable
private String downloadPhoto(@Nullable GetFamilyQuery.Photo photo) {
String photoPath = getPhotoPath(photo);
Expand Down