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
    	// only admin of  the MN or the CN is allowed a full delete
183
        boolean allowed = false;
184
        allowed = isNodeAdmin(session);
185
        allowed = allowed || isAdminAuthorized(session);
186
        if (!allowed) { 
187
            throw new NotAuthorized("1320", "The provided identity does not have " + "permission to delete objects on the Node.");
188
        }
189
    	
190
    	// defer to superclass implementation
191
        return super.delete(session, pid);
192
    }
193

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

    
225
        String localId = null;
226
        boolean allowed = false;
227
        boolean isScienceMetadata = false;
228
        
229
        if (session == null) {
230
        	throw new InvalidToken("1210", "No session has been provided");
231
        }
232
        Subject subject = session.getSubject();
233

    
234
        // verify the pid is valid format
235
        if (isValidIdentifier(pid)) {
236
        	throw new InvalidRequest("1202", "The provided identifier is invalid.");
237
        }
238

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

    
260
        // does the subject have WRITE ( == update) priveleges on the pid?
261
        allowed = isAuthorized(session, pid, Permission.WRITE);
262

    
263
        if (allowed) {
264
        	
265
        	// check quality of SM
266
        	if (sysmeta.getObsoletedBy() != null) {
267
        		throw new InvalidSystemMetadata("1300", "Cannot include obsoletedBy when updating object");
268
        	}
269
        	if (sysmeta.getObsoletes() != null && !sysmeta.getObsoletes().getValue().equals(pid.getValue())) {
270
        		throw new InvalidSystemMetadata("1300", "The identifier provided in obsoletes does not match old Identifier");
271
        	}
272

    
273
            // get the existing system metadata for the object
274
            SystemMetadata existingSysMeta = getSystemMetadata(session, pid);
275

    
276
            // add the newPid to the obsoletedBy list for the existing sysmeta
277
            existingSysMeta.setObsoletedBy(newPid);
278

    
279
            // then update the existing system metadata
280
            updateSystemMetadata(existingSysMeta);
281

    
282
            // prep the new system metadata, add pid to the affected lists
283
            sysmeta.setObsoletes(pid);
284
            //sysmeta.addDerivedFrom(pid);
285

    
286
            isScienceMetadata = isScienceMetadata(sysmeta);
287

    
288
            // do we have XML metadata or a data object?
289
            if (isScienceMetadata) {
290

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

    
302
                    }
303

    
304
                } catch (IOException e) {
305
                    String msg = "The Node is unable to create the object. " + "There was a problem converting the object to XML";
306
                    logMetacat.info(msg);
307
                    throw new ServiceFailure("1310", msg + ": " + e.getMessage());
308

    
309
                }
310

    
311
            } else {
312

    
313
                // update the data object
314
                localId = insertDataObject(object, newPid, session);
315

    
316
            }
317

    
318
            // and insert the new system metadata
319
            insertSystemMetadata(sysmeta);
320

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

    
324
        } else {
325
            throw new NotAuthorized("1200", "The provided identity does not have " + "permission to UPDATE the object identified by " + pid.getValue()
326
                    + " on the Member Node.");
327
        }
328

    
329
        return newPid;
330
    }
331

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

    
335
        // check for null session
336
        if (session == null) {
337
          throw new InvalidToken("1110", "Session is required to WRITE to the Node.");
338
        }
339
        // set the submitter to match the certificate
340
        sysmeta.setSubmitter(session.getSubject());
341
        // set the originating node
342
        NodeReference originMemberNode = this.getCapabilities().getIdentifier();
343
        sysmeta.setOriginMemberNode(originMemberNode);
344
        sysmeta.setArchived(false);
345

    
346
        // set the dates
347
        Date now = Calendar.getInstance().getTime();
348
        sysmeta.setDateSysMetadataModified(now);
349
        sysmeta.setDateUploaded(now);
350
        
351
        // set the serial version
352
        sysmeta.setSerialVersion(BigInteger.ZERO);
353

    
354
        // check that we are not attempting to subvert versioning
355
        if (sysmeta.getObsoletes() != null && sysmeta.getObsoletes().getValue() != null) {
356
            throw new InvalidSystemMetadata("1180", 
357
              "The supplied system metadata is invalid. " +
358
              "The obsoletes field cannot have a value when creating entries.");
359
        }
360
        
361
        if (sysmeta.getObsoletedBy() != null && sysmeta.getObsoletedBy().getValue() != null) {
362
            throw new InvalidSystemMetadata("1180", 
363
              "The supplied system metadata is invalid. " +
364
              "The obsoletedBy field cannot have a value when creating entries.");
365
        }
366
        
367

    
368
        // call the shared impl
369
        return super.create(session, pid, object, sysmeta);
370
    }
371

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

    
399
        if (session != null && sysmeta != null && sourceNode != null) {
400
            logMetacat.info("MNodeService.replicate() called with parameters: \n" +
401
                            "\tSession.Subject      = "                           +
402
                            session.getSubject().getValue() + "\n"                +
403
                            "\tidentifier           = "                           + 
404
                            sysmeta.getIdentifier().getValue()                    +
405
                            "\n" + "\tSource NodeReference ="                     +
406
                            sourceNode.getValue());
407
        }
408
        boolean result = false;
409
        String nodeIdStr = null;
410
        NodeReference nodeId = null;
411

    
412
        // get the referenced object
413
        Identifier pid = sysmeta.getIdentifier();
414

    
415
        // get from the membernode
416
        // TODO: switch credentials for the server retrieval?
417
        this.mn = D1Client.getMN(sourceNode);
418
        this.cn = D1Client.getCN();
419
        InputStream object = null;
420
        Session thisNodeSession = null;
421
        SystemMetadata localSystemMetadata = null;
422
        BaseException failure = null;
423
        String localId = null;
424
        
425
        // TODO: check credentials
426
        // cannot be called by public
427
        if (session == null || session.getSubject() == null) {
428
            String msg = "No session was provided to replicate identifier " +
429
            sysmeta.getIdentifier().getValue();
430
            logMetacat.info(msg);
431
            throw new NotAuthorized("2152", msg);
432
            
433
        }
434

    
435

    
436
        // get the local node id
437
        try {
438
            nodeIdStr = PropertyService.getProperty("dataone.nodeId");
439
            nodeId = new NodeReference();
440
            nodeId.setValue(nodeIdStr);
441

    
442
        } catch (PropertyNotFoundException e1) {
443
            String msg = "Couldn't get dataone.nodeId property: " + e1.getMessage();
444
            failure = new ServiceFailure("2151", msg);
445
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
446
            logMetacat.error(msg);
447
            return true;
448

    
449
        }
450
        
451

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

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

    
487
            }
488

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

    
496
        } catch (NotFound e) {
497
            String msg = "Could not retrieve object to replicate (NotFound): "+ e.getMessage();
498
            failure = new ServiceFailure("2151", msg);
499
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
500
            logMetacat.error(msg);
501
            throw new ServiceFailure("2151", msg);
502

    
503
        }
504

    
505
        // verify checksum on the object, if supported
506
        if (object.markSupported()) {
507
            Checksum givenChecksum = sysmeta.getChecksum();
508
            Checksum computedChecksum = null;
509
            try {
510
                computedChecksum = ChecksumUtil.checksum(object, givenChecksum.getAlgorithm());
511
                object.reset();
512

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

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

    
550
        // finish by setting the replication status
551
        setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.COMPLETED, null);
552
        return result;
553

    
554
    }
555

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

    
574
        return super.get(session, pid);
575

    
576
    }
577

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

    
600
        Checksum checksum = null;
601

    
602
        InputStream inputStream = get(session, pid);
603

    
604
        try {
605
            checksum = ChecksumUtil.checksum(inputStream, algorithm);
606

    
607
        } catch (NoSuchAlgorithmException e) {
608
            throw new ServiceFailure("1410", "The checksum for the object specified by " + pid.getValue() + "could not be returned due to an internal error: "
609
                    + e.getMessage());
610
        } catch (IOException e) {
611
            throw new ServiceFailure("1410", "The checksum for the object specified by " + pid.getValue() + "could not be returned due to an internal error: "
612
                    + e.getMessage());
613
        }
614

    
615
        if (checksum == null) {
616
            throw new ServiceFailure("1410", "The checksum for the object specified by " + pid.getValue() + "could not be returned.");
617
        }
618

    
619
        return checksum;
620
    }
621

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

    
642
        return super.getSystemMetadata(session, pid);
643
    }
644

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

    
673
        ObjectList objectList = null;
674

    
675
        try {
676
            objectList = IdentifierManager.getInstance().querySystemMetadata(startTime, endTime, objectFormatId, replicaStatus, start, count);
677
        } catch (Exception e) {
678
            throw new ServiceFailure("1580", "Error querying system metadata: " + e.getMessage());
679
        }
680

    
681
        return objectList;
682
    }
683

    
684
    /**
685
     * Return a description of the node's capabilities and services.
686
     * 
687
     * @return node - the technical capabilities of the Member Node
688
     * 
689
     * @throws ServiceFailure
690
     * @throws NotAuthorized
691
     * @throws InvalidRequest
692
     * @throws NotImplemented
693
     */
694
    @Override
695
    public Node getCapabilities() 
696
        throws NotImplemented, ServiceFailure {
697

    
698
        String nodeName = null;
699
        String nodeId = null;
700
        String subject = null;
701
        String contactSubject = null;
702
        String nodeDesc = null;
703
        String nodeTypeString = null;
704
        NodeType nodeType = null;
705
        String mnCoreServiceVersion = null;
706
        String mnReadServiceVersion = null;
707
        String mnAuthorizationServiceVersion = null;
708
        String mnStorageServiceVersion = null;
709
        String mnReplicationServiceVersion = null;
710

    
711
        boolean nodeSynchronize = false;
712
        boolean nodeReplicate = false;
713
        boolean mnCoreServiceAvailable = false;
714
        boolean mnReadServiceAvailable = false;
715
        boolean mnAuthorizationServiceAvailable = false;
716
        boolean mnStorageServiceAvailable = false;
717
        boolean mnReplicationServiceAvailable = false;
718

    
719
        try {
720
            // get the properties of the node based on configuration information
721
            nodeName = PropertyService.getProperty("dataone.nodeName");
722
            nodeId = PropertyService.getProperty("dataone.nodeId");
723
            subject = PropertyService.getProperty("dataone.subject");
724
            contactSubject = PropertyService.getProperty("dataone.contactSubject");
725
            nodeDesc = PropertyService.getProperty("dataone.nodeDescription");
726
            nodeTypeString = PropertyService.getProperty("dataone.nodeType");
727
            nodeType = NodeType.convert(nodeTypeString);
728
            nodeSynchronize = new Boolean(PropertyService.getProperty("dataone.nodeSynchronize")).booleanValue();
729
            nodeReplicate = new Boolean(PropertyService.getProperty("dataone.nodeReplicate")).booleanValue();
730

    
731
            mnCoreServiceVersion = PropertyService.getProperty("dataone.mnCore.serviceVersion");
732
            mnReadServiceVersion = PropertyService.getProperty("dataone.mnRead.serviceVersion");
733
            mnAuthorizationServiceVersion = PropertyService.getProperty("dataone.mnAuthorization.serviceVersion");
734
            mnStorageServiceVersion = PropertyService.getProperty("dataone.mnStorage.serviceVersion");
735
            mnReplicationServiceVersion = PropertyService.getProperty("dataone.mnReplication.serviceVersion");
736

    
737
            mnCoreServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnCore.serviceAvailable")).booleanValue();
738
            mnReadServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnRead.serviceAvailable")).booleanValue();
739
            mnAuthorizationServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnAuthorization.serviceAvailable")).booleanValue();
740
            mnStorageServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnStorage.serviceAvailable")).booleanValue();
741
            mnReplicationServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnReplication.serviceAvailable")).booleanValue();
742

    
743
            // Set the properties of the node based on configuration information and
744
            // calls to current status methods
745
            String serviceName = SystemUtil.getSecureContextURL() + "/" + PropertyService.getProperty("dataone.serviceName");
746
            Node node = new Node();
747
            node.setBaseURL(serviceName + "/" + nodeTypeString);
748
            node.setDescription(nodeDesc);
749

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

    
766
            NodeReference identifier = new NodeReference();
767
            identifier.setValue(nodeId);
768
            node.setIdentifier(identifier);
769
            Subject s = new Subject();
770
            s.setValue(subject);
771
            node.addSubject(s);
772
            Subject contact = new Subject();
773
            contact.setValue(contactSubject);
774
            node.addContactSubject(contact);
775
            node.setName(nodeName);
776
            node.setReplicate(nodeReplicate);
777
            node.setSynchronize(nodeSynchronize);
778

    
779
            // services: MNAuthorization, MNCore, MNRead, MNReplication, MNStorage
780
            Services services = new Services();
781

    
782
            Service sMNCore = new Service();
783
            sMNCore.setName("MNCore");
784
            sMNCore.setVersion(mnCoreServiceVersion);
785
            sMNCore.setAvailable(mnCoreServiceAvailable);
786

    
787
            Service sMNRead = new Service();
788
            sMNRead.setName("MNRead");
789
            sMNRead.setVersion(mnReadServiceVersion);
790
            sMNRead.setAvailable(mnReadServiceAvailable);
791

    
792
            Service sMNAuthorization = new Service();
793
            sMNAuthorization.setName("MNAuthorization");
794
            sMNAuthorization.setVersion(mnAuthorizationServiceVersion);
795
            sMNAuthorization.setAvailable(mnAuthorizationServiceAvailable);
796

    
797
            Service sMNStorage = new Service();
798
            sMNStorage.setName("MNStorage");
799
            sMNStorage.setVersion(mnStorageServiceVersion);
800
            sMNStorage.setAvailable(mnStorageServiceAvailable);
801

    
802
            Service sMNReplication = new Service();
803
            sMNReplication.setName("MNReplication");
804
            sMNReplication.setVersion(mnReplicationServiceVersion);
805
            sMNReplication.setAvailable(mnReplicationServiceAvailable);
806

    
807
            services.addService(sMNRead);
808
            services.addService(sMNCore);
809
            services.addService(sMNAuthorization);
810
            services.addService(sMNStorage);
811
            services.addService(sMNReplication);
812
            node.setServices(services);
813

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

    
830
            node.setType(nodeType);
831
            return node;
832

    
833
        } catch (PropertyNotFoundException pnfe) {
834
            String msg = "MNodeService.getCapabilities(): " + "property not found: " + pnfe.getMessage();
835
            logMetacat.error(msg);
836
            throw new ServiceFailure("2162", msg);
837
        }
838
    }
839

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

    
863
        MonitorList monitorList = new MonitorList();
864

    
865
        try {
866

    
867
            // get log records first
868
            Log logs = getLogRecords(session, startTime, endTime, event, null, 0, null);
869

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

    
888
            }
889
        } catch (Exception e) {
890
            e.printStackTrace();
891
            throw new ServiceFailure("2081", "Could not retrieve statistics: " + e.getMessage());
892
        }
893

    
894
        return monitorList;
895

    
896
    }
897

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

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

    
932
            }
933
            
934
        } else {
935
            throw new ServiceFailure("2161", "The identifier cannot be null.");
936

    
937
        }
938
        
939
        try {
940
            localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
941
        } catch (McdbDocNotFoundException e) {
942
            throw new ServiceFailure("2161", "The identifier specified by " + 
943
                    syncFailed.getPid() + " was not found on this node.");
944

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

    
965
    }
966

    
967
    /**
968
     * Essentially a get() but with different logging behavior
969
     */
970
    @Override
971
    public InputStream getReplica(Session session, Identifier pid) 
972
        throws NotAuthorized, NotImplemented, ServiceFailure, InvalidToken {
973

    
974
        logMetacat.info("MNodeService.getReplica() called.");
975

    
976
        // cannot be called by public
977
        if (session == null) {
978
        	throw new InvalidToken("2183", "No session was provided.");
979
        }
980
        
981
        logMetacat.info("MNodeService.getReplica() called with parameters: \n" +
982
             "\tSession.Subject      = " + session.getSubject().getValue() + "\n" +
983
             "\tIdentifier           = " + pid.getValue());
984

    
985
        InputStream inputStream = null; // bytes to be returned
986
        handler = new MetacatHandler(new Timer());
987
        boolean allowed = false;
988
        String localId; // the metacat docid for the pid
989

    
990
        // get the local docid from Metacat
991
        try {
992
            localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
993
        } catch (McdbDocNotFoundException e) {
994
            throw new ServiceFailure("2181", "The object specified by " + 
995
                    pid.getValue() + " does not exist at this node.");
996
            
997
        }
998

    
999
        Subject targetNodeSubject = session.getSubject();
1000

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

    
1012
        } catch (InvalidRequest e1) {
1013
            throw new ServiceFailure("2181", "Could not determine if node is authorized: " 
1014
                    + e1.getMessage());
1015

    
1016
        }
1017

    
1018
        logMetacat.info("Called D1Client.isNodeAuthorized(). Allowed = " + allowed +
1019
            " for identifier " + pid.getValue());
1020

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

    
1031
        // if we fail to set the input stream
1032
        if (inputStream == null) {
1033
            throw new ServiceFailure("2181", "The object specified by " + 
1034
                pid.getValue() + "does not exist at this node.");
1035
        }
1036

    
1037
        // log the replica event
1038
        String principal = null;
1039
        if (session.getSubject() != null) {
1040
            principal = session.getSubject().getValue();
1041
        }
1042
        EventLog.getInstance().log(request.getRemoteAddr(), 
1043
            request.getHeader("User-Agent"), principal, localId, "replicate");
1044

    
1045
        return inputStream;
1046
    }
1047

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

    
1182

    
1183
    }
1184

    
1185
	@Override
1186
	public Identifier generateIdentifier(Session arg0, String arg1, String arg2)
1187
			throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
1188
			InvalidRequest {
1189
		throw new NotImplemented("2194", "Member Node does not implement generateIdentifier method");
1190
	}
1191

    
1192
	@Override
1193
	public boolean isAuthorized(Identifier pid, Permission permission)
1194
			throws ServiceFailure, InvalidRequest, InvalidToken, NotFound,
1195
			NotAuthorized, NotImplemented {
1196

    
1197
		return isAuthorized(null, pid, permission);
1198
	}
1199

    
1200
	@Override
1201
	public boolean systemMetadataChanged(Identifier pid, long serialVersion, Date dateSysMetaLastModified)
1202
			throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
1203
			InvalidRequest {
1204

    
1205
		return systemMetadataChanged(null, pid, serialVersion, dateSysMetaLastModified);
1206
	}
1207

    
1208
	@Override
1209
	public Log getLogRecords(Date fromDate, Date toDate, Event event, String pidFilter,
1210
			Integer start, Integer count) throws InvalidRequest, InvalidToken,
1211
			NotAuthorized, NotImplemented, ServiceFailure {
1212

    
1213
		return getLogRecords(null, fromDate, toDate, event, pidFilter, start, count);
1214
	}
1215

    
1216
	@Override
1217
	public DescribeResponse describe(Identifier pid) throws InvalidToken,
1218
			NotAuthorized, NotImplemented, ServiceFailure, NotFound {
1219

    
1220
		return describe(null, pid);
1221
	}
1222

    
1223
	@Override
1224
	public InputStream get(Identifier pid) throws InvalidToken, NotAuthorized,
1225
			NotImplemented, ServiceFailure, NotFound, InsufficientResources {
1226

    
1227
		return get(null, pid);
1228
	}
1229

    
1230
	@Override
1231
	public Checksum getChecksum(Identifier pid, String algorithm)
1232
			throws InvalidRequest, InvalidToken, NotAuthorized, NotImplemented,
1233
			ServiceFailure, NotFound {
1234

    
1235
		return getChecksum(null, pid, algorithm);
1236
	}
1237

    
1238
	@Override
1239
	public SystemMetadata getSystemMetadata(Identifier pid)
1240
			throws InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
1241
			NotFound {
1242

    
1243
		return getSystemMetadata(null, pid);
1244
	}
1245

    
1246
	@Override
1247
	public ObjectList listObjects(Date startTime, Date endTime,
1248
			ObjectFormatIdentifier objectFormatId, Boolean replicaStatus, Integer start,
1249
			Integer count) throws InvalidRequest, InvalidToken, NotAuthorized,
1250
			NotImplemented, ServiceFailure {
1251

    
1252
		return listObjects(null, startTime, endTime, objectFormatId, replicaStatus, start, count);
1253
	}
1254

    
1255
	@Override
1256
	public boolean synchronizationFailed(SynchronizationFailed syncFailed)
1257
			throws InvalidToken, NotAuthorized, NotImplemented, ServiceFailure {
1258

    
1259
		return synchronizationFailed(null, syncFailed);
1260
	}
1261

    
1262
	@Override
1263
	public InputStream getReplica(Identifier pid) throws InvalidToken,
1264
			NotAuthorized, NotImplemented, ServiceFailure, NotFound,
1265
			InsufficientResources {
1266

    
1267
		return getReplica(null, pid);
1268
	}
1269

    
1270
	@Override
1271
	public boolean replicate(SystemMetadata sysmeta, NodeReference sourceNode)
1272
			throws NotImplemented, ServiceFailure, NotAuthorized,
1273
			InvalidRequest, InvalidToken, InsufficientResources,
1274
			UnsupportedType {
1275

    
1276
		return replicate(null, sysmeta, sourceNode);
1277
	}
1278

    
1279
	@Override
1280
	public Identifier create(Identifier pid, InputStream object,
1281
			SystemMetadata sysmeta) throws IdentifierNotUnique,
1282
			InsufficientResources, InvalidRequest, InvalidSystemMetadata,
1283
			InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
1284
			UnsupportedType {
1285

    
1286
		return create(null, pid, object, sysmeta);
1287
	}
1288

    
1289
	@Override
1290
	public Identifier delete(Identifier pid) throws InvalidToken,
1291
			ServiceFailure, NotAuthorized, NotFound, NotImplemented {
1292

    
1293
		return delete(null, pid);
1294
	}
1295

    
1296
	@Override
1297
	public Identifier generateIdentifier(String arg0, String arg1)
1298
			throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
1299
			InvalidRequest {
1300

    
1301
		return generateIdentifier(null, arg0, arg1);
1302
	}
1303

    
1304
	@Override
1305
	public Identifier update(Identifier pid, InputStream object,
1306
			Identifier newPid, SystemMetadata sysmeta) throws IdentifierNotUnique,
1307
			InsufficientResources, InvalidRequest, InvalidSystemMetadata,
1308
			InvalidToken, NotAuthorized, NotImplemented, ServiceFailure,
1309
			UnsupportedType, NotFound {
1310

    
1311
		return update(null, pid, object, newPid, sysmeta);
1312
	}
1313
    
1314
}
(3-3/5)