private AnalyzerTestMapping validateAnalyzerAndTestName( String analyzerId, String analyzerTestName, String testId, ActionMessages errors, boolean newMapping) { // This is not very efficient but this is a very low usage action if (GenericValidator.isBlankOrNull(analyzerId) || GenericValidator.isBlankOrNull(analyzerTestName) || GenericValidator.isBlankOrNull(testId)) { errors.add(ActionErrors.GLOBAL_MESSAGE, new ActionError("error.all.required")); return null; } AnalyzerTestMapping existingMapping = null; AnalyzerTestMappingDAO mappingDAO = new AnalyzerTestMappingDAOImpl(); List<AnalyzerTestMapping> testMappingList = mappingDAO.getAllAnalyzerTestMappings(); for (AnalyzerTestMapping testMapping : testMappingList) { if (analyzerId.equals(testMapping.getAnalyzerId()) && analyzerTestName.equals(testMapping.getAnalyzerTestName())) { if (newMapping) { errors.add( ActionErrors.GLOBAL_MESSAGE, new ActionError("error.analyzer.test.name.duplicate")); return null; } else { existingMapping = testMapping; testMapping.setTestId(testId); break; } } } return existingMapping; }
private static void addChildMenuItems( StringBuffer html, List<MenuItem> menuTree, String contextPath, boolean topLevel) { int topLevelCount = 0; for (MenuItem menuItem : menuTree) { Menu menu = menuItem.getMenu(); if (topLevel) { if (topLevelCount == 0) { html.append("\t<li id=\"nav-first\" >\n"); } else if (topLevelCount == menuTree.size() - 1) { html.append("\t<li id=\"nav-last\" >\n"); } else { html.append("\t<li>\n"); } topLevelCount++; } else { html.append("\t<li>\n"); } html.append("\t\t<a "); html.append("id=\""); html.append(menu.getElementId()); html.append("\" "); if (!GenericValidator.isBlankOrNull(menu.getLocalizedTooltip())) { html.append(" title=\""); html.append(menu.getLocalizedTooltip()); html.append("\" "); } if (menu.isOpenInNewWindow()) { html.append(" target=\"_blank\" "); } if (GenericValidator.isBlankOrNull(menu.getActionURL()) && GenericValidator.isBlankOrNull(menu.getClickAction())) { html.append(" class=\"no-link\" >"); } else { html.append(" href=\""); html.append(contextPath); html.append(menu.getActionURL()); html.append("\" >"); } html.append(menu.getLocalizedTitle()); html.append("</a>\n"); if (!menuItem.getChildMenus().isEmpty()) { html.append("<ul>\n"); addChildMenuItems(html, menuItem.getChildMenus(), contextPath, false); html.append("</ul>\n"); } html.append("\t</li>\n"); } }
public boolean matchRegExp(String regExp, String inputValue) { boolean validation = true; 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; } } return validation; }
public String validateNewFullName(JiraClient client, String fullName) { if (GenericValidator.isBlankOrNull(fullName)) { return "Please enter a full name."; } return null; }
/** @see javax.servlet.jsp.tagext.BodyTagSupport#doStartTag() */ public int doStartTag() throws JspException { final String pageAccess = (String) pageContext.getAttribute("access"); if ((pageAccess != null) && pageAccess.equals(Access.READONLY) && !forceReadWrite) { return SKIP_BODY; } // Recherche si un parent est du bon type Tag curParent = null; for (curParent = getParent(); (curParent != null) && !(curParent instanceof ColsTag); ) { curParent = curParent.getParent(); } if (curParent == null) { throw new JspException("ColTag must be used between Cols Tag."); } colsTag = (ColsTag) curParent; if (!GenericValidator.isBlankOrNull(colsTag.getEmptyKey()) && (pageContext.getAttribute(colsTag.getId()) == null)) { return SKIP_BODY; } else { return EVAL_PAGE; } }
public void validate(Errors errors) { if (StringUtils.isBlank(getUser().getCsmUser().getLoginName())) { errors.rejectValue("user.csmUser.loginName", "error.user.name.not.specified"); } else { User existing = authorizationManager.getUser(getUser().getCsmUser().getLoginName()); boolean existingMismatch = existing != null && !existing.getUserId().equals(getUser().getCsmUser().getUserId()); if (!lookUpBoundUser && ((isNewUser() && existing != null) || existingMismatch)) { errors.rejectValue("user.csmUser.loginName", "error.user.name.already.exists"); } } if (StringUtils.isBlank(getUser().getCsmUser().getFirstName())) { errors.rejectValue("user.csmUser.firstName", "error.user.firstName.not.specified"); } if (StringUtils.isBlank(getUser().getCsmUser().getLastName())) { errors.rejectValue("user.csmUser.lastName", "error.user.lastName.not.specified"); } if (!GenericValidator.isEmail(getUser().getCsmUser().getEmailId())) { errors.rejectValue("user.csmUser.emailId", "error.user.email.invalid"); } if (isNewUser() && getUsesLocalPasswords() && (StringUtils.isBlank(getPassword()))) { errors.rejectValue("password", "error.user.password.not.specified"); } if (getPassword() != null || getRePassword() != null) { if (!ComparisonUtils.nullSafeEquals(getPassword(), getRePassword())) { errors.rejectValue("rePassword", "error.user.repassword.does.not.match.password"); } } }
/** * Validates that two fields match. * * @param bean * @param va * @param field * @param errors * @param request * @return boolean */ public static boolean validateTwoFields( Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); String sProperty2 = field.getVarValue("secondProperty"); String value2 = ValidatorUtils.getValueAsString(bean, sProperty2); if (!GenericValidator.isBlankOrNull(value)) { try { if (!value.equals(value2)) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } } catch (Exception e) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } } return true; }
public void validate(Customer customer, String password, String passwordConfirm, Errors errors) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "password.required"); ValidationUtils.rejectIfEmptyOrWhitespace( errors, "passwordConfirm", "passwordConfirm.required"); errors.pushNestedPath("customer"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required"); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required"); errors.popNestedPath(); if (errors.hasErrors()) { if (!passwordConfirm.equals(password)) { errors.rejectValue("passwordConfirm", "invalid"); } if (!customer.getFirstName().matches(validNameRegex)) { errors.rejectValue("firstName", "firstName.invalid", null, null); } if (!customer.getLastName().matches(validNameRegex)) { errors.rejectValue("lastName", "lastName.invalid", null, null); } if (!customer.getPassword().matches(validPasswordRegex)) { errors.rejectValue("password", "password.invalid", null, null); } if (!password.equals(passwordConfirm)) { errors.rejectValue("password", "passwordConfirm.invalid", null, null); } if (!GenericValidator.isEmail(customer.getEmailAddress())) { errors.rejectValue("emailAddress", "emailAddress.invalid", null, null); } } }
private void addAnalyzerResultFromLine(List<AnalyzerResults> results, String line) { String[] fields = StringUtil.separateCSVWithMixedEmbededQuotes(line); // This insures that the row has not been truncated if (fields.length < maxViewedIndex) { return; } AnalyzerReaderUtil readerUtil = new AnalyzerReaderUtil(); String analyzerAccessionNumber = fields[Sample_ID].replace("\"", ""); analyzerAccessionNumber = StringUtil.strip(analyzerAccessionNumber, " "); String date = fields[Date_Analyzed].replace("\"", ""); // this is sort of dumb, we have the indexes we are interested in for (int i = 0; i < testNameIndex.length; i++) { if (!GenericValidator.isBlankOrNull(testNameIndex[i])) { MappedTestName mappedName = AnalyzerTestNameCache.instance() .getMappedTest(AnalyzerType.FACSCANTO, testNameIndex[i].replace("\"", "")); if (mappedName == null) { mappedName = AnalyzerTestNameCache.instance() .getEmptyMappedTestName( AnalyzerType.FACSCANTO, testNameIndex[i].replace("\"", "")); } AnalyzerResults analyzerResults = new AnalyzerResults(); analyzerResults.setAnalyzerId(mappedName.getAnalyzerId()); String result = fields[i].replace("\"", ""); result = roundTwoDigits(result); analyzerResults.setResult(result); analyzerResults.setUnits(unitsIndex[i]); analyzerResults.setCompleteDate( DateUtil.convertStringDateToTimestampWithPatternNoLocale(date, DATE_PATTERN)); // analyzerResults.setCompleteTime(DateUtil.convertStringDateToTimestamp(date)); analyzerResults.setTestId(mappedName.getTestId()); analyzerResults.setAccessionNumber(analyzerAccessionNumber); analyzerResults.setTestName(mappedName.getOpenElisTestName()); if (analyzerAccessionNumber != null) { analyzerResults.setIsControl( analyzerAccessionNumber.startsWith(CONTROL_ACCESSION_PREFIX)); } else { analyzerResults.setIsControl(false); } results.add(analyzerResults); AnalyzerResults resultFromDB = readerUtil.createAnalyzerResultFromDB(analyzerResults); if (resultFromDB != null) { results.add(resultFromDB); } } } }
private ResultLimit ageBasedResultLimit(List<ResultLimit> resultLimits, Patient patient) { ResultLimit resultLimit = null; // First we look for a limit with no gender for (ResultLimit limit : resultLimits) { if (GenericValidator.isBlankOrNull(limit.getGender()) && !limit.ageLimitsAreDefault() && getCurrPatientAge(patient) >= limit.getMinAge() && getCurrPatientAge(patient) <= limit.getMaxAge()) { resultLimit = limit; break; } } // if none is found then drop the no gender requirement if (resultLimit == null) { for (ResultLimit limit : resultLimits) { if (!limit.ageLimitsAreDefault() && getCurrPatientAge(patient) >= limit.getMinAge() && getCurrPatientAge(patient) <= limit.getMaxAge()) { resultLimit = limit; break; } } } return resultLimit == null ? defaultResultLimit(resultLimits) : resultLimit; }
private void merge(String[] base, String[] line) { for (int i = 0; i < base.length; ++i) { if (GenericValidator.isBlankOrNull(base[i])) { base[i] = line[i]; } } }
public boolean isInRange(Double dMax, Double dMin, String inputValue) { boolean validation = true; if ((dMax != null && dMax != 0) || (dMin != null && dMin != 0)) { if (GenericValidator.isDouble(inputValue)) { double dValue = Double.parseDouble(inputValue); if (!GenericValidator.isInRange(dValue, dMin, dMax)) { validation = false; } } else if (!GenericValidator.isBlankOrNull(inputValue)) { validation = false; } } return validation; }
@JavaScriptMethod public String isValidGroupName(String value) { if (GenericValidator.isBlankOrNull(value) || value.length() < 3) { return "Please use at least three character long group names."; } return null; }
private ResultLimit defaultResultLimit(List<ResultLimit> resultLimits) { for (ResultLimit limit : resultLimits) { if (GenericValidator.isBlankOrNull(limit.getGender()) && limit.ageLimitsAreDefault()) { return limit; } } return new ResultLimit(); }
public static String getDisplayReferenceRange( ResultLimit resultLimit, String significantDigits, String separator) { String range = ""; if (resultLimit != null && !GenericValidator.isBlankOrNull(resultLimit.getResultTypeId())) { if (NUMERIC_RESULT_TYPE_ID.equals(resultLimit.getResultTypeId())) { range = getDisplayNormalRange( resultLimit.getLowNormal(), resultLimit.getHighNormal(), significantDigits, separator); } else if (SELECT_LIST_RESULT_TYPE_IDS.contains(resultLimit.getResultTypeId()) && !GenericValidator.isBlankOrNull(resultLimit.getDictionaryNormalId())) { return dictionaryDAO.getDataForId(resultLimit.getDictionaryNormalId()).getLocalizedName(); } } return range; }
public String validateNewUsername(JiraClient client, String username) { if (GenericValidator.isBlankOrNull(username)) { return "Please enter a username."; } else if (isUsernameRegistered(client, username)) { return "This username is already used."; } return null; }
public String validateNewPassword(JiraClient client, String password) { if (GenericValidator.isBlankOrNull(password)) { return "Please enter a password."; } else if (password.length() < 5) { return "Minimum password length is 5 characters."; } return null; }
public ResultLimit getResultLimitForTestAndPatient(Test test, Patient patient) { currPatientAge = INVALID_PATIENT_AGE; @SuppressWarnings("unchecked") List<ResultLimit> resultLimits = resultLimitDAO.getAllResultLimitsForTest(test); if (resultLimits.isEmpty()) { return null; } else if (patient == null || patient.getBirthDate() == null && GenericValidator.isBlankOrNull(patient.getGender())) { return defaultResultLimit(resultLimits); } else if (GenericValidator.isBlankOrNull(patient.getGender())) { return ageBasedResultLimit(resultLimits, patient); } else if (patient.getBirthDate() == null) { return genderBasedResultLimit(resultLimits, patient); } else { return ageAndGenderBasedResultLimit(resultLimits, patient); } }
public boolean isInteger(String inputValue) { boolean validation = true; if (!GenericValidator.isInt(inputValue)) { validation = false; } return validation; }
private List<IdValuePair> getDictionaryValuesForTest(String testId) { if (!GenericValidator.isBlankOrNull(testId)) { for (NonNumericTests test : nonNumericTests) { if (testId.equals(test.testId)) { return test.dictionaryValues; } } } return new ArrayList<IdValuePair>(); }
protected RejectionReportBean createRejectionReportBean( String noteText, Analysis analysis, boolean useTestName) { RejectionReportBean item = new RejectionReportBean(); AnalysisService analysisService = new AnalysisService(analysis); SampleService sampleService = new SampleService(analysisService.getAnalysis().getSampleItem().getSample()); PatientService patientService = new PatientService(sampleService.getSample()); List<Result> results = analysisService.getResults(); for (Result result : results) { String signature = new ResultService(result).getSignature(); if (!GenericValidator.isBlankOrNull(signature)) { item.setTechnician(signature); break; } } item.setAccessionNumber(sampleService.getAccessionNumber().substring(PREFIX_LENGTH)); item.setReceivedDate(sampleService.getTwoYearReceivedDateForDisplay()); item.setCollectionDate( DateUtil.convertTimestampToTwoYearStringDate( analysisService.getAnalysis().getSampleItem().getCollectionDate())); item.setRejectionReason(noteText); StringBuilder nameBuilder = new StringBuilder(patientService.getLastName().toUpperCase()); if (!GenericValidator.isBlankOrNull(patientService.getNationalId())) { if (nameBuilder.length() > 0) { nameBuilder.append(" / "); } nameBuilder.append(patientService.getNationalId()); } if (useTestName) { item.setPatientOrTestName(analysisService.getTest().getLocalizedName()); item.setNonPrintingPatient(nameBuilder.toString()); } else { item.setPatientOrTestName(nameBuilder.toString()); } return item; }
private boolean validateSelection(ReportSpecificationList selectList) { boolean complete = !GenericValidator.isBlankOrNull(selectList.getSelection()) && !"0".equals(selectList.getSelection()); if (!complete) { add1LineErrorMessage("report.error.message.activity.missing"); } return complete; }
public boolean minLength(Integer iMin, String inputValue) { boolean validation = true; if (iMin != null && iMin != 0) { if (!GenericValidator.minLength(inputValue, iMin)) { validation = false; } } return validation; }
public String validateNewEmail(JiraClient client, String email) { if (GenericValidator.isBlankOrNull(email)) { return "Please enter an email address."; } else if (!EmailValidator.getInstance().isValid(email)) { return "Please enter a valid email address."; } else if (isEmailAddressRegistered(client, email)) { return "Email address already registered."; } return null; }
/** * Move everything appropriate to the referralItem including one or more of the referralResults * from the given list. Note: This method removes an item from the referralResults list. * * @param referralItem The source item * @param referralResults The created list */ private List<ReferralResult> setReferralItemForNextTest( IReferralResultTest referralItem, List<ReferralResult> referralResults) { ReferralResult nextTestFirstResult = referralResults.remove(0); List<ReferralResult> resultsForOtherTests = new ArrayList<ReferralResult>(referralResults); referralItem.setReferredTestId(nextTestFirstResult.getTestId()); referralItem.setReferredTestIdShadow(referralItem.getReferredTestId()); referralItem.setReferredReportDate( DateUtil.convertTimestampToStringDate(nextTestFirstResult.getReferralReportDate())); // We can not use ResultService because that assumes the result is for an analysis, not a // referral Result result = nextTestFirstResult.getResult(); String resultType = (result != null) ? result.getResultType() : "N"; referralItem.setReferredResultType(resultType); if (!ResultType.isMultiSelectVariant(resultType)) { if (result != null) { String resultValue = GenericValidator.isBlankOrNull(result.getValue()) ? "" : result.getValue(); referralItem.setReferredResult(resultValue); referralItem.setReferredDictionaryResult(resultValue); } } else { ArrayList<Result> resultList = new ArrayList<Result>(); resultList.add(nextTestFirstResult.getResult()); for (ReferralResult referralResult : referralResults) { if (nextTestFirstResult.getTestId().equals(referralResult.getTestId()) && !GenericValidator.isBlankOrNull(referralResult.getResult().getValue())) { resultList.add(referralResult.getResult()); resultsForOtherTests.remove(referralResult); } } referralItem.setMultiSelectResultValues( ResultService.getJSONStringForMultiSelect(resultList)); } return resultsForOtherTests; }
public boolean validate( CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context) { String value = null; value = getValueAsString(source, propertyName); if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.isEmail(value)) { JobEntryValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail(context, VALIDATOR_NAME)); return false; } else { return true; } }
private String getAppropriateResultValue(List<Result> results) { Result result = results.get(0); if (ResultType.DICTIONARY.matches(result.getResultType())) { Dictionary dictionary = dictionaryDAO.getDictionaryById(result.getValue()); if (dictionary != null) { return dictionary.getLocalizedName(); } } else if (ResultType.isMultiSelectVariant(result.getResultType())) { Dictionary dictionary = new Dictionary(); StringBuilder multiResult = new StringBuilder(); for (Result subResult : results) { dictionary.setId(subResult.getValue()); dictionaryDAO.getData(dictionary); if (dictionary.getId() != null) { multiResult.append(dictionary.getLocalizedName()); multiResult.append(", "); } } if (multiResult.length() > 0) { multiResult.setLength(multiResult.length() - 2); // remove last ", " } return multiResult.toString(); } else { String resultValue = GenericValidator.isBlankOrNull(result.getValue()) ? "" : result.getValue(); if (!GenericValidator.isBlankOrNull(resultValue) && result.getAnalysis().getTest().getUnitOfMeasure() != null) { resultValue += " " + result.getAnalysis().getTest().getUnitOfMeasure().getName(); } return resultValue; } return ""; }
@Override public void initializeReport(BaseActionForm dynaForm) { super.initializeReport(); errorFound = false; lowerDateRange = dynaForm.getString("lowerDateRange"); upperDateRange = dynaForm.getString("upperDateRange"); if (GenericValidator.isBlankOrNull(lowerDateRange)) { errorFound = true; ErrorMessages msgs = new ErrorMessages(); msgs.setMsgLine1(StringUtil.getMessageForKey("report.error.message.noPrintableItems")); errorMsgs.add(msgs); } if (GenericValidator.isBlankOrNull(upperDateRange)) { upperDateRange = lowerDateRange; } try { lowDate = DateUtil.convertStringDateToSqlDate(lowerDateRange); highDate = DateUtil.convertStringDateToSqlDate(upperDateRange); } catch (LIMSRuntimeException re) { errorFound = true; ErrorMessages msgs = new ErrorMessages(); msgs.setMsgLine1(StringUtil.getMessageForKey("report.error.message.date.format")); errorMsgs.add(msgs); } createReportParameters(); initializeReportItems(); setTestMapForAllTests(); setAnalysisForDateRange(); setTestAggregates(); }
public int compare(PatientSearchResults o1, PatientSearchResults o2) { if (o1.getLastName() == null) { return o2.getLastName() == null ? 0 : 1; } else if (o2.getLastName() == null) { return -1; } int lastNameResults = o1.getLastName().compareToIgnoreCase(o2.getLastName()); if (lastNameResults == 0) { if (GenericValidator.isBlankOrNull(o1.getFirstName()) && GenericValidator.isBlankOrNull(o2.getFirstName())) { return 0; } String oneName = (o1.getFirstName() == null) ? " " : o1.getFirstName(); String twoName = (o2.getFirstName() == null) ? " " : o2.getFirstName(); return oneName.compareToIgnoreCase(twoName); } else { return lastNameResults; } }
public static boolean validate( Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, ServletContext application) { String valueString = ValidatorUtils.getValueAsString(bean, field.getProperty()); String sProperty2 = ValidatorUtils.getValueAsString(bean, field.getVarValue("month")); String sProperty3 = ValidatorUtils.getValueAsString(bean, field.getVarValue("day")); if (((valueString == null) && (sProperty2 == null) && (sProperty3 == null)) || ((valueString.length() == 0) && (sProperty2.length() == 0) && (sProperty3.length() == 0))) { // errors.add(field.getKey(),Resources.getActionError(request, va, // field)); return true; } Integer year = null; Integer month = null; Integer day = null; try { year = new Integer(valueString); month = new Integer(sProperty2); day = new Integer(sProperty3); } catch (NumberFormatException e) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } if (!GenericValidator.isBlankOrNull(valueString)) { if (!Data.validDate(day, month, year) || year == null || month == null || day == null || year.intValue() < 1 || month.intValue() < 0 || day.intValue() < 1) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); } return false; } return true; }