Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Monday, April 11, 2016

Execute DDL scripts when a spring application is initialized

Normally everyone would encounter a situation where in they want to execute few of the database scripts while deploying a solution. These scripts might include anything like executing a procedure, running a batch, insert script for defaulting of few values, update to existing dataset etc., 

When such situation arises, we can follow the below mentioned approach as an initial approach to handle it.

Spring by default tries to load a script file "data.sql" located in the classpath i.e., where the application.properties, log4j.properties etc., are present. 

Hence try to consolidate all the scripts into one file and name it as "data.sql" and place it under "<<apacheTomcatFolder>>\webapps\<<app>>\WEB-INF\classes", 

Disadvantages of this approach :
  • Since it is an automated process, any failure in the execution of scripts will not be known unless we go through the log files. Hence error percentage should be minimum.
  • Using the above approach, we cannot divide all the scripts into different modules and execute with different names. By default the spring will look for a file named "data.sql" unless someone overrides this setting in application.properties which is not explained in this blogpost.
  • A restart is needed for every change in this file. Try to use only when the script is flawless and also can be executed during the deployment. If there is a provision to execute the scripts in database then try to use that as it will provide more control over the scripts that will be run.

Friday, December 26, 2014

What is script connector and how to configure it ???

This post is to understand about "Script connector" and how to configure it. Understanding the necessity of script connector is best explained by explaining about the environment that I have been experienced to.

Without script connector :

I was a part of a team which works  on a framework called "Cordys" and which leverages the usage of its connector capability (able to connect to different systems which are in different platforms like .net, java etc.,) using pre-built connectors like UDDI, SAP Connector etc., As a part of the project we need to integrate with couple of systems and build a process performs a functionality by integrating with those systems. We use UDDI services, SAP Services etc., Hence the development of the process is a lot dependent on the implementation and availability of these services without which we won't be able to finish the implementation of the process.

It would be ideal if we remove this dependency and implement it. There is a way to implement it using a connector built by coe team of cordys which is "Script Connector". Advantages of script connector are 
  • It mimics the response(user configured response) from different system and hence we won't be depending on the availability of the main system instead we create a dummy system which responds like the way main response does.
  • Implementation would be very smooth and doesn't need to depend on any other system.
  • All possible cases can be tested without even bothering the main system.
How to mimic the response  :

There are many ways to replicate the main system by dummy system, current explanation deals with mimic-ing the response by custom logic by retrieving the mimic-ed response from xml store of cordys. 

Initial configuration of script connector : 
In order to have script connector completely configured we need to install the script connector isvp in the environment. My cordys environment is "BOP4.1CU6", hence I would install an ISVP and this isvp can be found out from cordys wiki at this particular link,
https://wiki.cordys.com/display/dsc/Script+Connector
Step 1 : Install the isvp


Step 2 : Go to your organization and try creating a new container. You will be finding a new entry for script connector as shown below,

Step 3:  Go ahead and create the container normally.

Extra configuration to be made :

Here in this section this extra configuration is to be done in order to mimic the response for your service.

Step 4 : Find out what is the web service which you want to mimic. In my case it is "ConversionRate" for which I need to connect to internet and I don't have internet, hence I need to remove this dependency by using script connector.

Step 5 : Edit config.properties file located in the directory 
<<CordysInstalledDirectory>>/coe/scriptconnector/config.properties by adding the below property

*=scripts/all.js  --- This property says any service that you want to mimic can go and refer all.js file. Actual implementation is done at all.js file. I will try to attach all.js file as a comment to the blog post. One must have this file at the location 
<<CordysInstalledDirectory>>/coe/scriptconnector/scripts/.


Step 6 : Have all.js file in the location mentioned above.



Step 7 : According to the implementation in all.js, we must configure our custom response in xml store. The mandatory things we need to make sure are,
  • We must have a folder in xml store as shown below
    • Collection->scriptconnector->all.js
  • Now create a folder with the same name as your "WebServiceOperation" in my case it is "ConversionRate".
  • Now create an Item with any name but which ends with suffix "-Cur" and put any response in that item. In my case it is "success-Cur". All these steps are shown in the below figure,


Step 8 : Attach the interface to be tested to script connector and test it. You would see the same response which you configured in the xml store.



After testing with all possible cases and when we are done with the development from our side we can port these contents to whatever environment you want and connect the interface to the real system instead of script connector. Script connector should be used only in the development environment and not encouraged to be used in any other environments apart from development.     

Thursday, February 20, 2014

How to check where is syntax error in javascript?

By simply looking at a javascript file one cannot say where is the syntax error (if any). And there is no compiler as such during our development which will say that. We simply write DOM methods or functions in the javascript unlike Java (Eclipse is a tool which will validate the source code during development). But this is not available in javascript. However during development of any application in cordys there will be a place where you add events/javascript functions in any XForm. Cordys will be able to tell if the XForm has any errors but it won't tell where exactly the error is (eg., will not tell the line number of the error) which will make difficult for a developer to locate where exactly is the error,

There is an online website which will validate the javascript and will notify the error if there are any,

All you have to do is to copy the javascript and paste in the place provided in the website. A sample screen is shown below


And the website you are looking for is given below

http://www.javascriptlint.com/online_lint.php

On Click of the lint button it will show the errors if there are any in the javascript file.