Revision 6881
Added by ben leinfelder almost 13 years ago
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java | ||
---|---|---|
28 | 28 |
import java.util.Calendar; |
29 | 29 |
import java.util.Date; |
30 | 30 |
import java.util.List; |
31 |
import java.util.Set; |
|
32 | 31 |
import java.util.concurrent.locks.Lock; |
33 | 32 |
|
34 | 33 |
import javax.servlet.http.HttpServletRequest; |
... | ... | |
72 | 71 |
import org.dataone.service.types.v1.Session; |
73 | 72 |
import org.dataone.service.types.v1.Subject; |
74 | 73 |
import org.dataone.service.types.v1.SystemMetadata; |
74 |
import org.dataone.service.types.v1.util.ServiceMethodRestrictionUtil; |
|
75 | 75 |
|
76 | 76 |
import edu.ucsb.nceas.metacat.EventLog; |
77 | 77 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
... | ... | |
204 | 204 |
} |
205 | 205 |
|
206 | 206 |
/** |
207 |
* Deletes the replica from the given Member Node |
|
208 |
* NOTE: MN.delete() may be an "archive" operation. TBD. |
|
209 |
* @param session |
|
210 |
* @param pid |
|
211 |
* @param nodeId |
|
212 |
* @param serialVersion |
|
213 |
* @return |
|
214 |
* @throws InvalidToken |
|
215 |
* @throws ServiceFailure |
|
216 |
* @throws NotAuthorized |
|
217 |
* @throws NotFound |
|
218 |
* @throws NotImplemented |
|
219 |
*/ |
|
220 |
public boolean deleteReplicationMetadata(Session session, Identifier pid, NodeReference nodeId, long serialVersion) |
|
221 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
|
222 |
|
|
223 |
List<Node> nodeList = D1Client.getCN().listNodes().getNodeList(); |
|
224 |
|
|
225 |
// check permissions |
|
226 |
boolean isAllowed = ServiceMethodRestrictionUtil.isMethodAllowed(session.getSubject(), nodeList, "CNReplication", "deleteReplicationMetadata"); |
|
227 |
|
|
228 |
if (isAllowed) { |
|
229 |
throw new NotAuthorized("0000", "Caller is not authorized to deleteReplicationMetadata"); |
|
230 |
} |
|
231 |
|
|
232 |
// delete the replica from the given node |
|
233 |
D1Client.getMN(nodeId).delete(session, pid); |
|
234 |
|
|
235 |
return true; |
|
236 |
} |
|
237 |
|
|
238 |
|
|
239 |
/** |
|
207 | 240 |
* Set the replication status for an object given the object identifier |
208 | 241 |
* |
209 | 242 |
* @param session - the Session object containing the credentials for the Subject |
... | ... | |
377 | 410 |
|
378 | 411 |
return true; |
379 | 412 |
} |
380 |
|
|
381 |
/** |
|
382 |
* Test that the specified relationship between pidOfSubject and pidOfObject exists |
|
383 |
* |
|
384 |
* @param session - the Session object containing the credentials for the Subject |
|
385 |
* @param node - the node information for the given node be modified |
|
386 |
* |
|
387 |
* @return true if the relationship exists |
|
388 |
* |
|
389 |
* @throws InvalidToken |
|
390 |
* @throws ServiceFailure |
|
391 |
* @throws NotAuthorized |
|
392 |
* @throws NotFound |
|
393 |
* @throws InvalidRequest |
|
394 |
* @throws NotImplemented |
|
395 |
*/ |
|
396 |
@Override |
|
397 |
public boolean assertRelation(Session session, Identifier pidOfSubject, |
|
398 |
String relationship, Identifier pidOfObject) |
|
399 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, |
|
400 |
InvalidRequest, NotImplemented { |
|
401 |
|
|
402 |
// The lock to be used for thyis identifier |
|
403 |
Lock lock = null; |
|
404 |
|
|
405 |
boolean asserted = false; |
|
406 |
|
|
407 |
// are we allowed to do this? |
|
408 |
if (!isAuthorized(session, pidOfSubject, Permission.READ)) { |
|
409 |
throw new NotAuthorized("4881", Permission.READ + " not allowed on " + pidOfSubject.getValue()); |
|
410 |
} |
|
411 |
|
|
412 |
SystemMetadata systemMetadata = null; |
|
413 |
try { |
|
414 |
lock = HazelcastService.getInstance().getLock(pidOfSubject.getValue()); |
|
415 |
lock.lock(); |
|
416 |
systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pidOfSubject); |
|
417 |
|
|
418 |
|
|
419 |
// check relationships |
|
420 |
// TODO: use ORE map |
|
421 |
if (relationship.equalsIgnoreCase("describes")) { |
|
422 |
|
|
423 |
} |
|
424 |
|
|
425 |
if (relationship.equalsIgnoreCase("describedBy")) { |
|
426 |
|
|
427 |
} |
|
428 |
|
|
429 |
if (relationship.equalsIgnoreCase("derivedFrom")) { |
|
430 |
|
|
431 |
} |
|
432 |
|
|
433 |
if (relationship.equalsIgnoreCase("obsoletes")) { |
|
434 |
Identifier pid = systemMetadata.getObsoletes(); |
|
435 |
if (pid.getValue().equals(pidOfObject.getValue())) { |
|
436 |
asserted = true; |
|
437 |
|
|
438 |
} |
|
439 |
//return systemMetadata.getObsoleteList().contains(pidOfObject); |
|
440 |
} |
|
441 |
if (relationship.equalsIgnoreCase("obsoletedBy")) { |
|
442 |
Identifier pid = systemMetadata.getObsoletedBy(); |
|
443 |
if (pid.getValue().equals(pidOfObject.getValue())) { |
|
444 |
asserted = true; |
|
445 |
|
|
446 |
} |
|
447 |
//return systemMetadata.getObsoletedByList().contains(pidOfObject); |
|
448 |
} |
|
449 |
|
|
450 |
} catch (Exception e) { |
|
451 |
throw new ServiceFailure("4270", "Could not assert relation for: " + |
|
452 |
pidOfSubject.getValue() + |
|
453 |
". The error message was: " + e.getMessage()); |
|
454 |
|
|
455 |
} finally { |
|
456 |
lock.unlock(); |
|
457 |
logMetacat.debug("Unlocked identifier " + pidOfSubject.getValue()); |
|
458 |
|
|
459 |
} |
|
460 |
|
|
461 |
return asserted; |
|
462 |
} |
|
463 | 413 |
|
464 | 414 |
/** |
465 | 415 |
* Return the checksum of the object given the identifier |
Also available in: Unified diff
add method: deleteReplicationMetadata
remove method: assertRelation
update the D1 jars
https://redmine.dataone.org/issues/2187
https://redmine.dataone.org/issues/2158