Revision 7864
Added by ben leinfelder almost 11 years ago
MNodeService.java | ||
---|---|---|
1553 | 1553 |
* |
1554 | 1554 |
* @param originalIdentifier |
1555 | 1555 |
* @param request |
1556 |
* @throws InvalidRequest |
|
1557 |
* @throws EZIDException |
|
1558 |
* @throws InvalidToken |
|
1559 |
* @throws NotAuthorized |
|
1560 |
* @throws NotImplemented |
|
1561 |
* @throws ServiceFailure |
|
1556 |
* @throws InvalidRequest |
|
1557 |
* @throws NotImplemented |
|
1558 |
* @throws NotAuthorized |
|
1559 |
* @throws ServiceFailure |
|
1560 |
* @throws InvalidToken |
|
1562 | 1561 |
* @throws NotFound |
1563 |
* @throws InsufficientResources |
|
1564 |
* @throws IdentifierNotUnique |
|
1565 |
* @throws InvalidSystemMetadata |
|
1566 |
* @throws UnsupportedType |
|
1567 |
* @throws McdbDocNotFoundException |
|
1568 |
* @throws OREParserException |
|
1569 |
* @throws URISyntaxException |
|
1570 |
* @throws OREException |
|
1571 |
* @throws UnsupportedEncodingException |
|
1572 |
* @throws ORESerialiserException |
|
1573 |
* @throws NoSuchAlgorithmException |
|
1562 |
* @throws InvalidSystemMetadata |
|
1563 |
* @throws InsufficientResources |
|
1564 |
* @throws UnsupportedType |
|
1565 |
* @throws IdentifierNotUnique |
|
1574 | 1566 |
*/ |
1575 |
public Identifier publish(Session session, Identifier originalIdentifier) throws InvalidRequest, EZIDException, InvalidToken, NotAuthorized, NotImplemented, ServiceFailure, NotFound, InsufficientResources, IdentifierNotUnique, InvalidSystemMetadata, UnsupportedType, McdbDocNotFoundException, UnsupportedEncodingException, OREException, URISyntaxException, OREParserException, ORESerialiserException, NoSuchAlgorithmException {
|
|
1567 |
public Identifier publish(Session session, Identifier originalIdentifier) throws InvalidToken, ServiceFailure, NotAuthorized, NotImplemented, InvalidRequest, NotFound, IdentifierNotUnique, UnsupportedType, InsufficientResources, InvalidSystemMetadata {
|
|
1576 | 1568 |
|
1577 | 1569 |
// mint a DOI for the new revision |
1578 | 1570 |
Identifier newIdentifier = this.generateIdentifier(session, MNodeService.DOI_SCHEME, null); |
... | ... | |
1587 | 1579 |
InputStream inputStream = this.get(session, originalIdentifier); |
1588 | 1580 |
|
1589 | 1581 |
// update the object |
1590 |
this.update(session, originalIdentifier, inputStream , newIdentifier, sysmeta);
|
|
1582 |
this.update(session, originalIdentifier, inputStream, newIdentifier, sysmeta); |
|
1591 | 1583 |
|
1592 |
// TODO: update ORE that references the scimeta |
|
1593 |
String localId = IdentifierManager.getInstance().getLocalId(originalIdentifier.getValue()); |
|
1594 |
Identifier potentialOreIdentifier = new Identifier(); |
|
1595 |
potentialOreIdentifier.setValue(SystemMetadataFactory.RESOURCE_MAP_PREFIX + localId); |
|
1596 |
|
|
1597 |
InputStream oreInputStream = null; |
|
1584 |
// update ORE that references the scimeta |
|
1585 |
// TODO: better ORE location algorithm -- this is just convention for generated resource maps and is fragile |
|
1598 | 1586 |
try { |
1599 |
oreInputStream = this.get(session, potentialOreIdentifier); |
|
1600 |
} catch (NotFound nf) { |
|
1601 |
// this is probably okay for many sci meta data docs |
|
1602 |
logMetacat.warn("No potential ORE map found for: " + potentialOreIdentifier.getValue()); |
|
1603 |
} |
|
1604 |
if (oreInputStream != null) { |
|
1605 |
Identifier newOreIdentifier = MNodeService.getInstance(request).generateIdentifier(session, MNodeService.UUID_SCHEME, null); |
|
1606 |
|
|
1607 |
Map<Identifier, Map<Identifier, List<Identifier>>> resourceMapStructure = ResourceMapFactory.getInstance().parseResourceMap(oreInputStream); |
|
1608 |
Map<Identifier, List<Identifier>> sciMetaMap = resourceMapStructure.get(potentialOreIdentifier); |
|
1609 |
List<Identifier> dataIdentifiers = sciMetaMap.get(originalIdentifier); |
|
1587 |
String localId = IdentifierManager.getInstance().getLocalId(originalIdentifier.getValue()); |
|
1610 | 1588 |
|
1611 |
// TODO: ensure all data package objects allow public read |
|
1612 |
|
|
1613 |
// reconstruct the ORE with the new identifiers |
|
1614 |
sciMetaMap.remove(originalIdentifier); |
|
1615 |
sciMetaMap.put(newIdentifier, dataIdentifiers); |
|
1589 |
Identifier potentialOreIdentifier = new Identifier(); |
|
1590 |
potentialOreIdentifier.setValue(SystemMetadataFactory.RESOURCE_MAP_PREFIX + localId); |
|
1616 | 1591 |
|
1617 |
ResourceMap resourceMap = ResourceMapFactory.getInstance().createResourceMap(newOreIdentifier, sciMetaMap); |
|
1618 |
String resourceMapString = ResourceMapFactory.getInstance().serializeResourceMap(resourceMap); |
|
1619 |
|
|
1620 |
// get the original ORE SM and update the values |
|
1621 |
SystemMetadata oreSysMeta = this.getSystemMetadata(session, potentialOreIdentifier); |
|
1622 |
oreSysMeta.setIdentifier(newOreIdentifier); |
|
1623 |
oreSysMeta.setObsoletes(potentialOreIdentifier); |
|
1624 |
oreSysMeta.setObsoletedBy(null); |
|
1625 |
oreSysMeta.setSize(BigInteger.valueOf(resourceMapString.getBytes("UTF-8").length)); |
|
1626 |
oreSysMeta.setChecksum(ChecksumUtil.checksum(resourceMapString.getBytes("UTF-8"), oreSysMeta.getChecksum().getAlgorithm())); |
|
1627 |
|
|
1628 |
// save the updated ORE |
|
1629 |
this.update( |
|
1630 |
session, |
|
1631 |
potentialOreIdentifier, |
|
1632 |
new ByteArrayInputStream(resourceMapString.getBytes("UTF-8")), |
|
1633 |
newOreIdentifier, |
|
1634 |
oreSysMeta); |
|
1635 |
|
|
1592 |
InputStream oreInputStream = null; |
|
1593 |
try { |
|
1594 |
oreInputStream = this.get(session, potentialOreIdentifier); |
|
1595 |
} catch (NotFound nf) { |
|
1596 |
// this is probably okay for many sci meta data docs |
|
1597 |
logMetacat.warn("No potential ORE map found for: " + potentialOreIdentifier.getValue()); |
|
1598 |
} |
|
1599 |
if (oreInputStream != null) { |
|
1600 |
Identifier newOreIdentifier = MNodeService.getInstance(request).generateIdentifier(session, MNodeService.UUID_SCHEME, null); |
|
1601 |
|
|
1602 |
Map<Identifier, Map<Identifier, List<Identifier>>> resourceMapStructure = ResourceMapFactory.getInstance().parseResourceMap(oreInputStream); |
|
1603 |
Map<Identifier, List<Identifier>> sciMetaMap = resourceMapStructure.get(potentialOreIdentifier); |
|
1604 |
List<Identifier> dataIdentifiers = sciMetaMap.get(originalIdentifier); |
|
1605 |
|
|
1606 |
// TODO: ensure all data package objects allow public read |
|
1607 |
|
|
1608 |
// reconstruct the ORE with the new identifiers |
|
1609 |
sciMetaMap.remove(originalIdentifier); |
|
1610 |
sciMetaMap.put(newIdentifier, dataIdentifiers); |
|
1611 |
|
|
1612 |
ResourceMap resourceMap = ResourceMapFactory.getInstance().createResourceMap(newOreIdentifier, sciMetaMap); |
|
1613 |
String resourceMapString = ResourceMapFactory.getInstance().serializeResourceMap(resourceMap); |
|
1614 |
|
|
1615 |
// get the original ORE SM and update the values |
|
1616 |
SystemMetadata oreSysMeta = this.getSystemMetadata(session, potentialOreIdentifier); |
|
1617 |
oreSysMeta.setIdentifier(newOreIdentifier); |
|
1618 |
oreSysMeta.setObsoletes(potentialOreIdentifier); |
|
1619 |
oreSysMeta.setObsoletedBy(null); |
|
1620 |
oreSysMeta.setSize(BigInteger.valueOf(resourceMapString.getBytes("UTF-8").length)); |
|
1621 |
oreSysMeta.setChecksum(ChecksumUtil.checksum(resourceMapString.getBytes("UTF-8"), oreSysMeta.getChecksum().getAlgorithm())); |
|
1622 |
|
|
1623 |
// save the updated ORE |
|
1624 |
this.update( |
|
1625 |
session, |
|
1626 |
potentialOreIdentifier, |
|
1627 |
new ByteArrayInputStream(resourceMapString.getBytes("UTF-8")), |
|
1628 |
newOreIdentifier, |
|
1629 |
oreSysMeta); |
|
1630 |
|
|
1631 |
} |
|
1632 |
} catch (McdbDocNotFoundException e) { |
|
1633 |
// report as service failure |
|
1634 |
ServiceFailure sf = new ServiceFailure("1030", e.getMessage()); |
|
1635 |
sf.initCause(e); |
|
1636 |
throw sf; |
|
1637 |
} catch (UnsupportedEncodingException e) { |
|
1638 |
// report as service failure |
|
1639 |
ServiceFailure sf = new ServiceFailure("1030", e.getMessage()); |
|
1640 |
sf.initCause(e); |
|
1641 |
throw sf; |
|
1642 |
} catch (OREException e) { |
|
1643 |
// report as service failure |
|
1644 |
ServiceFailure sf = new ServiceFailure("1030", e.getMessage()); |
|
1645 |
sf.initCause(e); |
|
1646 |
throw sf; |
|
1647 |
} catch (URISyntaxException e) { |
|
1648 |
// report as service failure |
|
1649 |
ServiceFailure sf = new ServiceFailure("1030", e.getMessage()); |
|
1650 |
sf.initCause(e); |
|
1651 |
throw sf; |
|
1652 |
} catch (OREParserException e) { |
|
1653 |
// report as service failure |
|
1654 |
ServiceFailure sf = new ServiceFailure("1030", e.getMessage()); |
|
1655 |
sf.initCause(e); |
|
1656 |
throw sf; |
|
1657 |
} catch (ORESerialiserException e) { |
|
1658 |
// report as service failure |
|
1659 |
ServiceFailure sf = new ServiceFailure("1030", e.getMessage()); |
|
1660 |
sf.initCause(e); |
|
1661 |
throw sf; |
|
1662 |
} catch (NoSuchAlgorithmException e) { |
|
1663 |
// report as service failure |
|
1664 |
ServiceFailure sf = new ServiceFailure("1030", e.getMessage()); |
|
1665 |
sf.initCause(e); |
|
1666 |
throw sf; |
|
1636 | 1667 |
} |
1637 | 1668 |
|
1638 | 1669 |
return newIdentifier; |
Also available in: Unified diff
include mn.publish() REST endpoint handling. https://projects.ecoinformatics.org/ecoinfo/issues/6024