Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.29 KB | None | 0 0
  1. // TODO: 16/4/2019
  2. public boolean ValidarExpresiones(Elemento elemento, String valor, boolean validoexp ) {
  3. String expreg = elemento.getStringValorAttr("expresionregular");
  4. if (!expreg.isEmpty()) {
  5. expreg = expreg.equals("*") ? "\\w+" : expreg;
  6. try {
  7. if (!valor.matches(expreg)) {
  8. String regexrerrormsg = elemento.getStringValorAttr("regexrerrormsg");
  9. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  10. validoexp = false;
  11.  
  12. if (regexrerrormsg.isEmpty()) {
  13. regexrerrormsg = "La expresion regular: " + expreg + "es incorrecta.";
  14. }
  15. elemento.setStringValorAttr("MensajeGeneral", regexrerrormsg, true);
  16. // isValid = false;
  17. validoexp = false;
  18. }
  19. } catch (Exception ex) {
  20. // isValid = false;
  21. validoexp = false;
  22. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  23. elemento.setStringValorAttr("MensajeGeneral", "La expresion regular es invalida.", true);
  24. // Toasty.error(mContext, "Expresión Regular Mal Configurada", Toast.LENGTH_SHORT, true).show();
  25. }
  26. }else {
  27. validoexp = true;
  28. }
  29. return validoexp;
  30. }
  31.  
  32. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  33. private boolean ValidationsByChilds(List<Elemento> elementos, boolean isValid) {
  34. for (Elemento elemento : elementos) {
  35. boolean visible = elemento.getBooleanValorAttr("visible");
  36. boolean habilitado = elemento.getBooleanValorAttr("habilitado");
  37. boolean mostrarMensajeLonMin = true;
  38. boolean mostrarMensajeExpReg = true;
  39.  
  40. if (visible && habilitado) {
  41. String lmax = elemento.getStringValorAttr("longitudmaxima");
  42. String lmin = elemento.getStringValorAttr("longitudminima");
  43.  
  44. String valor = elemento.getStringValorAttr("valor");
  45. String valorM = elemento.getStringValorAttr("valormetadato");
  46. String expreg = elemento.getStringValorAttr("expresionregular");
  47.  
  48.  
  49. elemento.setBooleanValorAttr("mostrarMensajeLonMax", false, true);
  50. if (lmax.length() > 0) {
  51. if (Integer.parseInt(lmax) > 0) {
  52. if (valor.length() > Integer.parseInt(lmax)) {
  53. elemento.setBooleanValorAttr("mostrarMensajeLonMax", true, true);
  54. elemento.setStringValorAttr("MensajeLonMax", String.format("La longitud máxima es de: %s", lmax), true);
  55. isValid = false;
  56. }
  57. }
  58. }
  59.  
  60. elemento.setBooleanValorAttr("mostrarMensajeRequerido", false, true);
  61. if (elemento.getBooleanValorAttr("requerido")) {
  62. // TODO: 12/4/2019
  63. if ((elemento.tipoelemento == TipoElemento.audio) || (elemento.tipoelemento == TipoElemento.imagen) ||
  64. (elemento.tipoelemento == TipoElemento.firma) || (elemento.tipoelemento == TipoElemento.video) ||
  65. (elemento.tipoelemento == TipoElemento.huelladigital) || (elemento.tipoelemento == TipoElemento.rostrovivo) ||
  66. (elemento.tipoelemento == TipoElemento.georeferencia)) {
  67. if (elemento.tipoelemento == TipoElemento.georeferencia) {
  68. if (elemento.getBooleanValorAttr("pedirmapa")) {
  69. String file = elemento.getStringValorAttr("nombrearchivo");
  70. if (file.isEmpty()) {
  71. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  72. elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
  73. isValid = false;
  74. }
  75. }
  76. if (valor.isEmpty()) {
  77. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  78. elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
  79. isValid = false;
  80. }
  81. } else if (elemento.tipoelemento == TipoElemento.huelladigital) {
  82. String file = elemento.getStringValorAttr("scorepromedio");
  83. if (file.isEmpty()) {
  84. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  85. elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
  86. isValid = false;
  87. }
  88. } else {
  89. String file = elemento.getStringValorAttr("nombrearchivo");
  90. if (file.isEmpty()) {
  91. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  92. elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
  93. isValid = false;
  94. }
  95. }
  96. } else if ((elemento.tipoelemento == TipoElemento.lista)) {
  97. if (valorM.isEmpty()) {
  98. elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
  99. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  100. isValid = false;
  101. }
  102. } else if ((elemento.tipoelemento == TipoElemento.logico)) {
  103. if (valor.toLowerCase().equals("false")) {
  104. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  105.  
  106. elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
  107. isValid = false;
  108.  
  109. }
  110. } else {
  111. if (valor.isEmpty()) {
  112. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  113. elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
  114. isValid = false;
  115. }
  116. }
  117. // TODO: 12/4/2019 primer if requerido
  118. if (!ValidarMenor(lmin, valor, mostrarMensajeLonMin)) {
  119. if (valor.isEmpty()) {
  120. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  121. elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
  122. isValid = false;
  123. } else {
  124. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  125. elemento.setStringValorAttr("MensajeGeneral", String.format("La longitud mínima es de: %s", lmin), true);
  126. isValid = false;
  127. }
  128. } else { //TODO: 12/4/2019 si es requerido y expresion regular
  129. if (!ValidarExpresiones(elemento, valor, mostrarMensajeExpReg)) {
  130. if (valor.isEmpty()) {
  131. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  132. elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
  133. isValid = false;
  134. } else {
  135. if (valor.isEmpty()) {
  136. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  137. elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
  138. isValid = false;
  139. } else {
  140. if (!expreg.isEmpty()) {
  141. expreg = expreg.equals("*") ? "\\w+" : expreg;
  142. try {
  143. if (!valor.matches(expreg)) {
  144. String regexrerrormsg = elemento.getStringValorAttr("regexrerrormsg");
  145. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  146.  
  147. if (regexrerrormsg.isEmpty()) {
  148. regexrerrormsg = "La expresion regular: " + expreg + "es incorrecta.";
  149. }
  150. elemento.setStringValorAttr("regexrerrormsg", regexrerrormsg, true);
  151.  
  152. isValid = false;
  153. }
  154. } catch (Exception ex) {
  155. isValid = false;
  156. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  157. elemento.setStringValorAttr("MensajeGeneral", "La expresion regular es invalida.", true);
  158. // Toasty.error(mContext, "Expresión Regular Mal Configurada", Toast.LENGTH_SHORT, true).show();
  159. }
  160. }
  161. }
  162. }
  163. }
  164. }
  165.  
  166. } else if (!ValidarExpresiones(elemento, valor, mostrarMensajeExpReg)) { //TODO: 12/4/2019 si no es requerido y expresion regular
  167. if (valor.isEmpty()) {
  168.  
  169. isValid = false;
  170. } else {
  171. if (!expreg.isEmpty()) {
  172. expreg = expreg.equals("*") ? "\\w+" : expreg;
  173. try {
  174. if (!valor.matches(expreg)) {
  175. String regexrerrormsg = elemento.getStringValorAttr("regexrerrormsg");
  176. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  177.  
  178. if (regexrerrormsg.isEmpty()) {
  179. regexrerrormsg = "La expresion regular: " + expreg + "es incorrecta.";
  180. }
  181. elemento.setStringValorAttr("regexrerrormsg", regexrerrormsg, true);
  182.  
  183. isValid = false;
  184. }
  185. } catch (Exception ex) {
  186. isValid = false;
  187. elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
  188. elemento.setStringValorAttr("MensajeGeneral", "La expresion regular es invalida.", true);
  189. // Toasty.error(mContext, "Expresión Regular Mal Configurada", Toast.LENGTH_SHORT, true).show();
  190. }
  191. }
  192. }
  193. }
  194. // TODO: 12/4/2019
  195.  
  196. if (elemento.estadisticas.size() > 0) {
  197. if (isValid) {
  198. elemento.estadisticas.get(elemento.estadisticas.size() - 1).CapturaOk = true;
  199. } else {
  200. elemento.estadisticas.get(elemento.estadisticas.size() - 1).CapturaError = true;
  201. }
  202. }
  203.  
  204. isValid = ValidationsByChilds(elemento.elementos, isValid);
  205. }
  206. }
  207.  
  208. return isValid;
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement