In WSO2 App Manager, when you create a new web app, you have to fill a set of predefined values (eg: Name, Version, Context etc.). If you want to add any custom fields to an app, you can easily do it.
First, Let's see how to add a custom field to UI (Jaggery APIs).
For example, let's take "Price" as the custom field.
1. Modify <APPM_HOME>/repository/resources/rxt/webapp.rxt. If you want to add "Price" as a mandatory field, add below code to the overview section of rxt file.
<field type="text" required="true">
<name>Price</name>
</field>
Note : If you don't want add the custom field as mandatory,
required="true" part is not necessary.
2. Login to Management console and navigate to Home > Extensions > Configure > Artifact Types and delete "
webapp.rxt"
3. Add following block under "fieldProperties" of <APPM_HOME>/repository/deployment/server/jageeryapps/publisher/config/ext/webapp.json
{
"field": "overview.price",
"name": "editable",
"value": true
}
4. Add below line to both <APPM_HOME>repository/deployment/server/jageeryapps/publisher/themes/appm/partials/add-asset.hbs
and
<APPM_HOME>repository/deployment/server/jageeryapps/publisher/themes/appm/partials/edit-asset.hbs
files.
{{{ form_render "overview_price" data.fields }}}
Now, Let's see how to add customized fields to the REST APIs.
5. Go to Main -> Browse -> in Management console and navigate to /_system/governance/appmgt/applicationdata/custom-property-definitions/webapp.json and click on "Edit As Text". Add the custom fields which you want to add.
{
"customPropertyDefinitions":
[
{"name":"overview_price"}
]
}
6. Restart App Manager.
7. Sample curl command with custom properties to create a web app is shown in below.
curl -X POST -H "Authorization: Bearer c4cdc394-931f-3e3f-9a91-f2be09fab1de" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{"name":"sampleApp","version":"1.0.0","banner":"36d35be6-1847-4d22-b885-16c653486a77/241eb51a2fdb683b.jpg","thumbnailUrl":"85229347-fcdf-4548-993e-1509dd4242df/dd24c0d2ea4a5697.png","displayName":"sampleApp","description":
"description","isSite":"false","context":"sampleContext","appUrL":"http://wso2.com",
"transport":"http", "customProperties":[
{
"name":"overview_price",
"value":"10"
}
]}' "http://localhost:9763/api/appm/publisher/v1.1/apps/webapp"
8. Web app create page with the newly added custom field(i.e. Price) will be shown as below.