Search This Blog

Tuesday, November 8, 2016

How to fetch from list of nested list- Dynamic Loop

Assume the bean is like below, CommentsBean has CommentsBeanlist.

public class CommentsBean {

int id;
int parentId;
String msg;
List commentsBeanList;

public CommentsBean() {

}

public CommentsBean(int id, int parentId, String msg) {
super();
this.id = id;
this.parentId = parentId;
this.msg = msg;
}

@Override
public String toString() {
return "CommentsBean [id=" + id + ", parentId=" + parentId + ", msg=" + msg + ", commentsBeanList="
+ commentsBeanList + "]";
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getParentId() {
return parentId;
}

public void setParentId(int parentId) {
this.parentId = parentId;
}

public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}

public List getCommentsBeanList() {
return commentsBeanList;
}

public void setCommentsBeanList(List commentsBeanList) {
this.commentsBeanList = commentsBeanList;
}


}


Program to extract that dynamically.

public class DynamicListLoop {

public static void main(String[] args) {
List commntsBeanList = new ArrayList<>();
List commntsBeanChildList1 = new ArrayList<>();
List commntsBeanChildList11 = new ArrayList<>();
CommentsBean commentsBeanchild20 = new CommentsBean(4,-1, "second");
CommentsBean commentsBeanchild21 = new CommentsBean(5,4, "second-child-1");
commntsBeanChildList11.add(commentsBeanchild20);
commntsBeanChildList11.add(commentsBeanchild21);
CommentsBean commentsBeanchild2 = new CommentsBean(3,2, "first-child-2");
CommentsBean commentsBeanchild = new CommentsBean(2,1, "first-child-1");
commentsBeanchild.setCommentsBeanList(commntsBeanChildList11);
commntsBeanChildList1.add(commentsBeanchild);
commntsBeanChildList1.add(commentsBeanchild2);
CommentsBean commentsBean = new CommentsBean(1,-1, "first");
commentsBean.setCommentsBeanList(commntsBeanChildList1);
commntsBeanList.add(commentsBean);
System.out.println(commntsBeanList.toString());
//write a function and pass the parent bean list.
commentsBeanParseInLoop (commntsBeanList );

}
public static void commentsBeanParseInLoop ( List commntsBeanList )
{
if ( commntsBeanList!=null && commntsBeanList.size() > 0 )
{
for ( CommentsBean cb : commntsBeanList )
{
System.out.println(cb.getId() + " : " + cb.getMsg() );
if ( cb.getCommentsBeanList() !=null && cb.getCommentsBeanList().size() > 0 )
{
//call the same function and pass the inner bean list
commentsBeanParseInLoop ( cb.getCommentsBeanList() );
}
}
}
}

}

Thursday, October 13, 2016

Nodejs nodemailer - Send Email

1. go to cmd prompt in your root project folder 
   Type npm install nodemailer


2. create mail.js

var express = require('express');
var nodemailer = require("nodemailer");
var smtpTransport = require("nodemailer-smtp-transport")
var app = express();

var smtpTransport = nodemailer.createTransport(smtpTransport({
    host : "smpt.gmail.com",
    secureConnection : false,
    port: 587,
    auth : {
        user : "drvijayy2k2@gmail.com",
        pass : "test123"    }
}));
app.get('/send',function(req,res){
    var mailOptions={
        from : "drvijayy2k2@gmail.com",
        to : "drvijayy2k2@gmail.com",
        subject : "Your Subject",
        text : "Your Text",
        html : "HTML GENERATED",
        /*attachments : [
            {   // file on disk as an attachment                //filename: 'a.txt',                path: 'd:/a.txt' // stream this file, use only path property and send the file name in the end, else you may get folder read error            }
        ]*/
    }
    console.log(mailOptions);
    smtpTransport.sendMail(mailOptions, function(error, response){
        if(error){
            console.log(error);
            res.end("error");
        }else{
            console.log(response.response.toString());
            console.log("Message sent: " + response.message);
            res.end("sent");
        }
    });
});

app.listen(3000,function(){
    console.log("Express Started on Port 3000");
});



3. Go to command prompt where the mail.js stored
    Type node mail.js



4. open brower
 http://localhost:3000/send



Wednesday, October 12, 2016

NodeJs VelocityJs in web app - Template Engine

just create a sample  velocity-text.js  file.

/** * Created by drvijay on 12-10-2016. */
   var context = {
        "name": "velocity"    }

var initialString = "Hello, ${name}!";

var velocityjs = require("velocityjs");
var renderedString = velocityjs.render(initialString,context);
console.log(context);
console.log(initialString);
console.log(renderedString);


// go to cmd type node velocity-text.js



INSTALL

First install velocityjs in your node_modules

npm install velocityjs

Now from your project (where the node_modules mentioned above exists) use browserify

browserify -r velocityjs  > velocity.js

This will create a velocity.js file that you can include in your website directly. If you don't have browserify then do npm install -g browserify

Usage

In your webpage js file first require velocityjs

var velocityjs = require("velocityjs");

Now to get the templated html do

var renderedString = velocityjs.render(initialString,context)

Note that velocity does not care if your initial string was html or not, you need to ensure that

NodeJs VelocityJs in web app - Template Engine

just create a sample  velocity-text.js  file.

/** * Created by drvijay on 12-10-2016. */
   var context = {
        "name": "velocity"    }

var initialString = "Hello, ${name}!";

var velocityjs = require("velocityjs");
var renderedString = velocityjs.render(initialString,context);
console.log(context);
console.log(initialString);
console.log(renderedString);


// go to cmd type node velocity-text.js



INSTALL

First install velocityjs in your node_modules

npm install velocityjs

Now from your project (where the node_modules mentioned above exists) use browserify

browserify -r velocityjs  > velocity.js

This will create a velocity.js file that you can include in your website directly. If you don't have browserify then do npm install -g browserify

Usage

In your webpage js file first require velocityjs

var velocityjs = require("velocityjs");

Now to get the templated html do

var renderedString = velocityjs.render(initialString,context)

Note that velocity does not care if your initial string was html or not, you need to ensure that

Thursday, September 29, 2016

Upload a file to SFTP using java

package com.sftp;

import java.io.File;
import java.io.FileInputStream;

import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;

/**
 * @author drvijay
 */

public class SFTPcallInJava
{

public static void main ( String [] args )
{
String SFTPHOST = "192.168.7.99";
int SFTPPORT = 2121;
String SFTPUSER = "vijayjava";
String SFTPPASS = "vijaytest123";
String SFTPWORKINGDIR = "/www/";

Session session = null;
Channel channel = null;
ChannelSftp channelSftp = null;

try
{
JSch jsch = new JSch ();
session = jsch.getSession ( SFTPUSER, SFTPHOST, SFTPPORT );
session.setPassword ( SFTPPASS );
java.util.Properties config = new java.util.Properties ();
config.put ( "StrictHostKeyChecking", "no" );
session.setConfig ( config );
session.connect ();
channel = session.openChannel ( "sftp" );
channel.connect ();
channelSftp = (ChannelSftp) channel;
channelSftp.cd ( SFTPWORKINGDIR );
File f = new File ( "D:/Temp/aamlog.txt" );
channelSftp.put ( new FileInputStream ( f ), f.getName () );
}
catch ( Exception ex )
{
ex.printStackTrace ();
}

}

}



NOTE - Add jsch-0.1.54.jar

Tuesday, September 20, 2016

STEPS FOR INSTALLING AND CONFIGURING THE APACHE SOLR IN TOMCAT x.x

STEPS FOR INSTALLING AND CONFIGURING THE APACHE SOLR
====================================================


1. copy the solr.war file and place into somewhere in the machine

2. copy the 'solr' folder which contains all cores , and place into some where in machine

3. add 'solr.xml' file  in "tomcat server\conf\Cataline\localhost\"

example: X:\apache-tomcat-8.0.32\conf\Catalina\localhost\solr.xml

4. in 'solr.xml' file we have to specify the path of 'solr.war' and 'solr' folder of cores.

           a)docBase for 'solr.war'  file
           b)environment value for 'solr' folder of cores


solr.xml
---------------



 

-------------



5. Run the tomcat server

  ex:localhost:8080

6. Run the solr admin console

  ex:localhost:8080/solr


7. You will get dashboard of 'solr'  and left side of main page you will get all the cores, which we have from 'solr' folder as specified point number 2.

8. the select the 'query result' and 'execute'



NOTE: Core we have to create manually  , and index the data with datatype manually into each cores.


by
naren


Friday, August 26, 2016

GIT Switch branch or SVN Relocate Changing a remote's URL

  1. 1. Open Git Bash.
  2. 2. Change the current working directory to your local project.
  3. 3. List your existing remotes in order to get the name of the remote you want to change.
    git remote -v
    origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
    origin  git@github.com:USERNAME/REPOSITORY.git (push)
    
  4. 4. Change your remote's URL from SSH to HTTPS with the git remote set-url command.
    git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git
    
  5. 5. Verify that the remote URL has changed.
    git remote -v
    # Verify new remote URL
    origin  https://github.com/USERNAME/OTHERREPOSITORY.git (fetch)
    origin  https://github.com/USERNAME/OTHERREPOSITORY.git (push)
    

GIT Switch branch or SVN Relocate Changing a remote's URL

  1. 1. Open Git Bash.
  2. 2. Change the current working directory to your local project.
  3. 3. List your existing remotes in order to get the name of the remote you want to change.
    git remote -v
    origin  git@github.com:USERNAME/REPOSITORY.git (fetch)
    origin  git@github.com:USERNAME/REPOSITORY.git (push)
    
  4. 4. Change your remote's URL from SSH to HTTPS with the git remote set-url command.
    git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git
    
  5. 5. Verify that the remote URL has changed.
    git remote -v
    # Verify new remote URL
    origin  https://github.com/USERNAME/OTHERREPOSITORY.git (fetch)
    origin  https://github.com/USERNAME/OTHERREPOSITORY.git (push)
    

Tuesday, June 14, 2016

Slim Framework - Global PHP reference Steps Installation

1. Download composer_setup.exe for windows
install it -> select php.exe from xampp/php/


2 Copy composer.phar from C:\ProgramData\ComposerSetup\bin [hidden folder] to D:\php\ [apache root directory]

3. type to install vendor folder [slim setups]
    D:\php> php composer.phar require slim/slim

4. create your root folder (ex: test) and in your index.php..
    add ../vendor/autoload.php

ex:index.php
 
   
    use \Psr\Http\Message\ServerRequestInterface as Request;
    use \Psr\Http\Message\ResponseInterface as Response;

    require '../vendor/autoload.php';

    $app = new \Slim\App;
    $app->get('/', function (Request $request, Response $response) {
         $response->getBody()->write("Welcome");
    });

    $app->get('/home/{name}', function (Request $request, Response $response) {
        $name = $request->getAttribute('name');
        $response->getBody()->write("Hello, $name");
   
        return $response;
    });
    $app->run();




5. run apache and in browser    http://localhost:8888/test/




Slim Framework - PHP Install Steps

1. Download composer_setup.exe for windows
install it -> select php.exe from xampp/php/

2. create a folder where your xampp root folder
    Create folder
    D:\works\beyond\php\test
    D:\works\beyond\php\test\src
    D:\works\beyond\php\test\src\public


2.1 Copy composer.phar from C:\ProgramData\ComposerSetup\bin [hidden folder] to X:\test\src

//install slim
3. X:\test\src> php composer.phar require slim/slim

//extra dependencies
4. X:\test\src> composer install

5. SVN commit with vendor folder as ignore. that will take care by composer.phar composer.lock composer.json.

6. Create a file X:\test\src\public\index.php
    write your program.
   

7. RUN xampp and type http://localhost:8888/test/src/public/

FOR REST API
*************

1. Go to xampp/apache/conf/httpd.conf change to doc root/directory to D:/test/public
2. restart the apache
3. api url. http://localhost:8888/hello/vijay

Tuesday, April 5, 2016

JDK Difference 1.8 vs 1.7 vs 1.6 .... 1.1





Java 8 (a.k.a 1.8)
Language changes:
  • lambda expressions (JSR 335, includes method handles)
  • continuation of Project Coin (small language improvements)
  • annotations on Java types
Library changes:

Java 7 (a.k.a 1.7)
Language changes:
Library changes:
Platform changes:

Java 6 (a.k.a 1.6)
Mostly incremental improvements to existing libraries, no new language features (except for the @Override snafu).

Java 5 (a.k.a 1.5)
Language Changes:
Library changes:
  • concurrency utilities in java.util.concurrent

Java 1.4
Language changes:
Library changes:

Java 1.3
Mostly minor improvements, really.
Platform changes:
  • HotSpot JVM: improvement over the original JIT

Java 1.2
Language changes:
Library changes:
Platform changes
  • a real JIT, greatly improving speed

Java 1.1
Language changes:
  • inner classes
Library changes:
  • AWT event changes
  • JDBC, RMI
  • reflection

Java 1.0
Initial release, everything is new ;-)


Hit Counter


View My Stats