Revision 10130
Added by Jing Tao about 8 years ago
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java | ||
---|---|---|
426 | 426 |
|
427 | 427 |
// we have the go ahead |
428 | 428 |
//if ( allowed ) { |
429 |
|
|
429 |
|
|
430 |
|
|
431 |
logMetacat.debug("Allowed to insert: " + pid.getValue()); |
|
432 |
|
|
430 | 433 |
// save the sysmeta |
431 | 434 |
try { |
432 | 435 |
// lock and unlock of the pid happens in the subclass |
433 | 436 |
HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta); |
434 |
|
|
435 | 437 |
|
436 | 438 |
} catch (Exception e) { |
437 |
logMetacat.error("Problem creating system metadata: " + pid.getValue(), e);
|
|
438 |
throw new ServiceFailure("1190", e.getMessage()); |
|
439 |
logMetacat.error("D1Node.create - There was problem to save the system metadata: " + pid.getValue(), e);
|
|
440 |
throw new ServiceFailure("1190", "There was problem to save the system metadata: " + pid.getValue()+" since "+e.getMessage());
|
|
439 | 441 |
} |
440 |
|
|
441 |
logMetacat.debug("Allowed to insert: " + pid.getValue()); |
|
442 |
|
|
442 |
boolean isScienceMetadata = false; |
|
443 | 443 |
// Science metadata (XML) or science data object? |
444 | 444 |
// TODO: there are cases where certain object formats are science metadata |
445 | 445 |
// but are not XML (netCDF ...). Handle this. |
446 | 446 |
if ( isScienceMetadata(sysmeta) ) { |
447 |
|
|
447 |
isScienceMetadata = true; |
|
448 | 448 |
// CASE METADATA: |
449 | 449 |
//String objectAsXML = ""; |
450 | 450 |
try { |
... | ... | |
457 | 457 |
//localId = im.getLocalId(pid.getValue()); |
458 | 458 |
|
459 | 459 |
} catch (IOException e) { |
460 |
removeSystemMeta(pid);
|
|
461 |
String msg = "The Node is unable to create the object. " +
|
|
462 |
"There was a problem converting the object to XML"; |
|
463 |
logMetacat.info(msg);
|
|
460 |
removeSystemMetaAndIdentifier(pid, localId);
|
|
461 |
String msg = "The Node is unable to create the object "+pid.getValue() +
|
|
462 |
" There was a problem converting the object to XML";
|
|
463 |
logMetacat.error(msg, e);
|
|
464 | 464 |
throw new ServiceFailure("1190", msg + ": " + e.getMessage()); |
465 | 465 |
|
466 | 466 |
} catch (ServiceFailure e) { |
467 |
removeSystemMeta(pid); |
|
467 |
removeSystemMetaAndIdentifier(pid, localId); |
|
468 |
logMetacat.error("D1NodeService.create - the node couldn't create the object "+pid.getValue()+" since "+e.getMessage(), e); |
|
468 | 469 |
throw e; |
469 | 470 |
} catch (Exception e) { |
470 |
removeSystemMeta(pid);
|
|
471 |
removeSystemMetaAndIdentifier(pid, localId);
|
|
471 | 472 |
logMetacat.error("The node is unable to create the object: "+pid.getValue()+ " since " + e.getMessage(), e); |
472 | 473 |
throw new ServiceFailure("1190", "The node is unable to create the object: " +pid.getValue()+" since "+ e.getMessage()); |
473 | 474 |
} |
... | ... | |
478 | 479 |
try { |
479 | 480 |
localId = insertDataObject(object, pid, session); |
480 | 481 |
} catch (ServiceFailure e) { |
481 |
removeSystemMeta(pid);
|
|
482 |
removeSystemMetaAndIdentifier(pid, localId);
|
|
482 | 483 |
throw e; |
483 | 484 |
} catch (Exception e) { |
484 |
removeSystemMeta(pid);
|
|
485 |
throw new ServiceFailure("1190", "The node is unable to create the object: " + e.getMessage());
|
|
485 |
removeSystemMetaAndIdentifier(pid, localId);
|
|
486 |
throw new ServiceFailure("1190", "The node is unable to create the object "+pid.getValue()+" since " + e.getMessage());
|
|
486 | 487 |
} |
487 | 488 |
|
488 | 489 |
} |
... | ... | |
491 | 492 |
|
492 | 493 |
logMetacat.debug("Done inserting new object: " + pid.getValue()); |
493 | 494 |
|
494 |
// setting the resulting identifier failed |
|
495 |
if (localId == null ) { |
|
496 |
removeSystemMeta(pid); |
|
497 |
throw new ServiceFailure("1190", "The Node is unable to create the object. "); |
|
495 |
// setting the resulting identifier failed. We will check if the object does exist. |
|
496 |
try { |
|
497 |
if (localId == null || !IdentifierManager.getInstance().objectFileExists(localId, isScienceMetadata) ) { |
|
498 |
removeSystemMetaAndIdentifier(pid, localId); |
|
499 |
throw new ServiceFailure("1190", "The Node is unable to create the object. "+pid.getValue()); |
|
500 |
} |
|
501 |
} catch (PropertyNotFoundException e) { |
|
502 |
removeSystemMetaAndIdentifier(pid, localId); |
|
503 |
throw new ServiceFailure("1190", "The Node is unable to create the object. "+pid.getValue() + " since "+e.getMessage()); |
|
498 | 504 |
} |
505 |
|
|
499 | 506 |
|
507 |
|
|
508 |
|
|
509 |
|
|
500 | 510 |
try { |
501 | 511 |
// submit for indexing |
502 | 512 |
MetacatSolrIndex.getInstance().submit(sysmeta.getIdentifier(), sysmeta, null, true); |
... | ... | |
506 | 516 |
|
507 | 517 |
resultPid = pid; |
508 | 518 |
|
509 |
logMetacat.debug("create() complete for object: " + pid.getValue());
|
|
519 |
logMetacat.info("create() complete for object: " + pid.getValue());
|
|
510 | 520 |
|
511 | 521 |
return resultPid; |
512 | 522 |
} |
... | ... | |
514 | 524 |
/* |
515 | 525 |
* Roll-back method when inserting data object fails. |
516 | 526 |
*/ |
517 |
protected void removeSystemMeta(Identifier id){
|
|
527 |
protected void removeSystemMetaAndIdentifier(Identifier id, String localId){
|
|
518 | 528 |
if(id != null) { |
519 |
logMetacat.debug("D1NodeService.removeSystemMeta - the system metadata of object "+id.getValue()+" will removed from both hazelcast and db tables"); |
|
529 |
logMetacat.debug("D1NodeService.removeSystemMeta - the system metadata of object "+id.getValue()+" will removed from both hazelcast and db tables since the object creation failed"); |
|
530 |
HazelcastService.getInstance().getSystemMetadataMap().remove(id); |
|
531 |
logMetacat.info("D1NodeService.removeSystemMeta - the system metadata of object "+id.getValue()+" has been removed from both hazelcast and db tables since the object creation failed"); |
|
532 |
try { |
|
533 |
if(localId != null && !localId.trim().equals("") && IdentifierManager.getInstance().mappingExists(id.getValue())) { |
|
534 |
IdentifierManager.getInstance().removeMapping(id.getValue(), localId); |
|
535 |
logMetacat.info("D1NodeService.removeSystemMeta - the identifier "+id.getValue()+" and local id "+localId+" have been removed from the identifier table since the object creation failed"); |
|
536 |
} |
|
537 |
} catch (Exception e) { |
|
538 |
logMetacat.warn("D1NodeService.removeSysteMeta - can't decide if the mapping of the pid "+id.getValue()+" and local id "+localId+" exists on the identifier table."); |
|
539 |
} |
|
520 | 540 |
} |
521 |
HazelcastService.getInstance().getSystemMetadataMap().remove(id); |
|
522 |
if(id != null) { |
|
523 |
logMetacat.debug("D1NodeService.removeSystemMeta - the system metadata of object "+id.getValue()+" has been removed from both hazelcast and db tables"); |
|
524 |
} |
|
525 | 541 |
} |
526 | 542 |
|
527 | 543 |
/* |
... | ... | |
1387 | 1403 |
*/ |
1388 | 1404 |
public String insertOrUpdateDocument(InputStream xmlStream, String encoding, Identifier pid, |
1389 | 1405 |
Session session, String insertOrUpdate, String formatId) |
1390 |
throws ServiceFailure, IOException {
|
|
1406 |
throws ServiceFailure, IOException, PropertyNotFoundException{
|
|
1391 | 1407 |
|
1392 | 1408 |
logMetacat.debug("Starting to insert xml document..."); |
1393 | 1409 |
IdentifierManager im = IdentifierManager.getInstance(); |
... | ... | |
1462 | 1478 |
handler = new MetacatHandler(new Timer()); |
1463 | 1479 |
String result = handler.handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), null, |
1464 | 1480 |
null, params, username, groupnames, false, false, xmlBytes, formatId); |
1465 |
|
|
1466 |
if(result.indexOf("<error>") != -1) { |
|
1481 |
boolean isScienceMetadata = true; |
|
1482 |
if(result.indexOf("<error>") != -1 || !IdentifierManager.getInstance().objectFileExists(localId, isScienceMetadata)) {
|
|
1467 | 1483 |
String detailCode = ""; |
1468 | 1484 |
if ( insertOrUpdate.equals("insert") ) { |
1469 | 1485 |
// make sure to remove the mapping so that subsequent attempts do not fail with IdentifierNotUnique |
Also available in: Unified diff
Add the code to check if the object does exist in the create method. If it doesn't, the system metadata and identifier will be removed.