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.Event;
64
import org.dataone.service.types.v1.Group;
65
import org.dataone.service.types.v1.Identifier;
66
import org.dataone.service.types.v1.Log;
67
import org.dataone.service.types.v1.LogEntry;
68
import org.dataone.service.types.v1.MonitorInfo;
69
import org.dataone.service.types.v1.MonitorList;
70
import org.dataone.service.types.v1.Node;
71
import org.dataone.service.types.v1.NodeList;
72
import org.dataone.service.types.v1.NodeReference;
73
import org.dataone.service.types.v1.NodeState;
74
import org.dataone.service.types.v1.NodeType;
75
import org.dataone.service.types.v1.ObjectFormatIdentifier;
76
import org.dataone.service.types.v1.ObjectList;
77
import org.dataone.service.types.v1.Permission;
78
import org.dataone.service.types.v1.Ping;
79
import org.dataone.service.types.v1.ReplicationStatus;
80
import org.dataone.service.types.v1.Schedule;
81
import org.dataone.service.types.v1.Service;
82
import org.dataone.service.types.v1.Services;
83
import org.dataone.service.types.v1.Session;
84
import org.dataone.service.types.v1.Subject;
85
import org.dataone.service.types.v1.Synchronization;
86
import org.dataone.service.types.v1.SystemMetadata;
87
import org.dataone.service.types.v1.util.ChecksumUtil;
88
import org.dataone.service.util.Constants;
89

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

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

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

    
140

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
278
            isScienceMetadata = isScienceMetadata(sysmeta);
279

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

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

    
294
                    }
295

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

    
301
                }
302

    
303
            } else {
304

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

    
308
            }
309

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

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

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

    
321
        return newPid;
322
    }
323

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

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

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

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

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

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

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

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

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

    
428

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

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

    
442
        }
443
        
444

    
445
        try {
446
            // do we already have a replica?
447
            try {
448
                localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
449

    
450
                String msg = "Can't read the object bytes properly, replica is invalid.";
451
                ServiceFailure serviceFailure = new ServiceFailure("2151", msg);
452
                
453
                // if we have a local id, get the local object
454
                try {
455
                    object = MetacatHandler.read(localId);
456
                    
457
                } catch (Exception e) {
458
                    // let the CN know that the replication failed
459
                    setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, serviceFailure);  
460
                    throw serviceFailure;
461
                    
462
                }
463

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

    
477
            }
478

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

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

    
493
        }
494

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

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

    
521
        // add it to local store
522
        Identifier retPid;
523
        try {
524
            // skip the MN.create -- this mutates the system metadata and we
525
            // dont want it to
526
            if ( localId == null ) {
527
                
528
                retPid = super.create(session, pid, object, sysmeta);
529
                result = (retPid.getValue().equals(pid.getValue()));
530
            }
531
            
532
        } catch (InvalidToken e) {
533
            String msg = "Could not save object to local store (InvalidToken): " + e.getMessage();
534
            failure = new ServiceFailure("2151", msg);
535
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
536
            logMetacat.error(msg);
537
            throw new ServiceFailure("2151", msg);
538
        
539
        } catch (IdentifierNotUnique e) {
540
            String msg = "Could not save object to local store (IdentifierNotUnique): " + e.getMessage();
541
            failure = new ServiceFailure("2151", msg);
542
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
543
            logMetacat.error(msg);
544
            throw new ServiceFailure("2151", msg);
545
        
546
        } catch (InvalidSystemMetadata e) {
547
            String msg = "Could not save object to local store (InvalidSystemMetadata): " + e.getMessage();
548
            failure = new ServiceFailure("2151", msg);
549
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
550
            logMetacat.error(msg);
551
            throw new ServiceFailure("2151", msg);
552
            
553
        }
554

    
555
        // finish by setting the replication status
556
        setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.COMPLETED, null);
557
        return result;
558

    
559
    }
560

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

    
579
        return super.get(session, pid);
580

    
581
    }
582

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

    
605
        Checksum checksum = null;
606

    
607
        InputStream inputStream = get(session, pid);
608

    
609
        try {
610
            checksum = ChecksumUtil.checksum(inputStream, algorithm);
611

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

    
620
        if (checksum == null) {
621
            throw new ServiceFailure("1410", "The checksum for the object specified by " + pid.getValue() + "could not be returned.");
622
        }
623

    
624
        return checksum;
625
    }
626

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

    
647
        return super.getSystemMetadata(session, pid);
648
    }
649

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

    
678
        ObjectList objectList = null;
679

    
680
        try {
681
            objectList = IdentifierManager.getInstance().querySystemMetadata(startTime, endTime, objectFormatId, replicaStatus, start, count);
682
        } catch (Exception e) {
683
            throw new ServiceFailure("1580", "Error querying system metadata: " + e.getMessage());
684
        }
685

    
686
        return objectList;
687
    }
688

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

    
703
        String nodeName = null;
704
        String nodeId = null;
705
        String subject = null;
706
        String contactSubject = null;
707
        String nodeDesc = null;
708
        String nodeTypeString = null;
709
        NodeType nodeType = null;
710
        String mnCoreServiceVersion = null;
711
        String mnReadServiceVersion = null;
712
        String mnAuthorizationServiceVersion = null;
713
        String mnStorageServiceVersion = null;
714
        String mnReplicationServiceVersion = null;
715

    
716
        boolean nodeSynchronize = false;
717
        boolean nodeReplicate = false;
718
        boolean mnCoreServiceAvailable = false;
719
        boolean mnReadServiceAvailable = false;
720
        boolean mnAuthorizationServiceAvailable = false;
721
        boolean mnStorageServiceAvailable = false;
722
        boolean mnReplicationServiceAvailable = false;
723

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

    
736
            mnCoreServiceVersion = PropertyService.getProperty("dataone.mnCore.serviceVersion");
737
            mnReadServiceVersion = PropertyService.getProperty("dataone.mnRead.serviceVersion");
738
            mnAuthorizationServiceVersion = PropertyService.getProperty("dataone.mnAuthorization.serviceVersion");
739
            mnStorageServiceVersion = PropertyService.getProperty("dataone.mnStorage.serviceVersion");
740
            mnReplicationServiceVersion = PropertyService.getProperty("dataone.mnReplication.serviceVersion");
741

    
742
            mnCoreServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnCore.serviceAvailable")).booleanValue();
743
            mnReadServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnRead.serviceAvailable")).booleanValue();
744
            mnAuthorizationServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnAuthorization.serviceAvailable")).booleanValue();
745
            mnStorageServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnStorage.serviceAvailable")).booleanValue();
746
            mnReplicationServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnReplication.serviceAvailable")).booleanValue();
747

    
748
            // Set the properties of the node based on configuration information and
749
            // calls to current status methods
750
            String serviceName = SystemUtil.getContextURL() + "/" + PropertyService.getProperty("dataone.serviceName");
751
            Node node = new Node();
752
            node.setBaseURL(serviceName + "/" + nodeTypeString);
753
            node.setDescription(nodeDesc);
754

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

    
771
            NodeReference identifier = new NodeReference();
772
            identifier.setValue(nodeId);
773
            node.setIdentifier(identifier);
774
            Subject s = new Subject();
775
            s.setValue(subject);
776
            node.addSubject(s);
777
            Subject contact = new Subject();
778
            contact.setValue(contactSubject);
779
            node.addContactSubject(contact);
780
            node.setName(nodeName);
781
            node.setReplicate(nodeReplicate);
782
            node.setSynchronize(nodeSynchronize);
783

    
784
            // services: MNAuthorization, MNCore, MNRead, MNReplication, MNStorage
785
            Services services = new Services();
786

    
787
            Service sMNCore = new Service();
788
            sMNCore.setName("MNCore");
789
            sMNCore.setVersion(mnCoreServiceVersion);
790
            sMNCore.setAvailable(mnCoreServiceAvailable);
791

    
792
            Service sMNRead = new Service();
793
            sMNRead.setName("MNRead");
794
            sMNRead.setVersion(mnReadServiceVersion);
795
            sMNRead.setAvailable(mnReadServiceAvailable);
796

    
797
            Service sMNAuthorization = new Service();
798
            sMNAuthorization.setName("MNAuthorization");
799
            sMNAuthorization.setVersion(mnAuthorizationServiceVersion);
800
            sMNAuthorization.setAvailable(mnAuthorizationServiceAvailable);
801

    
802
            Service sMNStorage = new Service();
803
            sMNStorage.setName("MNStorage");
804
            sMNStorage.setVersion(mnStorageServiceVersion);
805
            sMNStorage.setAvailable(mnStorageServiceAvailable);
806

    
807
            Service sMNReplication = new Service();
808
            sMNReplication.setName("MNReplication");
809
            sMNReplication.setVersion(mnReplicationServiceVersion);
810
            sMNReplication.setAvailable(mnReplicationServiceAvailable);
811

    
812
            services.addService(sMNRead);
813
            services.addService(sMNCore);
814
            services.addService(sMNAuthorization);
815
            services.addService(sMNStorage);
816
            services.addService(sMNReplication);
817
            node.setServices(services);
818

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

    
835
            node.setType(nodeType);
836
            return node;
837

    
838
        } catch (PropertyNotFoundException pnfe) {
839
            String msg = "MNodeService.getCapabilities(): " + "property not found: " + pnfe.getMessage();
840
            logMetacat.error(msg);
841
            throw new ServiceFailure("2162", msg);
842
        }
843
    }
844

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

    
868
        MonitorList monitorList = new MonitorList();
869

    
870
        try {
871

    
872
            // get log records first
873
            Log logs = getLogRecords(session, startTime, endTime, event, null, 0, null);
874

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

    
893
            }
894
        } catch (Exception e) {
895
            e.printStackTrace();
896
            throw new ServiceFailure("2081", "Could not retrieve statistics: " + e.getMessage());
897
        }
898

    
899
        return monitorList;
900

    
901
    }
902

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

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

    
937
            }
938
            
939
        } else {
940
            throw new ServiceFailure("2161", "The identifier cannot be null.");
941

    
942
        }
943
        
944
        try {
945
            localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
946
        } catch (McdbDocNotFoundException e) {
947
            throw new ServiceFailure("2161", "The identifier specified by " + 
948
                    syncFailed.getPid() + " was not found on this node.");
949

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

    
970
    }
971

    
972
    /**
973
     * Essentially a get() but with different logging behavior
974
     */
975
    @Override
976
    public InputStream getReplica(Session session, Identifier pid) 
977
        throws NotAuthorized, NotImplemented, ServiceFailure, InvalidToken {
978

    
979
        logMetacat.info("MNodeService.getReplica() called.");
980

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

    
990
        InputStream inputStream = null; // bytes to be returned
991
        handler = new MetacatHandler(new Timer());
992
        boolean allowed = false;
993
        String localId; // the metacat docid for the pid
994

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

    
1004
        Subject targetNodeSubject = session.getSubject();
1005

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

    
1017
        } catch (InvalidRequest e1) {
1018
            throw new ServiceFailure("2181", "Could not determine if node is authorized: " 
1019
                    + e1.getMessage());
1020

    
1021
        }
1022

    
1023
        logMetacat.info("Called D1Client.isNodeAuthorized(). Allowed = " + allowed +
1024
            " for identifier " + pid.getValue());
1025

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

    
1036
        // if we fail to set the input stream
1037
        if (inputStream == null) {
1038
            throw new ServiceFailure("2181", "The object specified by " + 
1039
                pid.getValue() + "does not exist at this node.");
1040
        }
1041

    
1042
        // log the replica event
1043
        String principal = null;
1044
        if (session.getSubject() != null) {
1045
            principal = session.getSubject().getValue();
1046
        }
1047
        EventLog.getInstance().log(request.getRemoteAddr(), 
1048
            request.getHeader("User-Agent"), principal, localId, "replicate");
1049

    
1050
        return inputStream;
1051
    }
1052

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

    
1187

    
1188
    }
1189

    
1190
	@Override
1191
	public Identifier generateIdentifier(Session arg0, String arg1, String arg2)
1192
			throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented,
1193
			InvalidRequest {
1194
		throw new NotImplemented("2194", "Member Node does not implement generateIdentifier method");
1195
	}
1196
    
1197
}
(3-3/5)