DEPRECATED

This Module is deprecated. Don't use it anymore! There won't be any bugfixes or improvements.

ec.datamanager-java-sdk

Java SDK for ec.datamanager. By entrecode.

Simply use the generated APIs of the ec.datamanager with Java.

The SDK is fully asyncron.

Setup

Get via Maven:

<dependency>
  <groupId>de.entrecode</groupId>
  <artifactId>datamanager_java_sdk</artifactId>
  <version>0.4.0</version>
</dependency>

or with Gradle:

compile 'de.entrecode:datamanager_java_sdk:0.4.0'

Usage

See the running example in srv/main/java/de.entrecode.datamanager_java_sdk.example.

Initialization

You need to connect to your Data Manager API using the DataManager(…) constructors.

Initializing dataManager with existing token:

DataManager dm = new DataManager(
  new URL("https://datamanager.entrecode.de/api/beefbeef"),
  UUID.fromString("8c3b7b55-531f-4a03-b584-09fdef59cb0c")
);

Alternative:

DataManager dm = new DataManager(
  "beefbeef",
  UUID.fromString("8c3b7b55-531f-4a03-b584-09fdef59cb0c")
);

Initializing without token (will be generated):

DataManager dm;
DataManager.create(
  new URL("https://datamanager.entrecode.de/api/beefbeef",
  new ECResponseListener<DataManager>{
    @Override
    public void onResponse(DataManager dataManager){
        dm = dataManager;
    }
  }, new ECErrorListener{
    @Override
    public void onError(ECError error){
        System.out.println(error.stringify());
    }
  });

Alternative without token:

DataManager dm;
DataManager.create(
  "beefbeef",
  new ECResponseListener<DataManager>{
    @Override
    public void onResponse(DataManager dataManager){
        dm = dataManager;
    }
  }, new ECErrorListener{
    @Override
    public void onError(ECError error){
        System.out.println(error.stringify());
    }
  });

Initializing with read-only mode:

DataManager dm = new DataManager("beefbeef", true); // throws ECMalformedDataManagerIDException

//OR

DataManager dm2 = new DataManager(
  new URL("https://datamanager.entrecode.de/api/beefbeef",
  true);

Get Entries

dm.model("myModel").entries()
    .levels(2)
    .onResponse(new ECResponseListener<List<ECEntry>>{
        @Override
        public void onResponse(List<ECEntry> entries){
            // TODO something       
        }
    })
    .onError(new ECErrorListener{
        @Override
        public void onError(ECError error){
            // TODO something
        }
    })
    .filter(new HashMap<String, String>(){{
        put("propertyA~", "LikeThat");
        put("propertyB", "ExactlyThat");
        put("propertyCFrom", "FromThat");
        put("propertyCTo", "ToThat");
    }})
    .go();

Get Entry

dm.model("myModel").entry("alwoigei")
    .levels(2)
    .onResponse(new ECResponseListener<ECEntry>{
        @Override
        public void onResponse(ECEntry entry){
            // TODO something
        }
    }).go();

Create Entry

ECEntry ecEntry = new ECEntry(…);
…
dm.model("myModel").createEntry(ecEntry)
    .onResponse(new ECResponseListener<ECEntry>{
        @Override
        public void onResponse(ECEntry entry){
            // TODO something
        }
    }).onError(new ECResponseListener<ECEntry>{
        @Override
        public void onResponse(ECEntry entry){
            // TODO something       
        }
    }).go();

Delete Entry

ECEntry ecEntry;
…
ecEntry.delete()
    .onResponse(new ECResponseListener{
        @Override
        public void onResponse(){
            // TODO something
        }
    }
    .onError(new ECErrorListener{
        @Override
        public void onError(ECError error){
            // TODO something
        }
    }).go();

Update Entry

ECEntry ecEntry;
…
ecEntry.save()
    .onResponse(new ECResponseListener<ECEntry>{
        @Override
        public void onResponse(ECEntry entry){
            // TODO something
        }
    })
    .onError(new ECErrorListener{
        @Override
        public void onError(){
            // TODO something
        }
    }).go();

Model List

dm.modelList()
    .onResponse(new ECResponseListener<List<Model>>{
        @Override
        public void onResponse(List<Model> models){
            // TODO something
        }
    }).go();

Get JSON Schema

dm.model("myModel").getSchema()
    .forMethod("PUT")
    .onResponse(new ECResponseListener<JsonObject>{
        @Override
        public void onResponse(JsonObject schema){
            // TODO something
        }
    })
    .onError(new ECErrorListener{
        @Override
        public void onError(){
            // TODO something
        }
    }).go();

User Managerment

dm.register()… // is shorthand for
dm.model("user").createEntry(new ECEntry())
    .onResponse(new ECResponseListener<UUID>{
        @Override
        public void onResponse(ECEntry user){
            // TODO save token
            saveSomwhere(user.getProperty("temporaryToken"));
        }
    })
    .onError(new ECErrorListener{
        @Override
        public void onError(){
            // TODO something
        }
    }).go();

Full example of updating a user entry:

ECErrorListener ecel = new ECErrorListener{
    @Override
    public void onError(ECError error){
        // TODO something
    }
}
dm.user("lsadklja")… // is shorthand for
dm.model("user").entry("lsadklja")
    .onResponse(new ECResponseListener<ECEntry>{
        @Override
        public void onResponse(ECEntry user){
            user.set("name", "André Code");
            user.save()
                .onResponse(new ECREsponseListener<ECEntry>{
                    @Override
                    public void onResponse(ECEntry user){
                        // TODO something
                    }
                }).onError(ecel).go();
        }
    })
    .onError(ecel).go();

Asset File Helper

The SDK can help you getting asset files, and image assets in the right sizes.

dm.getFileURL("46092f02-7441-4759-b6ff-8f3831d3da4b")
    .locale("en-US")
    .onResponse(new ECResponseListener<String>{
        @Override
        public void onResponse(String url){
            // TODO something
        }
    }).go();

For image Assets, the following helper is available:

dm.getImageURL("46092f02-7441-4759-b6ff-8f3831d3da4b")
    .size(500)
    .onResponse(new ECResponseListener<String>{
        @Override
        public void onResponse(String url){
            // TODO something
        }
    }).go();

// OR

dm.getFileURL("46092f02-7441-4759-b6ff-8f3831d3da4b")
    .image()
    .size(500)
    .onResponse(new ECResponseListener<String>{
        @Override
        public void onResponse(String url){
            // TODO something
        }
    }).go();

size(…) expects a pixel value. The largest edge of the returned image will be at least this value pixels in size, if available.

You can also request a thumbnail:

dm.getImageThumbURL("46092f02-7441-4759-b6ff-8f3831d3da4b")
    .size(100)
    .onResponse(new ECResponseListener<String>{
        @Override
        public void onResponse(String url){
            // TODO something
        }
    }).go();

// OR

dm.getImageURL("46092f02-7441-4759-b6ff-8f3831d3da4b")
    .size(500)
    .crop()
    .onResponse(new ECResponseListener<String>{
        @Override
        public void onResponse(String url){
            // TODO something
        }
    }).go();

Get Assets

dm.assets()
    .onResponse(new ECResponseListener<List<ECAssets>>{
        @Override
        public void onResponse(List<ECAssets> assets){
            // TODO something
        }
    }).go();

Get Asset

dm.asset("46092f02-7441-4759-b6ff-8f3831d3da4b")… // is shorthand for
dm.assets().filter(new HashMap<String, String>(){{
        put("assetID", "46092f02-7441-4759-b6ff-8f3831d3da4b");
    }})
    .onResponse(new ECResponseListener<ECAsset>{
        @Override
        public void onResponse(ECAsset asset){
            // TODO something
        }
    }).go();

Delete Asset

ECAsset asset;
…
asset.delete()
    .onResponse(new ECResponseListener{
        @Override
        public void onResponse(){
            // TODO something
        }
    }
    .onError(new ECErrorListener{
        @Override
        public void onError(ECError error){
            // TODO something
        }
    }).go();

Get Tags

dm.tags()
    .onResponse(new ECResponseListener<List<ECTag>>{
        @Override
        public void onResponse(List<ECTag> tags){
            // TODO something
        }
    }).go();

Get Tag

dm.tag("tagname")… // is shorthand for
dm.tag().filter(new HashMap<String, String>(){{
        put("tag", "tagname");
    }})
    .onResponse(new ECResponseListener<ECTag>{
        @Override
        public void onResponse(ECTag tag){
            // TODO something
        }
    }).go();

Edit Tag

ECTag tag = …
…
tag.save()
    .onResponse(new ECResponseListener<ECTag>{
        @Override
        public void onResponse(ECTag tag){
            // TODO something
        }
    }).go();

Delete Tag

ECTag tag;
…
tag.delete()
    .onResponse(new ECResponseListener{
        @Override
        public void onResponse(){
            // TODO something
        }
    }
    .onError(new ECErrorListener{
        @Override
        public void onError(ECError error){
            // TODO something
        }
    }).go();

Documentation

see JavaDoc.

Test & Coverage

Running tests with:

./gradlew test

Running tests with coverage:

./gradlew jacocoTestReport

Changelog

0.4.2

  • support for nested entries with level(int)

0.4.1

  • added tag api doc

0.4.0

  • use updated single resource responses in Public API.
  • added tag api.

0.2.3

  • SDK will use new thumbnail api for image assets

0.2.2

  • added JavaDoc

0.2.1

  • initial public release