Omeka REST API, Spring's RestTemplate and Jackson JSON library (part 2)

A bit of a learning curve, so there is, with regard to converting the retrieved JSON to Java objects (Plain Old Java Objects / POJOs — Spring beans). The building block of Omeka’s JSON documents is the Element. This seems to be based on Dublin Core metadata element sets, but does not seem to be a complete implementation. I still have to get my head around that side of things.

Each element can have up to 7 fields, one of which is a composite element_set containing 3 fields. This is from the Omeka documentation on the Element document:

{
  "id": 1,
  "url": "http://yourdomain.com/api/elements/1",
  "name": "Text",
  "order": 1,
  "description": "Any textual data included in the document",
  "comment": null,
  "element_set": {
    "id": 1,
    "url": "http://yourdomain.com/api/element_sets/1",
    "resource": "element_sets"
  },
}

Each element would appear to match up with Dublin Core elements, such as Title, Subject and Description. For example:

{
  "id": 41,
  "url": "http://192.168.1.17/api/elements/41",
  "name": "Description",
  "resource": "elements"
}

Omeka, it appears, only returns 4 fields for an element – at least in the example I have on my previous post.

If I want to add some text for an element, I need to use an Element Text document, within which is embedded the relevant Element document, as well as an Element Set document, which will almost certainly be a reference to Dublin Core’s element set – though it opens up the possibility for an alternative to Dublin Core metadata. The example below adds the description “Test Description” to an item or collection:

{
   "html": false,
   "text": "Test Description",
   "element_set": {
      "id": 1,
      "url": "http://192.168.1.17/api/element_sets/1",
      "name": "Dublin Core",
      "resource": "element_sets"
   },
   "element": {
      "id": 41,
      "url": "http://192.168.1.17/api/elements/41",
      "name": "Description",
      "resource": "elements"
   }
}

For now I have decided to base my Java classes (used in my Android app) on the fields in retrieved documents using Omeka’s REST API. Here are the classes required for an Element Text (with getters and setters left out to save on reading time):

public class ElementText {
  private boolean isHtml;
  private String text;
  private ElementSet elementSet;
  private Element element;

  // insert getters and setters
}
public class ElementSet {
  private int id;
  private String url;
  private String name;
  private String resource;
  private int order;
  private String description;
  private String comment;

  // insert getters and setters
}
public class Element {
  private int id;
  private String url;
  private String name;
  private String resource;
  private int order;
  private String description;
  private String comment;

  // insert getters and setters
}

Here is the Item class:

public class Item {
  private int id;
  private String url;
  private boolean isPublic;
  private boolean isFeatured;
  private Date added;
  private Date modified;
  Element itemType;
  Element collection;
  Element owner;
  Files files;
  List<Element> tags;
  List<ElementText> elementTexts;

  // insert getters and setters
}

The Files class seems to just contain the number of files and a link to where the files can be retrieved.

public class Files {
    private int count;
    private String url;
}

Now comes the hard part… the parsing from JSON and the creation of the Java objects from the JSON. I hope Spring and Jackson provide some help along the way! Let’s see what happens in part 3.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *