Browse Source

Before applying cascading validation

master
Preyea Regmi 5 years ago
parent
commit
45e74e2e0e
  1. 11
      app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV3/model/IDTypeDTO.java
  2. 15
      app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV3/model/PrimaryInformationDTO.java
  3. 145
      app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV3/presenter/KYCV3ViewModel.java
  4. 25
      app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV3/view/personal/CustomerDetailFragment.java

11
app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV3/model/IDTypeDTO.java

@ -1,5 +1,6 @@
package com.gmeremit.online.gmeremittance_native.kycV3.model;
import com.gmeremit.online.gmeremittance_native.utils.https.API_URL;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@ -19,6 +20,15 @@ public class IDTypeDTO {
@Expose
private List<String> dependent;
public IDTypeDTO() {
}
public IDTypeDTO(String id, String text) {
this.id = id;
this.text = text;
this.dependent = null;
}
public String getId() {
return id;
}
@ -43,6 +53,7 @@ public class IDTypeDTO {
this.dependent = dependent;
}
@Override
public String toString() {
return text;

15
app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV3/model/PrimaryInformationDTO.java

@ -100,6 +100,8 @@ public class PrimaryInformationDTO {
}
public String getAnotherIDType() {
if (anotherIDType == null)
return "";
return anotherIDType;
}
@ -108,6 +110,8 @@ public class PrimaryInformationDTO {
}
public String getAnotherIDNumber() {
if (anotherIDNumber == null)
return "";
return anotherIDNumber;
}
@ -117,6 +121,8 @@ public class PrimaryInformationDTO {
}
public String getAnotherIDIssueDate() {
if(anotherIDIssueDate==null)
return "";
return anotherIDIssueDate;
}
@ -125,6 +131,8 @@ public class PrimaryInformationDTO {
}
public String getAnotherIDExpiryDate() {
if(anotherIDExpiryDate==null)
return "";
return anotherIDExpiryDate;
}
@ -178,20 +186,19 @@ public class PrimaryInformationDTO {
}
public boolean isAnotherIDTypeValid() {
return anotherIDType != null && anotherIDType.length() > 0;
}
public boolean isPassportNoValid() {
return passportNumber!=null && passportNumber.length()>0;
return passportNumber != null && passportNumber.length() > 0;
}
public PrimaryInformationDTO createClone() {
return new PrimaryInformationDTO(this.bankId,this.bankAccount,this.passportNumber,this.passportIssueDate,this.passportExpiryDate,this.anotherIDType,this.anotherIDNumber,this.anotherIDIssueDate,this.anotherIDExpiryDate,this.branchId,this.refferalCode);
return new PrimaryInformationDTO(this.bankId, this.bankAccount, this.passportNumber, this.passportIssueDate, this.passportExpiryDate, this.anotherIDType, this.anotherIDNumber, this.anotherIDIssueDate, this.anotherIDExpiryDate, this.branchId, this.refferalCode);
}
public boolean isBranchValid() {
return branchId!=null&&branchId.length()>0;
return branchId != null && branchId.length() > 0;
}
}

145
app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV3/presenter/KYCV3ViewModel.java

@ -11,7 +11,6 @@ import com.gmeremit.online.gmeremittance_native.R;
import com.gmeremit.online.gmeremittance_native.addautodebitV2.view.AddPrimaryAccounAsAutoDebitActivity;
import com.gmeremit.online.gmeremittance_native.base.BaseViewModel;
import com.gmeremit.online.gmeremittance_native.customwidgets.CustomAlertDialog;
import com.gmeremit.online.gmeremittance_native.customwidgets.banklistingdialog.BankIconMapper;
import com.gmeremit.online.gmeremittance_native.kycV3.model.IDTextDTO;
import com.gmeremit.online.gmeremittance_native.kycV3.model.IDTypeDTO;
import com.gmeremit.online.gmeremittance_native.kycV3.model.KYCRelatedDataDTO;
@ -38,6 +37,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.BehaviorSubject;
import static android.app.Activity.RESULT_OK;
@ -54,11 +54,11 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
private MutableLiveData<Boolean> customerDetailForm1Button;
private MutableLiveData<Boolean> customerDetailForm2Button;
private MutableLiveData<Boolean> customerDetailForm3Button;
private MutableLiveData<Boolean> customerDetailAlternateIDFieldAccessLiveData;
private MutableLiveData<Boolean> customerDetailAlternateIDFieldEnableLiveData;
private MutableLiveData<Bitmap> passportImageLiveData;
private MutableLiveData<Bitmap> alternateIDImageLiveData;
private MutableLiveData<Boolean> alternateIDIssueDateRequireLiveData;
private MutableLiveData<Boolean> alternateIDExpiryDateRequireLiveData;
private MutableLiveData<Boolean> alternateIDIssueVisibilityDateRequireLiveData;
private MutableLiveData<Boolean> alternateIDExpiryDateVisibilityLiveData;
private CustomerDetailErrorLiveDataDTO customerDetailErrorLiveDataDTO;
@ -89,8 +89,8 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
private static final String ID_TYPE_NATIONAL_ID_CARD = "National ID";
private static final String ID_TYPE_DRIVING_LICENSE = "Driving License";
//Since we cannot propogate null in rxStream. So using a randomKey.
public static final String VALID_STRING_DATA = "validStringData!!@@##";
private BehaviorSubject<Boolean> alternateIdRelatedValidationSubject;
public KYCV3ViewModel(KYCV3PresenterInterface.KYCV3ViewContractInterface view, KYCV3GatewayInterface gatewayInterface) {
@ -101,11 +101,11 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
this.customerDetailForm1Button = new MutableLiveData<>();
this.customerDetailForm2Button = new MutableLiveData<>();
this.customerDetailForm3Button = new MutableLiveData<>();
this.customerDetailAlternateIDFieldAccessLiveData = new MutableLiveData<>();
this.customerDetailAlternateIDFieldEnableLiveData = new MutableLiveData<>();
this.passportImageLiveData = new MutableLiveData<>();
this.alternateIDImageLiveData = new MutableLiveData<>();
this.alternateIDIssueDateRequireLiveData = new MutableLiveData<>();
this.alternateIDExpiryDateRequireLiveData = new MutableLiveData<>();
this.alternateIDIssueVisibilityDateRequireLiveData = new MutableLiveData<>();
this.alternateIDExpiryDateVisibilityLiveData = new MutableLiveData<>();
this.customerDetailViewSubscriptions = new CompositeDisposable();
this.customerDetailErrorLiveDataDTO = new CustomerDetailErrorLiveDataDTO();
@ -119,6 +119,7 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
this.penntestReferenceSubmissionLiveData = new MutableLiveData<>();
this.penntestReferenceErrorMessageLiveData = new MutableLiveData<>();
alternateIdRelatedValidationSubject = BehaviorSubject.createDefault(true);
}
@ -145,6 +146,25 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
Observable.combineLatest(setUpForm1Validation(), setUpForm2Validation(), setUpForm3Validation(), (form1Result, form2Result, form3Result) -> form1Result && form2Result && form3Result)
.subscribeOn(AndroidSchedulers.mainThread())
.subscribeWith(new CustomerDetailFormViewBindingObserver()));
this.customerDetailViewSubscriptions.add(
setupAlternateIDDependenciesValidation()
.subscribeWith(new DisposableObserver<Boolean>() {
@Override
public void onNext(Boolean aBoolean) {
alternateIdRelatedValidationSubject.onNext(aBoolean);
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
}));
}
@Override
@ -198,6 +218,8 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
boolean result = isFullNameValid && isEmailValid && isAddressValid && isDobValid && isGenderValid && isCityValid;
Log.d(TAG, "Form 1 valid: " + result);
customerDetailForm1Button.setValue(result);
if (!result)
customerDetailForm2Button.setValue(false);
return result;
}
);
@ -214,24 +236,21 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
list.add(this.view.getCustomerDetailViewContract().getForm2ViewBindings().getPassportExpiryDateChangeEvent().map(val -> validator.validatePassportExpiryDate(val.toString())));
list.add(this.view.getCustomerDetailViewContract().getForm2ViewBindings().getGMEBranchChangeEvent().map(val -> validator.validateGmeBranch(val)));
list.add(this.view.getCustomerDetailViewContract().getForm2ViewBindings().getReferralCodeChangeEvent().map(val -> validator.validateReferralCode(val)));
list.add(alternateIdRelatedValidationSubject);
return this.setupAlternateIDDependenciesValidation().withLatestFrom(
Observable.combineLatest(
list,
args ->
{
boolean result = ((boolean) args[0]) && ((boolean) args[1]) && ((boolean) args[2])
&& ((boolean) args[3]) && ((boolean) args[4]) && ((boolean) args[5]) && ((boolean) args[6]);
customerDetailForm2Button.setValue(result);
log("Form 2 isValid : " + result);
return result;
}
), (alternateIdValidation, form2Validation) -> {
boolean result = form2Validation && alternateIdValidation;
log("Form 2 All isValid : " + result);
return Observable.combineLatest(
list,
args ->
{
boolean result = ((boolean) args[0]) && ((boolean) args[1]) && ((boolean) args[2])
&& ((boolean) args[3]) && ((boolean) args[4]) && ((boolean) args[5]) && ((boolean) args[6])
&& ((boolean) args[7]);
customerDetailForm2Button.setValue(result);
log("Form 2 isValid : " + result);
return result;
});
}
);
}
@ -246,7 +265,7 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
this.view.getCustomerDetailViewContract().getForm2ViewBindings().getAlternateIDIssuedDateChangeEvent().map(val -> validator.validateAlternateIDIssuedDate2(val.toString())),
this.view.getCustomerDetailViewContract().getForm2ViewBindings().getAlternateIDExpiryDateChangeEvent().map(val -> validator.validateAlternateIDExpiryDate2(val.toString())),
(isAlternateIdNoValid, isAlternateIdIssuedDateValid, isAlternatedIDExpiryDateValid) -> isAlternateIdNoValid && isAlternateIdIssuedDateValid && isAlternatedIDExpiryDateValid
).withLatestFrom(this.view.getCustomerDetailViewContract().getForm2ViewBindings().getAlternateIdTypeChangeEvent().map(val -> validator.validateAlternateIdType2(val)),
).withLatestFrom(this.view.getCustomerDetailViewContract().getForm2ViewBindings().getAlternateIdTypeChangeEvent().map(val -> validator.validateAlternateIdType(val)),
(isAlternatedTypeDependenciesValid, isAlternateIdTypeValid) -> {
log("AlternatedIDDependencies isValid : " + isAlternatedTypeDependenciesValid);
log("AlternateIDType isValid : " + isAlternateIdTypeValid);
@ -310,7 +329,14 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
@Override
public void clearAlternateIDFields() {
alternateIDIssueVisibilityDateRequireLiveData.setValue(false);
alternateIDExpiryDateVisibilityLiveData.setValue(false);
customerDetailAlternateIDFieldEnableLiveData.setValue(false);
customerDetailErrorLiveDataDTO.setValueToAnotherIdNoError(null);
customerDetailErrorLiveDataDTO.setValueToAnotherIDIssuedDateError(null);
customerDetailErrorLiveDataDTO.setValueToAnotherIDExpiryDateError(null);
alternateIdRelatedValidationSubject.onNext(true);
}
public void checkImageStatus(int requestCode, int resultCode, File data, float thumbnailHeight, float thumbnailWidth) {
@ -366,7 +392,7 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
@Override
public LiveData<Boolean> getForm2AlternateIdNumberFieldAccessLiveData() {
return customerDetailAlternateIDFieldAccessLiveData;
return customerDetailAlternateIDFieldEnableLiveData;
}
@Override
@ -381,12 +407,12 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
@Override
public LiveData<Boolean> getAlternateIdIssueDateRequireLiveData() {
return alternateIDIssueDateRequireLiveData;
return alternateIDIssueVisibilityDateRequireLiveData;
}
@Override
public LiveData<Boolean> getAlternateIdExpiryDateRequireLiveData() {
return alternateIDExpiryDateRequireLiveData;
return alternateIDExpiryDateVisibilityLiveData;
}
@Override
@ -433,7 +459,7 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
public void getKycRelatedData() {
compositeDisposable.add(
this.gateway.getKycRelatedData(gateway.getBasicAuth(view.getContext()), gateway.getUserID(), "kyc")
this.gateway.getKycRelatedData(gateway.getBasicAuth(view.getContext()), "sdf", "kyc")
.doOnSubscribe(sub -> view.showProgressBar(true, ""))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
@ -770,27 +796,27 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
}
if (kycRelatedDataDTO.getPrimaryInformation().isAnotherIDTypeValid()) {
alternateIDIssueDateRequireLiveData.setValue(false);
alternateIDExpiryDateRequireLiveData.setValue(false);
alternateIDIssueVisibilityDateRequireLiveData.setValue(false);
alternateIDExpiryDateVisibilityLiveData.setValue(false);
boolean hasIssuedDateRequiredField = false;
boolean hasExpiryDateRequiredField = false;
for (String dependent : val.getDependent()) {
if ("docIssueDate".equalsIgnoreCase(dependent)) {
alternateIDIssueDateRequireLiveData.setValue(true);
alternateIDIssueVisibilityDateRequireLiveData.setValue(true);
hasIssuedDateRequiredField = true;
} else if ("docExpiryDate".equalsIgnoreCase(dependent)) {
alternateIDExpiryDateRequireLiveData.setValue(true);
alternateIDExpiryDateVisibilityLiveData.setValue(true);
hasExpiryDateRequiredField = true;
}
}
if (!hasExpiryDateRequiredField)
anotherIdExpDateLiveData.setValue(VALID_STRING_DATA);
anotherIdExpDateLiveData.setValue("Asf");
else
anotherIdExpDateLiveData.setValue("");
if (!hasIssuedDateRequiredField)
anotherIdIssuedDateLiveData.setValue(VALID_STRING_DATA);
anotherIdIssuedDateLiveData.setValue("asf");
else
anotherIdIssuedDateLiveData.setValue("");
result = true;
@ -798,7 +824,7 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
customerDetailErrorLiveDataDTO.setValueToAnotherIdTypeError("Select different ID Type");
}
}
customerDetailAlternateIDFieldAccessLiveData.setValue(result);
customerDetailAlternateIDFieldEnableLiveData.setValue(result);
return result;
}
@ -822,13 +848,13 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
}
if (kycRelatedDataDTO.getPrimaryInformation().isAnotherIDTypeValid()) {
alternateIDIssueDateRequireLiveData.setValue(false);
alternateIDExpiryDateRequireLiveData.setValue(false);
alternateIDIssueVisibilityDateRequireLiveData.setValue(false);
alternateIDExpiryDateVisibilityLiveData.setValue(false);
for (String dependent : val.getDependent()) {
if ("docIssueDate".equalsIgnoreCase(dependent)) {
alternateIDIssueDateRequireLiveData.setValue(true);
alternateIDIssueVisibilityDateRequireLiveData.setValue(true);
} else if ("docExpiryDate".equalsIgnoreCase(dependent)) {
alternateIDExpiryDateRequireLiveData.setValue(true);
alternateIDExpiryDateVisibilityLiveData.setValue(true);
}
}
result = true;
@ -836,7 +862,7 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
customerDetailErrorLiveDataDTO.setValueToAnotherIdTypeError("Select different ID Type");
}
}
customerDetailAlternateIDFieldAccessLiveData.setValue(result);
customerDetailAlternateIDFieldEnableLiveData.setValue(result);
return result;
}
@ -897,12 +923,9 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
public boolean validateAlternateIdNo2(String alternateID) {
Log.d("AlternateIdValidation", "Alternate ID : " + alternateID);
kycRelatedDataDTO.getPrimaryInformation().setAnotherIDNumber(alternateID);
if(kycRelatedDataDTO.getPrimaryInformation().getAnotherIDType()==null||kycRelatedDataDTO.getPrimaryInformation().getAnotherIDType().length()==0)
{
customerDetailErrorLiveDataDTO.setValueToAnotherIdNoError(null);
return true;
}
if (kycRelatedDataDTO.getPrimaryInformation().isAnotherIDNoValid()) {
customerDetailErrorLiveDataDTO.setValueToAnotherIdNoError(null);
view.getCustomerDetailViewContract().enableAlternateIdFocusChangeAndImeOptionListener(true);
@ -921,19 +944,6 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
if (kycRelatedDataDTO.getPrimaryInformation() == null)
kycRelatedDataDTO.setPrimaryInformation(new PrimaryInformationDTO());
if(kycRelatedDataDTO.getPrimaryInformation().getAnotherIDType()==null||kycRelatedDataDTO.getPrimaryInformation().getAnotherIDType().length()==0)
{
customerDetailErrorLiveDataDTO.setValueToAnotherIDIssuedDateError(null);
return true;
}
if (VALID_STRING_DATA.equalsIgnoreCase(alternateIDIssuedDate)) {
kycRelatedDataDTO.getPrimaryInformation().setAnotherIDIssueDate("");
customerDetailErrorLiveDataDTO.setValueToAnotherIDIssuedDateError(null);
Log.d("AlternateIdValidation", "Issued Date : " + "Valid");
return true;
}
kycRelatedDataDTO.getPrimaryInformation().setAnotherIDIssueDate(alternateIDIssuedDate);
if (kycRelatedDataDTO.getPrimaryInformation().isAnotherIDIssuedDateValid()) {
customerDetailErrorLiveDataDTO.setValueToAnotherIDIssuedDateError(null);
@ -955,26 +965,13 @@ public class KYCV3ViewModel extends BaseViewModel implements KYCV3PresenterInter
if (kycRelatedDataDTO.getPrimaryInformation() == null)
kycRelatedDataDTO.setPrimaryInformation(new PrimaryInformationDTO());
if(kycRelatedDataDTO.getPrimaryInformation().getAnotherIDType()==null||kycRelatedDataDTO.getPrimaryInformation().getAnotherIDType().length()==0)
{
customerDetailErrorLiveDataDTO.setValueToAnotherIDExpiryDateError(null);
return true;
}
if (VALID_STRING_DATA.equalsIgnoreCase(alternateIDIExpiryDate)) {
kycRelatedDataDTO.getPrimaryInformation().setAnotherIDIssueDate("");
Log.d("AlternateIdValidation", "Expiry Date : " + "Valid");
return true;
}
kycRelatedDataDTO.getPrimaryInformation().setAnotherIDExpiryDate(alternateIDIExpiryDate);
if (kycRelatedDataDTO.getPrimaryInformation().isAnotherIDExpiryDateValid()) {
customerDetailErrorLiveDataDTO.setValueToAnotherIDExpiryDateError(null);
Log.d("AlternateIdValidation", "Expiry Date : " + "Valid");
return true;
} else {
customerDetailErrorLiveDataDTO.setValueToAnotherIDExpiryDateError(getStringfromStringId(R.string.empty_field_error_text));
Log.d("AlternateIdValidation", "Expiry Date : " + "InValid");
return false;
}
}

25
app/src/main/java/com/gmeremit/online/gmeremittance_native/kycV3/view/personal/CustomerDetailFragment.java

@ -272,7 +272,6 @@ public class CustomerDetailFragment extends BaseFragment implements KYCV3Present
kycv3ViewModel.onCustomerDetailFormReady(true);
}
private void subscribeToSubmitButtonEnable(KYCV3ViewModel kycv3ViewModel) {
@ -436,12 +435,12 @@ public class CustomerDetailFragment extends BaseFragment implements KYCV3Present
kycv3ViewModel.getPictureLabelForAnotherIDLiveData().observe(getViewLifecycleOwner(), label -> anotherIdPictureLabel.setText(label));
kycv3ViewModel.getAlternateIDExpiryDateLiveData().observe(getViewLifecycleOwner(),data->{
kycv3ViewModel.getAlternateIDExpiryDateLiveData().observe(getViewLifecycleOwner(), data -> {
ed_anotherExpiryDate.setText("");
form2ViewBindings.alternateIDNoExpiryDateSubject.onNext(data);
});
kycv3ViewModel.getAlternateIDIssuedDateLiveData().observe(getViewLifecycleOwner(),data->{
kycv3ViewModel.getAlternateIDIssuedDateLiveData().observe(getViewLifecycleOwner(), data -> {
ed_anotherIssueDate.setText("");
form2ViewBindings.alternateIDNoIssuedDateSubject.onNext(data);
});
@ -533,13 +532,19 @@ public class CustomerDetailFragment extends BaseFragment implements KYCV3Present
@OnClick(R.id.txt_another_id_clear)
public void onClearAnotherIdRelatedFields() {
// ViewModelProviders.of(getActivity()).get(KYCV3ViewModel.class).clearAlternateIDFields();
ed_idType.setText("");
form2ViewBindings.idTypeSubject.onNext(new IDTypeDTO());
ed_anotherIssueDate.setText("");
ed_anotherExpiryDate.setText("");
ed_idType.setText(null);
ed_anotherIssueDate.setText(null);
ed_anotherExpiryDate.setText(null);
form2ViewBindings.alternateIDNoIssuedDateSubject.onNext("");
form2ViewBindings.alternateIDNoIssuedDateSubject.onNext("");
ed_anotherId.setText("");
ViewModelProviders.of(getActivity()).get(KYCV3ViewModel.class).clearAlternateIDFields();
}
@ -1203,7 +1208,7 @@ public class CustomerDetailFragment extends BaseFragment implements KYCV3Present
}
public Observable<CharSequence> getAlternateIDNoChangeEvent() {
return RxTextView.textChanges(ed_anotherId).skipInitialValue();
return RxTextView.textChanges(ed_anotherId).skipInitialValue().filter(val -> val != null);
}

Loading…
Cancel
Save