Tuesday, April 3, 2012

Future requirements - API

I was preoccupied by the graphics of the application, although this was not the main idea behind this project. I should focus more on creating the needed API, than some fancy application. The developer using my API should be able to create, read, update and delete some data from the SQLite Database, and the backup to Google App Engine will be made transparently by the API.

So I created a new application, which simulates the creation of a developer and uses it to back everything up to Google App Engine. I use Generic Classes, so no matter what fields the developer's class will have, everything will work just fine. I do this by creating a JSON file with the fields of the class:

private <T> String createJsonFile(Class<T> Kind) {
    String json;

    /*Get all fields, including the private ones*/
    Field[] fields = Kind.getDeclaredFields();
    int fieldsNo = fields.length;

    /*For each field, add to the JSON String the field's name*/
    for (Field field : fields) {
        fieldsNo--;
        json += "\"" + field.getName() + "\"";
        if (fieldsNo != 0)
            json += ",";
    }
    return json;
}
So these are the steps that I should follow while redesigning the application:
  • Create JSON file from Class.
  • Create SQLite Database with this structure (the table should have the same fields).
  • Update the server concerning the schema.
    • POST the JSON file
  • Add one item to SQLite Database.
  • Read/Modify/Delete items from SQLite Database.
  • Synchronize the server when needed. 

These are small steps which I began already to implement. The last step can be further divided into smaller steps, but this is what I plan for now. It shouldn't be to difficult to implement, considering that most of it I already have, but I need to reorganize things.

An image with how should all look like is this one:

No comments:

Post a Comment