Showing posts with label jocu. Show all posts
Showing posts with label jocu. Show all posts

Sunday, October 30, 2011

JOCU – The Alpha

I’ve been working on an OData reader in java for some time now, and I am ready to show people the first alpha.  There are some pieces missing, and I would prefer better ways of accessing some of the data.  But here it is.

The release only has the underived version of the JOCU project.  It allows for most of the functionality from the OData protocol (the main one missing is the data format, this uses XML data src as apposed to the json format).

Here is a code snipit I wrote that uses the API from the JAR library.

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import lkoutzas.jocu.shared.AbstractCatelogueData;
import lkoutzas.jocu.shared.AbstractEntity;
import lkoutzas.jocu.underived.ODataEntity;
import lkoutzas.jocu.underived.ODataLink;
import lkoutzas.jocu.underived.ODataRepository;


public class RunJOCUDemo {

public static void main(String[] args) {

System.out.println("Welcome to the demo of the JOCU odata reader!!");
System.out.print("Catelogues Start: ");
System.out.println(new Timestamp(System.currentTimeMillis()));

// create the odata repository
ODataRepository oData = new ODataRepository();
// set the URI for the location of the repository
oData.SetURI("http://services.odata.org/OData/OData.svc/");
// get oData Catelogue
List<AbstractEntity> categlogues = oData.FetchODataCatelogues();
System.out.print("End: ");
System.out.println(new Timestamp(System.currentTimeMillis()));
// dump out results to show it works...
System.out.println("Catelogues...");
for(int i=0;i<categlogues.size();i++)
{
AbstractEntity local = categlogues.get(i);
System.out.println(local.getAttribute("href"));
}
System.out.println();
System.out.print("Entities Start: ");
System.out.println(new Timestamp(System.currentTimeMillis()));
// create the odata repository
ODataRepository oData2 = new ODataRepository();
// set the URI for the location of the repository
oData2.SetURI("http://services.odata.org/OData/OData.svc/");
// set the catelogue for the oData repositpory
oData2.SetCatelogue("Categories");
// query or filter the data request (need to detail full list)
oData2.getQuery().top("2").select("ID,Name");
// get entities
AbstractCatelogueData entities = oData2.FetchEntities();
System.out.print("End: ");
System.out.println(new Timestamp(System.currentTimeMillis()));

System.out.println("entities...");
for(int i=0;i<entities.getEntities().size();i++)
{
ODataEntity local = (ODataEntity) entities.getEntities().get(i);
System.out.println(local.field("ID") + ": " + local.field("Name") + " links are: ");
for(int j=0;j< local.getLinks().size();j++)
{
ODataLink odataLink = local.getLinks().get(j);
System.out.println(odataLink.getTitle() + " - " + odataLink.getHref() + " ("+ odataLink.getRelationship()+")");
}
}
}

}


As you can see, the API is pretty easy to use and I think pretty good.  So, for the “bits not in the alpha”.


Firstly, there is a bug that will mean that XML structured elements (CDATA as an example) are not parsed correctly.  They get broken down into separate elements rather than a single blob.


Also, I would like to improve the manner that the data is being accessed.  It feels a bit clunky to me. I am not sure how I can improve it, but I would like to see what I can think of.


The last missing bit / bug is that the expanded entities within the querystring.  At the moment I think it would fail badly.  The API will allow it, but the data will likely either cause the call to fail or it will will be ignored.


Once these items are in the code, I am going to work on the derived version, which will allow strongly typed objects and (hopefully) reduce the size of the downloaded packet.


The link for the alpha is here.  Let me know your thoughts.

Sunday, March 6, 2011

JOCU – The Final Stretch

So, I have the basics of an XML parser completed, now I need to implement this to deliver what I am wanting, which is the Java OData Consuming Utility.  I am going to work on the loosely typed or underived version first, then I will implement the derived version.

Briefly, lets look at the functionality we can expect from the repository. 

string GetSource() / SetSource(string)
This will define what the source of the oData is.

bool GetMetadataRequired() / void SetMetadataRequired(bool)
This will set or get if the metadata is required for this repository

ODataEntities Fetch()
This will get the entities from the oData query

IODataQuery Filter(string)
Applies the filter URI convention to the source

IODataQuery SetEntityCollection(string)
This will define which collection that it is desired to get

IODataQuery GetEntity(string)
Gets a single entity from the collection

IODataQuery SetOrderBy(string)
Sets what the list is ordered by

IODataQuery Top(string)
Sets the number of entities that we want returned

IODataQuery Expand(string)
Sets which related entities to expand

IODataQuery Format(string)
Sets the format to return the data in (not used really for what I want, should I scrap it?)

IODataQuery Select(string)
Identifies which entity items to select, and related items

IODataQuery InlineCount(string)
Sets the inline count property on the data source

IODataQuery CustomURIElement(string)
Sets a custom element to the query that is sent to the OData source

string GetMetadata(string)
This will get the OData collection metadata entry

And, from the point of view of the entity we have the following:

string Get(string)
Gets the value of the key passed though

string GetMetadata(string)
Gets the metadata value for the key passed though

Most of this is derived from the OData URI conventions, with some basic access functions thrown in.  I think that this is all I need to implement, but to be honest I’m not sure.  I have a feeling I will be uncovering more than I expect as I start to tackle the implementation of the repository access, but I need to start somewhere, and this is the best place.  I am aiming to finish this off in the next month or so, but as I am doing this in my spare time to have some fun we shall see what happens.