4740 |
05 Feb 09 |
nicklas |
1 |
/** |
4740 |
05 Feb 09 |
nicklas |
$Id$ |
4740 |
05 Feb 09 |
nicklas |
3 |
|
4740 |
05 Feb 09 |
nicklas |
Copyright (C) 2008 Nicklas Nordborg |
4740 |
05 Feb 09 |
nicklas |
5 |
|
4740 |
05 Feb 09 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
4740 |
05 Feb 09 |
nicklas |
Available at http://base.thep.lu.se/ |
4740 |
05 Feb 09 |
nicklas |
8 |
|
4740 |
05 Feb 09 |
nicklas |
BASE is free software; you can redistribute it and/or |
4740 |
05 Feb 09 |
nicklas |
modify it under the terms of the GNU General Public License |
4740 |
05 Feb 09 |
nicklas |
as published by the Free Software Foundation; either version 3 |
4740 |
05 Feb 09 |
nicklas |
of the License, or (at your option) any later version. |
4740 |
05 Feb 09 |
nicklas |
13 |
|
4740 |
05 Feb 09 |
nicklas |
BASE is distributed in the hope that it will be useful, |
4740 |
05 Feb 09 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4740 |
05 Feb 09 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4740 |
05 Feb 09 |
nicklas |
GNU General Public License for more details. |
4740 |
05 Feb 09 |
nicklas |
18 |
|
4740 |
05 Feb 09 |
nicklas |
You should have received a copy of the GNU General Public License |
4740 |
05 Feb 09 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
4740 |
05 Feb 09 |
nicklas |
21 |
*/ |
4740 |
05 Feb 09 |
nicklas |
22 |
package net.sf.basedb.util.overview.validator; |
4740 |
05 Feb 09 |
nicklas |
23 |
|
4740 |
05 Feb 09 |
nicklas |
24 |
import net.sf.basedb.core.BasicItem; |
5651 |
08 Jun 11 |
nicklas |
25 |
import net.sf.basedb.core.BioSource; |
5651 |
08 Jun 11 |
nicklas |
26 |
import net.sf.basedb.core.DbControl; |
4753 |
12 Feb 09 |
nicklas |
27 |
import net.sf.basedb.core.Extract; |
4740 |
05 Feb 09 |
nicklas |
28 |
import net.sf.basedb.core.Item; |
5651 |
08 Jun 11 |
nicklas |
29 |
import net.sf.basedb.core.ItemSubtype; |
5651 |
08 Jun 11 |
nicklas |
30 |
import net.sf.basedb.core.PermissionDeniedException; |
4740 |
05 Feb 09 |
nicklas |
31 |
import net.sf.basedb.core.Sample; |
4740 |
05 Feb 09 |
nicklas |
32 |
import net.sf.basedb.util.overview.Fix; |
5651 |
08 Jun 11 |
nicklas |
33 |
import net.sf.basedb.util.overview.Node.Type; |
5651 |
08 Jun 11 |
nicklas |
34 |
import net.sf.basedb.util.overview.OverviewContext; |
4740 |
05 Feb 09 |
nicklas |
35 |
import net.sf.basedb.util.overview.Validator; |
4740 |
05 Feb 09 |
nicklas |
36 |
import net.sf.basedb.util.overview.Node; |
5651 |
08 Jun 11 |
nicklas |
37 |
import net.sf.basedb.util.overview.node.ChildNodeDirection; |
4740 |
05 Feb 09 |
nicklas |
38 |
|
4740 |
05 Feb 09 |
nicklas |
39 |
/** |
4740 |
05 Feb 09 |
nicklas |
Validator implementation for sample. Validation rules: |
4740 |
05 Feb 09 |
nicklas |
<ul> |
4740 |
05 Feb 09 |
nicklas |
<li>Missing item: {@link Validator#MISSING_SAMPLE} |
4740 |
05 Feb 09 |
nicklas |
<li>Access denied: {@link Validator#DENIED_SAMPLE} |
5651 |
08 Jun 11 |
nicklas |
<li>Subtype of parent sample: {@link Validator#INCORRECT_SAMPLE_TYPE} |
5651 |
08 Jun 11 |
nicklas |
<li>Subtype of parent biosource: {@link Validator#INCORRECT_BIOSOURCE_TYPE} |
4740 |
05 Feb 09 |
nicklas |
</ul> |
4740 |
05 Feb 09 |
nicklas |
47 |
|
4740 |
05 Feb 09 |
nicklas |
@author Nicklas |
4740 |
05 Feb 09 |
nicklas |
@version 2.10 |
4740 |
05 Feb 09 |
nicklas |
@base.modified $Date$ |
4740 |
05 Feb 09 |
nicklas |
51 |
*/ |
4740 |
05 Feb 09 |
nicklas |
52 |
public class SampleValidator |
4764 |
16 Feb 09 |
nicklas |
53 |
extends NameableNodeValidator<Sample> |
4740 |
05 Feb 09 |
nicklas |
54 |
{ |
4740 |
05 Feb 09 |
nicklas |
55 |
|
4740 |
05 Feb 09 |
nicklas |
56 |
public SampleValidator() |
4740 |
05 Feb 09 |
nicklas |
57 |
{ |
4740 |
05 Feb 09 |
nicklas |
58 |
super(Validator.MISSING_SAMPLE, Validator.DENIED_SAMPLE); |
4740 |
05 Feb 09 |
nicklas |
59 |
} |
4740 |
05 Feb 09 |
nicklas |
60 |
|
4740 |
05 Feb 09 |
nicklas |
61 |
/* |
4740 |
05 Feb 09 |
nicklas |
From BasicValidator class |
4740 |
05 Feb 09 |
nicklas |
63 |
------------------------- |
4740 |
05 Feb 09 |
nicklas |
64 |
*/ |
5651 |
08 Jun 11 |
nicklas |
65 |
@Override |
5651 |
08 Jun 11 |
nicklas |
66 |
public void postValidate(DbControl dc, OverviewContext context, Node node, Node parentNode) |
5651 |
08 Jun 11 |
nicklas |
67 |
{ |
5651 |
08 Jun 11 |
nicklas |
68 |
super.postValidate(dc, context, node, parentNode); |
5651 |
08 Jun 11 |
nicklas |
69 |
|
5651 |
08 Jun 11 |
nicklas |
70 |
if (parentNode != null) |
5651 |
08 Jun 11 |
nicklas |
71 |
{ |
5651 |
08 Jun 11 |
nicklas |
72 |
Node parentItemNode = parentNode.getNodeType() == Type.ITEM ? parentNode : parentNode.getParent(); |
5651 |
08 Jun 11 |
nicklas |
73 |
Item parentType = parentItemNode.getItemType(); |
5651 |
08 Jun 11 |
nicklas |
74 |
|
5651 |
08 Jun 11 |
nicklas |
75 |
if (parentType == Item.BIOSOURCE) |
5651 |
08 Jun 11 |
nicklas |
76 |
{ |
5651 |
08 Jun 11 |
nicklas |
77 |
checkParentBioSourceSubtype(dc, context, node, parentItemNode); |
5651 |
08 Jun 11 |
nicklas |
78 |
} |
5651 |
08 Jun 11 |
nicklas |
79 |
else if (parentType == Item.SAMPLE) |
5651 |
08 Jun 11 |
nicklas |
80 |
{ |
5651 |
08 Jun 11 |
nicklas |
81 |
if (node.getChildNodeDirection() == ChildNodeDirection.FORWARD) |
5651 |
08 Jun 11 |
nicklas |
82 |
{ |
5651 |
08 Jun 11 |
nicklas |
83 |
checkParentSampleSubtype(dc, context, node, parentItemNode); |
5651 |
08 Jun 11 |
nicklas |
84 |
} |
5651 |
08 Jun 11 |
nicklas |
85 |
else |
5651 |
08 Jun 11 |
nicklas |
86 |
{ |
5651 |
08 Jun 11 |
nicklas |
87 |
checkParentSampleSubtype(dc, context, parentItemNode, node); |
5651 |
08 Jun 11 |
nicklas |
88 |
} |
5651 |
08 Jun 11 |
nicklas |
89 |
} |
5651 |
08 Jun 11 |
nicklas |
90 |
else if (parentType == Item.EXTRACT) |
5651 |
08 Jun 11 |
nicklas |
91 |
{ |
5651 |
08 Jun 11 |
nicklas |
92 |
ExtractValidator.checkParentSampleSubtype(dc, context, parentItemNode, node); |
5651 |
08 Jun 11 |
nicklas |
93 |
} |
6042 |
03 Apr 12 |
nicklas |
94 |
else if (parentType == Item.BIOPLATE) |
6042 |
03 Apr 12 |
nicklas |
95 |
{ |
6042 |
03 Apr 12 |
nicklas |
96 |
BioPlateValidator.checkBioMaterialInWell(dc, context, parentItemNode, node); |
6042 |
03 Apr 12 |
nicklas |
97 |
} |
5651 |
08 Jun 11 |
nicklas |
98 |
} |
5651 |
08 Jun 11 |
nicklas |
99 |
} |
5651 |
08 Jun 11 |
nicklas |
100 |
|
5651 |
08 Jun 11 |
nicklas |
101 |
|
4740 |
05 Feb 09 |
nicklas |
102 |
/** |
4740 |
05 Feb 09 |
nicklas |
The suggested fix is to add a parent sample to the extract |
4740 |
05 Feb 09 |
nicklas |
or one or more samples to the pooled sample. |
4740 |
05 Feb 09 |
nicklas |
105 |
*/ |
4740 |
05 Feb 09 |
nicklas |
106 |
@Override |
5651 |
08 Jun 11 |
nicklas |
107 |
protected Fix getMissingItemFix(DbControl dc, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
108 |
{ |
4740 |
05 Feb 09 |
nicklas |
109 |
Fix fix = null; |
4740 |
05 Feb 09 |
nicklas |
110 |
Item parentType = parentNode.getItemType(); |
4740 |
05 Feb 09 |
nicklas |
111 |
BasicItem parentItem = parentNode.getItem(); |
4740 |
05 Feb 09 |
nicklas |
112 |
if (parentType == Item.EXTRACT) |
4740 |
05 Feb 09 |
nicklas |
113 |
{ |
4753 |
12 Feb 09 |
nicklas |
114 |
fix = new Fix("Add parent sample to '" + ((Extract)parentItem).getName() + "'", parentItem); |
4740 |
05 Feb 09 |
nicklas |
115 |
} |
4740 |
05 Feb 09 |
nicklas |
116 |
else if (parentType == Item.SAMPLE) |
4740 |
05 Feb 09 |
nicklas |
117 |
{ |
4753 |
12 Feb 09 |
nicklas |
118 |
fix = new Fix("Add parents to '" + ((Sample)parentItem).getName() + "'", parentItem); |
4740 |
05 Feb 09 |
nicklas |
119 |
} |
4740 |
05 Feb 09 |
nicklas |
120 |
return fix; |
4740 |
05 Feb 09 |
nicklas |
121 |
} |
4740 |
05 Feb 09 |
nicklas |
122 |
// ---------------------------- |
5651 |
08 Jun 11 |
nicklas |
123 |
|
5651 |
08 Jun 11 |
nicklas |
124 |
/** |
5651 |
08 Jun 11 |
nicklas |
Check the subtype of the biosurce that is the parent to a sample. Given that |
5651 |
08 Jun 11 |
nicklas |
the sample has a non-null subtype, which has a related BIOSOURCE subtype, this |
5651 |
08 Jun 11 |
nicklas |
method checks if the parent biosource has the same subtype. If there is no related |
5651 |
08 Jun 11 |
nicklas |
subtype for the sample, any subtype for the parent is accepted. |
5651 |
08 Jun 11 |
nicklas |
@since 3.0 |
5651 |
08 Jun 11 |
nicklas |
130 |
*/ |
5651 |
08 Jun 11 |
nicklas |
131 |
public static void checkParentBioSourceSubtype(DbControl dc, OverviewContext context, Node sampleNode, Node bioSourceNode) |
5651 |
08 Jun 11 |
nicklas |
132 |
{ |
5807 |
14 Oct 11 |
nicklas |
133 |
Sample sample = (Sample)sampleNode.getItem(dc); |
5807 |
14 Oct 11 |
nicklas |
134 |
BioSource bioSource = (BioSource)bioSourceNode.getItem(dc); |
5651 |
08 Jun 11 |
nicklas |
135 |
|
5651 |
08 Jun 11 |
nicklas |
136 |
try |
5651 |
08 Jun 11 |
nicklas |
137 |
{ |
5651 |
08 Jun 11 |
nicklas |
138 |
ItemSubtype expectedSubtype = ItemSubtype.getRelatedSubtype(dc, sample, Item.BIOSOURCE, Item.SAMPLE); |
5651 |
08 Jun 11 |
nicklas |
139 |
ItemSubtype subtype = bioSource.getItemSubtype(); |
5651 |
08 Jun 11 |
nicklas |
140 |
|
5651 |
08 Jun 11 |
nicklas |
141 |
if (expectedSubtype != null && !expectedSubtype.equals(subtype)) |
5651 |
08 Jun 11 |
nicklas |
142 |
{ |
5807 |
14 Oct 11 |
nicklas |
143 |
ItemSubtype mySubtype = sample.getItemSubtype(); |
5807 |
14 Oct 11 |
nicklas |
144 |
Fix subtypeFix = subtype == null ? null : |
5807 |
14 Oct 11 |
nicklas |
145 |
new Fix("Change related biosource subtype of '" + mySubtype.getName() + |
5807 |
14 Oct 11 |
nicklas |
146 |
"' to '" + subtype.getName() + "'", mySubtype); |
5807 |
14 Oct 11 |
nicklas |
147 |
|
5651 |
08 Jun 11 |
nicklas |
148 |
if (expectedSubtype.getMainItemType() == Item.BIOSOURCE) |
5651 |
08 Jun 11 |
nicklas |
149 |
{ |
5651 |
08 Jun 11 |
nicklas |
// Expected another biosource subtype |
5651 |
08 Jun 11 |
nicklas |
151 |
context.createFailure(Validator.INCORRECT_BIOSOURCE_TYPE, sampleNode, |
5807 |
14 Oct 11 |
nicklas |
152 |
"Expected a biosource with subtype: " + expectedSubtype.getName(), |
5807 |
14 Oct 11 |
nicklas |
153 |
new Fix("Change subtype of '" + bioSource.getName() + "' to '" + expectedSubtype.getName() + "'", bioSource), |
5807 |
14 Oct 11 |
nicklas |
154 |
new Fix("Change subtype or parent biosource of '" + sampleNode.getTitle() + "'", sample), |
5807 |
14 Oct 11 |
nicklas |
155 |
subtypeFix |
5651 |
08 Jun 11 |
nicklas |
156 |
); |
5651 |
08 Jun 11 |
nicklas |
157 |
} |
5651 |
08 Jun 11 |
nicklas |
158 |
else |
5651 |
08 Jun 11 |
nicklas |
159 |
{ |
5651 |
08 Jun 11 |
nicklas |
// Expected a sample as parent |
5651 |
08 Jun 11 |
nicklas |
161 |
context.createFailure(Validator.INCORRECT_BIOSOURCE_TYPE, sampleNode, |
5807 |
14 Oct 11 |
nicklas |
162 |
"Expected a sample with subtype: " + expectedSubtype.getName(), |
5807 |
14 Oct 11 |
nicklas |
163 |
new Fix("Change subtype or parent biosource of '" + sampleNode.getTitle() + "'", sample), |
5807 |
14 Oct 11 |
nicklas |
164 |
subtypeFix |
5651 |
08 Jun 11 |
nicklas |
165 |
); |
5651 |
08 Jun 11 |
nicklas |
166 |
} |
5651 |
08 Jun 11 |
nicklas |
167 |
} |
5651 |
08 Jun 11 |
nicklas |
168 |
} |
5651 |
08 Jun 11 |
nicklas |
169 |
catch (PermissionDeniedException ex) |
5651 |
08 Jun 11 |
nicklas |
170 |
{} |
5651 |
08 Jun 11 |
nicklas |
171 |
} |
5651 |
08 Jun 11 |
nicklas |
172 |
|
5651 |
08 Jun 11 |
nicklas |
173 |
/** |
5651 |
08 Jun 11 |
nicklas |
Check the subtype of the sample that is the parent to another sample. Given that |
5651 |
08 Jun 11 |
nicklas |
the child sample has a non-null subtype, which has a related SAMPLE subtype, this |
5651 |
08 Jun 11 |
nicklas |
method checks if the parent sample has the same subtype. If there is no related |
5651 |
08 Jun 11 |
nicklas |
subtype for the child sample, any subtype for the parent is accepted. |
5651 |
08 Jun 11 |
nicklas |
@since 3.0 |
5651 |
08 Jun 11 |
nicklas |
179 |
*/ |
5651 |
08 Jun 11 |
nicklas |
180 |
public static void checkParentSampleSubtype(DbControl dc, OverviewContext context, Node childNode, Node parentNode) |
5651 |
08 Jun 11 |
nicklas |
181 |
{ |
5807 |
14 Oct 11 |
nicklas |
182 |
Sample child = (Sample)childNode.getItem(dc); |
5807 |
14 Oct 11 |
nicklas |
183 |
Sample parent = (Sample)parentNode.getItem(dc); |
5651 |
08 Jun 11 |
nicklas |
184 |
|
5651 |
08 Jun 11 |
nicklas |
185 |
try |
5651 |
08 Jun 11 |
nicklas |
186 |
{ |
5807 |
14 Oct 11 |
nicklas |
187 |
ItemSubtype expectedSubtype = ItemSubtype.getRelatedSubtype(dc, child, Item.SAMPLE, Item.BIOSOURCE); |
5651 |
08 Jun 11 |
nicklas |
188 |
ItemSubtype subtype = parent.getItemSubtype(); |
5651 |
08 Jun 11 |
nicklas |
189 |
|
5651 |
08 Jun 11 |
nicklas |
190 |
if (expectedSubtype != null && !expectedSubtype.equals(subtype)) |
5651 |
08 Jun 11 |
nicklas |
191 |
{ |
5807 |
14 Oct 11 |
nicklas |
192 |
ItemSubtype mySubtype = child.getItemSubtype(); |
5807 |
14 Oct 11 |
nicklas |
193 |
Fix subtypeFix = subtype == null || subtype.equals(mySubtype) ? null : |
5807 |
14 Oct 11 |
nicklas |
194 |
new Fix("Change related sample subtype of '" + mySubtype.getName() + |
5807 |
14 Oct 11 |
nicklas |
195 |
"' to '" + subtype.getName() + "'", mySubtype); |
5807 |
14 Oct 11 |
nicklas |
196 |
|
5807 |
14 Oct 11 |
nicklas |
197 |
if (expectedSubtype.getMainItemType() == Item.SAMPLE) |
5807 |
14 Oct 11 |
nicklas |
198 |
{ |
5807 |
14 Oct 11 |
nicklas |
199 |
context.createFailure(Validator.INCORRECT_SAMPLE_TYPE, childNode, |
5807 |
14 Oct 11 |
nicklas |
200 |
"Expected a sample with subtype: " + expectedSubtype.getName(), |
5807 |
14 Oct 11 |
nicklas |
201 |
new Fix("Change subtype of '" + parent.getName() + "' to '" + expectedSubtype.getName() + "'", parent), |
5807 |
14 Oct 11 |
nicklas |
202 |
new Fix("Change subtype or parent sample of '" + childNode.getTitle() + "'", child), |
5807 |
14 Oct 11 |
nicklas |
203 |
subtypeFix |
5807 |
14 Oct 11 |
nicklas |
204 |
); |
5807 |
14 Oct 11 |
nicklas |
205 |
} |
5807 |
14 Oct 11 |
nicklas |
206 |
else |
5807 |
14 Oct 11 |
nicklas |
207 |
{ |
5807 |
14 Oct 11 |
nicklas |
208 |
context.createFailure(Validator.INCORRECT_SAMPLE_TYPE, childNode, |
5807 |
14 Oct 11 |
nicklas |
209 |
"Expected a biosource with subtype: " + expectedSubtype.getName(), |
5807 |
14 Oct 11 |
nicklas |
210 |
new Fix("Change subtype or parent of '" + childNode.getTitle() + "'", child), |
5807 |
14 Oct 11 |
nicklas |
211 |
subtypeFix |
5807 |
14 Oct 11 |
nicklas |
212 |
); |
5807 |
14 Oct 11 |
nicklas |
213 |
} |
5651 |
08 Jun 11 |
nicklas |
214 |
} |
5651 |
08 Jun 11 |
nicklas |
215 |
} |
5651 |
08 Jun 11 |
nicklas |
216 |
catch (PermissionDeniedException ex) |
5651 |
08 Jun 11 |
nicklas |
217 |
{} |
5651 |
08 Jun 11 |
nicklas |
218 |
} |
5651 |
08 Jun 11 |
nicklas |
219 |
|
5651 |
08 Jun 11 |
nicklas |
220 |
|
4740 |
05 Feb 09 |
nicklas |
221 |
} |