|
1 | 1 | package org.biopax.validator.impl; |
2 | 2 |
|
3 | | -import java.util.*; |
4 | | - |
5 | | -import javax.annotation.PostConstruct; |
6 | | - |
7 | 3 | import org.biopax.paxtools.controller.PropertyEditor; |
8 | 4 | import org.biopax.paxtools.model.BioPAXElement; |
9 | 5 | import org.biopax.validator.api.AbstractRule; |
|
12 | 8 | import org.biopax.validator.api.CvValidator; |
13 | 9 | import org.springframework.beans.factory.annotation.Autowired; |
14 | 10 |
|
| 11 | +import javax.annotation.PostConstruct; |
| 12 | +import java.util.HashSet; |
| 13 | +import java.util.Set; |
| 14 | + |
15 | 15 | /** |
16 | 16 | * An abstract class for CV terms checks. |
17 | | - * |
18 | | - * @author rodche |
19 | 17 | * |
20 | 18 | * @param <D> property domain |
| 19 | + * @author rodche |
21 | 20 | */ |
22 | 21 | public abstract class AbstractCvRule<D extends BioPAXElement> extends AbstractRule<D> implements CvRule<D> { |
23 | | - |
24 | | - @Autowired |
25 | | - protected CvValidator ontologyManager; |
26 | | - |
27 | | - protected final Class<D> domain; |
28 | | - protected final String property; // helps validate generic ControlledVocabulary instances |
29 | | - protected final Set<CvRestriction> restrictions; |
30 | | - private Set<String> validTerms; |
31 | | - protected PropertyEditor<? super D, ?> editor; |
32 | | - |
33 | | - /** |
34 | | - * Constructor. |
35 | | - * |
36 | | - * @param domain a BioPAX class for which the CV terms restrictions apply |
37 | | - * @param property the name of the BioPAX property to get controlled vocabularies or null |
38 | | - * @param restrictions a list of beans, each defining names (a subtree of an ontology) that |
39 | | - * is either to include or exclude (when 'not' flag is set) from the valid names set. |
40 | | - */ |
41 | | - public AbstractCvRule(Class<D> domain, String property, CvRestriction... restrictions) |
42 | | - { |
43 | | - this.domain = domain; |
44 | | - this.property = property; |
45 | | - this.restrictions = new HashSet<CvRestriction>(restrictions.length); |
46 | | - for(CvRestriction c: restrictions) { |
47 | | - this.restrictions.add(c); |
48 | | - } |
| 22 | + |
| 23 | + @Autowired |
| 24 | + protected CvValidator ontologyManager; |
| 25 | + |
| 26 | + protected final Class<D> domain; |
| 27 | + protected final String property; // helps validate generic ControlledVocabulary instances |
| 28 | + protected final Set<CvRestriction> restrictions; |
| 29 | + private Set<String> validTerms; |
| 30 | + protected PropertyEditor<? super D, ?> editor; |
| 31 | + |
| 32 | + /** |
| 33 | + * Constructor. |
| 34 | + * |
| 35 | + * @param domain a BioPAX class for which the CV terms restrictions apply |
| 36 | + * @param property the name of the BioPAX property to get controlled vocabularies or null |
| 37 | + * @param restrictions a list of beans, each defining names (a subtree of an ontology) that |
| 38 | + * is either to include or exclude (when 'not' flag is set) from the valid names set. |
| 39 | + */ |
| 40 | + public AbstractCvRule(Class<D> domain, String property, CvRestriction... restrictions) { |
| 41 | + this.domain = domain; |
| 42 | + this.property = property; |
| 43 | + this.restrictions = new HashSet<CvRestriction>(restrictions.length); |
| 44 | + for (CvRestriction c : restrictions) { |
| 45 | + this.restrictions.add(c); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + @PostConstruct |
| 50 | + public void init() { |
| 51 | + if (ontologyManager != null) { |
| 52 | + setValidTerms(ontologyManager.getValidTermNames(this)); |
| 53 | + } else { |
| 54 | + throw new IllegalStateException("ontologyManager is NULL!"); |
49 | 55 | } |
50 | | - |
51 | | - @PostConstruct |
52 | | - public void init() { |
53 | | - if(ontologyManager != null) { |
54 | | - setValidTerms(ontologyManager.getValidTermNames(this)); |
55 | | - } else { |
56 | | - throw new IllegalStateException("ontologyManager is NULL!"); |
57 | | - } |
58 | | - }; |
59 | | - |
60 | | - |
61 | | - public boolean canCheck(Object thing) { |
62 | | - return domain.isInstance(thing); |
63 | | - } |
64 | | - |
65 | | - /* (non-Javadoc) |
66 | | - * @see org.biopax.validator.impl.CvRule#getValidTerms() |
67 | | - */ |
68 | | - public Set<String> getValidTerms() { |
69 | | - return validTerms; |
70 | | - } |
71 | | - |
72 | | - /* (non-Javadoc) |
73 | | - * @see org.biopax.validator.impl.CvRule#setValidTerms(java.util.Set) |
74 | | - */ |
75 | | - public void setValidTerms(Set<String> validTerms) { |
76 | | - this.validTerms = validTerms; |
77 | | - } |
78 | | - |
79 | | - // for unit testing |
80 | | - |
81 | | - /* (non-Javadoc) |
82 | | - * @see org.biopax.validator.impl.CvRule#getRestrictions() |
83 | | - */ |
84 | | - public Set<CvRestriction> getRestrictions() { |
85 | | - return restrictions; |
86 | | - } |
87 | | - |
88 | | - /* (non-Javadoc) |
89 | | - * @see org.biopax.validator.impl.CvRule#getDomain() |
90 | | - */ |
91 | | - public Class<D> getDomain() { |
92 | | - return domain; |
93 | | - } |
94 | | - |
95 | | - /* (non-Javadoc) |
96 | | - * @see org.biopax.validator.impl.CvRule#getProperty() |
97 | | - */ |
98 | | - public String getProperty() { |
99 | | - return property; |
100 | | - } |
101 | | - |
102 | | - /** |
103 | | - * Gets the internal BiopaxOntologyManager instance |
104 | | - * @return |
105 | | - */ |
106 | | - public CvValidator getBiopaxOntologyManager() { |
107 | | - return ontologyManager; |
108 | | - } |
109 | | - |
110 | | - /** |
111 | | - * Gets the corresponding CV property editor. |
112 | | - * Returns null if either the 'domain' itself is of CV type |
113 | | - * or the 'property' is null. |
114 | | - * |
115 | | - * @return |
116 | | - */ |
117 | | - public PropertyEditor<? super D, ?> getEditor() { |
118 | | - return editor; |
119 | | - } |
120 | | - |
121 | | - /** |
122 | | - * OntologyAccess IDs used to check this CV rule. |
123 | | - * These can be extracted from the CV rescrictions |
124 | | - * used to define the rule. |
125 | | - * (other ontologies are not used). |
126 | | - * |
127 | | - * @return |
128 | | - */ |
129 | | - protected Set<String> getOntologyIDs() { |
130 | | - Set<String> ids = new HashSet<String>(); |
131 | | - for(CvRestriction restriction : restrictions) |
132 | | - ids.add(restriction.getOntologyId()); |
133 | | - return ids; |
134 | | - } |
| 56 | + } |
| 57 | + |
| 58 | + ; |
| 59 | + |
| 60 | + |
| 61 | + public boolean canCheck(Object thing) { |
| 62 | + return domain.isInstance(thing); |
| 63 | + } |
| 64 | + |
| 65 | + /* (non-Javadoc) |
| 66 | + * @see org.biopax.validator.impl.CvRule#getValidTerms() |
| 67 | + */ |
| 68 | + public Set<String> getValidTerms() { |
| 69 | + return validTerms; |
| 70 | + } |
| 71 | + |
| 72 | + /* (non-Javadoc) |
| 73 | + * @see org.biopax.validator.impl.CvRule#setValidTerms(java.util.Set) |
| 74 | + */ |
| 75 | + public void setValidTerms(Set<String> validTerms) { |
| 76 | + this.validTerms = validTerms; |
| 77 | + } |
| 78 | + |
| 79 | + // for unit testing |
| 80 | + |
| 81 | + /* (non-Javadoc) |
| 82 | + * @see org.biopax.validator.impl.CvRule#getRestrictions() |
| 83 | + */ |
| 84 | + public Set<CvRestriction> getRestrictions() { |
| 85 | + return restrictions; |
| 86 | + } |
| 87 | + |
| 88 | + /* (non-Javadoc) |
| 89 | + * @see org.biopax.validator.impl.CvRule#getDomain() |
| 90 | + */ |
| 91 | + public Class<D> getDomain() { |
| 92 | + return domain; |
| 93 | + } |
| 94 | + |
| 95 | + /* (non-Javadoc) |
| 96 | + * @see org.biopax.validator.impl.CvRule#getProperty() |
| 97 | + */ |
| 98 | + public String getProperty() { |
| 99 | + return property; |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Gets the internal BiopaxOntologyManager instance |
| 104 | + * |
| 105 | + * @return ontology manager |
| 106 | + */ |
| 107 | + public CvValidator getBiopaxOntologyManager() { |
| 108 | + return ontologyManager; |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * Gets the corresponding CV property editor. |
| 113 | + * Returns null if either the 'domain' itself is of CV type |
| 114 | + * or the 'property' is null. |
| 115 | + * |
| 116 | + * @return biopax property editor |
| 117 | + */ |
| 118 | + public PropertyEditor<? super D, ?> getEditor() { |
| 119 | + return editor; |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | + * OntologyAccess IDs used to check this CV rule. |
| 124 | + * These can be extracted from the CV restrictions |
| 125 | + * used to define the rule. |
| 126 | + * (other ontologies are not used). |
| 127 | + * |
| 128 | + * @return ontology IDs, such as e.g. 'MI', 'GO' |
| 129 | + */ |
| 130 | + protected Set<String> getOntologyIDs() { |
| 131 | + Set<String> ids = new HashSet<String>(); |
| 132 | + for (CvRestriction restriction : restrictions) |
| 133 | + ids.add(restriction.getOntologyId()); |
| 134 | + return ids; |
| 135 | + } |
135 | 136 | } |
0 commit comments