diff --git a/.gitignore b/.gitignore index 8d8371b0..fa0fb6d8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ target .springBeans geo_data .extract +*.versionsBackup + diff --git a/biopax-validator-client/pom.xml b/biopax-validator-client/pom.xml index 3f202cd5..e38fa7ad 100644 --- a/biopax-validator-client/pom.xml +++ b/biopax-validator-client/pom.xml @@ -4,7 +4,7 @@ org.biopax.validator parent - 4.0.0-SNAPSHOT + 4.0.0 biopax-validator-client @@ -45,8 +45,9 @@ false org.biopax.validator.jaxb true - ${basedir}/src/main/resources - + + src/main/resources/validator-response-2.0.xsd + diff --git a/biopax-validator-client/src/main/resources/validator-response-2.0.xsd b/biopax-validator-client/src/main/resources/validator-response-2.0.xsd index 9dd1d9b7..9bc73a6b 100644 --- a/biopax-validator-client/src/main/resources/validator-response-2.0.xsd +++ b/biopax-validator-client/src/main/resources/validator-response-2.0.xsd @@ -1,27 +1,19 @@ - + - + - - - + - - - - - - - - - + + + - + @@ -31,22 +23,36 @@ - + - + + + - - - + + + + + + + + + - + + + + @@ -55,6 +61,9 @@ + + + @@ -63,4 +72,3 @@ - diff --git a/biopax-validator-web/pom.xml b/biopax-validator-web/pom.xml index a6b6d805..8c544674 100644 --- a/biopax-validator-web/pom.xml +++ b/biopax-validator-web/pom.xml @@ -2,7 +2,7 @@ parent org.biopax.validator - 4.0.0-SNAPSHOT + 4.0.0 4.0.0 diff --git a/biopax-validator/pom.xml b/biopax-validator/pom.xml index 3df9741b..3fc5c386 100644 --- a/biopax-validator/pom.xml +++ b/biopax-validator/pom.xml @@ -2,7 +2,7 @@ parent org.biopax.validator - 4.0.0-SNAPSHOT + 4.0.0 4.0.0 diff --git a/biopax-validator/src/main/java/org/biopax/validator/impl/AbstractCvRule.java b/biopax-validator/src/main/java/org/biopax/validator/impl/AbstractCvRule.java index 945dce35..42668810 100644 --- a/biopax-validator/src/main/java/org/biopax/validator/impl/AbstractCvRule.java +++ b/biopax-validator/src/main/java/org/biopax/validator/impl/AbstractCvRule.java @@ -1,9 +1,5 @@ package org.biopax.validator.impl; -import java.util.*; - -import javax.annotation.PostConstruct; - import org.biopax.paxtools.controller.PropertyEditor; import org.biopax.paxtools.model.BioPAXElement; import org.biopax.validator.api.AbstractRule; @@ -12,124 +8,129 @@ import org.biopax.validator.api.CvValidator; import org.springframework.beans.factory.annotation.Autowired; +import javax.annotation.PostConstruct; +import java.util.HashSet; +import java.util.Set; + /** * An abstract class for CV terms checks. - * - * @author rodche * * @param property domain + * @author rodche */ public abstract class AbstractCvRule extends AbstractRule implements CvRule { - - @Autowired - protected CvValidator ontologyManager; - - protected final Class domain; - protected final String property; // helps validate generic ControlledVocabulary instances - protected final Set restrictions; - private Set validTerms; - protected PropertyEditor editor; - - /** - * Constructor. - * - * @param domain a BioPAX class for which the CV terms restrictions apply - * @param property the name of the BioPAX property to get controlled vocabularies or null - * @param restrictions a list of beans, each defining names (a subtree of an ontology) that - * is either to include or exclude (when 'not' flag is set) from the valid names set. - */ - public AbstractCvRule(Class domain, String property, CvRestriction... restrictions) - { - this.domain = domain; - this.property = property; - this.restrictions = new HashSet(restrictions.length); - for(CvRestriction c: restrictions) { - this.restrictions.add(c); - } + + @Autowired + protected CvValidator ontologyManager; + + protected final Class domain; + protected final String property; // helps validate generic ControlledVocabulary instances + protected final Set restrictions; + private Set validTerms; + protected PropertyEditor editor; + + /** + * Constructor. + * + * @param domain a BioPAX class for which the CV terms restrictions apply + * @param property the name of the BioPAX property to get controlled vocabularies or null + * @param restrictions a list of beans, each defining names (a subtree of an ontology) that + * is either to include or exclude (when 'not' flag is set) from the valid names set. + */ + public AbstractCvRule(Class domain, String property, CvRestriction... restrictions) { + this.domain = domain; + this.property = property; + this.restrictions = new HashSet(restrictions.length); + for (CvRestriction c : restrictions) { + this.restrictions.add(c); + } + } + + @PostConstruct + public void init() { + if (ontologyManager != null) { + setValidTerms(ontologyManager.getValidTermNames(this)); + } else { + throw new IllegalStateException("ontologyManager is NULL!"); } - - @PostConstruct - public void init() { - if(ontologyManager != null) { - setValidTerms(ontologyManager.getValidTermNames(this)); - } else { - throw new IllegalStateException("ontologyManager is NULL!"); - } - }; - - - public boolean canCheck(Object thing) { - return domain.isInstance(thing); - } - - /* (non-Javadoc) - * @see org.biopax.validator.impl.CvRule#getValidTerms() - */ - public Set getValidTerms() { - return validTerms; - } - - /* (non-Javadoc) - * @see org.biopax.validator.impl.CvRule#setValidTerms(java.util.Set) - */ - public void setValidTerms(Set validTerms) { - this.validTerms = validTerms; - } - - // for unit testing - - /* (non-Javadoc) - * @see org.biopax.validator.impl.CvRule#getRestrictions() - */ - public Set getRestrictions() { - return restrictions; - } - - /* (non-Javadoc) - * @see org.biopax.validator.impl.CvRule#getDomain() - */ - public Class getDomain() { - return domain; - } - - /* (non-Javadoc) - * @see org.biopax.validator.impl.CvRule#getProperty() - */ - public String getProperty() { - return property; - } - - /** - * Gets the internal BiopaxOntologyManager instance - * @return - */ - public CvValidator getBiopaxOntologyManager() { - return ontologyManager; - } - - /** - * Gets the corresponding CV property editor. - * Returns null if either the 'domain' itself is of CV type - * or the 'property' is null. - * - * @return - */ - public PropertyEditor getEditor() { - return editor; - } - - /** - * OntologyAccess IDs used to check this CV rule. - * These can be extracted from the CV rescrictions - * used to define the rule. - * (other ontologies are not used). - * - * @return - */ - protected Set getOntologyIDs() { - Set ids = new HashSet(); - for(CvRestriction restriction : restrictions) - ids.add(restriction.getOntologyId()); - return ids; - } + } + + ; + + + public boolean canCheck(Object thing) { + return domain.isInstance(thing); + } + + /* (non-Javadoc) + * @see org.biopax.validator.impl.CvRule#getValidTerms() + */ + public Set getValidTerms() { + return validTerms; + } + + /* (non-Javadoc) + * @see org.biopax.validator.impl.CvRule#setValidTerms(java.util.Set) + */ + public void setValidTerms(Set validTerms) { + this.validTerms = validTerms; + } + + // for unit testing + + /* (non-Javadoc) + * @see org.biopax.validator.impl.CvRule#getRestrictions() + */ + public Set getRestrictions() { + return restrictions; + } + + /* (non-Javadoc) + * @see org.biopax.validator.impl.CvRule#getDomain() + */ + public Class getDomain() { + return domain; + } + + /* (non-Javadoc) + * @see org.biopax.validator.impl.CvRule#getProperty() + */ + public String getProperty() { + return property; + } + + /** + * Gets the internal BiopaxOntologyManager instance + * + * @return ontology manager + */ + public CvValidator getBiopaxOntologyManager() { + return ontologyManager; + } + + /** + * Gets the corresponding CV property editor. + * Returns null if either the 'domain' itself is of CV type + * or the 'property' is null. + * + * @return biopax property editor + */ + public PropertyEditor getEditor() { + return editor; + } + + /** + * OntologyAccess IDs used to check this CV rule. + * These can be extracted from the CV restrictions + * used to define the rule. + * (other ontologies are not used). + * + * @return ontology IDs, such as e.g. 'MI', 'GO' + */ + protected Set getOntologyIDs() { + Set ids = new HashSet(); + for (CvRestriction restriction : restrictions) + ids.add(restriction.getOntologyId()); + return ids; + } } diff --git a/biopax-validator/src/main/java/org/biopax/validator/impl/CvTermsRule.java b/biopax-validator/src/main/java/org/biopax/validator/impl/CvTermsRule.java index 09872e8b..006dfa2d 100644 --- a/biopax-validator/src/main/java/org/biopax/validator/impl/CvTermsRule.java +++ b/biopax-validator/src/main/java/org/biopax/validator/impl/CvTermsRule.java @@ -30,9 +30,9 @@ public abstract class CvTermsRule * * TODO a feature: to allow using a properties path in the 'property' parameter, like "modificationFeature/modificationType" * - * @param domain - * @param property - * @param restrictions + * @param domain biopax property domain (object) + * @param property biopax property name + * @param restrictions restrictions on the controlled vocabulary (ontology) terms, given biopax property context */ public CvTermsRule(Class domain, String property, CvRestriction... restrictions) { diff --git a/biopax-validator/src/main/java/org/biopax/validator/impl/ExceptionsAspect.java b/biopax-validator/src/main/java/org/biopax/validator/impl/ExceptionsAspect.java index 94e4167d..8e6d3b20 100644 --- a/biopax-validator/src/main/java/org/biopax/validator/impl/ExceptionsAspect.java +++ b/biopax-validator/src/main/java/org/biopax/validator/impl/ExceptionsAspect.java @@ -37,7 +37,8 @@ public class ExceptionsAspect extends AbstractAspect { * with the corresponding validation result * (this is the earliest possibility to do so)! * - * @param jp + * @param jp (AspectJ) joint point + * @param model biopax model */ @Around("execution(void org.biopax.paxtools.io.SimpleIOHandler.createAndBind(*)) " + "&& args(model)") diff --git a/biopax-validator/src/main/java/org/biopax/validator/rules/UnificationXrefLimitedRule.java b/biopax-validator/src/main/java/org/biopax/validator/rules/UnificationXrefLimitedRule.java index b960c65e..b2a341d6 100644 --- a/biopax-validator/src/main/java/org/biopax/validator/rules/UnificationXrefLimitedRule.java +++ b/biopax-validator/src/main/java/org/biopax/validator/rules/UnificationXrefLimitedRule.java @@ -4,41 +4,19 @@ * */ -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - import org.biopax.paxtools.model.BioPAXElement; -import org.biopax.paxtools.model.level3.BioSource; -import org.biopax.paxtools.model.level3.CellVocabulary; -import org.biopax.paxtools.model.level3.CellularLocationVocabulary; -import org.biopax.paxtools.model.level3.Dna; -import org.biopax.paxtools.model.level3.DnaReference; -import org.biopax.paxtools.model.level3.EvidenceCodeVocabulary; -import org.biopax.paxtools.model.level3.ExperimentalFormVocabulary; -import org.biopax.paxtools.model.level3.Interaction; -import org.biopax.paxtools.model.level3.InteractionVocabulary; -import org.biopax.paxtools.model.level3.PhenotypeVocabulary; -import org.biopax.paxtools.model.level3.PhysicalEntity; -import org.biopax.paxtools.model.level3.ProteinReference; -import org.biopax.paxtools.model.level3.Provenance; -import org.biopax.paxtools.model.level3.RelationshipTypeVocabulary; -import org.biopax.paxtools.model.level3.Rna; -import org.biopax.paxtools.model.level3.RnaReference; -import org.biopax.paxtools.model.level3.SequenceModificationVocabulary; -import org.biopax.paxtools.model.level3.SequenceRegionVocabulary; -import org.biopax.paxtools.model.level3.SmallMolecule; -import org.biopax.paxtools.model.level3.SmallMoleculeReference; -import org.biopax.paxtools.model.level3.TissueVocabulary; -import org.biopax.paxtools.model.level3.UnificationXref; -import org.biopax.paxtools.model.level3.XReferrable; +import org.biopax.paxtools.model.level3.*; import org.biopax.validator.api.AbstractRule; import org.biopax.validator.api.beans.Validation; import org.biopax.validator.utils.XrefHelper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + /** - * UnificationXref applicability rule + * UnificationXref applicability rule * (BioPAX class - allowed/denied unification xref db names) * * @author rodche @@ -46,115 +24,114 @@ @Component public class UnificationXrefLimitedRule extends AbstractRule { - private static final Map, Set> allow = - new ConcurrentHashMap, Set>(); - private static final Map, Set> deny = - new ConcurrentHashMap, Set>(); - - static { - // allow ONLY listed db names (synonyms will be considered too) for member UnificationXrefs of: - allow.put(BioSource.class, new HashSet(Arrays.asList("taxonomy"))); - allow.put(Provenance.class, new HashSet(Arrays.asList("miriam"))); - allow.put(CellVocabulary.class, new HashSet(Arrays.asList("cl"))); - allow.put(TissueVocabulary.class, new HashSet(Arrays.asList("bto"))); - allow.put(CellularLocationVocabulary.class, new HashSet(Arrays.asList("go"))); - allow.put(EvidenceCodeVocabulary.class, new HashSet(Arrays.asList("mi"))); - allow.put(ExperimentalFormVocabulary.class, new HashSet(Arrays.asList("mi"))); - allow.put(InteractionVocabulary.class, new HashSet(Arrays.asList("mi"))); - allow.put(SequenceModificationVocabulary.class, new HashSet(Arrays.asList("so","mod"))); - allow.put(PhenotypeVocabulary.class, new HashSet(Arrays.asList("pato"))); - allow.put(RelationshipTypeVocabulary.class, new HashSet(Arrays.asList("mi"))); - allow.put(SequenceRegionVocabulary.class, new HashSet(Arrays.asList("so"))); - - // not recommended xref.db names (and all synonyms) for UnificationXrefs of - deny.put(Dna.class, new HashSet(Arrays.asList("uniprot","pubmed"))); - deny.put(Rna.class, new HashSet(Arrays.asList("uniprot"))); - deny.put(DnaReference.class, new HashSet(Arrays.asList("uniprot","pubmed"))); - deny.put(RnaReference.class, new HashSet(Arrays.asList("uniprot"))); - deny.put(SmallMoleculeReference.class, new HashSet(Arrays.asList("uniprot"))); - deny.put(SmallMolecule.class, new HashSet(Arrays.asList("uniprot"))); - deny.put(PhysicalEntity.class, new HashSet(Arrays.asList("go"))); - deny.put(ProteinReference.class, new HashSet(Arrays.asList("OMIM","Entrez Gene"))); - deny.put(Interaction.class, new HashSet(Arrays.asList("mi"))); + private static final Map, Set> allow = + new ConcurrentHashMap, Set>(); + private static final Map, Set> deny = + new ConcurrentHashMap, Set>(); + + static { + // allow ONLY listed db names (synonyms will be considered too) for member UnificationXrefs of: + allow.put(BioSource.class, new HashSet(Arrays.asList("taxonomy"))); + allow.put(Provenance.class, new HashSet(Arrays.asList("miriam"))); + allow.put(CellVocabulary.class, new HashSet(Arrays.asList("cl"))); + allow.put(TissueVocabulary.class, new HashSet(Arrays.asList("bto"))); + allow.put(CellularLocationVocabulary.class, new HashSet(Arrays.asList("go"))); + allow.put(EvidenceCodeVocabulary.class, new HashSet(Arrays.asList("mi"))); + allow.put(ExperimentalFormVocabulary.class, new HashSet(Arrays.asList("mi"))); + allow.put(InteractionVocabulary.class, new HashSet(Arrays.asList("mi"))); + allow.put(SequenceModificationVocabulary.class, new HashSet(Arrays.asList("so", "mod"))); + allow.put(PhenotypeVocabulary.class, new HashSet(Arrays.asList("pato"))); + allow.put(RelationshipTypeVocabulary.class, new HashSet(Arrays.asList("mi"))); + allow.put(SequenceRegionVocabulary.class, new HashSet(Arrays.asList("so"))); + + // not recommended xref.db names (and all synonyms) for UnificationXrefs of + deny.put(Dna.class, new HashSet(Arrays.asList("uniprot", "pubmed"))); + deny.put(Rna.class, new HashSet(Arrays.asList("uniprot"))); + deny.put(DnaReference.class, new HashSet(Arrays.asList("uniprot", "pubmed"))); + deny.put(RnaReference.class, new HashSet(Arrays.asList("uniprot"))); + deny.put(SmallMoleculeReference.class, new HashSet(Arrays.asList("uniprot"))); + deny.put(SmallMolecule.class, new HashSet(Arrays.asList("uniprot"))); + deny.put(PhysicalEntity.class, new HashSet(Arrays.asList("go"))); + deny.put(ProteinReference.class, new HashSet(Arrays.asList("OMIM", "Entrez Gene"))); + deny.put(Interaction.class, new HashSet(Arrays.asList("mi"))); + } + + private XrefHelper helper; + + private boolean ready = false; + + // to init on the first check(..) call + void initInternalMaps() { + if (!ready) { + for (Class clazz : allow.keySet()) { + final Set a = allow.get(clazz); + for (String db : new HashSet(a)) { + Collection synonymsOfDb = helper.getSynonymsForDbName(db); + a.addAll(synonymsOfDb); + } + } + + for (Class clazz : deny.keySet()) { + final Set a = deny.get(clazz); + for (String db : new HashSet(a)) { + Collection synonymsOfDb = helper.getSynonymsForDbName(db); + a.addAll(synonymsOfDb); + } + } + + ready = true; } - - private XrefHelper helper; - - private boolean ready = false; - - // to init on the first check(..) call - void initInternalMaps() { - if(!ready) { - for (Class clazz : allow.keySet()) { - final Set a = allow.get(clazz); - for(String db : new HashSet(a)) { - Collection synonymsOfDb = helper.getSynonymsForDbName(db); - a.addAll(synonymsOfDb); - } - } - - for (Class clazz : deny.keySet()) { - final Set a = deny.get(clazz); - for(String db : new HashSet(a)) { - Collection synonymsOfDb = helper.getSynonymsForDbName(db); - a.addAll(synonymsOfDb); - } - } - - ready = true; - } + } + + + /* + * Constructor requires the two sets to be defined in + * the Spring application context. + * + * @param xrefHelper utils + */ + @Autowired + public UnificationXrefLimitedRule(XrefHelper xrefHelper) { + helper = xrefHelper; + } + + + public boolean canCheck(Object thing) { + return thing instanceof UnificationXref; + } + + public void check(final Validation validation, UnificationXref x) { + if (!ready) + initInternalMaps(); + + if (x.getDb() == null + || helper.getPrimaryDbName(x.getDb()) == null) { + // ignore for unknown databases (another rule checks) + return; } - - - /** - * Constructor requires the two sets to be defined in - * the Spring application context. - * - * @param xrefHelper - */ - @Autowired - public UnificationXrefLimitedRule (XrefHelper xrefHelper) { - helper = xrefHelper; + + // fix case sensitivity + final String xdb = helper.dbName(x.getDb()); + + // check constrains for each element containing this unification xref + for (XReferrable bpe : x.getXrefOf()) { + for (Class c : allow.keySet()) { + if (c.isInstance(bpe)) { + if (!allow.get(c).contains(xdb)) { + error(validation, x, "not.allowed.xref", false, x.getDb(), + bpe, c.getSimpleName(), allow.get(c).toString()); + } + } + } + for (Class c : deny.keySet()) { + if (c.isInstance(bpe)) { + if (deny.get(c).contains(xdb)) { + error(validation, x, "denied.xref", false, x.getDb(), + bpe, c.getSimpleName(), deny.get(c).toString()); + } + } + } } - - - public boolean canCheck(Object thing) { - return thing instanceof UnificationXref; - } - - public void check(final Validation validation, UnificationXref x) { - if(!ready) - initInternalMaps(); - - if (x.getDb() == null - || helper.getPrimaryDbName(x.getDb())==null) - { - // ignore for unknown databases (another rule checks) - return; - } - - // fix case sensitivity - final String xdb = helper.dbName(x.getDb()); - - // check constrains for each element containing this unification xref - for (XReferrable bpe : x.getXrefOf()) { - for (Class c : allow.keySet()) { - if (c.isInstance(bpe)) { - if (!allow.get(c).contains(xdb)) { - error(validation, x, "not.allowed.xref", false, x.getDb(), - bpe, c.getSimpleName(), allow.get(c).toString()); - } - } - } - for (Class c : deny.keySet()) { - if (c.isInstance(bpe)) { - if (deny.get(c).contains(xdb)) { - error(validation, x, "denied.xref", false, x.getDb(), - bpe, c.getSimpleName(), deny.get(c).toString()); - } - } - } - } - } + } } diff --git a/biopax-validator/src/main/java/org/biopax/validator/utils/Cluster.java b/biopax-validator/src/main/java/org/biopax/validator/utils/Cluster.java index aa5cf850..8c49aee6 100644 --- a/biopax-validator/src/main/java/org/biopax/validator/utils/Cluster.java +++ b/biopax-validator/src/main/java/org/biopax/validator/utils/Cluster.java @@ -8,14 +8,13 @@ public abstract class Cluster { * Implemented in concrete subclasses. * Must be "symmetric"; may be "transitive" or not (you decide) - * - * @param a - * @param b + * @param a an object + * @param b another object of the same type * @return true/false */ public abstract boolean match(T a, T b); - - + /** * Puts elements into sets of "similar" ones. * Every object belongs to exactly one cluster. @@ -29,9 +28,9 @@ public abstract class Cluster { * * @see #match(Object, Object) * - * @param elements - * @param clusterMaxSize - * @return + * @param elements objects + * @param clusterMaxSize max. size of a cluster + * @return groups of objects */ public final Set> cluster(Collection elements, int clusterMaxSize) { Set> clusters = new HashSet>(); diff --git a/biopax-validator/src/main/java/org/biopax/validator/utils/XrefHelper.java b/biopax-validator/src/main/java/org/biopax/validator/utils/XrefHelper.java index 71c89e80..ea714237 100644 --- a/biopax-validator/src/main/java/org/biopax/validator/utils/XrefHelper.java +++ b/biopax-validator/src/main/java/org/biopax/validator/utils/XrefHelper.java @@ -194,8 +194,8 @@ private boolean xcheck() { /** * Removes tail spaces and converts to upper case * - * @param name - * @return + * @param name original name + * @return normalized name */ public String dbName(String name) { return name.trim().toUpperCase(); @@ -230,8 +230,8 @@ private List getSynonymsForName(String name, CompositeCollection * Gets the primary name for the DB. * It returns NULL for "unknown" database name. * - * @param name case insensitive - * @return + * @param name case insensitive name (of a bio ID type/resource) name + * @return preferred name */ public String getPrimaryDbName(String name) { List names = getSynonymsForDbName(name); @@ -297,7 +297,7 @@ public boolean isSynonyms(String db1, String db2) { * otherwise, using MI or Miriam, * cannot be resolved. * - * @return + * @return name variants */ Set getUnofficialDbNames() { return unofficialDbNames; @@ -311,7 +311,7 @@ Set getUnofficialDbNames() { * otherwise, using MI or Miriam, cannot be resolved. * * @param db case insensitive - * @return + * @return true or false */ public boolean isUnofficialOrMisspelledDbName(final String db) { return getUnofficialDbNames().contains(dbName(db)); diff --git a/distr/pom.xml b/distr/pom.xml index 80d3d6c3..714b393e 100644 --- a/distr/pom.xml +++ b/distr/pom.xml @@ -2,7 +2,7 @@ parent org.biopax.validator - 4.0.0-SNAPSHOT + 4.0.0 4.0.0 diff --git a/obo-fetcher/pom.xml b/obo-fetcher/pom.xml index 0f6f5d45..1ee469c9 100644 --- a/obo-fetcher/pom.xml +++ b/obo-fetcher/pom.xml @@ -6,7 +6,7 @@ parent org.biopax.validator - 4.0.0-SNAPSHOT + 4.0.0 Ontologies Access diff --git a/pom.xml b/pom.xml index 3780e6b9..277faa81 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.biopax.validator parent - 4.0.0-SNAPSHOT + 4.0.0 pom @@ -114,7 +114,7 @@ - 1.7 + 1.8 UTF-8 UTF-8 github @@ -150,7 +150,7 @@ 2.5 2.8 2.7 - 1.6 + 2.4 2.8.2 1.6 1.6.5 @@ -508,7 +508,7 @@ public false - org.biopax.validator.jaxb + org.biopax.validator.jaxb:org.biopax.validator.api.beans:org.biopax.validator.impl:org.biopax.validator.rules:net.biomodels.* diff --git a/validator-core/pom.xml b/validator-core/pom.xml index c7e82c25..b800618f 100644 --- a/validator-core/pom.xml +++ b/validator-core/pom.xml @@ -3,7 +3,7 @@ parent org.biopax.validator - 4.0.0-SNAPSHOT + 4.0.0 validator-core @@ -25,11 +25,9 @@ compile - - org/biopax/validator/api/beans/*.java - - true - ${project.build.directory}/generated-resources/schemas + + src/main/java/org/biopax/validator/api/beans + diff --git a/validator-core/src/main/java/org/biopax/validator/api/AbstractAspect.java b/validator-core/src/main/java/org/biopax/validator/api/AbstractAspect.java index d05760f8..f5fecc85 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/AbstractAspect.java +++ b/validator-core/src/main/java/org/biopax/validator/api/AbstractAspect.java @@ -34,10 +34,10 @@ public abstract class AbstractAspect { * Registers the error in the validator. * * @param object a model element or parser/reader (e.g., InputStream) associated with the issue - * @param errorCode + * @param errorCode error code * @param reportedBy validation rule class name - * @param setFixed - * @param msgArgs + * @param setFixed whether the problem was auto-fixed or not + * @param msgArgs additional error message parameters */ public void report(Object object, String errorCode, String reportedBy, boolean setFixed, Object... msgArgs) @@ -56,10 +56,10 @@ public void report(Object object, String errorCode, * * This must be public method (for unclear reason, otherwise causes an AOP exception...) * - * @param t + * @param t the exception * @param obj model, element, or another related to the BioPAX data object - * @param errorCode - * @param reportedBy + * @param errorCode validator error code + * @param reportedBy validator rule name * @param details extra message to be added at the end of the original error message if not null */ public void reportException(Throwable t, Object obj, String errorCode, String reportedBy, String details) { diff --git a/validator-core/src/main/java/org/biopax/validator/api/AbstractRule.java b/validator-core/src/main/java/org/biopax/validator/api/AbstractRule.java index 8e7d6f80..7aaedf46 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/AbstractRule.java +++ b/validator-core/src/main/java/org/biopax/validator/api/AbstractRule.java @@ -1,10 +1,5 @@ package org.biopax.validator.api; -/* - * - */ - -import java.util.Arrays; import java.util.Collection; import org.biopax.validator.api.beans.ErrorType; @@ -23,7 +18,7 @@ */ public abstract class AbstractRule implements Rule { - protected Log logger = LogFactory.getLog(AbstractRule.class); + protected Log logger; @Autowired protected ValidatorUtils utils; diff --git a/validator-core/src/main/java/org/biopax/validator/api/CvRestriction.java b/validator-core/src/main/java/org/biopax/validator/api/CvRestriction.java index 9cd8cfe5..e096c466 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/CvRestriction.java +++ b/validator-core/src/main/java/org/biopax/validator/api/CvRestriction.java @@ -1,9 +1,5 @@ package org.biopax.validator.api; -/* - * - */ - /** * @author rodch */ diff --git a/validator-core/src/main/java/org/biopax/validator/api/CvRule.java b/validator-core/src/main/java/org/biopax/validator/api/CvRule.java index a15facf9..a4c2a4a1 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/CvRule.java +++ b/validator-core/src/main/java/org/biopax/validator/api/CvRule.java @@ -1,8 +1,5 @@ package org.biopax.validator.api; -/* - * - */ import java.util.Set; @@ -12,13 +9,13 @@ public interface CvRule extends Rule{ /** * Gets valid CV terms (that obey the restrictions) - * @return + * @return recommended CV terms */ Set getValidTerms(); /** * Sets valid terms for this CV rule. - * @param validTerms + * @param validTerms valid/recommended controlled vocabulary terms */ void setValidTerms(Set validTerms); diff --git a/validator-core/src/main/java/org/biopax/validator/api/CvValidator.java b/validator-core/src/main/java/org/biopax/validator/api/CvValidator.java index 9023bd90..18603458 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/CvValidator.java +++ b/validator-core/src/main/java/org/biopax/validator/api/CvValidator.java @@ -16,8 +16,8 @@ public interface CvValidator { * Gets valid ontology term names * using the constraints from the rule bean. * - * @param cvRule - * @return + * @param cvRule controlled vocabulary validation rule + * @return recommended terms */ Set getValidTermNames(CvRule cvRule); @@ -25,7 +25,7 @@ public interface CvValidator { * Gets valid ontology terms * using the constraints from the rule bean. * - * @param cvRule + * @param cvRule controlled vocabulary validation rule * @return a set of ontology terms (beans) */ Set getValidTerms(CvRule cvRule); @@ -45,8 +45,8 @@ public interface CvValidator { * * @see #getValidTermNames(Collection) * - * @param restrictions - * @return + * @param restrictions controlled vocabulary restrictions (on type, context, ontology terms) + * @return set of valid ontology terms (turned into lower case) */ Set getValidTermNamesLowerCase( Collection restrictions); @@ -56,8 +56,8 @@ Set getValidTermNamesLowerCase( * restriction bean to filter the data. * (restriction's 'NOT' property is ignored here) * - * @param restriction - * @return + * @param restriction a restriction (on type, context, ontology terms) + * @return recommended ontology terms (names) */ Set getTermNames(CvRestriction restriction); @@ -76,8 +76,8 @@ Set getValidTermNamesLowerCase( * criteria defined by the bean * ('NOT' property, if set 'true', is ignored) * - * @param restriction - * @return + * @param restriction restriction (on type, context, ontology terms) + * @return ontology terms (objects) */ Set getTerms(CvRestriction restriction); diff --git a/validator-core/src/main/java/org/biopax/validator/api/Rule.java b/validator-core/src/main/java/org/biopax/validator/api/Rule.java index 5a8972b4..6f6aba20 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/Rule.java +++ b/validator-core/src/main/java/org/biopax/validator/api/Rule.java @@ -1,15 +1,10 @@ package org.biopax.validator.api; -/* - * - */ - import org.biopax.validator.api.beans.Validation; /** * Validation rule interface. - * * Although at run time T is a BioPAXElement * (this is 100% true for the current version), * at compile time, when implementing a rule, one may @@ -19,37 +14,36 @@ * * @author rodche */ -public interface Rule { - - /** - * Validates the object. - * @param validation the object where the model, validation settings and errors are stored - * @param thing to validate - * @param fix try to fix the error case if found - */ - void check(Validation validation, T thing); - - /** - * Can check it? - * - * @param thing - * @return True when it can. - */ - boolean canCheck(Object thing); - - - /** - * Saves the error or warning that occurred or was fixed. - * - * Call this method from a validation rule implementation - * every time after a problem is found and/or fixed. - * - * @param validation the object where the model, validation settings and errors are stored - * @param object that is invalid or caused the error - * @param code error code, e.g., 'illegal.value' - * @param setFixed - * @param args extra parameters for the error message template - */ - void error(Validation validation, Object object, String code, boolean setFixed, Object... args); - +public interface Rule { + + /** + * Validates the object. + * + * @param validation the object where the model, validation settings and errors are stored + * @param thing to validate + */ + void check(Validation validation, T thing); + + /** + * Can check it? + * + * @param thing an object to validate + * @return True when this rule can check the object. + */ + boolean canCheck(Object thing); + + + /** + * Saves the error or warning that occurred or was fixed. + * Call this method from a validation rule implementation + * every time after a problem is found and/or fixed. + * + * @param validation the object where the model, validation settings and errors are stored + * @param object that is invalid or caused the error + * @param code error code, e.g., 'illegal.value' + * @param setFixed true/false - whether the issue was auto-fixed or not + * @param args extra parameters for the error message template + */ + void error(Validation validation, Object object, String code, boolean setFixed, Object... args); + } diff --git a/validator-core/src/main/java/org/biopax/validator/api/Validator.java b/validator-core/src/main/java/org/biopax/validator/api/Validator.java index ab2bcebf..7e0ff26e 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/Validator.java +++ b/validator-core/src/main/java/org/biopax/validator/api/Validator.java @@ -1,8 +1,5 @@ package org.biopax.validator.api; -/* - * - */ import java.io.InputStream; import java.util.Collection; @@ -13,16 +10,14 @@ /** * BioPAX Validator interface * - * * @author rodch - * */ public interface Validator { /** * Get all the currently loaded BioPAX rules (beans). * - * @return + * @return available (loaded) validation rules */ Set> getRules(); @@ -30,7 +25,7 @@ public interface Validator { /** * Gets all the currently registered validation results. * - * @return + * @return results */ Collection getResults(); @@ -42,8 +37,8 @@ public interface Validator { * The validation result is object where all the problems * related to this data instance are collected. * - * @param validation - * @param inputStream + * @param validation validation result object + * @param inputStream data input stream */ void importModel(Validation validation, InputStream inputStream); @@ -57,7 +52,7 @@ public interface Validator { * And we want to report these problems as well. * * @param element object (e.g., existing Model) - * @param validation + * @param validation results object */ void associate(Object element, Validation validation); @@ -80,7 +75,7 @@ public interface Validator { * (that it's been associated with). * * @param obj a BioPAX element, Model, or even SimpleIOHandler - * @return + * @return validation results */ Collection findValidation(Object obj); @@ -91,7 +86,7 @@ public interface Validator { * problems that might occur during * the model initialization and creation. * - * @param validation + * @param validation results object */ void validate(Validation validation); @@ -103,7 +98,7 @@ public interface Validator { * @param errorCode error code * @param reportedBy class name of a validation rule or a name of another BioPAX validating class, method (e.g., AOP aspect's method/joinpoint name). * @param isFixed if true, - find and set the attribute - * @param args + * @param args additional message parameters (details) */ void report(Object obj, String errorCode, String reportedBy, boolean isFixed, Object... args); diff --git a/validator-core/src/main/java/org/biopax/validator/api/ValidatorException.java b/validator-core/src/main/java/org/biopax/validator/api/ValidatorException.java index 183c5080..0244ee48 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/ValidatorException.java +++ b/validator-core/src/main/java/org/biopax/validator/api/ValidatorException.java @@ -1,9 +1,5 @@ package org.biopax.validator.api; -/* - * - */ - /** * A validation runtime exception. * diff --git a/validator-core/src/main/java/org/biopax/validator/api/ValidatorUtils.java b/validator-core/src/main/java/org/biopax/validator/api/ValidatorUtils.java index 445852dd..877558ca 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/ValidatorUtils.java +++ b/validator-core/src/main/java/org/biopax/validator/api/ValidatorUtils.java @@ -1,371 +1,356 @@ package org.biopax.validator.api; -/* - * - */ - - -import org.biopax.validator.api.beans.Behavior; -import org.biopax.validator.api.beans.Category; -import org.biopax.validator.api.beans.ErrorCaseType; -import org.biopax.validator.api.beans.ErrorType; -import org.biopax.validator.api.beans.Validation; -import org.biopax.validator.api.beans.ValidatorResponse; - -import java.io.IOException; -import java.io.Writer; -import java.util.*; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.transform.*; -import javax.xml.transform.dom.DOMResult; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - +import org.biopax.validator.api.beans.*; import org.springframework.context.MessageSource; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; - import org.springframework.stereotype.Service; import org.springframework.util.ResourceUtils; +import org.w3c.dom.Document; +import org.w3c.dom.Element; -import org.w3c.dom.*; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.*; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import java.io.IOException; +import java.io.Writer; +import java.util.Locale; /** * Validator Utility Class (not BioPAX specific). - * + *

* This is injected into other beans, keeps several global settings and objects, - * e.g., marshaller, and also provides static service methods to register, - * merge, do OXM, and resolve validation errors to human-readable verbose messages. + * e.g., marshaller, and also provides static service methods to register, + * merge, do OXM, and resolve validation errors to human-readable verbose messages. * * @author rodche */ @Service public class ValidatorUtils { - private static final Log logger = LogFactory.getLog(ValidatorUtils.class); - - private Locale locale; - private MessageSource messageSource; - //private static Jaxb2Marshaller resultsMarshaller; - private static JAXBContext jaxbContext; - private int maxErrors = Integer.MAX_VALUE; - - static { - try { - jaxbContext = JAXBContext.newInstance( - ValidatorResponse.class, Validation.class, - ErrorCaseType.class, ErrorType.class, - Behavior.class, Category.class); - } catch (JAXBException e) { - throw new RuntimeException("Failed to initialize the " + - "org.biopax.validator.result JAXB context!", e); - } + private static final Log logger = LogFactory.getLog(ValidatorUtils.class); + + private Locale locale; + private MessageSource messageSource; + //private static Jaxb2Marshaller resultsMarshaller; + private static JAXBContext jaxbContext; + private int maxErrors = Integer.MAX_VALUE; + + static { + try { + jaxbContext = JAXBContext.newInstance( + ValidatorResponse.class, Validation.class, + ErrorCaseType.class, ErrorType.class, + Behavior.class, Category.class); + } catch (JAXBException e) { + throw new RuntimeException("Failed to initialize the " + + "org.biopax.validator.result JAXB context!", e); } - - public ValidatorUtils() { - this.locale = Locale.getDefault(); - } - - public void setLocale(Locale locale) { - this.locale = locale; - } - - public Locale getLocale() { - return locale; - } - - /** - * Gets the results Marshaller (for validation results.) - * @return - */ - public static Marshaller getMarshaller() { - //return resultsMarshaller; - try { - Marshaller marshaller = jaxbContext.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); - return marshaller; - } catch (JAXBException e) { - throw new RuntimeException("Failed to create Marshaller", e); - } - } - - /** - * Gets the results Unmarshaller (for validation results.) - * @return - */ - public static Unmarshaller getUnmarshaller() { - //return resultsMarshaller; - try { - return jaxbContext.createUnmarshaller(); - } catch (JAXBException e) { - throw new RuntimeException("Failed to create Unmarshaller", e); - } - } - - - public void setMessageSource(MessageSource messageSource) { - this.messageSource = messageSource; - } - - public MessageSource getMessageSource() { - return messageSource; - } - - /** - * Gets current max number of errors to report. - * - * @return - */ - public int getMaxErrors() { - return maxErrors; + } + + public ValidatorUtils() { + this.locale = Locale.getDefault(); + } + + public void setLocale(Locale locale) { + this.locale = locale; + } + + public Locale getLocale() { + return locale; + } + + /** + * Gets the results Marshaller (for validation results.) + * + * @return + */ + public static Marshaller getMarshaller() { + //return resultsMarshaller; + try { + Marshaller marshaller = jaxbContext.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); + return marshaller; + } catch (JAXBException e) { + throw new RuntimeException("Failed to create Marshaller", e); } + } - /** - * Sets current max number of errors to report. - * - */ - public void setMaxErrors(int max) { - maxErrors = max; + /** + * Gets the results Unmarshaller (for validation results.) + * + * @return unmarshaller + */ + public static Unmarshaller getUnmarshaller() { + //return resultsMarshaller; + try { + return jaxbContext.createUnmarshaller(); + } catch (JAXBException e) { + throw new RuntimeException("Failed to create Unmarshaller", e); } - - - /** - * Writes the multiple results report. - * (as transformed XML). - * - * @param validatorResponse - * @param writer - */ - public static void write(ValidatorResponse validatorResponse, - Writer writer, Source xslt) - { - try { - if (xslt != null) { - Document doc = asDocument(validatorResponse); - Source xmlSource = new DOMSource(doc); - Result result = new StreamResult(writer); - TransformerFactory transFact = TransformerFactory.newInstance(); - Transformer trans = transFact.newTransformer(xslt); - trans.setOutputProperty(OutputKeys.INDENT, "yes"); - trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); - trans.transform(xmlSource, result); - } else { - // write without any xslt - getMarshaller().marshal(validatorResponse, writer); - } - - } catch (Exception e) { - throw new RuntimeException("Cannot transform/serialize/write: " - + validatorResponse, e); - } - } - - /** - * Writes the single validation report. - * (as transformed XML). - * - * @param validationResult - * @param writer - */ - public static void write(Validation validationResult, Writer writer, Source xslt) { - ValidatorResponse resp = new ValidatorResponse(); - resp.addValidationResult(validationResult); - write(resp, writer, xslt); - } - - /** - * Converts a validator response (contains one or - * several validation results) into the document. - * - * @param validatorResponse - * @return - */ - public static Document asDocument(ValidatorResponse validatorResponse) { - DOMResult domResult = marshal(validatorResponse); - Document validation = (Document) domResult.getNode(); - return validation; - } - - /** - * Converts one validation result - * into the DOM element. - * - * @param validationResult - * @return - */ - public static Element asElement(Validation validationResult) { - DOMResult domResult = marshal(validationResult); - Element validation = (Element) domResult.getNode().getFirstChild(); - return validation; - } - - - protected static DOMResult marshal(Object obj) { - DOMResult domResult = new DOMResult(); - try { - getMarshaller().marshal(obj, domResult); - } catch (Exception e) { - throw new RuntimeException("Cannot serialize object: " + obj, e); - } - return domResult; - } - - - /** - * Creates an error type with single error case. - * - * @param objectName - * @param errorCode - * @param ruleName - * @param profile validation profile - * @param isFixed - * @param msgArgs - * @return - */ - public ErrorType createError(String objectName, String errorCode, - String ruleName, String profile, boolean isFixed, - Object... msgArgs) - { - return createError(messageSource, locale, objectName, errorCode, ruleName, profile, isFixed, msgArgs); + } + + + public void setMessageSource(MessageSource messageSource) { + this.messageSource = messageSource; + } + + public MessageSource getMessageSource() { + return messageSource; + } + + /** + * Gets current max number of errors to report. + * + * @return maximal no. errors to be collected (to abort and return the results) + */ + public int getMaxErrors() { + return maxErrors; + } + + /** + * Sets current max number of errors to report. + * + * @param max maximal no. errors to be collected (to abort and return the results) + */ + public void setMaxErrors(int max) { + maxErrors = max; + } + + + /** + * Writes the multiple results report. + * (as transformed XML). + * + * @param validatorResponse results + * @param writer output + * @param xslt source + */ + public static void write(ValidatorResponse validatorResponse, Writer writer, Source xslt) { + try { + if (xslt != null) { + Document doc = asDocument(validatorResponse); + Source xmlSource = new DOMSource(doc); + Result result = new StreamResult(writer); + TransformerFactory transFact = TransformerFactory.newInstance(); + Transformer trans = transFact.newTransformer(xslt); + trans.setOutputProperty(OutputKeys.INDENT, "yes"); + trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); + trans.transform(xmlSource, result); + } else { + // write without any xslt + getMarshaller().marshal(validatorResponse, writer); + } + + } catch (Exception e) { + throw new RuntimeException("Cannot transform/serialize/write: " + + validatorResponse, e); } - - /** - * Creates an error type with single error case. - * If the message source is null (e.g., in tests, when a rule - * is checked outside the validator framework), - * - * @param messageSource - * @param locale - * @param objectName - * @param errorCode - * @param ruleName - * @param profile validation profile - * @param isFixed - * @param msgArgs - * @return - */ - public static ErrorType createError( - MessageSource messageSource, Locale locale, - String objectName, String errorCode, - String ruleName, String profile, boolean isFixed, - Object... msgArgs) - { - - if(objectName == null) { - objectName = "null"; - logger.warn("Creating an error " + errorCode + " for Null object!"); - } - - //get/use current behavior - Behavior behavior = getRuleBehavior(ruleName, profile, messageSource); - // new error object - ErrorType error = new ErrorType(errorCode, behavior); - - // build human-friendly messages using default locale and property files (msg sources) - String commonMsg = (messageSource != null) - ? messageSource.getMessage(errorCode + ".default", new Object[]{}, "No description.", locale) - : "No description."; - error.setMessage(commonMsg); - - String msg = (messageSource != null) - ? messageSource.getMessage(errorCode, msgArgs, StringUtils.join(msgArgs, "; "), locale).replaceAll("\r|\n+", " ") - : StringUtils.join(msgArgs, "; "); - - // resolve/set BioPAX problem category - String category = (messageSource != null) - ? messageSource.getMessage(errorCode + ".category", null, Category.INFORMATION.name(), locale) - : null; - if(category != null) - error.setCategory(Category.valueOf(category.trim().toUpperCase())); - - // add one error case - ErrorCaseType errorCase = new ErrorCaseType(ruleName, objectName, msg); - errorCase.setFixed(isFixed); // - error.addErrorCase(errorCase); - - //done. - return error; + } + + /** + * Writes the single validation report. + * (as transformed XML). + * + * @param validationResult results + * @param writer XML validation result output + * @param xslt source + */ + public static void write(Validation validationResult, Writer writer, Source xslt) { + ValidatorResponse resp = new ValidatorResponse(); + resp.addValidationResult(validationResult); + write(resp, writer, xslt); + } + + /** + * Converts a validator response (contains one or + * several validation results) into the document. + * + * @param validatorResponse results + * @return results as XML DOM + */ + public static Document asDocument(ValidatorResponse validatorResponse) { + DOMResult domResult = marshal(validatorResponse); + Document validation = (Document) domResult.getNode(); + return validation; + } + + /** + * Converts one validation result + * into the DOM element. + * + * @param validationResult results + * @return element (DOM) + */ + public static Element asElement(Validation validationResult) { + DOMResult domResult = marshal(validationResult); + Element validation = (Element) domResult.getNode().getFirstChild(); + return validation; + } + + + protected static DOMResult marshal(Object obj) { + DOMResult domResult = new DOMResult(); + try { + getMarshaller().marshal(obj, domResult); + } catch (Exception e) { + throw new RuntimeException("Cannot serialize object: " + obj, e); } + return domResult; + } + + + /** + * Creates an error type with single error case. + * + * @param objectName name of the problematic model object + * @param errorCode validator error code + * @param ruleName validation rule name + * @param profile validation profile + * @param isFixed true/false - whether it's auto-fixed or not + * @param msgArgs error message details + * @return error type obj. + */ + public ErrorType createError(String objectName, String errorCode, + String ruleName, String profile, boolean isFixed, + Object... msgArgs) { + return createError(messageSource, locale, objectName, errorCode, ruleName, profile, isFixed, msgArgs); + } - - /** - * Gets the validator's home directory path. - * - * @return - * @throws IOException - */ - public static String getHomeDir() throws IOException { - Resource r = new FileSystemResource(ResourceUtils.getFile("classpath:")); - return r.createRelative("..").getFile().getCanonicalPath(); + /** + * Creates an error type with single error case. + * If the message source is null (e.g., in tests, when a rule + * is checked outside the validator framework), + * + * @param messageSource error message source + * @param locale locale + * @param objectName name of the problematic model object + * @param errorCode validator error code + * @param ruleName validation rule name + * @param profile validation profile + * @param isFixed true/false - whether it's auto-fixed or not + * @param msgArgs error message details + * @return error type + */ + public static ErrorType createError( + MessageSource messageSource, Locale locale, + String objectName, String errorCode, + String ruleName, String profile, boolean isFixed, + Object... msgArgs) { + + if (objectName == null) { + objectName = "null"; + logger.warn("Creating an error " + errorCode + " for Null object!"); } - - - /** - * Gets rule's behavior (mode), to be used - * when registering an error case reported by the rule. - * - * @see Behavior - * - * @param ruleName validation rule class name, e.g., org.biopax.validator.rules.MyRule - * @param profile validation profile name or null (default profile) - * @return - */ - public Behavior getRuleBehavior(String ruleName, String profile) { - return getRuleBehavior(ruleName, profile, messageSource); + + //get/use current behavior + Behavior behavior = getRuleBehavior(ruleName, profile, messageSource); + // new error object + ErrorType error = new ErrorType(errorCode, behavior); + + // build human-friendly messages using default locale and property files (msg sources) + String commonMsg = (messageSource != null) + ? messageSource.getMessage(errorCode + ".default", new Object[]{}, "No description.", locale) + : "No description."; + error.setMessage(commonMsg); + + String msg = (messageSource != null) + ? messageSource.getMessage(errorCode, msgArgs, StringUtils.join(msgArgs, "; "), locale).replaceAll("\r|\n+", " ") + : StringUtils.join(msgArgs, "; "); + + // resolve/set BioPAX problem category + String category = (messageSource != null) + ? messageSource.getMessage(errorCode + ".category", null, Category.INFORMATION.name(), locale) + : null; + if (category != null) + error.setCategory(Category.valueOf(category.trim().toUpperCase())); + + // add one error case + ErrorCaseType errorCase = new ErrorCaseType(ruleName, objectName, msg); + errorCase.setFixed(isFixed); // + error.addErrorCase(errorCase); + + //done. + return error; + } + + + /** + * Gets the validator's home directory path. + * + * @return directory path + * @throws IOException when it fails to get the filesystem path + */ + public static String getHomeDir() throws IOException { + Resource r = new FileSystemResource(ResourceUtils.getFile("classpath:")); + return r.createRelative("..").getFile().getCanonicalPath(); + } + + + /** + * Gets rule's behavior (mode), to be used + * when registering an error case reported by the rule. + * + * @param ruleName validation rule class name, e.g., org.biopax.validator.rules.MyRule + * @param profile validation profile name or null (default profile) + * @return error level/mode + * @see Behavior + */ + public Behavior getRuleBehavior(String ruleName, String profile) { + return getRuleBehavior(ruleName, profile, messageSource); + } + + + /** + * Gets rule's behavior (mode) during unit testing + * when messageSource can be null. + * + * @param ruleName validation rule class name, e.g., org.biopax.validator.rules.MyRule + * @param profile validation profile name or null (default profile) + * @param messageSource error message source (properties) + * @return error level/mode + * @see ValidatorUtils#getRuleBehavior(String, String) + * @see ValidatorUtils#createError(MessageSource, Locale, String, String, String, String, boolean, Object...) + */ + private static Behavior getRuleBehavior(String ruleName, String profile, MessageSource messageSource) { + if (messageSource == null) return Behavior.ERROR; + + // get the default behavior value first + String value = messageSource.getMessage(ruleName + ".behavior", null, "ERROR", Locale.getDefault()); + + // - override from the profile, if set/available + if (profile != null && !profile.isEmpty()) + value = messageSource.getMessage(ruleName + ".behavior." + profile, null, value, Locale.getDefault()); + + return Behavior.valueOf(value.toUpperCase()); + } + + + /** + * @param ruleName validation rule class name, e.g., org.biopax.validator.rules.MyRule + * @return rule description + */ + public String getRuleDescription(String ruleName) { + + String tip = messageSource.getMessage(ruleName, null, "", + Locale.getDefault()); + if (tip == null || "".equals(tip)) { + tip = "description is not found in the messages.properties file"; + } else { + tip = StringEscapeUtils.escapeHtml4(tip); } - - - /** - * Gets rule's behavior (mode) during unit testing - * when messageSource can be null. - * - * @see ValidatorUtils#getRuleBehavior(String, String) - * @see ValidatorUtils#createError(MessageSource, Locale, String, String, String, String, boolean, Object...) - * - * @param ruleName validation rule class name, e.g., org.biopax.validator.rules.MyRule - * @param profile validation profile name or null (default profile) - * @param messageSource - * @return - */ - private static Behavior getRuleBehavior(String ruleName, String profile, MessageSource messageSource) { - if(messageSource == null) return Behavior.ERROR; - - // get the default behavior value first - String value = messageSource.getMessage(ruleName + ".behavior", null, "ERROR", Locale.getDefault()); - - // - override from the profile, if set/available - if(profile != null && !profile.isEmpty()) - value = messageSource.getMessage(ruleName + ".behavior." + profile, null, value, Locale.getDefault()); - - return Behavior.valueOf(value.toUpperCase()); - } - - - /** - * - * @param ruleName validation rule class name, e.g., org.biopax.validator.rules.MyRule - * @return - */ - public String getRuleDescription(String ruleName) { - - String tip = messageSource.getMessage(ruleName, null, "", - Locale.getDefault()); - if (tip == null || "".equals(tip)) { - tip = "description is not found in the messages.properties file"; - } else { - tip = StringEscapeUtils.escapeHtml4(tip); - } - - return tip; - } - + + return tip; + } + } diff --git a/validator-core/src/main/java/org/biopax/validator/api/beans/Behavior.java b/validator-core/src/main/java/org/biopax/validator/api/beans/Behavior.java index 184c20ff..076678a9 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/beans/Behavior.java +++ b/validator-core/src/main/java/org/biopax/validator/api/beans/Behavior.java @@ -1,8 +1,5 @@ package org.biopax.validator.api.beans; -/* - * - */ import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlType; @@ -13,8 +10,6 @@ * IGNORE -- skip: do not validate, nor report any messages; * ERROR -- report as error, fail if error limit is exceeded; * WARNING -- report as warning. - * - * @author rodche */ @XmlType(name="Behavior") @XmlEnum diff --git a/validator-core/src/main/java/org/biopax/validator/api/beans/Category.java b/validator-core/src/main/java/org/biopax/validator/api/beans/Category.java index 63ffe9c2..304f58ed 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/beans/Category.java +++ b/validator-core/src/main/java/org/biopax/validator/api/beans/Category.java @@ -1,16 +1,10 @@ package org.biopax.validator.api.beans; -/* - * - */ - import javax.xml.bind.annotation.XmlEnum; import javax.xml.bind.annotation.XmlType; /** - * Categories of error - * - * @author rodche + * Validation error category. */ @XmlType(name="Category") @XmlEnum diff --git a/validator-core/src/main/java/org/biopax/validator/api/beans/ErrorCaseType.java b/validator-core/src/main/java/org/biopax/validator/api/beans/ErrorCaseType.java index fb7d98d9..c4d16a19 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/beans/ErrorCaseType.java +++ b/validator-core/src/main/java/org/biopax/validator/api/beans/ErrorCaseType.java @@ -1,8 +1,5 @@ package org.biopax.validator.api.beans; -/* - * - */ import java.io.Serializable; import javax.xml.bind.annotation.*; diff --git a/validator-core/src/main/java/org/biopax/validator/api/beans/ErrorType.java b/validator-core/src/main/java/org/biopax/validator/api/beans/ErrorType.java index 184f45e2..52d44524 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/beans/ErrorType.java +++ b/validator-core/src/main/java/org/biopax/validator/api/beans/ErrorType.java @@ -1,8 +1,5 @@ package org.biopax.validator.api.beans; -/* - * - */ import java.io.Serializable; import java.util.*; @@ -58,7 +55,7 @@ public void setCategory(Category category) { /** * Unmodifiable set of validation current error cases. * - * @return + * @return error cases */ public synchronized Collection getErrorCase() { return Collections.unmodifiableSet(errorCase); @@ -86,7 +83,7 @@ public void setMessage(String message) { } /** - * Adds (may be updates...) a error case; + * Adds (or updates) an error case; * only the error message that happened last * (for the same object and rule) is kept * (e.g., in a series of unsuccessful attempts @@ -96,7 +93,7 @@ public void setMessage(String message) { * @see ErrorCaseType#equals(Object) * @see ErrorCaseType#hashCode() * - * @param newCase + * @param newCase case */ public synchronized void addErrorCase(ErrorCaseType newCase) { ErrorCaseType ect = findErrorCase(newCase); @@ -111,11 +108,7 @@ public synchronized void addErrorCase(ErrorCaseType newCase) { } } - /** - * Adds error cases - * - * @param cases - */ + public void addCases(Collection cases) { for (ErrorCaseType errorCase : cases) { addErrorCase(errorCase); @@ -162,9 +155,9 @@ public void setType(Behavior type) { } /** - * Total number of cases registered, including fixed. + * Total number of error cases registered, including those auto-fixed. * - * @return + * @return number */ public int getTotalCases() { return totalCases; @@ -174,9 +167,9 @@ public void setTotalCases(int n) { } /** - * Total number of cases not fixed yet. + * Total number of error cases not fixed yet. * - * @return + * @return number */ public int getNotFixedCases() { return notFixedCases; @@ -191,7 +184,7 @@ public void setNotFixedCases(int n) { * @param forObject if 'null', count everything * @param reportedBy if 'null', everything's counted * @param ignoreFixed skip fixed if true - * @return + * @return number */ public int countErrors(String forObject, String reportedBy, boolean ignoreFixed) { int count = 0; @@ -222,8 +215,8 @@ public int countErrors(String forObject, String reportedBy, boolean ignoreFixed) * * @see ErrorCaseType#equals(Object) * - * @param searchBy - * @return + * @param searchBy case type (as pattern) to match + * @return actual error case */ public synchronized ErrorCaseType findErrorCase(final ErrorCaseType searchBy) { if(errorCase.contains(searchBy)) { diff --git a/validator-core/src/main/java/org/biopax/validator/api/beans/Validation.java b/validator-core/src/main/java/org/biopax/validator/api/beans/Validation.java index ccbb419f..fd82523c 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/beans/Validation.java +++ b/validator-core/src/main/java/org/biopax/validator/api/beans/Validation.java @@ -1,8 +1,5 @@ package org.biopax.validator.api.beans; -/* - * - */ import java.io.Serializable; import java.util.*; @@ -100,12 +97,13 @@ public Validation() { * @param description default is "unknown" * @param autoFix default is false * @param errorLevel default is WARNING - * @param maxErrors default is 0 (means unlimited, actually it's {@link Integer#MAX_VALUE, but the effect is same}) + * @param maxErrors default is 0 (unlimited, actually it's {@link Integer#MAX_VALUE}, but the effect is same) * @param profile validation profile name (if null, the default is used) * - * @throws IllegalArgumentException when maxErrors < 0 + * @throws IllegalArgumentException when maxErrors value is negative */ - public Validation(Identifier idCalculator, String description, boolean autoFix, Behavior errorLevel, int maxErrors, String profile) { + public Validation(Identifier idCalculator, String description, boolean autoFix, + Behavior errorLevel, int maxErrors, String profile) { this(idCalculator); setDescription(description); @@ -127,7 +125,7 @@ public Validation(Identifier idCalculator, String description, boolean autoFix, /** * Gets the current Model. * - * @return + * @return model */ @XmlTransient public Object getModel() { @@ -144,7 +142,7 @@ public Object getModel() { * or continue working with; different models can share the same * objects, etc. * - * @param model + * @param model model */ public void setModel(Object model) { this.model = model; @@ -157,7 +155,7 @@ public void setModel(Object model) { * (Note: the property name is 'Error', and not 'Errors', * simply for the simpler object-XML binding.) * - * @return + * @return errors (each has unique error code, e.g., syntax.error) */ public Collection getError() { return error; @@ -165,10 +163,9 @@ public Collection getError() { /** - * This method should never be used - * (this is for OXM frameworks only)! + * This method should never be used (it's only used by the Spring OXM framework) * - * @param errors + * @param errors collected errors */ public synchronized void setError(Collection errors) { error.clear(); @@ -195,7 +192,7 @@ public String getModelData() * this is for the biopax-validator Web * server and client applications only. * - * @param modelData + * @param modelData serialized model/data */ public void setModelData(String modelData) { this.modelData = modelData; @@ -205,7 +202,7 @@ public void setModelData(String modelData) { * Returns the data as HTML-escaped string * (to show on a web page). * - * @return + * @return serialized/encoded object model ok to embed into an html code */ @XmlTransient public String getModelDataHtmlEscaped() { @@ -227,7 +224,7 @@ public String getModelDataHtmlEscaped() { * the new error cases will be copied to it; * otherwise, the new one is simply added to the set. * - * It also updates the notfixed errors counter, + * It also updates the not-fixed errors counter, * taking into account current validation threshold (level) * and error's own type {@link Behavior} set by a validation rule * that created it! @@ -276,7 +273,7 @@ public synchronized void addError(ErrorType e) { /** * Removes the error type and all cases. - * @param e + * @param e error */ public synchronized void removeError(ErrorType e) { error.remove(e); @@ -286,7 +283,7 @@ public synchronized void removeError(ErrorType e) { /** * Sets the information about this validation task. * - * @param description + * @param description of the object model (to be validated) */ public void setDescription(String description) { this.description = description; @@ -296,7 +293,7 @@ public void setDescription(String description) { /** * Information about this validation task. * - * @return + * @return description of the object model (to be validated) */ public String getDescription() { return description; @@ -307,7 +304,7 @@ public String getDescription() { * This method should never be used * (this is for OXM frameworks only) * - * @param comments + * @param comments some info */ public void setComment(Collection comments) { this.comment.clear(); @@ -316,8 +313,8 @@ public void setComment(Collection comments) { /** - * Adds a comment, e.g., counts, regarding this validation task. - * @param comment + * Add some details, stats regarding the validation task. + * @param comment some info */ public void addComment(String comment) { this.comment.add(comment); @@ -326,7 +323,7 @@ public void addComment(String comment) { /** * Comments (e.g., counts) about this validation task. - * @return + * @return strings */ public Collection getComment() { return comment; @@ -335,8 +332,7 @@ public Collection getComment() { /** * Validation results summary. - * - * @return + * @return summary */ public synchronized String getSummary() { return summary; @@ -349,7 +345,7 @@ public void setSummary(String summary) { /** * String representation of this validation settings and results: * {@link #getDescription()} plus {@link #getSummary()} - * + * @return some info, such as description and summary */ @Override public String toString() { @@ -363,23 +359,21 @@ public String toString() { * Searches for existing (registered) error type. * This is mostly for testing. * - * @param code - * @param type - * @return + * @param code error code + * @param type level + * @return matching error class */ public ErrorType findErrorType(String code, Behavior type) { return findErrorType(new ErrorType(code, type)); } - /** + /* * Finds the same error type among * existing (already happened to have error cases) * * @see ErrorType#equals(Object) * @see ErrorType#hashCode() - * - * @param errorType - * @return + * */ private ErrorType findErrorType(ErrorType errorType) { if(getError().contains(errorType)) { @@ -393,16 +387,14 @@ private ErrorType findErrorType(ErrorType errorType) { } - /** + /* * Finds the same error case in the registry. * * @see ErrorType#equals(Object) * @see ErrorType#hashCode() * @see ErrorCaseType#equals(Object) * @see ErrorCaseType#hashCode() - * - * @param errorType - * @return + * */ private ErrorCaseType findErrorCase(ErrorType errorType, ErrorCaseType errCase) { ErrorType etype = findErrorType(errorType); @@ -425,7 +417,7 @@ private ErrorCaseType findErrorCase(ErrorType errorType, ErrorCaseType errCase) * @param category when 'null', counts all * @param ignoreWarnings do not count WARNINGs * @param ignoreFixed do not count fixed - * @return + * @return number of error cases */ public int countErrors(String forObject, String reportedBy, String code, Category category, boolean ignoreWarnings, boolean ignoreFixed) { @@ -461,7 +453,7 @@ public int countErrors(String forObject, String reportedBy, * if it makes sense, and if there is a {@link Rule} or some method * (such as in AOP Aspects) which is about to register errors about O. * - * @return + * @return objects */ @XmlTransient public Set getObjects() { @@ -488,20 +480,20 @@ protected void setFix(boolean fix) { /** * Gets the error reporting level/threshold, i.e., * this is to ignore issues reported with a level - * less than desired; e.g., to hide warnings (similar to logging). + * less than desired; e.g., if 'ERROR' then hide all warnings (similar to logging). * - * @return + * @return min. error level */ public Behavior getThreshold() { return threshold; } /** - * Sets the errors reporting level. + * Sets the min. error reporting level. * * @see #getThreshold() * - * @param threshold + * @param threshold minimal level (of ignore, warning, error) */ protected void setThreshold(Behavior threshold) { this.threshold = threshold; @@ -511,7 +503,7 @@ protected void setThreshold(Behavior threshold) { * Total number of {@link Behavior#ERROR} and * {@link Behavior#WARNING} cases (either fixed or not). * - * @return + * @return number of different type of error/warning */ public int getTotalProblemsFound() { return totalProblemsFound; @@ -524,8 +516,7 @@ public void setTotalProblemsFound(int n) { /** * Total number of {@link Behavior#ERROR} and * {@link Behavior#WARNING} cases, NOT fixed. - * - * @return + * @return the no. not fixed warning or error cases */ public synchronized int getNotFixedProblems() { return notFixedProblems; @@ -536,8 +527,7 @@ public void setNotFixedProblems(int n) { /** * Total number of NOT fixed {@link Behavior#ERROR} cases. - * - * @return + * @return the no. not fixed error cases */ public synchronized int getNotFixedErrors() { return notFixedErrors; @@ -595,7 +585,7 @@ public int getMaxErrors() { * an integer value between 0 and {@link Integer#MAX_VALUE}, otherwise * it has no effect ({@link #isMaxErrorsSet()} will return 'false'). * - * @param maxErrors + * @param maxErrors max no. errors to collect */ protected void setMaxErrors(int maxErrors) { this.maxErrors = maxErrors; @@ -614,7 +604,7 @@ public boolean isMaxErrorsSet() { /** * Gets normalizer settings. - * @return + * @return settings */ @XmlTransient public Properties getProperties() { @@ -623,9 +613,10 @@ public Properties getProperties() { /** - * Validation profile to used when checking/reporting issues. + * Validation profile (a set of active rules and levels) + * to apply when checking/reporting issues. * - * @return the profile + * @return the validation profile */ public String getProfile() { return profile; @@ -635,7 +626,7 @@ public String getProfile() { /** * Sets the validation profile to use when checking/reporting issues. * - * @param profile the profile name + * @param profile the validation profile name */ protected void setProfile(String profile) { this.profile = profile; @@ -648,8 +639,8 @@ protected void setProfile(String profile) { * objects related to this validation. * (for error reporting) * - * @param obj - * @return + * @param obj model object + * @return id */ public String identify(Object obj) { return idCalc.identify(obj); @@ -683,8 +674,8 @@ public static interface Identifier { * method, if any, is not known to the core validation framework * in advance, and toString method may not be satisfactory. * - * @param obj - * @return + * @param obj a model element or, e.g., stream + * @return id */ String identify(Object obj); diff --git a/validator-core/src/main/java/org/biopax/validator/api/beans/ValidatorResponse.java b/validator-core/src/main/java/org/biopax/validator/api/beans/ValidatorResponse.java index 929e6305..d254131f 100644 --- a/validator-core/src/main/java/org/biopax/validator/api/beans/ValidatorResponse.java +++ b/validator-core/src/main/java/org/biopax/validator/api/beans/ValidatorResponse.java @@ -1,8 +1,5 @@ package org.biopax.validator.api.beans; -/* - * - */ import java.io.Serializable; import java.util.*;