Re: [dspace-tech] Re: Setting a ResourcePolicy via REST API?

2016-08-08 Thread Creel, James Silas
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:  on behalf of Holly Becker 

Date: Thursday, August 4, 2016 at 3:58 PM
To: DSpace Technical Support 
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=V6tqD

[dspace-tech] Re: Setting a ResourcePolicy via REST API?

2016-08-06 Thread Evgeni Dimitrov
Well, sorry for the "noise" :)

For me (with DSpace 5.4) it looks like this:

curl -X GET  http://localhost:8080/rest/bitstreams/303399

Good luck.

On Friday, August 5, 2016 at 8:35:53 PM UTC+3, Holly Becker wrote:
>
> Thanks for the clarification.
>
> The bitstream ID I got from checking 
> https://demo.dspace.org/rest/bitstreams/ and looking at the "link" and 
> "uuid" properties of the bitstreams returned.  
> https://demo.dspace.org/rest/bitstreams/ea41e143-0b2c-447a-a46d-681282c6ff9a 
> returns bitstream information, so I don't think that's the problem.
>
> What I'm looking for is a description of what a POSTed ResourcePolicy 
> looks like, or otherwise how to set policies on a bitstream through the 
> REST API (or SWORD2 API).
>
> Cheers,
> -Holly
>
> On Friday, August 5, 2016 at 2:37:55 AM UTC-7, Evgeni Dimitrov wrote:
>>
>> I mean that the documentation says
>>
>> POST /bitstreams/{bitstream id}/policy
>>
>> and in what you have
>>
>> curl -X POST 
>> https://demo.dspace.org/rest/bitstreams/ea41e143-0b2c-447a-a46d-681282c6ff9a/policy
>>  
>>
>> the "ea41e143-0b2c-447a-a46d-681282c6ff9a" looks more like 
>> "rest-dspace-token" than "bitstream id"
>>
>>
>> On Thursday, August 4, 2016 at 11:58:58 PM UTC+3, Holly Becker wrote:
>>>
>>> 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


 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 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 When posting 
> a policy, I get different behavior on demo.dspace.org.  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
>
> [2] To reproduce
> curl -X POST 
> https://demo.dspace.org/rest/bitstreams/ea41e143-0b2c-447a-a46d-681282c6ff9a/policy
>  
> --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 'dspacedemo+ad...@gmail.com: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
> '
> 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 = ('dspacede...@gmail.com', 'dspace')
> response = requests.post(url, json=json_body, auth=auth, verify=False)
> print response  # 
> 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.containe

[dspace-tech] Re: Setting a ResourcePolicy via REST API?

2016-08-05 Thread Holly Becker
Thanks for the clarification.

The bitstream ID I got from checking 
https://demo.dspace.org/rest/bitstreams/ and looking at the "link" and 
"uuid" properties of the bitstreams returned.  
https://demo.dspace.org/rest/bitstreams/ea41e143-0b2c-447a-a46d-681282c6ff9a 
returns bitstream information, so I don't think that's the problem.

What I'm looking for is a description of what a POSTed ResourcePolicy looks 
like, or otherwise how to set policies on a bitstream through the REST API 
(or SWORD2 API).

Cheers,
-Holly

On Friday, August 5, 2016 at 2:37:55 AM UTC-7, Evgeni Dimitrov wrote:
>
> I mean that the documentation says
>
> POST /bitstreams/{bitstream id}/policy
>
> and in what you have
>
> curl -X POST 
> https://demo.dspace.org/rest/bitstreams/ea41e143-0b2c-447a-a46d-681282c6ff9a/policy
>  
>
> the "ea41e143-0b2c-447a-a46d-681282c6ff9a" looks more like 
> "rest-dspace-token" than "bitstream id"
>
>
> On Thursday, August 4, 2016 at 11:58:58 PM UTC+3, Holly Becker wrote:
>>
>> 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
>>>
>>>
>>> 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 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 When posting 
 a policy, I get different behavior on demo.dspace.org.  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

 [2] To reproduce
 curl -X POST 
 https://demo.dspace.org/rest/bitstreams/ea41e143-0b2c-447a-a46d-681282c6ff9a/policy
  
 --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 'dspacedemo+ad...@gmail.com: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
 '
 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 = ('dspacede...@gmail.com', 'dspace')
 response = requests.post(url, json=json_body, auth=auth, verify=False)
 print response  # 
 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.apac

[dspace-tech] Re: Setting a ResourcePolicy via REST API?

2016-08-05 Thread Evgeni Dimitrov
I mean that the documentation says

POST /bitstreams/{bitstream id}/policy

and in what you have

curl -X POST 
https://demo.dspace.org/rest/bitstreams/ea41e143-0b2c-447a-a46d-681282c6ff9a/policy
 


the "ea41e143-0b2c-447a-a46d-681282c6ff9a" looks more like 
"rest-dspace-token" than "bitstream id"


On Thursday, August 4, 2016 at 11:58:58 PM UTC+3, Holly Becker wrote:
>
> 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
>>
>>
>> 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 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 When posting a 
>>> policy, I get different behavior on demo.dspace.org.  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
>>>
>>> [2] To reproduce
>>> curl -X POST 
>>> https://demo.dspace.org/rest/bitstreams/ea41e143-0b2c-447a-a46d-681282c6ff9a/policy
>>>  
>>> --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 'dspacedemo+ad...@gmail.com: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
>>> '
>>> 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 = ('dspacede...@gmail.com', 'dspace')
>>> response = requests.post(url, json=json_body, auth=auth, verify=False)
>>> print response  # 
>>> 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.ObjectMap

[dspace-tech] Re: Setting a ResourcePolicy via REST API?

2016-08-04 Thread Holly Becker
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
>
>
> 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 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 When posting a 
>> policy, I get different behavior on demo.dspace.org.  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
>>
>> [2] To reproduce
>> curl -X POST 
>> https://demo.dspace.org/rest/bitstreams/ea41e143-0b2c-447a-a46d-681282c6ff9a/policy
>>  
>> --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 'dspacedemo+ad...@gmail.com: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
>> '
>> 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 = ('dspacede...@gmail.com', 'dspace')
>> response = requests.post(url, json=json_body, auth=auth, verify=False)
>> print response  # 
>> 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.je

[dspace-tech] Re: Setting a ResourcePolicy via REST API?

2016-07-12 Thread Evgeni Dimitrov
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


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 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 When posting a 
> policy, I get different behavior on demo.dspace.org.  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
>
> [2] To reproduce
> curl -X POST 
> https://demo.dspace.org/rest/bitstreams/ea41e143-0b2c-447a-a46d-681282c6ff9a/policy
>  
> --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 'dspacedemo+ad...@gmail.com: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
> '
> 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 = ('dspacede...@gmail.com ', 'dspace')
> response = requests.post(url, json=json_body, auth=auth, verify=False)
> print response  # 
> 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.AbstractR