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; |
4740 |
05 Feb 09 |
nicklas |
23 |
|
4745 |
10 Feb 09 |
nicklas |
24 |
import java.util.Arrays; |
4745 |
10 Feb 09 |
nicklas |
25 |
import java.util.Collections; |
4745 |
10 Feb 09 |
nicklas |
26 |
import java.util.LinkedHashMap; |
4745 |
10 Feb 09 |
nicklas |
27 |
import java.util.List; |
4745 |
10 Feb 09 |
nicklas |
28 |
import java.util.Map; |
4745 |
10 Feb 09 |
nicklas |
29 |
|
4743 |
09 Feb 09 |
nicklas |
30 |
import java.util.HashSet; |
4743 |
09 Feb 09 |
nicklas |
31 |
import java.util.Set; |
4743 |
09 Feb 09 |
nicklas |
32 |
|
7527 |
07 Nov 18 |
nicklas |
33 |
import org.apache.commons.collections4.IteratorUtils; |
6047 |
18 Apr 12 |
nicklas |
34 |
|
4743 |
09 Feb 09 |
nicklas |
35 |
import net.sf.basedb.core.Annotatable; |
4743 |
09 Feb 09 |
nicklas |
36 |
import net.sf.basedb.core.AnnotationType; |
6047 |
18 Apr 12 |
nicklas |
37 |
import net.sf.basedb.core.Application; |
4740 |
05 Feb 09 |
nicklas |
38 |
import net.sf.basedb.core.BasicItem; |
4740 |
05 Feb 09 |
nicklas |
39 |
import net.sf.basedb.core.DbControl; |
5985 |
24 Feb 12 |
nicklas |
40 |
import net.sf.basedb.core.ItemSubtype; |
4745 |
10 Feb 09 |
nicklas |
41 |
import net.sf.basedb.core.Presets; |
4743 |
09 Feb 09 |
nicklas |
42 |
import net.sf.basedb.core.Item; |
4743 |
09 Feb 09 |
nicklas |
43 |
import net.sf.basedb.core.ItemQuery; |
4743 |
09 Feb 09 |
nicklas |
44 |
import net.sf.basedb.core.ItemResultIterator; |
4740 |
05 Feb 09 |
nicklas |
45 |
import net.sf.basedb.core.Project; |
4745 |
10 Feb 09 |
nicklas |
46 |
import net.sf.basedb.core.SessionControl; |
5985 |
24 Feb 12 |
nicklas |
47 |
import net.sf.basedb.core.Subtypable; |
4743 |
09 Feb 09 |
nicklas |
48 |
import net.sf.basedb.core.Type; |
4743 |
09 Feb 09 |
nicklas |
49 |
import net.sf.basedb.core.query.Expressions; |
4743 |
09 Feb 09 |
nicklas |
50 |
import net.sf.basedb.core.query.Hql; |
4743 |
09 Feb 09 |
nicklas |
51 |
import net.sf.basedb.core.query.Restrictions; |
6091 |
24 Aug 12 |
nicklas |
52 |
import net.sf.basedb.util.AnnotationUtil; |
6091 |
24 Aug 12 |
nicklas |
53 |
import net.sf.basedb.util.AnnotationUtil.Cache; |
6047 |
18 Apr 12 |
nicklas |
54 |
import net.sf.basedb.util.extensions.ClientContext; |
6047 |
18 Apr 12 |
nicklas |
55 |
import net.sf.basedb.util.extensions.ExtensionsInvoker; |
6047 |
18 Apr 12 |
nicklas |
56 |
import net.sf.basedb.util.extensions.Registry; |
6088 |
21 Aug 12 |
nicklas |
57 |
import net.sf.basedb.util.extensions.manager.Settings; |
6047 |
18 Apr 12 |
nicklas |
58 |
import net.sf.basedb.util.overview.extensions.ValidationRuleAction; |
4740 |
05 Feb 09 |
nicklas |
59 |
import net.sf.basedb.util.overview.filter.BasicItemFilter; |
4740 |
05 Feb 09 |
nicklas |
60 |
|
4740 |
05 Feb 09 |
nicklas |
61 |
/** |
4767 |
17 Feb 09 |
nicklas |
Utility class for the overview generation functionality. |
4740 |
05 Feb 09 |
nicklas |
63 |
|
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 |
67 |
*/ |
4745 |
10 Feb 09 |
nicklas |
68 |
public final class OverviewUtil |
4740 |
05 Feb 09 |
nicklas |
69 |
{ |
4740 |
05 Feb 09 |
nicklas |
70 |
|
6047 |
18 Apr 12 |
nicklas |
71 |
private static Map<String, List<ValidationRuleAction>> staticRules; |
4745 |
10 Feb 09 |
nicklas |
72 |
|
4767 |
17 Feb 09 |
nicklas |
73 |
/** |
6047 |
18 Apr 12 |
nicklas |
Get all static (built-in) validation rules grouped by relationship. The key of the map |
4767 |
17 Feb 09 |
nicklas |
is a title that groups related validation rules, for example: |
4767 |
17 Feb 09 |
nicklas |
"Project default", "Missing items", etc. |
4767 |
17 Feb 09 |
nicklas |
@return A map with a string key and list of validation rules |
4767 |
17 Feb 09 |
nicklas |
as value |
6047 |
18 Apr 12 |
nicklas |
@since 3.2 |
4767 |
17 Feb 09 |
nicklas |
80 |
*/ |
6047 |
18 Apr 12 |
nicklas |
81 |
public static Map<String, List<ValidationRuleAction>> getStaticRules() |
4745 |
10 Feb 09 |
nicklas |
82 |
{ |
6047 |
18 Apr 12 |
nicklas |
83 |
if (staticRules == null) |
4745 |
10 Feb 09 |
nicklas |
84 |
{ |
6047 |
18 Apr 12 |
nicklas |
85 |
Map<String, List<ValidationRuleAction>> temp = new LinkedHashMap<String, List<ValidationRuleAction>>(); |
4745 |
10 Feb 09 |
nicklas |
86 |
temp.put("Project defaults", |
6047 |
18 Apr 12 |
nicklas |
87 |
Arrays.asList(new ValidationRuleAction[] |
4745 |
10 Feb 09 |
nicklas |
88 |
{ |
4745 |
10 Feb 09 |
nicklas |
89 |
Validator.NONDEFAULT_PLATFORM, |
4745 |
10 Feb 09 |
nicklas |
90 |
Validator.NONDEFAULT_RAWDATATYPE, Validator.NONDEFAULT_ARRAYDESIGN, |
4745 |
10 Feb 09 |
nicklas |
91 |
Validator.NONDEFAULT_PROTOCOL, Validator.NONDEFAULT_HARDWARE, |
4745 |
10 Feb 09 |
nicklas |
92 |
Validator.NONDEFAULT_SOFTWARE |
4745 |
10 Feb 09 |
nicklas |
93 |
}) |
4745 |
10 Feb 09 |
nicklas |
94 |
); |
4745 |
10 Feb 09 |
nicklas |
95 |
temp.put("Missing items", |
6047 |
18 Apr 12 |
nicklas |
96 |
Arrays.asList(new ValidationRuleAction[] |
4745 |
10 Feb 09 |
nicklas |
97 |
{ |
4745 |
10 Feb 09 |
nicklas |
98 |
Validator.MISSING_BIOSOURCE, Validator.MISSING_SAMPLE, Validator.MISSING_EXTRACT, |
6042 |
03 Apr 12 |
nicklas |
99 |
Validator.MISSING_BIOPLATE, Validator.MISSING_PHYSICALBIOASSAY, |
5807 |
14 Oct 11 |
nicklas |
100 |
Validator.MISSING_DERIVEDBIOASSAY, Validator.MISSING_ARRAYDESIGN, Validator.MISSING_PROTOCOL, |
5651 |
08 Jun 11 |
nicklas |
101 |
Validator.MISSING_HARDWARE, Validator.MISSING_SOFTWARE, Validator.MISSING_TAG, |
7861 |
21 Oct 20 |
nicklas |
102 |
Validator.MISSING_KIT, Validator.MISSING_FILE, |
5500 |
18 Nov 10 |
nicklas |
103 |
Validator.MISSING_ARRAYSLIDE, Validator.MISSING_ARRAYBATCH, Validator.MISSING_ANYTOANY |
4745 |
10 Feb 09 |
nicklas |
104 |
}) |
4745 |
10 Feb 09 |
nicklas |
105 |
); |
5651 |
08 Jun 11 |
nicklas |
106 |
temp.put("Subtypes", |
6047 |
18 Apr 12 |
nicklas |
107 |
Arrays.asList(new ValidationRuleAction[] |
5651 |
08 Jun 11 |
nicklas |
108 |
{ |
5651 |
08 Jun 11 |
nicklas |
109 |
Validator.INCORRECT_BIOSOURCE_TYPE, Validator.INCORRECT_SAMPLE_TYPE, |
6042 |
03 Apr 12 |
nicklas |
110 |
Validator.INCORRECT_EXTRACT_TYPE, Validator.INCORRECT_BIOMATERIAL_TYPE, |
6042 |
03 Apr 12 |
nicklas |
111 |
Validator.INCORRECT_PHYSICALBIOASSAY_TYPE, |
5807 |
14 Oct 11 |
nicklas |
112 |
Validator.INCORRECT_DERIVEDBIOASSAY_TYPE, Validator.INCORRECT_PROTOCOLTYPE, |
5651 |
08 Jun 11 |
nicklas |
113 |
Validator.INCORRECT_HARDWARETYPE, Validator.INCORRECT_SOFTWARETYPE, |
7861 |
21 Oct 20 |
nicklas |
114 |
Validator.INCORRECT_TAGTYPE, Validator.INCORRECT_KITTYPE, Validator.INCORRECT_FILETYPE |
5651 |
08 Jun 11 |
nicklas |
115 |
}) |
5651 |
08 Jun 11 |
nicklas |
116 |
); |
4745 |
10 Feb 09 |
nicklas |
117 |
temp.put("Annotations", |
6047 |
18 Apr 12 |
nicklas |
118 |
Arrays.asList(new ValidationRuleAction[] |
4745 |
10 Feb 09 |
nicklas |
119 |
{ |
4745 |
10 Feb 09 |
nicklas |
120 |
Validator.MISSING_MIAME_ANNOTATION, Validator.MISSING_FACTORVALUE, |
4745 |
10 Feb 09 |
nicklas |
121 |
Validator.MISSING_PARAMETER, Validator.ANNOTATION_IS_PARAMETER, |
6024 |
23 Mar 12 |
nicklas |
122 |
Validator.ANNOTATION_INVALID_VALUE, Validator.ANNOTATION_TOO_MANY_VALUES, |
6024 |
23 Mar 12 |
nicklas |
123 |
Validator.ANNOTATION_INVALID_ITEM, |
4752 |
11 Feb 09 |
nicklas |
124 |
Validator.ANNOTATION_INHERIT_FROM_NONPARENT, |
6960 |
01 Oct 15 |
nicklas |
125 |
Validator.ANNOTATION_CLONED_FROM_UNKNOWNPARENT, Validator.ANNOTATION_CLONE_OUTOFSYNC, |
4752 |
11 Feb 09 |
nicklas |
126 |
Validator.ANNOTATION_INHERIT_FROM_DENIEDPARENT, |
4752 |
11 Feb 09 |
nicklas |
127 |
Validator.ANNOTATION_INHERIT_MULTIPLE |
4745 |
10 Feb 09 |
nicklas |
128 |
}) |
4745 |
10 Feb 09 |
nicklas |
129 |
); |
4745 |
10 Feb 09 |
nicklas |
130 |
|
4745 |
10 Feb 09 |
nicklas |
131 |
temp.put("Files", |
6047 |
18 Apr 12 |
nicklas |
132 |
Arrays.asList(new ValidationRuleAction[] |
4745 |
10 Feb 09 |
nicklas |
133 |
{ |
4745 |
10 Feb 09 |
nicklas |
134 |
Validator.DATAFILE_INVALID, Validator.DATAFILE_NOTVALIDATED, |
4745 |
10 Feb 09 |
nicklas |
135 |
Validator.MISSING_DATAFILE, Validator.DATAFILE_NOTPLATFORM, |
5721 |
06 Sep 11 |
nicklas |
136 |
Validator.DATAFILE_TOOMANYFILES, |
4752 |
11 Feb 09 |
nicklas |
137 |
Validator.DATAFILE_INVALID_ITEM, Validator.DENIED_DATAFILETYPE, |
4752 |
11 Feb 09 |
nicklas |
138 |
Validator.DENIED_FILE |
4745 |
10 Feb 09 |
nicklas |
139 |
}) |
4745 |
10 Feb 09 |
nicklas |
140 |
); |
4745 |
10 Feb 09 |
nicklas |
141 |
|
4745 |
10 Feb 09 |
nicklas |
142 |
temp.put("Denied access", |
6047 |
18 Apr 12 |
nicklas |
143 |
Arrays.asList(new ValidationRuleAction[] |
5807 |
14 Oct 11 |
nicklas |
144 |
{ |
6042 |
03 Apr 12 |
nicklas |
145 |
Validator.DENIED_BIOSOURCE, Validator.DENIED_SAMPLE, Validator.DENIED_EXTRACT, Validator.DENIED_BIOPLATE, |
5807 |
14 Oct 11 |
nicklas |
146 |
Validator.DENIED_TAG, Validator.DENIED_PHYSICALBIOASSAY, Validator.DENIED_DERIVEDBIOASSAY, |
7005 |
09 Nov 15 |
nicklas |
147 |
Validator.DENIED_ARRAYDESIGN, Validator.DENIED_PLATFORM, Validator.DENIED_PROTOCOL, |
7005 |
09 Nov 15 |
nicklas |
148 |
Validator.DENIED_HARDWARE, Validator.DENIED_SOFTWARE, Validator.DENIED_KIT, |
7005 |
09 Nov 15 |
nicklas |
149 |
Validator.DENIED_ARRAYSLIDE, Validator.DENIED_ARRAYBATCH, |
5500 |
18 Nov 10 |
nicklas |
150 |
Validator.DENIED_ANYTOANY |
5807 |
14 Oct 11 |
nicklas |
151 |
}) |
4745 |
10 Feb 09 |
nicklas |
152 |
); |
4745 |
10 Feb 09 |
nicklas |
153 |
|
5815 |
18 Oct 11 |
nicklas |
154 |
temp.put("Link consistency", |
6047 |
18 Apr 12 |
nicklas |
155 |
Arrays.asList(new ValidationRuleAction[] |
5807 |
14 Oct 11 |
nicklas |
156 |
{ |
5807 |
14 Oct 11 |
nicklas |
157 |
Validator.NONMATHCING_ARRAYDESIGN, Validator.MULTIPLE_ARRAYDESIGNS, |
5807 |
14 Oct 11 |
nicklas |
158 |
Validator.CIRCULAR_REFERENCE, |
5807 |
14 Oct 11 |
nicklas |
159 |
Validator.NONUNIQUE_TAG, Validator.DIFFERENT_TAG, Validator.TAGGED_PARENT, |
5807 |
14 Oct 11 |
nicklas |
160 |
Validator.PARENT_EXTRACT_MISMATCH |
5807 |
14 Oct 11 |
nicklas |
161 |
|
5807 |
14 Oct 11 |
nicklas |
162 |
}) |
5807 |
14 Oct 11 |
nicklas |
163 |
); |
5807 |
14 Oct 11 |
nicklas |
164 |
|
4745 |
10 Feb 09 |
nicklas |
165 |
temp.put("Other", |
6047 |
18 Apr 12 |
nicklas |
166 |
Arrays.asList(new ValidationRuleAction[] |
4745 |
10 Feb 09 |
nicklas |
167 |
{ |
5807 |
14 Oct 11 |
nicklas |
168 |
Validator.NONMATCHING_SPOTCOUNT, Validator.INCORRECT_BIOASSAY_POSITION, |
7005 |
09 Nov 15 |
nicklas |
169 |
Validator.NONUNIQUE_NAME_FOR_TYPE, Validator.NONUNIQUE_NAME_GLOBAL, |
7005 |
09 Nov 15 |
nicklas |
170 |
Validator.KIT_USED_AFTER_EXPIRATIONDATE |
4745 |
10 Feb 09 |
nicklas |
171 |
}) |
4745 |
10 Feb 09 |
nicklas |
172 |
); |
4745 |
10 Feb 09 |
nicklas |
173 |
|
6047 |
18 Apr 12 |
nicklas |
174 |
staticRules = Collections.unmodifiableMap(temp); |
4745 |
10 Feb 09 |
nicklas |
175 |
} |
6047 |
18 Apr 12 |
nicklas |
176 |
|
6047 |
18 Apr 12 |
nicklas |
177 |
return staticRules; |
4745 |
10 Feb 09 |
nicklas |
178 |
} |
4745 |
10 Feb 09 |
nicklas |
179 |
|
4767 |
17 Feb 09 |
nicklas |
180 |
/** |
6047 |
18 Apr 12 |
nicklas |
Get all static and extension validation rules grouped by relationship. The key of the map |
6047 |
18 Apr 12 |
nicklas |
is a title that groups related validation rules, for example: |
6047 |
18 Apr 12 |
nicklas |
"Project default", "Missing items", etc. |
6132 |
14 Sep 12 |
nicklas |
@param dc An open DbControl |
6132 |
14 Sep 12 |
nicklas |
@param overview The overview tree |
6047 |
18 Apr 12 |
nicklas |
@return A map with a string key and list of validation rules |
6047 |
18 Apr 12 |
nicklas |
as value |
6047 |
18 Apr 12 |
nicklas |
@since 3.2 |
6047 |
18 Apr 12 |
nicklas |
189 |
*/ |
6047 |
18 Apr 12 |
nicklas |
190 |
public static Map<String, List<ValidationRuleAction>> getAllRules(DbControl dc, GenericOverview overview) |
6047 |
18 Apr 12 |
nicklas |
191 |
{ |
6047 |
18 Apr 12 |
nicklas |
// Get static rules |
6047 |
18 Apr 12 |
nicklas |
193 |
Map<String, List<ValidationRuleAction>> allRules = new LinkedHashMap<String, List<ValidationRuleAction>>(getStaticRules()); |
6047 |
18 Apr 12 |
nicklas |
// Check extensions registry for more validation rules |
6047 |
18 Apr 12 |
nicklas |
195 |
Registry registry = Application.getExtensionsManager().getRegistry(); |
6088 |
21 Aug 12 |
nicklas |
196 |
Settings settings = Application.getExtensionsManager().getSettings(); |
7605 |
26 Feb 19 |
nicklas |
197 |
ExtensionsInvoker<ValidationRuleAction> invoker = registry.useExtensions(new ClientContext(dc, overview), settings, "net.sf.basedb.util.overview.validationrule"); |
6047 |
18 Apr 12 |
nicklas |
198 |
|
7527 |
07 Nov 18 |
nicklas |
199 |
List<ValidationRuleAction> xtRules = IteratorUtils.toList(invoker.iterator()); |
6047 |
18 Apr 12 |
nicklas |
200 |
if (xtRules != null && xtRules.size() > 0) |
6047 |
18 Apr 12 |
nicklas |
201 |
{ |
6047 |
18 Apr 12 |
nicklas |
202 |
allRules.put("Extensions", xtRules); |
6047 |
18 Apr 12 |
nicklas |
203 |
} |
6047 |
18 Apr 12 |
nicklas |
204 |
return allRules; |
6047 |
18 Apr 12 |
nicklas |
205 |
} |
6047 |
18 Apr 12 |
nicklas |
206 |
|
6047 |
18 Apr 12 |
nicklas |
207 |
|
6047 |
18 Apr 12 |
nicklas |
208 |
/** |
4767 |
17 Feb 09 |
nicklas |
Name of setting to store saved presets. DO NOT CHANGE the name since |
4767 |
17 Feb 09 |
nicklas |
since it is used in the database to store the presets. |
4767 |
17 Feb 09 |
nicklas |
211 |
*/ |
4745 |
10 Feb 09 |
nicklas |
212 |
private static final String presetsSetting = "experiment.overview.presets"; |
4745 |
10 Feb 09 |
nicklas |
213 |
|
4745 |
10 Feb 09 |
nicklas |
214 |
/** |
4745 |
10 Feb 09 |
nicklas |
Get the validation options presets for the currently logged in user. |
4745 |
10 Feb 09 |
nicklas |
If changes are made to the presets call {@link #saveValidationPresets(SessionControl)} |
4745 |
10 Feb 09 |
nicklas |
to make sure the changes are saved to the database. |
4745 |
10 Feb 09 |
nicklas |
218 |
|
4745 |
10 Feb 09 |
nicklas |
@param sc The session control for the logged in user |
4745 |
10 Feb 09 |
nicklas |
@return The validation option presets |
4745 |
10 Feb 09 |
nicklas |
221 |
*/ |
4745 |
10 Feb 09 |
nicklas |
222 |
public static Presets getValidationPresets(SessionControl sc) |
4745 |
10 Feb 09 |
nicklas |
223 |
{ |
4745 |
10 Feb 09 |
nicklas |
224 |
Presets presets = (Presets)sc.getSessionSetting(presetsSetting); |
4745 |
10 Feb 09 |
nicklas |
225 |
if (presets == null) |
4745 |
10 Feb 09 |
nicklas |
226 |
{ |
4745 |
10 Feb 09 |
nicklas |
227 |
String xml = sc.getUserDefaultSetting(presetsSetting); |
4745 |
10 Feb 09 |
nicklas |
228 |
presets = new Presets(); |
4745 |
10 Feb 09 |
nicklas |
229 |
if (xml != null) |
4745 |
10 Feb 09 |
nicklas |
230 |
{ |
4745 |
10 Feb 09 |
nicklas |
231 |
presets.loadFrom(xml); |
4745 |
10 Feb 09 |
nicklas |
232 |
} |
4745 |
10 Feb 09 |
nicklas |
233 |
sc.setSessionSetting(presetsSetting, presets); |
4745 |
10 Feb 09 |
nicklas |
234 |
} |
4745 |
10 Feb 09 |
nicklas |
235 |
return presets; |
4745 |
10 Feb 09 |
nicklas |
236 |
} |
4745 |
10 Feb 09 |
nicklas |
237 |
|
4745 |
10 Feb 09 |
nicklas |
238 |
/** |
4745 |
10 Feb 09 |
nicklas |
Save the validation option presets for the logged in user. The presets |
4745 |
10 Feb 09 |
nicklas |
are stored as user default settings |
4745 |
10 Feb 09 |
nicklas |
({@link SessionControl#setUserDefaultSetting(String, String)}) |
4745 |
10 Feb 09 |
nicklas |
with the name <code>experiment.overview.presets</code> |
4745 |
10 Feb 09 |
nicklas |
@param sc The session control for the logged in user |
4745 |
10 Feb 09 |
nicklas |
244 |
*/ |
4745 |
10 Feb 09 |
nicklas |
245 |
public static void saveValidationPresets(SessionControl sc) |
4745 |
10 Feb 09 |
nicklas |
246 |
{ |
4745 |
10 Feb 09 |
nicklas |
247 |
Presets presets = getValidationPresets(sc); |
4745 |
10 Feb 09 |
nicklas |
248 |
if (presets != null) |
4745 |
10 Feb 09 |
nicklas |
249 |
{ |
4745 |
10 Feb 09 |
nicklas |
250 |
sc.setUserDefaultSetting(presetsSetting, presets.asXml()); |
4745 |
10 Feb 09 |
nicklas |
251 |
} |
4745 |
10 Feb 09 |
nicklas |
252 |
} |
4745 |
10 Feb 09 |
nicklas |
253 |
|
4767 |
17 Feb 09 |
nicklas |
254 |
/** |
4767 |
17 Feb 09 |
nicklas |
Create a new overview for the given item and project. The created |
4767 |
17 Feb 09 |
nicklas |
overview is cached and can be retrieved with {@link |
4767 |
17 Feb 09 |
nicklas |
#getCurrentOverview(SessionControl)} or {@link |
4767 |
17 Feb 09 |
nicklas |
#getNewOrCurrentOverview(DbControl, BasicItem, Project)}. |
4767 |
17 Feb 09 |
nicklas |
259 |
|
4767 |
17 Feb 09 |
nicklas |
@param dc A DbControl to use for database access |
4767 |
17 Feb 09 |
nicklas |
@param item The item to generate the overview for |
4767 |
17 Feb 09 |
nicklas |
@param project The project that should be used for validation |
4767 |
17 Feb 09 |
nicklas |
of default items |
4767 |
17 Feb 09 |
nicklas |
@return An overview |
4767 |
17 Feb 09 |
nicklas |
@see #getNewOrCurrentOverview(DbControl, BasicItem, Project) |
4767 |
17 Feb 09 |
nicklas |
@see #getCurrentOverview(SessionControl) |
4767 |
17 Feb 09 |
nicklas |
267 |
*/ |
4745 |
10 Feb 09 |
nicklas |
268 |
public static GenericOverview getNewOverview(DbControl dc, BasicItem item, Project project) |
4745 |
10 Feb 09 |
nicklas |
269 |
{ |
4745 |
10 Feb 09 |
nicklas |
270 |
SessionControl sc = dc.getSessionControl(); |
4745 |
10 Feb 09 |
nicklas |
271 |
GenericOverview overview = new GenericOverview(dc, item, project); |
4745 |
10 Feb 09 |
nicklas |
272 |
sc.setSessionSetting("generic.overview", overview); |
4745 |
10 Feb 09 |
nicklas |
273 |
return overview; |
4745 |
10 Feb 09 |
nicklas |
274 |
} |
4745 |
10 Feb 09 |
nicklas |
275 |
|
4767 |
17 Feb 09 |
nicklas |
276 |
/** |
4767 |
17 Feb 09 |
nicklas |
Get the current overview or create a new overview. This method will first |
4767 |
17 Feb 09 |
nicklas |
check if a cached overview for the same item/project exists. If it does, |
4767 |
17 Feb 09 |
nicklas |
the existing overview is returned, otherwise a new overview is created. |
4767 |
17 Feb 09 |
nicklas |
280 |
|
4767 |
17 Feb 09 |
nicklas |
@param dc A DbControl to use for database access |
4767 |
17 Feb 09 |
nicklas |
@param item The item to generate the overview for |
4767 |
17 Feb 09 |
nicklas |
@param project The project that should be used for validation |
4767 |
17 Feb 09 |
nicklas |
of default items |
4767 |
17 Feb 09 |
nicklas |
@return An overview |
4767 |
17 Feb 09 |
nicklas |
@see #getNewOverview(DbControl, BasicItem, Project) |
4767 |
17 Feb 09 |
nicklas |
@see #getCurrentOverview(SessionControl) |
4767 |
17 Feb 09 |
nicklas |
288 |
*/ |
4767 |
17 Feb 09 |
nicklas |
289 |
public static GenericOverview getNewOrCurrentOverview(DbControl dc, BasicItem item, Project project) |
4745 |
10 Feb 09 |
nicklas |
290 |
{ |
4767 |
17 Feb 09 |
nicklas |
291 |
GenericOverview overview = getCurrentOverview(dc.getSessionControl()); |
4745 |
10 Feb 09 |
nicklas |
292 |
if (overview != null) |
4745 |
10 Feb 09 |
nicklas |
293 |
{ |
4745 |
10 Feb 09 |
nicklas |
294 |
boolean sameItem = item.equals(overview.getRootItem()); |
4745 |
10 Feb 09 |
nicklas |
295 |
boolean sameProject = (project==null && overview.getProject() == null) || |
4745 |
10 Feb 09 |
nicklas |
296 |
(project != null && project.equals(overview.getProject())); |
4745 |
10 Feb 09 |
nicklas |
297 |
if (!sameItem || !sameProject) overview = null; |
4745 |
10 Feb 09 |
nicklas |
298 |
} |
4745 |
10 Feb 09 |
nicklas |
299 |
if (overview == null) |
4745 |
10 Feb 09 |
nicklas |
300 |
{ |
4767 |
17 Feb 09 |
nicklas |
301 |
overview = getNewOverview(dc, item, project); |
4745 |
10 Feb 09 |
nicklas |
302 |
} |
4745 |
10 Feb 09 |
nicklas |
303 |
return overview; |
4745 |
10 Feb 09 |
nicklas |
304 |
} |
4745 |
10 Feb 09 |
nicklas |
305 |
|
4767 |
17 Feb 09 |
nicklas |
306 |
/** |
4767 |
17 Feb 09 |
nicklas |
Get the currently cached overview. |
4767 |
17 Feb 09 |
nicklas |
@param sc The session control that contains the cached overview |
4767 |
17 Feb 09 |
nicklas |
@return An overview, or null if no current overview exists |
4767 |
17 Feb 09 |
nicklas |
310 |
*/ |
4767 |
17 Feb 09 |
nicklas |
311 |
public static GenericOverview getCurrentOverview(SessionControl sc) |
4745 |
10 Feb 09 |
nicklas |
312 |
{ |
4767 |
17 Feb 09 |
nicklas |
313 |
return (GenericOverview)sc.getSessionSetting("generic.overview"); |
4745 |
10 Feb 09 |
nicklas |
314 |
} |
4745 |
10 Feb 09 |
nicklas |
315 |
|
4767 |
17 Feb 09 |
nicklas |
316 |
/** |
4767 |
17 Feb 09 |
nicklas |
Find the first parent node that has a reference to the given item. |
4767 |
17 Feb 09 |
nicklas |
@param node The node to start looking at |
4767 |
17 Feb 09 |
nicklas |
@param item The item to look for |
4767 |
17 Feb 09 |
nicklas |
@return The first parent node (including the given) that has a reference to |
4767 |
17 Feb 09 |
nicklas |
the given item, or null if no such node exists |
4767 |
17 Feb 09 |
nicklas |
322 |
*/ |
4740 |
05 Feb 09 |
nicklas |
323 |
public static Node getCircularRef(Node node, BasicItem item) |
4740 |
05 Feb 09 |
nicklas |
324 |
{ |
4767 |
17 Feb 09 |
nicklas |
325 |
if (item.equals(node.getItem())) return node; |
4767 |
17 Feb 09 |
nicklas |
326 |
return node.getFirstParent(new BasicItemFilter(item)); |
4740 |
05 Feb 09 |
nicklas |
327 |
} |
4740 |
05 Feb 09 |
nicklas |
328 |
|
4767 |
17 Feb 09 |
nicklas |
329 |
/** |
5985 |
24 Feb 12 |
nicklas |
Add a restriction to the query that limit the returned result to those items |
5985 |
24 Feb 12 |
nicklas |
that has a subtype with the {@link ItemSubtype#getPushAnnotations()} flag set. |
5985 |
24 Feb 12 |
nicklas |
@since 3.1 |
5985 |
24 Feb 12 |
nicklas |
333 |
*/ |
5985 |
24 Feb 12 |
nicklas |
334 |
public static void restrictToPushAnnotationSubtypes(ItemQuery<? extends Subtypable> query) |
5985 |
24 Feb 12 |
nicklas |
335 |
{ |
5985 |
24 Feb 12 |
nicklas |
336 |
query.join(Hql.innerJoin("itemSubtype", "sbt")); |
5985 |
24 Feb 12 |
nicklas |
337 |
query.restrict(Restrictions.eq(Hql.property("sbt", "pushAnnotations"), Expressions.bool(true))); |
5985 |
24 Feb 12 |
nicklas |
338 |
} |
5985 |
24 Feb 12 |
nicklas |
339 |
|
5985 |
24 Feb 12 |
nicklas |
340 |
/** |
4767 |
17 Feb 09 |
nicklas |
Get all annotation types that has been marked as "Required for MIAME". |
4767 |
17 Feb 09 |
nicklas |
The annotation types found by this method will be cached in the overview |
4767 |
17 Feb 09 |
nicklas |
context. Subsequent calls will return the cached annotation types. |
4767 |
17 Feb 09 |
nicklas |
344 |
|
4767 |
17 Feb 09 |
nicklas |
@param dc A DbControl to use for database access |
4767 |
17 Feb 09 |
nicklas |
@param context The current overview context (will be used to prepare |
4767 |
17 Feb 09 |
nicklas |
the query for annotation types; see {@link OverviewContext#initQuery(ItemQuery, String)} |
4767 |
17 Feb 09 |
nicklas |
@param itemType An optional item type that is used to limit what |
4767 |
17 Feb 09 |
nicklas |
annotation types to look for |
4767 |
17 Feb 09 |
nicklas |
@return A set with the annotation types |
4767 |
17 Feb 09 |
nicklas |
351 |
*/ |
4767 |
17 Feb 09 |
nicklas |
352 |
@SuppressWarnings("unchecked") |
4743 |
09 Feb 09 |
nicklas |
353 |
public static Set<AnnotationType> getMiameAnnotationTypes(DbControl dc, OverviewContext context, Item itemType) |
4743 |
09 Feb 09 |
nicklas |
354 |
{ |
4767 |
17 Feb 09 |
nicklas |
355 |
String cacheKey = "miame.annotationtypes"; |
4767 |
17 Feb 09 |
nicklas |
356 |
if (itemType != null) cacheKey += "." + itemType.name(); |
4743 |
09 Feb 09 |
nicklas |
357 |
Set<AnnotationType> miameAnnotationTypes = |
4743 |
09 Feb 09 |
nicklas |
358 |
(Set<AnnotationType>)context.getCachedObject(cacheKey); |
4743 |
09 Feb 09 |
nicklas |
359 |
|
4743 |
09 Feb 09 |
nicklas |
360 |
if (miameAnnotationTypes == null) |
4743 |
09 Feb 09 |
nicklas |
361 |
{ |
4743 |
09 Feb 09 |
nicklas |
362 |
miameAnnotationTypes = new HashSet<AnnotationType>(); |
4743 |
09 Feb 09 |
nicklas |
363 |
context.setCachedObject(cacheKey, miameAnnotationTypes); |
4743 |
09 Feb 09 |
nicklas |
364 |
|
4743 |
09 Feb 09 |
nicklas |
// Load 'Required for MIAME' annotation types (parameter='false' must also be set) |
4743 |
09 Feb 09 |
nicklas |
366 |
ItemQuery<AnnotationType> query = context.initQuery(AnnotationType.getQuery(itemType), "name"); |
4743 |
09 Feb 09 |
nicklas |
367 |
query.restrict( |
4743 |
09 Feb 09 |
nicklas |
368 |
Restrictions.eq( |
4743 |
09 Feb 09 |
nicklas |
369 |
Hql.property("requiredForMiame"), |
4743 |
09 Feb 09 |
nicklas |
370 |
Expressions.parameter("miameFlag", true, Type.BOOLEAN) |
4743 |
09 Feb 09 |
nicklas |
371 |
) |
4743 |
09 Feb 09 |
nicklas |
372 |
); |
4743 |
09 Feb 09 |
nicklas |
373 |
query.restrict( |
4743 |
09 Feb 09 |
nicklas |
374 |
Restrictions.eq( |
4743 |
09 Feb 09 |
nicklas |
375 |
Hql.property("protocolParameter"), |
4743 |
09 Feb 09 |
nicklas |
376 |
Expressions.parameter("parameterFlag", false, Type.BOOLEAN) |
4743 |
09 Feb 09 |
nicklas |
377 |
) |
4743 |
09 Feb 09 |
nicklas |
378 |
); |
4743 |
09 Feb 09 |
nicklas |
379 |
ItemResultIterator<AnnotationType> it = query.iterate(dc); |
4743 |
09 Feb 09 |
nicklas |
380 |
while (it.hasNext()) |
4743 |
09 Feb 09 |
nicklas |
381 |
{ |
4743 |
09 Feb 09 |
nicklas |
382 |
miameAnnotationTypes.add(it.next()); |
4743 |
09 Feb 09 |
nicklas |
383 |
} |
4743 |
09 Feb 09 |
nicklas |
384 |
} |
4743 |
09 Feb 09 |
nicklas |
385 |
return miameAnnotationTypes; |
4743 |
09 Feb 09 |
nicklas |
386 |
} |
4743 |
09 Feb 09 |
nicklas |
387 |
|
4767 |
17 Feb 09 |
nicklas |
388 |
/** |
4767 |
17 Feb 09 |
nicklas |
Get all annotatable parent items for the given item. The parents that are found by |
4767 |
17 Feb 09 |
nicklas |
this method will be cached in the current overview context. Subsequent calls will |
4767 |
17 Feb 09 |
nicklas |
return the cached information. |
4767 |
17 Feb 09 |
nicklas |
@param dc A DbControl to use for database access |
4767 |
17 Feb 09 |
nicklas |
@param context The current overview context |
4767 |
17 Feb 09 |
nicklas |
@param item The annotatable item that we should find parents for |
4767 |
17 Feb 09 |
nicklas |
@return A set with the parents |
4767 |
17 Feb 09 |
nicklas |
396 |
*/ |
4743 |
09 Feb 09 |
nicklas |
397 |
public static Set<Annotatable> getAnnotatableParents(DbControl dc, OverviewContext context, Annotatable item) |
4743 |
09 Feb 09 |
nicklas |
398 |
{ |
6091 |
24 Aug 12 |
nicklas |
399 |
Cache cache = (Cache)context.getCachedObject("annotatable.parent.cache"); |
6091 |
24 Aug 12 |
nicklas |
400 |
if (cache == null) |
4743 |
09 Feb 09 |
nicklas |
401 |
{ |
6091 |
24 Aug 12 |
nicklas |
402 |
cache = AnnotationUtil.createCache(); |
6091 |
24 Aug 12 |
nicklas |
403 |
context.setCachedObject("annotatable.parent.cache", cache); |
5749 |
19 Sep 11 |
nicklas |
404 |
} |
6091 |
24 Aug 12 |
nicklas |
405 |
return AnnotationUtil.getAllAnnotatableParentItems(dc, item, null, cache); |
4743 |
09 Feb 09 |
nicklas |
406 |
} |
6091 |
24 Aug 12 |
nicklas |
407 |
|
4743 |
09 Feb 09 |
nicklas |
408 |
|
4740 |
05 Feb 09 |
nicklas |
409 |
} |