Making ImportIO simpler with Java.
This project is maintained by thuzhen
Facilitator is a project that aims to integrate ImportIO better in Java apps by caching and parsing data retrieved by ImportIO. This project is just a hobby and is not affiliated with ImportIO.
Facilitator provides an easy and quick way to get POJOs out of your data. Let's see how.
IOClient is a special subclass of ImportIO that provides all the tools to parse your data.
IOClient client = new IOClient("YOURUSERID", "YOURSECRETKEY");
Your query can be almost anything.
Mark the fields you want to fill with @Attribute("name") annotation with "name" being the column name of your data in ImportIO. Here's an example that could describe a product from a website such as Amazon.
class Product
{
@Id
protected long id;
@Attribute("name")
protected String name;
@Attribute("image")
protected String imageUrl;
@Attribute("price")
protected Money price;
...
protected Integer someOtherField
...
}
Some special classes such as Date and Money are handled by Facilitator, which means if your field represent a date, its class could be either Date, Long (in which case it will correspond to the timestamp), or String (it will correspond to the date as a string). Here's a quick table of compatible types and classes:
Types | Classes | Value |
---|---|---|
Date | java.util.Date Long String |
- timestamp literal date |
Money | org.joda.money.Money Double String |
- Amount of money Amount of money + currency sign |
It will get you a list of POJO instances. You will have to tell the client which class it should generate (here, Product.class)
List<Product> products = client.populate(query, Product.class);
client.populate(query, Product.class, true);
Facilitator automatically cache all the queries you make (actually no more than 200 to save memory) with a TTL of one hour. Which means that if you call populate() again with the same query, it won't reload fresh data unless you force refresh (passing true a the third parameter) or the TTL has expired.
Facilitator has been built so you can extend it to automatically parse your data and fit it into POJOs. If you want to add your own parser, this is actually quite simple. Explanations coming soon.