Project

General

Profile

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: 2016-11-09 17:26:27 -0800 (Wed, 09 Nov 2016) $'
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.math.BigInteger;
28
import java.sql.SQLException;
29
import java.util.Date;
30
import java.util.List;
31

    
32
import javax.servlet.http.HttpServletRequest;
33

    
34
import org.apache.commons.io.IOUtils;
35
import org.apache.log4j.Logger;
36
import org.dataone.service.cn.v1.CNAuthorization;
37
import org.dataone.service.cn.v1.CNCore;
38
import org.dataone.service.cn.v1.CNRead;
39
import org.dataone.service.cn.v1.CNReplication;
40
import org.dataone.service.exceptions.BaseException;
41
import org.dataone.service.exceptions.IdentifierNotUnique;
42
import org.dataone.service.exceptions.InsufficientResources;
43
import org.dataone.service.exceptions.InvalidRequest;
44
import org.dataone.service.exceptions.InvalidSystemMetadata;
45
import org.dataone.service.exceptions.InvalidToken;
46
import org.dataone.service.exceptions.NotAuthorized;
47
import org.dataone.service.exceptions.NotFound;
48
import org.dataone.service.exceptions.NotImplemented;
49
import org.dataone.service.exceptions.ServiceFailure;
50
import org.dataone.service.exceptions.UnsupportedType;
51
import org.dataone.service.exceptions.VersionMismatch;
52
import org.dataone.service.types.v1.AccessPolicy;
53
import org.dataone.service.types.v1.Checksum;
54
import org.dataone.service.types.v1.ChecksumAlgorithmList;
55
import org.dataone.service.types.v1.DescribeResponse;
56
import org.dataone.service.types.v1.Event;
57
import org.dataone.service.types.v1.Identifier;
58
import org.dataone.service.types.v1.Log;
59
import org.dataone.service.types.v1.NodeList;
60
import org.dataone.service.types.v1.NodeReference;
61
import org.dataone.service.types.v1.ObjectFormat;
62
import org.dataone.service.types.v1.ObjectFormatIdentifier;
63
import org.dataone.service.types.v1.ObjectFormatList;
64
import org.dataone.service.types.v1.ObjectList;
65
import org.dataone.service.types.v1.ObjectLocationList;
66
import org.dataone.service.types.v1.Permission;
67
import org.dataone.service.types.v1.Replica;
68
import org.dataone.service.types.v1.ReplicationPolicy;
69
import org.dataone.service.types.v1.ReplicationStatus;
70
import org.dataone.service.types.v1.Session;
71
import org.dataone.service.types.v1.Subject;
72
import org.dataone.service.types.v1.SystemMetadata;
73
import org.dataone.service.types.v1_1.QueryEngineDescription;
74
import org.dataone.service.types.v1_1.QueryEngineList;
75
import org.dataone.service.types.v2.TypeFactory;
76

    
77
import edu.ucsb.nceas.metacat.IdentifierManager;
78
import edu.ucsb.nceas.metacat.dataone.D1NodeVersionChecker;
79
import edu.ucsb.nceas.metacat.dataone.convert.LogV2toV1Converter;
80
import edu.ucsb.nceas.metacat.properties.PropertyService;
81

    
82
/**
83
 * Represents Metacat's implementation of the DataONE Coordinating Node service
84
 * API. Methods implement the various CN* interfaces, and methods common to both
85
 * Member Node and Coordinating Node interfaces are found in the D1NodeService
86
 * super class.
87
 * 
88
 */
89
public class CNodeService implements CNAuthorization, CNCore, CNRead,
90
		CNReplication {
91

    
92
	// pass through to the most recent implementation
93
	private edu.ucsb.nceas.metacat.dataone.CNodeService impl = null;
94

    
95
	/* the logger instance */
96
	private Logger logMetacat = null;
97

    
98
	/**
99
	 * singleton accessor
100
	 */
101
	public static CNodeService getInstance(HttpServletRequest request) {
102
		return new CNodeService(request);
103
	}
104

    
105
	/**
106
	 * Constructor, private for singleton access
107
	 */
108
	private CNodeService(HttpServletRequest request) {
109

    
110
		logMetacat = Logger.getLogger(CNodeService.class);
111

    
112
		impl = edu.ucsb.nceas.metacat.dataone.CNodeService.getInstance(request);
113

    
114
	}
115

    
116
	@Override
117
	public boolean deleteReplicationMetadata(Identifier pid,
118
			NodeReference nodeId, long serialVersion) throws InvalidToken, InvalidRequest,
119
			ServiceFailure, NotAuthorized, NotFound, NotImplemented,
120
			VersionMismatch {
121
		return impl.deleteReplicationMetadata(null, pid, nodeId, serialVersion);
122
	}
123

    
124
	@Override
125
	@Deprecated
126
	public boolean deleteReplicationMetadata(Session session, Identifier pid,
127
			NodeReference nodeId, long serialVersion) throws InvalidToken, InvalidRequest,
128
			ServiceFailure, NotAuthorized, NotFound, NotImplemented,
129
			VersionMismatch {
130
		return impl.deleteReplicationMetadata(session, pid, nodeId, serialVersion);
131

    
132
	}
133

    
134
	@Override
135
	public boolean isNodeAuthorized(Subject targetNodeSubject, Identifier pid)
136
			throws NotImplemented, NotAuthorized, InvalidToken, ServiceFailure,
137
			NotFound, InvalidRequest {
138
		return impl.isNodeAuthorized(null, targetNodeSubject, pid);
139

    
140
	}
141

    
142
	@Override
143
	@Deprecated
144
	public boolean isNodeAuthorized(Session originatingNodeSession, Subject targetNodeSubject, Identifier pid)
145
			throws NotImplemented, NotAuthorized, InvalidToken, ServiceFailure,
146
			NotFound, InvalidRequest {
147
		return impl.isNodeAuthorized(originatingNodeSession, targetNodeSubject, pid);
148
	}
149

    
150
	@Override
151
	public boolean setReplicationPolicy(Identifier pid,
152
			ReplicationPolicy policy, long serialVersion) throws NotImplemented, NotFound,
153
			NotAuthorized, ServiceFailure, InvalidRequest, InvalidToken,
154
			VersionMismatch {
155
	    String serviceFailure = "4882";
156
        String notFound = "4884";
157
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object for given PID "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
158
                "No object could be found for given PID: "+pid.getValue());
159
		return impl.setReplicationPolicy(null, pid, policy, serialVersion);
160
	}
161

    
162
	@Override
163
	@Deprecated
164
	public boolean setReplicationPolicy(Session session, Identifier pid,
165
			ReplicationPolicy policy, long serialVersion) throws NotImplemented, NotFound,
166
			NotAuthorized, ServiceFailure, InvalidRequest, InvalidToken,
167
			VersionMismatch {
168
		return impl.setReplicationPolicy(session, pid, policy, serialVersion);
169

    
170
	}
171

    
172
	@Override
173
	public boolean setReplicationStatus(Identifier pid,
174
			NodeReference targetNode, ReplicationStatus status, BaseException failure) 
175
			throws ServiceFailure, NotImplemented, InvalidToken, NotAuthorized, InvalidRequest, NotFound {
176
		return impl.setReplicationStatus(null, pid, targetNode, status, failure);
177
	}
178

    
179
	@Override
180
	@Deprecated
181
	public boolean setReplicationStatus(Session session, Identifier pid,
182
			NodeReference targetNode, ReplicationStatus status, BaseException failure)
183
			throws ServiceFailure, NotImplemented, InvalidToken, NotAuthorized,
184
			InvalidRequest, NotFound {
185
	    String serviceFailure = "4700";
186
        String notFound = "4740";
187
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object for given PID "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
188
                "No object could be found for given PID: "+pid.getValue());
189
		return impl.setReplicationStatus(session, pid, targetNode, status, failure);
190
	}
191

    
192
	@Override
193
	public boolean updateReplicationMetadata(Identifier pid,
194
			Replica replica, long serialVersion) throws NotImplemented, NotAuthorized, ServiceFailure,
195
			NotFound, InvalidRequest, InvalidToken, VersionMismatch {
196
		return impl.updateReplicationMetadata(null, pid, replica, serialVersion);
197
	}
198

    
199
	@Override
200
	@Deprecated
201
	public boolean updateReplicationMetadata(Session session, Identifier pid,
202
			Replica replica, long serialVersion) throws NotImplemented, NotAuthorized,
203
			ServiceFailure, NotFound, InvalidRequest, InvalidToken,
204
			VersionMismatch {
205
		return impl.updateReplicationMetadata(session, pid, replica, serialVersion);
206
	}
207

    
208
	@Override
209
	public DescribeResponse describe(Identifier pid) throws InvalidToken,
210
			NotAuthorized, NotImplemented, ServiceFailure, NotFound {
211
	    String serviceFailure = "4931";
212
        String notFound = "4933";
213
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The system metadata for given PID "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
214
                "No system metadata could be found for given PID: "+pid.getValue());
215
		return impl.describe(null, pid);
216
	}
217

    
218
	@Override
219
	@Deprecated
220
	public DescribeResponse describe(Session session, Identifier pid)
221
			throws InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
222
			NotFound {
223
	    String serviceFailure = "4931";
224
        String notFound = "4933";
225
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The system metadata for given PID "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
226
                "No system metadata could be found for given PID: "+pid.getValue());
227
		return impl.describe(session, pid);
228
	}
229

    
230
	@Override
231
	public InputStream get(Identifier pid) throws InvalidToken,
232
			ServiceFailure, NotAuthorized, NotFound, NotImplemented {
233
        String serviceFailure = "1030";
234
        String notFound = "1020";
235
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object specified by "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
236
                "The object specified by "+pid.getValue()+" does not exist at this node");
237
		return impl.get(null, pid);
238
	}
239

    
240
	@Override
241
	@Deprecated
242
	public InputStream get(Session session, Identifier pid) throws InvalidToken,
243
			ServiceFailure, NotAuthorized, NotFound, NotImplemented {
244
	    String serviceFailure = "1030";
245
        String notFound = "1020";
246
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object specified by "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
247
                "The object specified by "+pid.getValue()+" does not exist at this node");
248
		return impl.get(session, pid);
249
	}
250

    
251
	@Override
252
	public Checksum getChecksum(Identifier pid) throws InvalidToken,
253
			ServiceFailure, NotAuthorized, NotFound, NotImplemented {
254
		return impl.getChecksum(null, pid);
255
	}
256

    
257
	@Override
258
	@Deprecated
259
	public Checksum getChecksum(Session session, Identifier pid)
260
			throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
261
			NotImplemented {
262
		return impl.getChecksum(session, pid);
263
	}
264

    
265
	@Override
266
	public QueryEngineDescription getQueryEngineDescription(String queryEngine)
267
			throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
268
			NotFound {
269
		return impl.getQueryEngineDescription(null, queryEngine);
270
	}
271

    
272
	@Override
273
	public SystemMetadata getSystemMetadata(Identifier pid)
274
			throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
275
			NotImplemented {
276
	    String serviceFailure = "1090";
277
        String notFound = "1060";
278
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The system metadata for given PID "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
279
                "No system metadata could be found for given PID: "+pid.getValue());
280
        org.dataone.service.types.v2.SystemMetadata sysMeta = impl.getSystemMetadata(null, pid);
281
        SystemMetadata retSysMeta = null;
282
        try {
283
            retSysMeta = TypeFactory.convertTypeFromType(sysMeta, SystemMetadata.class);
284
        } catch (Exception e) {
285
            // report as service failure
286
            ServiceFailure sf = new ServiceFailure("1090", e.getMessage());
287
            sf.initCause(e);
288
            throw sf;
289
        }
290
        return retSysMeta;
291
	}
292

    
293
	@Override
294
	@Deprecated
295
	public SystemMetadata getSystemMetadata(Session session, Identifier pid)
296
			throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
297
			NotImplemented {
298
	    String serviceFailure = "1090";
299
        String notFound = "1060";
300
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The system metadata for given PID "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
301
                "No system metadata could be found for given PID: "+pid.getValue());
302
        org.dataone.service.types.v2.SystemMetadata sysMeta = impl.getSystemMetadata(session, pid);
303
        SystemMetadata retSysMeta = null;
304
        try {
305
            retSysMeta = TypeFactory.convertTypeFromType(sysMeta, SystemMetadata.class);
306
        } catch (Exception e) {
307
            // report as service failure
308
            ServiceFailure sf = new ServiceFailure("1090", e.getMessage());
309
            sf.initCause(e);
310
            throw sf;
311
        }
312
        return retSysMeta;
313
	}
314

    
315
	@Override
316
	public ObjectList listObjects(Date startTime, Date endTime,
317
			ObjectFormatIdentifier formatid, Boolean replicaStatus, Integer start,
318
			Integer count) throws InvalidRequest, InvalidToken, NotAuthorized,
319
			NotImplemented, ServiceFailure {
320
	    NodeReference nodeId = null;
321
        if(!replicaStatus) {
322
            //not include those objects whose authoritative node is not this mn
323
            nodeId = new NodeReference();
324
            try {
325
                String currentNodeId = PropertyService.getInstance().getProperty("dataone.nodeId"); // return only pids for which this mn
326
                nodeId.setValue(currentNodeId);
327
            } catch(Exception e) {
328
                throw new ServiceFailure("1580", e.getMessage());
329
            }
330
        }
331
		return impl.listObjects(null, startTime, endTime, formatid, null, nodeId, start, count);
332
	}
333

    
334
	@Override
335
	@Deprecated
336
	public ObjectList listObjects(Session session, Date startTime, Date endTime,
337
			ObjectFormatIdentifier formatid, Boolean replicaStatus, Integer start,
338
			Integer count) throws InvalidRequest, InvalidToken, NotAuthorized,
339
			NotImplemented, ServiceFailure {
340
	    NodeReference nodeId = null;
341
        if(!replicaStatus) {
342
            //not include those objects whose authoritative node is not this mn
343
            nodeId = new NodeReference();
344
            try {
345
                String currentNodeId = PropertyService.getInstance().getProperty("dataone.nodeId"); // return only pids for which this mn
346
                nodeId.setValue(currentNodeId);
347
            } catch(Exception e) {
348
                throw new ServiceFailure("1580", e.getMessage());
349
            }
350
        }
351
		return impl.listObjects(session, startTime, endTime, formatid, null, nodeId, start, count);
352
	}
353

    
354
	@Override
355
	public QueryEngineList listQueryEngines() throws InvalidToken,
356
			ServiceFailure, NotAuthorized, NotImplemented {
357
		return impl.listQueryEngines(null);
358
	}
359

    
360
	@Override
361
	public InputStream query(String queryEngine, String query) throws InvalidToken,
362
			ServiceFailure, NotAuthorized, InvalidRequest, NotImplemented,
363
			NotFound {
364
		return impl.query(null, queryEngine, query);
365
	}
366

    
367
	@Override
368
	public ObjectLocationList resolve(Identifier pid) throws InvalidToken,
369
			ServiceFailure, NotAuthorized, NotFound, NotImplemented {
370
		return impl.resolve(null, pid);
371
	}
372

    
373
	@Override
374
	@Deprecated
375
	public ObjectLocationList resolve(Session session, Identifier pid)
376
			throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
377
			NotImplemented {
378
		return impl.resolve(session, pid);
379
	}
380

    
381
	@Override
382
	public ObjectList search(String queryType, String query) throws InvalidToken,
383
			ServiceFailure, NotAuthorized, InvalidRequest, NotImplemented {
384
		return impl.search(null, queryType, query);
385
	}
386

    
387
	@Override
388
	@Deprecated
389
	public ObjectList search(Session session, String queryType, String query)
390
			throws InvalidToken, ServiceFailure, NotAuthorized, InvalidRequest,
391
			NotImplemented {
392
		return impl.search(session, queryType, query);
393
	}
394

    
395
	@Override
396
	public Identifier archive(Identifier pid) throws InvalidToken,
397
			ServiceFailure, NotAuthorized, NotFound, NotImplemented {
398
	    String serviceFailure = "4972";
399
        String notFound = "4971";
400
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object specified by "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
401
                "The object specified by "+pid.getValue()+" does not exist at this node.");
402
		return impl.archive(null, pid);
403
	}
404

    
405
	@Override
406
	@Deprecated
407
	public Identifier archive(Session session, Identifier pid)
408
			throws InvalidToken, ServiceFailure, InvalidRequest, NotAuthorized,
409
			NotFound, NotImplemented {
410
	    String serviceFailure = "4972";
411
        String notFound = "4971";
412
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object specified by "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
413
                "The object specified by "+pid.getValue()+" does not exist at this node.");
414
		return impl.archive(session, pid);
415
	}
416

    
417
	@Override
418
	public Identifier create(Identifier pid, InputStream object,
419
			SystemMetadata sysmeta) throws InvalidToken, ServiceFailure,
420
			NotAuthorized, IdentifierNotUnique, UnsupportedType,
421
			InsufficientResources, InvalidSystemMetadata, NotImplemented,
422
			InvalidRequest {
423
		return this.create(null, pid, object, sysmeta);
424
	}
425

    
426
	@Override
427
	@Deprecated
428
	public Identifier create(Session session, Identifier pid, InputStream object,
429
			SystemMetadata sysmeta) throws InvalidToken, ServiceFailure,
430
			NotAuthorized, IdentifierNotUnique, UnsupportedType,
431
			InsufficientResources, InvalidSystemMetadata, NotImplemented,
432
			InvalidRequest {
433
		
434
		//convert sysmeta to newer version
435
		org.dataone.service.types.v2.SystemMetadata v2Sysmeta = null;
436
		try {
437
			v2Sysmeta = TypeFactory.convertTypeFromType(sysmeta, org.dataone.service.types.v2.SystemMetadata.class);
438
		} catch (Exception e) {
439
		    IOUtils.closeQuietly(object);
440
			// report as service failure
441
			ServiceFailure sf = new ServiceFailure("1030", e.getMessage());
442
			sf.initCause(e);
443
			throw sf;
444
		}
445
		
446
		return impl.create(session, pid, object, v2Sysmeta);
447
	}
448

    
449
	@Override
450
	public Identifier delete(Identifier pid) throws InvalidToken,
451
			ServiceFailure, NotAuthorized, NotFound, NotImplemented {
452
	    String serviceFailure = "4962";
453
        String notFound = "4961";
454
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object specified by "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
455
                "The object specified by "+pid.getValue()+" does not exist at this node.");
456
		return impl.delete(null, pid);
457
	}
458

    
459
	@Override
460
	@Deprecated
461
	public Identifier delete(Session session, Identifier pid)
462
			throws InvalidToken, ServiceFailure, InvalidRequest, NotAuthorized,
463
			NotFound, NotImplemented {
464
	    String serviceFailure = "4962";
465
        String notFound = "4961";
466
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object specified by "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
467
                "The object specified by "+pid.getValue()+" does not exist at this node.");
468
		return impl.delete(session, pid);
469
	}
470

    
471
	@Override
472
	public Identifier generateIdentifier(String scheme, String fragment)
473
			throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
474
			InvalidRequest {
475
		return impl.generateIdentifier(null, scheme, fragment);
476
	}
477

    
478
	@Override
479
	@Deprecated
480
	public Identifier generateIdentifier(Session session, String scheme, String fragment)
481
			throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
482
			InvalidRequest {
483
		return impl.generateIdentifier(session, scheme, fragment);
484
	}
485

    
486
	@Override
487
	public ObjectFormat getFormat(ObjectFormatIdentifier fmtid)
488
			throws ServiceFailure, NotFound, NotImplemented, InvalidRequest {
489
	        org.dataone.service.types.v2.ObjectFormat format = impl.getFormat(fmtid);
490
	        ObjectFormat v1Format = null;
491
	        try {
492
	            v1Format = TypeFactory.convertTypeFromType(format, ObjectFormat.class);
493
	        } catch (Exception e) {
494
	            ServiceFailure sf = new ServiceFailure("4846", e.getMessage());
495
	            sf.initCause(e);
496
	            throw sf;
497
	        }
498
		return v1Format;
499
	}
500

    
501
	@Override
502
	public Log getLogRecords(Date fromDate, Date toDate, Event event,
503
			String pidFilter, Integer start, Integer count) throws InvalidToken, InvalidRequest,
504
			ServiceFailure, NotAuthorized, NotImplemented,
505
			InsufficientResources {
506
		return this.getLogRecords(null, fromDate, toDate, event, pidFilter, start, count);
507
	}
508

    
509
	@Override
510
	@Deprecated
511
	public Log getLogRecords(Session session, Date fromDate, Date toDate, Event event,
512
			String pidFilter, Integer start, Integer count) throws InvalidToken,
513
			InvalidRequest, ServiceFailure, NotAuthorized, NotImplemented,
514
			InsufficientResources {
515
	    Log retLog = new Log();
516
        if(pidFilter != null && !pidFilter.trim().equals("")) {
517
            String serviceFailure = "1490";
518
            String notFound = "1020";
519
            Identifier pid = new Identifier();
520
            pid.setValue(pidFilter);
521
            try {
522
                impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object for given PID "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
523
                        "The given PID: "+pid.getValue()+" doesn't exist in this node");
524
            } catch (NotFound e) {
525
                //return 0 record since the pid doesn't exist
526
                logMetacat.info(e.getMessage());
527
                return retLog;
528
            }
529
            
530
        }
531
	    String eventValue = null;
532
        if(event != null) {
533
            eventValue = event.xmlValue();
534
        }
535
		org.dataone.service.types.v2.Log log = impl.getLogRecords(session, fromDate, toDate, eventValue, pidFilter, start, count);
536
		try {
537
			retLog = TypeFactory.convertTypeFromType(log, Log.class);
538
            //LogV2toV1Converter converter = new LogV2toV1Converter();
539
            //retLog = converter.convert(log);
540
		} catch (Exception e) {
541
			// report as service failure
542
			ServiceFailure sf = new ServiceFailure("1490", e.getMessage());
543
			sf.initCause(e);
544
			throw sf;
545
		}
546
		return retLog;
547
	}
548

    
549
	@Override
550
	public boolean hasReservation(Subject subject, Identifier pid)
551
			throws InvalidToken, ServiceFailure, NotFound, NotAuthorized,
552
			NotImplemented, InvalidRequest {
553
		return impl.hasReservation(null, subject, pid);
554
	}
555

    
556
	@Override
557
	@Deprecated
558
	public boolean hasReservation(Session session, Subject subject, Identifier pid)
559
			throws InvalidToken, ServiceFailure, NotFound, NotAuthorized,
560
			NotImplemented, InvalidRequest {
561
		return impl.hasReservation(session, subject, pid);
562

    
563
	}
564

    
565
	@Override
566
	public ChecksumAlgorithmList listChecksumAlgorithms()
567
			throws ServiceFailure, NotImplemented {
568
		return impl.listChecksumAlgorithms();
569
	}
570

    
571
	@Override
572
	public ObjectFormatList listFormats() throws ServiceFailure, NotImplemented {
573
		org.dataone.service.types.v2.ObjectFormatList formats = impl.listFormats();
574
		ObjectFormatList retFormats = new ObjectFormatList();
575
		try {
576
		    /*if(formats != null) {
577
		        List<org.dataone.service.types.v2.ObjectFormat> objectFormatList = formats.getObjectFormatList();
578
		        if(objectFormatList != null) {
579
		            for(org.dataone.service.types.v2.ObjectFormat format : objectFormatList) {
580
	                    ObjectFormat v1Format = TypeFactory.convertTypeFromType(format, ObjectFormat.class);
581
	                    retFormats.addObjectFormat(v1Format);
582
	                }
583
		        }
584
		        
585
		    }*/
586
			retFormats = TypeFactory.convertTypeFromType(formats, ObjectFormatList.class);
587
		} catch (Exception e) {
588
			// report as service failure
589
			ServiceFailure sf = new ServiceFailure("4841", e.getMessage());
590
			sf.initCause(e);
591
			throw sf;
592
		}
593
		return retFormats;
594
	}
595

    
596
	@Override
597
	public NodeList listNodes() throws NotImplemented, ServiceFailure {
598
		org.dataone.service.types.v2.NodeList nodes = impl.listNodes();
599
		NodeList retNodes = null;
600
		try {
601
			retNodes = TypeFactory.convertTypeFromType(nodes, NodeList.class);
602
		} catch (Exception e) {
603
			// report as service failure
604
			ServiceFailure sf = new ServiceFailure("4801", e.getMessage());
605
			sf.initCause(e);
606
			throw sf;
607
		}
608
		return retNodes;
609
	}
610

    
611
	@Override
612
	public Date ping() throws NotImplemented, ServiceFailure,
613
			InsufficientResources {
614
		return impl.ping();
615
	}
616

    
617
	@Override
618
	public Identifier registerSystemMetadata(Identifier pid,
619
			SystemMetadata sysmeta) throws NotImplemented, NotAuthorized,
620
			ServiceFailure, InvalidRequest, InvalidSystemMetadata, InvalidToken {
621
		return this.registerSystemMetadata(null, pid, sysmeta);
622
		
623
	}
624

    
625
	@Override
626
	@Deprecated
627
	public Identifier registerSystemMetadata(Session session, Identifier pid,
628
			SystemMetadata sysmeta) throws NotImplemented, NotAuthorized,
629
			ServiceFailure, InvalidRequest, InvalidSystemMetadata, InvalidToken {
630
	    if (pid == null || pid.getValue().trim().equals("")) {
631
	        throw new InvalidRequest("4863", "The pid should not be null in the register system metadata request");
632
	    }
633
	    if(sysmeta == null) {
634
	        throw new InvalidRequest("4863", "The system metadata object should not be null in the register system metadata request for the pid"+pid.getValue());
635
	    }
636
		//convert sysmeta to newer version
637
		org.dataone.service.types.v2.SystemMetadata v2Sysmeta = null;
638
		try {
639
			v2Sysmeta = TypeFactory.convertTypeFromType(sysmeta, org.dataone.service.types.v2.SystemMetadata.class);
640
			
641
		} catch (Exception e) {
642
			// report as service failure
643
			ServiceFailure sf = new ServiceFailure("1030", e.getMessage());
644
			sf.initCause(e);
645
			throw sf;
646
		}
647
		//this method will apply to the objects whose authoritative mn is v1.
648
        D1NodeVersionChecker checker = new D1NodeVersionChecker(v2Sysmeta.getAuthoritativeMemberNode());
649
        String version = checker.getVersion("MNRead");
650
        if(version == null) {
651
            throw new ServiceFailure("4862", "Couldn't determine the MNRead version of the authoritative member node for the pid "+pid.getValue());
652
        } else if (version.equalsIgnoreCase(D1NodeVersionChecker.V2)) {
653
            //we don't apply this method to an object whose authoritative node is v2
654
            throw new NotAuthorized("4861", edu.ucsb.nceas.metacat.dataone.CNodeService.V2V1MISSMATCH);
655
        } else if (!version.equalsIgnoreCase(D1NodeVersionChecker.V1)) {
656
            //we don't understand this version (it is not v1 or v2)
657
            throw new InvalidRequest("4863", "The version of the MNRead is "+version+" for the authoritative member node of the object "+pid.getValue()+". We don't support it.");
658
        }
659
        //set the serial version to one
660
        v2Sysmeta.setSerialVersion(BigInteger.ONE);
661
        // the v2(impl).registerSysteMetadata will reset the system metadata modification date 
662
        //for the objects whose authoritative member node is v1. 
663
		return impl.registerSystemMetadata(session, pid, v2Sysmeta);
664
	}
665

    
666
	@Override
667
	public Identifier reserveIdentifier(Identifier pid) throws InvalidToken,
668
			ServiceFailure, NotAuthorized, IdentifierNotUnique, NotImplemented,
669
			InvalidRequest {
670
		return impl.reserveIdentifier(null, pid);
671
	}
672

    
673
	@Override
674
	@Deprecated
675
	public Identifier reserveIdentifier(Session session, Identifier pid)
676
			throws InvalidToken, ServiceFailure, NotAuthorized,
677
			IdentifierNotUnique, NotImplemented, InvalidRequest {
678
		return impl.reserveIdentifier(session, pid);
679
	}
680

    
681
	@Override
682
	public boolean setObsoletedBy(Identifier pid, Identifier obsoletedByPid, long serialVersion)
683
			throws NotImplemented, NotFound, NotAuthorized, ServiceFailure,
684
			InvalidRequest, InvalidToken, VersionMismatch {
685
	    /*String serviceFailure = "4941";
686
        String notFound = "4944";
687
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object for given PID "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
688
                "No object could be found for given PID: "+obsoletedByPid.getValue());*/
689
		return impl.setObsoletedBy(null, pid, obsoletedByPid, serialVersion);
690
	}
691

    
692
	@Override
693
	@Deprecated
694
	public boolean setObsoletedBy(Session session, Identifier pid, Identifier obsoletedByPid, long serialVersion) 
695
			throws NotImplemented, NotFound,
696
			NotAuthorized, ServiceFailure, InvalidRequest, InvalidToken,
697
			VersionMismatch {
698
	    /*String serviceFailure = "4941";
699
        String notFound = "4944";
700
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object for given PID "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
701
                "No object could be found for given PID: "+obsoletedByPid.getValue());*/
702
		return impl.setObsoletedBy(session, pid, obsoletedByPid, serialVersion);
703

    
704
	}
705

    
706
	@Override
707
	public boolean isAuthorized(Identifier pid, Permission permission)
708
			throws ServiceFailure, InvalidToken, NotFound, NotAuthorized,
709
			NotImplemented, InvalidRequest {
710
	    String serviceFailure = "1760";
711
        String notFound = "1800";
712
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object specified by "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
713
                "The object specified by "+pid.getValue()+" does not exist at this node.");
714
		return impl.isAuthorized(null, pid, permission);
715
	}
716

    
717
	@Override
718
	@Deprecated
719
	public boolean isAuthorized(Session session, Identifier pid, Permission permission)
720
			throws ServiceFailure, InvalidToken, NotFound, NotAuthorized,
721
			NotImplemented, InvalidRequest {
722
	    String serviceFailure = "1760";
723
        String notFound = "1800";
724
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object specified by "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
725
                "The object specified by "+pid.getValue()+" does not exist at this node.");
726
		return impl.isAuthorized(session, pid, permission);
727
	}
728

    
729
	@Override
730
	public boolean setAccessPolicy(Identifier pid,
731
			AccessPolicy accessPolicy, long serialVersion)
732
			throws InvalidToken, NotFound, NotImplemented, NotAuthorized,
733
			ServiceFailure, InvalidRequest, VersionMismatch {
734
	    String serviceFailure = "4430";
735
        String notFound = "4400";
736
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object for given PID "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
737
                "No object could be found for given PID: "+pid.getValue());
738
		return impl.setAccessPolicy(null, pid, accessPolicy, serialVersion);
739
	}
740

    
741
	@Override
742
	@Deprecated
743
	public boolean setAccessPolicy(Session session, Identifier pid,
744
			AccessPolicy accessPolicy, long serialVersion) throws InvalidToken, NotFound,
745
			NotImplemented, NotAuthorized, ServiceFailure, InvalidRequest,
746
			VersionMismatch {
747
	    String serviceFailure = "4430";
748
        String notFound = "4400";
749
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object for given PID "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
750
                "No object could be found for given PID: "+pid.getValue());
751
		return impl.setAccessPolicy(session, pid, accessPolicy, serialVersion);
752
	}
753

    
754
	@Override
755
	public Identifier setRightsHolder(Identifier pid, Subject userId, long serialVersion)
756
			throws InvalidToken, ServiceFailure, NotFound, NotAuthorized,
757
			NotImplemented, InvalidRequest, VersionMismatch {
758
	    String serviceFailure = "4490";
759
        String notFound = "4460";
760
        impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object for given PID "+pid.getValue()+" couldn't be identified if it exists",  notFound, 
761
                "No object could be found for given PID: "+pid.getValue());
762
		return impl.setRightsHolder(null, pid, userId, serialVersion);
763
	}
764

    
765
	@Override
766
	@Deprecated
767
	public Identifier setRightsHolder(Session session, Identifier pid,
768
			Subject userId, long serialVersion) throws InvalidToken, ServiceFailure,
769
			NotFound, NotAuthorized, NotImplemented, InvalidRequest,
770
			VersionMismatch {
771
		return impl.setRightsHolder(session, pid, userId, serialVersion);
772

    
773
	}
774

    
775
}
(1-1/2)