Skip to content

druka/JFluidDB

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is a direct port of FluidDB.net ( http://github.com/ntoll/FluidDB.NET/tree/master )
by Nicholas Tollervey ( http://ntoll.org/ ) from C# to Java.

See the AUTHORS file for contributors.

See the TODO file for the next things to be implemented.

Unit tests (using jUnit http://www.junit.org/) can be found in the test directories under 
src/com/fluidinfo/

To be able to run the unit tests you need to provide some valid credentials for the sandbox instance
of FluidDB. You can supply these by putting a credentials.json file in your home directory - the
test fixture will attempt to read this file and use the username and password defined therein. See the
credentials.json.example file for an example of the correct contents of this file.

This is still a very early stage, but any help is appreciated in getting this up and running in a more 
complete fashion.

Currently we have a class (FluidConnector) that facilitates interaction with FluidDB, a suite of tests
for this class and some other helper classes.

I (ntoll) have partially completed a FOM (Fluid-Object-Mapper) to sit on top of the FluidConnector 
class.

All feedback, patches, bug-reports are most welcome!

Example usage:

import java.io.IOException;
import com.fluidinfo.*;
import com.fluidinfo.fom.*;
import com.fluidinfo.fom.Object;
import org.json.*;

public class fluidTest {

    /**
     * Some example code for using the Fluid Object Model (FOM) classes with 
     * FluidDB
     * @throws JSONException 
     * @throws IOException 
     * @throws FluidException 
     * @throws FOMException 
     */
    public static void main(String[] args) throws FOMException, FluidException, IOException, JSONException {
        // The FluidDB class represents the instance of FluidDB you're connecting to.
        // The default constructor is set to use http://fluiddb.fluidinfo.com/ but we're
        // passing the URI to the sandbox here.
        FluidDB fdb = new FluidDB(FluidConnector.SandboxURL);
        // Login to FluidDB with your credentials
        String username = "username";
        String password = "password";
        fdb.Login(username, password);
        // Get the User object representing me
        User u = fdb.getLoggedInUser();
        // My root namespace
        Namespace root = u.RootNamespace();
        // Create a new namespace underneath my root namespace
        Namespace books = root.createNamespace("books", "For storing tags about books I might be reading.");
        // Add some tags to the new namespace
        Tag title = books.createTag("Title", "The title of a book I've read", true);
        Tag authors = books.createTag("Authors", "The author list", true);
        Tag hasRead = books.createTag("HasRead", "Indicates I've read this book", true);
        Tag rating = books.createTag("Rating", "Marks out of ten", true);
        Tag comment = books.createTag("Comment", "Some notes and commentary", false);
        
        // Create a new object
        Object seven_pillars = fdb.createObject("ISBN:0954641809");
        // Associate some tag/values with it
        // The first tag is only associating a tag *not* a value too
        seven_pillars.tag(hasRead);
        // We're associating values with the tags
        seven_pillars.tag(title, "Seven Pillars of Wisdom");
        seven_pillars.tag(authors, new String[]{"T.E.Lawrence"});
        seven_pillars.tag(rating, 8);
        seven_pillars.tag(comment, "The dreamers of the day are dangerous men, for they may act out their dreams with open eyes, to make it possible.");
        
        // A search of all objects that I have read 
        String[] result = fdb.searchObjects("has "+username+"/books/HasRead");
        // result will contain only one result... the id for the seven_pillars Object
        // Lets instantiate it and get a list of the available tags I have permission to see
        Object newObj = fdb.getObject(result[0]);
        String[] tagPaths = newObj.getTagPaths();
        // tagPaths will include my tags I created above...
        // Lets get the first tag and find out what is in it...
        Tag newTag = fdb.getTag(tagPaths[0]);
        FluidResponse r = newObj.getTagValue(newTag);
        // Assuming all is well the result is returned by calling r.getResponseContent(); 
        // Lets do some cleanup...
        
        // Remove the tags from the object that we created to represent the seven pillars
        newObj.deleteTag(title);
        newObj.deleteTag(authors);
        newObj.deleteTag(hasRead);
        newObj.deleteTag(rating);
        newObj.deleteTag(comment);
        
        // Now delete the tags
        title.delete();
        authors.delete();
        hasRead.delete();
        rating.delete();
        comment.delete();
        
        // and finally the namespace
        books.delete();
    }
}

About

A simple Java library for interacting with fluiddb

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%