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; |
4740 |
05 Feb 09 |
nicklas |
25 |
import net.sf.basedb.core.DbControl; |
5136 |
15 Oct 09 |
nicklas |
26 |
import net.sf.basedb.core.FileStoreEnabled; |
4740 |
05 Feb 09 |
nicklas |
27 |
import net.sf.basedb.core.Item; |
4740 |
05 Feb 09 |
nicklas |
28 |
import net.sf.basedb.core.Platform; |
4740 |
05 Feb 09 |
nicklas |
29 |
import net.sf.basedb.core.PlatformVariant; |
4740 |
05 Feb 09 |
nicklas |
30 |
import net.sf.basedb.core.Project; |
4740 |
05 Feb 09 |
nicklas |
31 |
import net.sf.basedb.core.RawBioAssay; |
4740 |
05 Feb 09 |
nicklas |
32 |
import net.sf.basedb.util.overview.Fix; |
4740 |
05 Feb 09 |
nicklas |
33 |
import net.sf.basedb.util.overview.OverviewContext; |
4740 |
05 Feb 09 |
nicklas |
34 |
import net.sf.basedb.util.overview.Validator; |
4740 |
05 Feb 09 |
nicklas |
35 |
import net.sf.basedb.util.overview.Node; |
4740 |
05 Feb 09 |
nicklas |
36 |
|
4740 |
05 Feb 09 |
nicklas |
37 |
/** |
4740 |
05 Feb 09 |
nicklas |
Validator implementation for platforms/variants. Validation rules: |
4740 |
05 Feb 09 |
nicklas |
<ul> |
4740 |
05 Feb 09 |
nicklas |
<li>Access denied: {@link Validator#DENIED_PLATFORM} |
4740 |
05 Feb 09 |
nicklas |
<li>Non-default platform: {@link Validator#NONDEFAULT_PLATFORM} |
4740 |
05 Feb 09 |
nicklas |
</ul> |
4740 |
05 Feb 09 |
nicklas |
43 |
|
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 |
47 |
*/ |
4740 |
05 Feb 09 |
nicklas |
48 |
public class PlatformValidator |
4764 |
16 Feb 09 |
nicklas |
49 |
extends NameableNodeValidator<Platform> |
4740 |
05 Feb 09 |
nicklas |
50 |
{ |
4740 |
05 Feb 09 |
nicklas |
51 |
|
4740 |
05 Feb 09 |
nicklas |
52 |
public PlatformValidator() |
4740 |
05 Feb 09 |
nicklas |
53 |
{ |
4740 |
05 Feb 09 |
nicklas |
54 |
super(null, Validator.DENIED_PLATFORM); |
4740 |
05 Feb 09 |
nicklas |
55 |
} |
4740 |
05 Feb 09 |
nicklas |
56 |
|
4740 |
05 Feb 09 |
nicklas |
57 |
/* |
4740 |
05 Feb 09 |
nicklas |
From BasicNodeValidator class |
4740 |
05 Feb 09 |
nicklas |
59 |
----------------------------- |
4740 |
05 Feb 09 |
nicklas |
60 |
*/ |
4740 |
05 Feb 09 |
nicklas |
61 |
/** |
5218 |
18 Jan 10 |
jari |
Checks if the platform is the same as |
4740 |
05 Feb 09 |
nicklas |
the default for the project. |
4740 |
05 Feb 09 |
nicklas |
64 |
*/ |
4740 |
05 Feb 09 |
nicklas |
65 |
@Override |
4740 |
05 Feb 09 |
nicklas |
66 |
public void postValidate(DbControl dc, OverviewContext context, Node node, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
67 |
{ |
4740 |
05 Feb 09 |
nicklas |
68 |
super.postValidate(dc, context, node, parentNode); |
5807 |
14 Oct 11 |
nicklas |
69 |
Platform platform = (Platform)node.getItem(dc); |
5136 |
15 Oct 09 |
nicklas |
70 |
PlatformVariant variant = null; |
5136 |
15 Oct 09 |
nicklas |
71 |
boolean failedVariant = false; |
5807 |
14 Oct 11 |
nicklas |
72 |
BasicItem parentItem = parentNode.getItem(dc); |
5136 |
15 Oct 09 |
nicklas |
73 |
try |
5136 |
15 Oct 09 |
nicklas |
74 |
{ |
5136 |
15 Oct 09 |
nicklas |
75 |
variant = ((FileStoreEnabled)parentItem).getVariant(); |
5136 |
15 Oct 09 |
nicklas |
76 |
} |
5136 |
15 Oct 09 |
nicklas |
77 |
catch (Throwable t) |
5136 |
15 Oct 09 |
nicklas |
78 |
{ |
5136 |
15 Oct 09 |
nicklas |
// Failure to load the variant is detected by other validators |
5136 |
15 Oct 09 |
nicklas |
80 |
failedVariant = true; |
5136 |
15 Oct 09 |
nicklas |
81 |
} |
4740 |
05 Feb 09 |
nicklas |
82 |
String parentTypeName = parentNode.getItemType().toString().toLowerCase(); |
4740 |
05 Feb 09 |
nicklas |
83 |
boolean canChangePlatform = false; |
4740 |
05 Feb 09 |
nicklas |
84 |
if (parentNode.getItemType() == Item.RAWBIOASSAY) |
4740 |
05 Feb 09 |
nicklas |
85 |
{ |
4740 |
05 Feb 09 |
nicklas |
86 |
RawBioAssay rba = (RawBioAssay)parentItem; |
4740 |
05 Feb 09 |
nicklas |
87 |
canChangePlatform = rba.getNumDbSpots() == 0; |
4740 |
05 Feb 09 |
nicklas |
88 |
} |
4740 |
05 Feb 09 |
nicklas |
89 |
|
5652 |
10 Jun 11 |
nicklas |
90 |
|
5652 |
10 Jun 11 |
nicklas |
91 |
Project project = context.getProject(); |
5652 |
10 Jun 11 |
nicklas |
92 |
if (project != null) |
4740 |
05 Feb 09 |
nicklas |
93 |
{ |
5813 |
18 Oct 11 |
nicklas |
94 |
if (variant != null) |
5652 |
10 Jun 11 |
nicklas |
95 |
{ |
5813 |
18 Oct 11 |
nicklas |
// The item has a platform variant, so we check that |
5814 |
18 Oct 11 |
nicklas |
97 |
if (!project.isDefaultItem(variant) && !project.isDefaultItem(platform) && |
5814 |
18 Oct 11 |
nicklas |
98 |
(project.hasDefaultForItem(variant) || project.hasDefaultForItem(platform))) |
5813 |
18 Oct 11 |
nicklas |
99 |
{ |
5813 |
18 Oct 11 |
nicklas |
100 |
context.createFailure(Validator.NONDEFAULT_PLATFORM, parentNode, null, |
5813 |
18 Oct 11 |
nicklas |
101 |
canChangePlatform ? new Fix("Change platform/variant of " + parentTypeName, parentItem) : null, |
5814 |
18 Oct 11 |
nicklas |
102 |
new Fix("Add '" + variant.getName() + "' as default platform variant to project", project), |
5814 |
18 Oct 11 |
nicklas |
103 |
new Fix("Add '" + platform.getName() + "' as default platform to project", project) |
5813 |
18 Oct 11 |
nicklas |
104 |
); |
5813 |
18 Oct 11 |
nicklas |
105 |
} |
5652 |
10 Jun 11 |
nicklas |
106 |
} |
5813 |
18 Oct 11 |
nicklas |
107 |
else if (!failedVariant) |
5813 |
18 Oct 11 |
nicklas |
108 |
{ |
5813 |
18 Oct 11 |
nicklas |
// The item only has a platform, so we check that |
5814 |
18 Oct 11 |
nicklas |
110 |
if (!project.isDefaultItem(platform) && project.hasDefaultForItem(platform)) |
5813 |
18 Oct 11 |
nicklas |
111 |
{ |
5813 |
18 Oct 11 |
nicklas |
112 |
context.createFailure(Validator.NONDEFAULT_PLATFORM, parentNode, null, |
5813 |
18 Oct 11 |
nicklas |
113 |
canChangePlatform ? new Fix("Change platform of " + parentTypeName, parentItem) : null, |
5813 |
18 Oct 11 |
nicklas |
114 |
new Fix("Add '" + platform.getName() + "' as default platform to project", project) |
5813 |
18 Oct 11 |
nicklas |
115 |
); |
5813 |
18 Oct 11 |
nicklas |
116 |
} |
5813 |
18 Oct 11 |
nicklas |
117 |
} |
4740 |
05 Feb 09 |
nicklas |
118 |
} |
4740 |
05 Feb 09 |
nicklas |
119 |
} |
4740 |
05 Feb 09 |
nicklas |
120 |
|
4740 |
05 Feb 09 |
nicklas |
121 |
/** |
4740 |
05 Feb 09 |
nicklas |
@return Always null |
4740 |
05 Feb 09 |
nicklas |
123 |
*/ |
4740 |
05 Feb 09 |
nicklas |
124 |
@Override |
5651 |
08 Jun 11 |
nicklas |
125 |
protected Fix getMissingItemFix(DbControl dc, Node parentNode) |
4740 |
05 Feb 09 |
nicklas |
126 |
{ |
4740 |
05 Feb 09 |
nicklas |
127 |
return null; |
4740 |
05 Feb 09 |
nicklas |
128 |
} |
4740 |
05 Feb 09 |
nicklas |
129 |
// -------------------------------- |
4740 |
05 Feb 09 |
nicklas |
130 |
} |