Tuesday, November 22, 2016

[WSO2 App Manager] How to Customize Webapp Overview Page

I posted several posts on how to add different custom input fields to Publisher. In this post, let's see how to customize Publisher overview page.

By default, webapp overview page is like below.




If you want to preview custom fields in the overview page, you need to modify <APPM_HOME>/repository/deployment/server/jaggeryapps/publisher/themes/appm/helpers/splitter.js.

Suppose you added a custom field called "Price" like in this post. Then you have to add below condition inside splitData function of above file.
   
   else if (dataPart[i].name == "overview_price") {  
     overview_main.push(dataPart[i]);  
   }  
   

Then,  the webapp overview page with custom feild will look like below.

Sunday, November 13, 2016

[WSO2 API Manager] How to Add a User Signup Workflow

From WSO2 API Manager, new developers can self-sign up to the API Store.  After that,  they can login to API Store using that account. But if admins want to approve those new accounts before new developers use their accounts, workflows can be configured. For that, we are using WSO2 Business Process Server (BPS).

Let's see how to add a user signup workflow.

  1. If API Manager and Business Process Server are running on the same machine, follow this step.

  2. Set Offset value to 2 in <BPS_HOME>/repository/conf/carbon.xml.
       
        <Offset>2</Offset>  
       
    
  3. If there is no directory called "epr" inside <BPS_HOME>/repository/conf/, then create it.
  4. Copy following epr files from APIM_HOME>/business-processes/epr to <BPS_HOME>/repository/conf/epr.
    • UserSignupService.epr
    • UserSignupProcess.epr
  5. Start BPS and login to Management console.
  6. Go to Home > Manage > Processes > Add > BPEL. Then, upload <APIM_HOME>/business-processes/user-signup/BPEL/UserSignupApprovalProcess_1.0.0.zip.

  7. Go to Home > Manage > Human Tasks >. Then, upload <APIM_HOME>/business-processes/user-signup/HumanTask/UserApprovalTask-1.0.0.zip.


  8. Configuration on BPS is finished.  Now, let's see how to configure WSO2 APIM.
  9. Start APIM and  login to Management console.
  10. Go to Home > Resources > Browse and navigate to /_system/governance/apimgt/applicationdata/workflow-extensions.xml. Click on "Edit As Text". 
  11. Comment <UserSignUp executor="org.wso2.carbon.apimgt.impl.workflow.UserSignUpSimpleWorkflowExecutor"> and uncomment  <UserSignUp executor="org.wso2.carbon.apimgt.impl.workflow.UserSignUpWSWorkflowExecutor">
  12. Also, update below property values based on your BPS server credintials, service endpoint.
       
     <UserSignUp executor="org.wso2.carbon.apimgt.impl.workflow.UserSignUpWSWorkflowExecutor">  
          <Property name="serviceEndpoint">http://localhost:9765/services/UserSignupProcess/</Property>  
          <Property name="username">admin</Property>  
          <Property name="password">admin</Property>  
          <Property name="callbackURL">https://localhost:8243/services/WorkflowCallbackService</Property>  
       </UserSignUp>  
       
    

    Now Configuration in API Manager is finished. 
  13. Now, go to API store and sign up to the store. 
  14. When you signup to the API Store you will get a Notification. (User account awaiting Administrator Approval).
  15. Then, login to Admin Dashboard (https:<Server Host>:9443/admin). 
  16. Go to Tasks > User Creation. Then you will able to see the pending user approval tasks like below.
  17. If you click on "Start" button, the tasks status changed into "In_Progress". 
  18. Once, you click on "Complete" button, signed up user account become active and that user able to login to the API Store.

Thursday, November 10, 2016

Google Analytics Tracking for WSO2 App Manager

Google Analytics is a free Web analytics service that provides statistics and basic analytical tools. We can configure WSO2 App Manager to track web application and sites invocation statistics through Google Analytics.

First, let's see how to setup a google Analytic account.

1. Go to http://www.google.com/analytics/ and Click on Analytic tab.
2. Then, click on "Admin" tab and create a New Account.
3. Click on "Website" and give account information like in below. Here, you have to fill the information which you want to track.
4. Click on 'Get Tracking Id'. Then you will redirect to a page like below. From there you can get the Tracking Id.
5.  Configure WSO2 App Manager with received Tracking code. Enable google analytics and add TrackingID of <APPM_HOME>/repository/conf/app-manager.xml as shown below.
   
  <GoogleAnalyticsTracking>  
 <!--Enable/Disable Google Analytics Tracking-->  
      <Enabled>true</Enabled>  
      <!--Google Analytics Tracking ID-->  
      <TrackingID>UA-86711225-1</TrackingID>  
 </GoogleAnalyticsTracking>  
   
6. Restart server.
7. Place the below JavaScript code snippet into the pages that you need to track with your Google Analytics account.
   
 <script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript">  
   function invokeStatistics(){      
   var tracking_code = ["<TRACKING_CODE>"];      
   var request = $.ajax({      
     url: "http://<AM_GATEWAY_URL>:8280/statistics/",      
     type: "GET",      
     headers: {        
       "trackingCode":tracking_code,      
       }         
     }  
   );    
 }  
 </script>  
   

Now we have successfully integrated WSO2 App Manager with Google Analytics. Let's see how we can see the statistics.

Real-time statistics


Then go to Google Analytics [http://www.google.com/analytics/] and select the created account above.

The following image shows an invocation of a specific Web application. The Google Analytics graphs and statistics are displayed at runtime in its Real-Time view. In below graphs, you will able to see a hit on "PageViews" per second and active users.


Reporting statistics

Google Analytics reporting statistics will take more than 24 hours from the time of invocation.

A sample dashboard with populated statistics is shown in below.


Monday, November 7, 2016

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

In WSO2 App Manager, when you create a new web app, you have to fill a set of predefined values. If you want to add any custom fields to an app, you can easily do it.

Suppose you want to add a custom dropdown field to webapp create page. Say the custom dropdown field name is "App Network Type". 

First, Let's see how to add a custom field to UI (Jaggery APIs).
  1. Modify <APPM_HOME>/repository/resources/rxt/webapp.rxt.
  2.    
       <field type = "text">  
           <name label = "App Network Type">App Network Type</name>  
       </field>  
       
    
  3. Login to Management console and navigate to Home > Extensions > Configure > Artifact Types and delete "webapp.rxt"
  4. Add below code snippet to the required place of <APPM_HOME>repository/deployment/server/jageeryapps/publisher/themes/appm/partials/add-asset.hbs
  5.    
     <div class="form-group">  
       <label class = "control-label col-sm-2">App Network Type : </label>  
       <div class = "col-sm-10">  
         <select id = "appNetworkType" class = "col-lg-6 col-sm-12 col-xs-12">  
           <option value = "None">None</option>  
           <option value = "Online">Online</option>  
           <option value = "Offline">Offline</option>  
         </select>  
       </div>  
       <input type = "hidden" required = "" class = "col-lg-6 col-sm-12 col-xs-12" name = "overview_appNetworkType"  
           id = "overview_appNetworkType">  
     </div>  
       
    
  6. Add below code snippet to <APPM_HOME>/repository/deployment/server/jaggeryapps/publisher/themes/appm/partials/edit-asset.hbs.
  7.    
     <div class = "form-group">  
       <label class = "control-label col-sm-2">App Network Type : </label>  
       <div class = "col-sm-10">  
         <select id = "appNetworkType" class = "col-lg-6 col-sm-12 col-xs-12">  
           <option value = "None">None</option>  
           <option value = "Online">Online</option>  
           <option value = "Offline">Offline</option>  
         </select>  
       </div>  
       
       <input type='hidden' value="{{{snoop "fields(name=overview_appNetworkType).value" data}}}"  
       name="overview_appNetworkType" id="overview_appNetworkType"/>  
     </div>  
       
    
  8. To save selected value in registry, you need to add below function inside $(document ).ready(function() {} of <APPM_HOME>/repository/deployment/server/jaggeryapps/publisher/themes/appm/js/resource-add.js
  9.    
     $("#appNetworkType").change(function() {  
       var selectedNetworkType = $('#appNetworkType').find(":selected").text();  
       $('#overview_appNetworkType').val(selectedNetworkType);  
     });  
       
    
  10. To preview the selected dropdown field value in app edit page, add below code snippet inside $(document ).ready(function() {} of  <APPM_HOME>/repository/deployment/server/jaggeryapps/publisher/themes/appm/js/resource-edit.js.
  11.    
     var selectedNetworkType = $('#overview_appNetworkType').val();  
     $( "#appNetworkType" ).each(function( index ) {  
       $(this).val(selectedNetworkType);  
     });  
       
     $("#appNetworkType").change(function() {  
       var selectedNetworkType = $('#appNetworkType').find(":selected").text();  
       $('#overview_appNetworkType').val(selectedNetworkType);  
     });  
       
    
  12. When you create a new version of an existing webapp, to copy the selected dropdown value to the new version, add below line to
    <APPM_HOME>/repository/deployment/server/jaggeryapps/publisher/themes/appm/partials/copy-app.hbs
  13.    
     <input type='text' value= "{{{snoop "fields(name=overview_appNetworkType).value" data}}}" name = "overview_appNetworkType" id = "overview_appNetworkType"/>   
       
    

    Now, Let's see how to add customized fields to the REST APIs.
  14. 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.
  15.    
     {   
        "customPropertyDefinitions":   
         [   
          {"name" : "overview_appNetworkType"}   
         ]   
      }   
       
    
  16. Restart App Manager.
  17. Web app create page with the newly added dropdown field will be shown as below. 

Wednesday, November 2, 2016

[WSO2 App Manager] How to Disable App Types

WSO2 App Manager facilitates creating, publishing, and managing Webapps, Sites, mobile applications.  By default, these three app types are enabled in WSO2 App Manager. Enabled app types has mentioned under <EnabledAssetTypeList> in <AppM_Home>/repository/conf/app-manager.xml
   
   <EnabledAssetTypeList>  
     <Type>webapp</Type>  
     <Type>mobileapp</Type>  
     <Type>site</Type>  
   </EnabledAssetTypeList>  
   

If you want to disable any app type from App Manager, you can easily do it. You just have to remove unwanted app types from above configuration and restart the server.

If you disable mobileapp from App Manager, Publisher shows as below.

Store will show like below.



If you want remove "Site" from App Manager, you have to do two additional steps. Because Webapps and Sites are using same creating and editing pages in Publisher.
You have not to allow users to create "Sites" from Publisher. For that, you have to remove the relevant div(as shown in below image) from Publisher UI.




Comment below code block of
<AppM_Home>/deployment/server/jaggeryapps/publisher/themes/appm/partialspublisher/themes/appm/partials/add-asset.hbs

   
   <div class = "form-group" type = 'hidden'>  
     <label class = "control-label col-sm-2">Treat as a Site: </label>  
     <div class = "col-sm-10 checkbox-div">  
       <input type = "checkbox" class = "treatAsASite_checkbox">  
      </div>  
   </div>  
   
   
Comment below code block of
<AppM_Home>/deployment/server/jaggeryapps/publisher/themes/appm/partialspublisher/themes/appm/partials/edit-asset.hbs

   
   <div class = "form-group" type = "hidden">  
     <label class = "control-label col-sm-2">Treat as a Site: </label>  
     <div class = "col-sm-10 checkbox-div">  
      <label>  
        <input type = "checkbox" class = "treatAsASite_checkbox"  
          value = "{{{snoop "fields(name=overview_treatAsASite).value" data}}}">  
       </label>  
     </div>