Skip to content

Gestalt Asset Core Quick Start

Immortius edited this page May 30, 2015 · 21 revisions

Gestalt Asset Core Quick Start

Defining an Asset type

There are two important classes when defining a new asset type.

Firstly, the AssetData class provides an implementation-agnostic representation of the data needed to create the asset:

public class BookData implements AssetData {
    private String title;
    private String body;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }
}

Then there is the Asset class itself:

public class Book extends Asset<BookData> {

    private String title;
    private String body;

    public Book(ResourceUrn urn, BookData data, AssetType<?, BookData> type) {
        super(urn, type);
        reload(data);
    }

    @Override
    protected void doReload(BookData data) {
        title = data.getTitle();
        body = data.getBody();
    }

    @Override
    protected void doDispose() {
        title = "";
        body = "";
    }

    public String getTitle() {
        return title;
    }

    public String getBody() {
        return body;
    }
}

Establishing an AssetTypeManager

AssetTypeManager is is the central manager for all asset types. ModuleAwareAssetTypeManager will set up asset types to read

ModuleAwareAssetTypeManager assetTypeManager = new ModuleAwareAssetTypeManager();
assetTypeManager.registerCoreAssetType(Book.class, Book::new, "books");
assetTypeManager.switchEnvironment(moduleEnvironment);

Obtaining Assets

AssetManager assetManager = new AssetManager(assetTypeManager);
Optional<Book> myBook = assetManager.getAsset("engine:mybook", Book.class);
Optional<Book> myBook = assetManager.getAsset("engine:mybook", Book.class);
Set<ResourceUrn> bookUrns = assetManager.getAvailableAssets(Book.class);

Programatically creating/reloading Assets

BookData data = new BookData();
Book myBook = assetManager.loadAsset(new ResourceUrn("engine:mybook"), data, Book.class);
BookData data = new BookData();
myBook.reload(data);

AssetDataProducers

``java