PageRenderTime 28ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/BMovil_v940/app/src/main/java/suitebancomer/aplicaciones/bmovil/classes/gui/delegates/ConfirmacionRegistroDelegate.java

https://gitlab.com/edddea/api_contratacion_arq
Java | 313 lines | 263 code | 42 blank | 8 comment | 44 complexity | eb75efd7fc92742ffc03bede5370288c MD5 | raw file
  1. package suitebancomer.aplicaciones.bmovil.classes.gui.delegates;
  2. import java.util.ArrayList;
  3. import bancomer.api.common.commons.Constants;
  4. import bancomer.api.common.commons.Constants.TipoInstrumento;
  5. import bancomer.api.common.commons.Constants.TipoOtpAutenticacion;
  6. import suitebancomer.aplicaciones.bmovil.classes.common.Session;
  7. import suitebancomer.aplicaciones.bmovil.classes.gui.controllers.BmovilViewsController;
  8. import suitebancomer.aplicaciones.bmovil.classes.gui.controllers.ConfirmacionRegistroViewController;
  9. import suitebancomer.aplicaciones.bmovil.classes.io.ServerResponse;
  10. import suitebancomer.classes.gui.controllers.BaseViewController;
  11. import com.bancomer.mbanking.BmovilApp;
  12. import com.bancomer.mbanking.R;
  13. import com.bancomer.mbanking.SuiteApp;
  14. public class ConfirmacionRegistroDelegate extends DelegateBaseAutenticacion {
  15. private ConfirmacionRegistroViewController viewController;
  16. public final static long CONFIRMACION_REGISTRO_DELEGATE_DELEGATE_ID = 0x9ef4f4c61ca109afL;
  17. private DelegateBaseOperacion opDelegate;
  18. private boolean debePedirContrasena;
  19. private boolean debePedirNip;
  20. private TipoOtpAutenticacion tokenAMostrar;
  21. private boolean debePedirCVV;
  22. private TipoInstrumento tipoInstrumentoSeguridad;
  23. public void setViewController(ConfirmacionRegistroViewController viewController) {
  24. this.viewController = viewController;
  25. }
  26. public ConfirmacionRegistroDelegate(DelegateBaseOperacion delegateOp) {
  27. this.opDelegate = delegateOp;
  28. debePedirContrasena = opDelegate.mostrarContrasenia();
  29. debePedirNip = opDelegate.mostrarNIP();
  30. debePedirCVV = opDelegate.mostrarCVV();
  31. tokenAMostrar = opDelegate.tokenAMostrar();
  32. String instrumento = Session.getInstance(SuiteApp.appContext).getSecurityInstrument();
  33. if (instrumento.equals(Constants.IS_TYPE_DP270)) {
  34. tipoInstrumentoSeguridad = TipoInstrumento.DP270;
  35. } else if (instrumento.equals(Constants.IS_TYPE_OCRA)) {
  36. tipoInstrumentoSeguridad = TipoInstrumento.OCRA;
  37. } else if (instrumento.equals(Constants.TYPE_SOFTOKEN.S1.value)) {
  38. tipoInstrumentoSeguridad = TipoInstrumento.SoftToken;
  39. } else {
  40. tipoInstrumentoSeguridad = TipoInstrumento.sinInstrumento;
  41. }
  42. }
  43. public void consultaDatosLista() {
  44. viewController.setListaDatos(opDelegate.getDatosTablaConfirmacion());
  45. }
  46. public DelegateBaseOperacion consultaOperationsDelegate() {
  47. return opDelegate;
  48. }
  49. public boolean consultaDebePedirContrasena() {
  50. return debePedirContrasena;
  51. }
  52. public boolean consultaDebePedirNIP() {
  53. return debePedirNip;
  54. }
  55. public boolean consultaDebePedirCVV() {
  56. return debePedirCVV;
  57. }
  58. public Constants.TipoInstrumento consultaTipoInstrumentoSeguridad() {
  59. return tipoInstrumentoSeguridad;
  60. }
  61. public Constants.TipoOtpAutenticacion consultaInstrumentoSeguridad() {
  62. return tokenAMostrar;
  63. }
  64. public boolean validaDatos(){
  65. boolean esOk = true;
  66. StringBuilder msg = new StringBuilder("");
  67. if(debePedirContrasena){
  68. String contrasena = viewController.pideContrasena();
  69. if(contrasena.length() == 0){
  70. esOk = false;
  71. msg.append(viewController.getString(R.string.confirmation_valorVacio));
  72. msg.append(" ");
  73. msg.append(viewController.getString(R.string.confirmation_componenteContrasena));
  74. msg.append(".");
  75. }else if(contrasena.length() != Constants.PASSWORD_LENGTH){
  76. esOk = false;
  77. msg.append(viewController.getString(R.string.confirmation_valorIncompleto1));
  78. msg.append(" ");
  79. msg.append(Constants.PASSWORD_LENGTH);
  80. msg.append(" ");
  81. msg.append(viewController.getString(R.string.confirmation_valorIncompleto2));
  82. msg.append(" ");
  83. msg.append(viewController.getString(R.string.confirmation_componenteContrasena));
  84. msg.append(".");
  85. }
  86. }else if(debePedirNip){
  87. String nip = viewController.pideNIP();
  88. if(nip.length() == 0){
  89. esOk = false;
  90. msg.append(viewController.getString(R.string.confirmation_valorVacio));
  91. msg.append(" ");
  92. msg.append(viewController.getString(R.string.confirmation_componenteNip));
  93. msg.append(".");
  94. }else if(nip.length() != Constants.NIP_LENGTH){
  95. esOk = false;
  96. msg.append(viewController.getString(R.string.confirmation_valorIncompleto1));
  97. msg.append(" ");
  98. msg.append(Constants.NIP_LENGTH);
  99. msg.append(" ");
  100. msg.append(viewController.getString(R.string.confirmation_valorIncompleto2));
  101. msg.append(" ");
  102. msg.append(viewController.getString(R.string.confirmation_componenteNip));
  103. msg.append(".");
  104. }
  105. }else if(tokenAMostrar != Constants.TipoOtpAutenticacion.ninguno){
  106. String asm = viewController.pideASM();
  107. if (asm.equals("")) {
  108. esOk = false;
  109. String mensaje = viewController.getString(R.string.confirmation_valorVacio);
  110. mensaje += " ";
  111. switch (tipoInstrumentoSeguridad) {
  112. case OCRA:
  113. mensaje += getEtiquetaCampoOCRA();
  114. break;
  115. case DP270:
  116. mensaje += getEtiquetaCampoDP270();
  117. break;
  118. case SoftToken:
  119. if (SuiteApp.getSofttokenStatus()) {
  120. mensaje += getEtiquetaCampoSoftokenActivado();
  121. } else {
  122. mensaje += getEtiquetaCampoSoftokenDesactivado();
  123. }
  124. break;
  125. default:
  126. break;
  127. }
  128. mensaje += ".";
  129. msg = new StringBuilder(mensaje);
  130. } else if (asm.length() != Constants.ASM_LENGTH) {
  131. esOk = false;
  132. String mensaje = viewController.getString(R.string.confirmation_valorIncompleto1);
  133. mensaje += " ";
  134. mensaje += Constants.ASM_LENGTH;
  135. mensaje += " ";
  136. mensaje += viewController.getString(R.string.confirmation_valorIncompleto2);
  137. mensaje += " ";
  138. switch (tipoInstrumentoSeguridad) {
  139. case OCRA:
  140. mensaje += getEtiquetaCampoOCRA();
  141. break;
  142. case DP270:
  143. mensaje += getEtiquetaCampoDP270();
  144. break;
  145. case SoftToken:
  146. if (SuiteApp.getSofttokenStatus()) {
  147. mensaje += getEtiquetaCampoSoftokenActivado();
  148. } else {
  149. mensaje += getEtiquetaCampoSoftokenDesactivado();
  150. }
  151. break;
  152. default:
  153. break;
  154. }
  155. mensaje += ".";
  156. msg = new StringBuilder(mensaje);
  157. }
  158. }else if(debePedirCVV){
  159. String cvv = viewController.pideCVV();
  160. if (cvv.equals("")) {
  161. esOk = false;
  162. String mensaje = viewController.getString(R.string.confirmation_valorVacio);
  163. mensaje += " ";
  164. mensaje += viewController.getString(R.string.confirmation_componenteCvv);
  165. mensaje += ".";
  166. msg = new StringBuilder(mensaje);
  167. } else if (cvv.length() != Constants.CVV_LENGTH) {
  168. esOk = false;
  169. String mensaje = viewController.getString(R.string.confirmation_valorIncompleto1);
  170. mensaje += " ";
  171. mensaje += Constants.CVV_LENGTH;
  172. mensaje += " ";
  173. mensaje += viewController.getString(R.string.confirmation_valorIncompleto2);
  174. mensaje += " ";
  175. mensaje += viewController.getString(R.string.confirmation_componenteCvv);
  176. mensaje += ".";
  177. msg = new StringBuilder(mensaje);
  178. }
  179. }
  180. if(!esOk)
  181. viewController.showInformationAlert(msg.toString());
  182. return esOk;
  183. }
  184. /**
  185. * notifica al delegate de la op actual la confirmacion para realizar la operacion.
  186. *
  187. * @param contrasena
  188. * @param nip
  189. * @param asm
  190. * @param cvv
  191. */
  192. public void enviaPeticionOperacion(String contrasena, String nip, String asm, String cvv) {
  193. String newToken = null;
  194. if(tokenAMostrar != TipoOtpAutenticacion.ninguno && tipoInstrumentoSeguridad == TipoInstrumento.SoftToken && SuiteApp.getSofttokenStatus())
  195. newToken = loadOtpFromSofttoken(tokenAMostrar);
  196. if(null != newToken)
  197. asm = newToken;
  198. if (opDelegate instanceof AltaRetiroSinTarjetaDelegate) {
  199. opDelegate.realizaOperacion(viewController, contrasena, nip, asm, cvv);
  200. }else {
  201. opDelegate.realizaOperacion(viewController, contrasena, nip, asm);
  202. }
  203. }
  204. @Override
  205. public String getEtiquetaCampoNip() {
  206. return viewController.getString(R.string.confirmation_nip);
  207. }
  208. @Override
  209. public String getTextoAyudaNIP() {
  210. return viewController.getString(R.string.confirmation_ayudaNip);
  211. }
  212. @Override
  213. public String getEtiquetaCampoContrasenia() {
  214. return viewController.getString(R.string.confirmation_contrasena);
  215. }
  216. @Override
  217. public String getEtiquetaCampoOCRA() {
  218. return viewController.getString(R.string.confirmation_ocra);
  219. }
  220. @Override
  221. public String getEtiquetaCampoDP270() {
  222. return viewController.getString(R.string.confirmation_dp270);
  223. }
  224. @Override
  225. public String getEtiquetaCampoSoftokenActivado() {
  226. return viewController.getString(R.string.confirmation_softtokenActivado);
  227. }
  228. @Override
  229. public String getEtiquetaCampoSoftokenDesactivado() {
  230. return viewController.getString(R.string.confirmation_softtokenDesactivado);
  231. }
  232. @Override
  233. public String getEtiquetaCampoCVV() {
  234. return viewController.getString(R.string.confirmation_CVV);
  235. }
  236. @Override
  237. public int getTextoEncabezado() {
  238. return opDelegate.getTextoEncabezado();
  239. }
  240. @Override
  241. public int getNombreImagenEncabezado() {
  242. return opDelegate.getNombreImagenEncabezado();
  243. }
  244. @Override
  245. public void analyzeResponse(int operationId, ServerResponse response) {
  246. if(response.getStatus() == ServerResponse.OPERATION_ERROR){
  247. viewController.limpiarCampos();
  248. BmovilApp bmApp = SuiteApp.getInstance().getBmovilApplication();
  249. BmovilViewsController bmvc = bmApp.getBmovilViewsController();
  250. BaseViewController current = bmvc.getCurrentViewControllerApp();
  251. current.showInformationAlert(response.getMessageText());
  252. }
  253. opDelegate.analyzeResponse(operationId, response);
  254. }
  255. @Override
  256. public ArrayList<Object> getDatosRegistroOp() {
  257. return opDelegate.getDatosTablaConfirmacion();
  258. }
  259. @Override
  260. public ArrayList<Object> getDatosRegistroExitoso() {
  261. return opDelegate.getDatosRegistroExitoso();
  262. }
  263. @Override
  264. public TipoOtpAutenticacion tokenAMostrar() {
  265. return tokenAMostrar;
  266. }
  267. @Override
  268. public String loadOtpFromSofttoken(TipoOtpAutenticacion tipoOTP) {
  269. return loadOtpFromSofttoken(tipoOTP, opDelegate);
  270. }
  271. }