Dear Holly,
We have had success updating the bitstream policies at the bitstream endpoint
rather than the policy endpoint. You can just embed the policy JSON in the
bistream JSON as for example:
{"id":235,"name":"dissertation_0.pdf.txt","handle":null,"type":"bitstream","link":"/rest/bitstreams/235","expand":["parent","policies","all"],"bundleName":"TEXT","description":"ocr_text","format":"Text","mimeType":"text/plain","sizeBytes":43,"parentObject":null,"retrieveLink":"/bitstreams/235/retrieve","checkSum":{"value":"2b0144d81300a4a8c4f2a2a891280a84","checkSumAlgorithm":"MD5"},"sequenceId":-1,"policies":[{"action":"READ","groupId":"5","rpType":"TYPE_CUSTOM"}]}
That worked on my localhost at the /rest/bitstreams/{bitstream id} endpoint.
Best of luck,
James
From: <[email protected]> on behalf of Holly Becker
<[email protected]>
Date: Thursday, August 4, 2016 at 3:58 PM
To: DSpace Technical Support <[email protected]>
Subject: [dspace-tech] Re: Setting a ResourcePolicy via REST API?
Hi,
That endpoint gives me item information, but doesn't include anything about
bitstreams or policies. Can you clarify your suggestion?
Thanks,
-Holly
On Tuesday, July 12, 2016 at 7:38:40 AM UTC-7, Evgeni Dimitrov wrote:
I think with curl you should do something like this:
curl -X GET -H "Content-Type: application/json" -H "rest-dspace-token:
d4020530-ce01-471d-a474-5fb0cea04661"
http://localhost:8080/rest/items/2<https://urldefense.proofpoint.com/v2/url?u=http-3A__localhost-3A8080_rest_items_2&d=CwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=V6tqD8ofDtKmseXi7TXu4l-_PxkyYWnoGE_B1XhiAjg&m=R7MnVTz45Yj3HcZsupmlscWHK4r_cRo7g6AGGpTpaAQ&s=9vobBvg0hbEXi6DatV7LimPpU3NQvf8QgUy1E3LCBDw&e=>
On Tuesday, July 12, 2016 at 1:46:18 AM UTC+3, Holly Becker wrote:
Hello all,
I'm trying to post bitstream policies to the REST API, and having trouble
finding what the correct format for the ResourcePolicy is. The documentation
[1] says a ResourcePolicy is
[{"id":317127,"action":"READ","epersonId":-1,"groupId":0,"resourceId":47166,"resourceType":"bitstream","rpDescription":null,"rpName":null,"rpType":"TYPE_INHERITED","startDate":null,"endDate":null}]
This looks like the policies returned by /rest/bitstreams/?expand=policies
However, when I post that policy or policies that look similar I get a 500
server error [3] on a local install of DSpace 5.
On
demo.dspace.org<https://urldefense.proofpoint.com/v2/url?u=http-3A__demo.dspace.org&d=CwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=V6tqD8ofDtKmseXi7TXu4l-_PxkyYWnoGE_B1XhiAjg&m=R7MnVTz45Yj3HcZsupmlscWHK4r_cRo7g6AGGpTpaAQ&s=6R3Tv8ApNXIZVvKHkIGQIw6s1QnaszzdBBwG0x02pQg&e=>
none of the bitstreams have policies, even when I add one in the GUI, and I
get a 500 when querying
https://demo.dspace.org/rest/bitstreams/?expand=policies<https://urldefense.proofpoint.com/v2/url?u=https-3A__demo.dspace.org_rest_bitstreams_-3Fexpand-3Dpolicies&d=CwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=V6tqD8ofDtKmseXi7TXu4l-_PxkyYWnoGE_B1XhiAjg&m=R7MnVTz45Yj3HcZsupmlscWHK4r_cRo7g6AGGpTpaAQ&s=BGrczgQlQ1Ncj3xdqPHFVuhFLQg2C5Z4Xx3b8yIQHec&e=>
When posting a policy, I get different behavior on
demo.dspace.org<https://urldefense.proofpoint.com/v2/url?u=http-3A__demo.dspace.org&d=CwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=V6tqD8ofDtKmseXi7TXu4l-_PxkyYWnoGE_B1XhiAjg&m=R7MnVTz45Yj3HcZsupmlscWHK4r_cRo7g6AGGpTpaAQ&s=6R3Tv8ApNXIZVvKHkIGQIw6s1QnaszzdBBwG0x02pQg&e=>.
It gives a 400 error, but the same exception. [2]
Can someone point me towards more detailed documentation, or provide an
explanation of what a ResourcePolicy is supposed to look like? Is there a
better or different way to set bitstream policies through the REST API or
SWORD2 API?
Thanks,
-Holly Becker
Archivematica developer
[1]
https://wiki.duraspace.org/display/DSDOC5x/REST+API<https://urldefense.proofpoint.com/v2/url?u=https-3A__wiki.duraspace.org_display_DSDOC5x_REST-2BAPI&d=CwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=V6tqD8ofDtKmseXi7TXu4l-_PxkyYWnoGE_B1XhiAjg&m=R7MnVTz45Yj3HcZsupmlscWHK4r_cRo7g6AGGpTpaAQ&s=3hWHPprz-f49VceReJ9jxRe9PEBUeoLGobymL8mnA3Q&e=>
[2] To reproduce
curl -X POST
https://demo.dspace.org/rest/bitstreams/ea41e143-0b2c-447a-a46d-681282c6ff9a/policy<https://urldefense.proofpoint.com/v2/url?u=https-3A__demo.dspace.org_rest_bitstreams_ea41e143-2D0b2c-2D447a-2Da46d-2D681282c6ff9a_policy&d=CwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=V6tqD8ofDtKmseXi7TXu4l-_PxkyYWnoGE_B1XhiAjg&m=R7MnVTz45Yj3HcZsupmlscWHK4r_cRo7g6AGGpTpaAQ&s=zE1Oj1abHKcfLl2yxhLl3i17NC1n2xYM7YlG0geBdc4&e=>
--data
'[{"id":317127,"action":"READ","epersonId":-1,"groupId":0,"resourceId":47166,"resourceType":"bitstream","rpDescription":null,"rpName":null,"rpType":"TYPE_INHERITED","startDate":null,"endDate":null}]'
-u '[email protected]:dspace' -H 'Content-type: application/json' -k
Response:
Can not deserialize instance of org.dspace.rest.common.ResourcePolicy out of
START_ARRAY token
at [Source:
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@43a44ac9;
line: 1, column: 1]
Or (in Python2, requires 'requests' library):
import requests
url =
'https://demo.dspace.org/rest/bitstreams/ea41e143-0b2c-447a-a46d-681282c6ff9a/policy<https://urldefense.proofpoint.com/v2/url?u=https-3A__demo.dspace.org_rest_bitstreams_ea41e143-2D0b2c-2D447a-2Da46d-2D681282c6ff9a_policy&d=CwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=V6tqD8ofDtKmseXi7TXu4l-_PxkyYWnoGE_B1XhiAjg&m=R7MnVTz45Yj3HcZsupmlscWHK4r_cRo7g6AGGpTpaAQ&s=zE1Oj1abHKcfLl2yxhLl3i17NC1n2xYM7YlG0geBdc4&e=>'
json_body =
[{"id":317127,"action":"READ","epersonId":-1,"groupId":0,"resourceId":47166,"resourceType":"bitstream","rpDescription":None,"rpName":None,"rpType":"TYPE_INHERITED","startDate":None,"endDate":None}]
auth = ('[email protected]', 'dspace')
response = requests.post(url, json=json_body, auth=auth, verify=False)
print response # <Response [400]>
print response.content # 'Can not deserialize instance of
org.dspace.rest.common.ResourcePolicy out of START_ARRAY token\n at [Source:
org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@32229b7e;
line: 1, column: 1]'
[3] Traceback from DSpace 5 server (catalina.out)
Jul 11, 2016 6:13:58 PM com.sun.jersey.spi.container.ContainerResponse
mapMappableContainerException
SEVERE: The exception contained within MappableContainerException could not be
mapped to a response, re-throwing to the HTTP container
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of
org.dspace.rest.common.ResourcePolicy out of START_ARRAY token
at [Source: org.apache.catalina.connector.CoyoteInputStream@4c4b6dda; line: 1,
column: 1]
at
org.codehaus.jackson.map.JsonMappingException.from(JsonMappingException.java:163)
at
org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:219)
at
org.codehaus.jackson.map.deser.StdDeserializationContext.mappingException(StdDeserializationContext.java:212)
at
org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromArray(BeanDeserializer.java:869)
at
org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:597)
at
org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2695)
at
org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1308)
at
org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
at
com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy.readFrom(JacksonProviderProxy.java:139)
at
com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:490)
at
com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
at
com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:86)
at
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)
at
com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:203)
at
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at
com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
at
com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
--
You received this message because you are subscribed to the Google Groups
"DSpace Technical Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to
[email protected]<mailto:[email protected]>.
To post to this group, send email to
[email protected]<mailto:[email protected]>.
Visit this group at
https://groups.google.com/group/dspace-tech<https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_group_dspace-2Dtech&d=CwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=V6tqD8ofDtKmseXi7TXu4l-_PxkyYWnoGE_B1XhiAjg&m=R7MnVTz45Yj3HcZsupmlscWHK4r_cRo7g6AGGpTpaAQ&s=NBBnQQPgAbDF6EhCLTOI_-i4gRpkmUeIkhdlVYSfLZQ&e=>.
For more options, visit
https://groups.google.com/d/optout<https://urldefense.proofpoint.com/v2/url?u=https-3A__groups.google.com_d_optout&d=CwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=V6tqD8ofDtKmseXi7TXu4l-_PxkyYWnoGE_B1XhiAjg&m=R7MnVTz45Yj3HcZsupmlscWHK4r_cRo7g6AGGpTpaAQ&s=2rVXS6n9H4jodf_9aMVYVoDlDVBcwEakPWO528oYrjo&e=>.
--
You received this message because you are subscribed to the Google Groups
"DSpace Technical Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/dspace-tech.
For more options, visit https://groups.google.com/d/optout.