Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the content of an Assignment in Sakai via REST

Tags:

java

rest

sakai

In Sakai, I successfully get a Assignemnt via url: http://xxx/direct/assignment/ASSIGNMENTID.xml. However, in this entity, there is no detailed context (I mean, the teacher's instruction of assignment). There's only a content contentReference element in XML.

<contentReference>/assignment/c/mercury/b0de53c7-09b6-4ba0-964b-cb0a9e5a028d</contentReference>

When I followed this link, I got 404 Error:

Attempted to access an entity URL path (/assignment/c/mercury/b0de53c7-09b6-4ba0-964b-cb0a9e5a028d) for an entity (/assignment/c) that does not exist

I tried Google for API document on Sakai entity, but it turns out to be out dated (some url are wrong on my demo version of Sakai 2.9.3). Then I tried digging into the source code of Sakai. However, what I found is only a file on rsmart server:

  • AssignmentEntityProvider.java :

    https://source.sakaiproject.org/websvn/filedetails.php?repname=sakai-svn&path=%2Fmsub%2Frsmart.com%2Fassignment%2Ftrunk%2Fassignment-tool%2Ftool%2Fsrc%2Fjava%2Forg%2Fsakaiproject%2Fassignment%2Fentityproviders%2FAssignmentEntityProvider.java&peg=131026

In it I found:

        throw new IllegalArgumentException(
                "Must include context and assignmentId in the path ("
                        + view
                        + "): e.g. /assignment/a/{context}/{assignmentId}");

I tried using this URL on my server to get the detailed content(especially the teacher's instruction). Still another 404 Error with the same content as above.

At last, I found that the /assignment/a/ might be a mis-spelling of /assignment/annc/{context}/{assignmentId}. So now I sent:

http://localhost:8080/direct/assignment/annc/mercury/403d28b4-e152-463d-a615-972db97d34d3.xml

Another error pop out:

HTTP Status 500 - EntityEncodingException: Unable to handle output request for format xml for this path (/assignment/annc/mercury/403d28b4-e152-463d-a615-972db97d34d3.xml) for prefix (assignment) for entity (/assignment/annc), request url (/assignment/annc/mercury/403d28b4-e152-463d-a615-972db97d34d3.xml): Failure during internal output encoding of entity: /assignment/annc

Any idea about the url to get the teacher's instruction data via RESTful? Thx.


The XML data of an assignment.

<assignment type='bean' size='29'>
  <access type='bean' size='0'>
  </access>
  <attachments type='collection' size='1'>
    <decoratedattachment type='bean' size='2'>
      <name>LC Circuit (show name).png</name>
      <url>http://localhost:8080/access/content/attachment/mercury/%E4%BD%9C%E4%B8%9A/a11ef34a-0578-433a-ba7e-9c3bad948bf5/1111.png</url>
    </decoratedattachment>
  </attachments>
  <authorLastModified>admin</authorLastModified>
  <authors type='collection' size='0'>
  </authors>
  <closeTime type='bean' size='2'>
    <display>2014-9-12 下午5:00</display>
    <time type='number'>1410512400000</time>
  </closeTime>
  <closeTimeString>2014-9-12 下午5:00</closeTimeString>
  <content/>
  <contentReference>/assignment/c/mercury/b0de53c7-09b6-4ba0-964b-cb0a9e5a028d</contentReference>
  <context>mercury</context>
  <creator>admin</creator>
  <dropDeadTime type='bean' size='2'>
    <display>2014-8-12 下午5:00</display>
    <time type='number'>1407834000000</time>
  </dropDeadTime>
  <dropDeadTimeString>2014-8-12 下午5:00</dropDeadTimeString>
  <dueTime type='bean' size='2'>
    <display>2014-8-12 下午5:00</display>
    <time type='number'>1407834000000</time>
  </dueTime>
  <dueTimeString>2014-8-12 下午5:00</dueTimeString>
  <groups type='collection' size='0'>
  </groups>
  <id>403d28b4-e152-463d-a615-972db97d34d3</id>
  <openTime type='bean' size='2'>
    <display>2014-5-5 下午12:00</display>
    <time type='number'>1399262400000</time>
  </openTime>
  <openTimeString>2014-5-5 下午12:00</openTimeString>
  <position_order type='number'>0</position_order>
  <section></section>
  <status>开始</status>
  <timeCreated type='bean' size='2'>
    <display>2014-5-5 上午11:33</display>
    <time type='number'>1399260782158</time>
  </timeCreated>
  <timeLastModified type='bean' size='2'>
    <display>2014-5-6 上午8:46</display>
    <time type='number'>1399337194163</time>
  </timeLastModified>
  <title>A test assign</title>
  <draft type='boolean'>false</draft>
  <entityReference>/assignment/403d28b4-e152-463d-a615-972db97d34d3</entityReference>
  <entityURL>http://localhost:8080/direct/assignment/403d28b4-e152-463d-a615-972db97d34d3</entityURL>
  <entityId>403d28b4-e152-463d-a615-972db97d34d3</entityId>
  <entityTitle>A test assign</entityTitle>
</assignment>
like image 808
taper Avatar asked May 22 '14 10:05

taper


1 Answers

NOTE: This answer is for Sakai 10. If you have an older version you will need to add some of new features manually that were added in project Keitai (https://jira.sakaiproject.org/browse/SAK-23358).

Using the Sakai 10.x nightly server:

http://nightly2.sakaiproject.org:8081/portal

And a site with the following id:

61a1ebbd-e507-4ca3-8f88-65abca0803d9

This URL will get a list of the assignments in a course:

http://nightly2.sakaiproject.org:8081/direct/assignment/site/61a1ebbd-e507-4ca3-8f88-65abca0803d9.json

(which returns JSON as shown below)

{"entityPrefix": "assignment", "assignment_collection": [
{
  "access": {
  },
  "attachments": [],
  "authorLastModified": "admin",
  "authors": [],
  "closeTime": {
    "display": "Jun 11, 2014 5:00 pm",
    "time": 1402520400000
  },
  "closeTimeString": "Jun 11, 2014 5:00 pm",
  "content": null,
  "contentReference": "\/assignment\/c\/61a1ebbd-e507-4ca3-8f88-65abca0803d9\/1fd9f025-2974-48d1-bcb5-ef47c4e89a30",
  "context": "61a1ebbd-e507-4ca3-8f88-65abca0803d9",
  "creator": "admin",
  "dropDeadTime": {
    "display": "Jun 11, 2014 5:00 pm",
    "time": 1402520400000
  },
  "dropDeadTimeString": "Jun 11, 2014 5:00 pm",
  "dueTime": {
    "display": "Jun 11, 2014 5:00 pm",
    "time": 1402520400000
  },
  "dueTimeString": "Jun 11, 2014 5:00 pm",
  "groups": [],
  "id": "8d96871c-8dcb-4963-b74a-f478dee53142",
  "instructions": "<p>This is an assignment<\/p>",
  "openTime": {
    "display": "Jun 4, 2014 12:00 pm",
    "time": 1401897600000
  },
  "openTimeString": "Jun 4, 2014 12:00 pm",
  "position_order": 0,
  "section": "",
  "status": "Open",
  "timeCreated": {
    "display": "Jun 4, 2014 11:30 pm",
    "time": 1401939011264
  },
  "timeLastModified": {
    "display": "Jun 4, 2014 11:30 pm",
    "time": 1401939011286
  },
  "title": "AZ assignment",
  "draft": false,
  "entityReference": "\/assignment\/8d96871c-8dcb-4963-b74a-f478dee53142",
  "entityURL": "http:\/\/nightly2.sakaiproject.org:8081\/direct\/assignment\/8d96871c-8dcb-4963-b74a-f478dee53142",
  "entityId": "8d96871c-8dcb-4963-b74a-f478dee53142",
  "entityTitle": "AZ assignment"
}
]}

From that you can find the id of an assignment in the list (which is also possible to get other ways) and then return the data of a single assignment like so:

http://nightly2.sakaiproject.org:8081/direct/assignment/item/8d96871c-8dcb-4963-b74a-f478dee53142.json

(which returns JSON as shown below)

{
  "access": {
  },
  "attachments": [],
  "authorLastModified": "admin",
  "authors": [],
  "closeTime": {
    "display": "Jun 11, 2014 5:00 pm",
    "time": 1402520400000
  },
  "closeTimeString": "Jun 11, 2014 5:00 pm",
  "content": null,
  "contentReference": "\/assignment\/c\/61a1ebbd-e507-4ca3-8f88-65abca0803d9\/1fd9f025-2974-48d1-bcb5-ef47c4e89a30",
  "context": "61a1ebbd-e507-4ca3-8f88-65abca0803d9",
  "creator": "admin",
  "dropDeadTime": {
    "display": "Jun 11, 2014 5:00 pm",
    "time": 1402520400000
  },
  "dropDeadTimeString": "Jun 11, 2014 5:00 pm",
  "dueTime": {
    "display": "Jun 11, 2014 5:00 pm",
    "time": 1402520400000
  },
  "dueTimeString": "Jun 11, 2014 5:00 pm",
  "groups": [],
  "id": "8d96871c-8dcb-4963-b74a-f478dee53142",
  "instructions": "<p>This is an assignment<\/p>",
  "openTime": {
    "display": "Jun 4, 2014 12:00 pm",
    "time": 1401897600000
  },
  "openTimeString": "Jun 4, 2014 12:00 pm",
  "position_order": 0,
  "section": "",
  "status": "Open",
  "timeCreated": {
    "display": "Jun 4, 2014 11:30 pm",
    "time": 1401939011264
  },
  "timeLastModified": {
    "display": "Jun 4, 2014 11:30 pm",
    "time": 1401939011286
  },
  "title": "AZ assignment",
  "draft": false,
  "entityReference": "\/assignment\/8d96871c-8dcb-4963-b74a-f478dee53142",
  "entityURL": "http:\/\/nightly2.sakaiproject.org:8081\/direct\/assignment\/8d96871c-8dcb-4963-b74a-f478dee53142",
  "entityId": "8d96871c-8dcb-4963-b74a-f478dee53142",
  "entityTitle": "AZ assignment"
}
like image 114
Aaron Zeckoski Avatar answered Oct 21 '22 17:10

Aaron Zeckoski