Wednesday, November 20, 2013

Deploy your own Enterprise Store [part 2]

I have explained how to install WSO2 ES with bundled default assets in the previous blog post.In this post I will explain how to introduce your own digital asset type to the ES.

Before going though those steps we need to understand a bit about WSO2 Governance Registry. WSO2 GREG enables storing meta-data of our digital assets and assets themselves. You can find more information about WSO2 GREG from here.

Make sure you have WSO2 ES up and running for now,
Browse following URL and sign-in to the management console with the use of given user credentials(default).
Management Console : https://localhost:9443/admin/carbon/admin/login.jsp
Username :admin
Password :admin 
If you browse through following, Main>Resources > Browse> _system> governance > sites > admin > Facebook you will see something similar to the following screen-shot.


This is exactly where all information of Facebook (site-asset) stored. If you select the version 1.0.0 you can see meta-data as well as the properties of this asset.


Lets move to the publisher for a second, browse https://localhost:9443/publisher/asset/site and you will get,


If you compare form fields of add-site form with the properties of above Facebook site-asset, you can clearly understand the relationship between them.

Lets add our own asset type to the ES now. Make sure you proceed with a fresh WSO2 ES pack now on, just unzip already downloaded zip to a different location.

All the resources you need to create are available @ mp3-store git repo.
You can either replace existing files or update as explain in following steps.

1. Introduce meta-data model(rxt file)
If you browse repository/resources/rxts/ directory inside ES distribution, you can see number of .rxt files there. Open site.rxt file using your favorite text editor.

(Yeah !! now you know exactly where all those add-site form fields came from.)

You may create your own meta-data model now.
Create mp3.rxt (Yes im going to create a Music Store) with the following content.
<?xml version="1.0"?>
<artifactType type="application/vnd.wso2-mp3+xml" shortName="mp3" singularLabel="MP3" pluralLabel="MP3s"
              hasNamespace="false" iconSet="10">
    <storagePath>/mp3s/@{overview_provider}/@{overview_name}/@{overview_version}</storagePath>
    <nameAttribute>overview_name</nameAttribute>
    <ui>
        <list>
            <column name="Provider">
                <data type="path" value="overview_provider" href="@{storagePath}"/>
            </column>
            <column name="Name">
                <data type="path" value="overview_name" href="@{storagePath}"/>
            </column>
            <column name="Version">
                <data type="path" value="overview_version" href="@{storagePath}"/>
            </column>
        </list>
    </ui>
    <content>
        <table name="Overview">
            <field type="text" required="true">
                <name>Provider</name>
            </field>
            <field type="text" required="true">
                <name>Name</name>
            </field>
            <field type="text" required="true">
                <name>Version</name>
            </field>
            <field type="text">
                <name>Createdtime</name>
            </field>
        <field type="options">
                <name label="Category">Category</name>
                <values>
                    <value>Country</value>
                    <value>Pop</value>
                    <value>Rock</value>
                </values>
            </field>
        <field type="text" url="true">
                <name>URL</name>
            </field>
        <field type="text" required="true">
                <name>Artists</name>
            </field>
            <field type="text-area">
                <name>Description</name>
            </field>
        </table>
        <table name="Images">
            <field type="text" required="true">
                <name>Thumbnail</name>
            </field>
            <field type="text" required="true">
                <name>Banner</name>
            </field>
        </table>
    </content>

</artifactType>

2. Introduce new asset type to the store.
Go to the repository/deployment/server/jaggeryapps/store/config/ directory inside youe ES distribution.
Open store-tenant.json file and update following line with the new asset type.
"assets": ["gadget", "site", "ebook","mp3"],
3. Go to repository/deployment/server/jaggeryapps/store/extensions/assets directory inside youe ES distribution.
Create a directory called mp3 inside assets directory and copy/paste content from already existing asset type.You can update the content if you wish to do so.

Create mp3.json inside repository/deployment/server/jaggeryapps/store/config/ext/ directory with the following content. You can refer existing default artifact json while creating this.

Sample

{
    "applyTo": "mp3",


    "import": [
        "/modules/rxt/ext/scripts/form.overview.exporter.js",
        "/modules/rxt/ext/scripts/form.exporter.js"],

    "fieldPropertyRules": [
        "overview.name:order=1",
        "overview.provider:order=2",
        "overview.description:order=3",
        "overview.version:order=4"
    ],

    "tables": [

        {
            "name": "*"
        }

    ],

    "fieldProperties": [

        {
            "field": "*",
            "name": "order",
            "value": ""
        },
        {
            "field": "*",
            "name": "hidden",
            "value": "false"
        },
        {
            "field": "*",
            "name": "visible",
            "value": "true"
        },
        {
            "field": "overview.*",
            "name": "save",
            "value": "default"
        },
        {
            "field": "overview.*",
            "name": "editable",
            "value": true
        },
         {
            "field": "images.*",
            "name": "editable",
            "value": true
        },
        {
            "field": "*.lifeCycle",
            "name": "save",
            "value": "asset.lifecycle.action.save"
        },
        {
            "field": "overview.provider",
            "name": "readOnly",
            "value": "true"
        },
         {
            "field":"overview.provider",
            "name":"editable",
            "value":false
        },
         {
            "field":"overview.name",
            "name":"editable",
            "value":false
        },
        {
            "field": "overview.createdtime",
            "name": "hidden",
            "value": "true"
        },
        {
            "field":"overview.version",
            "name":"editable",
            "value":false
        },

    ],

    "fields": [
        {
            "name": "lifeCycle",
            "table": "*",
            "label": "Life Cycle",
            "value": "SampleLifeCycle2"

        } ,
        {
            "name": "banner",
            "table": "images",
            "type": "file"
        },
        {
            "name": "thumbnail",
            "table": "images",
            "type": "file"
        },
        {
            "name": "url",
            "table": "overview",
            "type": "file"
        },
        {
            "name": "description",
            "table": "overview",
            "value": "The provider has not given a description."
        }

    ],

    "permissions": {
        "created": ["Internal/private_{overview_provider}"],
        "in-review": ["Internal/reviewer", "Internal/private_{overview_provider}"],
        "published": ["Internal/private_{overview_provider}"],
        "unpublished": ["Internal/private_{overview_provider}"]
    },


    "storage": {

        "images_banner": {

            "lifecycle": {
                "created": ["Internal/private_{overview_provider}"],
                "in-review": ["Internal/reviewer", "Internal/private_{overview_provider}"],
                "published": ["Internal/everyone", "Internal/private_{overview_provider}", "Internal/reviewer"],
                "unpublished": ["Internal/private_{overview_provider}"]
            }
        },

        "images_thumbnail": {

            "lifecycle": {
                "created": ["Internal/private_{overview_provider}"],
                "in-review": ["Internal/reviewer", "Internal/private_{overview_provider}"],
                "published": ["Internal/everyone", "Internal/private_{overview_provider}", "Internal/reviewer"],
                "unpublished": ["Internal/private_{overview_provider}"]
            }
        }

    }
}



4.  Introduce new asset type to the publisher.
Go to the  repository/deployment/server/jaggeryapps/publisher/config/ directory inside youe ES distribution.
 Open publisher-tenant.json file and update following line with the new asset type.
"collections": ["gadgets", "sites", "ebooks","mp3s"],


5. Go to the repository/deployment/server/jaggeryapps/publisher/config/ext/ directory inside youe ES distribution. create mp3.json file with the following content.


{
    "applyTo": "mp3",
    "import": [
        "/modules/ext/scripts/rxt.importer.js",
        "/modules/ext/scripts/form.exporter.js"],
    "fieldPropertyRules": [
        "overview.name:order=1",
        "overview.provider:order=2",
        "overview.description:order=3",
        "overview.version:order=4"
    ],
    "tables": [
        {
            "name": "*"
        }
    ],
    "fieldProperties": [
        {
            "field": "*",
            "name": "order",
            "value": ""
        },
        {
            "field": "*",
            "name": "hidden",
            "value": "false"
        },
        {
            "field": "*",
            "name": "visible",
            "value": "true"
        },
        {
            "field": "overview.*",
            "name": "save",
            "value": "default"
        },
        {
            "field": "overview.*",
            "name": "editable",
            "value": true
        },
         {
            "field": "images.*",
            "name": "editable",
            "value": true
        },
        {
            "field": "*.lifeCycle",
            "name": "save",
            "value": "asset.lifecycle.action.save"
        },
        {
            "field": "overview.provider",
            "name": "readOnly",
            "value": "true"
        },
         {
            "field":"overview.provider",
            "name":"editable",
            "value":false
        },
         {
            "field":"overview.name",
            "name":"editable",
            "value":false
        },
        {
            "field": "overview.createdtime",
            "name": "hidden",
            "value": "true"
        },
        {
            "field":"overview.version",
            "name":"editable",
            "value":false
        },

    ],
    "fields": [
        {
            "name": "lifeCycle",
            "table": "*",
            "label": "Life Cycle",
            "value": "SampleLifeCycle2"
        } ,
        {
            "name": "banner",
            "table": "images",
            "type": "file"
        },
        {
            "name": "thumbnail",
            "table": "images",
            "type": "file"
        },
        {
            "name": "url",
            "table": "overview",
            "type": "file"
        },
        {
            "name": "description",
            "table": "overview",
            "value": "The provider has not given a description."
        }
    ],
    "permissions": {
        "created": ["Internal/private_{overview_provider}"],
        "in-review": ["Internal/reviewer", "Internal/private_{overview_provider}"],
        "published": ["Internal/private_{overview_provider}"],
        "unpublished": ["Internal/private_{overview_provider}"]
    },
    "storage": {
        "images_banner": {
            "lifecycle": {
                "created": ["Internal/private_{overview_provider}"],
                "in-review": ["Internal/reviewer", "Internal/private_{overview_provider}"],
                "published": ["Internal/everyone", "Internal/private_{overview_provider}", "Internal/reviewer"],
                "unpublished": ["Internal/private_{overview_provider}"]
            }
        },
        "images_thumbnail": {
            "lifecycle": {
                "created": ["Internal/private_{overview_provider}"],
                "in-review": ["Internal/reviewer", "Internal/private_{overview_provider}"],
                "published": ["Internal/everyone", "Internal/private_{overview_provider}", "Internal/reviewer"],
                "unpublished": ["Internal/private_{overview_provider}"]
            }
        }

    }
}
Now you can test the set-up by publishing a mp3.



Start your fresh ES with above changes and browse our mp3 asset type using, https://localhost:9443/publisher/asset/mp3. Yes!! you will get something similar to the following screen-shot.


Just fill those form fields with your own values and create the first mp3 asset on ES :)

You will redirect to a page, where you can see something similar to this.
(Here I'm using the same Thumbnail and Banner created for the CNN site)


You can select your mp3, browse life-cycle and change its state to In-review -> published from created state.( If you do not have permission to run above step just log-in as admin to the ES)


Lets, log-in to the store and browse our newly added asset type using following URL http://localhost:9763/store/assets/mp3


And if you select already published MP3,in my case skyfall :). You will see something similar to the following where you can download, comment and rate the asset.


Now, you are good to go with your own asset (mp3) store.

No comments:

Post a Comment