Example usage for org.springframework.validation ValidationUtils rejectIfEmpty

List of usage examples for org.springframework.validation ValidationUtils rejectIfEmpty

Introduction

In this page you can find the example usage for org.springframework.validation ValidationUtils rejectIfEmpty.

Prototype

public static void rejectIfEmpty(Errors errors, String field, String errorCode) 

Source Link

Document

Reject the given field with the given error code if the value is empty.

Usage

From source file:io.onedecision.engine.decisions.model.dmn.validators.DefinitionsValidator.java

public void validate(Object obj, Errors e) {
    ValidationUtils.rejectIfEmpty(e, "name", "name.empty");
}

From source file:org.openmrs.module.dataimporttool.resources.DataImportToolValidator.java

public void validate(Object obj, Errors e) {

    ValidationUtils.rejectIfEmptyOrWhitespace(e, "matchFile", "matchFile.empty");
    ValidationUtils.rejectIfEmpty(e, "leftDbDriver", "leftDbDriver.empty");
    ValidationUtils.rejectIfEmpty(e, "rightDbDriver", "rightDbDriver.empty");
    ValidationUtils.rejectIfEmpty(e, "MatchLocation", "MatchLocation.empty");
    ValidationUtils.rejectIfEmpty(e, "rightDbLocation", "rightDbLocation.empty");
    ValidationUtils.rejectIfEmpty(e, "leftDbLocation", "leftDbLocation.empty");
    ValidationUtils.rejectIfEmpty(e, "leftDbName", "leftDbName.empty");
    ValidationUtils.rejectIfEmpty(e, "rightDbName", "rightDbName.empty");

    DataImportTool dit = (DataImportTool) obj;
    if (dit.getMatchFormat().compareToIgnoreCase("xls") != 0)
        e.rejectValue("matchFormat", "Match format must be xls");

}

From source file:org.ihtsdo.otf.refset.domain.MemberValidator.java

@Override
public void validate(Object m, Errors e) {

    ValidationUtils.rejectIfEmpty(e, "referencedComponentId", "Referenced component id is mandatory");
    //ValidationUtils.rejectIfEmpty(e, "effectiveTime", "Effective time can not be empty");
    ValidationUtils.rejectIfEmpty(e, "moduleId", "Module Id is Mandatory");
    ValidationUtils.rejectIfEmpty(e, "published", "Published flag is mandatory");
    ValidationUtils.rejectIfEmpty(e, "active", "Active Flag is mandatory");

}

From source file:org.ihtsdo.otf.refset.domain.RefsetValidator.java

@Override
public void validate(Object m, Errors e) {

    //ValidationUtils.rejectIfEmpty(e, "effectiveTime", "Effective time can not be empty");
    ValidationUtils.rejectIfEmpty(e, "moduleId", "Module Id is Mandatory");
    ValidationUtils.rejectIfEmpty(e, "typeId", "Refset type id is mandatory");
    ValidationUtils.rejectIfEmpty(e, "active", "Active Flag is mandatory");
    ValidationUtils.rejectIfEmpty(e, "componentTypeId", "Refset members type id is mandatory");
    ValidationUtils.rejectIfEmpty(e, "description", "Refset description is mandatory");
    ValidationUtils.rejectIfEmpty(e, "languageCode", "Refset language is mandatory");
    ValidationUtils.rejectIfEmpty(e, "published", "Indication of Refset is published or not is mandatory");

}

From source file:org.jasig.portlet.ClassifiedsPortlet.domain.SubmitAdFormValidator.java

public void validate(Object target, Errors errors) {

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "category", "required.category");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", "required.title");
    ValidationUtils.rejectIfEmpty(errors, "startDate", "required.startDate");
    ValidationUtils.rejectIfEmpty(errors, "endDate", "required.endDate");
    ValidationUtils.rejectIfEmpty(errors, "description", "required.description");

    Ad form = (Ad) target;//from  www.  j ava  2 s. c  om

    if (form.getPolicyAccepted() == false) {

        errors.rejectValue("policyAccepted", "required.policyAccepted");
    }

    if (form.getStartDate() != null && form.getEndDate() != null
            && !form.getStartDate().before(form.getEndDate())) {
        errors.rejectValue("startDate", "invalid.startDateAfterEndDate");
    }

    Calendar cal = Calendar.getInstance();
    Date today = new Date();

    cal.setTime(today);
    cal.add(Calendar.DATE, 60);
    Date maxStartDate = cal.getTime();

    if (form.getStartDate() != null && form.getStartDate().after(maxStartDate)) {
        errors.rejectValue("startDate", "invalid.startDatePastMaximumDays");
    }

    cal.setTime(today);
    cal.add(Calendar.DATE, 120);
    Date maxEndDate = cal.getTime();

    if (form.getEndDate() != null && form.getEndDate().after(maxEndDate)) {
        errors.rejectValue("startDate", "invalid.endDatePastMaximumDays");
    }

    if (form.getDescription().length() > 2056) {
        errors.rejectValue("description", "tolong.description");
    }
    ;

    if (form.getCategory() == null) {
        errors.rejectValue("category", "required.category");
    }
    ;

}

From source file:org.tonguetied.web.ChangePasswordFormValidator.java

public void validate(Object target, Errors errors) {
    ValidationUtils.rejectIfEmpty(errors, FIELD_NEW_PASSWORD, "error.password.required");
    validateNewPassword((ChangePasswordForm) target, errors);
}

From source file:com.pkrete.locationservice.admin.validator.ShelfValidator.java

@Override
public void validate(Object target, Errors errors) {
    super.validate(target, errors);

    ValidationUtils.rejectIfEmpty(errors, "locationCode", "error.shelf.location_code");

    Shelf shelf = (Shelf) target;//  ww w.ja v a 2s.c  om

    if (shelf.getCollection() == null) {
        // Collection can not be null
        errors.rejectValue("collection", "error.location.collection.null");
    } else if (shelf.getCollection().getOwner().getId() != shelf.getOwner().getId()) {
        // Collection and Library must have the same Owner
        errors.rejectValue("collection", "error.location.collection.invalid");
    }
}

From source file:com.pkrete.locationservice.admin.validator.SubjectMatterValidator.java

@Override
public void validate(Object target, Errors errors) {
    ValidationUtils.rejectIfEmpty(errors, "indexTerm", "error.subjectmatter.index_term");

    SubjectMatter subject = (SubjectMatter) target;

    if (subject.getIndexTerm().length() > 100) {
        errors.rejectValue("indexTerm", "error.subjectmatter.index_term.length");
    }/*from w w  w. j av a 2 s .c  o  m*/

    if (subject.getLanguage() == null) {
        errors.rejectValue("language", "error.subjectmatter.language");
    } else {
        if (subject.getOwner().getId() != subject.getLanguage().getOwner().getId()) {
            errors.rejectValue("language", "error.subjectmatter.language.owner");
        }
    }
}

From source file:org.opentides.web.validator.ImageValidator.java

@Override
public void validate(Object obj, Errors errors) {
    AjaxUpload ajaxUpload = (AjaxUpload) obj;
    MultipartFile attachment = ajaxUpload.getAttachment();
    ValidationUtils.rejectIfEmpty(errors, "attachment", "photo.image-required");
    if (attachment != null && !attachment.isEmpty()) {
        String contentType = attachment.getContentType().substring(0, 6);
        if (!"image/".equals(contentType)) {
            errors.rejectValue("attachment", "photo.invalid-file-type",
                    "Invalid file. Profile Image must be in PNG, JPEG, GIF or BMP format.");
        } else if (attachment.getSize() > 1024 * 1024 * 10) {
            errors.rejectValue("attachment", "photo.invalid-file-size",
                    "Invalid file. Maximum file size is 10 Megabytes");
        }/*  ww  w  . j a v a  2 s. c o  m*/
    }

}

From source file:ru.trett.cis.validators.AssetValidator.java

@Override
public void validate(Object o, Errors errors) {
    ValidationUtils.rejectIfEmpty(errors, "deviceModel.deviceType.type", "not.empty");
    ValidationUtils.rejectIfEmpty(errors, "deviceModel.deviceBrand.brand", "not.empty");
    ValidationUtils.rejectIfEmpty(errors, "deviceModel.model", "not.empty");

    Asset obj = (Asset) o;//from   www.j  av  a  2  s . c  o  m
    //if serial and a inventory number are not present do not check
    if (obj.getSerialNumber().length() == 0 && obj.getInventoryNumber().length() == 0)
        return;

    List<Asset> assets = inventoryService.getAssetsBySerialNumber(obj.getSerialNumber().toUpperCase());

    // if assets exists
    for (Asset asset : assets) {
        if (asset != null) {

            DeviceModel model = inventoryService.getModelByTypeAndBrandAndModel(
                    obj.getDeviceModel().getDeviceType().getType(),
                    obj.getDeviceModel().getDeviceBrand().getBrand(), obj.getDeviceModel().getModel());

            //return if device model are not the same
            if (!asset.getDeviceModel().equals(model))
                break;

            //if asset with given serial number is present but with another inventory number
            if (asset.getInventoryNumber().length() > 0
                    && !asset.getInventoryNumber().equals(obj.getInventoryNumber().toUpperCase())) {
                errors.rejectValue("inventoryNumber", "asset.wrong.inventory");
                break;
            }

            Invoice invoice = inventoryService.getLastInvoiceForAsset(asset);

            if (invoice == null)
                throw new RuntimeException("Invoice date error");

            if (invoice.getStatus() == Invoice.Status.DRAFT) {
                errors.rejectValue("serialNumber", "asset.block");
                break;
            }
        }
    }
}