Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // TODO: 16/4/2019
- public boolean ValidarExpresiones(Elemento elemento, String valor, boolean validoexp ) {
- String expreg = elemento.getStringValorAttr("expresionregular");
- if (!expreg.isEmpty()) {
- expreg = expreg.equals("*") ? "\\w+" : expreg;
- try {
- if (!valor.matches(expreg)) {
- String regexrerrormsg = elemento.getStringValorAttr("regexrerrormsg");
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- validoexp = false;
- if (regexrerrormsg.isEmpty()) {
- regexrerrormsg = "La expresion regular: " + expreg + "es incorrecta.";
- }
- elemento.setStringValorAttr("MensajeGeneral", regexrerrormsg, true);
- // isValid = false;
- validoexp = false;
- }
- } catch (Exception ex) {
- // isValid = false;
- validoexp = false;
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- elemento.setStringValorAttr("MensajeGeneral", "La expresion regular es invalida.", true);
- // Toasty.error(mContext, "Expresión Regular Mal Configurada", Toast.LENGTH_SHORT, true).show();
- }
- }else {
- validoexp = true;
- }
- return validoexp;
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- private boolean ValidationsByChilds(List<Elemento> elementos, boolean isValid) {
- for (Elemento elemento : elementos) {
- boolean visible = elemento.getBooleanValorAttr("visible");
- boolean habilitado = elemento.getBooleanValorAttr("habilitado");
- boolean mostrarMensajeLonMin = true;
- boolean mostrarMensajeExpReg = true;
- if (visible && habilitado) {
- String lmax = elemento.getStringValorAttr("longitudmaxima");
- String lmin = elemento.getStringValorAttr("longitudminima");
- String valor = elemento.getStringValorAttr("valor");
- String valorM = elemento.getStringValorAttr("valormetadato");
- String expreg = elemento.getStringValorAttr("expresionregular");
- elemento.setBooleanValorAttr("mostrarMensajeLonMax", false, true);
- if (lmax.length() > 0) {
- if (Integer.parseInt(lmax) > 0) {
- if (valor.length() > Integer.parseInt(lmax)) {
- elemento.setBooleanValorAttr("mostrarMensajeLonMax", true, true);
- elemento.setStringValorAttr("MensajeLonMax", String.format("La longitud máxima es de: %s", lmax), true);
- isValid = false;
- }
- }
- }
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", false, true);
- if (elemento.getBooleanValorAttr("requerido")) {
- // TODO: 12/4/2019
- if ((elemento.tipoelemento == TipoElemento.audio) || (elemento.tipoelemento == TipoElemento.imagen) ||
- (elemento.tipoelemento == TipoElemento.firma) || (elemento.tipoelemento == TipoElemento.video) ||
- (elemento.tipoelemento == TipoElemento.huelladigital) || (elemento.tipoelemento == TipoElemento.rostrovivo) ||
- (elemento.tipoelemento == TipoElemento.georeferencia)) {
- if (elemento.tipoelemento == TipoElemento.georeferencia) {
- if (elemento.getBooleanValorAttr("pedirmapa")) {
- String file = elemento.getStringValorAttr("nombrearchivo");
- if (file.isEmpty()) {
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
- isValid = false;
- }
- }
- if (valor.isEmpty()) {
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
- isValid = false;
- }
- } else if (elemento.tipoelemento == TipoElemento.huelladigital) {
- String file = elemento.getStringValorAttr("scorepromedio");
- if (file.isEmpty()) {
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
- isValid = false;
- }
- } else {
- String file = elemento.getStringValorAttr("nombrearchivo");
- if (file.isEmpty()) {
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
- isValid = false;
- }
- }
- } else if ((elemento.tipoelemento == TipoElemento.lista)) {
- if (valorM.isEmpty()) {
- elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- isValid = false;
- }
- } else if ((elemento.tipoelemento == TipoElemento.logico)) {
- if (valor.toLowerCase().equals("false")) {
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
- isValid = false;
- }
- } else {
- if (valor.isEmpty()) {
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
- isValid = false;
- }
- }
- // TODO: 12/4/2019 primer if requerido
- if (!ValidarMenor(lmin, valor, mostrarMensajeLonMin)) {
- if (valor.isEmpty()) {
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
- isValid = false;
- } else {
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- elemento.setStringValorAttr("MensajeGeneral", String.format("La longitud mínima es de: %s", lmin), true);
- isValid = false;
- }
- } else { //TODO: 12/4/2019 si es requerido y expresion regular
- if (!ValidarExpresiones(elemento, valor, mostrarMensajeExpReg)) {
- if (valor.isEmpty()) {
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
- isValid = false;
- } else {
- if (valor.isEmpty()) {
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- elemento.setStringValorAttr("MensajeGeneral", String.format("Campo requerido"), true);
- isValid = false;
- } else {
- if (!expreg.isEmpty()) {
- expreg = expreg.equals("*") ? "\\w+" : expreg;
- try {
- if (!valor.matches(expreg)) {
- String regexrerrormsg = elemento.getStringValorAttr("regexrerrormsg");
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- if (regexrerrormsg.isEmpty()) {
- regexrerrormsg = "La expresion regular: " + expreg + "es incorrecta.";
- }
- elemento.setStringValorAttr("regexrerrormsg", regexrerrormsg, true);
- isValid = false;
- }
- } catch (Exception ex) {
- isValid = false;
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- elemento.setStringValorAttr("MensajeGeneral", "La expresion regular es invalida.", true);
- // Toasty.error(mContext, "Expresión Regular Mal Configurada", Toast.LENGTH_SHORT, true).show();
- }
- }
- }
- }
- }
- }
- } else if (!ValidarExpresiones(elemento, valor, mostrarMensajeExpReg)) { //TODO: 12/4/2019 si no es requerido y expresion regular
- if (valor.isEmpty()) {
- isValid = false;
- } else {
- if (!expreg.isEmpty()) {
- expreg = expreg.equals("*") ? "\\w+" : expreg;
- try {
- if (!valor.matches(expreg)) {
- String regexrerrormsg = elemento.getStringValorAttr("regexrerrormsg");
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- if (regexrerrormsg.isEmpty()) {
- regexrerrormsg = "La expresion regular: " + expreg + "es incorrecta.";
- }
- elemento.setStringValorAttr("regexrerrormsg", regexrerrormsg, true);
- isValid = false;
- }
- } catch (Exception ex) {
- isValid = false;
- elemento.setBooleanValorAttr("mostrarMensajeRequerido", true, true);
- elemento.setStringValorAttr("MensajeGeneral", "La expresion regular es invalida.", true);
- // Toasty.error(mContext, "Expresión Regular Mal Configurada", Toast.LENGTH_SHORT, true).show();
- }
- }
- }
- }
- // TODO: 12/4/2019
- if (elemento.estadisticas.size() > 0) {
- if (isValid) {
- elemento.estadisticas.get(elemento.estadisticas.size() - 1).CapturaOk = true;
- } else {
- elemento.estadisticas.get(elemento.estadisticas.size() - 1).CapturaError = true;
- }
- }
- isValid = ValidationsByChilds(elemento.elementos, isValid);
- }
- }
- return isValid;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement