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