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 |
|
6098 |
03 Sep 12 |
nicklas |
24 |
import java.util.ArrayList; |
6098 |
03 Sep 12 |
nicklas |
25 |
import java.util.HashSet; |
6098 |
03 Sep 12 |
nicklas |
26 |
import java.util.List; |
6098 |
03 Sep 12 |
nicklas |
27 |
import java.util.Set; |
6098 |
03 Sep 12 |
nicklas |
28 |
|
5651 |
08 Jun 11 |
nicklas |
29 |
import net.sf.basedb.core.DbControl; |
6098 |
03 Sep 12 |
nicklas |
30 |
import net.sf.basedb.core.DerivedBioAssay; |
5651 |
08 Jun 11 |
nicklas |
31 |
import net.sf.basedb.core.Extract; |
6098 |
03 Sep 12 |
nicklas |
32 |
import net.sf.basedb.core.Include; |
6098 |
03 Sep 12 |
nicklas |
33 |
import net.sf.basedb.core.ItemQuery; |
5651 |
08 Jun 11 |
nicklas |
34 |
import net.sf.basedb.core.ItemSubtype; |
5651 |
08 Jun 11 |
nicklas |
35 |
import net.sf.basedb.core.PermissionDeniedException; |
5642 |
26 May 11 |
nicklas |
36 |
import net.sf.basedb.core.PhysicalBioAssay; |
4740 |
05 Feb 09 |
nicklas |
37 |
import net.sf.basedb.core.Item; |
6799 |
25 Mar 15 |
nicklas |
38 |
import net.sf.basedb.util.listable.ExtractToParentExtractTransformer; |
6799 |
25 Mar 15 |
nicklas |
39 |
import net.sf.basedb.util.listable.SourceItemTransformer; |
6799 |
25 Mar 15 |
nicklas |
40 |
import net.sf.basedb.util.listable.TransformContext; |
4740 |
05 Feb 09 |
nicklas |
41 |
import net.sf.basedb.util.overview.Fix; |
5651 |
08 Jun 11 |
nicklas |
42 |
import net.sf.basedb.util.overview.OverviewContext; |
4740 |
05 Feb 09 |
nicklas |
43 |
import net.sf.basedb.util.overview.Validator; |
4740 |
05 Feb 09 |
nicklas |
44 |
import net.sf.basedb.util.overview.Node; |
5651 |
08 Jun 11 |
nicklas |
45 |
import net.sf.basedb.util.overview.Node.Type; |
4740 |
05 Feb 09 |
nicklas |
46 |
|
4740 |
05 Feb 09 |
nicklas |
47 |
/** |
5651 |
08 Jun 11 |
nicklas |
Validator implementation for physical bioassays. Validation rules: |
4740 |
05 Feb 09 |
nicklas |
<ul> |
5807 |
14 Oct 11 |
nicklas |
<li>Missing item: {@link Validator#MISSING_PHYSICALBIOASSAY} |
5807 |
14 Oct 11 |
nicklas |
<li>Access denied: {@link Validator#DENIED_PHYSICALBIOASSAY} |
5651 |
08 Jun 11 |
nicklas |
<li>Subtype of parent extract: {@link Validator#INCORRECT_EXTRACT_TYPE} |
4740 |
05 Feb 09 |
nicklas |
</ul> |
4740 |
05 Feb 09 |
nicklas |
54 |
|
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 |
58 |
*/ |
5651 |
08 Jun 11 |
nicklas |
59 |
public class PhysicalBioAssayValidator |
5642 |
26 May 11 |
nicklas |
60 |
extends NameableNodeValidator<PhysicalBioAssay> |
4740 |
05 Feb 09 |
nicklas |
61 |
{ |
4740 |
05 Feb 09 |
nicklas |
62 |
|
5651 |
08 Jun 11 |
nicklas |
63 |
public PhysicalBioAssayValidator() |
4740 |
05 Feb 09 |
nicklas |
64 |
{ |
5807 |
14 Oct 11 |
nicklas |
65 |
super(Validator.MISSING_PHYSICALBIOASSAY, Validator.DENIED_PHYSICALBIOASSAY); |
4740 |
05 Feb 09 |
nicklas |
66 |
} |
4740 |
05 Feb 09 |
nicklas |
67 |
|
4740 |
05 Feb 09 |
nicklas |
68 |
/* |
4740 |
05 Feb 09 |
nicklas |
From BasicValidator class |
4740 |
05 Feb 09 |
nicklas |
70 |
------------------------- |
5651 |
08 Jun 11 |
nicklas |
71 |
*/ |
5651 |
08 Jun 11 |
nicklas |
72 |
@Override |
5651 |
08 Jun 11 |
nicklas |
73 |
public void postValidate(DbControl dc, OverviewContext context, Node node, Node parentNode) |
5651 |
08 Jun 11 |
nicklas |
74 |
{ |
5651 |
08 Jun 11 |
nicklas |
75 |
super.postValidate(dc, context, node, parentNode); |
5651 |
08 Jun 11 |
nicklas |
76 |
|
5651 |
08 Jun 11 |
nicklas |
77 |
if (parentNode != null) |
5651 |
08 Jun 11 |
nicklas |
78 |
{ |
5651 |
08 Jun 11 |
nicklas |
79 |
Node parentItemNode = parentNode.getNodeType() == Type.ITEM ? parentNode : parentNode.getParent(); |
5651 |
08 Jun 11 |
nicklas |
80 |
Item parentType = parentItemNode.getItemType(); |
5651 |
08 Jun 11 |
nicklas |
81 |
|
5651 |
08 Jun 11 |
nicklas |
82 |
if (parentType == Item.EXTRACT) |
5651 |
08 Jun 11 |
nicklas |
83 |
{ |
5651 |
08 Jun 11 |
nicklas |
84 |
checkExtractSubtype(dc, context, node, parentItemNode); |
5651 |
08 Jun 11 |
nicklas |
85 |
} |
5807 |
14 Oct 11 |
nicklas |
86 |
else if (parentType == Item.DERIVEDBIOASSAY) |
5807 |
14 Oct 11 |
nicklas |
87 |
{ |
5807 |
14 Oct 11 |
nicklas |
88 |
DerivedBioAssayValidator.checkPhysicalBioAssaySubtype(dc, context, parentItemNode, node); |
5807 |
14 Oct 11 |
nicklas |
89 |
} |
5651 |
08 Jun 11 |
nicklas |
90 |
} |
5651 |
08 Jun 11 |
nicklas |
91 |
} |
5651 |
08 Jun 11 |
nicklas |
92 |
|
4740 |
05 Feb 09 |
nicklas |
93 |
/** |
5652 |
10 Jun 11 |
nicklas |
@return Always null (since it can never be missing) |
4740 |
05 Feb 09 |
nicklas |
95 |
*/ |
4740 |
05 Feb 09 |
nicklas |
96 |
@Override |
5651 |
08 Jun 11 |
nicklas |
97 |
protected Fix getMissingItemFix(DbControl dc, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
98 |
{ |
5652 |
10 Jun 11 |
nicklas |
99 |
return null; |
4740 |
05 Feb 09 |
nicklas |
100 |
} |
4740 |
05 Feb 09 |
nicklas |
101 |
// ---------------------------- |
4740 |
05 Feb 09 |
nicklas |
102 |
|
5651 |
08 Jun 11 |
nicklas |
103 |
|
5651 |
08 Jun 11 |
nicklas |
104 |
/** |
5651 |
08 Jun 11 |
nicklas |
Check the subtype of the extract that is the parent to a physical bioassay. Given that |
5651 |
08 Jun 11 |
nicklas |
the bioassay has a non-null subtype, which has a related EXTRACT subtype, this |
5651 |
08 Jun 11 |
nicklas |
method checks if the parent extract has the same subtype. If there is no related |
5651 |
08 Jun 11 |
nicklas |
subtype for the bioassay, any subtype for the parent is accepted. |
5651 |
08 Jun 11 |
nicklas |
109 |
*/ |
5651 |
08 Jun 11 |
nicklas |
110 |
public static void checkExtractSubtype(DbControl dc, OverviewContext context, Node bioAssayNode, Node extractNode) |
5651 |
08 Jun 11 |
nicklas |
111 |
{ |
5807 |
14 Oct 11 |
nicklas |
112 |
PhysicalBioAssay bioAssay = (PhysicalBioAssay)bioAssayNode.getItem(dc); |
5807 |
14 Oct 11 |
nicklas |
113 |
Extract extract = (Extract)extractNode.getItem(dc); |
5651 |
08 Jun 11 |
nicklas |
114 |
|
5651 |
08 Jun 11 |
nicklas |
115 |
try |
5651 |
08 Jun 11 |
nicklas |
116 |
{ |
5651 |
08 Jun 11 |
nicklas |
117 |
ItemSubtype expectedSubtype = ItemSubtype.getRelatedSubtype(dc, bioAssay, Item.EXTRACT, 0); |
5651 |
08 Jun 11 |
nicklas |
118 |
ItemSubtype subtype = extract.getItemSubtype(); |
5651 |
08 Jun 11 |
nicklas |
119 |
|
5651 |
08 Jun 11 |
nicklas |
120 |
if (expectedSubtype != null && !expectedSubtype.equals(subtype)) |
5651 |
08 Jun 11 |
nicklas |
121 |
{ |
5807 |
14 Oct 11 |
nicklas |
122 |
ItemSubtype mySubtype = bioAssay.getItemSubtype(); |
5807 |
14 Oct 11 |
nicklas |
123 |
Fix subtypeFix = subtype == null ? null : |
5807 |
14 Oct 11 |
nicklas |
124 |
new Fix("Change related extract subtype of '" + mySubtype.getName() + |
5807 |
14 Oct 11 |
nicklas |
125 |
"' to '" + subtype.getName() + "'", mySubtype); |
5807 |
14 Oct 11 |
nicklas |
126 |
|
5651 |
08 Jun 11 |
nicklas |
127 |
context.createFailure(Validator.INCORRECT_EXTRACT_TYPE, bioAssayNode, |
5807 |
14 Oct 11 |
nicklas |
128 |
"Expected an extract with subtype: " + expectedSubtype.getName(), |
5807 |
14 Oct 11 |
nicklas |
129 |
new Fix("Change subtype of '" + extract.getName() + "' to '" + expectedSubtype.getName() + "'", extract), |
5807 |
14 Oct 11 |
nicklas |
130 |
new Fix("Change subtype or parent of '" + bioAssayNode.getTitle() + "'", bioAssay), |
5807 |
14 Oct 11 |
nicklas |
131 |
subtypeFix |
5651 |
08 Jun 11 |
nicklas |
132 |
); |
5651 |
08 Jun 11 |
nicklas |
133 |
} |
5651 |
08 Jun 11 |
nicklas |
134 |
} |
5651 |
08 Jun 11 |
nicklas |
135 |
catch (PermissionDeniedException ex) |
5651 |
08 Jun 11 |
nicklas |
136 |
{} |
5651 |
08 Jun 11 |
nicklas |
137 |
} |
5651 |
08 Jun 11 |
nicklas |
138 |
|
6098 |
03 Sep 12 |
nicklas |
139 |
/** |
6098 |
03 Sep 12 |
nicklas |
Get all physical bioassays that are parents to the given derived bioassay. This is a |
6098 |
03 Sep 12 |
nicklas |
utility method that provides caching support so that queries don't have to be repeated |
6098 |
03 Sep 12 |
nicklas |
for the same derived bioassay. |
6098 |
03 Sep 12 |
nicklas |
@since 3.2 |
6098 |
03 Sep 12 |
nicklas |
144 |
*/ |
6098 |
03 Sep 12 |
nicklas |
145 |
@SuppressWarnings("unchecked") |
6098 |
03 Sep 12 |
nicklas |
146 |
public static List<PhysicalBioAssay> getPhysicalBioAssays(DbControl dc, OverviewContext context, DerivedBioAssay bioAssay) |
6098 |
03 Sep 12 |
nicklas |
147 |
{ |
6098 |
03 Sep 12 |
nicklas |
148 |
String cacheKey = "derivedbioassay." + bioAssay.getId() + ".physicalbioassays"; |
6098 |
03 Sep 12 |
nicklas |
149 |
List<PhysicalBioAssay> physicalBioAssays = (List<PhysicalBioAssay>)context.getCachedObject(cacheKey); |
6098 |
03 Sep 12 |
nicklas |
150 |
|
6098 |
03 Sep 12 |
nicklas |
151 |
if (physicalBioAssays == null) |
6098 |
03 Sep 12 |
nicklas |
152 |
{ |
6098 |
03 Sep 12 |
nicklas |
153 |
ItemQuery<PhysicalBioAssay> query = bioAssay.getPhysicalBioAssays(); |
6098 |
03 Sep 12 |
nicklas |
154 |
query.include(Include.ALL); |
6098 |
03 Sep 12 |
nicklas |
155 |
physicalBioAssays = new ArrayList<PhysicalBioAssay>(query.list(dc)); |
6098 |
03 Sep 12 |
nicklas |
156 |
context.setCachedObject(cacheKey, physicalBioAssays); |
6098 |
03 Sep 12 |
nicklas |
157 |
} |
6098 |
03 Sep 12 |
nicklas |
158 |
return physicalBioAssays; |
6098 |
03 Sep 12 |
nicklas |
159 |
} |
6098 |
03 Sep 12 |
nicklas |
160 |
|
6098 |
03 Sep 12 |
nicklas |
161 |
/** |
6098 |
03 Sep 12 |
nicklas |
Get all parent extracts that are associated with the given physical bioassay. |
6098 |
03 Sep 12 |
nicklas |
@since 3.2 |
6098 |
03 Sep 12 |
nicklas |
164 |
*/ |
6098 |
03 Sep 12 |
nicklas |
165 |
@SuppressWarnings("unchecked") |
6098 |
03 Sep 12 |
nicklas |
166 |
public static Set<Extract> getAllParentExtracts(DbControl dc, OverviewContext context, PhysicalBioAssay bioAssay) |
6098 |
03 Sep 12 |
nicklas |
167 |
{ |
6098 |
03 Sep 12 |
nicklas |
168 |
String cacheKey = "physicalbioassay." + bioAssay.getId() + ".extracts"; |
6098 |
03 Sep 12 |
nicklas |
169 |
Set<Extract> allExtracts = (Set<Extract>)context.getCachedObject(cacheKey); |
6098 |
03 Sep 12 |
nicklas |
170 |
|
6098 |
03 Sep 12 |
nicklas |
171 |
if (allExtracts == null) |
6098 |
03 Sep 12 |
nicklas |
172 |
{ |
6098 |
03 Sep 12 |
nicklas |
173 |
ItemQuery<Extract> query = bioAssay.getExtracts(0); |
6098 |
03 Sep 12 |
nicklas |
174 |
query.include(Include.ALL); |
6799 |
25 Mar 15 |
nicklas |
175 |
|
6799 |
25 Mar 15 |
nicklas |
176 |
SourceItemTransformer transformer = new ExtractToParentExtractTransformer(true); |
6799 |
25 Mar 15 |
nicklas |
177 |
Set<Integer> extractIds = transformer.transform(new TransformContext(dc), new HashSet<Integer>(query.idList(dc))); |
6799 |
25 Mar 15 |
nicklas |
178 |
|
6799 |
25 Mar 15 |
nicklas |
179 |
allExtracts = new HashSet<Extract>(extractIds.size()); |
6799 |
25 Mar 15 |
nicklas |
180 |
for (int id : extractIds) |
6799 |
25 Mar 15 |
nicklas |
181 |
{ |
6799 |
25 Mar 15 |
nicklas |
182 |
allExtracts.add(Extract.getById(dc, id)); |
6799 |
25 Mar 15 |
nicklas |
183 |
} |
6098 |
03 Sep 12 |
nicklas |
184 |
context.setCachedObject(cacheKey, allExtracts); |
6098 |
03 Sep 12 |
nicklas |
185 |
} |
6098 |
03 Sep 12 |
nicklas |
186 |
return allExtracts; |
6098 |
03 Sep 12 |
nicklas |
187 |
} |
6098 |
03 Sep 12 |
nicklas |
188 |
|
4740 |
05 Feb 09 |
nicklas |
189 |
} |