Posts

OpenAPI vs Swagger

Image
Most of the people think Swagger and openAPI is same. But, it is not. Then what are those. It is true that, until 2015, openAPI specification is called as Swagger specification. But, in 2015, SmartBear donated the fostering of openAPI to openAPI initiatives. Hence, since 2015, this specification was renamed to the OpenAPI specification.  https://smartbear.com/news/news-releases/smartbear-launches-open-api-initiative-with-key-in/ Then let me explain the difference between openAPI and Swagger. What is OpenAPI? OpenAPI is a standard specification which can be used to describe your REST API including, All the endpoints defined in your Rest API     Operations defined on each endpoint Operation parameters (input and output parameters) Request bodies Response bodies Authentication Methods (Basic, OpenID) License Information, terms of use This openAPI specification can be written in both YAML and JSON. These specifications...

PIVOT clause in Orcale

Image
PIVOT and UNPIVOT clause in Oracle - this is something I learnt recently. PIVOT and UNPIVOT is introduced from Oracle 11g version. This post will explain about PIVOT clause in Oracle. PIVOT Assume a scenario as below. You have a table which stores some parameter information. it has two columns called PARAMETER_NAME and PARAMETER_VALUE those are used to save parameter names and values. Now you get a requirement, that you need to create a new view  from old table. But, in this new view, there should be a separate column for each parameter.  To achieve this requirement, you can get help of PIVOT clause. PIVOT clause is allowed you to transpose the rows in a table to columns by aggregating the data. Hence, PIVOT clause returns the more columns and fewer rows than the starting data set (table). Syntax for PIVOT clause. SELECT      col0, col1, col2 FROM      table_name PIVOT  (   aggregate_fun...

How to generate direct line token to start a new conversation between your own client application and bot framework in Java

You can enable the communication between your bot framework and your client application using Direct Line API. When you add your client application as a site to communicate with your bot framework through azure portal, bot framework will generate secret keys. Your client application can use these generated secret keys to authenticate direct line requests issued to your bot framework. Let me explain how we can generate token to start a  conversations between your own client and bot framework. When we send a request to direct line for generating token,  if the request is successful it will send the conversation id and token that is valid to that conversation id. If client application already has a earlier used conversation Id, you can pass that id as an input to this method for generating token. If there is no conversation id, you can pass null value.  Return type of this method is a Map to retrieve generated token and conversation Id which is valid for that to...

How to traverse through a given json string

Recently, I came across a scenario that requires to traverse through the json property keys and values of a given json object. Add below maven dependency into the pom file of the project. <dependency>             <groupId>org.json</groupId>             <artifactId>json</artifactId>             <version>20180130</version> </dependency> Below three method will help to traverse through the json object void iterateJSONObject(JSONObject jsonObject) {         jsonObject.keys().forEachRemaining(key -> {             Object value = jsonObject.get(key);             System.out.println("Key: " + key);             iterateValue(value);         });     }       void iterateJSONArray(JSONAr...

How to convert Json property names of a given Json String to Title case using regular expression in Java

Image
Recently I came across a requirement to convert json property names of given Json string to title case. Let me explain it with a example. Assume you have below json string. Now you want to convert json property names to title case or to make first letter of the property name to upper case. You can write the code as below. You will get output as,

Responsible use of AI

The Sri Lanka Association for Software and Service Companies (SLASSCOM) successfully hosted ‘SLASSCOM AI ASIA Summit 2019’ for the second consecutive year on 6th of November at the Shangri-La, Colombo. While more than 400 participants took part to this event, eminent experts in AI from diverse industrial and academic backgrounds spoke about different interesting topics related to AI. Out of these interesting topics, Dr. Inga Strumke, Manager - AI and Mac hine Learning at PwC Norway, shared an important AI factor which is vital from both business and software engineering perspective. It is ‘Responsible use of AI’ What is Responsible AI? Assume you want to translate ‘She is a doctor. He is a nurse. ’ from English to Hungarian using a language translator which is using AI. You will get it as ‘Ő egy orvos. Ő egy nővér.’ . And then again, if you translate it from Hungarian to English using same translator, you will get it as ‘He is a doctor. She is a nurse.’ Even ...

How to create a Server which accepts Client Certificate in Java

When you need to create a server which is requiring client certificate, you can use below code for that. package testserver; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.net.InetSocketAddress; import java.security.KeyStore; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLParameters; import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManagerFactory; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpsConfigurator; import com.sun.net.httpserver.HttpsExchange; import com.sun.net.httpserver.HttpsParameters; import com.sun.net.httpserver.HttpsServer; public class TestServer {     /**      * @param args the command line arguments      */     final static String Server_Password = "password";     final static String keystore = "D://NetbeansProjects/...

Generating XML using DBMS_XMLGEN

DBMS_XMLGEN  Oracle package is used to convert the result of sql query to a XML format and returns it as a CLOB . First, Create a sql as below. stmt_   VARCHAR2(32000) ;  ctx_    dbms_xmlgen.ctxHandle; xml_    XmlType; role_   VARCHAR2(20) := 'ENDUSER'; stmt_ := 'SELECT                t.role,                t.description,                t.created CREATED_DATE,                CURSOR(SELECT grant_id                         FROM system_grant_tab                         WHERE role ='''|| role_||'''                         ORDER BY nlssort(grant_id, ''nls_sort=binary'')) SYSTEM_GRANTS     F...

'Can't Find Project Or Library' in MS Excel 2010

Image
To resolve this issue you can use below workaround. Open the Excel Click 'ALT +F1' to switch to the Visual Basic Editor Go to Tools -> References Click to clear the check box of the library which is marked as Missing and then click 'OK' Or Restore the referenced file in the path which is shown in the dialog box Or  If the referenced file is in a new location,clear the Missing reference and Create a new reference to that  file.   This link provides the more information about this issue :  http://support.microsoft.com/kb/282331

How to prevent the user from typing in the windows application combo box

Image
If you need to prevent the user from typing in the windows application combo box, property called ‘Dropdown Style’ should be changed from ‘Drop Down’ to ‘Dropdown List’. Normally, default value of the ‘Dropdown Style’ is ‘Drop Down’ and this allows user to type in the combo box.

How to deploy multiple PLSQL files at once

Image
This article describes how to deploy multiple pl/sql files (.api, .sql, .etc) at once using command prompt. First of all you have to store names of the plsql fiels in a text file in below way and save it in the folder where your plsql files are saved. Then open the command prompt and  change directory path to where your plsql files and text file is saved. Then type below commands in the command prompt and press enter. sqlplus/nolog conn username/password@service_name Then write @ sign and drag and drop the text file to command prompt or type the path of the text file. Press enter button. Do not forget to type @ sign before the path of the text file. Now all oracle files included in text files are deployed in your oracle database at once. If there are any compile errors in your db files, those are shown in the command prompt clearly. If There are more db files, it is difficult to type all file names in the text file. So you can create a script for this. Ope...

Conditional Compilation in Oracle

What is Conditional Compilation? PL/SQL source code is compiled selectively based on the compiler directives. Therefore, in the compile time code can be different according to conditions. Why do we need Conditional Compilation? Using conditional compilation features, we can include version specific features to our PLSQL source code. Therefore, In any production environments which use different versions,  Code is compiled and application is running properly without any issue. Assume, in development environments, we have developed multiple components such as component A for finance, component B for manufacturing, and component C for Sales. Now if we call methods written in component B for packages in component C, there is no issue when compiling and running particular code since all the components are properly deployed in the development environment. But, assume one of our customers install only component C in production environment, now when compiling the codes it gives e...

Create your own custom search engine

Google has provided its users to create a simple and powerful custom search engine. You can follow below simple steps to crate your own search engine Go to http://www.google.com/cse Give URL of the sites that you need to emphasize when searching, select the language and give a name to search engine.  Then you  will get your own search engine.  Then Start to search :)) This allows users to get uninterrupted browsing experiences with speed and simple search.

Is your computer boy or girl?

Would you like to know that your computer is a girl or boy? If so Try this :) Open your notepad Copy and paste CreateObject("SAPI.SpVoice").Speak"Hi Darling, How are you"  Save as computer_sex.vbs Run the file Now what you  hear? If you hear a male voice you have a boy computer, if it is a female voice, well, you have a girl computer. I have a boy computer :)). How is yours??  Also you can get the name of the voice owner by including below code. Set VObj = CreateObject("SAPI.SpVoice") For Each Voice In VObj.getvoices I = I + 1 VObj.Speak "Hello I am " & Voice.GetDescription & " and Nice to meet you" Next   

Override Methods in C#

In C#, when we override methods we have to keep remember some important points. Assume there is a parent class called ClassA and it has a method called method().  If we are going to override that method in  a subclass ClassB, we have to use virtual and override keywords properly in suitable places. virtual should be used with method() in parent class and  override should be used with method() in sub class. If we do not use these keywords properly Overridden functionality  is not working properly.  namespace BasicLangEx {     class ClassA     {         public virtual void method()         {             Console.WriteLine("Method A");         }     } } namespace BasicLangEx {     class ClassB : ClassA     { ...

Tips to Tune SQL Queries

In this post I hope to give some knowledge about the Oracle Execution plan and  the some tips to optimize sql queries for better performances. Execution Plan Oracle can run Explain plan for given SELECT, INSERT,UPDATE, DELETE SQL  statements as below Oracle - EXPLAIN PLAN FOR SELECT customer_name FROM CUSTOMER; MySql -   Explain SELECT customer_name FROM CUSTOMER;   Then it displays the execution plan chosen by the Oracle optimizer, which contains the  sequence of operations used to run a particular sql statement. Execution plan contains,  tables, views referenced by the statement access methods for each tables and views (table access full,table access by index) join methods data operations such as sort, aggregate cost, cardinality parallel executions   According to the execution plan you can get the idea to optimize a given sql statement in  a proper way.Now I am going to explain the ways that can be used to tune/optimize the...