Revision 6800
Added by ben leinfelder about 13 years ago
src/edu/ucsb/nceas/metacat/dataone/SystemMetadataFactory.java | ||
---|---|---|
90 | 90 |
|
91 | 91 |
public class SystemMetadataFactory { |
92 | 92 |
|
93 |
private static final String resourceMapPrefix = "resourceMap_"; |
|
93 | 94 |
private static Logger logMetacat = Logger.getLogger(SystemMetadataFactory.class); |
94 | 95 |
|
95 | 96 |
/** |
... | ... | |
449 | 450 |
|
450 | 451 |
// ORE map |
451 | 452 |
if (includeORE) { |
453 |
// can we generate them? |
|
452 | 454 |
if (!dataIds.isEmpty()) { |
453 |
// generate the ORE map for this datapackage |
|
454 |
Identifier resourceMapId = new Identifier(); |
|
455 |
// want to be able to run this over and over again for now |
|
456 |
resourceMapId.setValue("resourceMap_" + sysMeta.getIdentifier().getValue() + "_" + System.currentTimeMillis()); |
|
457 |
idMap.put(sysMeta.getIdentifier(), dataIds); |
|
458 |
ResourceMap rm = ResourceMapFactory.getInstance().createResourceMap(resourceMapId, idMap); |
|
459 |
String resourceMapXML = ResourceMapFactory.getInstance().serializeResourceMap(rm); |
|
460 |
// copy most of the same system metadata as the packaging metadata |
|
461 |
SystemMetadata resourceMapSysMeta = new SystemMetadata(); |
|
462 |
BeanUtils.copyProperties(resourceMapSysMeta, sysMeta); |
|
463 |
resourceMapSysMeta.setIdentifier(resourceMapId); |
|
464 |
Checksum oreChecksum = ChecksumUtil.checksum(IOUtils.toInputStream(resourceMapXML, MetaCatServlet.DEFAULT_ENCODING), "MD5"); |
|
465 |
resourceMapSysMeta.setChecksum(oreChecksum); |
|
466 |
ObjectFormatIdentifier formatId = ObjectFormatCache.getInstance().getFormat("http://www.openarchives.org/ore/terms").getFormatId(); |
|
467 |
resourceMapSysMeta.setFormatId(formatId); |
|
468 |
// TODO: other fields to update? |
|
469 |
resourceMapSysMeta.setObsoletes(null); |
|
470 |
resourceMapSysMeta.setObsoletedBy(null); |
|
471 |
resourceMapSysMeta.setSize(BigInteger.valueOf(sizeOfStream(IOUtils.toInputStream(resourceMapXML, MetaCatServlet.DEFAULT_ENCODING)))); |
|
472 |
|
|
473 |
// save it locally |
|
474 |
Session session = new Session(); |
|
475 |
session.setSubject(submitter); |
|
476 |
MockHttpServletRequest request = new MockHttpServletRequest(null, null, null); |
|
477 |
MNodeService.getInstance(request).create( |
|
478 |
session, |
|
479 |
resourceMapId, |
|
480 |
IOUtils.toInputStream(resourceMapXML, MetaCatServlet.DEFAULT_ENCODING), |
|
481 |
resourceMapSysMeta); |
|
455 |
// it doesn't exist in the system? |
|
456 |
if (!oreExistsFor(sysMeta.getIdentifier())) { |
|
457 |
|
|
458 |
// generate the ORE map for this datapackage |
|
459 |
Identifier resourceMapId = new Identifier(); |
|
460 |
// want to be able to run this over and over again for now |
|
461 |
resourceMapId.setValue(resourceMapPrefix + sysMeta.getIdentifier().getValue()); |
|
462 |
idMap.put(sysMeta.getIdentifier(), dataIds); |
|
463 |
ResourceMap rm = ResourceMapFactory.getInstance().createResourceMap(resourceMapId, idMap); |
|
464 |
String resourceMapXML = ResourceMapFactory.getInstance().serializeResourceMap(rm); |
|
465 |
// copy most of the same system metadata as the packaging metadata |
|
466 |
SystemMetadata resourceMapSysMeta = new SystemMetadata(); |
|
467 |
BeanUtils.copyProperties(resourceMapSysMeta, sysMeta); |
|
468 |
resourceMapSysMeta.setIdentifier(resourceMapId); |
|
469 |
Checksum oreChecksum = ChecksumUtil.checksum(IOUtils.toInputStream(resourceMapXML, MetaCatServlet.DEFAULT_ENCODING), "MD5"); |
|
470 |
resourceMapSysMeta.setChecksum(oreChecksum); |
|
471 |
ObjectFormatIdentifier formatId = ObjectFormatCache.getInstance().getFormat("http://www.openarchives.org/ore/terms").getFormatId(); |
|
472 |
resourceMapSysMeta.setFormatId(formatId); |
|
473 |
resourceMapSysMeta.setSize(BigInteger.valueOf(sizeOfStream(IOUtils.toInputStream(resourceMapXML, MetaCatServlet.DEFAULT_ENCODING)))); |
|
474 |
|
|
475 |
// set the revision graph |
|
476 |
resourceMapSysMeta.setObsoletes(null); |
|
477 |
resourceMapSysMeta.setObsoletedBy(null); |
|
478 |
// look up the resource map that this one obsoletes |
|
479 |
if (sysMeta.getObsoletes() != null) { |
|
480 |
Identifier resourceMapObsoletes = new Identifier(); |
|
481 |
resourceMapObsoletes.setValue(resourceMapPrefix + sysMeta.getObsoletes().getValue()); |
|
482 |
resourceMapSysMeta.setObsoletes(resourceMapObsoletes); |
|
483 |
SystemMetadata resourceMapObsoletesSystemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(resourceMapObsoletes); |
|
484 |
if (resourceMapObsoletesSystemMetadata != null) { |
|
485 |
resourceMapObsoletesSystemMetadata.setObsoletedBy(resourceMapId); |
|
486 |
HazelcastService.getInstance().getSystemMetadataMap().put(resourceMapObsoletes, resourceMapObsoletesSystemMetadata); |
|
487 |
} |
|
488 |
} |
|
489 |
// look up the resource map that this one is obsoletedBy |
|
490 |
if (sysMeta.getObsoletedBy() != null) { |
|
491 |
Identifier resourceMapObsoletedBy = new Identifier(); |
|
492 |
resourceMapObsoletedBy.setValue(resourceMapPrefix + sysMeta.getObsoletedBy().getValue()); |
|
493 |
resourceMapSysMeta.setObsoletedBy(resourceMapObsoletedBy); |
|
494 |
SystemMetadata resourceMapObsoletedBySystemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(resourceMapObsoletedBy); |
|
495 |
if (resourceMapObsoletedBySystemMetadata != null) { |
|
496 |
resourceMapObsoletedBySystemMetadata.setObsoletes(resourceMapId); |
|
497 |
HazelcastService.getInstance().getSystemMetadataMap().put(resourceMapObsoletedBy, resourceMapObsoletedBySystemMetadata); |
|
498 |
} |
|
499 |
} |
|
500 |
|
|
501 |
// save it locally |
|
502 |
Session session = new Session(); |
|
503 |
session.setSubject(submitter); |
|
504 |
MockHttpServletRequest request = new MockHttpServletRequest(null, null, null); |
|
505 |
MNodeService.getInstance(request).create( |
|
506 |
session, |
|
507 |
resourceMapId, |
|
508 |
IOUtils.toInputStream(resourceMapXML, MetaCatServlet.DEFAULT_ENCODING), |
|
509 |
resourceMapSysMeta); |
|
510 |
} |
|
482 | 511 |
} |
483 | 512 |
} |
484 | 513 |
|
... | ... | |
503 | 532 |
|
504 | 533 |
return sysMeta; |
505 | 534 |
} |
535 |
|
|
536 |
/** |
|
537 |
* Determines if we already have registered an ORE map for this package |
|
538 |
* @param guid of the EML/packaging object |
|
539 |
* @return true if there is an ORE map for the given package |
|
540 |
*/ |
|
541 |
private static boolean oreExistsFor(Identifier guid) { |
|
542 |
// TODO: implement call to CN.search() |
|
543 |
return false; |
|
544 |
} |
|
506 | 545 |
|
507 | 546 |
/** |
508 | 547 |
* Find the size (in bytes) of a stream. Note: This needs to refactored out |
Also available in: Unified diff
add revision history to the generated ORE objects -- we use the revision history of the EML package as a basis because the each ORE revision mirrors the revision of the EML package.
Add a placeholder for checking if an equivalent ORE map exists in the DataONE infrastructure - this will be a call to CN.search() that looks at the solr index for OREs based on the EML package ID.