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:  $'
7
 *     '$Date:  $'
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;
25

    
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.math.BigInteger;
29
import java.security.NoSuchAlgorithmException;
30
import java.sql.SQLException;
31
import java.util.Calendar;
32
import java.util.Date;
33
import java.util.List;
34
import java.util.Timer;
35

    
36
import javax.servlet.http.HttpServletRequest;
37

    
38
import org.apache.commons.io.IOUtils;
39
import org.apache.log4j.Logger;
40
import org.dataone.client.CNode;
41
import org.dataone.client.D1Client;
42
import org.dataone.client.MNode;
43
import org.dataone.client.auth.CertificateManager;
44
import org.dataone.configuration.Settings;
45
import org.dataone.service.exceptions.BaseException;
46
import org.dataone.service.exceptions.IdentifierNotUnique;
47
import org.dataone.service.exceptions.InsufficientResources;
48
import org.dataone.service.exceptions.InvalidRequest;
49
import org.dataone.service.exceptions.InvalidSystemMetadata;
50
import org.dataone.service.exceptions.InvalidToken;
51
import org.dataone.service.exceptions.NotAuthorized;
52
import org.dataone.service.exceptions.NotFound;
53
import org.dataone.service.exceptions.NotImplemented;
54
import org.dataone.service.exceptions.ServiceFailure;
55
import org.dataone.service.exceptions.SynchronizationFailed;
56
import org.dataone.service.exceptions.UnsupportedType;
57
import org.dataone.service.mn.tier1.v1.MNCore;
58
import org.dataone.service.mn.tier1.v1.MNRead;
59
import org.dataone.service.mn.tier2.v1.MNAuthorization;
60
import org.dataone.service.mn.tier3.v1.MNStorage;
61
import org.dataone.service.mn.tier4.v1.MNReplication;
62
import org.dataone.service.types.v1.Checksum;
63
import org.dataone.service.types.v1.DescribeResponse;
64
import org.dataone.service.types.v1.Event;
65
import org.dataone.service.types.v1.Group;
66
import org.dataone.service.types.v1.Identifier;
67
import org.dataone.service.types.v1.Log;
68
import org.dataone.service.types.v1.LogEntry;
69
import org.dataone.service.types.v1.MonitorInfo;
70
import org.dataone.service.types.v1.MonitorList;
71
import org.dataone.service.types.v1.Node;
72
import org.dataone.service.types.v1.NodeList;
73
import org.dataone.service.types.v1.NodeReference;
74
import org.dataone.service.types.v1.NodeState;
75
import org.dataone.service.types.v1.NodeType;
76
import org.dataone.service.types.v1.ObjectFormatIdentifier;
77
import org.dataone.service.types.v1.ObjectList;
78
import org.dataone.service.types.v1.Permission;
79
import org.dataone.service.types.v1.Ping;
80
import org.dataone.service.types.v1.ReplicationStatus;
81
import org.dataone.service.types.v1.Schedule;
82
import org.dataone.service.types.v1.Service;
83
import org.dataone.service.types.v1.Services;
84
import org.dataone.service.types.v1.Session;
85
import org.dataone.service.types.v1.Subject;
86
import org.dataone.service.types.v1.Synchronization;
87
import org.dataone.service.types.v1.SystemMetadata;
88
import org.dataone.service.types.v1.util.ChecksumUtil;
89
import org.dataone.service.util.Constants;
90

    
91
import edu.ucsb.nceas.metacat.DocumentImpl;
92
import edu.ucsb.nceas.metacat.EventLog;
93
import edu.ucsb.nceas.metacat.IdentifierManager;
94
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
95
import edu.ucsb.nceas.metacat.MetacatHandler;
96
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
97
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService;
98
import edu.ucsb.nceas.metacat.properties.PropertyService;
99
import edu.ucsb.nceas.metacat.util.SystemUtil;
100
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
101

    
102
/**
103
 * Represents Metacat's implementation of the DataONE Member Node 
104
 * service API. Methods implement the various MN* interfaces, and methods common
105
 * to both Member Node and Coordinating Node interfaces are found in the
106
 * D1NodeService base class.
107
 * 
108
 * Implements:
109
 * MNCore.ping()
110
 * MNCore.getLogRecords()
111
 * MNCore.getObjectStatistics()
112
 * MNCore.getOperationStatistics()
113
 * MNCore.getStatus()
114
 * MNCore.getCapabilities()
115
 * MNRead.get()
116
 * MNRead.getSystemMetadata()
117
 * MNRead.describe()
118
 * MNRead.getChecksum()
119
 * MNRead.listObjects()
120
 * MNRead.synchronizationFailed()
121
 * MNAuthorization.isAuthorized()
122
 * MNAuthorization.setAccessPolicy()
123
 * MNStorage.create()
124
 * MNStorage.update()
125
 * MNStorage.delete()
126
 * MNReplication.replicate()
127
 * 
128
 */
129
public class MNodeService extends D1NodeService 
130
    implements MNAuthorization, MNCore, MNRead, MNReplication, MNStorage {
131

    
132
    /* the logger instance */
133
    private Logger logMetacat = null;
134
    
135
    /* A reference to a remote Memeber Node */
136
    private MNode mn;
137
    
138
    /* A reference to a Coordinating Node */
139
    private CNode cn;
140

    
141

    
142
    /**
143
     * Singleton accessor to get an instance of MNodeService.
144
     * 
145
     * @return instance - the instance of MNodeService
146
     */
147
    public static MNodeService getInstance(HttpServletRequest request) {
148
        return new MNodeService(request);
149
    }
150

    
151
    /**
152
     * Constructor, private for singleton access
153
     */
154
    private MNodeService(HttpServletRequest request) {
155
        super(request);
156
        logMetacat = Logger.getLogger(MNodeService.class);
157
        
158
        // set the Member Node certificate file location
159
        CertificateManager.getInstance().setCertificateLocation(Settings.getConfiguration().getString("D1Client.certificate.file"));
160
    }
161

    
162
    /**
163
     * Deletes an object from the Member Node, where the object is either a 
164
     * data object or a science metadata object.
165
     * 
166
     * @param session - the Session object containing the credentials for the Subject
167
     * @param pid - The object identifier to be deleted
168
     * 
169
     * @return pid - the identifier of the object used for the deletion
170
     * 
171
     * @throws InvalidToken
172
     * @throws ServiceFailure
173
     * @throws NotAuthorized
174
     * @throws NotFound
175
     * @throws NotImplemented
176
     * @throws InvalidRequest
177
     */
178
    @Override
179
    public Identifier delete(Session session, Identifier pid) 
180
        throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
181

    
182
    	// defer to superclass implementation
183
        return super.delete(session, pid);
184
    }
185

    
186
    /**
187
     * Updates an existing object by creating a new object identified by 
188
     * newPid on the Member Node which explicitly obsoletes the object 
189
     * identified by pid through appropriate changes to the SystemMetadata 
190
     * of pid and newPid
191
     * 
192
     * @param session - the Session object containing the credentials for the Subject
193
     * @param pid - The identifier of the object to be updated
194
     * @param object - the new object bytes
195
     * @param sysmeta - the new system metadata describing the object
196
     * 
197
     * @return newPid - the identifier of the new object
198
     * 
199
     * @throws InvalidToken
200
     * @throws ServiceFailure
201
     * @throws NotAuthorized
202
     * @throws NotFound
203
     * @throws NotImplemented
204
     * @throws IdentifierNotUnique
205
     * @throws UnsupportedType
206
     * @throws InsufficientResources
207
     * @throws InvalidSystemMetadata
208
     * @throws InvalidRequest
209
     */
210
    @Override
211
    public Identifier update(Session session, Identifier pid, InputStream object, 
212
        Identifier newPid, SystemMetadata sysmeta) 
213
        throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, 
214
        UnsupportedType, InsufficientResources, NotFound, 
215
        InvalidSystemMetadata, NotImplemented, InvalidRequest {
216

    
217
        String localId = null;
218
        boolean allowed = false;
219
        boolean isScienceMetadata = false;
220
        
221
        if (session == null) {
222
        	throw new InvalidToken("1210", "No session has been provided");
223
        }
224
        Subject subject = session.getSubject();
225

    
226
        // do we have a valid pid?
227
        if (pid == null || pid.getValue().trim().equals("")) {
228
            throw new InvalidRequest("1202", "The provided identifier was invalid.");
229
            
230
        }
231

    
232
        // check for the existing identifier
233
        try {
234
            localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
235
            
236
        } catch (McdbDocNotFoundException e) {
237
            throw new InvalidRequest("1202", "The object with the provided " + 
238
                "identifier was not found.");
239
            
240
        }
241
        
242
        // set the originating node
243
        NodeReference originMemberNode = this.getCapabilities().getIdentifier();
244
        sysmeta.setOriginMemberNode(originMemberNode);
245
        
246
        // set the submitter to match the certificate
247
        sysmeta.setSubmitter(subject);
248
        // set the dates
249
        Date now = Calendar.getInstance().getTime();
250
        sysmeta.setDateSysMetadataModified(now);
251
        sysmeta.setDateUploaded(now);
252

    
253
        // does the subject have WRITE ( == update) priveleges on the pid?
254
        allowed = isAuthorized(session, pid, Permission.WRITE);
255

    
256
        if (allowed) {
257
        	
258
        	// check quality of SM
259
        	if (sysmeta.getObsoletedBy() != null) {
260
        		throw new InvalidSystemMetadata("1300", "Cannot include obsoletedBy when updating object");
261
        	}
262
        	if (sysmeta.getObsoletes() != null && !sysmeta.getObsoletes().getValue().equals(pid.getValue())) {
263
        		throw new InvalidSystemMetadata("1300", "The identifier provided in obsoletes does not match old Identifier");
264
        	}
265

    
266
            // get the existing system metadata for the object
267
            SystemMetadata existingSysMeta = getSystemMetadata(session, pid);
268

    
269
            // add the newPid to the obsoletedBy list for the existing sysmeta
270
            existingSysMeta.setObsoletedBy(newPid);
271

    
272
            // then update the existing system metadata
273
            updateSystemMetadata(existingSysMeta);
274

    
275
            // prep the new system metadata, add pid to the affected lists
276
            sysmeta.setObsoletes(pid);
277
            //sysmeta.addDerivedFrom(pid);
278

    
279
            isScienceMetadata = isScienceMetadata(sysmeta);
280

    
281
            // do we have XML metadata or a data object?
282
            if (isScienceMetadata) {
283

    
284
                // update the science metadata XML document
285
                // TODO: handle non-XML metadata/data documents (like netCDF)
286
                // TODO: don't put objects into memory using stream to string
287
                String objectAsXML = "";
288
                try {
289
                    objectAsXML = IOUtils.toString(object, "UTF-8");
290
                    localId = insertOrUpdateDocument(objectAsXML, newPid, session, "update");
291
                    // register the newPid and the generated localId
292
                    if (newPid != null) {
293
                        IdentifierManager.getInstance().createMapping(newPid.getValue(), localId);
294

    
295
                    }
296

    
297
                } catch (IOException e) {
298
                    String msg = "The Node is unable to create the object. " + "There was a problem converting the object to XML";
299
                    logMetacat.info(msg);
300
                    throw new ServiceFailure("1310", msg + ": " + e.getMessage());
301

    
302
                }
303

    
304
            } else {
305

    
306
                // update the data object
307
                localId = insertDataObject(object, newPid, session);
308

    
309
            }
310

    
311
            // and insert the new system metadata
312
            insertSystemMetadata(sysmeta);
313

    
314
            // log the update event
315
            EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), subject.getValue(), localId, Event.UPDATE.toString());
316

    
317
        } else {
318
            throw new NotAuthorized("1200", "The provided identity does not have " + "permission to UPDATE the object identified by " + pid.getValue()
319
                    + " on the Member Node.");
320
        }
321

    
322
        return newPid;
323
    }
324

    
325
    public Identifier create(Session session, Identifier pid, InputStream object, SystemMetadata sysmeta) throws InvalidToken, ServiceFailure, NotAuthorized,
326
            IdentifierNotUnique, UnsupportedType, InsufficientResources, InvalidSystemMetadata, NotImplemented, InvalidRequest {
327

    
328
        // check for null session
329
        if (session == null) {
330
          throw new InvalidToken("1110", "Session is required to WRITE to the Node.");
331
        }
332
        // set the submitter to match the certificate
333
        sysmeta.setSubmitter(session.getSubject());
334
        // set the originating node
335
        NodeReference originMemberNode = this.getCapabilities().getIdentifier();
336
        sysmeta.setOriginMemberNode(originMemberNode);
337
        sysmeta.setArchived(false);
338

    
339
        // set the dates
340
        Date now = Calendar.getInstance().getTime();
341
        sysmeta.setDateSysMetadataModified(now);
342
        sysmeta.setDateUploaded(now);
343
        
344
        // set the serial version
345
        sysmeta.setSerialVersion(BigInteger.ZERO);
346

    
347
        // check that we are not attempting to subvert versioning
348
        if (sysmeta.getObsoletes() != null && sysmeta.getObsoletes().getValue() != null) {
349
            throw new InvalidSystemMetadata("1180", 
350
              "The supplied system metadata is invalid. " +
351
              "The obsoletes field cannot have a value when creating entries.");
352
        }
353
        
354
        if (sysmeta.getObsoletedBy() != null && sysmeta.getObsoletedBy().getValue() != null) {
355
            throw new InvalidSystemMetadata("1180", 
356
              "The supplied system metadata is invalid. " +
357
              "The obsoletedBy field cannot have a value when creating entries.");
358
        }
359
        
360

    
361
        // call the shared impl
362
        return super.create(session, pid, object, sysmeta);
363
    }
364

    
365
    /**
366
     * Called by a Coordinating Node to request that the Member Node create a 
367
     * copy of the specified object by retrieving it from another Member 
368
     * Node and storing it locally so that it can be made accessible to 
369
     * the DataONE system.
370
     * 
371
     * @param session - the Session object containing the credentials for the Subject
372
     * @param sysmeta - Copy of the CN held system metadata for the object
373
     * @param sourceNode - A reference to node from which the content should be 
374
     *                     retrieved. The reference should be resolved by 
375
     *                     checking the CN node registry.
376
     * 
377
     * @return true if the replication succeeds
378
     * 
379
     * @throws ServiceFailure
380
     * @throws NotAuthorized
381
     * @throws NotImplemented
382
     * @throws UnsupportedType
383
     * @throws InsufficientResources
384
     * @throws InvalidRequest
385
     */
386
    @Override
387
    public boolean replicate(Session session, SystemMetadata sysmeta,
388
            NodeReference sourceNode) throws NotImplemented, ServiceFailure,
389
            NotAuthorized, InvalidRequest, InsufficientResources,
390
            UnsupportedType {
391

    
392
        if (session != null && sysmeta != null && sourceNode != null) {
393
            logMetacat.info("MNodeService.replicate() called with parameters: \n" +
394
                            "\tSession.Subject      = "                           +
395
                            session.getSubject().getValue() + "\n"                +
396
                            "\tidentifier           = "                           + 
397
                            sysmeta.getIdentifier().getValue()                    +
398
                            "\n" + "\tSource NodeReference ="                     +
399
                            sourceNode.getValue());
400
        }
401
        boolean result = false;
402
        String nodeIdStr = null;
403
        NodeReference nodeId = null;
404

    
405
        // get the referenced object
406
        Identifier pid = sysmeta.getIdentifier();
407

    
408
        // get from the membernode
409
        // TODO: switch credentials for the server retrieval?
410
        this.mn = D1Client.getMN(sourceNode);
411
        this.cn = D1Client.getCN();
412
        InputStream object = null;
413
        Session thisNodeSession = null;
414
        SystemMetadata localSystemMetadata = null;
415
        BaseException failure = null;
416
        String localId = null;
417
        
418
        // TODO: check credentials
419
        // cannot be called by public
420
        if (session == null || session.getSubject() == null) {
421
            String msg = "No session was provided to replicate identifier " +
422
            sysmeta.getIdentifier().getValue();
423
            failure = new NotAuthorized("2152", msg);
424
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
425
            logMetacat.info(msg);
426
            return true;
427
        }
428

    
429

    
430
        // get the local node id
431
        try {
432
            nodeIdStr = PropertyService.getProperty("dataone.nodeId");
433
            nodeId = new NodeReference();
434
            nodeId.setValue(nodeIdStr);
435

    
436
        } catch (PropertyNotFoundException e1) {
437
            String msg = "Couldn't get dataone.nodeId property: " + e1.getMessage();
438
            failure = new ServiceFailure("2151", msg);
439
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
440
            logMetacat.error(msg);
441
            return true;
442

    
443
        }
444
        
445

    
446
        try {
447
            // do we already have a replica?
448
            try {
449
                localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
450
                // if we have a local id, get the local object
451
                try {
452
                    object = MetacatHandler.read(localId);
453
                } catch (Exception e) {
454
                	// NOTE: we may already know about this ID because it could be a data file described by a metadata file
455
                	// https://redmine.dataone.org/issues/2572
456
                	// TODO: fix this so that we don't prevent ourselves from getting replicas
457
                	
458
                    // let the CN know that the replication failed
459
                	logMetacat.warn("Object content not found on this node despite having localId: " + localId);
460
                	String msg = "Can't read the object bytes properly, replica is invalid.";
461
                    ServiceFailure serviceFailure = new ServiceFailure("2151", msg);
462
                    setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, serviceFailure);
463
                    logMetacat.warn(msg);
464
                    throw serviceFailure;
465
                    
466
                }
467

    
468
            } catch (McdbDocNotFoundException e) {
469
                logMetacat.info("No replica found. Continuing.");
470
                
471
            }
472
            
473
            // no local replica, get a replica
474
            if ( object == null ) {
475
                // session should be null to use the default certificate
476
                // location set in the Certificate manager
477
                object = mn.getReplica(thisNodeSession, pid);
478
                logMetacat.info("MNodeService.getReplica() called for identifier "
479
                                + pid.getValue());
480

    
481
            }
482

    
483
        } catch (InvalidToken e) {            
484
            String msg = "Could not retrieve object to replicate (InvalidToken): "+ e.getMessage();
485
            failure = new ServiceFailure("2151", msg);
486
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
487
            logMetacat.error(msg);
488
            throw new ServiceFailure("2151", msg);
489

    
490
        } catch (NotFound e) {
491
            String msg = "Could not retrieve object to replicate (NotFound): "+ e.getMessage();
492
            failure = new ServiceFailure("2151", msg);
493
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
494
            logMetacat.error(msg);
495
            throw new ServiceFailure("2151", msg);
496

    
497
        }
498

    
499
        // verify checksum on the object, if supported
500
        if (object.markSupported()) {
501
            Checksum givenChecksum = sysmeta.getChecksum();
502
            Checksum computedChecksum = null;
503
            try {
504
                computedChecksum = ChecksumUtil.checksum(object, givenChecksum.getAlgorithm());
505
                object.reset();
506

    
507
            } catch (Exception e) {
508
                String msg = "Error computing checksum on replica: " + e.getMessage();
509
                logMetacat.error(msg);
510
                ServiceFailure sf = new ServiceFailure("2151", msg);
511
                sf.initCause(e);
512
                throw sf;
513
            }
514
            if (!givenChecksum.getValue().equals(computedChecksum.getValue())) {
515
                logMetacat.error("Given    checksum for " + pid.getValue() + 
516
                    "is " + givenChecksum.getValue());
517
                logMetacat.error("Computed checksum for " + pid.getValue() + 
518
                    "is " + computedChecksum.getValue());
519
                throw new ServiceFailure("2151",
520
                        "Computed checksum does not match declared checksum");
521
            }
522
        }
523

    
524
        // add it to local store
525
        Identifier retPid;
526
        try {
527
            // skip the MN.create -- this mutates the system metadata and we don't want it to
528
            if ( localId == null ) {
529
                // TODO: this will fail if we already "know" about the identifier
530
            	// FIXME: see https://redmine.dataone.org/issues/2572
531
                retPid = super.create(session, pid, object, sysmeta);
532
                result = (retPid.getValue().equals(pid.getValue()));
533
            }
534
            
535
        } catch (Exception e) {
536
            String msg = "Could not save object to local store (" + e.getClass().getName() + "): " + e.getMessage();
537
            failure = new ServiceFailure("2151", msg);
538
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
539
            logMetacat.error(msg);
540
            throw new ServiceFailure("2151", msg);
541
            
542
        }
543

    
544
        // finish by setting the replication status
545
        setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.COMPLETED, null);
546
        return result;
547

    
548
    }
549

    
550
    /**
551
     * Return the object identified by the given object identifier
552
     * 
553
     * @param session - the Session object containing the credentials for the Subject
554
     * @param pid - the object identifier for the given object
555
     * 
556
     * @return inputStream - the input stream of the given object
557
     * 
558
     * @throws InvalidToken
559
     * @throws ServiceFailure
560
     * @throws NotAuthorized
561
     * @throws InvalidRequest
562
     * @throws NotImplemented
563
     */
564
    @Override
565
    public InputStream get(Session session, Identifier pid) 
566
    throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
567

    
568
        return super.get(session, pid);
569

    
570
    }
571

    
572
    /**
573
     * Returns a Checksum for the specified object using an accepted hashing algorithm
574
     * 
575
     * @param session - the Session object containing the credentials for the Subject
576
     * @param pid - the object identifier for the given object
577
     * @param algorithm -  the name of an algorithm that will be used to compute 
578
     *                     a checksum of the bytes of the object
579
     * 
580
     * @return checksum - the checksum of the given object
581
     * 
582
     * @throws InvalidToken
583
     * @throws ServiceFailure
584
     * @throws NotAuthorized
585
     * @throws NotFound
586
     * @throws InvalidRequest
587
     * @throws NotImplemented
588
     */
589
    @Override
590
    public Checksum getChecksum(Session session, Identifier pid, String algorithm) 
591
        throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
592
        InvalidRequest, NotImplemented {
593

    
594
        Checksum checksum = null;
595

    
596
        InputStream inputStream = get(session, pid);
597

    
598
        try {
599
            checksum = ChecksumUtil.checksum(inputStream, algorithm);
600

    
601
        } catch (NoSuchAlgorithmException e) {
602
            throw new ServiceFailure("1410", "The checksum for the object specified by " + pid.getValue() + "could not be returned due to an internal error: "
603
                    + e.getMessage());
604
        } catch (IOException e) {
605
            throw new ServiceFailure("1410", "The checksum for the object specified by " + pid.getValue() + "could not be returned due to an internal error: "
606
                    + e.getMessage());
607
        }
608

    
609
        if (checksum == null) {
610
            throw new ServiceFailure("1410", "The checksum for the object specified by " + pid.getValue() + "could not be returned.");
611
        }
612

    
613
        return checksum;
614
    }
615

    
616
    /**
617
     * Return the system metadata for a given object
618
     * 
619
     * @param session - the Session object containing the credentials for the Subject
620
     * @param pid - the object identifier for the given object
621
     * 
622
     * @return inputStream - the input stream of the given system metadata object
623
     * 
624
     * @throws InvalidToken
625
     * @throws ServiceFailure
626
     * @throws NotAuthorized
627
     * @throws NotFound
628
     * @throws InvalidRequest
629
     * @throws NotImplemented
630
     */
631
    @Override
632
    public SystemMetadata getSystemMetadata(Session session, Identifier pid) 
633
        throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
634
        NotImplemented {
635

    
636
        return super.getSystemMetadata(session, pid);
637
    }
638

    
639
    /**
640
     * Retrieve the list of objects present on the MN that match the calling parameters
641
     * 
642
     * @param session - the Session object containing the credentials for the Subject
643
     * @param startTime - Specifies the beginning of the time range from which 
644
     *                    to return object (>=)
645
     * @param endTime - Specifies the beginning of the time range from which 
646
     *                  to return object (>=)
647
     * @param objectFormat - Restrict results to the specified object format
648
     * @param replicaStatus - Indicates if replicated objects should be returned in the list
649
     * @param start - The zero-based index of the first value, relative to the 
650
     *                first record of the resultset that matches the parameters.
651
     * @param count - The maximum number of entries that should be returned in 
652
     *                the response. The Member Node may return less entries 
653
     *                than specified in this value.
654
     * 
655
     * @return objectList - the list of objects matching the criteria
656
     * 
657
     * @throws InvalidToken
658
     * @throws ServiceFailure
659
     * @throws NotAuthorized
660
     * @throws InvalidRequest
661
     * @throws NotImplemented
662
     */
663
    @Override
664
    public ObjectList listObjects(Session session, Date startTime, Date endTime, ObjectFormatIdentifier objectFormatId, Boolean replicaStatus, Integer start,
665
            Integer count) throws NotAuthorized, InvalidRequest, NotImplemented, ServiceFailure, InvalidToken {
666

    
667
        ObjectList objectList = null;
668

    
669
        try {
670
            objectList = IdentifierManager.getInstance().querySystemMetadata(startTime, endTime, objectFormatId, replicaStatus, start, count);
671
        } catch (Exception e) {
672
            throw new ServiceFailure("1580", "Error querying system metadata: " + e.getMessage());
673
        }
674

    
675
        return objectList;
676
    }
677

    
678
    /**
679
     * Return a description of the node's capabilities and services.
680
     * 
681
     * @return node - the technical capabilities of the Member Node
682
     * 
683
     * @throws ServiceFailure
684
     * @throws NotAuthorized
685
     * @throws InvalidRequest
686
     * @throws NotImplemented
687
     */
688
    @Override
689
    public Node getCapabilities() 
690
        throws NotImplemented, ServiceFailure {
691

    
692
        String nodeName = null;
693
        String nodeId = null;
694
        String subject = null;
695
        String contactSubject = null;
696
        String nodeDesc = null;
697
        String nodeTypeString = null;
698
        NodeType nodeType = null;
699
        String mnCoreServiceVersion = null;
700
        String mnReadServiceVersion = null;
701
        String mnAuthorizationServiceVersion = null;
702
        String mnStorageServiceVersion = null;
703
        String mnReplicationServiceVersion = null;
704

    
705
        boolean nodeSynchronize = false;
706
        boolean nodeReplicate = false;
707
        boolean mnCoreServiceAvailable = false;
708
        boolean mnReadServiceAvailable = false;
709
        boolean mnAuthorizationServiceAvailable = false;
710
        boolean mnStorageServiceAvailable = false;
711
        boolean mnReplicationServiceAvailable = false;
712

    
713
        try {
714
            // get the properties of the node based on configuration information
715
            nodeName = PropertyService.getProperty("dataone.nodeName");
716
            nodeId = PropertyService.getProperty("dataone.nodeId");
717
            subject = PropertyService.getProperty("dataone.subject");
718
            contactSubject = PropertyService.getProperty("dataone.contactSubject");
719
            nodeDesc = PropertyService.getProperty("dataone.nodeDescription");
720
            nodeTypeString = PropertyService.getProperty("dataone.nodeType");
721
            nodeType = NodeType.convert(nodeTypeString);
722
            nodeSynchronize = new Boolean(PropertyService.getProperty("dataone.nodeSynchronize")).booleanValue();
723
            nodeReplicate = new Boolean(PropertyService.getProperty("dataone.nodeReplicate")).booleanValue();
724

    
725
            mnCoreServiceVersion = PropertyService.getProperty("dataone.mnCore.serviceVersion");
726
            mnReadServiceVersion = PropertyService.getProperty("dataone.mnRead.serviceVersion");
727
            mnAuthorizationServiceVersion = PropertyService.getProperty("dataone.mnAuthorization.serviceVersion");
728
            mnStorageServiceVersion = PropertyService.getProperty("dataone.mnStorage.serviceVersion");
729
            mnReplicationServiceVersion = PropertyService.getProperty("dataone.mnReplication.serviceVersion");
730

    
731
            mnCoreServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnCore.serviceAvailable")).booleanValue();
732
            mnReadServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnRead.serviceAvailable")).booleanValue();
733
            mnAuthorizationServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnAuthorization.serviceAvailable")).booleanValue();
734
            mnStorageServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnStorage.serviceAvailable")).booleanValue();
735
            mnReplicationServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnReplication.serviceAvailable")).booleanValue();
736

    
737
            // Set the properties of the node based on configuration information and
738
            // calls to current status methods
739
            String serviceName = SystemUtil.getContextURL() + "/" + PropertyService.getProperty("dataone.serviceName");
740
            Node node = new Node();
741
            node.setBaseURL(serviceName + "/" + nodeTypeString);
742
            node.setDescription(nodeDesc);
743

    
744
            // set the node's health information
745
            node.setState(NodeState.UP);
746
            
747
            // set the ping response to the current value
748
            Ping canPing = new Ping();
749
            canPing.setSuccess(false);
750
            try {
751
            	Date pingDate = ping();
752
                canPing.setSuccess(pingDate != null);
753
            } catch (BaseException e) {
754
                e.printStackTrace();
755
                // guess it can't be pinged
756
            }
757
            
758
            node.setPing(canPing);
759

    
760
            NodeReference identifier = new NodeReference();
761
            identifier.setValue(nodeId);
762
            node.setIdentifier(identifier);
763
            Subject s = new Subject();
764
            s.setValue(subject);
765
            node.addSubject(s);
766
            Subject contact = new Subject();
767
            contact.setValue(contactSubject);
768
            node.addContactSubject(contact);
769
            node.setName(nodeName);
770
            node.setReplicate(nodeReplicate);
771
            node.setSynchronize(nodeSynchronize);
772

    
773
            // services: MNAuthorization, MNCore, MNRead, MNReplication, MNStorage
774
            Services services = new Services();
775

    
776
            Service sMNCore = new Service();
777
            sMNCore.setName("MNCore");
778
            sMNCore.setVersion(mnCoreServiceVersion);
779
            sMNCore.setAvailable(mnCoreServiceAvailable);
780

    
781
            Service sMNRead = new Service();
782
            sMNRead.setName("MNRead");
783
            sMNRead.setVersion(mnReadServiceVersion);
784
            sMNRead.setAvailable(mnReadServiceAvailable);
785

    
786
            Service sMNAuthorization = new Service();
787
            sMNAuthorization.setName("MNAuthorization");
788
            sMNAuthorization.setVersion(mnAuthorizationServiceVersion);
789
            sMNAuthorization.setAvailable(mnAuthorizationServiceAvailable);
790

    
791
            Service sMNStorage = new Service();
792
            sMNStorage.setName("MNStorage");
793
            sMNStorage.setVersion(mnStorageServiceVersion);
794
            sMNStorage.setAvailable(mnStorageServiceAvailable);
795

    
796
            Service sMNReplication = new Service();
797
            sMNReplication.setName("MNReplication");
798
            sMNReplication.setVersion(mnReplicationServiceVersion);
799
            sMNReplication.setAvailable(mnReplicationServiceAvailable);
800

    
801
            services.addService(sMNRead);
802
            services.addService(sMNCore);
803
            services.addService(sMNAuthorization);
804
            services.addService(sMNStorage);
805
            services.addService(sMNReplication);
806
            node.setServices(services);
807

    
808
            // Set the schedule for synchronization
809
            Synchronization synchronization = new Synchronization();
810
            Schedule schedule = new Schedule();
811
            Date now = new Date();
812
            schedule.setYear(PropertyService.getProperty("dataone.nodeSynchronization.schedule.year"));
813
            schedule.setMon(PropertyService.getProperty("dataone.nodeSynchronization.schedule.mon"));
814
            schedule.setMday(PropertyService.getProperty("dataone.nodeSynchronization.schedule.mday"));
815
            schedule.setWday(PropertyService.getProperty("dataone.nodeSynchronization.schedule.wday"));
816
            schedule.setHour(PropertyService.getProperty("dataone.nodeSynchronization.schedule.hour"));
817
            schedule.setMin(PropertyService.getProperty("dataone.nodeSynchronization.schedule.min"));
818
            schedule.setSec(PropertyService.getProperty("dataone.nodeSynchronization.schedule.sec"));
819
            synchronization.setSchedule(schedule);
820
            synchronization.setLastHarvested(now);
821
            synchronization.setLastCompleteHarvest(now);
822
            node.setSynchronization(synchronization);
823

    
824
            node.setType(nodeType);
825
            return node;
826

    
827
        } catch (PropertyNotFoundException pnfe) {
828
            String msg = "MNodeService.getCapabilities(): " + "property not found: " + pnfe.getMessage();
829
            logMetacat.error(msg);
830
            throw new ServiceFailure("2162", msg);
831
        }
832
    }
833

    
834
    /**
835
     * Returns the number of operations that have been serviced by the node 
836
     * over time periods of one and 24 hours.
837
     * 
838
     * @param session - the Session object containing the credentials for the Subject
839
     * @param period - An ISO8601 compatible DateTime range specifying the time 
840
     *                 range for which to return operation statistics.
841
     * @param requestor - Limit to operations performed by given requestor identity.
842
     * @param event -  Enumerated value indicating the type of event being examined
843
     * @param format - Limit to events involving objects of the specified format
844
     * 
845
     * @return the desired log records
846
     * 
847
     * @throws InvalidToken
848
     * @throws ServiceFailure
849
     * @throws NotAuthorized
850
     * @throws InvalidRequest
851
     * @throws NotImplemented
852
     */
853
    public MonitorList getOperationStatistics(Session session, Date startTime, 
854
        Date endTime, Subject requestor, Event event, ObjectFormatIdentifier formatId)
855
        throws NotImplemented, ServiceFailure, NotAuthorized, InsufficientResources, UnsupportedType {
856

    
857
        MonitorList monitorList = new MonitorList();
858

    
859
        try {
860

    
861
            // get log records first
862
            Log logs = getLogRecords(session, startTime, endTime, event, null, 0, null);
863

    
864
            // TODO: aggregate by day or hour -- needs clarification
865
            int count = 1;
866
            for (LogEntry logEntry : logs.getLogEntryList()) {
867
                Identifier pid = logEntry.getIdentifier();
868
                Date logDate = logEntry.getDateLogged();
869
                // if we are filtering by format
870
                if (formatId != null) {
871
                    SystemMetadata sysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
872
                    if (!sysmeta.getFormatId().getValue().equals(formatId.getValue())) {
873
                        // does not match
874
                        continue;
875
                    }
876
                }
877
                MonitorInfo item = new MonitorInfo();
878
                item.setCount(count);
879
                item.setDate(new java.sql.Date(logDate.getTime()));
880
                monitorList.addMonitorInfo(item);
881

    
882
            }
883
        } catch (Exception e) {
884
            e.printStackTrace();
885
            throw new ServiceFailure("2081", "Could not retrieve statistics: " + e.getMessage());
886
        }
887

    
888
        return monitorList;
889

    
890
    }
891

    
892
    /**
893
     * A callback method used by a CN to indicate to a MN that it cannot 
894
     * complete synchronization of the science metadata identified by pid.  Log
895
     * the event in the metacat event log.
896
     * 
897
     * @param session
898
     * @param syncFailed
899
     * 
900
     * @throws ServiceFailure
901
     * @throws NotAuthorized
902
     * @throws NotImplemented
903
     */
904
    @Override
905
    public boolean synchronizationFailed(Session session, SynchronizationFailed syncFailed) 
906
        throws NotImplemented, ServiceFailure, NotAuthorized {
907

    
908
        String localId;
909
        Identifier pid;
910
        if ( syncFailed.getPid() != null ) {
911
            pid = new Identifier();
912
            pid.setValue(syncFailed.getPid());
913
            boolean allowed;
914
            
915
            //are we allowed? only CNs
916
            try {
917
                allowed = isAdminAuthorized(session);
918
                if ( !allowed ){
919
                    throw new NotAuthorized("2162", 
920
                            "Not allowed to call synchronizationFailed() on this node.");
921
                }
922
            } catch (InvalidToken e) {
923
                throw new NotAuthorized("2162", 
924
                        "Not allowed to call synchronizationFailed() on this node.");
925

    
926
            }
927
            
928
        } else {
929
            throw new ServiceFailure("2161", "The identifier cannot be null.");
930

    
931
        }
932
        
933
        try {
934
            localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
935
        } catch (McdbDocNotFoundException e) {
936
            throw new ServiceFailure("2161", "The identifier specified by " + 
937
                    syncFailed.getPid() + " was not found on this node.");
938

    
939
        }
940
        // TODO: update the CN URL below when the CNRead.SynchronizationFailed
941
        // method is changed to include the URL as a parameter
942
        logMetacat.debug("Synchronization for the object identified by " + 
943
                pid.getValue() + " failed from " + syncFailed.getNodeId() + 
944
                " Logging the event to the Metacat EventLog as a 'syncFailed' event.");
945
        // TODO: use the event type enum when the SYNCHRONIZATION_FAILED event is added
946
        String principal = Constants.SUBJECT_PUBLIC;
947
        if (session != null && session.getSubject() != null) {
948
          principal = session.getSubject().getValue();
949
        }
950
        try {
951
          EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), principal, localId, "synchronization_failed");
952
        } catch (Exception e) {
953
            throw new ServiceFailure("2161", "Could not log the error for: " + pid.getValue());
954
        }
955
        //EventLog.getInstance().log("CN URL WILL GO HERE", 
956
        //  session.getSubject().getValue(), localId, Event.SYNCHRONIZATION_FAILED);
957
        return true;
958

    
959
    }
960

    
961
    /**
962
     * Essentially a get() but with different logging behavior
963
     */
964
    @Override
965
    public InputStream getReplica(Session session, Identifier pid) 
966
        throws NotAuthorized, NotImplemented, ServiceFailure, InvalidToken {
967

    
968
        logMetacat.info("MNodeService.getReplica() called.");
969

    
970
        // cannot be called by public
971
        if (session == null) {
972
        	throw new InvalidToken("2183", "No session was provided.");
973
        }
974
        
975
        logMetacat.info("MNodeService.getReplica() called with parameters: \n" +
976
             "\tSession.Subject      = " + session.getSubject().getValue() + "\n" +
977
             "\tIdentifier           = " + pid.getValue());
978

    
979
        InputStream inputStream = null; // bytes to be returned
980
        handler = new MetacatHandler(new Timer());
981
        boolean allowed = false;
982
        String localId; // the metacat docid for the pid
983

    
984
        // get the local docid from Metacat
985
        try {
986
            localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
987
        } catch (McdbDocNotFoundException e) {
988
            throw new ServiceFailure("2181", "The object specified by " + 
989
                    pid.getValue() + " does not exist at this node.");
990
            
991
        }
992

    
993
        Subject targetNodeSubject = session.getSubject();
994

    
995
        // check for authorization to replicate, null session to act as this source MN
996
        try {
997
            allowed = D1Client.getCN().isNodeAuthorized(null, targetNodeSubject, pid);
998
        } catch (InvalidToken e1) {
999
            throw new ServiceFailure("2181", "Could not determine if node is authorized: " 
1000
                + e1.getMessage());
1001
            
1002
        } catch (NotFound e1) {
1003
            throw new ServiceFailure("2181", "Could not determine if node is authorized: " 
1004
                    + e1.getMessage());
1005

    
1006
        } catch (InvalidRequest e1) {
1007
            throw new ServiceFailure("2181", "Could not determine if node is authorized: " 
1008
                    + e1.getMessage());
1009

    
1010
        }
1011

    
1012
        logMetacat.info("Called D1Client.isNodeAuthorized(). Allowed = " + allowed +
1013
            " for identifier " + pid.getValue());
1014

    
1015
        // if the person is authorized, perform the read
1016
        if (allowed) {
1017
            try {
1018
                inputStream = MetacatHandler.read(localId);
1019
            } catch (Exception e) {
1020
                throw new ServiceFailure("1020", "The object specified by " + 
1021
                    pid.getValue() + "could not be returned due to error: " + e.getMessage());
1022
            }
1023
        }
1024

    
1025
        // if we fail to set the input stream
1026
        if (inputStream == null) {
1027
            throw new ServiceFailure("2181", "The object specified by " + 
1028
                pid.getValue() + "does not exist at this node.");
1029
        }
1030

    
1031
        // log the replica event
1032
        String principal = null;
1033
        if (session.getSubject() != null) {
1034
            principal = session.getSubject().getValue();
1035
        }
1036
        EventLog.getInstance().log(request.getRemoteAddr(), 
1037
            request.getHeader("User-Agent"), principal, localId, "replicate");
1038

    
1039
        return inputStream;
1040
    }
1041

    
1042
    /**
1043
     * A method to notify the Member Node that the authoritative copy of 
1044
     * system metadata on the Coordinating Nodes has changed.
1045
     * 
1046
     * @param session   Session information that contains the identity of the 
1047
     *                  calling user as retrieved from the X.509 certificate 
1048
     *                  which must be traceable to the CILogon service.
1049
     * @param serialVersion   The serialVersion of the system metadata
1050
     * @param dateSysMetaLastModified  The time stamp for when the system metadata was changed
1051
     * @throws NotImplemented
1052
     * @throws ServiceFailure
1053
     * @throws NotAuthorized
1054
     * @throws InvalidRequest
1055
     * @throws InvalidToken
1056
     */
1057
    public boolean systemMetadataChanged(Session session, Identifier pid,
1058
        long serialVersion, Date dateSysMetaLastModified) 
1059
        throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest,
1060
        InvalidToken {
1061
        
1062
        SystemMetadata currentLocalSysMeta = null;
1063
        SystemMetadata newSysMeta = null;
1064
        CNode cn = D1Client.getCN();
1065
        NodeList nodeList = null;
1066
        Subject callingSubject = null;
1067
        boolean allowed = false;
1068
        
1069
        // are we allowed to call this?
1070
        callingSubject = session.getSubject();
1071
        nodeList = cn.listNodes();
1072
        
1073
        for(Node node : nodeList.getNodeList()) {
1074
            // must be a CN
1075
            if ( node.getType().equals(NodeType.CN)) {
1076
               List<Subject> subjectList = node.getSubjectList();
1077
               // the calling subject must be in the subject list
1078
               if ( subjectList.contains(callingSubject)) {
1079
                   allowed = true;
1080
                   
1081
               }
1082
               
1083
            }
1084
        }
1085
        
1086
        if (!allowed ) {
1087
            String msg = "The subject identified by " + callingSubject.getValue() +
1088
              " is not authorized to call this service.";
1089
            throw new NotAuthorized("1331", msg);
1090
            
1091
        }
1092
        
1093
        // compare what we have locally to what is sent in the change notification
1094
        try {
1095
            currentLocalSysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
1096
             
1097
        } catch (RuntimeException e) {
1098
            String msg = "SystemMetadata for pid " + pid.getValue() +
1099
              " couldn't be updated because it couldn't be found locally: " +
1100
              e.getMessage();
1101
            logMetacat.error(msg);
1102
            ServiceFailure sf = new ServiceFailure("1333", msg);
1103
            sf.initCause(e);
1104
            throw sf; 
1105
        }
1106
        
1107
        if (currentLocalSysMeta.getSerialVersion().longValue() < serialVersion ) {
1108
            try {
1109
                newSysMeta = cn.getSystemMetadata(null, pid);
1110
            } catch (NotFound e) {
1111
                // huh? you just said you had it
1112
            	String msg = "On updating the local copy of system metadata " + 
1113
                "for pid " + pid.getValue() +", the CN reports it is not found." +
1114
                " The error message was: " + e.getMessage();
1115
                logMetacat.error(msg);
1116
                ServiceFailure sf = new ServiceFailure("1333", msg);
1117
                sf.initCause(e);
1118
                throw sf;
1119
            }
1120
            
1121
            // update the local copy of system metadata for the pid
1122
            try {
1123
                HazelcastService.getInstance().getSystemMetadataMap().put(newSysMeta.getIdentifier(), newSysMeta);
1124
                logMetacat.info("Updated local copy of system metadata for pid " +
1125
                    pid.getValue() + " after change notification from the CN.");
1126
                
1127
            } catch (RuntimeException e) {
1128
                String msg = "SystemMetadata for pid " + pid.getValue() +
1129
                  " couldn't be updated: " +
1130
                  e.getMessage();
1131
                logMetacat.error(msg);
1132
                ServiceFailure sf = new ServiceFailure("1333", msg);
1133
                sf.initCause(e);
1134
                throw sf;
1135
            }
1136
        }
1137
        
1138
        return true;
1139
        
1140
    }
1141
    
1142
    /*
1143
     * Set the replication status for the object on the Coordinating Node
1144
     * 
1145
     * @param session - the session for the this target node
1146
     * @param pid - the identifier of the object being updated
1147
     * @param nodeId - the identifier of this target node
1148
     * @param status - the replication status to set
1149
     * @param failure - the exception to include, if any
1150
     */
1151
    private void setReplicationStatus(Session session, Identifier pid, 
1152
        NodeReference nodeId, ReplicationStatus status, BaseException failure) 
1153
        throws ServiceFailure, NotImplemented, NotAuthorized, 
1154
        InvalidRequest {
1155
        
1156
        // call the CN as the MN to set the replication status
1157
        try {
1158
            this.cn = D1Client.getCN();
1159
            this.cn.setReplicationStatus(session, pid, nodeId,
1160
                    status, failure);
1161
            
1162
        } catch (InvalidToken e) {
1163
        	String msg = "Could not set the replication status for " + pid.getValue() + " on the CN (InvalidToken): " + e.getMessage();
1164
            logMetacat.error(msg);
1165
        	throw new ServiceFailure("2151",
1166
                    msg);
1167
            
1168
        } catch (NotFound e) {
1169
        	String msg = "Could not set the replication status for " + pid.getValue() + " on the CN (NotFound): " + e.getMessage();
1170
            logMetacat.error(msg);
1171
        	throw new ServiceFailure("2151",
1172
                    msg);
1173
            
1174
        }
1175

    
1176

    
1177
    }
1178

    
1179
	@Override
1180
	public Identifier generateIdentifier(Session arg0, String arg1, String arg2)
1181
			throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
1182
			InvalidRequest {
1183
		throw new NotImplemented("2194", "Member Node does not implement generateIdentifier method");
1184
	}
1185

    
1186
	@Override
1187
	public boolean isAuthorized(Identifier pid, Permission permission)
1188
			throws ServiceFailure, InvalidRequest, InvalidToken, NotFound,
1189
			NotAuthorized, NotImplemented {
1190

    
1191
		return isAuthorized(null, pid, permission);
1192
	}
1193

    
1194
	@Override
1195
	public boolean systemMetadataChanged(Identifier pid, long serialVersion, Date dateSysMetaLastModified)
1196
			throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
1197
			InvalidRequest {
1198

    
1199
		return systemMetadataChanged(null, pid, serialVersion, dateSysMetaLastModified);
1200
	}
1201

    
1202
	@Override
1203
	public Log getLogRecords(Date fromDate, Date toDate, Event event, String pidFilter,
1204
			Integer start, Integer count) throws InvalidRequest, InvalidToken,
1205
			NotAuthorized, NotImplemented, ServiceFailure {
1206

    
1207
		return getLogRecords(null, fromDate, toDate, event, pidFilter, start, count);
1208
	}
1209

    
1210
	@Override
1211
	public DescribeResponse describe(Identifier pid) throws InvalidToken,
1212
			NotAuthorized, NotImplemented, ServiceFailure, NotFound {
1213

    
1214
		return describe(null, pid);
1215
	}
1216

    
1217
	@Override
1218
	public InputStream get(Identifier pid) throws InvalidToken, NotAuthorized,
1219
			NotImplemented, ServiceFailure, NotFound, InsufficientResources {
1220

    
1221
		return get(null, pid);
1222
	}
1223

    
1224
	@Override
1225
	public Checksum getChecksum(Identifier pid, String algorithm)
1226
			throws InvalidRequest, InvalidToken, NotAuthorized, NotImplemented,
1227
			ServiceFailure, NotFound {
1228

    
1229
		return getChecksum(null, pid, algorithm);
1230
	}
1231

    
1232
	@Override
1233
	public SystemMetadata getSystemMetadata(Identifier pid)
1234
			throws InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
1235
			NotFound {
1236

    
1237
		return getSystemMetadata(null, pid);
1238
	}
1239

    
1240
	@Override
1241
	public ObjectList listObjects(Date startTime, Date endTime,
1242
			ObjectFormatIdentifier objectFormatId, Boolean replicaStatus, Integer start,
1243
			Integer count) throws InvalidRequest, InvalidToken, NotAuthorized,
1244
			NotImplemented, ServiceFailure {
1245

    
1246
		return listObjects(null, startTime, endTime, objectFormatId, replicaStatus, start, count);
1247
	}
1248

    
1249
	@Override
1250
	public boolean synchronizationFailed(SynchronizationFailed syncFailed)
1251
			throws InvalidToken, NotAuthorized, NotImplemented, ServiceFailure {
1252

    
1253
		return synchronizationFailed(null, syncFailed);
1254
	}
1255

    
1256
	@Override
1257
	public InputStream getReplica(Identifier pid) throws InvalidToken,
1258
			NotAuthorized, NotImplemented, ServiceFailure, NotFound,
1259
			InsufficientResources {
1260

    
1261
		return getReplica(null, pid);
1262
	}
1263

    
1264
	@Override
1265
	public boolean replicate(SystemMetadata sysmeta, NodeReference sourceNode)
1266
			throws NotImplemented, ServiceFailure, NotAuthorized,
1267
			InvalidRequest, InvalidToken, InsufficientResources,
1268
			UnsupportedType {
1269

    
1270
		return replicate(null, sysmeta, sourceNode);
1271
	}
1272

    
1273
	@Override
1274
	public Identifier create(Identifier pid, InputStream object,
1275
			SystemMetadata sysmeta) throws IdentifierNotUnique,
1276
			InsufficientResources, InvalidRequest, InvalidSystemMetadata,
1277
			InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
1278
			UnsupportedType {
1279

    
1280
		return create(null, pid, object, sysmeta);
1281
	}
1282

    
1283
	@Override
1284
	public Identifier delete(Identifier pid) throws InvalidToken,
1285
			ServiceFailure, NotAuthorized, NotFound, NotImplemented {
1286

    
1287
		return delete(null, pid);
1288
	}
1289

    
1290
	@Override
1291
	public Identifier generateIdentifier(String arg0, String arg1)
1292
			throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
1293
			InvalidRequest {
1294

    
1295
		return generateIdentifier(null, arg0, arg1);
1296
	}
1297

    
1298
	@Override
1299
	public Identifier update(Identifier pid, InputStream object,
1300
			Identifier newPid, SystemMetadata sysmeta) throws IdentifierNotUnique,
1301
			InsufficientResources, InvalidRequest, InvalidSystemMetadata,
1302
			InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
1303
			UnsupportedType, NotFound {
1304

    
1305
		return update(null, pid, object, newPid, sysmeta);
1306
	}
1307
    
1308
}
(3-3/5)