Project

General

Profile

« Previous | Next » 

Revision 7148

implement MN and CN.archive() method -- really just the existing delete() methods.
https://redmine.dataone.org/issues/2674
https://redmine.dataone.org/issues/2675

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
371 371
  }
372 372
  
373 373
  /**
374
   * Deletes an object from the Coordinating Node, where the object is a 
375
   * a science metadata object.
376
   * 
377
   * @param session - the Session object containing the credentials for the Subject
378
   * @param pid - The object identifier to be deleted
379
   * 
380
   * @return pid - the identifier of the object used for the deletion
381
   * 
382
   * @throws InvalidToken
383
   * @throws ServiceFailure
384
   * @throws NotAuthorized
385
   * @throws NotFound
386
   * @throws NotImplemented
387
   * @throws InvalidRequest
388
   */
389
  @Override
390
  public Identifier archive(Session session, Identifier pid) 
391
      throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
392

  
393
	  // check that it is CN/admin
394
	  boolean allowed = isAdminAuthorized(session);
395
	  
396
	  if (!allowed) {
397
		  String msg = "The subject is not allowed to call delete() on a Coordinating Node.";
398
		  logMetacat.info(msg);
399
		  throw new NotAuthorized("1320", msg);
400
	  }
401
	  
402
	  // defer to superclass implementation
403
	  Identifier retId =  super.archive(session, pid);
404
      
405
	  // notify the replicas
406
	  SystemMetadata systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
407
	  if (systemMetadata.getReplicaList() != null) {
408
		  for (Replica replica: systemMetadata.getReplicaList()) {
409
			  NodeReference replicaNode = replica.getReplicaMemberNode();
410
			  try {
411
				  // TODO: implement in the clients
412
				  //Identifier mnRetId = D1Client.getMN(replicaNode).archive(null, pid);
413
			  } catch (Exception e) {
414
				  // all we can really do is log errors and carry on with life
415
				  logMetacat.error("Error archiving pid: " +  pid.getValue() + " from replica MN: " + replicaNode.getValue(), e);
416
			}
417
			  
418
		  }
419
	  }
420
	  
421
	  return retId;
422
      
423
  }
424
  
425
  /**
374 426
   * Set the obsoletedBy attribute in System Metadata
375 427
   * @param session
376 428
   * @param pid
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
1377 1377
      
1378 1378
  }
1379 1379

  
1380
/**
1381
   * Archives an object, where the object is either a 
1382
   * data object or a science metadata object.
1383
   * 
1384
   * @param session - the Session object containing the credentials for the Subject
1385
   * @param pid - The object identifier to be archived
1386
   * 
1387
   * @return pid - the identifier of the object used for the archiving
1388
   * 
1389
   * @throws InvalidToken
1390
   * @throws ServiceFailure
1391
   * @throws NotAuthorized
1392
   * @throws NotFound
1393
   * @throws NotImplemented
1394
   * @throws InvalidRequest
1395
   */
1396
  public Identifier archive(Session session, Identifier pid) 
1397
      throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
1380 1398

  
1399
      String localId = null;
1400
      boolean allowed = false;
1401
      String username = Constants.SUBJECT_PUBLIC;
1402
      String[] groupnames = null;
1403
      if (session == null) {
1404
      	throw new InvalidToken("1330", "No session has been provided");
1405
      } else {
1406
          username = session.getSubject().getValue();
1407
          if (session.getSubjectInfo() != null) {
1408
              List<Group> groupList = session.getSubjectInfo().getGroupList();
1409
              if (groupList != null) {
1410
                  groupnames = new String[groupList.size()];
1411
                  for (int i = 0; i > groupList.size(); i++) {
1412
                      groupnames[i] = groupList.get(i).getGroupName();
1413
                  }
1414
              }
1415
          }
1416
      }
1417

  
1418
      // do we have a valid pid?
1419
      if (pid == null || pid.getValue().trim().equals("")) {
1420
          throw new ServiceFailure("1350", "The provided identifier was invalid.");
1421
      }
1422

  
1423
      // check for the existing identifier
1424
      try {
1425
          localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
1426
      } catch (McdbDocNotFoundException e) {
1427
          throw new NotFound("1340", "The object with the provided " + "identifier was not found.");
1428
      }
1429

  
1430
      // does the subject have archive (a D1 CHANGE_PERMISSION level) privileges on the pid?
1431
      try {
1432
			allowed = isAuthorized(session, pid, Permission.CHANGE_PERMISSION);
1433
		} catch (InvalidRequest e) {
1434
          throw new ServiceFailure("1350", e.getDescription());
1435
		}
1436
          
1437

  
1438
      if (allowed) {
1439
          try {
1440
              // archive the document
1441
        	  // this method just archives it in metacat
1442
              DocumentImpl.delete(localId, username, groupnames, null);
1443
              EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), username, localId, Event.DELETE.xmlValue());
1444

  
1445
              // archive it
1446
              SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
1447
              sysMeta.setArchived(true);
1448
              HazelcastService.getInstance().getSystemMetadataMap().put(pid, sysMeta);
1449
              
1450
          } catch (McdbDocNotFoundException e) {
1451
              throw new NotFound("1340", "The provided identifier was invalid.");
1452

  
1453
          } catch (SQLException e) {
1454
              throw new ServiceFailure("1350", "There was a problem archiving the object." + "The error message was: " + e.getMessage());
1455

  
1456
          } catch (InsufficientKarmaException e) {
1457
              throw new NotAuthorized("1320", "The provided identity does not have " + "permission to archive this object.");
1458

  
1459
          } catch (Exception e) { // for some reason DocumentImpl throws a general Exception
1460
              throw new ServiceFailure("1350", "There was a problem archiving the object." + "The error message was: " + e.getMessage());
1461
          }
1462

  
1463
      } else {
1464
          throw new NotAuthorized("1320", "The provided identity does not have " + "permission to archive the object on the Node.");
1465
      }
1466

  
1467
      return pid;
1468
  }
1469

  
1470

  
1381 1471
}

Also available in: Unified diff