Revision 6572
Added by Chris Jones almost 13 years ago
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java | ||
---|---|---|
253 | 253 |
|
254 | 254 |
// save the sysmeta |
255 | 255 |
try { |
256 |
// lock and unlock of the pid happens in the subclass |
|
256 | 257 |
HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta); |
258 |
|
|
257 | 259 |
} catch (Exception e) { |
258 | 260 |
logMetacat.error("Problem creating system metadata: " + pid.getValue(), e); |
259 | 261 |
throw new ServiceFailure("1190", e.getMessage()); |
... | ... | |
506 | 508 |
* @throws NotImplemented |
507 | 509 |
*/ |
508 | 510 |
public SystemMetadata getSystemMetadata(Session session, Identifier pid) |
509 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, |
|
510 |
InvalidRequest, NotImplemented { |
|
511 |
|
|
512 |
if (!isAuthorized(session, pid, Permission.READ)) { |
|
513 |
throw new NotAuthorized("1400", Permission.READ + " not allowed on " + pid.getValue()); |
|
514 |
} |
|
515 |
SystemMetadata systemMetadata = null; |
|
516 |
try { |
|
517 |
systemMetadata = IdentifierManager.getInstance().getSystemMetadata(pid.getValue()); |
|
518 |
} catch (McdbDocNotFoundException e) { |
|
519 |
throw new NotFound("1420", "No record found for: " + pid.getValue()); |
|
520 |
} |
|
511 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, |
|
512 |
InvalidRequest, NotImplemented { |
|
513 |
|
|
514 |
if (!isAuthorized(session, pid, Permission.READ)) { |
|
515 |
throw new NotAuthorized("1400", Permission.READ + " not allowed on " + pid.getValue()); |
|
516 |
} |
|
517 |
SystemMetadata systemMetadata = null; |
|
518 |
try { |
|
519 |
HazelcastService.getInstance().getSystemMetadataMap().lock(pid); |
|
520 |
systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
|
521 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid); |
|
522 |
|
|
523 |
} catch (Exception e) { |
|
524 |
// convert hazelcast RuntimeException to NotFound |
|
525 |
throw new NotFound("1420", "No record found for: " + pid.getValue()); |
|
526 |
|
|
527 |
} |
|
521 | 528 |
|
522 | 529 |
return systemMetadata; |
523 | 530 |
} |
524 |
|
|
531 |
|
|
525 | 532 |
/** |
526 |
* Set access for a given object using the object identifier and a Subject |
|
527 |
* under a given Session. |
|
528 |
* |
|
529 |
* @param session - the Session object containing the credentials for the Subject |
|
530 |
* @param pid - the object identifier for the given object to apply the policy |
|
531 |
* @param policy - the access policy to be applied |
|
532 |
* |
|
533 |
* @return true if the application of the policy succeeds |
|
534 |
* @throws InvalidToken |
|
535 |
* @throws ServiceFailure |
|
536 |
* @throws NotFound |
|
537 |
* @throws NotAuthorized |
|
538 |
* @throws NotImplemented |
|
539 |
* @throws InvalidRequest |
|
540 |
*/ |
|
541 |
public boolean setAccessPolicy(Session session, Identifier pid, |
|
542 |
AccessPolicy accessPolicy) |
|
543 |
throws InvalidToken, ServiceFailure, NotFound, NotAuthorized, |
|
544 |
NotImplemented, InvalidRequest { |
|
545 |
|
|
546 |
boolean success = false; |
|
547 |
|
|
548 |
// get the subject |
|
549 |
Subject subject = session.getSubject(); |
|
550 |
// get the system metadata |
|
551 |
String pidStr = pid.getValue(); |
|
552 |
|
|
553 |
// are we allowed to do this? |
|
554 |
if (!isAuthorized(session, pid, Permission.CHANGE_PERMISSION)) { |
|
555 |
throw new NotAuthorized("4420", "not allowed by " + subject.getValue() + " on " + pidStr); |
|
556 |
} |
|
557 |
|
|
558 |
SystemMetadata systemMetadata = null; |
|
559 |
try { |
|
560 |
systemMetadata = IdentifierManager.getInstance().getSystemMetadata(pidStr); |
|
561 |
} catch (McdbDocNotFoundException e) { |
|
562 |
throw new NotFound("4400", "No record found for: " + pid); |
|
563 |
} |
|
564 |
|
|
565 |
// set the access policy |
|
566 |
systemMetadata.setAccessPolicy(accessPolicy); |
|
567 |
|
|
568 |
// update the metadata |
|
569 |
try { |
|
570 |
HazelcastService.getInstance().getSystemMetadataMap().lock(systemMetadata.getIdentifier()); |
|
571 |
HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata); |
|
572 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(systemMetadata.getIdentifier()); |
|
573 |
} catch (Exception e) { |
|
574 |
throw new ServiceFailure("4430", e.getMessage()); |
|
575 |
} finally { |
|
576 |
HazelcastService.getInstance().getSystemMetadataMap().unlock(systemMetadata.getIdentifier()); |
|
577 |
} |
|
578 |
|
|
579 |
// TODO: how do we know if the map was persisted? |
|
580 |
success = true; |
|
581 |
|
|
582 |
return success; |
|
583 |
} |
|
584 |
|
|
585 |
/** |
|
586 | 533 |
* Test if the user identified by the provided token has authorization |
587 | 534 |
* for operation on the specified object. |
588 | 535 |
* |
... | ... | |
956 | 903 |
* Insert a systemMetadata document and return its localId |
957 | 904 |
*/ |
958 | 905 |
protected void insertSystemMetadata(SystemMetadata sysmeta) |
959 |
throws ServiceFailure { |
|
960 |
|
|
961 |
logMetacat.debug("Starting to insert SystemMetadata..."); |
|
962 |
sysmeta.setDateSysMetadataModified(new Date()); |
|
963 |
logMetacat.debug("Inserting new system metadata with modified date " + |
|
964 |
sysmeta.getDateSysMetadataModified()); |
|
965 |
|
|
966 |
//insert the system metadata |
|
967 |
try { |
|
968 |
HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta); |
|
969 |
} catch (Exception e) { |
|
970 |
throw new ServiceFailure("1190", e.getMessage()); |
|
971 |
} |
|
906 |
throws ServiceFailure { |
|
907 |
|
|
908 |
logMetacat.debug("Starting to insert SystemMetadata..."); |
|
909 |
sysmeta.setDateSysMetadataModified(Calendar.getInstance().getTime()); |
|
910 |
logMetacat.debug("Inserting new system metadata with modified date " + |
|
911 |
sysmeta.getDateSysMetadataModified()); |
|
912 |
|
|
913 |
//insert the system metadata |
|
914 |
try { |
|
915 |
// note: the calling subclass handles the map hazelcast lock/unlock |
|
916 |
HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta); |
|
917 |
|
|
918 |
} catch (Exception e) { |
|
919 |
throw new ServiceFailure("1190", e.getMessage()); |
|
920 |
|
|
921 |
} |
|
972 | 922 |
} |
973 | 923 |
|
974 | 924 |
/** |
Also available in: Unified diff
Update getSystemMetadata() to lock(); get(); unlock() to ensure we have the latest version of system metadata from the hzSystemMetadata map. Remove the setAccessPolicy() method since it is being deprecated in the MNAuthorization API.
change insertSystemMetadata() to use a finer grained Date object on insertion. Locking of the pid happens in the subclass prior to the insert.