Unknown macro: {next_previous_links}
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 17 Next »

The following subsections explain an asset extension in-depth.

An asset type, which is also referred to as an artifact type, is a resource in that is used in the Publisher and Store. WSO2 Enterprise Store (ES) ships some default assets: Gadgets and Sites. An asset extension allows you to define a new asset type with a set of custom behaviors and views. The behaviors defined within an asset extension are only applicable for that specific asset type.

When should I use an Asset Extension?

ES automatically generates a set of basic views and provides generic business logic for CRUD (create, read, update and delete), lifecycle and subscription operations. However, the generic behavior may not always be sufficient, and you may want to define your own business logic for a CRUD operation or change a generic view. For example:

  • Changing an asset view - Modifying the way the asset listing page appears.
  • Changing CRUD behavior of an asset - Calling an external end-point after creating an asset instance.

Therefore, you need create a new Asset Extension in such instances to be able to add a new customized asset type to ES. 

Overall structure of an Asset Extension

The Asset Extensions are maintained in a single folder, namely the assets directory. The following diagram explained the folder structure of the assets directory. This diagram shows a number of asset extensions along with the default extension. The default directory contains sub-folders that handle the behavior and views of a generic asset type. In addition, the default directory provides an example of the structure that should be maintained for an asset extension. However, note that each of the listed items are optional. Therefore, an asset extension need not have all of the items indicated in the following diagram. The ES extension model will automatically inherit the CRUD logic and pages from the default extension folder.

Asset Extension Folder Structure

Asset Extension components

The following diagram illustrates the structure of an asset extension:

An Asset Extension may contain one or more of the following elements:

  • An asset.js script
    This script is used to carryout the following actions:
    • Define a callback method that allows the CRUD logic to be modified.
    • Define new pages and APIs.
    • Override the current pages and APIs.
    • Change the RXT properties of an asset.
    • Define a callback method, which is called on the asset data prior to rendering.
      For more information, see asset.js Script.
  • A themes directory
    • Any partials, JS scripts or CSS files for new or overridden pages are added in this directory.
    • This directory is used to customize the view. For more information, see Asset Extension.
  • An apis directory
    • Controllers, which either override the existing APIs or add new endpoints, are added in this directory.
    • The APIs defined in the asset.js server callback method are looked up in this folder.
  • A pages directory
    • Controllers, which either override the existing pages or add new pages, are added to this directory.
    • The pages defined in the asset.js server callback method are looked up in this folder.

Customizing the view

The themes directory is used to customize the view. ES views are rendered using the Caramel MVC framework. The Extension Model works together with the Caramel framework, to determine from which location a view should be loaded. When a resource is consumed by the Caramel framework, the Extension Model examines the request URI to determine if the request originated for a particular asset type. Thereafter, it will attempt to locate the resource from within the Asset Extension directory. This allows any of the corresponding partials of a view to be overridden individually, based on a specific asset type. However, if needed you can also override the partials of a view globally, so that it affects all the asset types.

  • No labels