Showing posts with label Images. Show all posts
Showing posts with label Images. Show all posts

Monday, August 22, 2016

[WSO2 App Manager] How to Add Custom Image Field to a Webapp

In default publisher UI, two images can be uploaded when creating a webapp. They are image banner and image thumbnail. Suppose you want to add the another image input too for apps, and let’s see how to do that.

First, Let's see how to add a custom image field to UI (Jaggery APIs).

For example,  let's take "Logo" as the custom field.

1. Modify <APPM_HOME>/repository/resources/rxt/webapp.rxt by adding below code under <table name="Images">.
   
   <field type="text">  
      <name>Logo</name>  
   </field>  
   
2. Login to Management console and navigate to Home > Extensions > Configure > Artifact Types and delete "webapp.rxt"

3. Add following block under "fields" of <APPM_HOME>/repository/deployment/server/jageeryapps/publisher/config/ext/webapp.json
   
   {  
      "name": "logo",  
      "table": "images",  
      "type": "imageFile"  
   }  
   
4. Add following line under "storeFields" of <APPM_HOME>/repository/deployment/server/jaggeryapps/publisher/config/storage.json
   
   "images_logo"  
   
5. 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 "images_logo" data.fields }}}  
   
6. When you create a new version of an existing webapp, to copy the image field value to the new version, you need to add below line to
<APPM_HOME>/repository/deployment/server/jaggeryapps/publisher/themes/appm/partials/copy-app.hbs
   
   <input type='text' value="{{{snoop "fields(name=images_logo).value" data}}}" name="images_logo" id="images_logo"/>  
   
   

Now, Let's see how to add customized image field to the REST APIs.

7. 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 inside customPropertyDefinitions section.
   
   {  
     "customPropertyDefinitions":  
     [  
       {"name":"images_logo"}  
     ]  
   }  
   
8. Restart App Manager.

9. Sample curl command with custom image property 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":"images_logo",   
    "value":"1b3bfd53-ff9a-4dd3-85f0-5e75e6bfa215/R9GxtyGTG7gN5hQ.jpg"   
   }   
  ]}' "http://localhost:9763/api/appm/publisher/v1.1/apps/webapp"   
   
Note : Refer this to upload a image to the system. Then, you can use that uploaded image  to create web app from REST APIs.

8. Web app create page with the newly added image field(i.e. Logo) will be shown as below.

save image

Thursday, July 21, 2016

[WSO2 App Manager] How to create a web app with a thumbnail and banner using REST APIs.

From WSO2 App Manager 1.2.0, most of functionalities are exposed through REST APIs. By this post, let's see how to create a web app with an uploaded thumbnail and banner using REST APIs.

  1. Obtain the consumer key/secret key pair by calling below curl command.

    sample curl command :

    > curl -X POST -H "Authorization: Basic YWRtaW46YWRtaW4=" -H "Content-Type: application/json" -H "Cache-Control: no-cache"  -d '{ "callbackUrl": "www.google.lk", "clientName": "app_11_04_0013121", "tokenScope": "Production", "owner": "admin", "grantType": "password refresh_token", "saasApp": true }' "http://localhost:9763/api/appm/oauth/v1.0/register"

    You will get the response as :

    >  {  "clientId": "dd06pbCzyzN7Ud1onZCb6SoCXA8a",
      "clientName": "app_11_04_0013122",
      "callBackURL": "www.google.lk",
      "clientSecret": "GL56h00WQVMdv1Lx8UGivcMcDqUa"
    }
  2. Generate the access token using the already created OAuth application.

    sample curl command :

    > curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Basic ZGQwNnBiQ3p5ek43VWQxb25aQ2I2U29DWEE4YTpHTDU2aDAwV1FWTWR2MUx4OFVHaXZjTWNEcVVh" -H "Cache-Control: no-cache" -H "Postman-Token: b418193e-fe30-5f91-fc3c-e41231201a7f" -d 'username=admin&amp;password=admin&amp;grant_type=password&amp;scope=appm:read appm:administration appm:create' "http://localhost:9763/oauth2/token"

    You will get the response as :
    {
     "scope": "appm:administration appm:create appm:read",   "token_type": "Bearer",   "expires_in": 3600,   "refresh_token": "6bda08b3-f44a-31be-988b-6630347357c3",   "access_token": "c4cdc394-931f-3e3f-9a91-f2be09fab1de"
    }
  3. Upload images which you want to upload.

    URL
    http://apis.wso2.com/api/appm/publisher/v1.1/apps/static-contents
    HTTP Method
    POST
    Scope
    appm:create

    sample curl command :


     > curl -X POST -H "Authorization: Bearer 03de85fc-6009-3831-b7b3-206aa7cef885" -H "Content-Type: multipart/form-data" -F "file=@/home/lakshani/Downloads/wso2.png" "http://localhost:9763/api/appm/publisher/v1.1/apps/static-contents?appType=webapp"

    You will get the response as :

    > {"id":"85229347-fcdf-4548-993e-1509dd4242df/dd24c0d2ea4a5697.png"}

  4. Create the web app with the uploaded images. For thumbnailUrl and banner of app create request, you can use "id" in the 3rd step's response.

    URL
    http://apis.wso2.com/api/appm/publisher/v1.1/apps/{appType}
    HTTP Method
    POST
    Scope
    appm:create
sample curl command :

>  curl -X POST -H "Authorization: Bearer 03de85fc-6009-3831-b7b3-206aa7cef885" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{"name":"testApp","version":"1.0.0","banner":"36d35be6-1847-4d22-b885-16c653486a77/241eb51a2fdb683b.jpg","thumbnailUrl":"85229347-fcdf-4548-993e-1509dd4242df/dd24c0d2ea4a5697.png","displayName":"testApp","description":"description","isSite":"false","context":"sampleContext","appUrL":"http://wso2.com","transport":"http"}' "http://localhost:9763/api/appm/publisher/v1.1/apps/webapp"

You will get the response as :

> {"AppId":"7ab144d1-a6da-4dbf-b361-1f5b62c2cdf7"}

You can go to the publisher UI and verify whether app creation with Images is succeed or not.
That's all :)