Revision 9600
Added by Jing Tao over 8 years ago
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java | ||
---|---|---|
39 | 39 |
import javax.servlet.http.HttpServletRequest; |
40 | 40 |
|
41 | 41 |
import org.apache.commons.beanutils.BeanUtils; |
42 |
import org.apache.commons.io.IOUtils; |
|
42 | 43 |
import org.apache.log4j.Logger; |
43 | 44 |
import org.dataone.client.v2.CNode; |
44 | 45 |
import org.dataone.client.v2.MNode; |
... | ... | |
1804 | 1805 |
throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, |
1805 | 1806 |
UnsupportedType, InsufficientResources, InvalidSystemMetadata, |
1806 | 1807 |
NotImplemented, InvalidRequest { |
1807 |
|
|
1808 |
// verify the pid is valid format |
|
1808 |
|
|
1809 |
try { |
|
1810 |
// verify the pid is valid format |
|
1809 | 1811 |
if (!isValidIdentifier(pid)) { |
1810 | 1812 |
throw new InvalidRequest("4891", "The provided identifier is invalid."); |
1811 | 1813 |
} |
... | ... | |
1877 | 1879 |
logMetacat.debug("Unlocked identifier " + pid.getValue()); |
1878 | 1880 |
} |
1879 | 1881 |
} |
1880 |
|
|
1881 |
return pid; |
|
1882 |
} finally { |
|
1883 |
IOUtils.closeQuietly(object); |
|
1884 |
} |
|
1885 |
return pid; |
|
1882 | 1886 |
|
1883 | 1887 |
} |
1884 | 1888 |
|
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java | ||
---|---|---|
309 | 309 |
throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, |
310 | 310 |
UnsupportedType, InsufficientResources, NotFound, |
311 | 311 |
InvalidSystemMetadata, NotImplemented, InvalidRequest { |
312 |
|
|
312 |
try { |
|
313 | 313 |
if(isReadOnlyMode()) { |
314 | 314 |
throw new ServiceFailure("1310", ReadOnlyChecker.DATAONEERROR); |
315 | 315 |
} |
... | ... | |
531 | 531 |
throw new NotAuthorized("1200", "The provided identity does not have " + "permission to UPDATE the object identified by " + pid.getValue() |
532 | 532 |
+ " on the Member Node."); |
533 | 533 |
} |
534 |
|
|
534 |
} finally { |
|
535 |
IOUtils.closeQuietly(object); |
|
536 |
} |
|
535 | 537 |
return newPid; |
536 | 538 |
} |
537 | 539 |
|
538 | 540 |
public Identifier create(Session session, Identifier pid, InputStream object, SystemMetadata sysmeta) throws InvalidToken, ServiceFailure, NotAuthorized, |
539 | 541 |
IdentifierNotUnique, UnsupportedType, InsufficientResources, InvalidSystemMetadata, NotImplemented, InvalidRequest { |
540 |
|
|
542 |
Identifier resultPid = null; |
|
543 |
try { |
|
541 | 544 |
if(isReadOnlyMode()) { |
542 | 545 |
throw new ServiceFailure("1190", ReadOnlyChecker.DATAONEERROR); |
543 | 546 |
} |
... | ... | |
613 | 616 |
} |
614 | 617 |
|
615 | 618 |
// call the shared impl |
616 |
Identifier resultPid = super.create(session, pid, object, sysmeta);
|
|
619 |
resultPid = super.create(session, pid, object, sysmeta); |
|
617 | 620 |
|
618 | 621 |
// attempt to register the identifier - it checks if it is a doi |
619 | 622 |
try { |
... | ... | |
623 | 626 |
sf.initCause(e); |
624 | 627 |
throw sf; |
625 | 628 |
} |
626 |
|
|
629 |
} finally { |
|
630 |
IOUtils.closeQuietly(object); |
|
631 |
} |
|
627 | 632 |
// return |
628 | 633 |
return resultPid ; |
629 | 634 |
} |
src/edu/ucsb/nceas/metacat/dataone/v1/CNodeService.java | ||
---|---|---|
31 | 31 |
|
32 | 32 |
import javax.servlet.http.HttpServletRequest; |
33 | 33 |
|
34 |
import org.apache.commons.io.IOUtils; |
|
34 | 35 |
import org.apache.log4j.Logger; |
35 | 36 |
import org.dataone.service.cn.v1.CNAuthorization; |
36 | 37 |
import org.dataone.service.cn.v1.CNCore; |
... | ... | |
435 | 436 |
try { |
436 | 437 |
v2Sysmeta = TypeFactory.convertTypeFromType(sysmeta, org.dataone.service.types.v2.SystemMetadata.class); |
437 | 438 |
} catch (Exception e) { |
439 |
IOUtils.closeQuietly(object); |
|
438 | 440 |
// report as service failure |
439 | 441 |
ServiceFailure sf = new ServiceFailure("1030", e.getMessage()); |
440 | 442 |
sf.initCause(e); |
src/edu/ucsb/nceas/metacat/dataone/v1/MNodeService.java | ||
---|---|---|
30 | 30 |
|
31 | 31 |
import javax.servlet.http.HttpServletRequest; |
32 | 32 |
|
33 |
import org.apache.commons.io.IOUtils; |
|
33 | 34 |
import org.apache.log4j.Logger; |
34 | 35 |
import org.dataone.service.exceptions.IdentifierNotUnique; |
35 | 36 |
import org.dataone.service.exceptions.InsufficientResources; |
... | ... | |
172 | 173 |
try { |
173 | 174 |
v2Sysmeta = TypeFactory.convertTypeFromType(sysmeta, org.dataone.service.types.v2.SystemMetadata.class); |
174 | 175 |
} catch (Exception e) { |
176 |
IOUtils.closeQuietly(object); |
|
175 | 177 |
// report as service failure |
176 | 178 |
ServiceFailure sf = new ServiceFailure("1190", e.getMessage()); |
177 | 179 |
sf.initCause(e); |
... | ... | |
237 | 239 |
//check if the pid exists and not a sid |
238 | 240 |
String serviceFailure = "1310"; |
239 | 241 |
String notFound = "1280"; |
240 |
impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object specified by "+pid.getValue()+" couldn't be identified if it exists", notFound, |
|
242 |
try { |
|
243 |
impl.checkV1SystemMetaPidExist(pid, serviceFailure, "The object specified by "+pid.getValue()+" couldn't be identified if it exists", notFound, |
|
241 | 244 |
"The object specified by "+pid.getValue()+" does not exist at this node."); |
245 |
} catch (Exception e) { |
|
246 |
IOUtils.closeQuietly(object); |
|
247 |
throw e; |
|
248 |
} |
|
242 | 249 |
//convert sysmeta to newer version |
243 | 250 |
org.dataone.service.types.v2.SystemMetadata v2Sysmeta = null; |
244 | 251 |
try { |
245 | 252 |
v2Sysmeta = TypeFactory.convertTypeFromType(sysmeta, org.dataone.service.types.v2.SystemMetadata.class); |
246 | 253 |
} catch (Exception e) { |
254 |
IOUtils.closeQuietly(object); |
|
247 | 255 |
// report as service failure |
248 | 256 |
ServiceFailure sf = new ServiceFailure("1030", e.getMessage()); |
249 | 257 |
sf.initCause(e); |
Also available in: Unified diff
Close the input stream on the create/update method when the code aborts.