Revision 6067
Added by rnahf almost 14 years ago
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java | ||
---|---|---|
32 | 32 |
import javax.servlet.ServletContext; |
33 | 33 |
import javax.servlet.http.HttpServletRequest; |
34 | 34 |
import javax.servlet.http.HttpServletResponse; |
35 |
|
|
36 |
import java.security.NoSuchAlgorithmException; |
|
37 |
import java.sql.SQLException; |
|
35 | 38 |
import java.text.DateFormat; |
36 | 39 |
import java.text.ParseException; |
37 | 40 |
import java.text.ParsePosition; |
... | ... | |
64 | 67 |
import org.jibx.runtime.IUnmarshallingContext; |
65 | 68 |
import org.jibx.runtime.JiBXException; |
66 | 69 |
|
70 |
import edu.ucsb.nceas.metacat.AccessionNumberException; |
|
67 | 71 |
import edu.ucsb.nceas.metacat.DBUtil; |
68 | 72 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
69 | 73 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException; |
... | ... | |
1028 | 1032 |
* that don't already have it. https://trac.dataone.org/ticket/591 |
1029 | 1033 |
* |
1030 | 1034 |
* called with POST meta/?op=generatemissingsystemmetadata |
1035 |
* @throws SQLException |
|
1036 |
* @throws AccessionNumberException |
|
1037 |
* @throws NoSuchAlgorithmException |
|
1038 |
* @throws InvalidRequest |
|
1039 |
* @throws NotImplemented |
|
1040 |
* @throws NotFound |
|
1041 |
* @throws NotAuthorized |
|
1042 |
* @throws InvalidToken |
|
1043 |
* @throws PropertyNotFoundException |
|
1044 |
* @throws McdbDocNotFoundException |
|
1045 |
* @throws ServiceFailure |
|
1031 | 1046 |
*/ |
1032 |
private void generateMissingSystemMetadata() |
|
1047 |
private void generateMissingSystemMetadata() throws ServiceFailure, McdbDocNotFoundException, PropertyNotFoundException, |
|
1048 |
InvalidToken, NotAuthorized, NotFound, NotImplemented, InvalidRequest, NoSuchAlgorithmException, |
|
1049 |
AccessionNumberException, SQLException |
|
1033 | 1050 |
{ |
1034 | 1051 |
AuthToken token = new AuthToken(sessionId); |
1035 | 1052 |
CrudService.getInstance().generateMissingSystemMetadata(token); |
... | ... | |
1599 | 1616 |
/** |
1600 | 1617 |
* Earthgrid API > Put Service >Put Function : calls MetacatHandler > handleInsertOrUpdateAction |
1601 | 1618 |
* |
1602 |
* @param guid ID of data object to be inserted or updated |
|
1619 |
* @param guid - ID of data object to be inserted or updated. If action is update, the pid |
|
1620 |
* is the existing pid. If insert, the pid is the new one |
|
1603 | 1621 |
* @throws IOException |
1604 | 1622 |
*/ |
1605 |
private void putObject(String guid, String action) {
|
|
1606 |
System.out.println("ResourceHandler: putObject with guid " + guid);
|
|
1607 |
logMetacat.debug("Entering putObject: " + guid + "/" + action);
|
|
1623 |
private void putObject(String pid, String action) {
|
|
1624 |
System.out.println("ResourceHandler: putObject with pid " + pid);
|
|
1625 |
logMetacat.debug("Entering putObject: " + pid + "/" + action);
|
|
1608 | 1626 |
OutputStream out = null; |
1609 | 1627 |
try { |
1610 | 1628 |
out = response.getOutputStream(); |
... | ... | |
1718 | 1736 |
|
1719 | 1737 |
// Check if the objectId exists |
1720 | 1738 |
IdentifierManager im = IdentifierManager.getInstance(); |
1721 |
if (im.identifierExists(guid)) {
|
|
1722 |
throw new IdentifierNotUnique("1000", "Identifier is already in use: " + guid);
|
|
1739 |
if (im.identifierExists(pid)) {
|
|
1740 |
throw new IdentifierNotUnique("1000", "Identifier is already in use: " + pid);
|
|
1723 | 1741 |
} |
1724 | 1742 |
|
1725 | 1743 |
logMetacat.debug("Commence creation..."); |
1726 | 1744 |
IBindingFactory bfact = |
1727 | 1745 |
BindingDirectory.getFactory(SystemMetadata.class); |
1728 | 1746 |
IUnmarshallingContext uctx = bfact.createUnmarshallingContext(); |
1729 |
SystemMetadata m = (SystemMetadata) uctx.unmarshalDocument(sysmeta, null);
|
|
1747 |
SystemMetadata smd = (SystemMetadata) uctx.unmarshalDocument(sysmeta, null);
|
|
1730 | 1748 |
|
1731 | 1749 |
CrudService cs = CrudService.getInstance(); |
1732 | 1750 |
AuthToken token = new AuthToken(sessionId); |
1733 | 1751 |
cs.setParamsFromRequest(request); |
1734 | 1752 |
Identifier id = new Identifier(); |
1735 |
id.setValue(guid);
|
|
1736 |
System.out.println("creating object with guid " + id.getValue());
|
|
1737 |
Identifier rId = cs.create(token, id, object, m);
|
|
1753 |
id.setValue(pid);
|
|
1754 |
System.out.println("creating object with pid " + id.getValue());
|
|
1755 |
Identifier rId = cs.create(token, id, object, smd);
|
|
1738 | 1756 |
serializeServiceType(Identifier.class, rId, out); |
1739 | 1757 |
|
1740 | 1758 |
} else if (action.equals(FUNCTION_NAME_UPDATE)) { //handle updates |
1759 |
|
|
1760 |
// Check if the objectId exists |
|
1741 | 1761 |
IdentifierManager im = IdentifierManager.getInstance(); |
1762 |
if (!im.identifierExists(pid)) { |
|
1763 |
throw new NotFound("1280", "The pid you are trying to update does not exist: " + pid); |
|
1764 |
} |
|
1765 |
// check that the newPid parameter was provided and it doesn't exist |
|
1766 |
if(multipartparams.get("newPid") == null) |
|
1767 |
throw new InvalidRequest("1202", "'newPid' must be contained in the request parameters."); |
|
1768 |
String newPidString = multipartparams.get("newPid").get(0); |
|
1769 |
if (im.identifierExists(newPidString)) |
|
1770 |
throw new IdentifierNotUnique("1220", "Identifier is already in use: " + newPidString); |
|
1771 |
|
|
1772 |
|
|
1773 |
Identifier newPid = new Identifier(); |
|
1774 |
Identifier obsoletedPid = new Identifier(); |
|
1775 |
newPid.setValue(newPidString); |
|
1776 |
obsoletedPid.setValue(pid); |
|
1777 |
|
|
1778 |
|
|
1742 | 1779 |
CrudService cs = CrudService.getInstance(); |
1743 |
Identifier obsoletedGuid = new Identifier(); |
|
1744 |
Identifier id = new Identifier(); |
|
1745 |
id.setValue(guid); |
|
1746 | 1780 |
AuthToken token = new AuthToken(sessionId); |
1747 |
|
|
1748 |
//do some checks |
|
1749 |
if(multipartparams.get("obsoletedGuid") == null) |
|
1750 |
{ |
|
1751 |
throw new InvalidRequest("1202", "obsoletedGuid must be contained in the request parameters."); |
|
1752 |
} |
|
1753 |
//get the obsoletedGuid |
|
1754 |
String obsGuidS = multipartparams.get("obsoletedGuid").get(0); |
|
1755 |
obsoletedGuid.setValue(obsGuidS); |
|
1756 |
|
|
1757 |
if (!im.identifierExists(obsoletedGuid.getValue())) |
|
1758 |
{ |
|
1759 |
throw new InvalidRequest("1202", "The guid you are trying to update does not exist."); |
|
1760 |
} |
|
1761 |
|
|
1762 |
|
|
1781 |
|
|
1763 | 1782 |
logMetacat.debug("Commence update..."); |
1764 | 1783 |
|
1765 | 1784 |
//get the systemmetadata |
1766 | 1785 |
IBindingFactory bfact = |
1767 |
BindingDirectory.getFactory(SystemMetadata.class); |
|
1768 |
IUnmarshallingContext uctx = bfact.createUnmarshallingContext(); |
|
1769 |
SystemMetadata m = (SystemMetadata) uctx.unmarshalDocument(sysmeta, null); |
|
1770 |
|
|
1771 |
//do the update |
|
1772 |
try |
|
1773 |
{ |
|
1774 |
cs.setParamsFromRequest(request); |
|
1775 |
Identifier rId = cs.update(token, id, object, obsoletedGuid, m); |
|
1776 |
serializeServiceType(Identifier.class, rId, out); |
|
1777 |
} |
|
1778 |
catch(NotFound e) |
|
1779 |
{ |
|
1780 |
throw new InvalidRequest("1202", "The guid you are trying to update does not exist."); |
|
1781 |
} |
|
1782 |
|
|
1786 |
BindingDirectory.getFactory(SystemMetadata.class); |
|
1787 |
IUnmarshallingContext uctx = bfact.createUnmarshallingContext(); |
|
1788 |
SystemMetadata smd = (SystemMetadata) uctx.unmarshalDocument(sysmeta, null); |
|
1789 |
|
|
1790 |
cs.setParamsFromRequest(request); |
|
1791 |
Identifier rId = cs.update(token, newPid, object, obsoletedPid, smd); |
|
1792 |
serializeServiceType(Identifier.class, rId, out); |
|
1783 | 1793 |
} else { |
1784 | 1794 |
throw new InvalidRequest("1000", "Operation must be create or update."); |
1785 | 1795 |
} |
... | ... | |
1796 | 1806 |
} catch (ServiceFailure e) { |
1797 | 1807 |
response.setStatus(500); |
1798 | 1808 |
serializeException(e, out); |
1809 |
} catch (NotFound e) { |
|
1810 |
response.setStatus(500); |
|
1811 |
serializeException(e, out); |
|
1799 | 1812 |
} catch (IdentifierNotUnique e) { |
1800 | 1813 |
response.setStatus(500); |
1801 | 1814 |
serializeException(e, out); |
Also available in: Unified diff
committing changes related to the new restservice update specification (newPid vs. obsoletedGuid)