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 |
}
|
implement MN and CN.archive() method -- really just the existing delete() methods.
https://redmine.dataone.org/issues/2674
https://redmine.dataone.org/issues/2675