2564 |
08 Aug 14 |
nicklas |
1 |
package net.sf.basedb.reggie.dao; |
2564 |
08 Aug 14 |
nicklas |
2 |
|
2564 |
08 Aug 14 |
nicklas |
3 |
import java.lang.reflect.Field; |
2564 |
08 Aug 14 |
nicklas |
4 |
import java.util.List; |
2564 |
08 Aug 14 |
nicklas |
5 |
|
3837 |
12 Apr 16 |
nicklas |
6 |
import org.json.simple.JSONObject; |
3837 |
12 Apr 16 |
nicklas |
7 |
|
2564 |
08 Aug 14 |
nicklas |
8 |
import net.sf.basedb.core.DbControl; |
2564 |
08 Aug 14 |
nicklas |
9 |
import net.sf.basedb.core.FileServer; |
2564 |
08 Aug 14 |
nicklas |
10 |
import net.sf.basedb.core.Include; |
2564 |
08 Aug 14 |
nicklas |
11 |
import net.sf.basedb.core.InvalidDataException; |
2564 |
08 Aug 14 |
nicklas |
12 |
import net.sf.basedb.core.ItemNotFoundException; |
2564 |
08 Aug 14 |
nicklas |
13 |
import net.sf.basedb.core.ItemQuery; |
2564 |
08 Aug 14 |
nicklas |
14 |
import net.sf.basedb.core.Type; |
2564 |
08 Aug 14 |
nicklas |
15 |
import net.sf.basedb.core.query.Expressions; |
2564 |
08 Aug 14 |
nicklas |
16 |
import net.sf.basedb.core.query.Hql; |
2564 |
08 Aug 14 |
nicklas |
17 |
import net.sf.basedb.core.query.Restrictions; |
2564 |
08 Aug 14 |
nicklas |
18 |
|
2564 |
08 Aug 14 |
nicklas |
19 |
/** |
2564 |
08 Aug 14 |
nicklas |
Used to define file servers for access to external files. |
2564 |
08 Aug 14 |
nicklas |
21 |
|
2564 |
08 Aug 14 |
nicklas |
@author nicklas |
2564 |
08 Aug 14 |
nicklas |
@since 2.16 |
2564 |
08 Aug 14 |
nicklas |
24 |
*/ |
2564 |
08 Aug 14 |
nicklas |
25 |
public class Fileserver |
2564 |
08 Aug 14 |
nicklas |
26 |
{ |
2564 |
08 Aug 14 |
nicklas |
27 |
|
2564 |
08 Aug 14 |
nicklas |
28 |
/** |
3600 |
13 Nov 15 |
nicklas |
The file server containing analyzed data files for SCAN-B samples. |
2564 |
08 Aug 14 |
nicklas |
30 |
*/ |
2564 |
08 Aug 14 |
nicklas |
31 |
public static final Fileserver PROJECT_ARCHIVE = |
2564 |
08 Aug 14 |
nicklas |
32 |
new Fileserver("ProjectArchive", "net.sf.basedb.xfiles.sftp-connection-manager", |
3600 |
13 Nov 15 |
nicklas |
33 |
"File server containing secondary analysis results for SCAN-B samples."); |
7046 |
14 Feb 23 |
nicklas |
34 |
|
7046 |
14 Feb 23 |
nicklas |
35 |
/** |
7046 |
14 Feb 23 |
nicklas |
The file server containing analyzed data files for SCAN-B DNA samples. |
7046 |
14 Feb 23 |
nicklas |
@since 4.45 |
7046 |
14 Feb 23 |
nicklas |
38 |
*/ |
7046 |
14 Feb 23 |
nicklas |
39 |
public static final Fileserver PROJECT_ARCHIVE_DNA = |
7046 |
14 Feb 23 |
nicklas |
40 |
new Fileserver("ProjectArchiveDNA", "net.sf.basedb.xfiles.sftp-connection-manager", |
7046 |
14 Feb 23 |
nicklas |
41 |
"File server containing secondary analysis results for SCAN-B DNA samples."); |
7046 |
14 Feb 23 |
nicklas |
42 |
|
3600 |
13 Nov 15 |
nicklas |
43 |
|
3600 |
13 Nov 15 |
nicklas |
44 |
/** |
3600 |
13 Nov 15 |
nicklas |
The file server containing analyzed data files for |
3600 |
13 Nov 15 |
nicklas |
external samples. |
3600 |
13 Nov 15 |
nicklas |
@since 4.0 |
3600 |
13 Nov 15 |
nicklas |
48 |
*/ |
3600 |
13 Nov 15 |
nicklas |
49 |
public static final Fileserver EXTERNAL_ARCHIVE = |
3600 |
13 Nov 15 |
nicklas |
50 |
new Fileserver("ExternalArchive", "net.sf.basedb.xfiles.sftp-connection-manager", |
3600 |
13 Nov 15 |
nicklas |
51 |
"File server containing secondary analysis results for external samples."); |
2564 |
08 Aug 14 |
nicklas |
52 |
|
2564 |
08 Aug 14 |
nicklas |
53 |
/** |
4431 |
29 Mar 17 |
nicklas |
The file server for exporting data releases. |
4431 |
29 Mar 17 |
nicklas |
@since 4.10 |
4431 |
29 Mar 17 |
nicklas |
56 |
*/ |
4431 |
29 Mar 17 |
nicklas |
57 |
public static final Fileserver RELEASE_ARCHIVE = |
4431 |
29 Mar 17 |
nicklas |
58 |
new Fileserver("ReleaseArchive", "net.sf.basedb.xfiles.sftp-connection-manager", |
4431 |
29 Mar 17 |
nicklas |
59 |
"File server for exporting released data to other servers."); |
4431 |
29 Mar 17 |
nicklas |
60 |
|
4431 |
29 Mar 17 |
nicklas |
61 |
/** |
6177 |
23 Mar 21 |
nicklas |
The file server containing data files coming from external labs |
6209 |
13 Apr 21 |
nicklas |
that we should import. This is a temporary location and the |
6209 |
13 Apr 21 |
nicklas |
files will be moved to IMPORT_ARCHIVE after the import. |
6177 |
23 Mar 21 |
nicklas |
@since 4.32 |
6177 |
23 Mar 21 |
nicklas |
66 |
*/ |
6209 |
13 Apr 21 |
nicklas |
67 |
public static final Fileserver IMPORT_GATEWAY = |
6209 |
13 Apr 21 |
nicklas |
68 |
new Fileserver("ImportGateway", "net.sf.basedb.xfiles.sftp-connection-manager", |
6209 |
13 Apr 21 |
nicklas |
69 |
"File server containing data from external labs that should be imported. " + |
6209 |
13 Apr 21 |
nicklas |
70 |
"This is a temporary storage location and the files will be moved to ImportArchive."); |
6209 |
13 Apr 21 |
nicklas |
71 |
|
6209 |
13 Apr 21 |
nicklas |
72 |
/** |
6209 |
13 Apr 21 |
nicklas |
The file server containing data files coming from external labs |
6209 |
13 Apr 21 |
nicklas |
after they have been imported. |
6209 |
13 Apr 21 |
nicklas |
@since 4.32 |
6209 |
13 Apr 21 |
nicklas |
76 |
*/ |
6177 |
23 Mar 21 |
nicklas |
77 |
public static final Fileserver IMPORT_ARCHIVE = |
6177 |
23 Mar 21 |
nicklas |
78 |
new Fileserver("ImportArchive", "net.sf.basedb.xfiles.sftp-connection-manager", |
6209 |
13 Apr 21 |
nicklas |
79 |
"File server containing data from external labs after they have been imported."); |
6177 |
23 Mar 21 |
nicklas |
80 |
|
6209 |
13 Apr 21 |
nicklas |
81 |
|
6177 |
23 Mar 21 |
nicklas |
82 |
/** |
2564 |
08 Aug 14 |
nicklas |
Get the file server by name of the static constant defined in this class. |
2564 |
08 Aug 14 |
nicklas |
84 |
|
2564 |
08 Aug 14 |
nicklas |
@param cName The name of the static constant |
2564 |
08 Aug 14 |
nicklas |
@return A bioplate type object or null if not found |
2564 |
08 Aug 14 |
nicklas |
87 |
*/ |
2564 |
08 Aug 14 |
nicklas |
88 |
public static Fileserver getByCName(String cName) |
2564 |
08 Aug 14 |
nicklas |
89 |
{ |
2564 |
08 Aug 14 |
nicklas |
90 |
if (cName == null) return null; |
2564 |
08 Aug 14 |
nicklas |
91 |
Fileserver fs = null; |
2564 |
08 Aug 14 |
nicklas |
92 |
try |
2564 |
08 Aug 14 |
nicklas |
93 |
{ |
2564 |
08 Aug 14 |
nicklas |
94 |
Field f = Fileserver.class.getDeclaredField(cName); |
2564 |
08 Aug 14 |
nicklas |
95 |
fs = (Fileserver)f.get(null); |
2564 |
08 Aug 14 |
nicklas |
96 |
} |
2564 |
08 Aug 14 |
nicklas |
97 |
catch (NoSuchFieldException ex) |
2564 |
08 Aug 14 |
nicklas |
98 |
{} |
2564 |
08 Aug 14 |
nicklas |
99 |
catch (IllegalAccessException ex) |
2564 |
08 Aug 14 |
nicklas |
100 |
{} |
2564 |
08 Aug 14 |
nicklas |
101 |
catch (ClassCastException ex) |
2564 |
08 Aug 14 |
nicklas |
102 |
{} |
2564 |
08 Aug 14 |
nicklas |
103 |
return fs; |
2564 |
08 Aug 14 |
nicklas |
104 |
} |
2564 |
08 Aug 14 |
nicklas |
105 |
|
2564 |
08 Aug 14 |
nicklas |
106 |
private final String name; |
2564 |
08 Aug 14 |
nicklas |
107 |
private final String connectionManagerId; |
2564 |
08 Aug 14 |
nicklas |
108 |
private final String description; |
2564 |
08 Aug 14 |
nicklas |
109 |
private int id; |
3837 |
12 Apr 16 |
nicklas |
110 |
private JSONObject json; |
2564 |
08 Aug 14 |
nicklas |
111 |
|
2564 |
08 Aug 14 |
nicklas |
112 |
/** |
2564 |
08 Aug 14 |
nicklas |
Create a new definition |
2564 |
08 Aug 14 |
nicklas |
@param name The name of the subtype |
2564 |
08 Aug 14 |
nicklas |
@param connectionManagerId The connection manager to use |
2564 |
08 Aug 14 |
nicklas |
116 |
*/ |
2564 |
08 Aug 14 |
nicklas |
117 |
private Fileserver(String name, String connectionManagerId, String description) |
2564 |
08 Aug 14 |
nicklas |
118 |
{ |
2564 |
08 Aug 14 |
nicklas |
119 |
this.name = name; |
2564 |
08 Aug 14 |
nicklas |
120 |
this.connectionManagerId = connectionManagerId; |
2564 |
08 Aug 14 |
nicklas |
121 |
this.description = description; |
2564 |
08 Aug 14 |
nicklas |
122 |
} |
2564 |
08 Aug 14 |
nicklas |
123 |
|
2564 |
08 Aug 14 |
nicklas |
124 |
/** |
2564 |
08 Aug 14 |
nicklas |
Get the name of the biomaterial list. |
2564 |
08 Aug 14 |
nicklas |
126 |
*/ |
2564 |
08 Aug 14 |
nicklas |
127 |
public String getName() |
2564 |
08 Aug 14 |
nicklas |
128 |
{ |
2564 |
08 Aug 14 |
nicklas |
129 |
return name; |
2564 |
08 Aug 14 |
nicklas |
130 |
} |
2564 |
08 Aug 14 |
nicklas |
131 |
|
2564 |
08 Aug 14 |
nicklas |
132 |
/** |
2564 |
08 Aug 14 |
nicklas |
Get the list description. |
2564 |
08 Aug 14 |
nicklas |
134 |
*/ |
2564 |
08 Aug 14 |
nicklas |
135 |
public String getDescription() |
2564 |
08 Aug 14 |
nicklas |
136 |
{ |
2564 |
08 Aug 14 |
nicklas |
137 |
return description; |
2564 |
08 Aug 14 |
nicklas |
138 |
} |
2564 |
08 Aug 14 |
nicklas |
139 |
|
2564 |
08 Aug 14 |
nicklas |
140 |
/** |
2564 |
08 Aug 14 |
nicklas |
Get the id of the connection manager to use. |
2564 |
08 Aug 14 |
nicklas |
142 |
*/ |
2564 |
08 Aug 14 |
nicklas |
143 |
public String getConnectionManagerId() |
2564 |
08 Aug 14 |
nicklas |
144 |
{ |
2564 |
08 Aug 14 |
nicklas |
145 |
return connectionManagerId; |
2564 |
08 Aug 14 |
nicklas |
146 |
} |
2564 |
08 Aug 14 |
nicklas |
147 |
|
2564 |
08 Aug 14 |
nicklas |
148 |
/** |
2564 |
08 Aug 14 |
nicklas |
Load the file server as a BASE item |
2564 |
08 Aug 14 |
nicklas |
@param dc The DbControl to use for database access |
2564 |
08 Aug 14 |
nicklas |
@return An FileServer object |
2564 |
08 Aug 14 |
nicklas |
152 |
*/ |
2564 |
08 Aug 14 |
nicklas |
153 |
public FileServer load(DbControl dc) |
2564 |
08 Aug 14 |
nicklas |
154 |
{ |
2564 |
08 Aug 14 |
nicklas |
155 |
FileServer list = null; |
2564 |
08 Aug 14 |
nicklas |
156 |
if (id == 0) |
2564 |
08 Aug 14 |
nicklas |
157 |
{ |
2564 |
08 Aug 14 |
nicklas |
158 |
List<FileServer> result = list(dc); |
2564 |
08 Aug 14 |
nicklas |
159 |
if (result.size() == 0) |
2564 |
08 Aug 14 |
nicklas |
160 |
{ |
2564 |
08 Aug 14 |
nicklas |
161 |
throw new ItemNotFoundException("FileServer["+getName()+"]"); |
2564 |
08 Aug 14 |
nicklas |
162 |
} |
2564 |
08 Aug 14 |
nicklas |
163 |
else if (result.size() > 1) |
2564 |
08 Aug 14 |
nicklas |
164 |
{ |
2564 |
08 Aug 14 |
nicklas |
165 |
throw new InvalidDataException("Found > 1 FileServer["+getName()+"]"); |
2564 |
08 Aug 14 |
nicklas |
166 |
} |
2564 |
08 Aug 14 |
nicklas |
167 |
list = result.get(0); |
2564 |
08 Aug 14 |
nicklas |
168 |
id = list.getId(); |
2564 |
08 Aug 14 |
nicklas |
169 |
} |
2564 |
08 Aug 14 |
nicklas |
170 |
else |
2564 |
08 Aug 14 |
nicklas |
171 |
{ |
2564 |
08 Aug 14 |
nicklas |
172 |
list = FileServer.getById(dc, id); |
2564 |
08 Aug 14 |
nicklas |
173 |
} |
2564 |
08 Aug 14 |
nicklas |
174 |
return list; |
2564 |
08 Aug 14 |
nicklas |
175 |
} |
2564 |
08 Aug 14 |
nicklas |
176 |
|
2564 |
08 Aug 14 |
nicklas |
177 |
/** |
7221 |
31 May 23 |
nicklas |
Load the file server as a BASE item. Return null if not found. |
7221 |
31 May 23 |
nicklas |
@param dc The DbControl to use for database access |
7221 |
31 May 23 |
nicklas |
@return An FileServer object |
7221 |
31 May 23 |
nicklas |
@since 4.48 |
7221 |
31 May 23 |
nicklas |
182 |
*/ |
7221 |
31 May 23 |
nicklas |
183 |
public FileServer get(DbControl dc) |
7221 |
31 May 23 |
nicklas |
184 |
{ |
7221 |
31 May 23 |
nicklas |
185 |
FileServer list = null; |
7221 |
31 May 23 |
nicklas |
186 |
if (id == 0) |
7221 |
31 May 23 |
nicklas |
187 |
{ |
7221 |
31 May 23 |
nicklas |
188 |
List<FileServer> result = list(dc); |
7221 |
31 May 23 |
nicklas |
189 |
if (result.size() == 1) |
7221 |
31 May 23 |
nicklas |
190 |
{ |
7221 |
31 May 23 |
nicklas |
191 |
list = result.get(0); |
7221 |
31 May 23 |
nicklas |
192 |
id = list.getId(); |
7221 |
31 May 23 |
nicklas |
193 |
} |
7221 |
31 May 23 |
nicklas |
194 |
} |
7221 |
31 May 23 |
nicklas |
195 |
else |
7221 |
31 May 23 |
nicklas |
196 |
{ |
7221 |
31 May 23 |
nicklas |
197 |
list = FileServer.getById(dc, id); |
7221 |
31 May 23 |
nicklas |
198 |
} |
7221 |
31 May 23 |
nicklas |
199 |
return list; |
7221 |
31 May 23 |
nicklas |
200 |
} |
7221 |
31 May 23 |
nicklas |
201 |
|
7221 |
31 May 23 |
nicklas |
202 |
|
7221 |
31 May 23 |
nicklas |
203 |
/** |
2564 |
08 Aug 14 |
nicklas |
List all file server registered in BASE with an name matching this |
2564 |
08 Aug 14 |
nicklas |
definition. Normally, only a single file server should be returned. |
2564 |
08 Aug 14 |
nicklas |
206 |
*/ |
2564 |
08 Aug 14 |
nicklas |
207 |
public List<FileServer> list(DbControl dc) |
2564 |
08 Aug 14 |
nicklas |
208 |
{ |
2564 |
08 Aug 14 |
nicklas |
209 |
ItemQuery<FileServer> query = FileServer.getQuery(); |
2564 |
08 Aug 14 |
nicklas |
210 |
query.restrict( |
2564 |
08 Aug 14 |
nicklas |
211 |
Restrictions.eq( |
2564 |
08 Aug 14 |
nicklas |
212 |
Hql.property("name"), |
2564 |
08 Aug 14 |
nicklas |
213 |
Expressions.parameter("name", getName(), Type.STRING) |
2564 |
08 Aug 14 |
nicklas |
214 |
)); |
2564 |
08 Aug 14 |
nicklas |
215 |
query.include(Include.ALL); |
2564 |
08 Aug 14 |
nicklas |
216 |
return query.list(dc); |
2564 |
08 Aug 14 |
nicklas |
217 |
} |
2564 |
08 Aug 14 |
nicklas |
218 |
|
3837 |
12 Apr 16 |
nicklas |
219 |
/** |
3837 |
12 Apr 16 |
nicklas |
Get the subtype information as a JSON object ready to be sent as an AJAX response. |
3837 |
12 Apr 16 |
nicklas |
@since 4.3 |
3837 |
12 Apr 16 |
nicklas |
222 |
*/ |
3837 |
12 Apr 16 |
nicklas |
223 |
public JSONObject asJSONObject(DbControl dc) |
3837 |
12 Apr 16 |
nicklas |
224 |
{ |
3837 |
12 Apr 16 |
nicklas |
225 |
if (json == null) |
3837 |
12 Apr 16 |
nicklas |
226 |
{ |
3837 |
12 Apr 16 |
nicklas |
227 |
FileServer fs = load(dc); |
3837 |
12 Apr 16 |
nicklas |
228 |
json = new JSONObject(); |
3837 |
12 Apr 16 |
nicklas |
229 |
json.put("id", id); |
3837 |
12 Apr 16 |
nicklas |
230 |
json.put("name", getName()); |
3837 |
12 Apr 16 |
nicklas |
231 |
json.put("host", fs.getHost()); |
3837 |
12 Apr 16 |
nicklas |
232 |
} |
3837 |
12 Apr 16 |
nicklas |
233 |
return json; |
3837 |
12 Apr 16 |
nicklas |
234 |
} |
2564 |
08 Aug 14 |
nicklas |
235 |
|
2564 |
08 Aug 14 |
nicklas |
236 |
} |