Example usage for com.jgoodies.validation ValidationResult hasErrors

List of usage examples for com.jgoodies.validation ValidationResult hasErrors

Introduction

In this page you can find the example usage for com.jgoodies.validation ValidationResult hasErrors.

Prototype

public boolean hasErrors() 

Source Link

Document

Checks and answers whether this validation result contains a message of type ERROR .

Usage

From source file:org.archiviststoolkit.dialog.BatchLocationCreation.java

License:Open Source License

private void validateLocation() throws ValidationException {
    ValidationResult validationResult = validator.validate();
    if (validationResult.hasErrors()) {
        JGoodiesValidationUtils.showValidationMessage(this,
                "To save the record, please fix the following errors:", validationResult);
        throw new ValidationException("Invalid data");
    }/* www.  j  av a2s  .c o m*/
}

From source file:org.archiviststoolkit.editor.rde.RapidResourceComponentDataEntry.java

License:Open Source License

private boolean validateData() {
    ValidationResult validationResult = validator.validate();
    if (validationResult.hasErrors()) {
        JGoodiesValidationUtils.showValidationMessage(this,
                "To save the record, please fix the following errors:", validationResult);
        return false;
    }/*from   w  w w  .  ja v  a2 s.  c o  m*/
    if (validationResult.hasWarnings()) {
        JGoodiesValidationUtils.showValidationMessage(this, "Note: some fields are invalid.", validationResult);
    }
    return true;

}

From source file:org.archiviststoolkit.editor.rde.RapidResourceComponentDataEntry2.java

License:Open Source License

private boolean validateData() {
    // generate resource components
    try {/*from  w w  w. j  av  a2  s  .c  o m*/
        resourceComponent = generateComponentRecord();
        ATValidator validator = null;

        // validate any instances
        Set<ArchDescriptionInstances> instances = resourceComponent.getInstances();
        for (ArchDescriptionInstances adi : instances) {
            if (adi instanceof ArchDescriptionAnalogInstances) {
                validator = ValidatorFactory.getInstance().getValidator((ArchDescriptionAnalogInstances) adi);
            } else if (adi instanceof ArchDescriptionDigitalInstances) {
                DigitalObjects digitalObject = ((ArchDescriptionDigitalInstances) adi).getDigitalObject();
                validator = ValidatorFactory.getInstance().getValidator(digitalObject);
            } else {
                continue; // should never get here
            }

            ValidationResult validationResult = validator.validate();
            if (validationResult.hasErrors()) {
                JGoodiesValidationUtils.showValidationMessage(this,
                        "To save the record, please fix the following errors:", validationResult);
                return false;
            }

            if (validationResult.hasWarnings()) {
                JGoodiesValidationUtils.showValidationMessage(this, "Note: some fields are invalid.",
                        validationResult);
            }
        }

        // validate any repeating data
        Set<ArchDescriptionRepeatingData> repeatingData = resourceComponent.getRepeatingData();
        for (ArchDescriptionRepeatingData adrd : repeatingData) {
            if (adrd instanceof ArchDescriptionNotes) {
                validator = ValidatorFactory.getInstance().getValidator((ArchDescriptionNotes) adrd);
            } else {
                continue; // only validating ArchDescription Notes for now
            }

            ValidationResult validationResult = validator.validate();
            if (validationResult.hasErrors()) {
                JGoodiesValidationUtils.showValidationMessage(this,
                        "To save the record, please fix the following errors:", validationResult);
                return false;
            }

            if (validationResult.hasWarnings()) {
                JGoodiesValidationUtils.showValidationMessage(this, "Note: some fields are invalid.",
                        validationResult);
            }
        }

        // get resource component validator
        validator = ValidatorFactory.getInstance().getValidator(resourceComponent);

        ValidationResult validationResult = validator.validate();
        if (validationResult.hasErrors()) {
            JGoodiesValidationUtils.showValidationMessage(this,
                    "To save the record, please fix the following errors:", validationResult);
            return false;
        }

        if (validationResult.hasWarnings()) {
            JGoodiesValidationUtils.showValidationMessage(this, "Note: some fields are invalid.",
                    validationResult);
        }
    } catch (RDEPopulateException e) {
        resourceComponent = null;
        return false;
    }

    return true;
}

From source file:org.archiviststoolkit.mydomain.DomainAccessObjectImpl.java

License:Open Source License

/**
 * Find instances through a named query without parameters.
 *
 * @param propertyName the name of the property
 * @param oldValue     the old value of the property
 * @param newValue     the new value of the property
 * @return the number of records updated
 * @throws LookupException if we failed to execute the query
 *///  w w w  . j  av  a 2 s.com

public int updateTextField(String propertyName, String oldValue, String newValue,
        InfiniteProgressPanel progressPanel)
        throws LookupException, IllegalAccessException, InvocationTargetException, ValidationException {
    Session session = SessionFactory.getInstance().openSession();
    Transaction tx = session.beginTransaction();
    ATValidator validator;
    ValidationResult validationResult;

    Collection records = session.createCriteria(this.getPersistentClass())
            .add(Expression.eq(propertyName, oldValue)).list();
    int updatedEntities = records.size();
    int count = 1;
    int textDepth = progressPanel.getTextDepth();
    String message;
    for (Object record : records) {
        message = count++ + " of " + updatedEntities;
        progressPanel.setTextLine(message, textDepth + 1);
        BeanUtils.setProperty(record, propertyName, newValue);
        validator = ValidatorFactory.getInstance().getValidator((DomainObject) record);
        if (validator != null) {
            validationResult = validator.validate();
            if (validationResult.hasErrors()) {
                // we have an error so roll back the transaction and throw an error
                tx.rollback();
                session.close();
                throw new ValidationException("For the record named \"" + record.toString() + "\"\n"
                        + validationResult.getMessagesText());
            }
        }

        session.update(record);
    }
    tx.commit();
    session.close();
    return updatedEntities;
}

From source file:org.archiviststoolkit.mydomain.DomainImportController.java

License:Open Source License

/**
 * Import and duplicate.// www . ja  v  a 2 s.  co  m
 *
 * @param collection the collection to inject into the db
 */

public void domainImport(Collection<DomainObject> collection, Component parent,
        InfiniteProgressPanel progressPanel) {
    DomainAccessObject access = null;

    // see wheter to clear the total records
    if (clearTotalRecords) {
        totalRecords = 0;
    }

    ATValidator validator;
    ValidationResult validationResult;
    boolean recordValid;

    for (DomainObject instance : collection) {
        // check to see if this operation was cancelled if so return
        if (progressPanel.isProcessCancelled()) {
            this.addLineToImportLog("Import of record(s) cancelled by user");
            return;
        }

        try {
            if (clearTotalRecords) { // since total records was clear then we need to increment
                totalRecords++;
            }
            recordValid = true;
            progressPanel.setTextLine("Saving record " + totalRecords, 2);
            access = DomainAccessObjectFactory.getInstance().getDomainAccessObject(instance.getClass());
            validator = ValidatorFactory.getInstance().getValidator(instance);
            if (validator != null) {
                validationResult = validator.validate();
                if (validationResult.hasErrors()) {
                    errors = getErrors() + 1;
                    this.addLineToImportLog("Invalid Record number " + totalRecords + "\n"
                            + validationResult.getMessagesText());
                    recordValid = false;
                }
            }
            if (recordValid || instance instanceof org.archiviststoolkit.model.Resources) {
                access.add(instance);
                insertedRecords++;
            }
        } catch (PersistenceException e) {
            errors = getErrors() + 1;
            if (e.getCause() instanceof ConstraintViolationException) {
                this.addLineToImportLog("Error saving, duplicate record: " + instance);
                logger.error(e.getMessage());
            } else {
                this.addLineToImportLog("Error saving record " + totalRecords + ": " + instance + "\n"
                        + e.getCause().getCause() + "\n");
                logger.error(e.getMessage());
            }
        }
    }
}

From source file:org.archiviststoolkit.mydomain.DomainObject.java

License:Open Source License

public boolean validateAndDisplayDialog(EventObject ae) {

    ATValidator validator = ValidatorFactory.getInstance().getValidator(this);
    if (validator == null) {
        //nothing registered so just return true
        return true;
    } else {/*  ww  w . j a  v  a 2s  .c o m*/
        ValidationResult validationResult = validator.validate();
        if (validationResult.hasErrors()) {
            JGoodiesValidationUtils.showValidationMessage(ae,
                    "To save the record, please fix the following errors:", validationResult);
            return false;
        }
        if (validationResult.hasWarnings()) {
            JGoodiesValidationUtils.showValidationMessage(ae, "Note: some fields are invalid.",
                    validationResult);
        }
        return true;
    }
}

From source file:org.archiviststoolkit.mydomain.SubjectsDAO.java

License:Open Source License

public Subjects lookupSubject(String subjectValue, String subjectTermType, String subjectSource, boolean create)
        throws PersistenceException, ValidationException, UnknownLookupListException {

    if (subjectValue.length() == 0) {
        //do not add blank subjects
        return null;
    } else {// w ww.  ja  v  a 2  s.c o m
        Session session = SessionFactory.getInstance().openSession();
        Subjects subject = (Subjects) session.createCriteria(Subjects.class)
                .add(Expression.eq(Subjects.PROPERTYNAME_SUBJECT_TERM, subjectValue))
                .add(Expression.eq(Subjects.PROPERTYNAME_SUBJECT_TERM_TYPE, subjectTermType))
                .add(Expression.eq(Subjects.PROPERTYNAME_SUBJECT_SOURCE, subjectSource)).uniqueResult();
        session.close();
        if (subject != null) {
            return subject;
        } else if (create) {
            subject = new Subjects();
            subject.setSubjectTerm(subjectValue);
            subject.setSubjectTermType(subjectTermType);
            subject.setSubjectSource(subjectSource);
            ATValidator validator = ValidatorFactory.getInstance().getValidator(subject);
            ValidationResult validationResult = validator.validate();
            if (validationResult.hasErrors()) {
                throw new ValidationException(validationResult.getMessagesText());
            }
            this.add(subject);
            //make sure that subject term type and source have the values added to the lookup lists
            ATFieldInfo fieldInfo = ATFieldInfo
                    .getFieldInfo(Subjects.class.getName() + "." + Subjects.PROPERTYNAME_SUBJECT_SOURCE);
            LookupListUtils.addItemToList(fieldInfo.getLookupList(), subjectSource);
            fieldInfo = ATFieldInfo
                    .getFieldInfo(Subjects.class.getName() + "." + Subjects.PROPERTYNAME_SUBJECT_TERM_TYPE);
            LookupListUtils.addItemToList(fieldInfo.getLookupList(), subjectTermType);
            Subjects.addSubjectToLookupList(subject);
            return subject;
        } else {
            return null;
        }

    }
}

From source file:org.archiviststoolkit.plugin.ATPluginUtils.java

License:Open Source License

/**
 * Method to valid a AT record. Calling this ensures that no invalid
 * records are saved to the database/*from   w  w  w.  j a  va 2 s .  co  m*/
 *
 * @param component UI component that is requesting validation of the record
 * @param record The AT record to validate
 * @return true if the record valide, false otherwise
 */
public static boolean validateRecord(Component component, DomainObject record) {
    ATValidator validator = ValidatorFactory.getInstance().getValidator(record);
    if (validator == null) {
        //nothing registered so just return true
        return true;
    } else {
        ValidationResult validationResult = validator.validate();
        if (validationResult.hasErrors()) {
            JGoodiesValidationUtils.showValidationMessage(component,
                    "To save the record, please fix the following errors:", validationResult);
            return false;
        }
        if (validationResult.hasWarnings()) {
            JGoodiesValidationUtils.showValidationMessage(component, "Note: some fields are invalid.",
                    validationResult);
        }
        return true;
    }
}

From source file:org.openthinclient.console.ui.DirObjectEditPanel.java

License:Open Source License

/**
 * @param okButton//from www  .  j a va  2 s  . c o m
 */
private void doValidate(final JButton okButton) {
    final ValidationResult validate = validator.validate();
    okButton.setEnabled(!validate.hasErrors());
    DirObjectEditPanel.this.revalidate();
    vrm.setResult(validate);
}

From source file:org.openthinclient.console.wizards.newdirobject.ConfigurationPanel.java

License:Open Source License

public boolean isValid() {
    final ValidationResult validate = validator.validate();
    if (!validate.hasErrors()) {
        if (validate.hasMessages()) {
            final PropertyValidationMessage m = (PropertyValidationMessage) validate.getMessages().get(0);
            wd.putProperty("WizardPanel_errorMessage", m.formattedText()); //$NON-NLS-1$
        } else/*  w w w.j a v  a2  s.  c  om*/
            wd.putProperty("WizardPanel_errorMessage", null); //$NON-NLS-1$
        return true;
    } else {
        final PropertyValidationMessage m = (PropertyValidationMessage) validate.getErrors().iterator().next();
        wd.putProperty("WizardPanel_errorMessage", m.formattedText()); //$NON-NLS-1$
        return false;
    }
}