Java ServiceAPI and additional fields

Previous posts have described the Java client and file upload.  This post details how to fetch the value of additional fields.

Field Names

As described elsewhere the name to use to fetch an additional field is its search clause name, as seen in the client.

adf.PNG

Get field values as text

Once you know the correct names for your fields you need to fetch them.  A full sample is provided in the samples repo, in short you need to:

  1. request the fields by name
  2. request string values be returned
  3. parse the string value as necessary.

Example

See the samples repo for the full sample. 

Records request = new Records();
request.q = "number:rec_222";
// tell the search request to return both string and actual values for the fields and properties
request.setPropertyValue(PropertyType.Both);
request.setStringDisplayType(StringDisplayType.WebService);     

request.Properties = makePropertyList("RoadSurface", "DateOfIssue", "PoliceOfficer");

RecordsResponse response = client.get(request);
Record rec = response.Results.get(0);

ITrimProperty dateOfIssue = rec.Fields.get("DateOfIssue");

SimpleDateFormat parser = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss zzz");
Date date = parser.parse(dateOfIssue.getStringValue());
System.out.println(date);

Java ServiceAPI client

Prior to Content Manager 9.0 there was no supported Java client for the ServiceAPI, although I did publish an experimental project.  As of 9.0 we are able to use the ServiceStack Java client.  This video demonstrates that client. 

The code

The sample project I created in the video is on our samples site. Beware, in the video I omit the call to 'setAlwaysSendBasicAuthHeaders', you should always call this when using basic authentication.

Java and the ServiceAPI

Intro

On a sunny Friday afternoon my mind turns away from deadlines and release dates and toward pet projects.  My impression has been that we do not have many Java developers in the Records Manager world, at least I don't hear from them.  Maybe that is just because they have given up long ago.  Given the seeming lack of interest we have never put a lot of time into supporting Java developers, the question for me became, how can we do something that is more than nothing without the 'gung ho' of an official toolkit?

Open Source

As of last night our unofficial Codeplex site contains a Java toolkit for consuming the ServiceAPI.  It is not complete missing some non-core bits (such as the ability to fetch messages, object and property definitions etc).  It is also very much a part time project by a part time Java programmer (me).  If you happen to be an expert Java programmer please make some suggestions (or create a pull request), it would be great to make this thing better.

The future

The amount of time I put into this will correlate pretty directly to the interest I get, if no one asks questions (or complains) not much will happen.