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 |
|
4762 |
16 Feb 09 |
nicklas |
24 |
import java.util.HashSet; |
4762 |
16 Feb 09 |
nicklas |
25 |
import java.util.Set; |
4762 |
16 Feb 09 |
nicklas |
26 |
|
4740 |
05 Feb 09 |
nicklas |
27 |
import net.sf.basedb.core.ArrayDesign; |
4740 |
05 Feb 09 |
nicklas |
28 |
import net.sf.basedb.core.BasicItem; |
4740 |
05 Feb 09 |
nicklas |
29 |
import net.sf.basedb.core.DbControl; |
5807 |
14 Oct 11 |
nicklas |
30 |
import net.sf.basedb.core.DerivedBioAssay; |
4762 |
16 Feb 09 |
nicklas |
31 |
import net.sf.basedb.core.Experiment; |
4740 |
05 Feb 09 |
nicklas |
32 |
import net.sf.basedb.core.Item; |
4760 |
16 Feb 09 |
nicklas |
33 |
import net.sf.basedb.core.PermissionDeniedException; |
4740 |
05 Feb 09 |
nicklas |
34 |
import net.sf.basedb.core.Project; |
4760 |
16 Feb 09 |
nicklas |
35 |
import net.sf.basedb.core.RawBioAssay; |
6959 |
01 Oct 15 |
nicklas |
36 |
import net.sf.basedb.core.RootRawBioAssay; |
4740 |
05 Feb 09 |
nicklas |
37 |
import net.sf.basedb.util.overview.Fix; |
4740 |
05 Feb 09 |
nicklas |
38 |
import net.sf.basedb.util.overview.OverviewContext; |
4740 |
05 Feb 09 |
nicklas |
39 |
import net.sf.basedb.util.overview.Validator; |
4740 |
05 Feb 09 |
nicklas |
40 |
import net.sf.basedb.util.overview.filter.ItemTypeFilter; |
4740 |
05 Feb 09 |
nicklas |
41 |
import net.sf.basedb.util.overview.Node; |
4740 |
05 Feb 09 |
nicklas |
42 |
|
4740 |
05 Feb 09 |
nicklas |
43 |
/** |
4740 |
05 Feb 09 |
nicklas |
Validator implementation for array designs. Validation rules: |
4740 |
05 Feb 09 |
nicklas |
<ul> |
4740 |
05 Feb 09 |
nicklas |
<li>Missing item: {@link Validator#MISSING_ARRAYDESIGN} |
4740 |
05 Feb 09 |
nicklas |
<li>Access denied: {@link Validator#DENIED_ARRAYDESIGN} |
4740 |
05 Feb 09 |
nicklas |
<li>Non-default array design: {@link Validator#NONDEFAULT_ARRAYDESIGN} |
4740 |
05 Feb 09 |
nicklas |
<li>Non-matching array design: {@link Validator#NONMATHCING_ARRAYDESIGN} |
4762 |
16 Feb 09 |
nicklas |
<li>Use of multiple array design in an experiment: {@link Validator#MULTIPLE_ARRAYDESIGNS} |
4740 |
05 Feb 09 |
nicklas |
</ul> |
4740 |
05 Feb 09 |
nicklas |
52 |
|
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 |
56 |
*/ |
4740 |
05 Feb 09 |
nicklas |
57 |
public class ArrayDesignValidator |
4764 |
16 Feb 09 |
nicklas |
58 |
extends NameableNodeValidator<ArrayDesign> |
4740 |
05 Feb 09 |
nicklas |
59 |
{ |
4740 |
05 Feb 09 |
nicklas |
60 |
|
4740 |
05 Feb 09 |
nicklas |
61 |
public ArrayDesignValidator() |
4740 |
05 Feb 09 |
nicklas |
62 |
{ |
4740 |
05 Feb 09 |
nicklas |
63 |
super(Validator.MISSING_ARRAYDESIGN, Validator.DENIED_ARRAYDESIGN); |
4740 |
05 Feb 09 |
nicklas |
64 |
} |
4740 |
05 Feb 09 |
nicklas |
65 |
|
4740 |
05 Feb 09 |
nicklas |
66 |
/* |
4740 |
05 Feb 09 |
nicklas |
From BasicValidator class |
4740 |
05 Feb 09 |
nicklas |
68 |
------------------------- |
4740 |
05 Feb 09 |
nicklas |
69 |
*/ |
4740 |
05 Feb 09 |
nicklas |
70 |
@Override |
4740 |
05 Feb 09 |
nicklas |
71 |
public void postValidate(DbControl dc, OverviewContext context, Node node, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
72 |
{ |
4740 |
05 Feb 09 |
nicklas |
73 |
super.postValidate(dc, context, node, parentNode); |
4740 |
05 Feb 09 |
nicklas |
74 |
Project project = context.getProject(); |
4740 |
05 Feb 09 |
nicklas |
75 |
ArrayDesign design = (ArrayDesign)node.getItem(); |
5652 |
10 Jun 11 |
nicklas |
76 |
if (project != null) |
4740 |
05 Feb 09 |
nicklas |
77 |
{ |
5814 |
18 Oct 11 |
nicklas |
78 |
if (!project.isDefaultItem(design) && project.hasDefaultForItem(design)) |
5652 |
10 Jun 11 |
nicklas |
79 |
{ |
5652 |
10 Jun 11 |
nicklas |
80 |
context.createFailure(Validator.NONDEFAULT_ARRAYDESIGN, node, null, |
5652 |
10 Jun 11 |
nicklas |
81 |
new Fix("Change default array design for project", project) |
5652 |
10 Jun 11 |
nicklas |
82 |
); |
5652 |
10 Jun 11 |
nicklas |
83 |
} |
4740 |
05 Feb 09 |
nicklas |
84 |
} |
4740 |
05 Feb 09 |
nicklas |
85 |
|
4740 |
05 Feb 09 |
nicklas |
// Check that a raw bioassay has same "direct" array desing as |
5807 |
14 Oct 11 |
nicklas |
// via physical bioassay->slide... |
6969 |
02 Oct 15 |
nicklas |
88 |
Item parentType = parentNode != null ? parentNode.getItemType() : null; |
6969 |
02 Oct 15 |
nicklas |
89 |
if (parentType == Item.RAWBIOASSAY || parentType == Item.ROOTRAWBIOASSAY) |
4740 |
05 Feb 09 |
nicklas |
90 |
{ |
6959 |
01 Oct 15 |
nicklas |
91 |
RawBioAssay rba = parentType == Item.RAWBIOASSAY ? (RawBioAssay)parentNode.getItem(dc) : ((RootRawBioAssay)parentNode.getItem()).getRawBioAssay(); |
4762 |
16 Feb 09 |
nicklas |
92 |
try |
4740 |
05 Feb 09 |
nicklas |
93 |
{ |
5807 |
14 Oct 11 |
nicklas |
94 |
DerivedBioAssay bioAssay = rba.getParentBioAssay(); |
5807 |
14 Oct 11 |
nicklas |
95 |
if (bioAssay != null) |
4760 |
16 Feb 09 |
nicklas |
96 |
{ |
5807 |
14 Oct 11 |
nicklas |
97 |
ArrayDesign other = bioAssay.getArrayDesign(); |
5807 |
14 Oct 11 |
nicklas |
98 |
if (other != null && !design.equals(other)) |
4760 |
16 Feb 09 |
nicklas |
99 |
{ |
4762 |
16 Feb 09 |
nicklas |
100 |
context.createFailure(Validator.NONMATHCING_ARRAYDESIGN, parentNode, null); |
4760 |
16 Feb 09 |
nicklas |
101 |
} |
4760 |
16 Feb 09 |
nicklas |
102 |
} |
4740 |
05 Feb 09 |
nicklas |
103 |
} |
4762 |
16 Feb 09 |
nicklas |
104 |
catch (PermissionDeniedException ex) |
4762 |
16 Feb 09 |
nicklas |
105 |
{} |
4740 |
05 Feb 09 |
nicklas |
106 |
} |
4762 |
16 Feb 09 |
nicklas |
107 |
|
4762 |
16 Feb 09 |
nicklas |
// Check if experiment is using more than one array design |
5807 |
14 Oct 11 |
nicklas |
109 |
checkExperimentArrayDesign(dc, context, parentNode, design); |
4740 |
05 Feb 09 |
nicklas |
110 |
} |
4740 |
05 Feb 09 |
nicklas |
111 |
|
4762 |
16 Feb 09 |
nicklas |
112 |
@Override |
4762 |
16 Feb 09 |
nicklas |
113 |
public boolean preMissingItem(DbControl dc, OverviewContext context, Node parentNode) |
4762 |
16 Feb 09 |
nicklas |
114 |
{ |
5807 |
14 Oct 11 |
nicklas |
115 |
checkExperimentArrayDesign(dc, context, parentNode, null); |
4762 |
16 Feb 09 |
nicklas |
116 |
return super.preMissingItem(dc, context, parentNode); |
4762 |
16 Feb 09 |
nicklas |
117 |
} |
4762 |
16 Feb 09 |
nicklas |
118 |
|
4740 |
05 Feb 09 |
nicklas |
119 |
/** |
4740 |
05 Feb 09 |
nicklas |
The suggested fix is to add an array design to the |
4740 |
05 Feb 09 |
nicklas |
raw bioassay. |
4740 |
05 Feb 09 |
nicklas |
122 |
*/ |
4740 |
05 Feb 09 |
nicklas |
123 |
@Override |
5651 |
08 Jun 11 |
nicklas |
124 |
protected Fix getMissingItemFix(DbControl dc, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
125 |
{ |
4740 |
05 Feb 09 |
nicklas |
126 |
Fix fix = null; |
4740 |
05 Feb 09 |
nicklas |
127 |
Item parentType = parentNode.getItemType(); |
4740 |
05 Feb 09 |
nicklas |
128 |
BasicItem parentItem = parentNode.getItem(); |
4740 |
05 Feb 09 |
nicklas |
129 |
if (parentType == Item.RAWBIOASSAY) |
4740 |
05 Feb 09 |
nicklas |
130 |
{ |
4740 |
05 Feb 09 |
nicklas |
131 |
fix = new Fix("Add array design to raw bioassay", parentItem); |
4740 |
05 Feb 09 |
nicklas |
132 |
} |
4740 |
05 Feb 09 |
nicklas |
133 |
return fix; |
4740 |
05 Feb 09 |
nicklas |
134 |
} |
4740 |
05 Feb 09 |
nicklas |
135 |
// ---------------------------- |
4762 |
16 Feb 09 |
nicklas |
136 |
|
4762 |
16 Feb 09 |
nicklas |
137 |
/** |
4762 |
16 Feb 09 |
nicklas |
Check if an experiment has used more than one array design. |
4762 |
16 Feb 09 |
nicklas |
The context cache keep a Set with all arraydesign we have |
4762 |
16 Feb 09 |
nicklas |
seen so for for a given experiment (including null) |
4762 |
16 Feb 09 |
nicklas |
141 |
*/ |
4762 |
16 Feb 09 |
nicklas |
142 |
@SuppressWarnings("unchecked") |
5807 |
14 Oct 11 |
nicklas |
143 |
private void checkExperimentArrayDesign(DbControl dc, OverviewContext context, Node parentNode, ArrayDesign design) |
4762 |
16 Feb 09 |
nicklas |
144 |
{ |
4762 |
16 Feb 09 |
nicklas |
// We should only check array design that are connected to raw bioassays |
4762 |
16 Feb 09 |
nicklas |
146 |
if (parentNode == null || parentNode.getItemType() != Item.RAWBIOASSAY) return; |
4762 |
16 Feb 09 |
nicklas |
147 |
|
4762 |
16 Feb 09 |
nicklas |
148 |
Node experimentNode = parentNode.getFirstParent(new ItemTypeFilter(Item.EXPERIMENT)); |
4762 |
16 Feb 09 |
nicklas |
149 |
if (experimentNode != null) |
4762 |
16 Feb 09 |
nicklas |
150 |
{ |
5807 |
14 Oct 11 |
nicklas |
151 |
Experiment exp = (Experiment)experimentNode.getItem(dc); |
4762 |
16 Feb 09 |
nicklas |
152 |
String cacheKey = "experiment." + exp.getId() + ".arraydesign"; |
4762 |
16 Feb 09 |
nicklas |
153 |
Set<ArrayDesign> used = (Set<ArrayDesign>)context.getCachedObject(cacheKey); |
4762 |
16 Feb 09 |
nicklas |
154 |
if (used == null) |
4762 |
16 Feb 09 |
nicklas |
155 |
{ |
4762 |
16 Feb 09 |
nicklas |
156 |
used = new HashSet<ArrayDesign>(); |
4762 |
16 Feb 09 |
nicklas |
157 |
context.setCachedObject(cacheKey, used); |
4762 |
16 Feb 09 |
nicklas |
158 |
} |
4762 |
16 Feb 09 |
nicklas |
159 |
if (used.add(design)) |
4762 |
16 Feb 09 |
nicklas |
160 |
{ |
4762 |
16 Feb 09 |
nicklas |
161 |
if (used.size() == 2) |
4762 |
16 Feb 09 |
nicklas |
162 |
{ |
4762 |
16 Feb 09 |
nicklas |
163 |
context.createFailure(Validator.MULTIPLE_ARRAYDESIGNS, experimentNode, null); |
4762 |
16 Feb 09 |
nicklas |
164 |
} |
4762 |
16 Feb 09 |
nicklas |
165 |
} |
4762 |
16 Feb 09 |
nicklas |
166 |
} |
4762 |
16 Feb 09 |
nicklas |
167 |
} |
4740 |
05 Feb 09 |
nicklas |
168 |
} |