Thursday, August 20, 2015

MongoDB as a Service

Command to create mongodb as a service is 

mongod --dbpath="C:\Program Files\MongoDB\data" --logpath="C:\Program Files\MongoDB\log\log.txt" --install

Execute above command from Mongodb's bin folder,




References :

http://www.mkyong.com/mongodb/how-to-run-mongodb-as-windows-service/

http://stackoverflow.com/questions/2438055/how-to-run-mongodb-as-windows-service

Wednesday, August 19, 2015

Command to publish jar into your local Maven Repository


D:\Kiran\Kiran\Projects\NCB\ETL>mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.0.3 -Dpackaging=jar -Dfile=ojdbc6.jar
 -DgeneratePom=true

Points to be noted :

  • Maven client to be installed. You can check if maven is installed by running the below command ,
    mvn -version which would result in the below result,



  • Executing above command  results in below results,


Once you see the BUILD SUCCESS in the above command result,

You can add dependency in your POM.xml as below,

                <dependency>
<groupId>com.oracle</groupId> <!-- Group ID from the command-->
<artifactId>ojdbc6</artifactId>  <!-- Artifact ID from the command-->
<version>11.2.0.3</version>       <!-- Version from the command-->
</dependency>

References :


Saturday, July 25, 2015

How to know what version of OS you are running

Command to show the os version of windows,

Open command prompt and type in the below command

wmic os get osarchitecture


Thursday, July 16, 2015

Serialize manually using faster jackson library in spring

I am trying to get a JSON Structure for my object Order which internally has OrderDetails as oneToMany mapping,

@Entity
public class Order {    
    /*
        All the fields associated with this class
    */      
    @OneToMany(fetch = FetchType.EAGER, mappedBy = "orderId")
    private Set<OrderDetails> orderDetails;

    //Getters for all properties defined in this class as jackson would depend on this thing
}
In my case I am using a textWebSocket which is expecting a message only in String format so I need to serialize the objects and push to the client, I am depending on faster jackson to do it and here it goes,

public String getObjectAsString()
{

    //orderObjs : Considering this is the list of objects of class Order

    ObjectMapper objMapper = new ObjectMapper();
            returnValue = objMapper.writerWithType(
                    objMapper.getTypeFactory().constructCollectionType(
                            List.class, Order.class)).writeValueAsString(
                    orderObjs);
    return returnValue;
}

objMapper.writerWithType(objMapper.getTypeFactory().constructCollectionType(List.class,Order.class)).writeValueAsString(orderObjs);

Monday, July 6, 2015

Use a new keyword and still inject the object : Spring

Spring works on dependency injection. This means there is no need to create an object explicitly, spring will do it for you.

But there are situations where you have to create new objects (ex., Reflection). By going with this approach you are conveying string that you will have control over the current object. i.e., any Autowired fields inside the object class will be null and spring will not consider injecting it. 

But there is a way to autowire those fields as well,

appctx.getAutowireCapableBeanFactory().autowireBean(wsdlParserAPIObject);

where appctx is ApplicationContext which is autowired.

http://stackoverflow.com/questions/31237062/using-class-forname-but-want-to-autowire-members-of-the-target-class

Monday, June 29, 2015

Call a procedure from Spring

How to call a procedure using spring :

In this blog post I would take you through the approach of calling a procedure from spring using "StoredProcedure" approach.

StoredProcedure is an abstract class which has to be extended.

Define a class which extends StoredProcedure, below is a sample which is shown,

Then call a procedure which is shown as below,





Friday, June 26, 2015

Autowire datasource while using JdbcDAOSupport

public class EntityDAO extends JdbcDaoSupport{

Logger logger = LoggerFactory.getLogger(EntityDAO.class);

@Autowired
private DataSource datasource;


/*
* Setting data source as it extends jdbcDAOSupport
*/
@Autowired
private void initialize()
{
setDataSource(datasource);
}

Wednesday, May 20, 2015

Comparing arrays in Java Script

A sample on how to compare two arrays :


Array.prototype.diff = function(a) {
    return this.filter(function(i) {return a.indexOf(i) < 0;});
};
var a = ['b','c'];
var b = ['b','c','d','e','f'];
var temp = a.diff(b);
temp.length;

Credits : Nikhil

Friday, April 10, 2015

Queries for faster development

Concatenation of column values :

I want to concatenate one column values and get it as an aggregated result from database,

For Eg :

EMAIL_ADDRESS 

kiran.joshi@darkhorseboa.com
j.kiran809@gmail.com
j.kiran@alahli.com

Result should be something like this

<to><address><emailAddress>kiran.joshi@darkhorseboa.com</address><address><emailAddress>j.kiran809@gmail.com</emailAddress></address><address><emailAddress>j.kiran@alahli.com</emailAddress></address></to>

This can be achieved in SQL Server using STUFF function and the link can be found here

http://learnings.joshikiran.com/2014/10/how-to-use-stuff-keyword-in-microsoft.html

In Oracle it can be achieved by,

SELECT 
  '<to>'||LISTAGG('<address><emailAddress>'||EMAIL_ADDRESS||'</emailAddress></address>','')
    WITHIN GROUP (ORDER BY COLUMN3)||'</to>' AS ALIAS_ID
FROM TABLE1
WHERE COLUMN2 = 'sample' AND EMAIL_ADDRESS IS NOT NULL;

Note : This works for Oracle version 11g R2 and higher only.

Credits : PadmaPriya Iyengar
----------------------------------------------------------------------------------------------------------------------

Tuesday, April 7, 2015

Authenticator is not instantiated via the properties constructor

I am triggering a SOAP request from SOAP UI to a custom gateway of cordys environment which accepts user credentials in SOAP header.

For Ex :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:oas="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns="http://corp.alahli.com/middlewareservices/header/1.0/" xmlns:ns1="http://corp.alahli.com/middlewareservices/test/1.0/">
<soapenv:Header>
<oas:Security>
<oas:UsernameToken>
<oas:Username>${#Project#username}</oas:Username>
<oas:Password>${#Project#password}</oas:Password>
</oas:UsernameToken>
</oas:Security>
</soapenv:Header>
<soapenv:Body>
<!-- Main SOAP Request which is connected to service group SG1-->
</soapenv:Body>
</soapenv:Envelope>

Content which is shown in green color is the security information which I am passing from SOAP UI. I hope people are well aware what ${#Project#username} stands for (i.e., I am reading credentials from properties of SOAP Project).

Let's say the request is targeted to service group SG1 in this case. 

As we know that any cordys service is served using SAMLArt. In this case the SAMLArt will be provided by the custom gateway to the application container. Now when the custom gateway tries to get the SAMLArt it uses the property of the application container. If it does not find the property it might throw you an error which was my case.

I encountered an exception which says something like this,

com.eibus.security.authentication.InvalidAuthenticatorException: Authenticator is not instantiated through the properties constructor.
at com.eibus.security.authentication.AuthenticatorFactory.getAuthenticator(AuthenticatorFactory.java:78)
at com.eibus.security.identity.WSSecurityUsernameTokenIdentityType.validate(WSSecurityUsernameTokenIdentityType.java:64)
at com.eibus.soap.SOAPTransaction.<init>(SOAPTransaction.java:349)
at com.eibus.soap.SOAPTransaction.<init>(SOAPTransaction.java:175)
at com.eibus.soap.Processor.onReceive(Processor.java:970)
at com.eibus.soap.Processor.onReceive(Processor.java:943)
at com.eibus.connector.nom.Connector.onReceive(Connector.java:417)
at com.eibus.transport.Middleware$NonTransactionalWorkerThreadBody.run(Middleware.java:1758)
at com.eibus.util.threadpool.WorkerThread.run(WorkerThread.java:64)

Now I found out the property that was missing i.e., the authenticator class. We need to add the authenticator property to the service group that was implementing my service. This should be done by using LDAP explorer,

The property which is to be added is below,

<authenticator implementation="com.eibus.security.authentication.CARSAuthenticator" /> 

Since I am using CARSAuthenticator in my case. This should be added to the service group SG1 (in the above explained scenario). An example of such updation can be found below,



 

Saturday, April 4, 2015

Usage of elementFormDefault attribute of Schema tag

Learnings from Gora (amitagl27@gmail.com)

I was creating a WSDL in my project to generate contract first webservices. 

When I imported the WSDL in cordys, it gave me empty namespaces just after the attributes, i.e. it looked something like this :

<!--Cordys Input Structure-->

<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP:Body>
    <CreateForeclosureProcess xmlns="http://schemas.bas.com/ext/IntakeProcessServices/">
      <CaseId xmlns="">PARAMETER</CaseId>
    </CreateForeclosureProcess>
  </SOAP:Body>
</SOAP:Envelope>

<!-- External Tool input Structure, Wizdler (https://chrome.google.com/webstore/detail/wizdler/oebpmncolmhiapingjaagmapififiakb?hl=en)-->

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <CreateForeclosureProcess xmlns="http://schemas.bas.com/ext/IntakeProcessServices/">
            <CaseId xmlns="">[string]</CaseId>
        </CreateForeclosureProcess>
    </Body>
</Envelope>

I did two things to remove these namespaces.

1. To remove from Cordys : Instead to having a direct element in my Request schema, I created a reference to another element.

Old :

<xsd:element name="CreateForeclosureProcess">
         <xsd:complexType>
          <xsd:sequence>
 <xsd:element  type="xsd:string" name="CaseId" />           
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>

Modified :

<xsd:element name="CreateForeclosureProcess">
         <xsd:complexType>
          <xsd:sequence>
 <xsd:element ref="tns:CaseId" />            
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
  
  <xsd:element  type="xsd:string" name="CaseId" />

 2. Even after doing this, the Wizdler plugin was still showing the empty namespace, then a little research on web gave me following link :

http://docs.intersystems.com/ens20082/csp/docbook/DocBook.UI.Page.cls?KEY=GSOP_service_fine_tuning

which suggested to add 

elementFormDefault='qualified'
to my schema tag as an attribute.

Example :
<xsd:schema targetNamespace="http://www.darkhorseboa.org/ThirdPartyUtilities/" elementFormDefault="qualified">

Friday, March 27, 2015

Learnings on FTPClient class of Apache

Exploration is very good for a person but sometimes there wouldn't be a proper location where you get what you need. This was one of those instances in my exploration phase and hence I would like to share the learnings of FTPClient class.

Problem Statement : ftpClientObject.getTimestamp() is not returning time in seconds field.

Explanation :

My code is something like below,

private static void getFTPFileProperties(FTPClient client,
            String ftpLocation, String pattern) throws IOException {
    FTPFile[] fileList=null;
    fileList = client.listFiles();
    for(int i=0;i<fileList.length;i++)
    {
        FTPFile file= fileList[0];
        Calendar cal = file.getTimestamp();
        DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(dateFormater.format(cal.getTime()));
    }
}
From the above, variable cal is should ideally retrieve timestamp which will be having even seconds field. But somehow I am able to view the date part and only the hours part. The timestamp is carrying 00 in minutes and also in seconds.

Myself being helpless posted this question in stackoverflow and thankfully Martin has caught my problem absolutely right.

Reason : listFiles() will function something like ls command of unix and thus it might not retrieve the entire timestamp part. It is suggested to use mlistDir() function in order to get the entire timestamp. But only condition the method mlistDir is defined in Apache Commons 3.0 version and I was using Commons 2.0 which was the problem. The moment I changed it to Apache Commons 3.0 it started working.

There is also a function client.getModificationTime("upload/01%20(160).jpg"); which might give the same result but this also has limitations when Commons 2.0 is used.

http://www.programdevelop.com/1506369/ would make you understand what is the problem.

Thanks to Martin who has helped me in addressing my issue and thanks to stack overflow in helping me post it.

Reference :

http://stackoverflow.com/questions/29300686/ftpclient-listfiles-is-not-returning-time-in-seconds 

Tuesday, March 24, 2015

Get Amount in words from query : SQL Developer

Below query helps you get the amount in words and also in camel case

SELECT INITCAP(TO_CHAR(TO_DATE(ROUND(AMOUNT),'J'),'JSP')) AS AMOUNT_WORDS_CAMEL_CASE FROM DH_EXPLORATION;

Below screenshot is self explanatory,



In the query mentioned, TO_DATE is used to get the amount in words and INITCAP is used to get the amount in words as camel case.

Learnings : From GIB  

Sunday, March 15, 2015

Auto Login into windows user accounts

The user account in any computer is a security measure but we tend to be always in a situation where we are sure that only we will be using and at time this security measure might become a bit tedious thing. So in order to remove this user Id login situation we can make achieve this using windows functionality,

Padding 0's in XSLT

I want a string to be fixed to 10 digits and pad 0's if it is less than length 10. This I have to achieve in XSLT here is how we can do it,

substring(concat("0000000000",string(//b/text())),string-length(//b/text())+1)

Assuming //b will have the string which is to be formatted.

Where as the same can be achieved using String functions in java,

String.format("%010d", 1236)




Friday, March 13, 2015

Change default program from command line

Sometime we wont be able to open an executable jar using default program after some infinite attempts using "open with". I have faced similar problem as there is a jar which I have to open using javaw.exe and somehow I was unable to. So here is what I have did,

I have changed the default program of jarfile using command line and awesome thing is "IT WORKED" :P

here is the command,

 
And then I opened the jar and It worked,


Monday, March 9, 2015

How to change oracle user's password if it is expired

Problem statement : I am trying to connect to database using sql developer and it throwed an error saying "the password has expired" and I find it really difficult to change the password from oracle homepage (ver 11).

Resolution : Open the oracle client and connect using your username and password.  It will automatically ask for change password.

Strange thing is there are no password policies at all. You can keep the old password itself for new password :P


Tuesday, February 24, 2015

Custom date format in XForm

I want to display the date time in xform in a specific format like '20/02/2015 11:23 PM'

This can be by specifying format in the following way,

'dd/MM/yyyy shorttime' or 'dd/MM/yyyy longtime'

dateformats which are defined in cordys are below :


Right click on the field and select format and specify the format as mentioned below


Runtime display of the time which you have selected above 


Thursday, January 29, 2015

XPath for the node with maximum value for a particular element : XPath1.0

Here is the list of bond characters played in bond movies and their earnings from movies,

<JamesBondCharacters>
<JamesBond>
<Name>Sean Connery</Name>
<Earnings>40000</Earnings>
<Currency>GBP</Currency>
</JamesBond>
<JamesBond>
<Name>Roger Moore</Name>
<Earnings>55000</Earnings>
<Currency>GBP</Currency>
</JamesBond>
<JamesBond>
<Name>George Lazenby</Name>
<Earnings>20000</Earnings>
<Currency>GBP</Currency>
</JamesBond>
<JamesBond>
<Name>Timothy Dalton</Name>
<Earnings>25000</Earnings>
<Currency>GBP</Currency>
</JamesBond>
<JamesBond>
<Name>Pierce Brosnan</Name>
<Earnings>70000</Earnings>
<Currency>GBP</Currency>
</JamesBond>
<JamesBond>
<Name>Danial Craig</Name>
<Earnings>30000</Earnings>
<Currency>GBP</Currency>
</JamesBond>
</JamesBondCharacters>

From this list I want to get the Bond details who earned the highest and least during his time. This example is just taken for fun to understand the XPath. 

To get the highest earned bond details use the below XPath

//JamesBond[not(./Earnings<//JamesBond/Earnings)]

To get the least earned bond details use the below XPath

//JamesBond[not(./Earnings>//JamesBond/Earnings)]

Note : The XPath which we used here is valid in XPath1.0. Alternatively you can check the same here in the below link

http://www.online-toolz.com/tools/xpath-editor.php

Credits :
GIB Learnings from Anitha and Padma Priya Iyengar