List of usage examples for com.jgoodies.validation ValidationResult getMessagesText
public String getMessagesText()
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 *//*from w ww .j a va2s. co m*/ 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.// w w w.j a v a 2s . c o 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.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 {/*from www . j a v a2 s . c om*/ 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; } } }