1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2000-2011 Regents of the University of California and the
|
4
|
* National Center for Ecological Analysis and Synthesis
|
5
|
*
|
6
|
* '$Author: tao $'
|
7
|
* '$Date: 2014-12-22 14:31:24 -0800 (Mon, 22 Dec 2014) $'
|
8
|
*
|
9
|
* This program is free software; you can redistribute it and/or modify
|
10
|
* it under the terms of the GNU General Public License as published by
|
11
|
* the Free Software Foundation; either version 2 of the License, or
|
12
|
* (at your option) any later version.
|
13
|
*
|
14
|
* This program is distributed in the hope that it will be useful,
|
15
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
* GNU General Public License for more details.
|
18
|
*
|
19
|
* You should have received a copy of the GNU General Public License
|
20
|
* along with this program; if not, write to the Free Software
|
21
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
22
|
*/
|
23
|
|
24
|
package edu.ucsb.nceas.metacat.dataone.v1;
|
25
|
|
26
|
import java.io.InputStream;
|
27
|
import java.sql.SQLException;
|
28
|
import java.util.Date;
|
29
|
|
30
|
import javax.servlet.http.HttpServletRequest;
|
31
|
|
32
|
import org.apache.log4j.Logger;
|
33
|
import org.dataone.service.exceptions.IdentifierNotUnique;
|
34
|
import org.dataone.service.exceptions.InsufficientResources;
|
35
|
import org.dataone.service.exceptions.InvalidRequest;
|
36
|
import org.dataone.service.exceptions.InvalidSystemMetadata;
|
37
|
import org.dataone.service.exceptions.InvalidToken;
|
38
|
import org.dataone.service.exceptions.NotAuthorized;
|
39
|
import org.dataone.service.exceptions.NotFound;
|
40
|
import org.dataone.service.exceptions.NotImplemented;
|
41
|
import org.dataone.service.exceptions.ServiceFailure;
|
42
|
import org.dataone.service.exceptions.SynchronizationFailed;
|
43
|
import org.dataone.service.exceptions.UnsupportedType;
|
44
|
import org.dataone.service.mn.tier1.v1.MNCore;
|
45
|
import org.dataone.service.mn.tier1.v1.MNRead;
|
46
|
import org.dataone.service.mn.tier2.v1.MNAuthorization;
|
47
|
import org.dataone.service.mn.tier3.v1.MNStorage;
|
48
|
import org.dataone.service.mn.tier4.v1.MNReplication;
|
49
|
import org.dataone.service.mn.v1.MNQuery;
|
50
|
import org.dataone.service.types.v1.Checksum;
|
51
|
import org.dataone.service.types.v1.DescribeResponse;
|
52
|
import org.dataone.service.types.v1.Event;
|
53
|
import org.dataone.service.types.v1.Identifier;
|
54
|
import org.dataone.service.types.v1.Log;
|
55
|
import org.dataone.service.types.v1.Node;
|
56
|
import org.dataone.service.types.v1.NodeReference;
|
57
|
import org.dataone.service.types.v1.ObjectFormatIdentifier;
|
58
|
import org.dataone.service.types.v1.ObjectList;
|
59
|
import org.dataone.service.types.v1.Permission;
|
60
|
import org.dataone.service.types.v1.Session;
|
61
|
import org.dataone.service.types.v1.SystemMetadata;
|
62
|
import org.dataone.service.types.v1_1.QueryEngineDescription;
|
63
|
import org.dataone.service.types.v1_1.QueryEngineList;
|
64
|
import org.dataone.service.util.TypeMarshaller;
|
65
|
|
66
|
import edu.ucsb.nceas.metacat.IdentifierManager;
|
67
|
|
68
|
/**
|
69
|
* Represents Metacat's implementation of the DataONE Member Node
|
70
|
* service API, v1. Methods typically pass through to the current
|
71
|
* version implementation performing type conversion as needed.
|
72
|
*
|
73
|
*/
|
74
|
public class MNodeService
|
75
|
implements MNAuthorization, MNCore, MNRead, MNReplication, MNStorage, MNQuery {
|
76
|
|
77
|
/**
|
78
|
* current version implementation
|
79
|
*/
|
80
|
edu.ucsb.nceas.metacat.dataone.MNodeService impl = null;
|
81
|
|
82
|
/* the logger instance */
|
83
|
private Logger logMetacat = null;
|
84
|
|
85
|
/**
|
86
|
* Singleton accessor to get an instance of MNodeService.
|
87
|
*
|
88
|
* @return instance - the instance of MNodeService
|
89
|
*/
|
90
|
public static MNodeService getInstance(HttpServletRequest request) {
|
91
|
return new MNodeService(request);
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* Constructor, private for singleton access
|
96
|
*/
|
97
|
private MNodeService(HttpServletRequest request) {
|
98
|
logMetacat = Logger.getLogger(MNodeService.class);
|
99
|
impl = edu.ucsb.nceas.metacat.dataone.MNodeService.getInstance(request);
|
100
|
}
|
101
|
|
102
|
public void setSession(Session session) {
|
103
|
impl.setSession(session);
|
104
|
}
|
105
|
|
106
|
public boolean isAdminAuthorized(Session session) throws ServiceFailure, InvalidToken, NotAuthorized, NotImplemented {
|
107
|
return impl.isAdminAuthorized(session);
|
108
|
}
|
109
|
|
110
|
@Override
|
111
|
public QueryEngineDescription getQueryEngineDescription(String engine)
|
112
|
throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
|
113
|
NotFound {
|
114
|
return impl.getQueryEngineDescription(null, engine);
|
115
|
}
|
116
|
|
117
|
@Override
|
118
|
public QueryEngineList listQueryEngines() throws InvalidToken,
|
119
|
ServiceFailure, NotAuthorized, NotImplemented {
|
120
|
return impl.listQueryEngines(null);
|
121
|
}
|
122
|
|
123
|
@Override
|
124
|
public InputStream query(String engine, String query) throws InvalidToken,
|
125
|
ServiceFailure, NotAuthorized, InvalidRequest, NotImplemented,
|
126
|
NotFound {
|
127
|
return impl.query(null, engine, query);
|
128
|
}
|
129
|
|
130
|
@Override
|
131
|
public Identifier archive(Identifier pid) throws InvalidToken,
|
132
|
ServiceFailure, NotAuthorized, NotFound, NotImplemented {
|
133
|
return impl.archive(null, pid);
|
134
|
}
|
135
|
|
136
|
@Override
|
137
|
@Deprecated
|
138
|
public Identifier archive(Session session, Identifier pid)
|
139
|
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
|
140
|
NotImplemented {
|
141
|
return impl.archive(session, pid);
|
142
|
}
|
143
|
|
144
|
@Override
|
145
|
public Identifier create(Identifier pid, InputStream object,
|
146
|
SystemMetadata sysmeta) throws IdentifierNotUnique,
|
147
|
InsufficientResources, InvalidRequest, InvalidSystemMetadata,
|
148
|
InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
|
149
|
UnsupportedType {
|
150
|
return this.create(null, pid, object, sysmeta);
|
151
|
}
|
152
|
|
153
|
@Override
|
154
|
@Deprecated
|
155
|
public Identifier create(Session session, Identifier pid, InputStream object,
|
156
|
SystemMetadata sysmeta) throws IdentifierNotUnique,
|
157
|
InsufficientResources, InvalidRequest, InvalidSystemMetadata,
|
158
|
InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
|
159
|
UnsupportedType {
|
160
|
//convert sysmeta to newer version
|
161
|
org.dataone.service.types.v2.SystemMetadata v2Sysmeta = null;
|
162
|
try {
|
163
|
v2Sysmeta = TypeMarshaller.convertTypeFromType(sysmeta, org.dataone.service.types.v2.SystemMetadata.class);
|
164
|
} catch (Exception e) {
|
165
|
// report as service failure
|
166
|
ServiceFailure sf = new ServiceFailure("1190", e.getMessage());
|
167
|
sf.initCause(e);
|
168
|
throw sf;
|
169
|
}
|
170
|
|
171
|
return impl.create(session, pid, object, v2Sysmeta);
|
172
|
}
|
173
|
|
174
|
@Override
|
175
|
public Identifier delete(Identifier pid) throws InvalidToken,
|
176
|
ServiceFailure, NotAuthorized, NotFound, NotImplemented {
|
177
|
return impl.delete(null, pid);
|
178
|
}
|
179
|
|
180
|
@Override
|
181
|
@Deprecated
|
182
|
public Identifier delete(Session session, Identifier pid)
|
183
|
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
|
184
|
NotImplemented {
|
185
|
return impl.delete(session, pid);
|
186
|
}
|
187
|
|
188
|
@Override
|
189
|
public Identifier generateIdentifier(String scheme, String fragment)
|
190
|
throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
|
191
|
InvalidRequest {
|
192
|
return impl.generateIdentifier(null, scheme, fragment);
|
193
|
}
|
194
|
|
195
|
@Override
|
196
|
@Deprecated
|
197
|
public Identifier generateIdentifier(Session session, String scheme, String fragment)
|
198
|
throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
|
199
|
InvalidRequest {
|
200
|
return impl.generateIdentifier(session, scheme, fragment);
|
201
|
}
|
202
|
|
203
|
@Override
|
204
|
public Identifier update(Identifier pid, InputStream object,
|
205
|
Identifier newPid, SystemMetadata sysmeta) throws IdentifierNotUnique,
|
206
|
InsufficientResources, InvalidRequest, InvalidSystemMetadata,
|
207
|
InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
|
208
|
UnsupportedType, NotFound {
|
209
|
return this.update(null, pid, object, newPid, sysmeta);
|
210
|
}
|
211
|
|
212
|
@Override
|
213
|
@Deprecated
|
214
|
public Identifier update(Session session, Identifier pid, InputStream object,
|
215
|
Identifier newPid, SystemMetadata sysmeta) throws IdentifierNotUnique,
|
216
|
InsufficientResources, InvalidRequest, InvalidSystemMetadata,
|
217
|
InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
|
218
|
UnsupportedType, NotFound {
|
219
|
//convert sysmeta to newer version
|
220
|
org.dataone.service.types.v2.SystemMetadata v2Sysmeta = null;
|
221
|
try {
|
222
|
v2Sysmeta = TypeMarshaller.convertTypeFromType(sysmeta, org.dataone.service.types.v2.SystemMetadata.class);
|
223
|
} catch (Exception e) {
|
224
|
// report as service failure
|
225
|
ServiceFailure sf = new ServiceFailure("1030", e.getMessage());
|
226
|
sf.initCause(e);
|
227
|
throw sf;
|
228
|
}
|
229
|
return impl.update(session, pid, object, newPid, v2Sysmeta);
|
230
|
}
|
231
|
|
232
|
@Override
|
233
|
public boolean replicate(SystemMetadata sysmeta, NodeReference sourceNode)
|
234
|
throws NotImplemented, ServiceFailure, NotAuthorized,
|
235
|
InvalidRequest, InvalidToken, InsufficientResources,
|
236
|
UnsupportedType {
|
237
|
return this.replicate(null, sysmeta, sourceNode);
|
238
|
}
|
239
|
|
240
|
@Override
|
241
|
@Deprecated
|
242
|
public boolean replicate(Session session, SystemMetadata sysmeta,
|
243
|
NodeReference sourceNode) throws NotImplemented, ServiceFailure,
|
244
|
NotAuthorized, InvalidRequest, InvalidToken, InsufficientResources,
|
245
|
UnsupportedType {
|
246
|
//convert sysmeta to newer version
|
247
|
org.dataone.service.types.v2.SystemMetadata v2Sysmeta = null;
|
248
|
try {
|
249
|
v2Sysmeta = TypeMarshaller.convertTypeFromType(sysmeta, org.dataone.service.types.v2.SystemMetadata.class);
|
250
|
} catch (Exception e) {
|
251
|
// report as service failure
|
252
|
ServiceFailure sf = new ServiceFailure("1030", e.getMessage());
|
253
|
sf.initCause(e);
|
254
|
throw sf;
|
255
|
}
|
256
|
return impl.replicate(session, v2Sysmeta, sourceNode);
|
257
|
}
|
258
|
|
259
|
@Override
|
260
|
public DescribeResponse describe(Identifier pid) throws InvalidToken,
|
261
|
NotAuthorized, NotImplemented, ServiceFailure, NotFound {
|
262
|
return impl.describe(null, pid);
|
263
|
}
|
264
|
|
265
|
@Override
|
266
|
@Deprecated
|
267
|
public DescribeResponse describe(Session session, Identifier pid)
|
268
|
throws InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
|
269
|
NotFound {
|
270
|
return impl.describe(session, pid);
|
271
|
}
|
272
|
|
273
|
@Override
|
274
|
public InputStream get(Identifier pid) throws InvalidToken, NotAuthorized,
|
275
|
NotImplemented, ServiceFailure, NotFound, InsufficientResources {
|
276
|
String serviceFailure = "1030";
|
277
|
String notFound = "1020";
|
278
|
impl.checkV1SystemMetaPidExist(pid, serviceFailure, notFound);
|
279
|
return impl.get(null, pid);
|
280
|
}
|
281
|
|
282
|
@Override
|
283
|
@Deprecated
|
284
|
public InputStream get(Session session, Identifier pid) throws InvalidToken,
|
285
|
NotAuthorized, NotImplemented, ServiceFailure, NotFound,
|
286
|
InsufficientResources {
|
287
|
String serviceFailure = "1030";
|
288
|
String notFound = "1020";
|
289
|
impl.checkV1SystemMetaPidExist(pid, serviceFailure, notFound);
|
290
|
return impl.get(session, pid);
|
291
|
}
|
292
|
|
293
|
@Override
|
294
|
public Checksum getChecksum(Identifier pid, String algorithm)
|
295
|
throws InvalidRequest, InvalidToken, NotAuthorized, NotImplemented,
|
296
|
ServiceFailure, NotFound {
|
297
|
return impl.getChecksum(null, pid, algorithm);
|
298
|
}
|
299
|
|
300
|
@Override
|
301
|
@Deprecated
|
302
|
public Checksum getChecksum(Session session, Identifier pid, String algorithm)
|
303
|
throws InvalidRequest, InvalidToken, NotAuthorized, NotImplemented,
|
304
|
ServiceFailure, NotFound {
|
305
|
return impl.getChecksum(session, pid, algorithm);
|
306
|
}
|
307
|
|
308
|
@Override
|
309
|
public InputStream getReplica(Identifier pid) throws InvalidToken,
|
310
|
NotAuthorized, NotImplemented, ServiceFailure, NotFound,
|
311
|
InsufficientResources {
|
312
|
return impl.getReplica(null, pid);
|
313
|
}
|
314
|
|
315
|
@Override
|
316
|
@Deprecated
|
317
|
public InputStream getReplica(Session session, Identifier pid)
|
318
|
throws InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
|
319
|
NotFound, InsufficientResources {
|
320
|
return impl.get(session, pid);
|
321
|
}
|
322
|
|
323
|
@Override
|
324
|
public SystemMetadata getSystemMetadata(Identifier pid)
|
325
|
throws InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
|
326
|
NotFound {
|
327
|
|
328
|
return this.getSystemMetadata(null, pid);
|
329
|
|
330
|
}
|
331
|
|
332
|
@Override
|
333
|
@Deprecated
|
334
|
public SystemMetadata getSystemMetadata(Session session, Identifier pid)
|
335
|
throws InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
|
336
|
NotFound {
|
337
|
org.dataone.service.types.v2.SystemMetadata sysMeta = impl.getSystemMetadata(session, pid);
|
338
|
SystemMetadata retSysMeta = null;
|
339
|
try {
|
340
|
retSysMeta = TypeMarshaller.convertTypeFromType(sysMeta, SystemMetadata.class);
|
341
|
} catch (Exception e) {
|
342
|
// report as service failure
|
343
|
ServiceFailure sf = new ServiceFailure("4801", e.getMessage());
|
344
|
sf.initCause(e);
|
345
|
throw sf;
|
346
|
}
|
347
|
return retSysMeta;
|
348
|
}
|
349
|
|
350
|
@Override
|
351
|
public ObjectList listObjects(Date startTime, Date endTime,
|
352
|
ObjectFormatIdentifier objectFormatId, Boolean replicaStatus, Integer start,
|
353
|
Integer count) throws InvalidRequest, InvalidToken, NotAuthorized,
|
354
|
NotImplemented, ServiceFailure {
|
355
|
return this.listObjects(null, startTime, endTime, objectFormatId, replicaStatus, start, count);
|
356
|
}
|
357
|
|
358
|
@Override
|
359
|
@Deprecated
|
360
|
public ObjectList listObjects(Session session, Date startTime, Date endTime,
|
361
|
ObjectFormatIdentifier objectFormatId, Boolean replicaStatus, Integer start,
|
362
|
Integer count) throws InvalidRequest, InvalidToken, NotAuthorized,
|
363
|
NotImplemented, ServiceFailure {
|
364
|
return impl.listObjects(session, startTime, endTime, objectFormatId, null, replicaStatus, start, count);
|
365
|
}
|
366
|
|
367
|
@Override
|
368
|
public boolean synchronizationFailed(SynchronizationFailed syncFailed)
|
369
|
throws InvalidToken, NotAuthorized, NotImplemented, ServiceFailure {
|
370
|
return impl.synchronizationFailed(null, syncFailed);
|
371
|
}
|
372
|
|
373
|
@Override
|
374
|
@Deprecated
|
375
|
public boolean synchronizationFailed(Session session,
|
376
|
SynchronizationFailed syncFailed) throws InvalidToken, NotAuthorized,
|
377
|
NotImplemented, ServiceFailure {
|
378
|
return impl.synchronizationFailed(session, syncFailed);
|
379
|
}
|
380
|
|
381
|
@Override
|
382
|
public Node getCapabilities() throws NotImplemented, ServiceFailure {
|
383
|
org.dataone.service.types.v2.Node node = impl.getCapabilities();
|
384
|
Node retNode = null;
|
385
|
try {
|
386
|
retNode = TypeMarshaller.convertTypeFromType(node, Node.class);
|
387
|
} catch (Exception e) {
|
388
|
// report as service failure
|
389
|
ServiceFailure sf = new ServiceFailure("4801", e.getMessage());
|
390
|
sf.initCause(e);
|
391
|
throw sf;
|
392
|
}
|
393
|
return retNode;
|
394
|
}
|
395
|
|
396
|
@Override
|
397
|
public Log getLogRecords(Date fromDate, Date toDate, Event event,
|
398
|
String pidFilter, Integer start, Integer count) throws InvalidRequest, InvalidToken,
|
399
|
NotAuthorized, NotImplemented, ServiceFailure {
|
400
|
return this.getLogRecords(null, fromDate, toDate, event, pidFilter, start, count);
|
401
|
}
|
402
|
|
403
|
@Override
|
404
|
@Deprecated
|
405
|
public Log getLogRecords(Session session, Date fromDate, Date toDate, Event event,
|
406
|
String pidFilter, Integer start, Integer count) throws InvalidRequest, InvalidToken,
|
407
|
NotAuthorized, NotImplemented, ServiceFailure {
|
408
|
org.dataone.service.types.v2.Log log = impl.getLogRecords(session, fromDate, toDate, event.xmlValue(), pidFilter, start, count);
|
409
|
Log retLog = null;
|
410
|
try {
|
411
|
retLog = TypeMarshaller.convertTypeFromType(log, Log.class);
|
412
|
} catch (Exception e) {
|
413
|
// report as service failure
|
414
|
ServiceFailure sf = new ServiceFailure("1490", e.getMessage());
|
415
|
sf.initCause(e);
|
416
|
throw sf;
|
417
|
}
|
418
|
return retLog;
|
419
|
}
|
420
|
|
421
|
@Override
|
422
|
public Date ping() throws NotImplemented, ServiceFailure,
|
423
|
InsufficientResources {
|
424
|
return impl.ping();
|
425
|
}
|
426
|
|
427
|
@Override
|
428
|
public boolean isAuthorized(Identifier pid, Permission permission)
|
429
|
throws ServiceFailure, InvalidRequest, InvalidToken, NotFound,
|
430
|
NotAuthorized, NotImplemented {
|
431
|
return impl.isAuthorized(null, pid, permission);
|
432
|
}
|
433
|
|
434
|
@Override
|
435
|
@Deprecated
|
436
|
public boolean isAuthorized(Session session, Identifier pid, Permission permission)
|
437
|
throws ServiceFailure, InvalidRequest, InvalidToken, NotFound,
|
438
|
NotAuthorized, NotImplemented {
|
439
|
return impl.isAuthorized(session, pid, permission);
|
440
|
}
|
441
|
|
442
|
@Override
|
443
|
public boolean systemMetadataChanged(Identifier pid, long serialVersion, Date dateSysMetaLastModified)
|
444
|
throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
|
445
|
InvalidRequest {
|
446
|
return impl.systemMetadataChanged(null, pid, serialVersion, dateSysMetaLastModified);
|
447
|
|
448
|
}
|
449
|
|
450
|
@Override
|
451
|
@Deprecated
|
452
|
public boolean systemMetadataChanged(Session session, Identifier pid,
|
453
|
long serialVersion, Date dateSysMetaLastModified) throws InvalidToken, ServiceFailure,
|
454
|
NotAuthorized, NotImplemented, InvalidRequest {
|
455
|
return impl.systemMetadataChanged(session, pid, serialVersion, dateSysMetaLastModified);
|
456
|
}
|
457
|
|
458
|
// methods not defined in v1, but implemented in metacat pre-v2 release
|
459
|
|
460
|
public Identifier publish(Session session, Identifier originalIdentifier)
|
461
|
throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented, InvalidRequest, NotFound, IdentifierNotUnique, UnsupportedType, InsufficientResources, InvalidSystemMetadata {
|
462
|
return impl.publish(session, originalIdentifier);
|
463
|
|
464
|
}
|
465
|
|
466
|
public InputStream view(Session session, String format, Identifier pid)
|
467
|
throws InvalidToken, ServiceFailure, NotAuthorized, InvalidRequest,
|
468
|
NotImplemented, NotFound {
|
469
|
|
470
|
return impl.view(session, format, pid);
|
471
|
}
|
472
|
|
473
|
public InputStream getPackage(Session session, ObjectFormatIdentifier formatId,
|
474
|
Identifier pid) throws InvalidToken, ServiceFailure,
|
475
|
NotAuthorized, InvalidRequest, NotImplemented, NotFound {
|
476
|
return impl.getPackage(session, formatId, pid);
|
477
|
}
|
478
|
|
479
|
|
480
|
|
481
|
|
482
|
}
|