Example usage for org.apache.commons.validator GenericValidator isBlankOrNull

List of usage examples for org.apache.commons.validator GenericValidator isBlankOrNull

Introduction

In this page you can find the example usage for org.apache.commons.validator GenericValidator isBlankOrNull.

Prototype

public static boolean isBlankOrNull(String value) 

Source Link

Document

Checks if the field isn't null and length of the field is greater than zero not including whitespace.

Usage

From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.EctValidation.java

public boolean matchRegExp(String regExp, String inputValue) {

    boolean validation = true;
    org.apache.commons.validator.GenericValidator gValidator = new org.apache.commons.validator.GenericValidator();

    MiscUtils.getLogger().debug("matchRegExp function is called.");

    if (!GenericValidator.isBlankOrNull(regExp) && !GenericValidator.isBlankOrNull(inputValue)) {
        MiscUtils.getLogger().debug("both the regExp and inputValue is not blank nor null.");
        if (!inputValue.matches(regExp)) {
            MiscUtils.getLogger().debug("Regexp not matched");
            validation = false;/*from   ww w.  ja v  a 2 s.c  om*/

        }

    }
    return validation;
}

From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.EctValidation.java

public boolean isInRange(double dMax, double dMin, String inputValue) {

    boolean validation = true;
    org.apache.commons.validator.GenericValidator gValidator = new org.apache.commons.validator.GenericValidator();

    if ((dMax != 0) || (dMin != 0)) {
        if (GenericValidator.isDouble(inputValue)) {
            double dValue = Double.parseDouble(inputValue);

            if (!GenericValidator.isInRange(dValue, dMin, dMax)) {
                validation = false;/*from   w  ww .  ja va 2s.com*/
            }
        } else if (!GenericValidator.isBlankOrNull(inputValue)) {
            validation = false;
        }
    }
    return validation;
}

From source file:oscar.oscarEncounter.oscarMeasurements.pageUtil.FormUpdateAction.java

public boolean doInput(FlowSheetItem item, EctMeasurementTypesBean mtypeBean, MeasurementFlowSheet mFlowsheet,
        String inputType, String mInstructions, String value, String comment, String date, String apptNo,
        HttpServletRequest request) {//from w  w  w  .java2s.  co  m
    EctValidation ectValidation = new EctValidation();
    ActionMessages errors = new ActionMessages();

    String temp = request.getParameter("template");
    String demographicNo = request.getParameter("demographic_no");
    HttpSession session = request.getSession();
    String providerNo = (String) session.getAttribute("user");

    ResultSet rs;
    String regCharExp;

    String regExp = null;
    double dMax = 0;
    double dMin = 0;
    int iMax = 0;
    int iMin = 0;

    rs = ectValidation.getValidationType(inputType, mInstructions);
    regCharExp = ectValidation.getRegCharacterExp();

    boolean valid = true;

    try {

        if (rs.next()) {
            dMax = rs.getDouble("maxValue");
            dMin = rs.getDouble("minValue");
            iMax = rs.getInt("maxLength");
            iMin = rs.getInt("minLength");
            regExp = oscar.Misc.getString(rs, "regularExp");
        }
        rs.close();

        String inputTypeDisplay = mtypeBean.getTypeDisplayName();
        String inputValueName = item.getDisplayName();
        String inputValue = value;
        String comments = comment;
        String dateObserved = date;

        java.util.Calendar calender = java.util.Calendar.getInstance();
        String hour = Integer.toString(calender.get(java.util.Calendar.HOUR_OF_DAY));
        String min = Integer.toString(calender.get(java.util.Calendar.MINUTE));
        String second = Integer.toString(calender.get(java.util.Calendar.SECOND));
        String dateEntered = dateObserved + " " + hour + ":" + min + ":" + second;

        if (!ectValidation.isInRange(dMax, dMin, inputValue)) {
            errors.add(inputValueName, new ActionMessage("errors.range", inputTypeDisplay,
                    Double.toString(dMin), Double.toString(dMax)));
            saveErrors(request, errors);
            valid = false;
        }
        if (!ectValidation.maxLength(iMax, inputValue)) {
            errors.add(inputValueName,
                    new ActionMessage("errors.maxlength", inputTypeDisplay, Integer.toString(iMax)));
            saveErrors(request, errors);
            valid = false;
        }
        if (!ectValidation.minLength(iMin, inputValue)) {
            errors.add(inputValueName,
                    new ActionMessage("errors.minlength", inputTypeDisplay, Integer.toString(iMin)));
            saveErrors(request, errors);
            valid = false;
        }

        if (!ectValidation.matchRegExp(regExp, inputValue)) {
            errors.add(inputValueName, new ActionMessage("errors.invalid", inputTypeDisplay));
            saveErrors(request, errors);
            valid = false;
        }
        if (!ectValidation.isValidBloodPressure(regExp, inputValue)) {
            errors.add(inputValueName, new ActionMessage("error.bloodPressure"));
            saveErrors(request, errors);
            valid = false;
        }
        if (!ectValidation.isDate(dateObserved) && inputValue.compareTo("") != 0) {
            errors.add("Date", new ActionMessage("errors.invalidDate", inputTypeDisplay));
            saveErrors(request, errors);
            valid = false;
        }

        if (valid) {
            comments = org.apache.commons.lang.StringEscapeUtils.escapeSql(comments);
            MsgStringQuote str = new MsgStringQuote();

            Properties p = (Properties) session.getAttribute("providerBean");
            String by = "";
            if (p != null) {
                by = p.getProperty(providerNo, "");
            }

            org.apache.commons.validator.GenericValidator gValidator = new org.apache.commons.validator.GenericValidator();
            if (!GenericValidator.isBlankOrNull(inputValue)) {

                String[] dateComp = date.split("-");
                Date dateObs = new Date();
                dateObs.setYear(Integer.parseInt(dateComp[0]) - 1900);
                dateObs.setMonth(Integer.parseInt(dateComp[1]) - 1);
                dateObs.setDate(Integer.parseInt(dateComp[2]));

                Measurement measurement = new Measurement();
                measurement.setDemographicId(Integer.parseInt(demographicNo));
                measurement.setDataField(inputValue);
                measurement.setMeasuringInstruction(mInstructions);
                if (comments.equals("")) {
                    comments = " ";
                }
                measurement.setComments(comments);
                measurement.setDateObserved(dateObs);
                measurement.setType(inputType);
                if (apptNo != null) {
                    measurement.setAppointmentNo(Integer.parseInt(apptNo));
                } else {
                    measurement.setAppointmentNo(0);
                }
                measurement.setProviderNo(providerNo);

                //Find if the same data has already been entered into the system
                MeasurementDao measurementDao = (MeasurementDao) SpringUtils.getBean("measurementDao");
                List<Measurement> measurements = measurementDao.findMatching(measurement);

                if (measurements.size() == 0) {
                    //Write to the Dababase if all input values are valid
                    measurementDao.persist(measurement);
                }
                rs.close();
            }

        }

    } catch (SQLException e) {

    }

    return valid;
}

From source file:oscar.oscarEncounter.oscarMeasurements.util.WriteNewMeasurements.java

static private ActionMessages validate(Vector measures, String demographicNo) {
    ActionMessages errors = new ActionMessages();
    try {//from w  w  w  .  ja  va 2s . c  om

        EctValidation ectValidation = new EctValidation();
        ResultSet rs;
        boolean valid = true;
        for (int i = 0; i < measures.size(); i++) {
            Hashtable measure = (Hashtable) measures.get(i);
            String inputType = (String) measure.get("type");
            String inputValue = (String) measure.get("value");
            String dateObserved = (String) measure.get("dateObserved");
            String comments = (String) measure.get("comments");
            String mInstrc, regCharExp;
            String regExp = null;
            double dMax = 0;
            double dMin = 0;
            int iMax = 0;
            int iMin = 0;
            org.apache.commons.validator.GenericValidator gValidator = new org.apache.commons.validator.GenericValidator();
            if (GenericValidator.isBlankOrNull(inputValue)) {
                measures.removeElementAt(i);
                i--;
                continue;
            }
            mInstrc = (String) measure.get("measuringInstruction");
            rs = ectValidation.getValidationType(inputType, mInstrc);
            regCharExp = ectValidation.getRegCharacterExp();
            if (rs.next()) {
                dMax = rs.getDouble("maxValue");
                dMin = rs.getDouble("minValue");
                iMax = rs.getInt("maxLength");
                iMin = rs.getInt("minLength");
                regExp = oscar.Misc.getString(rs, "regularExp");
            } else {
                //if type with instruction does not exist
                errors.add(inputType, new ActionMessage("errors.oscarEncounter.Measurements.cannotFindType",
                        inputType, mInstrc));
                valid = false;
                continue;
            }
            rs.close();

            if (!ectValidation.isInRange(dMax, dMin, inputValue)) {
                errors.add(inputType, new ActionMessage("errors.range", inputType, Double.toString(dMin),
                        Double.toString(dMax)));
                valid = false;
            }
            if (!ectValidation.maxLength(iMax, inputValue)) {
                errors.add(inputType, new ActionMessage("errors.maxlength", inputType, Integer.toString(iMax)));
                valid = false;
            }
            if (!ectValidation.minLength(iMin, inputValue)) {
                errors.add(inputType, new ActionMessage("errors.minlength", inputType, Integer.toString(iMin)));
                valid = false;
            }
            if (!ectValidation.matchRegExp(regExp, inputValue)) {
                errors.add(inputType, new ActionMessage("errors.invalid", inputType));
                valid = false;
            }
            if (!ectValidation.isValidBloodPressure(regExp, inputValue)) {
                errors.add(inputType, new ActionMessage("error.bloodPressure"));
                valid = false;
            }
            if (!ectValidation.isDate(dateObserved) && inputValue.compareTo("") != 0) {
                errors.add(inputType, new ActionMessage("errors.invalidDate", inputType));
                valid = false;
            }

            if (!valid)
                continue;
            inputValue = org.apache.commons.lang.StringEscapeUtils.escapeSql(inputValue);
            inputType = org.apache.commons.lang.StringEscapeUtils.escapeSql(inputType);
            mInstrc = org.apache.commons.lang.StringEscapeUtils.escapeSql(mInstrc);
            comments = org.apache.commons.lang.StringEscapeUtils.escapeSql(comments);

            //Find if the same data has already been entered into the system
            String sql = "SELECT * FROM measurements WHERE demographicNo='" + demographicNo
                    + "' AND dataField='" + inputValue + "' AND measuringInstruction='" + mInstrc
                    + "' AND comments='" + comments + "' AND dateObserved='" + dateObserved + "'";
            rs = DBHandler.GetSQL(sql);
            if (rs.next()) {
                measures.remove(i);
                i--;
                continue;
            }
        }
    } catch (SQLException sqe) {
        MiscUtils.getLogger().error("Error", sqe);
    }
    return errors;
}

From source file:ubic.gemma.web.util.ValidationUtil.java

/**
 * Validates that a field has a length in some range. This goes with the custom declaration in the
 * validation-rules-custom.xml file.//  w  w w . j  a  va  2  s. c o m
 * 
 * @param bean
 * @param va
 * @param field
 * @param errors
 * @return boolean
 * @author pavlidis
 */
public static boolean validateLengthRange(Object bean, ValidatorAction va, Field field, Errors errors) {
    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    String minLengthS = field.getVarValue("minlength");
    String maxLengthS = field.getVarValue("maxlength");

    assert minLengthS != null && maxLengthS != null : "Length variables names aren't valid for field";

    if (!GenericValidator.isBlankOrNull(value)) {
        try {

            int minLength = Integer.parseInt(minLengthS);
            int maxLength = Integer.parseInt(maxLengthS);

            if (value.length() < minLength || value.length() > maxLength) {
                FieldChecks.rejectValue(errors, field, va);
                return false;
            }
        } catch (Exception e) {
            FieldChecks.rejectValue(errors, field, va);
            return false;
        }
    }

    return true;
}

From source file:us.mn.state.health.lims.address.valueholder.OrganizationAddress.java

public String getUniqueIdentifyer() {
    if (GenericValidator.isBlankOrNull(uniqueIdentifyer)) {
        uniqueIdentifyer = getOrganizationId() + "-" + getAddressPartId();
    }/*ww w. ja  va  2  s. c  om*/

    return uniqueIdentifyer;
}

From source file:us.mn.state.health.lims.address.valueholder.PersonAddress.java

public String getUniqueIdentifyer() {
    if (GenericValidator.isBlankOrNull(uniqueIdentifyer)) {
        uniqueIdentifyer = getPersonId() + "-" + getAddressPartId();
    }//from   w w  w.j a va  2 s.c  o m

    return uniqueIdentifyer;
}

From source file:us.mn.state.health.lims.analysis.daoimpl.AnalysisDAOImpl.java

@SuppressWarnings("unchecked")
public List<Analysis> getAnalysesBySampleId(String id) throws LIMSRuntimeException {
    List<Analysis> list = null;
    if (!GenericValidator.isBlankOrNull(id)) {
        try {/*from www.ja v a  2 s.c  om*/
            String sql = "from Analysis a where a.sampleItem.sample.id = :sampleId";

            org.hibernate.Query query = HibernateUtil.getSession().createQuery(sql);
            query.setInteger("sampleId", Integer.parseInt(id));

            list = query.list();
            closeSession();
        } catch (Exception e) {
            handleException(e, "getAnalysesBySampleId");
        }
    }
    return list;
}

From source file:us.mn.state.health.lims.analysis.daoimpl.AnalysisDAOImpl.java

@SuppressWarnings("unchecked")
@Override//w  ww .  ja v a  2s  . c  om
public List<Analysis> getAnalysisByAccessionAndTestId(String accessionNumber, String testId)
        throws LIMSRuntimeException {
    if (GenericValidator.isBlankOrNull(accessionNumber) || GenericValidator.isBlankOrNull(testId)) {
        return new ArrayList<Analysis>();
    }

    String sql = "From Analysis a where a.sampleItem.sample.accessionNumber = :accessionNumber and a.test.id = :testId";

    try {
        Query query = HibernateUtil.getSession().createQuery(sql);
        query.setString("accessionNumber", accessionNumber);
        query.setInteger("testId", Integer.parseInt(testId));
        List<Analysis> analysises = query.list();
        closeSession();
        return analysises;
    } catch (HibernateException e) {
        handleException(e, "getAnalysisByAccessionAndTestId");
    }

    return null;
}

From source file:us.mn.state.health.lims.analysis.valueholder.Analysis.java

public void setSampleItem(SampleItem sampleItem) {
    this.sampleItem.setValue(sampleItem);

    if (GenericValidator.isBlankOrNull(sampleTypeName) && sampleItem != null
            && sampleItem.getTypeOfSample() != null) {
        setSampleTypeName(sampleItem.getTypeOfSample().getLocalizedName());
    }/*from w w w . jav a 2  s .  c  om*/
}